0.js 529 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154
  1. (window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],{
  2. /***/ "./node_modules/lodash/lodash.js":
  3. /*!***************************************!*\
  4. !*** ./node_modules/lodash/lodash.js ***!
  5. \***************************************/
  6. /*! no static exports found */
  7. /*! all exports used */
  8. /***/ (function(module, exports, __webpack_require__) {
  9. /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
  10. * @license
  11. * Lodash <https://lodash.com/>
  12. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  13. * Released under MIT license <https://lodash.com/license>
  14. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  15. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  16. */
  17. ;(function() {
  18. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  19. var undefined;
  20. /** Used as the semantic version number. */
  21. var VERSION = '4.17.15';
  22. /** Used as the size to enable large array optimizations. */
  23. var LARGE_ARRAY_SIZE = 200;
  24. /** Error message constants. */
  25. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  26. FUNC_ERROR_TEXT = 'Expected a function';
  27. /** Used to stand-in for `undefined` hash values. */
  28. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  29. /** Used as the maximum memoize cache size. */
  30. var MAX_MEMOIZE_SIZE = 500;
  31. /** Used as the internal argument placeholder. */
  32. var PLACEHOLDER = '__lodash_placeholder__';
  33. /** Used to compose bitmasks for cloning. */
  34. var CLONE_DEEP_FLAG = 1,
  35. CLONE_FLAT_FLAG = 2,
  36. CLONE_SYMBOLS_FLAG = 4;
  37. /** Used to compose bitmasks for value comparisons. */
  38. var COMPARE_PARTIAL_FLAG = 1,
  39. COMPARE_UNORDERED_FLAG = 2;
  40. /** Used to compose bitmasks for function metadata. */
  41. var WRAP_BIND_FLAG = 1,
  42. WRAP_BIND_KEY_FLAG = 2,
  43. WRAP_CURRY_BOUND_FLAG = 4,
  44. WRAP_CURRY_FLAG = 8,
  45. WRAP_CURRY_RIGHT_FLAG = 16,
  46. WRAP_PARTIAL_FLAG = 32,
  47. WRAP_PARTIAL_RIGHT_FLAG = 64,
  48. WRAP_ARY_FLAG = 128,
  49. WRAP_REARG_FLAG = 256,
  50. WRAP_FLIP_FLAG = 512;
  51. /** Used as default options for `_.truncate`. */
  52. var DEFAULT_TRUNC_LENGTH = 30,
  53. DEFAULT_TRUNC_OMISSION = '...';
  54. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  55. var HOT_COUNT = 800,
  56. HOT_SPAN = 16;
  57. /** Used to indicate the type of lazy iteratees. */
  58. var LAZY_FILTER_FLAG = 1,
  59. LAZY_MAP_FLAG = 2,
  60. LAZY_WHILE_FLAG = 3;
  61. /** Used as references for various `Number` constants. */
  62. var INFINITY = 1 / 0,
  63. MAX_SAFE_INTEGER = 9007199254740991,
  64. MAX_INTEGER = 1.7976931348623157e+308,
  65. NAN = 0 / 0;
  66. /** Used as references for the maximum length and index of an array. */
  67. var MAX_ARRAY_LENGTH = 4294967295,
  68. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  69. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  70. /** Used to associate wrap methods with their bit flags. */
  71. var wrapFlags = [
  72. ['ary', WRAP_ARY_FLAG],
  73. ['bind', WRAP_BIND_FLAG],
  74. ['bindKey', WRAP_BIND_KEY_FLAG],
  75. ['curry', WRAP_CURRY_FLAG],
  76. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  77. ['flip', WRAP_FLIP_FLAG],
  78. ['partial', WRAP_PARTIAL_FLAG],
  79. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  80. ['rearg', WRAP_REARG_FLAG]
  81. ];
  82. /** `Object#toString` result references. */
  83. var argsTag = '[object Arguments]',
  84. arrayTag = '[object Array]',
  85. asyncTag = '[object AsyncFunction]',
  86. boolTag = '[object Boolean]',
  87. dateTag = '[object Date]',
  88. domExcTag = '[object DOMException]',
  89. errorTag = '[object Error]',
  90. funcTag = '[object Function]',
  91. genTag = '[object GeneratorFunction]',
  92. mapTag = '[object Map]',
  93. numberTag = '[object Number]',
  94. nullTag = '[object Null]',
  95. objectTag = '[object Object]',
  96. promiseTag = '[object Promise]',
  97. proxyTag = '[object Proxy]',
  98. regexpTag = '[object RegExp]',
  99. setTag = '[object Set]',
  100. stringTag = '[object String]',
  101. symbolTag = '[object Symbol]',
  102. undefinedTag = '[object Undefined]',
  103. weakMapTag = '[object WeakMap]',
  104. weakSetTag = '[object WeakSet]';
  105. var arrayBufferTag = '[object ArrayBuffer]',
  106. dataViewTag = '[object DataView]',
  107. float32Tag = '[object Float32Array]',
  108. float64Tag = '[object Float64Array]',
  109. int8Tag = '[object Int8Array]',
  110. int16Tag = '[object Int16Array]',
  111. int32Tag = '[object Int32Array]',
  112. uint8Tag = '[object Uint8Array]',
  113. uint8ClampedTag = '[object Uint8ClampedArray]',
  114. uint16Tag = '[object Uint16Array]',
  115. uint32Tag = '[object Uint32Array]';
  116. /** Used to match empty string literals in compiled template source. */
  117. var reEmptyStringLeading = /\b__p \+= '';/g,
  118. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  119. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  120. /** Used to match HTML entities and HTML characters. */
  121. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  122. reUnescapedHtml = /[&<>"']/g,
  123. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  124. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  125. /** Used to match template delimiters. */
  126. var reEscape = /<%-([\s\S]+?)%>/g,
  127. reEvaluate = /<%([\s\S]+?)%>/g,
  128. reInterpolate = /<%=([\s\S]+?)%>/g;
  129. /** Used to match property names within property paths. */
  130. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  131. reIsPlainProp = /^\w*$/,
  132. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  133. /**
  134. * Used to match `RegExp`
  135. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  136. */
  137. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  138. reHasRegExpChar = RegExp(reRegExpChar.source);
  139. /** Used to match leading and trailing whitespace. */
  140. var reTrim = /^\s+|\s+$/g,
  141. reTrimStart = /^\s+/,
  142. reTrimEnd = /\s+$/;
  143. /** Used to match wrap detail comments. */
  144. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  145. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  146. reSplitDetails = /,? & /;
  147. /** Used to match words composed of alphanumeric characters. */
  148. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  149. /** Used to match backslashes in property paths. */
  150. var reEscapeChar = /\\(\\)?/g;
  151. /**
  152. * Used to match
  153. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  154. */
  155. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  156. /** Used to match `RegExp` flags from their coerced string values. */
  157. var reFlags = /\w*$/;
  158. /** Used to detect bad signed hexadecimal string values. */
  159. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  160. /** Used to detect binary string values. */
  161. var reIsBinary = /^0b[01]+$/i;
  162. /** Used to detect host constructors (Safari). */
  163. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  164. /** Used to detect octal string values. */
  165. var reIsOctal = /^0o[0-7]+$/i;
  166. /** Used to detect unsigned integer values. */
  167. var reIsUint = /^(?:0|[1-9]\d*)$/;
  168. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  169. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  170. /** Used to ensure capturing order of template delimiters. */
  171. var reNoMatch = /($^)/;
  172. /** Used to match unescaped characters in compiled string literals. */
  173. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  174. /** Used to compose unicode character classes. */
  175. var rsAstralRange = '\\ud800-\\udfff',
  176. rsComboMarksRange = '\\u0300-\\u036f',
  177. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  178. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  179. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  180. rsDingbatRange = '\\u2700-\\u27bf',
  181. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  182. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  183. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  184. rsPunctuationRange = '\\u2000-\\u206f',
  185. 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',
  186. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  187. rsVarRange = '\\ufe0e\\ufe0f',
  188. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  189. /** Used to compose unicode capture groups. */
  190. var rsApos = "['\u2019]",
  191. rsAstral = '[' + rsAstralRange + ']',
  192. rsBreak = '[' + rsBreakRange + ']',
  193. rsCombo = '[' + rsComboRange + ']',
  194. rsDigits = '\\d+',
  195. rsDingbat = '[' + rsDingbatRange + ']',
  196. rsLower = '[' + rsLowerRange + ']',
  197. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  198. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  199. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  200. rsNonAstral = '[^' + rsAstralRange + ']',
  201. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  202. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  203. rsUpper = '[' + rsUpperRange + ']',
  204. rsZWJ = '\\u200d';
  205. /** Used to compose unicode regexes. */
  206. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  207. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  208. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  209. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  210. reOptMod = rsModifier + '?',
  211. rsOptVar = '[' + rsVarRange + ']?',
  212. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  213. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  214. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  215. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  216. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  217. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  218. /** Used to match apostrophes. */
  219. var reApos = RegExp(rsApos, 'g');
  220. /**
  221. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  222. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  223. */
  224. var reComboMark = RegExp(rsCombo, 'g');
  225. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  226. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  227. /** Used to match complex or compound words. */
  228. var reUnicodeWord = RegExp([
  229. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  230. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  231. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  232. rsUpper + '+' + rsOptContrUpper,
  233. rsOrdUpper,
  234. rsOrdLower,
  235. rsDigits,
  236. rsEmoji
  237. ].join('|'), 'g');
  238. /** 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/). */
  239. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  240. /** Used to detect strings that need a more robust regexp to match words. */
  241. 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 ]/;
  242. /** Used to assign default `context` object properties. */
  243. var contextProps = [
  244. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  245. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  246. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  247. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  248. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  249. ];
  250. /** Used to make template sourceURLs easier to identify. */
  251. var templateCounter = -1;
  252. /** Used to identify `toStringTag` values of typed arrays. */
  253. var typedArrayTags = {};
  254. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  255. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  256. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  257. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  258. typedArrayTags[uint32Tag] = true;
  259. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  260. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  261. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  262. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  263. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  264. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  265. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  266. typedArrayTags[weakMapTag] = false;
  267. /** Used to identify `toStringTag` values supported by `_.clone`. */
  268. var cloneableTags = {};
  269. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  270. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  271. cloneableTags[boolTag] = cloneableTags[dateTag] =
  272. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  273. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  274. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  275. cloneableTags[numberTag] = cloneableTags[objectTag] =
  276. cloneableTags[regexpTag] = cloneableTags[setTag] =
  277. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  278. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  279. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  280. cloneableTags[errorTag] = cloneableTags[funcTag] =
  281. cloneableTags[weakMapTag] = false;
  282. /** Used to map Latin Unicode letters to basic Latin letters. */
  283. var deburredLetters = {
  284. // Latin-1 Supplement block.
  285. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  286. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  287. '\xc7': 'C', '\xe7': 'c',
  288. '\xd0': 'D', '\xf0': 'd',
  289. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  290. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  291. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  292. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  293. '\xd1': 'N', '\xf1': 'n',
  294. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  295. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  296. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  297. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  298. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  299. '\xc6': 'Ae', '\xe6': 'ae',
  300. '\xde': 'Th', '\xfe': 'th',
  301. '\xdf': 'ss',
  302. // Latin Extended-A block.
  303. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  304. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  305. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  306. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  307. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  308. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  309. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  310. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  311. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  312. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  313. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  314. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  315. '\u0134': 'J', '\u0135': 'j',
  316. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  317. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  318. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  319. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  320. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  321. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  322. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  323. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  324. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  325. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  326. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  327. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  328. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  329. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  330. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  331. '\u0174': 'W', '\u0175': 'w',
  332. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  333. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  334. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  335. '\u0132': 'IJ', '\u0133': 'ij',
  336. '\u0152': 'Oe', '\u0153': 'oe',
  337. '\u0149': "'n", '\u017f': 's'
  338. };
  339. /** Used to map characters to HTML entities. */
  340. var htmlEscapes = {
  341. '&': '&amp;',
  342. '<': '&lt;',
  343. '>': '&gt;',
  344. '"': '&quot;',
  345. "'": '&#39;'
  346. };
  347. /** Used to map HTML entities to characters. */
  348. var htmlUnescapes = {
  349. '&amp;': '&',
  350. '&lt;': '<',
  351. '&gt;': '>',
  352. '&quot;': '"',
  353. '&#39;': "'"
  354. };
  355. /** Used to escape characters for inclusion in compiled string literals. */
  356. var stringEscapes = {
  357. '\\': '\\',
  358. "'": "'",
  359. '\n': 'n',
  360. '\r': 'r',
  361. '\u2028': 'u2028',
  362. '\u2029': 'u2029'
  363. };
  364. /** Built-in method references without a dependency on `root`. */
  365. var freeParseFloat = parseFloat,
  366. freeParseInt = parseInt;
  367. /** Detect free variable `global` from Node.js. */
  368. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  369. /** Detect free variable `self`. */
  370. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  371. /** Used as a reference to the global object. */
  372. var root = freeGlobal || freeSelf || Function('return this')();
  373. /** Detect free variable `exports`. */
  374. var freeExports = true && exports && !exports.nodeType && exports;
  375. /** Detect free variable `module`. */
  376. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  377. /** Detect the popular CommonJS extension `module.exports`. */
  378. var moduleExports = freeModule && freeModule.exports === freeExports;
  379. /** Detect free variable `process` from Node.js. */
  380. var freeProcess = moduleExports && freeGlobal.process;
  381. /** Used to access faster Node.js helpers. */
  382. var nodeUtil = (function() {
  383. try {
  384. // Use `util.types` for Node.js 10+.
  385. var types = freeModule && freeModule.require && freeModule.require('util').types;
  386. if (types) {
  387. return types;
  388. }
  389. // Legacy `process.binding('util')` for Node.js < 10.
  390. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  391. } catch (e) {}
  392. }());
  393. /* Node.js helper references. */
  394. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  395. nodeIsDate = nodeUtil && nodeUtil.isDate,
  396. nodeIsMap = nodeUtil && nodeUtil.isMap,
  397. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  398. nodeIsSet = nodeUtil && nodeUtil.isSet,
  399. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  400. /*--------------------------------------------------------------------------*/
  401. /**
  402. * A faster alternative to `Function#apply`, this function invokes `func`
  403. * with the `this` binding of `thisArg` and the arguments of `args`.
  404. *
  405. * @private
  406. * @param {Function} func The function to invoke.
  407. * @param {*} thisArg The `this` binding of `func`.
  408. * @param {Array} args The arguments to invoke `func` with.
  409. * @returns {*} Returns the result of `func`.
  410. */
  411. function apply(func, thisArg, args) {
  412. switch (args.length) {
  413. case 0: return func.call(thisArg);
  414. case 1: return func.call(thisArg, args[0]);
  415. case 2: return func.call(thisArg, args[0], args[1]);
  416. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  417. }
  418. return func.apply(thisArg, args);
  419. }
  420. /**
  421. * A specialized version of `baseAggregator` for arrays.
  422. *
  423. * @private
  424. * @param {Array} [array] The array to iterate over.
  425. * @param {Function} setter The function to set `accumulator` values.
  426. * @param {Function} iteratee The iteratee to transform keys.
  427. * @param {Object} accumulator The initial aggregated object.
  428. * @returns {Function} Returns `accumulator`.
  429. */
  430. function arrayAggregator(array, setter, iteratee, accumulator) {
  431. var index = -1,
  432. length = array == null ? 0 : array.length;
  433. while (++index < length) {
  434. var value = array[index];
  435. setter(accumulator, value, iteratee(value), array);
  436. }
  437. return accumulator;
  438. }
  439. /**
  440. * A specialized version of `_.forEach` for arrays without support for
  441. * iteratee shorthands.
  442. *
  443. * @private
  444. * @param {Array} [array] The array to iterate over.
  445. * @param {Function} iteratee The function invoked per iteration.
  446. * @returns {Array} Returns `array`.
  447. */
  448. function arrayEach(array, iteratee) {
  449. var index = -1,
  450. length = array == null ? 0 : array.length;
  451. while (++index < length) {
  452. if (iteratee(array[index], index, array) === false) {
  453. break;
  454. }
  455. }
  456. return array;
  457. }
  458. /**
  459. * A specialized version of `_.forEachRight` for arrays without support for
  460. * iteratee shorthands.
  461. *
  462. * @private
  463. * @param {Array} [array] The array to iterate over.
  464. * @param {Function} iteratee The function invoked per iteration.
  465. * @returns {Array} Returns `array`.
  466. */
  467. function arrayEachRight(array, iteratee) {
  468. var length = array == null ? 0 : array.length;
  469. while (length--) {
  470. if (iteratee(array[length], length, array) === false) {
  471. break;
  472. }
  473. }
  474. return array;
  475. }
  476. /**
  477. * A specialized version of `_.every` for arrays without support for
  478. * iteratee shorthands.
  479. *
  480. * @private
  481. * @param {Array} [array] The array to iterate over.
  482. * @param {Function} predicate The function invoked per iteration.
  483. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  484. * else `false`.
  485. */
  486. function arrayEvery(array, predicate) {
  487. var index = -1,
  488. length = array == null ? 0 : array.length;
  489. while (++index < length) {
  490. if (!predicate(array[index], index, array)) {
  491. return false;
  492. }
  493. }
  494. return true;
  495. }
  496. /**
  497. * A specialized version of `_.filter` for arrays without support for
  498. * iteratee shorthands.
  499. *
  500. * @private
  501. * @param {Array} [array] The array to iterate over.
  502. * @param {Function} predicate The function invoked per iteration.
  503. * @returns {Array} Returns the new filtered array.
  504. */
  505. function arrayFilter(array, predicate) {
  506. var index = -1,
  507. length = array == null ? 0 : array.length,
  508. resIndex = 0,
  509. result = [];
  510. while (++index < length) {
  511. var value = array[index];
  512. if (predicate(value, index, array)) {
  513. result[resIndex++] = value;
  514. }
  515. }
  516. return result;
  517. }
  518. /**
  519. * A specialized version of `_.includes` for arrays without support for
  520. * specifying an index to search from.
  521. *
  522. * @private
  523. * @param {Array} [array] The array to inspect.
  524. * @param {*} target The value to search for.
  525. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  526. */
  527. function arrayIncludes(array, value) {
  528. var length = array == null ? 0 : array.length;
  529. return !!length && baseIndexOf(array, value, 0) > -1;
  530. }
  531. /**
  532. * This function is like `arrayIncludes` except that it accepts a comparator.
  533. *
  534. * @private
  535. * @param {Array} [array] The array to inspect.
  536. * @param {*} target The value to search for.
  537. * @param {Function} comparator The comparator invoked per element.
  538. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  539. */
  540. function arrayIncludesWith(array, value, comparator) {
  541. var index = -1,
  542. length = array == null ? 0 : array.length;
  543. while (++index < length) {
  544. if (comparator(value, array[index])) {
  545. return true;
  546. }
  547. }
  548. return false;
  549. }
  550. /**
  551. * A specialized version of `_.map` for arrays without support for iteratee
  552. * shorthands.
  553. *
  554. * @private
  555. * @param {Array} [array] The array to iterate over.
  556. * @param {Function} iteratee The function invoked per iteration.
  557. * @returns {Array} Returns the new mapped array.
  558. */
  559. function arrayMap(array, iteratee) {
  560. var index = -1,
  561. length = array == null ? 0 : array.length,
  562. result = Array(length);
  563. while (++index < length) {
  564. result[index] = iteratee(array[index], index, array);
  565. }
  566. return result;
  567. }
  568. /**
  569. * Appends the elements of `values` to `array`.
  570. *
  571. * @private
  572. * @param {Array} array The array to modify.
  573. * @param {Array} values The values to append.
  574. * @returns {Array} Returns `array`.
  575. */
  576. function arrayPush(array, values) {
  577. var index = -1,
  578. length = values.length,
  579. offset = array.length;
  580. while (++index < length) {
  581. array[offset + index] = values[index];
  582. }
  583. return array;
  584. }
  585. /**
  586. * A specialized version of `_.reduce` for arrays without support for
  587. * iteratee shorthands.
  588. *
  589. * @private
  590. * @param {Array} [array] The array to iterate over.
  591. * @param {Function} iteratee The function invoked per iteration.
  592. * @param {*} [accumulator] The initial value.
  593. * @param {boolean} [initAccum] Specify using the first element of `array` as
  594. * the initial value.
  595. * @returns {*} Returns the accumulated value.
  596. */
  597. function arrayReduce(array, iteratee, accumulator, initAccum) {
  598. var index = -1,
  599. length = array == null ? 0 : array.length;
  600. if (initAccum && length) {
  601. accumulator = array[++index];
  602. }
  603. while (++index < length) {
  604. accumulator = iteratee(accumulator, array[index], index, array);
  605. }
  606. return accumulator;
  607. }
  608. /**
  609. * A specialized version of `_.reduceRight` for arrays without support for
  610. * iteratee shorthands.
  611. *
  612. * @private
  613. * @param {Array} [array] The array to iterate over.
  614. * @param {Function} iteratee The function invoked per iteration.
  615. * @param {*} [accumulator] The initial value.
  616. * @param {boolean} [initAccum] Specify using the last element of `array` as
  617. * the initial value.
  618. * @returns {*} Returns the accumulated value.
  619. */
  620. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  621. var length = array == null ? 0 : array.length;
  622. if (initAccum && length) {
  623. accumulator = array[--length];
  624. }
  625. while (length--) {
  626. accumulator = iteratee(accumulator, array[length], length, array);
  627. }
  628. return accumulator;
  629. }
  630. /**
  631. * A specialized version of `_.some` for arrays without support for iteratee
  632. * shorthands.
  633. *
  634. * @private
  635. * @param {Array} [array] The array to iterate over.
  636. * @param {Function} predicate The function invoked per iteration.
  637. * @returns {boolean} Returns `true` if any element passes the predicate check,
  638. * else `false`.
  639. */
  640. function arraySome(array, predicate) {
  641. var index = -1,
  642. length = array == null ? 0 : array.length;
  643. while (++index < length) {
  644. if (predicate(array[index], index, array)) {
  645. return true;
  646. }
  647. }
  648. return false;
  649. }
  650. /**
  651. * Gets the size of an ASCII `string`.
  652. *
  653. * @private
  654. * @param {string} string The string inspect.
  655. * @returns {number} Returns the string size.
  656. */
  657. var asciiSize = baseProperty('length');
  658. /**
  659. * Converts an ASCII `string` to an array.
  660. *
  661. * @private
  662. * @param {string} string The string to convert.
  663. * @returns {Array} Returns the converted array.
  664. */
  665. function asciiToArray(string) {
  666. return string.split('');
  667. }
  668. /**
  669. * Splits an ASCII `string` into an array of its words.
  670. *
  671. * @private
  672. * @param {string} The string to inspect.
  673. * @returns {Array} Returns the words of `string`.
  674. */
  675. function asciiWords(string) {
  676. return string.match(reAsciiWord) || [];
  677. }
  678. /**
  679. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  680. * without support for iteratee shorthands, which iterates over `collection`
  681. * using `eachFunc`.
  682. *
  683. * @private
  684. * @param {Array|Object} collection The collection to inspect.
  685. * @param {Function} predicate The function invoked per iteration.
  686. * @param {Function} eachFunc The function to iterate over `collection`.
  687. * @returns {*} Returns the found element or its key, else `undefined`.
  688. */
  689. function baseFindKey(collection, predicate, eachFunc) {
  690. var result;
  691. eachFunc(collection, function(value, key, collection) {
  692. if (predicate(value, key, collection)) {
  693. result = key;
  694. return false;
  695. }
  696. });
  697. return result;
  698. }
  699. /**
  700. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  701. * support for iteratee shorthands.
  702. *
  703. * @private
  704. * @param {Array} array The array to inspect.
  705. * @param {Function} predicate The function invoked per iteration.
  706. * @param {number} fromIndex The index to search from.
  707. * @param {boolean} [fromRight] Specify iterating from right to left.
  708. * @returns {number} Returns the index of the matched value, else `-1`.
  709. */
  710. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  711. var length = array.length,
  712. index = fromIndex + (fromRight ? 1 : -1);
  713. while ((fromRight ? index-- : ++index < length)) {
  714. if (predicate(array[index], index, array)) {
  715. return index;
  716. }
  717. }
  718. return -1;
  719. }
  720. /**
  721. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  722. *
  723. * @private
  724. * @param {Array} array The array to inspect.
  725. * @param {*} value The value to search for.
  726. * @param {number} fromIndex The index to search from.
  727. * @returns {number} Returns the index of the matched value, else `-1`.
  728. */
  729. function baseIndexOf(array, value, fromIndex) {
  730. return value === value
  731. ? strictIndexOf(array, value, fromIndex)
  732. : baseFindIndex(array, baseIsNaN, fromIndex);
  733. }
  734. /**
  735. * This function is like `baseIndexOf` except that it accepts a comparator.
  736. *
  737. * @private
  738. * @param {Array} array The array to inspect.
  739. * @param {*} value The value to search for.
  740. * @param {number} fromIndex The index to search from.
  741. * @param {Function} comparator The comparator invoked per element.
  742. * @returns {number} Returns the index of the matched value, else `-1`.
  743. */
  744. function baseIndexOfWith(array, value, fromIndex, comparator) {
  745. var index = fromIndex - 1,
  746. length = array.length;
  747. while (++index < length) {
  748. if (comparator(array[index], value)) {
  749. return index;
  750. }
  751. }
  752. return -1;
  753. }
  754. /**
  755. * The base implementation of `_.isNaN` without support for number objects.
  756. *
  757. * @private
  758. * @param {*} value The value to check.
  759. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  760. */
  761. function baseIsNaN(value) {
  762. return value !== value;
  763. }
  764. /**
  765. * The base implementation of `_.mean` and `_.meanBy` without support for
  766. * iteratee shorthands.
  767. *
  768. * @private
  769. * @param {Array} array The array to iterate over.
  770. * @param {Function} iteratee The function invoked per iteration.
  771. * @returns {number} Returns the mean.
  772. */
  773. function baseMean(array, iteratee) {
  774. var length = array == null ? 0 : array.length;
  775. return length ? (baseSum(array, iteratee) / length) : NAN;
  776. }
  777. /**
  778. * The base implementation of `_.property` without support for deep paths.
  779. *
  780. * @private
  781. * @param {string} key The key of the property to get.
  782. * @returns {Function} Returns the new accessor function.
  783. */
  784. function baseProperty(key) {
  785. return function(object) {
  786. return object == null ? undefined : object[key];
  787. };
  788. }
  789. /**
  790. * The base implementation of `_.propertyOf` without support for deep paths.
  791. *
  792. * @private
  793. * @param {Object} object The object to query.
  794. * @returns {Function} Returns the new accessor function.
  795. */
  796. function basePropertyOf(object) {
  797. return function(key) {
  798. return object == null ? undefined : object[key];
  799. };
  800. }
  801. /**
  802. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  803. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  804. *
  805. * @private
  806. * @param {Array|Object} collection The collection to iterate over.
  807. * @param {Function} iteratee The function invoked per iteration.
  808. * @param {*} accumulator The initial value.
  809. * @param {boolean} initAccum Specify using the first or last element of
  810. * `collection` as the initial value.
  811. * @param {Function} eachFunc The function to iterate over `collection`.
  812. * @returns {*} Returns the accumulated value.
  813. */
  814. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  815. eachFunc(collection, function(value, index, collection) {
  816. accumulator = initAccum
  817. ? (initAccum = false, value)
  818. : iteratee(accumulator, value, index, collection);
  819. });
  820. return accumulator;
  821. }
  822. /**
  823. * The base implementation of `_.sortBy` which uses `comparer` to define the
  824. * sort order of `array` and replaces criteria objects with their corresponding
  825. * values.
  826. *
  827. * @private
  828. * @param {Array} array The array to sort.
  829. * @param {Function} comparer The function to define sort order.
  830. * @returns {Array} Returns `array`.
  831. */
  832. function baseSortBy(array, comparer) {
  833. var length = array.length;
  834. array.sort(comparer);
  835. while (length--) {
  836. array[length] = array[length].value;
  837. }
  838. return array;
  839. }
  840. /**
  841. * The base implementation of `_.sum` and `_.sumBy` without support for
  842. * iteratee shorthands.
  843. *
  844. * @private
  845. * @param {Array} array The array to iterate over.
  846. * @param {Function} iteratee The function invoked per iteration.
  847. * @returns {number} Returns the sum.
  848. */
  849. function baseSum(array, iteratee) {
  850. var result,
  851. index = -1,
  852. length = array.length;
  853. while (++index < length) {
  854. var current = iteratee(array[index]);
  855. if (current !== undefined) {
  856. result = result === undefined ? current : (result + current);
  857. }
  858. }
  859. return result;
  860. }
  861. /**
  862. * The base implementation of `_.times` without support for iteratee shorthands
  863. * or max array length checks.
  864. *
  865. * @private
  866. * @param {number} n The number of times to invoke `iteratee`.
  867. * @param {Function} iteratee The function invoked per iteration.
  868. * @returns {Array} Returns the array of results.
  869. */
  870. function baseTimes(n, iteratee) {
  871. var index = -1,
  872. result = Array(n);
  873. while (++index < n) {
  874. result[index] = iteratee(index);
  875. }
  876. return result;
  877. }
  878. /**
  879. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  880. * of key-value pairs for `object` corresponding to the property names of `props`.
  881. *
  882. * @private
  883. * @param {Object} object The object to query.
  884. * @param {Array} props The property names to get values for.
  885. * @returns {Object} Returns the key-value pairs.
  886. */
  887. function baseToPairs(object, props) {
  888. return arrayMap(props, function(key) {
  889. return [key, object[key]];
  890. });
  891. }
  892. /**
  893. * The base implementation of `_.unary` without support for storing metadata.
  894. *
  895. * @private
  896. * @param {Function} func The function to cap arguments for.
  897. * @returns {Function} Returns the new capped function.
  898. */
  899. function baseUnary(func) {
  900. return function(value) {
  901. return func(value);
  902. };
  903. }
  904. /**
  905. * The base implementation of `_.values` and `_.valuesIn` which creates an
  906. * array of `object` property values corresponding to the property names
  907. * of `props`.
  908. *
  909. * @private
  910. * @param {Object} object The object to query.
  911. * @param {Array} props The property names to get values for.
  912. * @returns {Object} Returns the array of property values.
  913. */
  914. function baseValues(object, props) {
  915. return arrayMap(props, function(key) {
  916. return object[key];
  917. });
  918. }
  919. /**
  920. * Checks if a `cache` value for `key` exists.
  921. *
  922. * @private
  923. * @param {Object} cache The cache to query.
  924. * @param {string} key The key of the entry to check.
  925. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  926. */
  927. function cacheHas(cache, key) {
  928. return cache.has(key);
  929. }
  930. /**
  931. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  932. * that is not found in the character symbols.
  933. *
  934. * @private
  935. * @param {Array} strSymbols The string symbols to inspect.
  936. * @param {Array} chrSymbols The character symbols to find.
  937. * @returns {number} Returns the index of the first unmatched string symbol.
  938. */
  939. function charsStartIndex(strSymbols, chrSymbols) {
  940. var index = -1,
  941. length = strSymbols.length;
  942. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  943. return index;
  944. }
  945. /**
  946. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  947. * that is not found in the character symbols.
  948. *
  949. * @private
  950. * @param {Array} strSymbols The string symbols to inspect.
  951. * @param {Array} chrSymbols The character symbols to find.
  952. * @returns {number} Returns the index of the last unmatched string symbol.
  953. */
  954. function charsEndIndex(strSymbols, chrSymbols) {
  955. var index = strSymbols.length;
  956. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  957. return index;
  958. }
  959. /**
  960. * Gets the number of `placeholder` occurrences in `array`.
  961. *
  962. * @private
  963. * @param {Array} array The array to inspect.
  964. * @param {*} placeholder The placeholder to search for.
  965. * @returns {number} Returns the placeholder count.
  966. */
  967. function countHolders(array, placeholder) {
  968. var length = array.length,
  969. result = 0;
  970. while (length--) {
  971. if (array[length] === placeholder) {
  972. ++result;
  973. }
  974. }
  975. return result;
  976. }
  977. /**
  978. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  979. * letters to basic Latin letters.
  980. *
  981. * @private
  982. * @param {string} letter The matched letter to deburr.
  983. * @returns {string} Returns the deburred letter.
  984. */
  985. var deburrLetter = basePropertyOf(deburredLetters);
  986. /**
  987. * Used by `_.escape` to convert characters to HTML entities.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  994. /**
  995. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  996. *
  997. * @private
  998. * @param {string} chr The matched character to escape.
  999. * @returns {string} Returns the escaped character.
  1000. */
  1001. function escapeStringChar(chr) {
  1002. return '\\' + stringEscapes[chr];
  1003. }
  1004. /**
  1005. * Gets the value at `key` of `object`.
  1006. *
  1007. * @private
  1008. * @param {Object} [object] The object to query.
  1009. * @param {string} key The key of the property to get.
  1010. * @returns {*} Returns the property value.
  1011. */
  1012. function getValue(object, key) {
  1013. return object == null ? undefined : object[key];
  1014. }
  1015. /**
  1016. * Checks if `string` contains Unicode symbols.
  1017. *
  1018. * @private
  1019. * @param {string} string The string to inspect.
  1020. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1021. */
  1022. function hasUnicode(string) {
  1023. return reHasUnicode.test(string);
  1024. }
  1025. /**
  1026. * Checks if `string` contains a word composed of Unicode symbols.
  1027. *
  1028. * @private
  1029. * @param {string} string The string to inspect.
  1030. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1031. */
  1032. function hasUnicodeWord(string) {
  1033. return reHasUnicodeWord.test(string);
  1034. }
  1035. /**
  1036. * Converts `iterator` to an array.
  1037. *
  1038. * @private
  1039. * @param {Object} iterator The iterator to convert.
  1040. * @returns {Array} Returns the converted array.
  1041. */
  1042. function iteratorToArray(iterator) {
  1043. var data,
  1044. result = [];
  1045. while (!(data = iterator.next()).done) {
  1046. result.push(data.value);
  1047. }
  1048. return result;
  1049. }
  1050. /**
  1051. * Converts `map` to its key-value pairs.
  1052. *
  1053. * @private
  1054. * @param {Object} map The map to convert.
  1055. * @returns {Array} Returns the key-value pairs.
  1056. */
  1057. function mapToArray(map) {
  1058. var index = -1,
  1059. result = Array(map.size);
  1060. map.forEach(function(value, key) {
  1061. result[++index] = [key, value];
  1062. });
  1063. return result;
  1064. }
  1065. /**
  1066. * Creates a unary function that invokes `func` with its argument transformed.
  1067. *
  1068. * @private
  1069. * @param {Function} func The function to wrap.
  1070. * @param {Function} transform The argument transform.
  1071. * @returns {Function} Returns the new function.
  1072. */
  1073. function overArg(func, transform) {
  1074. return function(arg) {
  1075. return func(transform(arg));
  1076. };
  1077. }
  1078. /**
  1079. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1080. * and returns an array of their indexes.
  1081. *
  1082. * @private
  1083. * @param {Array} array The array to modify.
  1084. * @param {*} placeholder The placeholder to replace.
  1085. * @returns {Array} Returns the new array of placeholder indexes.
  1086. */
  1087. function replaceHolders(array, placeholder) {
  1088. var index = -1,
  1089. length = array.length,
  1090. resIndex = 0,
  1091. result = [];
  1092. while (++index < length) {
  1093. var value = array[index];
  1094. if (value === placeholder || value === PLACEHOLDER) {
  1095. array[index] = PLACEHOLDER;
  1096. result[resIndex++] = index;
  1097. }
  1098. }
  1099. return result;
  1100. }
  1101. /**
  1102. * Converts `set` to an array of its values.
  1103. *
  1104. * @private
  1105. * @param {Object} set The set to convert.
  1106. * @returns {Array} Returns the values.
  1107. */
  1108. function setToArray(set) {
  1109. var index = -1,
  1110. result = Array(set.size);
  1111. set.forEach(function(value) {
  1112. result[++index] = value;
  1113. });
  1114. return result;
  1115. }
  1116. /**
  1117. * Converts `set` to its value-value pairs.
  1118. *
  1119. * @private
  1120. * @param {Object} set The set to convert.
  1121. * @returns {Array} Returns the value-value pairs.
  1122. */
  1123. function setToPairs(set) {
  1124. var index = -1,
  1125. result = Array(set.size);
  1126. set.forEach(function(value) {
  1127. result[++index] = [value, value];
  1128. });
  1129. return result;
  1130. }
  1131. /**
  1132. * A specialized version of `_.indexOf` which performs strict equality
  1133. * comparisons of values, i.e. `===`.
  1134. *
  1135. * @private
  1136. * @param {Array} array The array to inspect.
  1137. * @param {*} value The value to search for.
  1138. * @param {number} fromIndex The index to search from.
  1139. * @returns {number} Returns the index of the matched value, else `-1`.
  1140. */
  1141. function strictIndexOf(array, value, fromIndex) {
  1142. var index = fromIndex - 1,
  1143. length = array.length;
  1144. while (++index < length) {
  1145. if (array[index] === value) {
  1146. return index;
  1147. }
  1148. }
  1149. return -1;
  1150. }
  1151. /**
  1152. * A specialized version of `_.lastIndexOf` which performs strict equality
  1153. * comparisons of values, i.e. `===`.
  1154. *
  1155. * @private
  1156. * @param {Array} array The array to inspect.
  1157. * @param {*} value The value to search for.
  1158. * @param {number} fromIndex The index to search from.
  1159. * @returns {number} Returns the index of the matched value, else `-1`.
  1160. */
  1161. function strictLastIndexOf(array, value, fromIndex) {
  1162. var index = fromIndex + 1;
  1163. while (index--) {
  1164. if (array[index] === value) {
  1165. return index;
  1166. }
  1167. }
  1168. return index;
  1169. }
  1170. /**
  1171. * Gets the number of symbols in `string`.
  1172. *
  1173. * @private
  1174. * @param {string} string The string to inspect.
  1175. * @returns {number} Returns the string size.
  1176. */
  1177. function stringSize(string) {
  1178. return hasUnicode(string)
  1179. ? unicodeSize(string)
  1180. : asciiSize(string);
  1181. }
  1182. /**
  1183. * Converts `string` to an array.
  1184. *
  1185. * @private
  1186. * @param {string} string The string to convert.
  1187. * @returns {Array} Returns the converted array.
  1188. */
  1189. function stringToArray(string) {
  1190. return hasUnicode(string)
  1191. ? unicodeToArray(string)
  1192. : asciiToArray(string);
  1193. }
  1194. /**
  1195. * Used by `_.unescape` to convert HTML entities to characters.
  1196. *
  1197. * @private
  1198. * @param {string} chr The matched character to unescape.
  1199. * @returns {string} Returns the unescaped character.
  1200. */
  1201. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1202. /**
  1203. * Gets the size of a Unicode `string`.
  1204. *
  1205. * @private
  1206. * @param {string} string The string inspect.
  1207. * @returns {number} Returns the string size.
  1208. */
  1209. function unicodeSize(string) {
  1210. var result = reUnicode.lastIndex = 0;
  1211. while (reUnicode.test(string)) {
  1212. ++result;
  1213. }
  1214. return result;
  1215. }
  1216. /**
  1217. * Converts a Unicode `string` to an array.
  1218. *
  1219. * @private
  1220. * @param {string} string The string to convert.
  1221. * @returns {Array} Returns the converted array.
  1222. */
  1223. function unicodeToArray(string) {
  1224. return string.match(reUnicode) || [];
  1225. }
  1226. /**
  1227. * Splits a Unicode `string` into an array of its words.
  1228. *
  1229. * @private
  1230. * @param {string} The string to inspect.
  1231. * @returns {Array} Returns the words of `string`.
  1232. */
  1233. function unicodeWords(string) {
  1234. return string.match(reUnicodeWord) || [];
  1235. }
  1236. /*--------------------------------------------------------------------------*/
  1237. /**
  1238. * Create a new pristine `lodash` function using the `context` object.
  1239. *
  1240. * @static
  1241. * @memberOf _
  1242. * @since 1.1.0
  1243. * @category Util
  1244. * @param {Object} [context=root] The context object.
  1245. * @returns {Function} Returns a new `lodash` function.
  1246. * @example
  1247. *
  1248. * _.mixin({ 'foo': _.constant('foo') });
  1249. *
  1250. * var lodash = _.runInContext();
  1251. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1252. *
  1253. * _.isFunction(_.foo);
  1254. * // => true
  1255. * _.isFunction(_.bar);
  1256. * // => false
  1257. *
  1258. * lodash.isFunction(lodash.foo);
  1259. * // => false
  1260. * lodash.isFunction(lodash.bar);
  1261. * // => true
  1262. *
  1263. * // Create a suped-up `defer` in Node.js.
  1264. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1265. */
  1266. var runInContext = (function runInContext(context) {
  1267. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1268. /** Built-in constructor references. */
  1269. var Array = context.Array,
  1270. Date = context.Date,
  1271. Error = context.Error,
  1272. Function = context.Function,
  1273. Math = context.Math,
  1274. Object = context.Object,
  1275. RegExp = context.RegExp,
  1276. String = context.String,
  1277. TypeError = context.TypeError;
  1278. /** Used for built-in method references. */
  1279. var arrayProto = Array.prototype,
  1280. funcProto = Function.prototype,
  1281. objectProto = Object.prototype;
  1282. /** Used to detect overreaching core-js shims. */
  1283. var coreJsData = context['__core-js_shared__'];
  1284. /** Used to resolve the decompiled source of functions. */
  1285. var funcToString = funcProto.toString;
  1286. /** Used to check objects for own properties. */
  1287. var hasOwnProperty = objectProto.hasOwnProperty;
  1288. /** Used to generate unique IDs. */
  1289. var idCounter = 0;
  1290. /** Used to detect methods masquerading as native. */
  1291. var maskSrcKey = (function() {
  1292. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1293. return uid ? ('Symbol(src)_1.' + uid) : '';
  1294. }());
  1295. /**
  1296. * Used to resolve the
  1297. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1298. * of values.
  1299. */
  1300. var nativeObjectToString = objectProto.toString;
  1301. /** Used to infer the `Object` constructor. */
  1302. var objectCtorString = funcToString.call(Object);
  1303. /** Used to restore the original `_` reference in `_.noConflict`. */
  1304. var oldDash = root._;
  1305. /** Used to detect if a method is native. */
  1306. var reIsNative = RegExp('^' +
  1307. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1308. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1309. );
  1310. /** Built-in value references. */
  1311. var Buffer = moduleExports ? context.Buffer : undefined,
  1312. Symbol = context.Symbol,
  1313. Uint8Array = context.Uint8Array,
  1314. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1315. getPrototype = overArg(Object.getPrototypeOf, Object),
  1316. objectCreate = Object.create,
  1317. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1318. splice = arrayProto.splice,
  1319. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1320. symIterator = Symbol ? Symbol.iterator : undefined,
  1321. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1322. var defineProperty = (function() {
  1323. try {
  1324. var func = getNative(Object, 'defineProperty');
  1325. func({}, '', {});
  1326. return func;
  1327. } catch (e) {}
  1328. }());
  1329. /** Mocked built-ins. */
  1330. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1331. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1332. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1333. /* Built-in method references for those with the same name as other `lodash` methods. */
  1334. var nativeCeil = Math.ceil,
  1335. nativeFloor = Math.floor,
  1336. nativeGetSymbols = Object.getOwnPropertySymbols,
  1337. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1338. nativeIsFinite = context.isFinite,
  1339. nativeJoin = arrayProto.join,
  1340. nativeKeys = overArg(Object.keys, Object),
  1341. nativeMax = Math.max,
  1342. nativeMin = Math.min,
  1343. nativeNow = Date.now,
  1344. nativeParseInt = context.parseInt,
  1345. nativeRandom = Math.random,
  1346. nativeReverse = arrayProto.reverse;
  1347. /* Built-in method references that are verified to be native. */
  1348. var DataView = getNative(context, 'DataView'),
  1349. Map = getNative(context, 'Map'),
  1350. Promise = getNative(context, 'Promise'),
  1351. Set = getNative(context, 'Set'),
  1352. WeakMap = getNative(context, 'WeakMap'),
  1353. nativeCreate = getNative(Object, 'create');
  1354. /** Used to store function metadata. */
  1355. var metaMap = WeakMap && new WeakMap;
  1356. /** Used to lookup unminified function names. */
  1357. var realNames = {};
  1358. /** Used to detect maps, sets, and weakmaps. */
  1359. var dataViewCtorString = toSource(DataView),
  1360. mapCtorString = toSource(Map),
  1361. promiseCtorString = toSource(Promise),
  1362. setCtorString = toSource(Set),
  1363. weakMapCtorString = toSource(WeakMap);
  1364. /** Used to convert symbols to primitives and strings. */
  1365. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1366. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1367. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1368. /*------------------------------------------------------------------------*/
  1369. /**
  1370. * Creates a `lodash` object which wraps `value` to enable implicit method
  1371. * chain sequences. Methods that operate on and return arrays, collections,
  1372. * and functions can be chained together. Methods that retrieve a single value
  1373. * or may return a primitive value will automatically end the chain sequence
  1374. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1375. * with `_#value`.
  1376. *
  1377. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1378. * enabled using `_.chain`.
  1379. *
  1380. * The execution of chained methods is lazy, that is, it's deferred until
  1381. * `_#value` is implicitly or explicitly called.
  1382. *
  1383. * Lazy evaluation allows several methods to support shortcut fusion.
  1384. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1385. * the creation of intermediate arrays and can greatly reduce the number of
  1386. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1387. * fusion if the section is applied to an array and iteratees accept only
  1388. * one argument. The heuristic for whether a section qualifies for shortcut
  1389. * fusion is subject to change.
  1390. *
  1391. * Chaining is supported in custom builds as long as the `_#value` method is
  1392. * directly or indirectly included in the build.
  1393. *
  1394. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1395. *
  1396. * The wrapper `Array` methods are:
  1397. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1398. *
  1399. * The wrapper `String` methods are:
  1400. * `replace` and `split`
  1401. *
  1402. * The wrapper methods that support shortcut fusion are:
  1403. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1404. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1405. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1406. *
  1407. * The chainable wrapper methods are:
  1408. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1409. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1410. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1411. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1412. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1413. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1414. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1415. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1416. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1417. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1418. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1419. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1420. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1421. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1422. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1423. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1424. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1425. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1426. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1427. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1428. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1429. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1430. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1431. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1432. *
  1433. * The wrapper methods that are **not** chainable by default are:
  1434. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1435. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1436. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1437. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1438. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1439. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1440. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1441. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1442. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1443. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1444. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1445. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1446. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1447. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1448. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1449. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1450. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1451. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1452. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1453. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1454. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1455. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1456. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1457. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1458. * `upperFirst`, `value`, and `words`
  1459. *
  1460. * @name _
  1461. * @constructor
  1462. * @category Seq
  1463. * @param {*} value The value to wrap in a `lodash` instance.
  1464. * @returns {Object} Returns the new `lodash` wrapper instance.
  1465. * @example
  1466. *
  1467. * function square(n) {
  1468. * return n * n;
  1469. * }
  1470. *
  1471. * var wrapped = _([1, 2, 3]);
  1472. *
  1473. * // Returns an unwrapped value.
  1474. * wrapped.reduce(_.add);
  1475. * // => 6
  1476. *
  1477. * // Returns a wrapped value.
  1478. * var squares = wrapped.map(square);
  1479. *
  1480. * _.isArray(squares);
  1481. * // => false
  1482. *
  1483. * _.isArray(squares.value());
  1484. * // => true
  1485. */
  1486. function lodash(value) {
  1487. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1488. if (value instanceof LodashWrapper) {
  1489. return value;
  1490. }
  1491. if (hasOwnProperty.call(value, '__wrapped__')) {
  1492. return wrapperClone(value);
  1493. }
  1494. }
  1495. return new LodashWrapper(value);
  1496. }
  1497. /**
  1498. * The base implementation of `_.create` without support for assigning
  1499. * properties to the created object.
  1500. *
  1501. * @private
  1502. * @param {Object} proto The object to inherit from.
  1503. * @returns {Object} Returns the new object.
  1504. */
  1505. var baseCreate = (function() {
  1506. function object() {}
  1507. return function(proto) {
  1508. if (!isObject(proto)) {
  1509. return {};
  1510. }
  1511. if (objectCreate) {
  1512. return objectCreate(proto);
  1513. }
  1514. object.prototype = proto;
  1515. var result = new object;
  1516. object.prototype = undefined;
  1517. return result;
  1518. };
  1519. }());
  1520. /**
  1521. * The function whose prototype chain sequence wrappers inherit from.
  1522. *
  1523. * @private
  1524. */
  1525. function baseLodash() {
  1526. // No operation performed.
  1527. }
  1528. /**
  1529. * The base constructor for creating `lodash` wrapper objects.
  1530. *
  1531. * @private
  1532. * @param {*} value The value to wrap.
  1533. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1534. */
  1535. function LodashWrapper(value, chainAll) {
  1536. this.__wrapped__ = value;
  1537. this.__actions__ = [];
  1538. this.__chain__ = !!chainAll;
  1539. this.__index__ = 0;
  1540. this.__values__ = undefined;
  1541. }
  1542. /**
  1543. * By default, the template delimiters used by lodash are like those in
  1544. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1545. * following template settings to use alternative delimiters.
  1546. *
  1547. * @static
  1548. * @memberOf _
  1549. * @type {Object}
  1550. */
  1551. lodash.templateSettings = {
  1552. /**
  1553. * Used to detect `data` property values to be HTML-escaped.
  1554. *
  1555. * @memberOf _.templateSettings
  1556. * @type {RegExp}
  1557. */
  1558. 'escape': reEscape,
  1559. /**
  1560. * Used to detect code to be evaluated.
  1561. *
  1562. * @memberOf _.templateSettings
  1563. * @type {RegExp}
  1564. */
  1565. 'evaluate': reEvaluate,
  1566. /**
  1567. * Used to detect `data` property values to inject.
  1568. *
  1569. * @memberOf _.templateSettings
  1570. * @type {RegExp}
  1571. */
  1572. 'interpolate': reInterpolate,
  1573. /**
  1574. * Used to reference the data object in the template text.
  1575. *
  1576. * @memberOf _.templateSettings
  1577. * @type {string}
  1578. */
  1579. 'variable': '',
  1580. /**
  1581. * Used to import variables into the compiled template.
  1582. *
  1583. * @memberOf _.templateSettings
  1584. * @type {Object}
  1585. */
  1586. 'imports': {
  1587. /**
  1588. * A reference to the `lodash` function.
  1589. *
  1590. * @memberOf _.templateSettings.imports
  1591. * @type {Function}
  1592. */
  1593. '_': lodash
  1594. }
  1595. };
  1596. // Ensure wrappers are instances of `baseLodash`.
  1597. lodash.prototype = baseLodash.prototype;
  1598. lodash.prototype.constructor = lodash;
  1599. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1600. LodashWrapper.prototype.constructor = LodashWrapper;
  1601. /*------------------------------------------------------------------------*/
  1602. /**
  1603. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1604. *
  1605. * @private
  1606. * @constructor
  1607. * @param {*} value The value to wrap.
  1608. */
  1609. function LazyWrapper(value) {
  1610. this.__wrapped__ = value;
  1611. this.__actions__ = [];
  1612. this.__dir__ = 1;
  1613. this.__filtered__ = false;
  1614. this.__iteratees__ = [];
  1615. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1616. this.__views__ = [];
  1617. }
  1618. /**
  1619. * Creates a clone of the lazy wrapper object.
  1620. *
  1621. * @private
  1622. * @name clone
  1623. * @memberOf LazyWrapper
  1624. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1625. */
  1626. function lazyClone() {
  1627. var result = new LazyWrapper(this.__wrapped__);
  1628. result.__actions__ = copyArray(this.__actions__);
  1629. result.__dir__ = this.__dir__;
  1630. result.__filtered__ = this.__filtered__;
  1631. result.__iteratees__ = copyArray(this.__iteratees__);
  1632. result.__takeCount__ = this.__takeCount__;
  1633. result.__views__ = copyArray(this.__views__);
  1634. return result;
  1635. }
  1636. /**
  1637. * Reverses the direction of lazy iteration.
  1638. *
  1639. * @private
  1640. * @name reverse
  1641. * @memberOf LazyWrapper
  1642. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1643. */
  1644. function lazyReverse() {
  1645. if (this.__filtered__) {
  1646. var result = new LazyWrapper(this);
  1647. result.__dir__ = -1;
  1648. result.__filtered__ = true;
  1649. } else {
  1650. result = this.clone();
  1651. result.__dir__ *= -1;
  1652. }
  1653. return result;
  1654. }
  1655. /**
  1656. * Extracts the unwrapped value from its lazy wrapper.
  1657. *
  1658. * @private
  1659. * @name value
  1660. * @memberOf LazyWrapper
  1661. * @returns {*} Returns the unwrapped value.
  1662. */
  1663. function lazyValue() {
  1664. var array = this.__wrapped__.value(),
  1665. dir = this.__dir__,
  1666. isArr = isArray(array),
  1667. isRight = dir < 0,
  1668. arrLength = isArr ? array.length : 0,
  1669. view = getView(0, arrLength, this.__views__),
  1670. start = view.start,
  1671. end = view.end,
  1672. length = end - start,
  1673. index = isRight ? end : (start - 1),
  1674. iteratees = this.__iteratees__,
  1675. iterLength = iteratees.length,
  1676. resIndex = 0,
  1677. takeCount = nativeMin(length, this.__takeCount__);
  1678. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1679. return baseWrapperValue(array, this.__actions__);
  1680. }
  1681. var result = [];
  1682. outer:
  1683. while (length-- && resIndex < takeCount) {
  1684. index += dir;
  1685. var iterIndex = -1,
  1686. value = array[index];
  1687. while (++iterIndex < iterLength) {
  1688. var data = iteratees[iterIndex],
  1689. iteratee = data.iteratee,
  1690. type = data.type,
  1691. computed = iteratee(value);
  1692. if (type == LAZY_MAP_FLAG) {
  1693. value = computed;
  1694. } else if (!computed) {
  1695. if (type == LAZY_FILTER_FLAG) {
  1696. continue outer;
  1697. } else {
  1698. break outer;
  1699. }
  1700. }
  1701. }
  1702. result[resIndex++] = value;
  1703. }
  1704. return result;
  1705. }
  1706. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1707. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1708. LazyWrapper.prototype.constructor = LazyWrapper;
  1709. /*------------------------------------------------------------------------*/
  1710. /**
  1711. * Creates a hash object.
  1712. *
  1713. * @private
  1714. * @constructor
  1715. * @param {Array} [entries] The key-value pairs to cache.
  1716. */
  1717. function Hash(entries) {
  1718. var index = -1,
  1719. length = entries == null ? 0 : entries.length;
  1720. this.clear();
  1721. while (++index < length) {
  1722. var entry = entries[index];
  1723. this.set(entry[0], entry[1]);
  1724. }
  1725. }
  1726. /**
  1727. * Removes all key-value entries from the hash.
  1728. *
  1729. * @private
  1730. * @name clear
  1731. * @memberOf Hash
  1732. */
  1733. function hashClear() {
  1734. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1735. this.size = 0;
  1736. }
  1737. /**
  1738. * Removes `key` and its value from the hash.
  1739. *
  1740. * @private
  1741. * @name delete
  1742. * @memberOf Hash
  1743. * @param {Object} hash The hash to modify.
  1744. * @param {string} key The key of the value to remove.
  1745. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1746. */
  1747. function hashDelete(key) {
  1748. var result = this.has(key) && delete this.__data__[key];
  1749. this.size -= result ? 1 : 0;
  1750. return result;
  1751. }
  1752. /**
  1753. * Gets the hash value for `key`.
  1754. *
  1755. * @private
  1756. * @name get
  1757. * @memberOf Hash
  1758. * @param {string} key The key of the value to get.
  1759. * @returns {*} Returns the entry value.
  1760. */
  1761. function hashGet(key) {
  1762. var data = this.__data__;
  1763. if (nativeCreate) {
  1764. var result = data[key];
  1765. return result === HASH_UNDEFINED ? undefined : result;
  1766. }
  1767. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1768. }
  1769. /**
  1770. * Checks if a hash value for `key` exists.
  1771. *
  1772. * @private
  1773. * @name has
  1774. * @memberOf Hash
  1775. * @param {string} key The key of the entry to check.
  1776. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1777. */
  1778. function hashHas(key) {
  1779. var data = this.__data__;
  1780. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1781. }
  1782. /**
  1783. * Sets the hash `key` to `value`.
  1784. *
  1785. * @private
  1786. * @name set
  1787. * @memberOf Hash
  1788. * @param {string} key The key of the value to set.
  1789. * @param {*} value The value to set.
  1790. * @returns {Object} Returns the hash instance.
  1791. */
  1792. function hashSet(key, value) {
  1793. var data = this.__data__;
  1794. this.size += this.has(key) ? 0 : 1;
  1795. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1796. return this;
  1797. }
  1798. // Add methods to `Hash`.
  1799. Hash.prototype.clear = hashClear;
  1800. Hash.prototype['delete'] = hashDelete;
  1801. Hash.prototype.get = hashGet;
  1802. Hash.prototype.has = hashHas;
  1803. Hash.prototype.set = hashSet;
  1804. /*------------------------------------------------------------------------*/
  1805. /**
  1806. * Creates an list cache object.
  1807. *
  1808. * @private
  1809. * @constructor
  1810. * @param {Array} [entries] The key-value pairs to cache.
  1811. */
  1812. function ListCache(entries) {
  1813. var index = -1,
  1814. length = entries == null ? 0 : entries.length;
  1815. this.clear();
  1816. while (++index < length) {
  1817. var entry = entries[index];
  1818. this.set(entry[0], entry[1]);
  1819. }
  1820. }
  1821. /**
  1822. * Removes all key-value entries from the list cache.
  1823. *
  1824. * @private
  1825. * @name clear
  1826. * @memberOf ListCache
  1827. */
  1828. function listCacheClear() {
  1829. this.__data__ = [];
  1830. this.size = 0;
  1831. }
  1832. /**
  1833. * Removes `key` and its value from the list cache.
  1834. *
  1835. * @private
  1836. * @name delete
  1837. * @memberOf ListCache
  1838. * @param {string} key The key of the value to remove.
  1839. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1840. */
  1841. function listCacheDelete(key) {
  1842. var data = this.__data__,
  1843. index = assocIndexOf(data, key);
  1844. if (index < 0) {
  1845. return false;
  1846. }
  1847. var lastIndex = data.length - 1;
  1848. if (index == lastIndex) {
  1849. data.pop();
  1850. } else {
  1851. splice.call(data, index, 1);
  1852. }
  1853. --this.size;
  1854. return true;
  1855. }
  1856. /**
  1857. * Gets the list cache value for `key`.
  1858. *
  1859. * @private
  1860. * @name get
  1861. * @memberOf ListCache
  1862. * @param {string} key The key of the value to get.
  1863. * @returns {*} Returns the entry value.
  1864. */
  1865. function listCacheGet(key) {
  1866. var data = this.__data__,
  1867. index = assocIndexOf(data, key);
  1868. return index < 0 ? undefined : data[index][1];
  1869. }
  1870. /**
  1871. * Checks if a list cache value for `key` exists.
  1872. *
  1873. * @private
  1874. * @name has
  1875. * @memberOf ListCache
  1876. * @param {string} key The key of the entry to check.
  1877. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1878. */
  1879. function listCacheHas(key) {
  1880. return assocIndexOf(this.__data__, key) > -1;
  1881. }
  1882. /**
  1883. * Sets the list cache `key` to `value`.
  1884. *
  1885. * @private
  1886. * @name set
  1887. * @memberOf ListCache
  1888. * @param {string} key The key of the value to set.
  1889. * @param {*} value The value to set.
  1890. * @returns {Object} Returns the list cache instance.
  1891. */
  1892. function listCacheSet(key, value) {
  1893. var data = this.__data__,
  1894. index = assocIndexOf(data, key);
  1895. if (index < 0) {
  1896. ++this.size;
  1897. data.push([key, value]);
  1898. } else {
  1899. data[index][1] = value;
  1900. }
  1901. return this;
  1902. }
  1903. // Add methods to `ListCache`.
  1904. ListCache.prototype.clear = listCacheClear;
  1905. ListCache.prototype['delete'] = listCacheDelete;
  1906. ListCache.prototype.get = listCacheGet;
  1907. ListCache.prototype.has = listCacheHas;
  1908. ListCache.prototype.set = listCacheSet;
  1909. /*------------------------------------------------------------------------*/
  1910. /**
  1911. * Creates a map cache object to store key-value pairs.
  1912. *
  1913. * @private
  1914. * @constructor
  1915. * @param {Array} [entries] The key-value pairs to cache.
  1916. */
  1917. function MapCache(entries) {
  1918. var index = -1,
  1919. length = entries == null ? 0 : entries.length;
  1920. this.clear();
  1921. while (++index < length) {
  1922. var entry = entries[index];
  1923. this.set(entry[0], entry[1]);
  1924. }
  1925. }
  1926. /**
  1927. * Removes all key-value entries from the map.
  1928. *
  1929. * @private
  1930. * @name clear
  1931. * @memberOf MapCache
  1932. */
  1933. function mapCacheClear() {
  1934. this.size = 0;
  1935. this.__data__ = {
  1936. 'hash': new Hash,
  1937. 'map': new (Map || ListCache),
  1938. 'string': new Hash
  1939. };
  1940. }
  1941. /**
  1942. * Removes `key` and its value from the map.
  1943. *
  1944. * @private
  1945. * @name delete
  1946. * @memberOf MapCache
  1947. * @param {string} key The key of the value to remove.
  1948. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1949. */
  1950. function mapCacheDelete(key) {
  1951. var result = getMapData(this, key)['delete'](key);
  1952. this.size -= result ? 1 : 0;
  1953. return result;
  1954. }
  1955. /**
  1956. * Gets the map value for `key`.
  1957. *
  1958. * @private
  1959. * @name get
  1960. * @memberOf MapCache
  1961. * @param {string} key The key of the value to get.
  1962. * @returns {*} Returns the entry value.
  1963. */
  1964. function mapCacheGet(key) {
  1965. return getMapData(this, key).get(key);
  1966. }
  1967. /**
  1968. * Checks if a map value for `key` exists.
  1969. *
  1970. * @private
  1971. * @name has
  1972. * @memberOf MapCache
  1973. * @param {string} key The key of the entry to check.
  1974. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1975. */
  1976. function mapCacheHas(key) {
  1977. return getMapData(this, key).has(key);
  1978. }
  1979. /**
  1980. * Sets the map `key` to `value`.
  1981. *
  1982. * @private
  1983. * @name set
  1984. * @memberOf MapCache
  1985. * @param {string} key The key of the value to set.
  1986. * @param {*} value The value to set.
  1987. * @returns {Object} Returns the map cache instance.
  1988. */
  1989. function mapCacheSet(key, value) {
  1990. var data = getMapData(this, key),
  1991. size = data.size;
  1992. data.set(key, value);
  1993. this.size += data.size == size ? 0 : 1;
  1994. return this;
  1995. }
  1996. // Add methods to `MapCache`.
  1997. MapCache.prototype.clear = mapCacheClear;
  1998. MapCache.prototype['delete'] = mapCacheDelete;
  1999. MapCache.prototype.get = mapCacheGet;
  2000. MapCache.prototype.has = mapCacheHas;
  2001. MapCache.prototype.set = mapCacheSet;
  2002. /*------------------------------------------------------------------------*/
  2003. /**
  2004. *
  2005. * Creates an array cache object to store unique values.
  2006. *
  2007. * @private
  2008. * @constructor
  2009. * @param {Array} [values] The values to cache.
  2010. */
  2011. function SetCache(values) {
  2012. var index = -1,
  2013. length = values == null ? 0 : values.length;
  2014. this.__data__ = new MapCache;
  2015. while (++index < length) {
  2016. this.add(values[index]);
  2017. }
  2018. }
  2019. /**
  2020. * Adds `value` to the array cache.
  2021. *
  2022. * @private
  2023. * @name add
  2024. * @memberOf SetCache
  2025. * @alias push
  2026. * @param {*} value The value to cache.
  2027. * @returns {Object} Returns the cache instance.
  2028. */
  2029. function setCacheAdd(value) {
  2030. this.__data__.set(value, HASH_UNDEFINED);
  2031. return this;
  2032. }
  2033. /**
  2034. * Checks if `value` is in the array cache.
  2035. *
  2036. * @private
  2037. * @name has
  2038. * @memberOf SetCache
  2039. * @param {*} value The value to search for.
  2040. * @returns {number} Returns `true` if `value` is found, else `false`.
  2041. */
  2042. function setCacheHas(value) {
  2043. return this.__data__.has(value);
  2044. }
  2045. // Add methods to `SetCache`.
  2046. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2047. SetCache.prototype.has = setCacheHas;
  2048. /*------------------------------------------------------------------------*/
  2049. /**
  2050. * Creates a stack cache object to store key-value pairs.
  2051. *
  2052. * @private
  2053. * @constructor
  2054. * @param {Array} [entries] The key-value pairs to cache.
  2055. */
  2056. function Stack(entries) {
  2057. var data = this.__data__ = new ListCache(entries);
  2058. this.size = data.size;
  2059. }
  2060. /**
  2061. * Removes all key-value entries from the stack.
  2062. *
  2063. * @private
  2064. * @name clear
  2065. * @memberOf Stack
  2066. */
  2067. function stackClear() {
  2068. this.__data__ = new ListCache;
  2069. this.size = 0;
  2070. }
  2071. /**
  2072. * Removes `key` and its value from the stack.
  2073. *
  2074. * @private
  2075. * @name delete
  2076. * @memberOf Stack
  2077. * @param {string} key The key of the value to remove.
  2078. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2079. */
  2080. function stackDelete(key) {
  2081. var data = this.__data__,
  2082. result = data['delete'](key);
  2083. this.size = data.size;
  2084. return result;
  2085. }
  2086. /**
  2087. * Gets the stack value for `key`.
  2088. *
  2089. * @private
  2090. * @name get
  2091. * @memberOf Stack
  2092. * @param {string} key The key of the value to get.
  2093. * @returns {*} Returns the entry value.
  2094. */
  2095. function stackGet(key) {
  2096. return this.__data__.get(key);
  2097. }
  2098. /**
  2099. * Checks if a stack value for `key` exists.
  2100. *
  2101. * @private
  2102. * @name has
  2103. * @memberOf Stack
  2104. * @param {string} key The key of the entry to check.
  2105. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2106. */
  2107. function stackHas(key) {
  2108. return this.__data__.has(key);
  2109. }
  2110. /**
  2111. * Sets the stack `key` to `value`.
  2112. *
  2113. * @private
  2114. * @name set
  2115. * @memberOf Stack
  2116. * @param {string} key The key of the value to set.
  2117. * @param {*} value The value to set.
  2118. * @returns {Object} Returns the stack cache instance.
  2119. */
  2120. function stackSet(key, value) {
  2121. var data = this.__data__;
  2122. if (data instanceof ListCache) {
  2123. var pairs = data.__data__;
  2124. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2125. pairs.push([key, value]);
  2126. this.size = ++data.size;
  2127. return this;
  2128. }
  2129. data = this.__data__ = new MapCache(pairs);
  2130. }
  2131. data.set(key, value);
  2132. this.size = data.size;
  2133. return this;
  2134. }
  2135. // Add methods to `Stack`.
  2136. Stack.prototype.clear = stackClear;
  2137. Stack.prototype['delete'] = stackDelete;
  2138. Stack.prototype.get = stackGet;
  2139. Stack.prototype.has = stackHas;
  2140. Stack.prototype.set = stackSet;
  2141. /*------------------------------------------------------------------------*/
  2142. /**
  2143. * Creates an array of the enumerable property names of the array-like `value`.
  2144. *
  2145. * @private
  2146. * @param {*} value The value to query.
  2147. * @param {boolean} inherited Specify returning inherited property names.
  2148. * @returns {Array} Returns the array of property names.
  2149. */
  2150. function arrayLikeKeys(value, inherited) {
  2151. var isArr = isArray(value),
  2152. isArg = !isArr && isArguments(value),
  2153. isBuff = !isArr && !isArg && isBuffer(value),
  2154. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2155. skipIndexes = isArr || isArg || isBuff || isType,
  2156. result = skipIndexes ? baseTimes(value.length, String) : [],
  2157. length = result.length;
  2158. for (var key in value) {
  2159. if ((inherited || hasOwnProperty.call(value, key)) &&
  2160. !(skipIndexes && (
  2161. // Safari 9 has enumerable `arguments.length` in strict mode.
  2162. key == 'length' ||
  2163. // Node.js 0.10 has enumerable non-index properties on buffers.
  2164. (isBuff && (key == 'offset' || key == 'parent')) ||
  2165. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2166. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2167. // Skip index properties.
  2168. isIndex(key, length)
  2169. ))) {
  2170. result.push(key);
  2171. }
  2172. }
  2173. return result;
  2174. }
  2175. /**
  2176. * A specialized version of `_.sample` for arrays.
  2177. *
  2178. * @private
  2179. * @param {Array} array The array to sample.
  2180. * @returns {*} Returns the random element.
  2181. */
  2182. function arraySample(array) {
  2183. var length = array.length;
  2184. return length ? array[baseRandom(0, length - 1)] : undefined;
  2185. }
  2186. /**
  2187. * A specialized version of `_.sampleSize` for arrays.
  2188. *
  2189. * @private
  2190. * @param {Array} array The array to sample.
  2191. * @param {number} n The number of elements to sample.
  2192. * @returns {Array} Returns the random elements.
  2193. */
  2194. function arraySampleSize(array, n) {
  2195. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2196. }
  2197. /**
  2198. * A specialized version of `_.shuffle` for arrays.
  2199. *
  2200. * @private
  2201. * @param {Array} array The array to shuffle.
  2202. * @returns {Array} Returns the new shuffled array.
  2203. */
  2204. function arrayShuffle(array) {
  2205. return shuffleSelf(copyArray(array));
  2206. }
  2207. /**
  2208. * This function is like `assignValue` except that it doesn't assign
  2209. * `undefined` values.
  2210. *
  2211. * @private
  2212. * @param {Object} object The object to modify.
  2213. * @param {string} key The key of the property to assign.
  2214. * @param {*} value The value to assign.
  2215. */
  2216. function assignMergeValue(object, key, value) {
  2217. if ((value !== undefined && !eq(object[key], value)) ||
  2218. (value === undefined && !(key in object))) {
  2219. baseAssignValue(object, key, value);
  2220. }
  2221. }
  2222. /**
  2223. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2224. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2225. * for equality comparisons.
  2226. *
  2227. * @private
  2228. * @param {Object} object The object to modify.
  2229. * @param {string} key The key of the property to assign.
  2230. * @param {*} value The value to assign.
  2231. */
  2232. function assignValue(object, key, value) {
  2233. var objValue = object[key];
  2234. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2235. (value === undefined && !(key in object))) {
  2236. baseAssignValue(object, key, value);
  2237. }
  2238. }
  2239. /**
  2240. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2241. *
  2242. * @private
  2243. * @param {Array} array The array to inspect.
  2244. * @param {*} key The key to search for.
  2245. * @returns {number} Returns the index of the matched value, else `-1`.
  2246. */
  2247. function assocIndexOf(array, key) {
  2248. var length = array.length;
  2249. while (length--) {
  2250. if (eq(array[length][0], key)) {
  2251. return length;
  2252. }
  2253. }
  2254. return -1;
  2255. }
  2256. /**
  2257. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2258. * by `iteratee` and values set by `setter`.
  2259. *
  2260. * @private
  2261. * @param {Array|Object} collection The collection to iterate over.
  2262. * @param {Function} setter The function to set `accumulator` values.
  2263. * @param {Function} iteratee The iteratee to transform keys.
  2264. * @param {Object} accumulator The initial aggregated object.
  2265. * @returns {Function} Returns `accumulator`.
  2266. */
  2267. function baseAggregator(collection, setter, iteratee, accumulator) {
  2268. baseEach(collection, function(value, key, collection) {
  2269. setter(accumulator, value, iteratee(value), collection);
  2270. });
  2271. return accumulator;
  2272. }
  2273. /**
  2274. * The base implementation of `_.assign` without support for multiple sources
  2275. * or `customizer` functions.
  2276. *
  2277. * @private
  2278. * @param {Object} object The destination object.
  2279. * @param {Object} source The source object.
  2280. * @returns {Object} Returns `object`.
  2281. */
  2282. function baseAssign(object, source) {
  2283. return object && copyObject(source, keys(source), object);
  2284. }
  2285. /**
  2286. * The base implementation of `_.assignIn` without support for multiple sources
  2287. * or `customizer` functions.
  2288. *
  2289. * @private
  2290. * @param {Object} object The destination object.
  2291. * @param {Object} source The source object.
  2292. * @returns {Object} Returns `object`.
  2293. */
  2294. function baseAssignIn(object, source) {
  2295. return object && copyObject(source, keysIn(source), object);
  2296. }
  2297. /**
  2298. * The base implementation of `assignValue` and `assignMergeValue` without
  2299. * value checks.
  2300. *
  2301. * @private
  2302. * @param {Object} object The object to modify.
  2303. * @param {string} key The key of the property to assign.
  2304. * @param {*} value The value to assign.
  2305. */
  2306. function baseAssignValue(object, key, value) {
  2307. if (key == '__proto__' && defineProperty) {
  2308. defineProperty(object, key, {
  2309. 'configurable': true,
  2310. 'enumerable': true,
  2311. 'value': value,
  2312. 'writable': true
  2313. });
  2314. } else {
  2315. object[key] = value;
  2316. }
  2317. }
  2318. /**
  2319. * The base implementation of `_.at` without support for individual paths.
  2320. *
  2321. * @private
  2322. * @param {Object} object The object to iterate over.
  2323. * @param {string[]} paths The property paths to pick.
  2324. * @returns {Array} Returns the picked elements.
  2325. */
  2326. function baseAt(object, paths) {
  2327. var index = -1,
  2328. length = paths.length,
  2329. result = Array(length),
  2330. skip = object == null;
  2331. while (++index < length) {
  2332. result[index] = skip ? undefined : get(object, paths[index]);
  2333. }
  2334. return result;
  2335. }
  2336. /**
  2337. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2338. *
  2339. * @private
  2340. * @param {number} number The number to clamp.
  2341. * @param {number} [lower] The lower bound.
  2342. * @param {number} upper The upper bound.
  2343. * @returns {number} Returns the clamped number.
  2344. */
  2345. function baseClamp(number, lower, upper) {
  2346. if (number === number) {
  2347. if (upper !== undefined) {
  2348. number = number <= upper ? number : upper;
  2349. }
  2350. if (lower !== undefined) {
  2351. number = number >= lower ? number : lower;
  2352. }
  2353. }
  2354. return number;
  2355. }
  2356. /**
  2357. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2358. * traversed objects.
  2359. *
  2360. * @private
  2361. * @param {*} value The value to clone.
  2362. * @param {boolean} bitmask The bitmask flags.
  2363. * 1 - Deep clone
  2364. * 2 - Flatten inherited properties
  2365. * 4 - Clone symbols
  2366. * @param {Function} [customizer] The function to customize cloning.
  2367. * @param {string} [key] The key of `value`.
  2368. * @param {Object} [object] The parent object of `value`.
  2369. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2370. * @returns {*} Returns the cloned value.
  2371. */
  2372. function baseClone(value, bitmask, customizer, key, object, stack) {
  2373. var result,
  2374. isDeep = bitmask & CLONE_DEEP_FLAG,
  2375. isFlat = bitmask & CLONE_FLAT_FLAG,
  2376. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2377. if (customizer) {
  2378. result = object ? customizer(value, key, object, stack) : customizer(value);
  2379. }
  2380. if (result !== undefined) {
  2381. return result;
  2382. }
  2383. if (!isObject(value)) {
  2384. return value;
  2385. }
  2386. var isArr = isArray(value);
  2387. if (isArr) {
  2388. result = initCloneArray(value);
  2389. if (!isDeep) {
  2390. return copyArray(value, result);
  2391. }
  2392. } else {
  2393. var tag = getTag(value),
  2394. isFunc = tag == funcTag || tag == genTag;
  2395. if (isBuffer(value)) {
  2396. return cloneBuffer(value, isDeep);
  2397. }
  2398. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2399. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2400. if (!isDeep) {
  2401. return isFlat
  2402. ? copySymbolsIn(value, baseAssignIn(result, value))
  2403. : copySymbols(value, baseAssign(result, value));
  2404. }
  2405. } else {
  2406. if (!cloneableTags[tag]) {
  2407. return object ? value : {};
  2408. }
  2409. result = initCloneByTag(value, tag, isDeep);
  2410. }
  2411. }
  2412. // Check for circular references and return its corresponding clone.
  2413. stack || (stack = new Stack);
  2414. var stacked = stack.get(value);
  2415. if (stacked) {
  2416. return stacked;
  2417. }
  2418. stack.set(value, result);
  2419. if (isSet(value)) {
  2420. value.forEach(function(subValue) {
  2421. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2422. });
  2423. } else if (isMap(value)) {
  2424. value.forEach(function(subValue, key) {
  2425. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2426. });
  2427. }
  2428. var keysFunc = isFull
  2429. ? (isFlat ? getAllKeysIn : getAllKeys)
  2430. : (isFlat ? keysIn : keys);
  2431. var props = isArr ? undefined : keysFunc(value);
  2432. arrayEach(props || value, function(subValue, key) {
  2433. if (props) {
  2434. key = subValue;
  2435. subValue = value[key];
  2436. }
  2437. // Recursively populate clone (susceptible to call stack limits).
  2438. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2439. });
  2440. return result;
  2441. }
  2442. /**
  2443. * The base implementation of `_.conforms` which doesn't clone `source`.
  2444. *
  2445. * @private
  2446. * @param {Object} source The object of property predicates to conform to.
  2447. * @returns {Function} Returns the new spec function.
  2448. */
  2449. function baseConforms(source) {
  2450. var props = keys(source);
  2451. return function(object) {
  2452. return baseConformsTo(object, source, props);
  2453. };
  2454. }
  2455. /**
  2456. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2457. *
  2458. * @private
  2459. * @param {Object} object The object to inspect.
  2460. * @param {Object} source The object of property predicates to conform to.
  2461. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2462. */
  2463. function baseConformsTo(object, source, props) {
  2464. var length = props.length;
  2465. if (object == null) {
  2466. return !length;
  2467. }
  2468. object = Object(object);
  2469. while (length--) {
  2470. var key = props[length],
  2471. predicate = source[key],
  2472. value = object[key];
  2473. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2474. return false;
  2475. }
  2476. }
  2477. return true;
  2478. }
  2479. /**
  2480. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2481. * to provide to `func`.
  2482. *
  2483. * @private
  2484. * @param {Function} func The function to delay.
  2485. * @param {number} wait The number of milliseconds to delay invocation.
  2486. * @param {Array} args The arguments to provide to `func`.
  2487. * @returns {number|Object} Returns the timer id or timeout object.
  2488. */
  2489. function baseDelay(func, wait, args) {
  2490. if (typeof func != 'function') {
  2491. throw new TypeError(FUNC_ERROR_TEXT);
  2492. }
  2493. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2494. }
  2495. /**
  2496. * The base implementation of methods like `_.difference` without support
  2497. * for excluding multiple arrays or iteratee shorthands.
  2498. *
  2499. * @private
  2500. * @param {Array} array The array to inspect.
  2501. * @param {Array} values The values to exclude.
  2502. * @param {Function} [iteratee] The iteratee invoked per element.
  2503. * @param {Function} [comparator] The comparator invoked per element.
  2504. * @returns {Array} Returns the new array of filtered values.
  2505. */
  2506. function baseDifference(array, values, iteratee, comparator) {
  2507. var index = -1,
  2508. includes = arrayIncludes,
  2509. isCommon = true,
  2510. length = array.length,
  2511. result = [],
  2512. valuesLength = values.length;
  2513. if (!length) {
  2514. return result;
  2515. }
  2516. if (iteratee) {
  2517. values = arrayMap(values, baseUnary(iteratee));
  2518. }
  2519. if (comparator) {
  2520. includes = arrayIncludesWith;
  2521. isCommon = false;
  2522. }
  2523. else if (values.length >= LARGE_ARRAY_SIZE) {
  2524. includes = cacheHas;
  2525. isCommon = false;
  2526. values = new SetCache(values);
  2527. }
  2528. outer:
  2529. while (++index < length) {
  2530. var value = array[index],
  2531. computed = iteratee == null ? value : iteratee(value);
  2532. value = (comparator || value !== 0) ? value : 0;
  2533. if (isCommon && computed === computed) {
  2534. var valuesIndex = valuesLength;
  2535. while (valuesIndex--) {
  2536. if (values[valuesIndex] === computed) {
  2537. continue outer;
  2538. }
  2539. }
  2540. result.push(value);
  2541. }
  2542. else if (!includes(values, computed, comparator)) {
  2543. result.push(value);
  2544. }
  2545. }
  2546. return result;
  2547. }
  2548. /**
  2549. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2550. *
  2551. * @private
  2552. * @param {Array|Object} collection The collection to iterate over.
  2553. * @param {Function} iteratee The function invoked per iteration.
  2554. * @returns {Array|Object} Returns `collection`.
  2555. */
  2556. var baseEach = createBaseEach(baseForOwn);
  2557. /**
  2558. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2559. *
  2560. * @private
  2561. * @param {Array|Object} collection The collection to iterate over.
  2562. * @param {Function} iteratee The function invoked per iteration.
  2563. * @returns {Array|Object} Returns `collection`.
  2564. */
  2565. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2566. /**
  2567. * The base implementation of `_.every` without support for iteratee shorthands.
  2568. *
  2569. * @private
  2570. * @param {Array|Object} collection The collection to iterate over.
  2571. * @param {Function} predicate The function invoked per iteration.
  2572. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2573. * else `false`
  2574. */
  2575. function baseEvery(collection, predicate) {
  2576. var result = true;
  2577. baseEach(collection, function(value, index, collection) {
  2578. result = !!predicate(value, index, collection);
  2579. return result;
  2580. });
  2581. return result;
  2582. }
  2583. /**
  2584. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2585. * `comparator` to determine the extremum value.
  2586. *
  2587. * @private
  2588. * @param {Array} array The array to iterate over.
  2589. * @param {Function} iteratee The iteratee invoked per iteration.
  2590. * @param {Function} comparator The comparator used to compare values.
  2591. * @returns {*} Returns the extremum value.
  2592. */
  2593. function baseExtremum(array, iteratee, comparator) {
  2594. var index = -1,
  2595. length = array.length;
  2596. while (++index < length) {
  2597. var value = array[index],
  2598. current = iteratee(value);
  2599. if (current != null && (computed === undefined
  2600. ? (current === current && !isSymbol(current))
  2601. : comparator(current, computed)
  2602. )) {
  2603. var computed = current,
  2604. result = value;
  2605. }
  2606. }
  2607. return result;
  2608. }
  2609. /**
  2610. * The base implementation of `_.fill` without an iteratee call guard.
  2611. *
  2612. * @private
  2613. * @param {Array} array The array to fill.
  2614. * @param {*} value The value to fill `array` with.
  2615. * @param {number} [start=0] The start position.
  2616. * @param {number} [end=array.length] The end position.
  2617. * @returns {Array} Returns `array`.
  2618. */
  2619. function baseFill(array, value, start, end) {
  2620. var length = array.length;
  2621. start = toInteger(start);
  2622. if (start < 0) {
  2623. start = -start > length ? 0 : (length + start);
  2624. }
  2625. end = (end === undefined || end > length) ? length : toInteger(end);
  2626. if (end < 0) {
  2627. end += length;
  2628. }
  2629. end = start > end ? 0 : toLength(end);
  2630. while (start < end) {
  2631. array[start++] = value;
  2632. }
  2633. return array;
  2634. }
  2635. /**
  2636. * The base implementation of `_.filter` without support for iteratee shorthands.
  2637. *
  2638. * @private
  2639. * @param {Array|Object} collection The collection to iterate over.
  2640. * @param {Function} predicate The function invoked per iteration.
  2641. * @returns {Array} Returns the new filtered array.
  2642. */
  2643. function baseFilter(collection, predicate) {
  2644. var result = [];
  2645. baseEach(collection, function(value, index, collection) {
  2646. if (predicate(value, index, collection)) {
  2647. result.push(value);
  2648. }
  2649. });
  2650. return result;
  2651. }
  2652. /**
  2653. * The base implementation of `_.flatten` with support for restricting flattening.
  2654. *
  2655. * @private
  2656. * @param {Array} array The array to flatten.
  2657. * @param {number} depth The maximum recursion depth.
  2658. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2659. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2660. * @param {Array} [result=[]] The initial result value.
  2661. * @returns {Array} Returns the new flattened array.
  2662. */
  2663. function baseFlatten(array, depth, predicate, isStrict, result) {
  2664. var index = -1,
  2665. length = array.length;
  2666. predicate || (predicate = isFlattenable);
  2667. result || (result = []);
  2668. while (++index < length) {
  2669. var value = array[index];
  2670. if (depth > 0 && predicate(value)) {
  2671. if (depth > 1) {
  2672. // Recursively flatten arrays (susceptible to call stack limits).
  2673. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2674. } else {
  2675. arrayPush(result, value);
  2676. }
  2677. } else if (!isStrict) {
  2678. result[result.length] = value;
  2679. }
  2680. }
  2681. return result;
  2682. }
  2683. /**
  2684. * The base implementation of `baseForOwn` which iterates over `object`
  2685. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2686. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2687. *
  2688. * @private
  2689. * @param {Object} object The object to iterate over.
  2690. * @param {Function} iteratee The function invoked per iteration.
  2691. * @param {Function} keysFunc The function to get the keys of `object`.
  2692. * @returns {Object} Returns `object`.
  2693. */
  2694. var baseFor = createBaseFor();
  2695. /**
  2696. * This function is like `baseFor` except that it iterates over properties
  2697. * in the opposite order.
  2698. *
  2699. * @private
  2700. * @param {Object} object The object to iterate over.
  2701. * @param {Function} iteratee The function invoked per iteration.
  2702. * @param {Function} keysFunc The function to get the keys of `object`.
  2703. * @returns {Object} Returns `object`.
  2704. */
  2705. var baseForRight = createBaseFor(true);
  2706. /**
  2707. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2708. *
  2709. * @private
  2710. * @param {Object} object The object to iterate over.
  2711. * @param {Function} iteratee The function invoked per iteration.
  2712. * @returns {Object} Returns `object`.
  2713. */
  2714. function baseForOwn(object, iteratee) {
  2715. return object && baseFor(object, iteratee, keys);
  2716. }
  2717. /**
  2718. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2719. *
  2720. * @private
  2721. * @param {Object} object The object to iterate over.
  2722. * @param {Function} iteratee The function invoked per iteration.
  2723. * @returns {Object} Returns `object`.
  2724. */
  2725. function baseForOwnRight(object, iteratee) {
  2726. return object && baseForRight(object, iteratee, keys);
  2727. }
  2728. /**
  2729. * The base implementation of `_.functions` which creates an array of
  2730. * `object` function property names filtered from `props`.
  2731. *
  2732. * @private
  2733. * @param {Object} object The object to inspect.
  2734. * @param {Array} props The property names to filter.
  2735. * @returns {Array} Returns the function names.
  2736. */
  2737. function baseFunctions(object, props) {
  2738. return arrayFilter(props, function(key) {
  2739. return isFunction(object[key]);
  2740. });
  2741. }
  2742. /**
  2743. * The base implementation of `_.get` without support for default values.
  2744. *
  2745. * @private
  2746. * @param {Object} object The object to query.
  2747. * @param {Array|string} path The path of the property to get.
  2748. * @returns {*} Returns the resolved value.
  2749. */
  2750. function baseGet(object, path) {
  2751. path = castPath(path, object);
  2752. var index = 0,
  2753. length = path.length;
  2754. while (object != null && index < length) {
  2755. object = object[toKey(path[index++])];
  2756. }
  2757. return (index && index == length) ? object : undefined;
  2758. }
  2759. /**
  2760. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2761. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2762. * symbols of `object`.
  2763. *
  2764. * @private
  2765. * @param {Object} object The object to query.
  2766. * @param {Function} keysFunc The function to get the keys of `object`.
  2767. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2768. * @returns {Array} Returns the array of property names and symbols.
  2769. */
  2770. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2771. var result = keysFunc(object);
  2772. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2773. }
  2774. /**
  2775. * The base implementation of `getTag` without fallbacks for buggy environments.
  2776. *
  2777. * @private
  2778. * @param {*} value The value to query.
  2779. * @returns {string} Returns the `toStringTag`.
  2780. */
  2781. function baseGetTag(value) {
  2782. if (value == null) {
  2783. return value === undefined ? undefinedTag : nullTag;
  2784. }
  2785. return (symToStringTag && symToStringTag in Object(value))
  2786. ? getRawTag(value)
  2787. : objectToString(value);
  2788. }
  2789. /**
  2790. * The base implementation of `_.gt` which doesn't coerce arguments.
  2791. *
  2792. * @private
  2793. * @param {*} value The value to compare.
  2794. * @param {*} other The other value to compare.
  2795. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2796. * else `false`.
  2797. */
  2798. function baseGt(value, other) {
  2799. return value > other;
  2800. }
  2801. /**
  2802. * The base implementation of `_.has` without support for deep paths.
  2803. *
  2804. * @private
  2805. * @param {Object} [object] The object to query.
  2806. * @param {Array|string} key The key to check.
  2807. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2808. */
  2809. function baseHas(object, key) {
  2810. return object != null && hasOwnProperty.call(object, key);
  2811. }
  2812. /**
  2813. * The base implementation of `_.hasIn` without support for deep paths.
  2814. *
  2815. * @private
  2816. * @param {Object} [object] The object to query.
  2817. * @param {Array|string} key The key to check.
  2818. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2819. */
  2820. function baseHasIn(object, key) {
  2821. return object != null && key in Object(object);
  2822. }
  2823. /**
  2824. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2825. *
  2826. * @private
  2827. * @param {number} number The number to check.
  2828. * @param {number} start The start of the range.
  2829. * @param {number} end The end of the range.
  2830. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2831. */
  2832. function baseInRange(number, start, end) {
  2833. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2834. }
  2835. /**
  2836. * The base implementation of methods like `_.intersection`, without support
  2837. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2838. *
  2839. * @private
  2840. * @param {Array} arrays The arrays to inspect.
  2841. * @param {Function} [iteratee] The iteratee invoked per element.
  2842. * @param {Function} [comparator] The comparator invoked per element.
  2843. * @returns {Array} Returns the new array of shared values.
  2844. */
  2845. function baseIntersection(arrays, iteratee, comparator) {
  2846. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2847. length = arrays[0].length,
  2848. othLength = arrays.length,
  2849. othIndex = othLength,
  2850. caches = Array(othLength),
  2851. maxLength = Infinity,
  2852. result = [];
  2853. while (othIndex--) {
  2854. var array = arrays[othIndex];
  2855. if (othIndex && iteratee) {
  2856. array = arrayMap(array, baseUnary(iteratee));
  2857. }
  2858. maxLength = nativeMin(array.length, maxLength);
  2859. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2860. ? new SetCache(othIndex && array)
  2861. : undefined;
  2862. }
  2863. array = arrays[0];
  2864. var index = -1,
  2865. seen = caches[0];
  2866. outer:
  2867. while (++index < length && result.length < maxLength) {
  2868. var value = array[index],
  2869. computed = iteratee ? iteratee(value) : value;
  2870. value = (comparator || value !== 0) ? value : 0;
  2871. if (!(seen
  2872. ? cacheHas(seen, computed)
  2873. : includes(result, computed, comparator)
  2874. )) {
  2875. othIndex = othLength;
  2876. while (--othIndex) {
  2877. var cache = caches[othIndex];
  2878. if (!(cache
  2879. ? cacheHas(cache, computed)
  2880. : includes(arrays[othIndex], computed, comparator))
  2881. ) {
  2882. continue outer;
  2883. }
  2884. }
  2885. if (seen) {
  2886. seen.push(computed);
  2887. }
  2888. result.push(value);
  2889. }
  2890. }
  2891. return result;
  2892. }
  2893. /**
  2894. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2895. * `object` with values transformed by `iteratee` and set by `setter`.
  2896. *
  2897. * @private
  2898. * @param {Object} object The object to iterate over.
  2899. * @param {Function} setter The function to set `accumulator` values.
  2900. * @param {Function} iteratee The iteratee to transform values.
  2901. * @param {Object} accumulator The initial inverted object.
  2902. * @returns {Function} Returns `accumulator`.
  2903. */
  2904. function baseInverter(object, setter, iteratee, accumulator) {
  2905. baseForOwn(object, function(value, key, object) {
  2906. setter(accumulator, iteratee(value), key, object);
  2907. });
  2908. return accumulator;
  2909. }
  2910. /**
  2911. * The base implementation of `_.invoke` without support for individual
  2912. * method arguments.
  2913. *
  2914. * @private
  2915. * @param {Object} object The object to query.
  2916. * @param {Array|string} path The path of the method to invoke.
  2917. * @param {Array} args The arguments to invoke the method with.
  2918. * @returns {*} Returns the result of the invoked method.
  2919. */
  2920. function baseInvoke(object, path, args) {
  2921. path = castPath(path, object);
  2922. object = parent(object, path);
  2923. var func = object == null ? object : object[toKey(last(path))];
  2924. return func == null ? undefined : apply(func, object, args);
  2925. }
  2926. /**
  2927. * The base implementation of `_.isArguments`.
  2928. *
  2929. * @private
  2930. * @param {*} value The value to check.
  2931. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2932. */
  2933. function baseIsArguments(value) {
  2934. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2935. }
  2936. /**
  2937. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2938. *
  2939. * @private
  2940. * @param {*} value The value to check.
  2941. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2942. */
  2943. function baseIsArrayBuffer(value) {
  2944. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2945. }
  2946. /**
  2947. * The base implementation of `_.isDate` without Node.js optimizations.
  2948. *
  2949. * @private
  2950. * @param {*} value The value to check.
  2951. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2952. */
  2953. function baseIsDate(value) {
  2954. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2955. }
  2956. /**
  2957. * The base implementation of `_.isEqual` which supports partial comparisons
  2958. * and tracks traversed objects.
  2959. *
  2960. * @private
  2961. * @param {*} value The value to compare.
  2962. * @param {*} other The other value to compare.
  2963. * @param {boolean} bitmask The bitmask flags.
  2964. * 1 - Unordered comparison
  2965. * 2 - Partial comparison
  2966. * @param {Function} [customizer] The function to customize comparisons.
  2967. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2968. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2969. */
  2970. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2971. if (value === other) {
  2972. return true;
  2973. }
  2974. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2975. return value !== value && other !== other;
  2976. }
  2977. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2978. }
  2979. /**
  2980. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2981. * deep comparisons and tracks traversed objects enabling objects with circular
  2982. * references to be compared.
  2983. *
  2984. * @private
  2985. * @param {Object} object The object to compare.
  2986. * @param {Object} other The other object to compare.
  2987. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2988. * @param {Function} customizer The function to customize comparisons.
  2989. * @param {Function} equalFunc The function to determine equivalents of values.
  2990. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2991. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2992. */
  2993. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2994. var objIsArr = isArray(object),
  2995. othIsArr = isArray(other),
  2996. objTag = objIsArr ? arrayTag : getTag(object),
  2997. othTag = othIsArr ? arrayTag : getTag(other);
  2998. objTag = objTag == argsTag ? objectTag : objTag;
  2999. othTag = othTag == argsTag ? objectTag : othTag;
  3000. var objIsObj = objTag == objectTag,
  3001. othIsObj = othTag == objectTag,
  3002. isSameTag = objTag == othTag;
  3003. if (isSameTag && isBuffer(object)) {
  3004. if (!isBuffer(other)) {
  3005. return false;
  3006. }
  3007. objIsArr = true;
  3008. objIsObj = false;
  3009. }
  3010. if (isSameTag && !objIsObj) {
  3011. stack || (stack = new Stack);
  3012. return (objIsArr || isTypedArray(object))
  3013. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3014. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3015. }
  3016. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3017. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3018. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3019. if (objIsWrapped || othIsWrapped) {
  3020. var objUnwrapped = objIsWrapped ? object.value() : object,
  3021. othUnwrapped = othIsWrapped ? other.value() : other;
  3022. stack || (stack = new Stack);
  3023. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3024. }
  3025. }
  3026. if (!isSameTag) {
  3027. return false;
  3028. }
  3029. stack || (stack = new Stack);
  3030. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3031. }
  3032. /**
  3033. * The base implementation of `_.isMap` without Node.js optimizations.
  3034. *
  3035. * @private
  3036. * @param {*} value The value to check.
  3037. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3038. */
  3039. function baseIsMap(value) {
  3040. return isObjectLike(value) && getTag(value) == mapTag;
  3041. }
  3042. /**
  3043. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3044. *
  3045. * @private
  3046. * @param {Object} object The object to inspect.
  3047. * @param {Object} source The object of property values to match.
  3048. * @param {Array} matchData The property names, values, and compare flags to match.
  3049. * @param {Function} [customizer] The function to customize comparisons.
  3050. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3051. */
  3052. function baseIsMatch(object, source, matchData, customizer) {
  3053. var index = matchData.length,
  3054. length = index,
  3055. noCustomizer = !customizer;
  3056. if (object == null) {
  3057. return !length;
  3058. }
  3059. object = Object(object);
  3060. while (index--) {
  3061. var data = matchData[index];
  3062. if ((noCustomizer && data[2])
  3063. ? data[1] !== object[data[0]]
  3064. : !(data[0] in object)
  3065. ) {
  3066. return false;
  3067. }
  3068. }
  3069. while (++index < length) {
  3070. data = matchData[index];
  3071. var key = data[0],
  3072. objValue = object[key],
  3073. srcValue = data[1];
  3074. if (noCustomizer && data[2]) {
  3075. if (objValue === undefined && !(key in object)) {
  3076. return false;
  3077. }
  3078. } else {
  3079. var stack = new Stack;
  3080. if (customizer) {
  3081. var result = customizer(objValue, srcValue, key, object, source, stack);
  3082. }
  3083. if (!(result === undefined
  3084. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3085. : result
  3086. )) {
  3087. return false;
  3088. }
  3089. }
  3090. }
  3091. return true;
  3092. }
  3093. /**
  3094. * The base implementation of `_.isNative` without bad shim checks.
  3095. *
  3096. * @private
  3097. * @param {*} value The value to check.
  3098. * @returns {boolean} Returns `true` if `value` is a native function,
  3099. * else `false`.
  3100. */
  3101. function baseIsNative(value) {
  3102. if (!isObject(value) || isMasked(value)) {
  3103. return false;
  3104. }
  3105. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3106. return pattern.test(toSource(value));
  3107. }
  3108. /**
  3109. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3110. *
  3111. * @private
  3112. * @param {*} value The value to check.
  3113. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3114. */
  3115. function baseIsRegExp(value) {
  3116. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3117. }
  3118. /**
  3119. * The base implementation of `_.isSet` without Node.js optimizations.
  3120. *
  3121. * @private
  3122. * @param {*} value The value to check.
  3123. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3124. */
  3125. function baseIsSet(value) {
  3126. return isObjectLike(value) && getTag(value) == setTag;
  3127. }
  3128. /**
  3129. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3130. *
  3131. * @private
  3132. * @param {*} value The value to check.
  3133. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3134. */
  3135. function baseIsTypedArray(value) {
  3136. return isObjectLike(value) &&
  3137. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3138. }
  3139. /**
  3140. * The base implementation of `_.iteratee`.
  3141. *
  3142. * @private
  3143. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3144. * @returns {Function} Returns the iteratee.
  3145. */
  3146. function baseIteratee(value) {
  3147. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3148. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3149. if (typeof value == 'function') {
  3150. return value;
  3151. }
  3152. if (value == null) {
  3153. return identity;
  3154. }
  3155. if (typeof value == 'object') {
  3156. return isArray(value)
  3157. ? baseMatchesProperty(value[0], value[1])
  3158. : baseMatches(value);
  3159. }
  3160. return property(value);
  3161. }
  3162. /**
  3163. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3164. *
  3165. * @private
  3166. * @param {Object} object The object to query.
  3167. * @returns {Array} Returns the array of property names.
  3168. */
  3169. function baseKeys(object) {
  3170. if (!isPrototype(object)) {
  3171. return nativeKeys(object);
  3172. }
  3173. var result = [];
  3174. for (var key in Object(object)) {
  3175. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3176. result.push(key);
  3177. }
  3178. }
  3179. return result;
  3180. }
  3181. /**
  3182. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3183. *
  3184. * @private
  3185. * @param {Object} object The object to query.
  3186. * @returns {Array} Returns the array of property names.
  3187. */
  3188. function baseKeysIn(object) {
  3189. if (!isObject(object)) {
  3190. return nativeKeysIn(object);
  3191. }
  3192. var isProto = isPrototype(object),
  3193. result = [];
  3194. for (var key in object) {
  3195. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3196. result.push(key);
  3197. }
  3198. }
  3199. return result;
  3200. }
  3201. /**
  3202. * The base implementation of `_.lt` which doesn't coerce arguments.
  3203. *
  3204. * @private
  3205. * @param {*} value The value to compare.
  3206. * @param {*} other The other value to compare.
  3207. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3208. * else `false`.
  3209. */
  3210. function baseLt(value, other) {
  3211. return value < other;
  3212. }
  3213. /**
  3214. * The base implementation of `_.map` without support for iteratee shorthands.
  3215. *
  3216. * @private
  3217. * @param {Array|Object} collection The collection to iterate over.
  3218. * @param {Function} iteratee The function invoked per iteration.
  3219. * @returns {Array} Returns the new mapped array.
  3220. */
  3221. function baseMap(collection, iteratee) {
  3222. var index = -1,
  3223. result = isArrayLike(collection) ? Array(collection.length) : [];
  3224. baseEach(collection, function(value, key, collection) {
  3225. result[++index] = iteratee(value, key, collection);
  3226. });
  3227. return result;
  3228. }
  3229. /**
  3230. * The base implementation of `_.matches` which doesn't clone `source`.
  3231. *
  3232. * @private
  3233. * @param {Object} source The object of property values to match.
  3234. * @returns {Function} Returns the new spec function.
  3235. */
  3236. function baseMatches(source) {
  3237. var matchData = getMatchData(source);
  3238. if (matchData.length == 1 && matchData[0][2]) {
  3239. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3240. }
  3241. return function(object) {
  3242. return object === source || baseIsMatch(object, source, matchData);
  3243. };
  3244. }
  3245. /**
  3246. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3247. *
  3248. * @private
  3249. * @param {string} path The path of the property to get.
  3250. * @param {*} srcValue The value to match.
  3251. * @returns {Function} Returns the new spec function.
  3252. */
  3253. function baseMatchesProperty(path, srcValue) {
  3254. if (isKey(path) && isStrictComparable(srcValue)) {
  3255. return matchesStrictComparable(toKey(path), srcValue);
  3256. }
  3257. return function(object) {
  3258. var objValue = get(object, path);
  3259. return (objValue === undefined && objValue === srcValue)
  3260. ? hasIn(object, path)
  3261. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3262. };
  3263. }
  3264. /**
  3265. * The base implementation of `_.merge` without support for multiple sources.
  3266. *
  3267. * @private
  3268. * @param {Object} object The destination object.
  3269. * @param {Object} source The source object.
  3270. * @param {number} srcIndex The index of `source`.
  3271. * @param {Function} [customizer] The function to customize merged values.
  3272. * @param {Object} [stack] Tracks traversed source values and their merged
  3273. * counterparts.
  3274. */
  3275. function baseMerge(object, source, srcIndex, customizer, stack) {
  3276. if (object === source) {
  3277. return;
  3278. }
  3279. baseFor(source, function(srcValue, key) {
  3280. stack || (stack = new Stack);
  3281. if (isObject(srcValue)) {
  3282. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3283. }
  3284. else {
  3285. var newValue = customizer
  3286. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3287. : undefined;
  3288. if (newValue === undefined) {
  3289. newValue = srcValue;
  3290. }
  3291. assignMergeValue(object, key, newValue);
  3292. }
  3293. }, keysIn);
  3294. }
  3295. /**
  3296. * A specialized version of `baseMerge` for arrays and objects which performs
  3297. * deep merges and tracks traversed objects enabling objects with circular
  3298. * references to be merged.
  3299. *
  3300. * @private
  3301. * @param {Object} object The destination object.
  3302. * @param {Object} source The source object.
  3303. * @param {string} key The key of the value to merge.
  3304. * @param {number} srcIndex The index of `source`.
  3305. * @param {Function} mergeFunc The function to merge values.
  3306. * @param {Function} [customizer] The function to customize assigned values.
  3307. * @param {Object} [stack] Tracks traversed source values and their merged
  3308. * counterparts.
  3309. */
  3310. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3311. var objValue = safeGet(object, key),
  3312. srcValue = safeGet(source, key),
  3313. stacked = stack.get(srcValue);
  3314. if (stacked) {
  3315. assignMergeValue(object, key, stacked);
  3316. return;
  3317. }
  3318. var newValue = customizer
  3319. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3320. : undefined;
  3321. var isCommon = newValue === undefined;
  3322. if (isCommon) {
  3323. var isArr = isArray(srcValue),
  3324. isBuff = !isArr && isBuffer(srcValue),
  3325. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3326. newValue = srcValue;
  3327. if (isArr || isBuff || isTyped) {
  3328. if (isArray(objValue)) {
  3329. newValue = objValue;
  3330. }
  3331. else if (isArrayLikeObject(objValue)) {
  3332. newValue = copyArray(objValue);
  3333. }
  3334. else if (isBuff) {
  3335. isCommon = false;
  3336. newValue = cloneBuffer(srcValue, true);
  3337. }
  3338. else if (isTyped) {
  3339. isCommon = false;
  3340. newValue = cloneTypedArray(srcValue, true);
  3341. }
  3342. else {
  3343. newValue = [];
  3344. }
  3345. }
  3346. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3347. newValue = objValue;
  3348. if (isArguments(objValue)) {
  3349. newValue = toPlainObject(objValue);
  3350. }
  3351. else if (!isObject(objValue) || isFunction(objValue)) {
  3352. newValue = initCloneObject(srcValue);
  3353. }
  3354. }
  3355. else {
  3356. isCommon = false;
  3357. }
  3358. }
  3359. if (isCommon) {
  3360. // Recursively merge objects and arrays (susceptible to call stack limits).
  3361. stack.set(srcValue, newValue);
  3362. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3363. stack['delete'](srcValue);
  3364. }
  3365. assignMergeValue(object, key, newValue);
  3366. }
  3367. /**
  3368. * The base implementation of `_.nth` which doesn't coerce arguments.
  3369. *
  3370. * @private
  3371. * @param {Array} array The array to query.
  3372. * @param {number} n The index of the element to return.
  3373. * @returns {*} Returns the nth element of `array`.
  3374. */
  3375. function baseNth(array, n) {
  3376. var length = array.length;
  3377. if (!length) {
  3378. return;
  3379. }
  3380. n += n < 0 ? length : 0;
  3381. return isIndex(n, length) ? array[n] : undefined;
  3382. }
  3383. /**
  3384. * The base implementation of `_.orderBy` without param guards.
  3385. *
  3386. * @private
  3387. * @param {Array|Object} collection The collection to iterate over.
  3388. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3389. * @param {string[]} orders The sort orders of `iteratees`.
  3390. * @returns {Array} Returns the new sorted array.
  3391. */
  3392. function baseOrderBy(collection, iteratees, orders) {
  3393. var index = -1;
  3394. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3395. var result = baseMap(collection, function(value, key, collection) {
  3396. var criteria = arrayMap(iteratees, function(iteratee) {
  3397. return iteratee(value);
  3398. });
  3399. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3400. });
  3401. return baseSortBy(result, function(object, other) {
  3402. return compareMultiple(object, other, orders);
  3403. });
  3404. }
  3405. /**
  3406. * The base implementation of `_.pick` without support for individual
  3407. * property identifiers.
  3408. *
  3409. * @private
  3410. * @param {Object} object The source object.
  3411. * @param {string[]} paths The property paths to pick.
  3412. * @returns {Object} Returns the new object.
  3413. */
  3414. function basePick(object, paths) {
  3415. return basePickBy(object, paths, function(value, path) {
  3416. return hasIn(object, path);
  3417. });
  3418. }
  3419. /**
  3420. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3421. *
  3422. * @private
  3423. * @param {Object} object The source object.
  3424. * @param {string[]} paths The property paths to pick.
  3425. * @param {Function} predicate The function invoked per property.
  3426. * @returns {Object} Returns the new object.
  3427. */
  3428. function basePickBy(object, paths, predicate) {
  3429. var index = -1,
  3430. length = paths.length,
  3431. result = {};
  3432. while (++index < length) {
  3433. var path = paths[index],
  3434. value = baseGet(object, path);
  3435. if (predicate(value, path)) {
  3436. baseSet(result, castPath(path, object), value);
  3437. }
  3438. }
  3439. return result;
  3440. }
  3441. /**
  3442. * A specialized version of `baseProperty` which supports deep paths.
  3443. *
  3444. * @private
  3445. * @param {Array|string} path The path of the property to get.
  3446. * @returns {Function} Returns the new accessor function.
  3447. */
  3448. function basePropertyDeep(path) {
  3449. return function(object) {
  3450. return baseGet(object, path);
  3451. };
  3452. }
  3453. /**
  3454. * The base implementation of `_.pullAllBy` without support for iteratee
  3455. * shorthands.
  3456. *
  3457. * @private
  3458. * @param {Array} array The array to modify.
  3459. * @param {Array} values The values to remove.
  3460. * @param {Function} [iteratee] The iteratee invoked per element.
  3461. * @param {Function} [comparator] The comparator invoked per element.
  3462. * @returns {Array} Returns `array`.
  3463. */
  3464. function basePullAll(array, values, iteratee, comparator) {
  3465. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3466. index = -1,
  3467. length = values.length,
  3468. seen = array;
  3469. if (array === values) {
  3470. values = copyArray(values);
  3471. }
  3472. if (iteratee) {
  3473. seen = arrayMap(array, baseUnary(iteratee));
  3474. }
  3475. while (++index < length) {
  3476. var fromIndex = 0,
  3477. value = values[index],
  3478. computed = iteratee ? iteratee(value) : value;
  3479. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3480. if (seen !== array) {
  3481. splice.call(seen, fromIndex, 1);
  3482. }
  3483. splice.call(array, fromIndex, 1);
  3484. }
  3485. }
  3486. return array;
  3487. }
  3488. /**
  3489. * The base implementation of `_.pullAt` without support for individual
  3490. * indexes or capturing the removed elements.
  3491. *
  3492. * @private
  3493. * @param {Array} array The array to modify.
  3494. * @param {number[]} indexes The indexes of elements to remove.
  3495. * @returns {Array} Returns `array`.
  3496. */
  3497. function basePullAt(array, indexes) {
  3498. var length = array ? indexes.length : 0,
  3499. lastIndex = length - 1;
  3500. while (length--) {
  3501. var index = indexes[length];
  3502. if (length == lastIndex || index !== previous) {
  3503. var previous = index;
  3504. if (isIndex(index)) {
  3505. splice.call(array, index, 1);
  3506. } else {
  3507. baseUnset(array, index);
  3508. }
  3509. }
  3510. }
  3511. return array;
  3512. }
  3513. /**
  3514. * The base implementation of `_.random` without support for returning
  3515. * floating-point numbers.
  3516. *
  3517. * @private
  3518. * @param {number} lower The lower bound.
  3519. * @param {number} upper The upper bound.
  3520. * @returns {number} Returns the random number.
  3521. */
  3522. function baseRandom(lower, upper) {
  3523. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3524. }
  3525. /**
  3526. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3527. * coerce arguments.
  3528. *
  3529. * @private
  3530. * @param {number} start The start of the range.
  3531. * @param {number} end The end of the range.
  3532. * @param {number} step The value to increment or decrement by.
  3533. * @param {boolean} [fromRight] Specify iterating from right to left.
  3534. * @returns {Array} Returns the range of numbers.
  3535. */
  3536. function baseRange(start, end, step, fromRight) {
  3537. var index = -1,
  3538. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3539. result = Array(length);
  3540. while (length--) {
  3541. result[fromRight ? length : ++index] = start;
  3542. start += step;
  3543. }
  3544. return result;
  3545. }
  3546. /**
  3547. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3548. *
  3549. * @private
  3550. * @param {string} string The string to repeat.
  3551. * @param {number} n The number of times to repeat the string.
  3552. * @returns {string} Returns the repeated string.
  3553. */
  3554. function baseRepeat(string, n) {
  3555. var result = '';
  3556. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3557. return result;
  3558. }
  3559. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3560. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3561. do {
  3562. if (n % 2) {
  3563. result += string;
  3564. }
  3565. n = nativeFloor(n / 2);
  3566. if (n) {
  3567. string += string;
  3568. }
  3569. } while (n);
  3570. return result;
  3571. }
  3572. /**
  3573. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3574. *
  3575. * @private
  3576. * @param {Function} func The function to apply a rest parameter to.
  3577. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3578. * @returns {Function} Returns the new function.
  3579. */
  3580. function baseRest(func, start) {
  3581. return setToString(overRest(func, start, identity), func + '');
  3582. }
  3583. /**
  3584. * The base implementation of `_.sample`.
  3585. *
  3586. * @private
  3587. * @param {Array|Object} collection The collection to sample.
  3588. * @returns {*} Returns the random element.
  3589. */
  3590. function baseSample(collection) {
  3591. return arraySample(values(collection));
  3592. }
  3593. /**
  3594. * The base implementation of `_.sampleSize` without param guards.
  3595. *
  3596. * @private
  3597. * @param {Array|Object} collection The collection to sample.
  3598. * @param {number} n The number of elements to sample.
  3599. * @returns {Array} Returns the random elements.
  3600. */
  3601. function baseSampleSize(collection, n) {
  3602. var array = values(collection);
  3603. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3604. }
  3605. /**
  3606. * The base implementation of `_.set`.
  3607. *
  3608. * @private
  3609. * @param {Object} object The object to modify.
  3610. * @param {Array|string} path The path of the property to set.
  3611. * @param {*} value The value to set.
  3612. * @param {Function} [customizer] The function to customize path creation.
  3613. * @returns {Object} Returns `object`.
  3614. */
  3615. function baseSet(object, path, value, customizer) {
  3616. if (!isObject(object)) {
  3617. return object;
  3618. }
  3619. path = castPath(path, object);
  3620. var index = -1,
  3621. length = path.length,
  3622. lastIndex = length - 1,
  3623. nested = object;
  3624. while (nested != null && ++index < length) {
  3625. var key = toKey(path[index]),
  3626. newValue = value;
  3627. if (index != lastIndex) {
  3628. var objValue = nested[key];
  3629. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3630. if (newValue === undefined) {
  3631. newValue = isObject(objValue)
  3632. ? objValue
  3633. : (isIndex(path[index + 1]) ? [] : {});
  3634. }
  3635. }
  3636. assignValue(nested, key, newValue);
  3637. nested = nested[key];
  3638. }
  3639. return object;
  3640. }
  3641. /**
  3642. * The base implementation of `setData` without support for hot loop shorting.
  3643. *
  3644. * @private
  3645. * @param {Function} func The function to associate metadata with.
  3646. * @param {*} data The metadata.
  3647. * @returns {Function} Returns `func`.
  3648. */
  3649. var baseSetData = !metaMap ? identity : function(func, data) {
  3650. metaMap.set(func, data);
  3651. return func;
  3652. };
  3653. /**
  3654. * The base implementation of `setToString` without support for hot loop shorting.
  3655. *
  3656. * @private
  3657. * @param {Function} func The function to modify.
  3658. * @param {Function} string The `toString` result.
  3659. * @returns {Function} Returns `func`.
  3660. */
  3661. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3662. return defineProperty(func, 'toString', {
  3663. 'configurable': true,
  3664. 'enumerable': false,
  3665. 'value': constant(string),
  3666. 'writable': true
  3667. });
  3668. };
  3669. /**
  3670. * The base implementation of `_.shuffle`.
  3671. *
  3672. * @private
  3673. * @param {Array|Object} collection The collection to shuffle.
  3674. * @returns {Array} Returns the new shuffled array.
  3675. */
  3676. function baseShuffle(collection) {
  3677. return shuffleSelf(values(collection));
  3678. }
  3679. /**
  3680. * The base implementation of `_.slice` without an iteratee call guard.
  3681. *
  3682. * @private
  3683. * @param {Array} array The array to slice.
  3684. * @param {number} [start=0] The start position.
  3685. * @param {number} [end=array.length] The end position.
  3686. * @returns {Array} Returns the slice of `array`.
  3687. */
  3688. function baseSlice(array, start, end) {
  3689. var index = -1,
  3690. length = array.length;
  3691. if (start < 0) {
  3692. start = -start > length ? 0 : (length + start);
  3693. }
  3694. end = end > length ? length : end;
  3695. if (end < 0) {
  3696. end += length;
  3697. }
  3698. length = start > end ? 0 : ((end - start) >>> 0);
  3699. start >>>= 0;
  3700. var result = Array(length);
  3701. while (++index < length) {
  3702. result[index] = array[index + start];
  3703. }
  3704. return result;
  3705. }
  3706. /**
  3707. * The base implementation of `_.some` without support for iteratee shorthands.
  3708. *
  3709. * @private
  3710. * @param {Array|Object} collection The collection to iterate over.
  3711. * @param {Function} predicate The function invoked per iteration.
  3712. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3713. * else `false`.
  3714. */
  3715. function baseSome(collection, predicate) {
  3716. var result;
  3717. baseEach(collection, function(value, index, collection) {
  3718. result = predicate(value, index, collection);
  3719. return !result;
  3720. });
  3721. return !!result;
  3722. }
  3723. /**
  3724. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3725. * performs a binary search of `array` to determine the index at which `value`
  3726. * should be inserted into `array` in order to maintain its sort order.
  3727. *
  3728. * @private
  3729. * @param {Array} array The sorted array to inspect.
  3730. * @param {*} value The value to evaluate.
  3731. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3732. * @returns {number} Returns the index at which `value` should be inserted
  3733. * into `array`.
  3734. */
  3735. function baseSortedIndex(array, value, retHighest) {
  3736. var low = 0,
  3737. high = array == null ? low : array.length;
  3738. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3739. while (low < high) {
  3740. var mid = (low + high) >>> 1,
  3741. computed = array[mid];
  3742. if (computed !== null && !isSymbol(computed) &&
  3743. (retHighest ? (computed <= value) : (computed < value))) {
  3744. low = mid + 1;
  3745. } else {
  3746. high = mid;
  3747. }
  3748. }
  3749. return high;
  3750. }
  3751. return baseSortedIndexBy(array, value, identity, retHighest);
  3752. }
  3753. /**
  3754. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3755. * which invokes `iteratee` for `value` and each element of `array` to compute
  3756. * their sort ranking. The iteratee is invoked with one argument; (value).
  3757. *
  3758. * @private
  3759. * @param {Array} array The sorted array to inspect.
  3760. * @param {*} value The value to evaluate.
  3761. * @param {Function} iteratee The iteratee invoked per element.
  3762. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3763. * @returns {number} Returns the index at which `value` should be inserted
  3764. * into `array`.
  3765. */
  3766. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3767. value = iteratee(value);
  3768. var low = 0,
  3769. high = array == null ? 0 : array.length,
  3770. valIsNaN = value !== value,
  3771. valIsNull = value === null,
  3772. valIsSymbol = isSymbol(value),
  3773. valIsUndefined = value === undefined;
  3774. while (low < high) {
  3775. var mid = nativeFloor((low + high) / 2),
  3776. computed = iteratee(array[mid]),
  3777. othIsDefined = computed !== undefined,
  3778. othIsNull = computed === null,
  3779. othIsReflexive = computed === computed,
  3780. othIsSymbol = isSymbol(computed);
  3781. if (valIsNaN) {
  3782. var setLow = retHighest || othIsReflexive;
  3783. } else if (valIsUndefined) {
  3784. setLow = othIsReflexive && (retHighest || othIsDefined);
  3785. } else if (valIsNull) {
  3786. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3787. } else if (valIsSymbol) {
  3788. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3789. } else if (othIsNull || othIsSymbol) {
  3790. setLow = false;
  3791. } else {
  3792. setLow = retHighest ? (computed <= value) : (computed < value);
  3793. }
  3794. if (setLow) {
  3795. low = mid + 1;
  3796. } else {
  3797. high = mid;
  3798. }
  3799. }
  3800. return nativeMin(high, MAX_ARRAY_INDEX);
  3801. }
  3802. /**
  3803. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3804. * support for iteratee shorthands.
  3805. *
  3806. * @private
  3807. * @param {Array} array The array to inspect.
  3808. * @param {Function} [iteratee] The iteratee invoked per element.
  3809. * @returns {Array} Returns the new duplicate free array.
  3810. */
  3811. function baseSortedUniq(array, iteratee) {
  3812. var index = -1,
  3813. length = array.length,
  3814. resIndex = 0,
  3815. result = [];
  3816. while (++index < length) {
  3817. var value = array[index],
  3818. computed = iteratee ? iteratee(value) : value;
  3819. if (!index || !eq(computed, seen)) {
  3820. var seen = computed;
  3821. result[resIndex++] = value === 0 ? 0 : value;
  3822. }
  3823. }
  3824. return result;
  3825. }
  3826. /**
  3827. * The base implementation of `_.toNumber` which doesn't ensure correct
  3828. * conversions of binary, hexadecimal, or octal string values.
  3829. *
  3830. * @private
  3831. * @param {*} value The value to process.
  3832. * @returns {number} Returns the number.
  3833. */
  3834. function baseToNumber(value) {
  3835. if (typeof value == 'number') {
  3836. return value;
  3837. }
  3838. if (isSymbol(value)) {
  3839. return NAN;
  3840. }
  3841. return +value;
  3842. }
  3843. /**
  3844. * The base implementation of `_.toString` which doesn't convert nullish
  3845. * values to empty strings.
  3846. *
  3847. * @private
  3848. * @param {*} value The value to process.
  3849. * @returns {string} Returns the string.
  3850. */
  3851. function baseToString(value) {
  3852. // Exit early for strings to avoid a performance hit in some environments.
  3853. if (typeof value == 'string') {
  3854. return value;
  3855. }
  3856. if (isArray(value)) {
  3857. // Recursively convert values (susceptible to call stack limits).
  3858. return arrayMap(value, baseToString) + '';
  3859. }
  3860. if (isSymbol(value)) {
  3861. return symbolToString ? symbolToString.call(value) : '';
  3862. }
  3863. var result = (value + '');
  3864. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3865. }
  3866. /**
  3867. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3868. *
  3869. * @private
  3870. * @param {Array} array The array to inspect.
  3871. * @param {Function} [iteratee] The iteratee invoked per element.
  3872. * @param {Function} [comparator] The comparator invoked per element.
  3873. * @returns {Array} Returns the new duplicate free array.
  3874. */
  3875. function baseUniq(array, iteratee, comparator) {
  3876. var index = -1,
  3877. includes = arrayIncludes,
  3878. length = array.length,
  3879. isCommon = true,
  3880. result = [],
  3881. seen = result;
  3882. if (comparator) {
  3883. isCommon = false;
  3884. includes = arrayIncludesWith;
  3885. }
  3886. else if (length >= LARGE_ARRAY_SIZE) {
  3887. var set = iteratee ? null : createSet(array);
  3888. if (set) {
  3889. return setToArray(set);
  3890. }
  3891. isCommon = false;
  3892. includes = cacheHas;
  3893. seen = new SetCache;
  3894. }
  3895. else {
  3896. seen = iteratee ? [] : result;
  3897. }
  3898. outer:
  3899. while (++index < length) {
  3900. var value = array[index],
  3901. computed = iteratee ? iteratee(value) : value;
  3902. value = (comparator || value !== 0) ? value : 0;
  3903. if (isCommon && computed === computed) {
  3904. var seenIndex = seen.length;
  3905. while (seenIndex--) {
  3906. if (seen[seenIndex] === computed) {
  3907. continue outer;
  3908. }
  3909. }
  3910. if (iteratee) {
  3911. seen.push(computed);
  3912. }
  3913. result.push(value);
  3914. }
  3915. else if (!includes(seen, computed, comparator)) {
  3916. if (seen !== result) {
  3917. seen.push(computed);
  3918. }
  3919. result.push(value);
  3920. }
  3921. }
  3922. return result;
  3923. }
  3924. /**
  3925. * The base implementation of `_.unset`.
  3926. *
  3927. * @private
  3928. * @param {Object} object The object to modify.
  3929. * @param {Array|string} path The property path to unset.
  3930. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3931. */
  3932. function baseUnset(object, path) {
  3933. path = castPath(path, object);
  3934. object = parent(object, path);
  3935. return object == null || delete object[toKey(last(path))];
  3936. }
  3937. /**
  3938. * The base implementation of `_.update`.
  3939. *
  3940. * @private
  3941. * @param {Object} object The object to modify.
  3942. * @param {Array|string} path The path of the property to update.
  3943. * @param {Function} updater The function to produce the updated value.
  3944. * @param {Function} [customizer] The function to customize path creation.
  3945. * @returns {Object} Returns `object`.
  3946. */
  3947. function baseUpdate(object, path, updater, customizer) {
  3948. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3949. }
  3950. /**
  3951. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3952. * without support for iteratee shorthands.
  3953. *
  3954. * @private
  3955. * @param {Array} array The array to query.
  3956. * @param {Function} predicate The function invoked per iteration.
  3957. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3958. * @param {boolean} [fromRight] Specify iterating from right to left.
  3959. * @returns {Array} Returns the slice of `array`.
  3960. */
  3961. function baseWhile(array, predicate, isDrop, fromRight) {
  3962. var length = array.length,
  3963. index = fromRight ? length : -1;
  3964. while ((fromRight ? index-- : ++index < length) &&
  3965. predicate(array[index], index, array)) {}
  3966. return isDrop
  3967. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3968. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3969. }
  3970. /**
  3971. * The base implementation of `wrapperValue` which returns the result of
  3972. * performing a sequence of actions on the unwrapped `value`, where each
  3973. * successive action is supplied the return value of the previous.
  3974. *
  3975. * @private
  3976. * @param {*} value The unwrapped value.
  3977. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3978. * @returns {*} Returns the resolved value.
  3979. */
  3980. function baseWrapperValue(value, actions) {
  3981. var result = value;
  3982. if (result instanceof LazyWrapper) {
  3983. result = result.value();
  3984. }
  3985. return arrayReduce(actions, function(result, action) {
  3986. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3987. }, result);
  3988. }
  3989. /**
  3990. * The base implementation of methods like `_.xor`, without support for
  3991. * iteratee shorthands, that accepts an array of arrays to inspect.
  3992. *
  3993. * @private
  3994. * @param {Array} arrays The arrays to inspect.
  3995. * @param {Function} [iteratee] The iteratee invoked per element.
  3996. * @param {Function} [comparator] The comparator invoked per element.
  3997. * @returns {Array} Returns the new array of values.
  3998. */
  3999. function baseXor(arrays, iteratee, comparator) {
  4000. var length = arrays.length;
  4001. if (length < 2) {
  4002. return length ? baseUniq(arrays[0]) : [];
  4003. }
  4004. var index = -1,
  4005. result = Array(length);
  4006. while (++index < length) {
  4007. var array = arrays[index],
  4008. othIndex = -1;
  4009. while (++othIndex < length) {
  4010. if (othIndex != index) {
  4011. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4012. }
  4013. }
  4014. }
  4015. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4016. }
  4017. /**
  4018. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4019. *
  4020. * @private
  4021. * @param {Array} props The property identifiers.
  4022. * @param {Array} values The property values.
  4023. * @param {Function} assignFunc The function to assign values.
  4024. * @returns {Object} Returns the new object.
  4025. */
  4026. function baseZipObject(props, values, assignFunc) {
  4027. var index = -1,
  4028. length = props.length,
  4029. valsLength = values.length,
  4030. result = {};
  4031. while (++index < length) {
  4032. var value = index < valsLength ? values[index] : undefined;
  4033. assignFunc(result, props[index], value);
  4034. }
  4035. return result;
  4036. }
  4037. /**
  4038. * Casts `value` to an empty array if it's not an array like object.
  4039. *
  4040. * @private
  4041. * @param {*} value The value to inspect.
  4042. * @returns {Array|Object} Returns the cast array-like object.
  4043. */
  4044. function castArrayLikeObject(value) {
  4045. return isArrayLikeObject(value) ? value : [];
  4046. }
  4047. /**
  4048. * Casts `value` to `identity` if it's not a function.
  4049. *
  4050. * @private
  4051. * @param {*} value The value to inspect.
  4052. * @returns {Function} Returns cast function.
  4053. */
  4054. function castFunction(value) {
  4055. return typeof value == 'function' ? value : identity;
  4056. }
  4057. /**
  4058. * Casts `value` to a path array if it's not one.
  4059. *
  4060. * @private
  4061. * @param {*} value The value to inspect.
  4062. * @param {Object} [object] The object to query keys on.
  4063. * @returns {Array} Returns the cast property path array.
  4064. */
  4065. function castPath(value, object) {
  4066. if (isArray(value)) {
  4067. return value;
  4068. }
  4069. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4070. }
  4071. /**
  4072. * A `baseRest` alias which can be replaced with `identity` by module
  4073. * replacement plugins.
  4074. *
  4075. * @private
  4076. * @type {Function}
  4077. * @param {Function} func The function to apply a rest parameter to.
  4078. * @returns {Function} Returns the new function.
  4079. */
  4080. var castRest = baseRest;
  4081. /**
  4082. * Casts `array` to a slice if it's needed.
  4083. *
  4084. * @private
  4085. * @param {Array} array The array to inspect.
  4086. * @param {number} start The start position.
  4087. * @param {number} [end=array.length] The end position.
  4088. * @returns {Array} Returns the cast slice.
  4089. */
  4090. function castSlice(array, start, end) {
  4091. var length = array.length;
  4092. end = end === undefined ? length : end;
  4093. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4094. }
  4095. /**
  4096. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4097. *
  4098. * @private
  4099. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4100. */
  4101. var clearTimeout = ctxClearTimeout || function(id) {
  4102. return root.clearTimeout(id);
  4103. };
  4104. /**
  4105. * Creates a clone of `buffer`.
  4106. *
  4107. * @private
  4108. * @param {Buffer} buffer The buffer to clone.
  4109. * @param {boolean} [isDeep] Specify a deep clone.
  4110. * @returns {Buffer} Returns the cloned buffer.
  4111. */
  4112. function cloneBuffer(buffer, isDeep) {
  4113. if (isDeep) {
  4114. return buffer.slice();
  4115. }
  4116. var length = buffer.length,
  4117. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4118. buffer.copy(result);
  4119. return result;
  4120. }
  4121. /**
  4122. * Creates a clone of `arrayBuffer`.
  4123. *
  4124. * @private
  4125. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4126. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4127. */
  4128. function cloneArrayBuffer(arrayBuffer) {
  4129. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4130. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4131. return result;
  4132. }
  4133. /**
  4134. * Creates a clone of `dataView`.
  4135. *
  4136. * @private
  4137. * @param {Object} dataView The data view to clone.
  4138. * @param {boolean} [isDeep] Specify a deep clone.
  4139. * @returns {Object} Returns the cloned data view.
  4140. */
  4141. function cloneDataView(dataView, isDeep) {
  4142. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4143. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4144. }
  4145. /**
  4146. * Creates a clone of `regexp`.
  4147. *
  4148. * @private
  4149. * @param {Object} regexp The regexp to clone.
  4150. * @returns {Object} Returns the cloned regexp.
  4151. */
  4152. function cloneRegExp(regexp) {
  4153. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4154. result.lastIndex = regexp.lastIndex;
  4155. return result;
  4156. }
  4157. /**
  4158. * Creates a clone of the `symbol` object.
  4159. *
  4160. * @private
  4161. * @param {Object} symbol The symbol object to clone.
  4162. * @returns {Object} Returns the cloned symbol object.
  4163. */
  4164. function cloneSymbol(symbol) {
  4165. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4166. }
  4167. /**
  4168. * Creates a clone of `typedArray`.
  4169. *
  4170. * @private
  4171. * @param {Object} typedArray The typed array to clone.
  4172. * @param {boolean} [isDeep] Specify a deep clone.
  4173. * @returns {Object} Returns the cloned typed array.
  4174. */
  4175. function cloneTypedArray(typedArray, isDeep) {
  4176. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4177. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4178. }
  4179. /**
  4180. * Compares values to sort them in ascending order.
  4181. *
  4182. * @private
  4183. * @param {*} value The value to compare.
  4184. * @param {*} other The other value to compare.
  4185. * @returns {number} Returns the sort order indicator for `value`.
  4186. */
  4187. function compareAscending(value, other) {
  4188. if (value !== other) {
  4189. var valIsDefined = value !== undefined,
  4190. valIsNull = value === null,
  4191. valIsReflexive = value === value,
  4192. valIsSymbol = isSymbol(value);
  4193. var othIsDefined = other !== undefined,
  4194. othIsNull = other === null,
  4195. othIsReflexive = other === other,
  4196. othIsSymbol = isSymbol(other);
  4197. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4198. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4199. (valIsNull && othIsDefined && othIsReflexive) ||
  4200. (!valIsDefined && othIsReflexive) ||
  4201. !valIsReflexive) {
  4202. return 1;
  4203. }
  4204. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4205. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4206. (othIsNull && valIsDefined && valIsReflexive) ||
  4207. (!othIsDefined && valIsReflexive) ||
  4208. !othIsReflexive) {
  4209. return -1;
  4210. }
  4211. }
  4212. return 0;
  4213. }
  4214. /**
  4215. * Used by `_.orderBy` to compare multiple properties of a value to another
  4216. * and stable sort them.
  4217. *
  4218. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4219. * specify an order of "desc" for descending or "asc" for ascending sort order
  4220. * of corresponding values.
  4221. *
  4222. * @private
  4223. * @param {Object} object The object to compare.
  4224. * @param {Object} other The other object to compare.
  4225. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4226. * @returns {number} Returns the sort order indicator for `object`.
  4227. */
  4228. function compareMultiple(object, other, orders) {
  4229. var index = -1,
  4230. objCriteria = object.criteria,
  4231. othCriteria = other.criteria,
  4232. length = objCriteria.length,
  4233. ordersLength = orders.length;
  4234. while (++index < length) {
  4235. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4236. if (result) {
  4237. if (index >= ordersLength) {
  4238. return result;
  4239. }
  4240. var order = orders[index];
  4241. return result * (order == 'desc' ? -1 : 1);
  4242. }
  4243. }
  4244. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4245. // that causes it, under certain circumstances, to provide the same value for
  4246. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4247. // for more details.
  4248. //
  4249. // This also ensures a stable sort in V8 and other engines.
  4250. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4251. return object.index - other.index;
  4252. }
  4253. /**
  4254. * Creates an array that is the composition of partially applied arguments,
  4255. * placeholders, and provided arguments into a single array of arguments.
  4256. *
  4257. * @private
  4258. * @param {Array} args The provided arguments.
  4259. * @param {Array} partials The arguments to prepend to those provided.
  4260. * @param {Array} holders The `partials` placeholder indexes.
  4261. * @params {boolean} [isCurried] Specify composing for a curried function.
  4262. * @returns {Array} Returns the new array of composed arguments.
  4263. */
  4264. function composeArgs(args, partials, holders, isCurried) {
  4265. var argsIndex = -1,
  4266. argsLength = args.length,
  4267. holdersLength = holders.length,
  4268. leftIndex = -1,
  4269. leftLength = partials.length,
  4270. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4271. result = Array(leftLength + rangeLength),
  4272. isUncurried = !isCurried;
  4273. while (++leftIndex < leftLength) {
  4274. result[leftIndex] = partials[leftIndex];
  4275. }
  4276. while (++argsIndex < holdersLength) {
  4277. if (isUncurried || argsIndex < argsLength) {
  4278. result[holders[argsIndex]] = args[argsIndex];
  4279. }
  4280. }
  4281. while (rangeLength--) {
  4282. result[leftIndex++] = args[argsIndex++];
  4283. }
  4284. return result;
  4285. }
  4286. /**
  4287. * This function is like `composeArgs` except that the arguments composition
  4288. * is tailored for `_.partialRight`.
  4289. *
  4290. * @private
  4291. * @param {Array} args The provided arguments.
  4292. * @param {Array} partials The arguments to append to those provided.
  4293. * @param {Array} holders The `partials` placeholder indexes.
  4294. * @params {boolean} [isCurried] Specify composing for a curried function.
  4295. * @returns {Array} Returns the new array of composed arguments.
  4296. */
  4297. function composeArgsRight(args, partials, holders, isCurried) {
  4298. var argsIndex = -1,
  4299. argsLength = args.length,
  4300. holdersIndex = -1,
  4301. holdersLength = holders.length,
  4302. rightIndex = -1,
  4303. rightLength = partials.length,
  4304. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4305. result = Array(rangeLength + rightLength),
  4306. isUncurried = !isCurried;
  4307. while (++argsIndex < rangeLength) {
  4308. result[argsIndex] = args[argsIndex];
  4309. }
  4310. var offset = argsIndex;
  4311. while (++rightIndex < rightLength) {
  4312. result[offset + rightIndex] = partials[rightIndex];
  4313. }
  4314. while (++holdersIndex < holdersLength) {
  4315. if (isUncurried || argsIndex < argsLength) {
  4316. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4317. }
  4318. }
  4319. return result;
  4320. }
  4321. /**
  4322. * Copies the values of `source` to `array`.
  4323. *
  4324. * @private
  4325. * @param {Array} source The array to copy values from.
  4326. * @param {Array} [array=[]] The array to copy values to.
  4327. * @returns {Array} Returns `array`.
  4328. */
  4329. function copyArray(source, array) {
  4330. var index = -1,
  4331. length = source.length;
  4332. array || (array = Array(length));
  4333. while (++index < length) {
  4334. array[index] = source[index];
  4335. }
  4336. return array;
  4337. }
  4338. /**
  4339. * Copies properties of `source` to `object`.
  4340. *
  4341. * @private
  4342. * @param {Object} source The object to copy properties from.
  4343. * @param {Array} props The property identifiers to copy.
  4344. * @param {Object} [object={}] The object to copy properties to.
  4345. * @param {Function} [customizer] The function to customize copied values.
  4346. * @returns {Object} Returns `object`.
  4347. */
  4348. function copyObject(source, props, object, customizer) {
  4349. var isNew = !object;
  4350. object || (object = {});
  4351. var index = -1,
  4352. length = props.length;
  4353. while (++index < length) {
  4354. var key = props[index];
  4355. var newValue = customizer
  4356. ? customizer(object[key], source[key], key, object, source)
  4357. : undefined;
  4358. if (newValue === undefined) {
  4359. newValue = source[key];
  4360. }
  4361. if (isNew) {
  4362. baseAssignValue(object, key, newValue);
  4363. } else {
  4364. assignValue(object, key, newValue);
  4365. }
  4366. }
  4367. return object;
  4368. }
  4369. /**
  4370. * Copies own symbols of `source` to `object`.
  4371. *
  4372. * @private
  4373. * @param {Object} source The object to copy symbols from.
  4374. * @param {Object} [object={}] The object to copy symbols to.
  4375. * @returns {Object} Returns `object`.
  4376. */
  4377. function copySymbols(source, object) {
  4378. return copyObject(source, getSymbols(source), object);
  4379. }
  4380. /**
  4381. * Copies own and inherited symbols of `source` to `object`.
  4382. *
  4383. * @private
  4384. * @param {Object} source The object to copy symbols from.
  4385. * @param {Object} [object={}] The object to copy symbols to.
  4386. * @returns {Object} Returns `object`.
  4387. */
  4388. function copySymbolsIn(source, object) {
  4389. return copyObject(source, getSymbolsIn(source), object);
  4390. }
  4391. /**
  4392. * Creates a function like `_.groupBy`.
  4393. *
  4394. * @private
  4395. * @param {Function} setter The function to set accumulator values.
  4396. * @param {Function} [initializer] The accumulator object initializer.
  4397. * @returns {Function} Returns the new aggregator function.
  4398. */
  4399. function createAggregator(setter, initializer) {
  4400. return function(collection, iteratee) {
  4401. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4402. accumulator = initializer ? initializer() : {};
  4403. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4404. };
  4405. }
  4406. /**
  4407. * Creates a function like `_.assign`.
  4408. *
  4409. * @private
  4410. * @param {Function} assigner The function to assign values.
  4411. * @returns {Function} Returns the new assigner function.
  4412. */
  4413. function createAssigner(assigner) {
  4414. return baseRest(function(object, sources) {
  4415. var index = -1,
  4416. length = sources.length,
  4417. customizer = length > 1 ? sources[length - 1] : undefined,
  4418. guard = length > 2 ? sources[2] : undefined;
  4419. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4420. ? (length--, customizer)
  4421. : undefined;
  4422. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4423. customizer = length < 3 ? undefined : customizer;
  4424. length = 1;
  4425. }
  4426. object = Object(object);
  4427. while (++index < length) {
  4428. var source = sources[index];
  4429. if (source) {
  4430. assigner(object, source, index, customizer);
  4431. }
  4432. }
  4433. return object;
  4434. });
  4435. }
  4436. /**
  4437. * Creates a `baseEach` or `baseEachRight` function.
  4438. *
  4439. * @private
  4440. * @param {Function} eachFunc The function to iterate over a collection.
  4441. * @param {boolean} [fromRight] Specify iterating from right to left.
  4442. * @returns {Function} Returns the new base function.
  4443. */
  4444. function createBaseEach(eachFunc, fromRight) {
  4445. return function(collection, iteratee) {
  4446. if (collection == null) {
  4447. return collection;
  4448. }
  4449. if (!isArrayLike(collection)) {
  4450. return eachFunc(collection, iteratee);
  4451. }
  4452. var length = collection.length,
  4453. index = fromRight ? length : -1,
  4454. iterable = Object(collection);
  4455. while ((fromRight ? index-- : ++index < length)) {
  4456. if (iteratee(iterable[index], index, iterable) === false) {
  4457. break;
  4458. }
  4459. }
  4460. return collection;
  4461. };
  4462. }
  4463. /**
  4464. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4465. *
  4466. * @private
  4467. * @param {boolean} [fromRight] Specify iterating from right to left.
  4468. * @returns {Function} Returns the new base function.
  4469. */
  4470. function createBaseFor(fromRight) {
  4471. return function(object, iteratee, keysFunc) {
  4472. var index = -1,
  4473. iterable = Object(object),
  4474. props = keysFunc(object),
  4475. length = props.length;
  4476. while (length--) {
  4477. var key = props[fromRight ? length : ++index];
  4478. if (iteratee(iterable[key], key, iterable) === false) {
  4479. break;
  4480. }
  4481. }
  4482. return object;
  4483. };
  4484. }
  4485. /**
  4486. * Creates a function that wraps `func` to invoke it with the optional `this`
  4487. * binding of `thisArg`.
  4488. *
  4489. * @private
  4490. * @param {Function} func The function to wrap.
  4491. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4492. * @param {*} [thisArg] The `this` binding of `func`.
  4493. * @returns {Function} Returns the new wrapped function.
  4494. */
  4495. function createBind(func, bitmask, thisArg) {
  4496. var isBind = bitmask & WRAP_BIND_FLAG,
  4497. Ctor = createCtor(func);
  4498. function wrapper() {
  4499. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4500. return fn.apply(isBind ? thisArg : this, arguments);
  4501. }
  4502. return wrapper;
  4503. }
  4504. /**
  4505. * Creates a function like `_.lowerFirst`.
  4506. *
  4507. * @private
  4508. * @param {string} methodName The name of the `String` case method to use.
  4509. * @returns {Function} Returns the new case function.
  4510. */
  4511. function createCaseFirst(methodName) {
  4512. return function(string) {
  4513. string = toString(string);
  4514. var strSymbols = hasUnicode(string)
  4515. ? stringToArray(string)
  4516. : undefined;
  4517. var chr = strSymbols
  4518. ? strSymbols[0]
  4519. : string.charAt(0);
  4520. var trailing = strSymbols
  4521. ? castSlice(strSymbols, 1).join('')
  4522. : string.slice(1);
  4523. return chr[methodName]() + trailing;
  4524. };
  4525. }
  4526. /**
  4527. * Creates a function like `_.camelCase`.
  4528. *
  4529. * @private
  4530. * @param {Function} callback The function to combine each word.
  4531. * @returns {Function} Returns the new compounder function.
  4532. */
  4533. function createCompounder(callback) {
  4534. return function(string) {
  4535. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4536. };
  4537. }
  4538. /**
  4539. * Creates a function that produces an instance of `Ctor` regardless of
  4540. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4541. *
  4542. * @private
  4543. * @param {Function} Ctor The constructor to wrap.
  4544. * @returns {Function} Returns the new wrapped function.
  4545. */
  4546. function createCtor(Ctor) {
  4547. return function() {
  4548. // Use a `switch` statement to work with class constructors. See
  4549. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4550. // for more details.
  4551. var args = arguments;
  4552. switch (args.length) {
  4553. case 0: return new Ctor;
  4554. case 1: return new Ctor(args[0]);
  4555. case 2: return new Ctor(args[0], args[1]);
  4556. case 3: return new Ctor(args[0], args[1], args[2]);
  4557. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4558. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4559. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4560. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4561. }
  4562. var thisBinding = baseCreate(Ctor.prototype),
  4563. result = Ctor.apply(thisBinding, args);
  4564. // Mimic the constructor's `return` behavior.
  4565. // See https://es5.github.io/#x13.2.2 for more details.
  4566. return isObject(result) ? result : thisBinding;
  4567. };
  4568. }
  4569. /**
  4570. * Creates a function that wraps `func` to enable currying.
  4571. *
  4572. * @private
  4573. * @param {Function} func The function to wrap.
  4574. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4575. * @param {number} arity The arity of `func`.
  4576. * @returns {Function} Returns the new wrapped function.
  4577. */
  4578. function createCurry(func, bitmask, arity) {
  4579. var Ctor = createCtor(func);
  4580. function wrapper() {
  4581. var length = arguments.length,
  4582. args = Array(length),
  4583. index = length,
  4584. placeholder = getHolder(wrapper);
  4585. while (index--) {
  4586. args[index] = arguments[index];
  4587. }
  4588. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4589. ? []
  4590. : replaceHolders(args, placeholder);
  4591. length -= holders.length;
  4592. if (length < arity) {
  4593. return createRecurry(
  4594. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4595. args, holders, undefined, undefined, arity - length);
  4596. }
  4597. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4598. return apply(fn, this, args);
  4599. }
  4600. return wrapper;
  4601. }
  4602. /**
  4603. * Creates a `_.find` or `_.findLast` function.
  4604. *
  4605. * @private
  4606. * @param {Function} findIndexFunc The function to find the collection index.
  4607. * @returns {Function} Returns the new find function.
  4608. */
  4609. function createFind(findIndexFunc) {
  4610. return function(collection, predicate, fromIndex) {
  4611. var iterable = Object(collection);
  4612. if (!isArrayLike(collection)) {
  4613. var iteratee = getIteratee(predicate, 3);
  4614. collection = keys(collection);
  4615. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4616. }
  4617. var index = findIndexFunc(collection, predicate, fromIndex);
  4618. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4619. };
  4620. }
  4621. /**
  4622. * Creates a `_.flow` or `_.flowRight` function.
  4623. *
  4624. * @private
  4625. * @param {boolean} [fromRight] Specify iterating from right to left.
  4626. * @returns {Function} Returns the new flow function.
  4627. */
  4628. function createFlow(fromRight) {
  4629. return flatRest(function(funcs) {
  4630. var length = funcs.length,
  4631. index = length,
  4632. prereq = LodashWrapper.prototype.thru;
  4633. if (fromRight) {
  4634. funcs.reverse();
  4635. }
  4636. while (index--) {
  4637. var func = funcs[index];
  4638. if (typeof func != 'function') {
  4639. throw new TypeError(FUNC_ERROR_TEXT);
  4640. }
  4641. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4642. var wrapper = new LodashWrapper([], true);
  4643. }
  4644. }
  4645. index = wrapper ? index : length;
  4646. while (++index < length) {
  4647. func = funcs[index];
  4648. var funcName = getFuncName(func),
  4649. data = funcName == 'wrapper' ? getData(func) : undefined;
  4650. if (data && isLaziable(data[0]) &&
  4651. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4652. !data[4].length && data[9] == 1
  4653. ) {
  4654. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4655. } else {
  4656. wrapper = (func.length == 1 && isLaziable(func))
  4657. ? wrapper[funcName]()
  4658. : wrapper.thru(func);
  4659. }
  4660. }
  4661. return function() {
  4662. var args = arguments,
  4663. value = args[0];
  4664. if (wrapper && args.length == 1 && isArray(value)) {
  4665. return wrapper.plant(value).value();
  4666. }
  4667. var index = 0,
  4668. result = length ? funcs[index].apply(this, args) : value;
  4669. while (++index < length) {
  4670. result = funcs[index].call(this, result);
  4671. }
  4672. return result;
  4673. };
  4674. });
  4675. }
  4676. /**
  4677. * Creates a function that wraps `func` to invoke it with optional `this`
  4678. * binding of `thisArg`, partial application, and currying.
  4679. *
  4680. * @private
  4681. * @param {Function|string} func The function or method name to wrap.
  4682. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4683. * @param {*} [thisArg] The `this` binding of `func`.
  4684. * @param {Array} [partials] The arguments to prepend to those provided to
  4685. * the new function.
  4686. * @param {Array} [holders] The `partials` placeholder indexes.
  4687. * @param {Array} [partialsRight] The arguments to append to those provided
  4688. * to the new function.
  4689. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4690. * @param {Array} [argPos] The argument positions of the new function.
  4691. * @param {number} [ary] The arity cap of `func`.
  4692. * @param {number} [arity] The arity of `func`.
  4693. * @returns {Function} Returns the new wrapped function.
  4694. */
  4695. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4696. var isAry = bitmask & WRAP_ARY_FLAG,
  4697. isBind = bitmask & WRAP_BIND_FLAG,
  4698. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4699. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4700. isFlip = bitmask & WRAP_FLIP_FLAG,
  4701. Ctor = isBindKey ? undefined : createCtor(func);
  4702. function wrapper() {
  4703. var length = arguments.length,
  4704. args = Array(length),
  4705. index = length;
  4706. while (index--) {
  4707. args[index] = arguments[index];
  4708. }
  4709. if (isCurried) {
  4710. var placeholder = getHolder(wrapper),
  4711. holdersCount = countHolders(args, placeholder);
  4712. }
  4713. if (partials) {
  4714. args = composeArgs(args, partials, holders, isCurried);
  4715. }
  4716. if (partialsRight) {
  4717. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4718. }
  4719. length -= holdersCount;
  4720. if (isCurried && length < arity) {
  4721. var newHolders = replaceHolders(args, placeholder);
  4722. return createRecurry(
  4723. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4724. args, newHolders, argPos, ary, arity - length
  4725. );
  4726. }
  4727. var thisBinding = isBind ? thisArg : this,
  4728. fn = isBindKey ? thisBinding[func] : func;
  4729. length = args.length;
  4730. if (argPos) {
  4731. args = reorder(args, argPos);
  4732. } else if (isFlip && length > 1) {
  4733. args.reverse();
  4734. }
  4735. if (isAry && ary < length) {
  4736. args.length = ary;
  4737. }
  4738. if (this && this !== root && this instanceof wrapper) {
  4739. fn = Ctor || createCtor(fn);
  4740. }
  4741. return fn.apply(thisBinding, args);
  4742. }
  4743. return wrapper;
  4744. }
  4745. /**
  4746. * Creates a function like `_.invertBy`.
  4747. *
  4748. * @private
  4749. * @param {Function} setter The function to set accumulator values.
  4750. * @param {Function} toIteratee The function to resolve iteratees.
  4751. * @returns {Function} Returns the new inverter function.
  4752. */
  4753. function createInverter(setter, toIteratee) {
  4754. return function(object, iteratee) {
  4755. return baseInverter(object, setter, toIteratee(iteratee), {});
  4756. };
  4757. }
  4758. /**
  4759. * Creates a function that performs a mathematical operation on two values.
  4760. *
  4761. * @private
  4762. * @param {Function} operator The function to perform the operation.
  4763. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4764. * @returns {Function} Returns the new mathematical operation function.
  4765. */
  4766. function createMathOperation(operator, defaultValue) {
  4767. return function(value, other) {
  4768. var result;
  4769. if (value === undefined && other === undefined) {
  4770. return defaultValue;
  4771. }
  4772. if (value !== undefined) {
  4773. result = value;
  4774. }
  4775. if (other !== undefined) {
  4776. if (result === undefined) {
  4777. return other;
  4778. }
  4779. if (typeof value == 'string' || typeof other == 'string') {
  4780. value = baseToString(value);
  4781. other = baseToString(other);
  4782. } else {
  4783. value = baseToNumber(value);
  4784. other = baseToNumber(other);
  4785. }
  4786. result = operator(value, other);
  4787. }
  4788. return result;
  4789. };
  4790. }
  4791. /**
  4792. * Creates a function like `_.over`.
  4793. *
  4794. * @private
  4795. * @param {Function} arrayFunc The function to iterate over iteratees.
  4796. * @returns {Function} Returns the new over function.
  4797. */
  4798. function createOver(arrayFunc) {
  4799. return flatRest(function(iteratees) {
  4800. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4801. return baseRest(function(args) {
  4802. var thisArg = this;
  4803. return arrayFunc(iteratees, function(iteratee) {
  4804. return apply(iteratee, thisArg, args);
  4805. });
  4806. });
  4807. });
  4808. }
  4809. /**
  4810. * Creates the padding for `string` based on `length`. The `chars` string
  4811. * is truncated if the number of characters exceeds `length`.
  4812. *
  4813. * @private
  4814. * @param {number} length The padding length.
  4815. * @param {string} [chars=' '] The string used as padding.
  4816. * @returns {string} Returns the padding for `string`.
  4817. */
  4818. function createPadding(length, chars) {
  4819. chars = chars === undefined ? ' ' : baseToString(chars);
  4820. var charsLength = chars.length;
  4821. if (charsLength < 2) {
  4822. return charsLength ? baseRepeat(chars, length) : chars;
  4823. }
  4824. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4825. return hasUnicode(chars)
  4826. ? castSlice(stringToArray(result), 0, length).join('')
  4827. : result.slice(0, length);
  4828. }
  4829. /**
  4830. * Creates a function that wraps `func` to invoke it with the `this` binding
  4831. * of `thisArg` and `partials` prepended to the arguments it receives.
  4832. *
  4833. * @private
  4834. * @param {Function} func The function to wrap.
  4835. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4836. * @param {*} thisArg The `this` binding of `func`.
  4837. * @param {Array} partials The arguments to prepend to those provided to
  4838. * the new function.
  4839. * @returns {Function} Returns the new wrapped function.
  4840. */
  4841. function createPartial(func, bitmask, thisArg, partials) {
  4842. var isBind = bitmask & WRAP_BIND_FLAG,
  4843. Ctor = createCtor(func);
  4844. function wrapper() {
  4845. var argsIndex = -1,
  4846. argsLength = arguments.length,
  4847. leftIndex = -1,
  4848. leftLength = partials.length,
  4849. args = Array(leftLength + argsLength),
  4850. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4851. while (++leftIndex < leftLength) {
  4852. args[leftIndex] = partials[leftIndex];
  4853. }
  4854. while (argsLength--) {
  4855. args[leftIndex++] = arguments[++argsIndex];
  4856. }
  4857. return apply(fn, isBind ? thisArg : this, args);
  4858. }
  4859. return wrapper;
  4860. }
  4861. /**
  4862. * Creates a `_.range` or `_.rangeRight` function.
  4863. *
  4864. * @private
  4865. * @param {boolean} [fromRight] Specify iterating from right to left.
  4866. * @returns {Function} Returns the new range function.
  4867. */
  4868. function createRange(fromRight) {
  4869. return function(start, end, step) {
  4870. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4871. end = step = undefined;
  4872. }
  4873. // Ensure the sign of `-0` is preserved.
  4874. start = toFinite(start);
  4875. if (end === undefined) {
  4876. end = start;
  4877. start = 0;
  4878. } else {
  4879. end = toFinite(end);
  4880. }
  4881. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4882. return baseRange(start, end, step, fromRight);
  4883. };
  4884. }
  4885. /**
  4886. * Creates a function that performs a relational operation on two values.
  4887. *
  4888. * @private
  4889. * @param {Function} operator The function to perform the operation.
  4890. * @returns {Function} Returns the new relational operation function.
  4891. */
  4892. function createRelationalOperation(operator) {
  4893. return function(value, other) {
  4894. if (!(typeof value == 'string' && typeof other == 'string')) {
  4895. value = toNumber(value);
  4896. other = toNumber(other);
  4897. }
  4898. return operator(value, other);
  4899. };
  4900. }
  4901. /**
  4902. * Creates a function that wraps `func` to continue currying.
  4903. *
  4904. * @private
  4905. * @param {Function} func The function to wrap.
  4906. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4907. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4908. * @param {*} placeholder The placeholder value.
  4909. * @param {*} [thisArg] The `this` binding of `func`.
  4910. * @param {Array} [partials] The arguments to prepend to those provided to
  4911. * the new function.
  4912. * @param {Array} [holders] The `partials` placeholder indexes.
  4913. * @param {Array} [argPos] The argument positions of the new function.
  4914. * @param {number} [ary] The arity cap of `func`.
  4915. * @param {number} [arity] The arity of `func`.
  4916. * @returns {Function} Returns the new wrapped function.
  4917. */
  4918. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4919. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4920. newHolders = isCurry ? holders : undefined,
  4921. newHoldersRight = isCurry ? undefined : holders,
  4922. newPartials = isCurry ? partials : undefined,
  4923. newPartialsRight = isCurry ? undefined : partials;
  4924. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4925. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4926. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4927. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4928. }
  4929. var newData = [
  4930. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4931. newHoldersRight, argPos, ary, arity
  4932. ];
  4933. var result = wrapFunc.apply(undefined, newData);
  4934. if (isLaziable(func)) {
  4935. setData(result, newData);
  4936. }
  4937. result.placeholder = placeholder;
  4938. return setWrapToString(result, func, bitmask);
  4939. }
  4940. /**
  4941. * Creates a function like `_.round`.
  4942. *
  4943. * @private
  4944. * @param {string} methodName The name of the `Math` method to use when rounding.
  4945. * @returns {Function} Returns the new round function.
  4946. */
  4947. function createRound(methodName) {
  4948. var func = Math[methodName];
  4949. return function(number, precision) {
  4950. number = toNumber(number);
  4951. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4952. if (precision && nativeIsFinite(number)) {
  4953. // Shift with exponential notation to avoid floating-point issues.
  4954. // See [MDN](https://mdn.io/round#Examples) for more details.
  4955. var pair = (toString(number) + 'e').split('e'),
  4956. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4957. pair = (toString(value) + 'e').split('e');
  4958. return +(pair[0] + 'e' + (+pair[1] - precision));
  4959. }
  4960. return func(number);
  4961. };
  4962. }
  4963. /**
  4964. * Creates a set object of `values`.
  4965. *
  4966. * @private
  4967. * @param {Array} values The values to add to the set.
  4968. * @returns {Object} Returns the new set.
  4969. */
  4970. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4971. return new Set(values);
  4972. };
  4973. /**
  4974. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4975. *
  4976. * @private
  4977. * @param {Function} keysFunc The function to get the keys of a given object.
  4978. * @returns {Function} Returns the new pairs function.
  4979. */
  4980. function createToPairs(keysFunc) {
  4981. return function(object) {
  4982. var tag = getTag(object);
  4983. if (tag == mapTag) {
  4984. return mapToArray(object);
  4985. }
  4986. if (tag == setTag) {
  4987. return setToPairs(object);
  4988. }
  4989. return baseToPairs(object, keysFunc(object));
  4990. };
  4991. }
  4992. /**
  4993. * Creates a function that either curries or invokes `func` with optional
  4994. * `this` binding and partially applied arguments.
  4995. *
  4996. * @private
  4997. * @param {Function|string} func The function or method name to wrap.
  4998. * @param {number} bitmask The bitmask flags.
  4999. * 1 - `_.bind`
  5000. * 2 - `_.bindKey`
  5001. * 4 - `_.curry` or `_.curryRight` of a bound function
  5002. * 8 - `_.curry`
  5003. * 16 - `_.curryRight`
  5004. * 32 - `_.partial`
  5005. * 64 - `_.partialRight`
  5006. * 128 - `_.rearg`
  5007. * 256 - `_.ary`
  5008. * 512 - `_.flip`
  5009. * @param {*} [thisArg] The `this` binding of `func`.
  5010. * @param {Array} [partials] The arguments to be partially applied.
  5011. * @param {Array} [holders] The `partials` placeholder indexes.
  5012. * @param {Array} [argPos] The argument positions of the new function.
  5013. * @param {number} [ary] The arity cap of `func`.
  5014. * @param {number} [arity] The arity of `func`.
  5015. * @returns {Function} Returns the new wrapped function.
  5016. */
  5017. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5018. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5019. if (!isBindKey && typeof func != 'function') {
  5020. throw new TypeError(FUNC_ERROR_TEXT);
  5021. }
  5022. var length = partials ? partials.length : 0;
  5023. if (!length) {
  5024. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5025. partials = holders = undefined;
  5026. }
  5027. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5028. arity = arity === undefined ? arity : toInteger(arity);
  5029. length -= holders ? holders.length : 0;
  5030. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5031. var partialsRight = partials,
  5032. holdersRight = holders;
  5033. partials = holders = undefined;
  5034. }
  5035. var data = isBindKey ? undefined : getData(func);
  5036. var newData = [
  5037. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5038. argPos, ary, arity
  5039. ];
  5040. if (data) {
  5041. mergeData(newData, data);
  5042. }
  5043. func = newData[0];
  5044. bitmask = newData[1];
  5045. thisArg = newData[2];
  5046. partials = newData[3];
  5047. holders = newData[4];
  5048. arity = newData[9] = newData[9] === undefined
  5049. ? (isBindKey ? 0 : func.length)
  5050. : nativeMax(newData[9] - length, 0);
  5051. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5052. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5053. }
  5054. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5055. var result = createBind(func, bitmask, thisArg);
  5056. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5057. result = createCurry(func, bitmask, arity);
  5058. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5059. result = createPartial(func, bitmask, thisArg, partials);
  5060. } else {
  5061. result = createHybrid.apply(undefined, newData);
  5062. }
  5063. var setter = data ? baseSetData : setData;
  5064. return setWrapToString(setter(result, newData), func, bitmask);
  5065. }
  5066. /**
  5067. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5068. * of source objects to the destination object for all destination properties
  5069. * that resolve to `undefined`.
  5070. *
  5071. * @private
  5072. * @param {*} objValue The destination value.
  5073. * @param {*} srcValue The source value.
  5074. * @param {string} key The key of the property to assign.
  5075. * @param {Object} object The parent object of `objValue`.
  5076. * @returns {*} Returns the value to assign.
  5077. */
  5078. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5079. if (objValue === undefined ||
  5080. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5081. return srcValue;
  5082. }
  5083. return objValue;
  5084. }
  5085. /**
  5086. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5087. * objects into destination objects that are passed thru.
  5088. *
  5089. * @private
  5090. * @param {*} objValue The destination value.
  5091. * @param {*} srcValue The source value.
  5092. * @param {string} key The key of the property to merge.
  5093. * @param {Object} object The parent object of `objValue`.
  5094. * @param {Object} source The parent object of `srcValue`.
  5095. * @param {Object} [stack] Tracks traversed source values and their merged
  5096. * counterparts.
  5097. * @returns {*} Returns the value to assign.
  5098. */
  5099. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5100. if (isObject(objValue) && isObject(srcValue)) {
  5101. // Recursively merge objects and arrays (susceptible to call stack limits).
  5102. stack.set(srcValue, objValue);
  5103. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5104. stack['delete'](srcValue);
  5105. }
  5106. return objValue;
  5107. }
  5108. /**
  5109. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5110. * objects.
  5111. *
  5112. * @private
  5113. * @param {*} value The value to inspect.
  5114. * @param {string} key The key of the property to inspect.
  5115. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5116. */
  5117. function customOmitClone(value) {
  5118. return isPlainObject(value) ? undefined : value;
  5119. }
  5120. /**
  5121. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5122. * partial deep comparisons.
  5123. *
  5124. * @private
  5125. * @param {Array} array The array to compare.
  5126. * @param {Array} other The other array to compare.
  5127. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5128. * @param {Function} customizer The function to customize comparisons.
  5129. * @param {Function} equalFunc The function to determine equivalents of values.
  5130. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5131. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5132. */
  5133. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5134. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5135. arrLength = array.length,
  5136. othLength = other.length;
  5137. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5138. return false;
  5139. }
  5140. // Assume cyclic values are equal.
  5141. var stacked = stack.get(array);
  5142. if (stacked && stack.get(other)) {
  5143. return stacked == other;
  5144. }
  5145. var index = -1,
  5146. result = true,
  5147. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5148. stack.set(array, other);
  5149. stack.set(other, array);
  5150. // Ignore non-index properties.
  5151. while (++index < arrLength) {
  5152. var arrValue = array[index],
  5153. othValue = other[index];
  5154. if (customizer) {
  5155. var compared = isPartial
  5156. ? customizer(othValue, arrValue, index, other, array, stack)
  5157. : customizer(arrValue, othValue, index, array, other, stack);
  5158. }
  5159. if (compared !== undefined) {
  5160. if (compared) {
  5161. continue;
  5162. }
  5163. result = false;
  5164. break;
  5165. }
  5166. // Recursively compare arrays (susceptible to call stack limits).
  5167. if (seen) {
  5168. if (!arraySome(other, function(othValue, othIndex) {
  5169. if (!cacheHas(seen, othIndex) &&
  5170. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5171. return seen.push(othIndex);
  5172. }
  5173. })) {
  5174. result = false;
  5175. break;
  5176. }
  5177. } else if (!(
  5178. arrValue === othValue ||
  5179. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5180. )) {
  5181. result = false;
  5182. break;
  5183. }
  5184. }
  5185. stack['delete'](array);
  5186. stack['delete'](other);
  5187. return result;
  5188. }
  5189. /**
  5190. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5191. * the same `toStringTag`.
  5192. *
  5193. * **Note:** This function only supports comparing values with tags of
  5194. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5195. *
  5196. * @private
  5197. * @param {Object} object The object to compare.
  5198. * @param {Object} other The other object to compare.
  5199. * @param {string} tag The `toStringTag` of the objects to compare.
  5200. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5201. * @param {Function} customizer The function to customize comparisons.
  5202. * @param {Function} equalFunc The function to determine equivalents of values.
  5203. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5204. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5205. */
  5206. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5207. switch (tag) {
  5208. case dataViewTag:
  5209. if ((object.byteLength != other.byteLength) ||
  5210. (object.byteOffset != other.byteOffset)) {
  5211. return false;
  5212. }
  5213. object = object.buffer;
  5214. other = other.buffer;
  5215. case arrayBufferTag:
  5216. if ((object.byteLength != other.byteLength) ||
  5217. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5218. return false;
  5219. }
  5220. return true;
  5221. case boolTag:
  5222. case dateTag:
  5223. case numberTag:
  5224. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5225. // Invalid dates are coerced to `NaN`.
  5226. return eq(+object, +other);
  5227. case errorTag:
  5228. return object.name == other.name && object.message == other.message;
  5229. case regexpTag:
  5230. case stringTag:
  5231. // Coerce regexes to strings and treat strings, primitives and objects,
  5232. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5233. // for more details.
  5234. return object == (other + '');
  5235. case mapTag:
  5236. var convert = mapToArray;
  5237. case setTag:
  5238. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5239. convert || (convert = setToArray);
  5240. if (object.size != other.size && !isPartial) {
  5241. return false;
  5242. }
  5243. // Assume cyclic values are equal.
  5244. var stacked = stack.get(object);
  5245. if (stacked) {
  5246. return stacked == other;
  5247. }
  5248. bitmask |= COMPARE_UNORDERED_FLAG;
  5249. // Recursively compare objects (susceptible to call stack limits).
  5250. stack.set(object, other);
  5251. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5252. stack['delete'](object);
  5253. return result;
  5254. case symbolTag:
  5255. if (symbolValueOf) {
  5256. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5257. }
  5258. }
  5259. return false;
  5260. }
  5261. /**
  5262. * A specialized version of `baseIsEqualDeep` for objects with support for
  5263. * partial deep comparisons.
  5264. *
  5265. * @private
  5266. * @param {Object} object The object to compare.
  5267. * @param {Object} other The other object to compare.
  5268. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5269. * @param {Function} customizer The function to customize comparisons.
  5270. * @param {Function} equalFunc The function to determine equivalents of values.
  5271. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5272. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5273. */
  5274. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5275. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5276. objProps = getAllKeys(object),
  5277. objLength = objProps.length,
  5278. othProps = getAllKeys(other),
  5279. othLength = othProps.length;
  5280. if (objLength != othLength && !isPartial) {
  5281. return false;
  5282. }
  5283. var index = objLength;
  5284. while (index--) {
  5285. var key = objProps[index];
  5286. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5287. return false;
  5288. }
  5289. }
  5290. // Assume cyclic values are equal.
  5291. var stacked = stack.get(object);
  5292. if (stacked && stack.get(other)) {
  5293. return stacked == other;
  5294. }
  5295. var result = true;
  5296. stack.set(object, other);
  5297. stack.set(other, object);
  5298. var skipCtor = isPartial;
  5299. while (++index < objLength) {
  5300. key = objProps[index];
  5301. var objValue = object[key],
  5302. othValue = other[key];
  5303. if (customizer) {
  5304. var compared = isPartial
  5305. ? customizer(othValue, objValue, key, other, object, stack)
  5306. : customizer(objValue, othValue, key, object, other, stack);
  5307. }
  5308. // Recursively compare objects (susceptible to call stack limits).
  5309. if (!(compared === undefined
  5310. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5311. : compared
  5312. )) {
  5313. result = false;
  5314. break;
  5315. }
  5316. skipCtor || (skipCtor = key == 'constructor');
  5317. }
  5318. if (result && !skipCtor) {
  5319. var objCtor = object.constructor,
  5320. othCtor = other.constructor;
  5321. // Non `Object` object instances with different constructors are not equal.
  5322. if (objCtor != othCtor &&
  5323. ('constructor' in object && 'constructor' in other) &&
  5324. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5325. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5326. result = false;
  5327. }
  5328. }
  5329. stack['delete'](object);
  5330. stack['delete'](other);
  5331. return result;
  5332. }
  5333. /**
  5334. * A specialized version of `baseRest` which flattens the rest array.
  5335. *
  5336. * @private
  5337. * @param {Function} func The function to apply a rest parameter to.
  5338. * @returns {Function} Returns the new function.
  5339. */
  5340. function flatRest(func) {
  5341. return setToString(overRest(func, undefined, flatten), func + '');
  5342. }
  5343. /**
  5344. * Creates an array of own enumerable property names and symbols of `object`.
  5345. *
  5346. * @private
  5347. * @param {Object} object The object to query.
  5348. * @returns {Array} Returns the array of property names and symbols.
  5349. */
  5350. function getAllKeys(object) {
  5351. return baseGetAllKeys(object, keys, getSymbols);
  5352. }
  5353. /**
  5354. * Creates an array of own and inherited enumerable property names and
  5355. * symbols of `object`.
  5356. *
  5357. * @private
  5358. * @param {Object} object The object to query.
  5359. * @returns {Array} Returns the array of property names and symbols.
  5360. */
  5361. function getAllKeysIn(object) {
  5362. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5363. }
  5364. /**
  5365. * Gets metadata for `func`.
  5366. *
  5367. * @private
  5368. * @param {Function} func The function to query.
  5369. * @returns {*} Returns the metadata for `func`.
  5370. */
  5371. var getData = !metaMap ? noop : function(func) {
  5372. return metaMap.get(func);
  5373. };
  5374. /**
  5375. * Gets the name of `func`.
  5376. *
  5377. * @private
  5378. * @param {Function} func The function to query.
  5379. * @returns {string} Returns the function name.
  5380. */
  5381. function getFuncName(func) {
  5382. var result = (func.name + ''),
  5383. array = realNames[result],
  5384. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5385. while (length--) {
  5386. var data = array[length],
  5387. otherFunc = data.func;
  5388. if (otherFunc == null || otherFunc == func) {
  5389. return data.name;
  5390. }
  5391. }
  5392. return result;
  5393. }
  5394. /**
  5395. * Gets the argument placeholder value for `func`.
  5396. *
  5397. * @private
  5398. * @param {Function} func The function to inspect.
  5399. * @returns {*} Returns the placeholder value.
  5400. */
  5401. function getHolder(func) {
  5402. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5403. return object.placeholder;
  5404. }
  5405. /**
  5406. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5407. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5408. * If arguments are provided, the chosen function is invoked with them and
  5409. * its result is returned.
  5410. *
  5411. * @private
  5412. * @param {*} [value] The value to convert to an iteratee.
  5413. * @param {number} [arity] The arity of the created iteratee.
  5414. * @returns {Function} Returns the chosen function or its result.
  5415. */
  5416. function getIteratee() {
  5417. var result = lodash.iteratee || iteratee;
  5418. result = result === iteratee ? baseIteratee : result;
  5419. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5420. }
  5421. /**
  5422. * Gets the data for `map`.
  5423. *
  5424. * @private
  5425. * @param {Object} map The map to query.
  5426. * @param {string} key The reference key.
  5427. * @returns {*} Returns the map data.
  5428. */
  5429. function getMapData(map, key) {
  5430. var data = map.__data__;
  5431. return isKeyable(key)
  5432. ? data[typeof key == 'string' ? 'string' : 'hash']
  5433. : data.map;
  5434. }
  5435. /**
  5436. * Gets the property names, values, and compare flags of `object`.
  5437. *
  5438. * @private
  5439. * @param {Object} object The object to query.
  5440. * @returns {Array} Returns the match data of `object`.
  5441. */
  5442. function getMatchData(object) {
  5443. var result = keys(object),
  5444. length = result.length;
  5445. while (length--) {
  5446. var key = result[length],
  5447. value = object[key];
  5448. result[length] = [key, value, isStrictComparable(value)];
  5449. }
  5450. return result;
  5451. }
  5452. /**
  5453. * Gets the native function at `key` of `object`.
  5454. *
  5455. * @private
  5456. * @param {Object} object The object to query.
  5457. * @param {string} key The key of the method to get.
  5458. * @returns {*} Returns the function if it's native, else `undefined`.
  5459. */
  5460. function getNative(object, key) {
  5461. var value = getValue(object, key);
  5462. return baseIsNative(value) ? value : undefined;
  5463. }
  5464. /**
  5465. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5466. *
  5467. * @private
  5468. * @param {*} value The value to query.
  5469. * @returns {string} Returns the raw `toStringTag`.
  5470. */
  5471. function getRawTag(value) {
  5472. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5473. tag = value[symToStringTag];
  5474. try {
  5475. value[symToStringTag] = undefined;
  5476. var unmasked = true;
  5477. } catch (e) {}
  5478. var result = nativeObjectToString.call(value);
  5479. if (unmasked) {
  5480. if (isOwn) {
  5481. value[symToStringTag] = tag;
  5482. } else {
  5483. delete value[symToStringTag];
  5484. }
  5485. }
  5486. return result;
  5487. }
  5488. /**
  5489. * Creates an array of the own enumerable symbols of `object`.
  5490. *
  5491. * @private
  5492. * @param {Object} object The object to query.
  5493. * @returns {Array} Returns the array of symbols.
  5494. */
  5495. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5496. if (object == null) {
  5497. return [];
  5498. }
  5499. object = Object(object);
  5500. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5501. return propertyIsEnumerable.call(object, symbol);
  5502. });
  5503. };
  5504. /**
  5505. * Creates an array of the own and inherited enumerable symbols of `object`.
  5506. *
  5507. * @private
  5508. * @param {Object} object The object to query.
  5509. * @returns {Array} Returns the array of symbols.
  5510. */
  5511. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5512. var result = [];
  5513. while (object) {
  5514. arrayPush(result, getSymbols(object));
  5515. object = getPrototype(object);
  5516. }
  5517. return result;
  5518. };
  5519. /**
  5520. * Gets the `toStringTag` of `value`.
  5521. *
  5522. * @private
  5523. * @param {*} value The value to query.
  5524. * @returns {string} Returns the `toStringTag`.
  5525. */
  5526. var getTag = baseGetTag;
  5527. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5528. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5529. (Map && getTag(new Map) != mapTag) ||
  5530. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5531. (Set && getTag(new Set) != setTag) ||
  5532. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5533. getTag = function(value) {
  5534. var result = baseGetTag(value),
  5535. Ctor = result == objectTag ? value.constructor : undefined,
  5536. ctorString = Ctor ? toSource(Ctor) : '';
  5537. if (ctorString) {
  5538. switch (ctorString) {
  5539. case dataViewCtorString: return dataViewTag;
  5540. case mapCtorString: return mapTag;
  5541. case promiseCtorString: return promiseTag;
  5542. case setCtorString: return setTag;
  5543. case weakMapCtorString: return weakMapTag;
  5544. }
  5545. }
  5546. return result;
  5547. };
  5548. }
  5549. /**
  5550. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5551. *
  5552. * @private
  5553. * @param {number} start The start of the view.
  5554. * @param {number} end The end of the view.
  5555. * @param {Array} transforms The transformations to apply to the view.
  5556. * @returns {Object} Returns an object containing the `start` and `end`
  5557. * positions of the view.
  5558. */
  5559. function getView(start, end, transforms) {
  5560. var index = -1,
  5561. length = transforms.length;
  5562. while (++index < length) {
  5563. var data = transforms[index],
  5564. size = data.size;
  5565. switch (data.type) {
  5566. case 'drop': start += size; break;
  5567. case 'dropRight': end -= size; break;
  5568. case 'take': end = nativeMin(end, start + size); break;
  5569. case 'takeRight': start = nativeMax(start, end - size); break;
  5570. }
  5571. }
  5572. return { 'start': start, 'end': end };
  5573. }
  5574. /**
  5575. * Extracts wrapper details from the `source` body comment.
  5576. *
  5577. * @private
  5578. * @param {string} source The source to inspect.
  5579. * @returns {Array} Returns the wrapper details.
  5580. */
  5581. function getWrapDetails(source) {
  5582. var match = source.match(reWrapDetails);
  5583. return match ? match[1].split(reSplitDetails) : [];
  5584. }
  5585. /**
  5586. * Checks if `path` exists on `object`.
  5587. *
  5588. * @private
  5589. * @param {Object} object The object to query.
  5590. * @param {Array|string} path The path to check.
  5591. * @param {Function} hasFunc The function to check properties.
  5592. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5593. */
  5594. function hasPath(object, path, hasFunc) {
  5595. path = castPath(path, object);
  5596. var index = -1,
  5597. length = path.length,
  5598. result = false;
  5599. while (++index < length) {
  5600. var key = toKey(path[index]);
  5601. if (!(result = object != null && hasFunc(object, key))) {
  5602. break;
  5603. }
  5604. object = object[key];
  5605. }
  5606. if (result || ++index != length) {
  5607. return result;
  5608. }
  5609. length = object == null ? 0 : object.length;
  5610. return !!length && isLength(length) && isIndex(key, length) &&
  5611. (isArray(object) || isArguments(object));
  5612. }
  5613. /**
  5614. * Initializes an array clone.
  5615. *
  5616. * @private
  5617. * @param {Array} array The array to clone.
  5618. * @returns {Array} Returns the initialized clone.
  5619. */
  5620. function initCloneArray(array) {
  5621. var length = array.length,
  5622. result = new array.constructor(length);
  5623. // Add properties assigned by `RegExp#exec`.
  5624. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5625. result.index = array.index;
  5626. result.input = array.input;
  5627. }
  5628. return result;
  5629. }
  5630. /**
  5631. * Initializes an object clone.
  5632. *
  5633. * @private
  5634. * @param {Object} object The object to clone.
  5635. * @returns {Object} Returns the initialized clone.
  5636. */
  5637. function initCloneObject(object) {
  5638. return (typeof object.constructor == 'function' && !isPrototype(object))
  5639. ? baseCreate(getPrototype(object))
  5640. : {};
  5641. }
  5642. /**
  5643. * Initializes an object clone based on its `toStringTag`.
  5644. *
  5645. * **Note:** This function only supports cloning values with tags of
  5646. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5647. *
  5648. * @private
  5649. * @param {Object} object The object to clone.
  5650. * @param {string} tag The `toStringTag` of the object to clone.
  5651. * @param {boolean} [isDeep] Specify a deep clone.
  5652. * @returns {Object} Returns the initialized clone.
  5653. */
  5654. function initCloneByTag(object, tag, isDeep) {
  5655. var Ctor = object.constructor;
  5656. switch (tag) {
  5657. case arrayBufferTag:
  5658. return cloneArrayBuffer(object);
  5659. case boolTag:
  5660. case dateTag:
  5661. return new Ctor(+object);
  5662. case dataViewTag:
  5663. return cloneDataView(object, isDeep);
  5664. case float32Tag: case float64Tag:
  5665. case int8Tag: case int16Tag: case int32Tag:
  5666. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5667. return cloneTypedArray(object, isDeep);
  5668. case mapTag:
  5669. return new Ctor;
  5670. case numberTag:
  5671. case stringTag:
  5672. return new Ctor(object);
  5673. case regexpTag:
  5674. return cloneRegExp(object);
  5675. case setTag:
  5676. return new Ctor;
  5677. case symbolTag:
  5678. return cloneSymbol(object);
  5679. }
  5680. }
  5681. /**
  5682. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5683. *
  5684. * @private
  5685. * @param {string} source The source to modify.
  5686. * @returns {Array} details The details to insert.
  5687. * @returns {string} Returns the modified source.
  5688. */
  5689. function insertWrapDetails(source, details) {
  5690. var length = details.length;
  5691. if (!length) {
  5692. return source;
  5693. }
  5694. var lastIndex = length - 1;
  5695. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5696. details = details.join(length > 2 ? ', ' : ' ');
  5697. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5698. }
  5699. /**
  5700. * Checks if `value` is a flattenable `arguments` object or array.
  5701. *
  5702. * @private
  5703. * @param {*} value The value to check.
  5704. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5705. */
  5706. function isFlattenable(value) {
  5707. return isArray(value) || isArguments(value) ||
  5708. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5709. }
  5710. /**
  5711. * Checks if `value` is a valid array-like index.
  5712. *
  5713. * @private
  5714. * @param {*} value The value to check.
  5715. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5716. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5717. */
  5718. function isIndex(value, length) {
  5719. var type = typeof value;
  5720. length = length == null ? MAX_SAFE_INTEGER : length;
  5721. return !!length &&
  5722. (type == 'number' ||
  5723. (type != 'symbol' && reIsUint.test(value))) &&
  5724. (value > -1 && value % 1 == 0 && value < length);
  5725. }
  5726. /**
  5727. * Checks if the given arguments are from an iteratee call.
  5728. *
  5729. * @private
  5730. * @param {*} value The potential iteratee value argument.
  5731. * @param {*} index The potential iteratee index or key argument.
  5732. * @param {*} object The potential iteratee object argument.
  5733. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5734. * else `false`.
  5735. */
  5736. function isIterateeCall(value, index, object) {
  5737. if (!isObject(object)) {
  5738. return false;
  5739. }
  5740. var type = typeof index;
  5741. if (type == 'number'
  5742. ? (isArrayLike(object) && isIndex(index, object.length))
  5743. : (type == 'string' && index in object)
  5744. ) {
  5745. return eq(object[index], value);
  5746. }
  5747. return false;
  5748. }
  5749. /**
  5750. * Checks if `value` is a property name and not a property path.
  5751. *
  5752. * @private
  5753. * @param {*} value The value to check.
  5754. * @param {Object} [object] The object to query keys on.
  5755. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5756. */
  5757. function isKey(value, object) {
  5758. if (isArray(value)) {
  5759. return false;
  5760. }
  5761. var type = typeof value;
  5762. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5763. value == null || isSymbol(value)) {
  5764. return true;
  5765. }
  5766. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5767. (object != null && value in Object(object));
  5768. }
  5769. /**
  5770. * Checks if `value` is suitable for use as unique object key.
  5771. *
  5772. * @private
  5773. * @param {*} value The value to check.
  5774. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5775. */
  5776. function isKeyable(value) {
  5777. var type = typeof value;
  5778. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5779. ? (value !== '__proto__')
  5780. : (value === null);
  5781. }
  5782. /**
  5783. * Checks if `func` has a lazy counterpart.
  5784. *
  5785. * @private
  5786. * @param {Function} func The function to check.
  5787. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5788. * else `false`.
  5789. */
  5790. function isLaziable(func) {
  5791. var funcName = getFuncName(func),
  5792. other = lodash[funcName];
  5793. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5794. return false;
  5795. }
  5796. if (func === other) {
  5797. return true;
  5798. }
  5799. var data = getData(other);
  5800. return !!data && func === data[0];
  5801. }
  5802. /**
  5803. * Checks if `func` has its source masked.
  5804. *
  5805. * @private
  5806. * @param {Function} func The function to check.
  5807. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5808. */
  5809. function isMasked(func) {
  5810. return !!maskSrcKey && (maskSrcKey in func);
  5811. }
  5812. /**
  5813. * Checks if `func` is capable of being masked.
  5814. *
  5815. * @private
  5816. * @param {*} value The value to check.
  5817. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5818. */
  5819. var isMaskable = coreJsData ? isFunction : stubFalse;
  5820. /**
  5821. * Checks if `value` is likely a prototype object.
  5822. *
  5823. * @private
  5824. * @param {*} value The value to check.
  5825. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5826. */
  5827. function isPrototype(value) {
  5828. var Ctor = value && value.constructor,
  5829. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5830. return value === proto;
  5831. }
  5832. /**
  5833. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5834. *
  5835. * @private
  5836. * @param {*} value The value to check.
  5837. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5838. * equality comparisons, else `false`.
  5839. */
  5840. function isStrictComparable(value) {
  5841. return value === value && !isObject(value);
  5842. }
  5843. /**
  5844. * A specialized version of `matchesProperty` for source values suitable
  5845. * for strict equality comparisons, i.e. `===`.
  5846. *
  5847. * @private
  5848. * @param {string} key The key of the property to get.
  5849. * @param {*} srcValue The value to match.
  5850. * @returns {Function} Returns the new spec function.
  5851. */
  5852. function matchesStrictComparable(key, srcValue) {
  5853. return function(object) {
  5854. if (object == null) {
  5855. return false;
  5856. }
  5857. return object[key] === srcValue &&
  5858. (srcValue !== undefined || (key in Object(object)));
  5859. };
  5860. }
  5861. /**
  5862. * A specialized version of `_.memoize` which clears the memoized function's
  5863. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5864. *
  5865. * @private
  5866. * @param {Function} func The function to have its output memoized.
  5867. * @returns {Function} Returns the new memoized function.
  5868. */
  5869. function memoizeCapped(func) {
  5870. var result = memoize(func, function(key) {
  5871. if (cache.size === MAX_MEMOIZE_SIZE) {
  5872. cache.clear();
  5873. }
  5874. return key;
  5875. });
  5876. var cache = result.cache;
  5877. return result;
  5878. }
  5879. /**
  5880. * Merges the function metadata of `source` into `data`.
  5881. *
  5882. * Merging metadata reduces the number of wrappers used to invoke a function.
  5883. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5884. * may be applied regardless of execution order. Methods like `_.ary` and
  5885. * `_.rearg` modify function arguments, making the order in which they are
  5886. * executed important, preventing the merging of metadata. However, we make
  5887. * an exception for a safe combined case where curried functions have `_.ary`
  5888. * and or `_.rearg` applied.
  5889. *
  5890. * @private
  5891. * @param {Array} data The destination metadata.
  5892. * @param {Array} source The source metadata.
  5893. * @returns {Array} Returns `data`.
  5894. */
  5895. function mergeData(data, source) {
  5896. var bitmask = data[1],
  5897. srcBitmask = source[1],
  5898. newBitmask = bitmask | srcBitmask,
  5899. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5900. var isCombo =
  5901. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5902. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5903. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5904. // Exit early if metadata can't be merged.
  5905. if (!(isCommon || isCombo)) {
  5906. return data;
  5907. }
  5908. // Use source `thisArg` if available.
  5909. if (srcBitmask & WRAP_BIND_FLAG) {
  5910. data[2] = source[2];
  5911. // Set when currying a bound function.
  5912. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5913. }
  5914. // Compose partial arguments.
  5915. var value = source[3];
  5916. if (value) {
  5917. var partials = data[3];
  5918. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5919. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5920. }
  5921. // Compose partial right arguments.
  5922. value = source[5];
  5923. if (value) {
  5924. partials = data[5];
  5925. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5926. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5927. }
  5928. // Use source `argPos` if available.
  5929. value = source[7];
  5930. if (value) {
  5931. data[7] = value;
  5932. }
  5933. // Use source `ary` if it's smaller.
  5934. if (srcBitmask & WRAP_ARY_FLAG) {
  5935. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5936. }
  5937. // Use source `arity` if one is not provided.
  5938. if (data[9] == null) {
  5939. data[9] = source[9];
  5940. }
  5941. // Use source `func` and merge bitmasks.
  5942. data[0] = source[0];
  5943. data[1] = newBitmask;
  5944. return data;
  5945. }
  5946. /**
  5947. * This function is like
  5948. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5949. * except that it includes inherited enumerable properties.
  5950. *
  5951. * @private
  5952. * @param {Object} object The object to query.
  5953. * @returns {Array} Returns the array of property names.
  5954. */
  5955. function nativeKeysIn(object) {
  5956. var result = [];
  5957. if (object != null) {
  5958. for (var key in Object(object)) {
  5959. result.push(key);
  5960. }
  5961. }
  5962. return result;
  5963. }
  5964. /**
  5965. * Converts `value` to a string using `Object.prototype.toString`.
  5966. *
  5967. * @private
  5968. * @param {*} value The value to convert.
  5969. * @returns {string} Returns the converted string.
  5970. */
  5971. function objectToString(value) {
  5972. return nativeObjectToString.call(value);
  5973. }
  5974. /**
  5975. * A specialized version of `baseRest` which transforms the rest array.
  5976. *
  5977. * @private
  5978. * @param {Function} func The function to apply a rest parameter to.
  5979. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5980. * @param {Function} transform The rest array transform.
  5981. * @returns {Function} Returns the new function.
  5982. */
  5983. function overRest(func, start, transform) {
  5984. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5985. return function() {
  5986. var args = arguments,
  5987. index = -1,
  5988. length = nativeMax(args.length - start, 0),
  5989. array = Array(length);
  5990. while (++index < length) {
  5991. array[index] = args[start + index];
  5992. }
  5993. index = -1;
  5994. var otherArgs = Array(start + 1);
  5995. while (++index < start) {
  5996. otherArgs[index] = args[index];
  5997. }
  5998. otherArgs[start] = transform(array);
  5999. return apply(func, this, otherArgs);
  6000. };
  6001. }
  6002. /**
  6003. * Gets the parent value at `path` of `object`.
  6004. *
  6005. * @private
  6006. * @param {Object} object The object to query.
  6007. * @param {Array} path The path to get the parent value of.
  6008. * @returns {*} Returns the parent value.
  6009. */
  6010. function parent(object, path) {
  6011. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6012. }
  6013. /**
  6014. * Reorder `array` according to the specified indexes where the element at
  6015. * the first index is assigned as the first element, the element at
  6016. * the second index is assigned as the second element, and so on.
  6017. *
  6018. * @private
  6019. * @param {Array} array The array to reorder.
  6020. * @param {Array} indexes The arranged array indexes.
  6021. * @returns {Array} Returns `array`.
  6022. */
  6023. function reorder(array, indexes) {
  6024. var arrLength = array.length,
  6025. length = nativeMin(indexes.length, arrLength),
  6026. oldArray = copyArray(array);
  6027. while (length--) {
  6028. var index = indexes[length];
  6029. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6030. }
  6031. return array;
  6032. }
  6033. /**
  6034. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6035. *
  6036. * @private
  6037. * @param {Object} object The object to query.
  6038. * @param {string} key The key of the property to get.
  6039. * @returns {*} Returns the property value.
  6040. */
  6041. function safeGet(object, key) {
  6042. if (key === 'constructor' && typeof object[key] === 'function') {
  6043. return;
  6044. }
  6045. if (key == '__proto__') {
  6046. return;
  6047. }
  6048. return object[key];
  6049. }
  6050. /**
  6051. * Sets metadata for `func`.
  6052. *
  6053. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6054. * period of time, it will trip its breaker and transition to an identity
  6055. * function to avoid garbage collection pauses in V8. See
  6056. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6057. * for more details.
  6058. *
  6059. * @private
  6060. * @param {Function} func The function to associate metadata with.
  6061. * @param {*} data The metadata.
  6062. * @returns {Function} Returns `func`.
  6063. */
  6064. var setData = shortOut(baseSetData);
  6065. /**
  6066. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6067. *
  6068. * @private
  6069. * @param {Function} func The function to delay.
  6070. * @param {number} wait The number of milliseconds to delay invocation.
  6071. * @returns {number|Object} Returns the timer id or timeout object.
  6072. */
  6073. var setTimeout = ctxSetTimeout || function(func, wait) {
  6074. return root.setTimeout(func, wait);
  6075. };
  6076. /**
  6077. * Sets the `toString` method of `func` to return `string`.
  6078. *
  6079. * @private
  6080. * @param {Function} func The function to modify.
  6081. * @param {Function} string The `toString` result.
  6082. * @returns {Function} Returns `func`.
  6083. */
  6084. var setToString = shortOut(baseSetToString);
  6085. /**
  6086. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6087. * with wrapper details in a comment at the top of the source body.
  6088. *
  6089. * @private
  6090. * @param {Function} wrapper The function to modify.
  6091. * @param {Function} reference The reference function.
  6092. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6093. * @returns {Function} Returns `wrapper`.
  6094. */
  6095. function setWrapToString(wrapper, reference, bitmask) {
  6096. var source = (reference + '');
  6097. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6098. }
  6099. /**
  6100. * Creates a function that'll short out and invoke `identity` instead
  6101. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6102. * milliseconds.
  6103. *
  6104. * @private
  6105. * @param {Function} func The function to restrict.
  6106. * @returns {Function} Returns the new shortable function.
  6107. */
  6108. function shortOut(func) {
  6109. var count = 0,
  6110. lastCalled = 0;
  6111. return function() {
  6112. var stamp = nativeNow(),
  6113. remaining = HOT_SPAN - (stamp - lastCalled);
  6114. lastCalled = stamp;
  6115. if (remaining > 0) {
  6116. if (++count >= HOT_COUNT) {
  6117. return arguments[0];
  6118. }
  6119. } else {
  6120. count = 0;
  6121. }
  6122. return func.apply(undefined, arguments);
  6123. };
  6124. }
  6125. /**
  6126. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6127. *
  6128. * @private
  6129. * @param {Array} array The array to shuffle.
  6130. * @param {number} [size=array.length] The size of `array`.
  6131. * @returns {Array} Returns `array`.
  6132. */
  6133. function shuffleSelf(array, size) {
  6134. var index = -1,
  6135. length = array.length,
  6136. lastIndex = length - 1;
  6137. size = size === undefined ? length : size;
  6138. while (++index < size) {
  6139. var rand = baseRandom(index, lastIndex),
  6140. value = array[rand];
  6141. array[rand] = array[index];
  6142. array[index] = value;
  6143. }
  6144. array.length = size;
  6145. return array;
  6146. }
  6147. /**
  6148. * Converts `string` to a property path array.
  6149. *
  6150. * @private
  6151. * @param {string} string The string to convert.
  6152. * @returns {Array} Returns the property path array.
  6153. */
  6154. var stringToPath = memoizeCapped(function(string) {
  6155. var result = [];
  6156. if (string.charCodeAt(0) === 46 /* . */) {
  6157. result.push('');
  6158. }
  6159. string.replace(rePropName, function(match, number, quote, subString) {
  6160. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6161. });
  6162. return result;
  6163. });
  6164. /**
  6165. * Converts `value` to a string key if it's not a string or symbol.
  6166. *
  6167. * @private
  6168. * @param {*} value The value to inspect.
  6169. * @returns {string|symbol} Returns the key.
  6170. */
  6171. function toKey(value) {
  6172. if (typeof value == 'string' || isSymbol(value)) {
  6173. return value;
  6174. }
  6175. var result = (value + '');
  6176. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6177. }
  6178. /**
  6179. * Converts `func` to its source code.
  6180. *
  6181. * @private
  6182. * @param {Function} func The function to convert.
  6183. * @returns {string} Returns the source code.
  6184. */
  6185. function toSource(func) {
  6186. if (func != null) {
  6187. try {
  6188. return funcToString.call(func);
  6189. } catch (e) {}
  6190. try {
  6191. return (func + '');
  6192. } catch (e) {}
  6193. }
  6194. return '';
  6195. }
  6196. /**
  6197. * Updates wrapper `details` based on `bitmask` flags.
  6198. *
  6199. * @private
  6200. * @returns {Array} details The details to modify.
  6201. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6202. * @returns {Array} Returns `details`.
  6203. */
  6204. function updateWrapDetails(details, bitmask) {
  6205. arrayEach(wrapFlags, function(pair) {
  6206. var value = '_.' + pair[0];
  6207. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6208. details.push(value);
  6209. }
  6210. });
  6211. return details.sort();
  6212. }
  6213. /**
  6214. * Creates a clone of `wrapper`.
  6215. *
  6216. * @private
  6217. * @param {Object} wrapper The wrapper to clone.
  6218. * @returns {Object} Returns the cloned wrapper.
  6219. */
  6220. function wrapperClone(wrapper) {
  6221. if (wrapper instanceof LazyWrapper) {
  6222. return wrapper.clone();
  6223. }
  6224. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6225. result.__actions__ = copyArray(wrapper.__actions__);
  6226. result.__index__ = wrapper.__index__;
  6227. result.__values__ = wrapper.__values__;
  6228. return result;
  6229. }
  6230. /*------------------------------------------------------------------------*/
  6231. /**
  6232. * Creates an array of elements split into groups the length of `size`.
  6233. * If `array` can't be split evenly, the final chunk will be the remaining
  6234. * elements.
  6235. *
  6236. * @static
  6237. * @memberOf _
  6238. * @since 3.0.0
  6239. * @category Array
  6240. * @param {Array} array The array to process.
  6241. * @param {number} [size=1] The length of each chunk
  6242. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6243. * @returns {Array} Returns the new array of chunks.
  6244. * @example
  6245. *
  6246. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6247. * // => [['a', 'b'], ['c', 'd']]
  6248. *
  6249. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6250. * // => [['a', 'b', 'c'], ['d']]
  6251. */
  6252. function chunk(array, size, guard) {
  6253. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6254. size = 1;
  6255. } else {
  6256. size = nativeMax(toInteger(size), 0);
  6257. }
  6258. var length = array == null ? 0 : array.length;
  6259. if (!length || size < 1) {
  6260. return [];
  6261. }
  6262. var index = 0,
  6263. resIndex = 0,
  6264. result = Array(nativeCeil(length / size));
  6265. while (index < length) {
  6266. result[resIndex++] = baseSlice(array, index, (index += size));
  6267. }
  6268. return result;
  6269. }
  6270. /**
  6271. * Creates an array with all falsey values removed. The values `false`, `null`,
  6272. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6273. *
  6274. * @static
  6275. * @memberOf _
  6276. * @since 0.1.0
  6277. * @category Array
  6278. * @param {Array} array The array to compact.
  6279. * @returns {Array} Returns the new array of filtered values.
  6280. * @example
  6281. *
  6282. * _.compact([0, 1, false, 2, '', 3]);
  6283. * // => [1, 2, 3]
  6284. */
  6285. function compact(array) {
  6286. var index = -1,
  6287. length = array == null ? 0 : array.length,
  6288. resIndex = 0,
  6289. result = [];
  6290. while (++index < length) {
  6291. var value = array[index];
  6292. if (value) {
  6293. result[resIndex++] = value;
  6294. }
  6295. }
  6296. return result;
  6297. }
  6298. /**
  6299. * Creates a new array concatenating `array` with any additional arrays
  6300. * and/or values.
  6301. *
  6302. * @static
  6303. * @memberOf _
  6304. * @since 4.0.0
  6305. * @category Array
  6306. * @param {Array} array The array to concatenate.
  6307. * @param {...*} [values] The values to concatenate.
  6308. * @returns {Array} Returns the new concatenated array.
  6309. * @example
  6310. *
  6311. * var array = [1];
  6312. * var other = _.concat(array, 2, [3], [[4]]);
  6313. *
  6314. * console.log(other);
  6315. * // => [1, 2, 3, [4]]
  6316. *
  6317. * console.log(array);
  6318. * // => [1]
  6319. */
  6320. function concat() {
  6321. var length = arguments.length;
  6322. if (!length) {
  6323. return [];
  6324. }
  6325. var args = Array(length - 1),
  6326. array = arguments[0],
  6327. index = length;
  6328. while (index--) {
  6329. args[index - 1] = arguments[index];
  6330. }
  6331. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6332. }
  6333. /**
  6334. * Creates an array of `array` values not included in the other given arrays
  6335. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6336. * for equality comparisons. The order and references of result values are
  6337. * determined by the first array.
  6338. *
  6339. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6340. *
  6341. * @static
  6342. * @memberOf _
  6343. * @since 0.1.0
  6344. * @category Array
  6345. * @param {Array} array The array to inspect.
  6346. * @param {...Array} [values] The values to exclude.
  6347. * @returns {Array} Returns the new array of filtered values.
  6348. * @see _.without, _.xor
  6349. * @example
  6350. *
  6351. * _.difference([2, 1], [2, 3]);
  6352. * // => [1]
  6353. */
  6354. var difference = baseRest(function(array, values) {
  6355. return isArrayLikeObject(array)
  6356. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6357. : [];
  6358. });
  6359. /**
  6360. * This method is like `_.difference` except that it accepts `iteratee` which
  6361. * is invoked for each element of `array` and `values` to generate the criterion
  6362. * by which they're compared. The order and references of result values are
  6363. * determined by the first array. The iteratee is invoked with one argument:
  6364. * (value).
  6365. *
  6366. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6367. *
  6368. * @static
  6369. * @memberOf _
  6370. * @since 4.0.0
  6371. * @category Array
  6372. * @param {Array} array The array to inspect.
  6373. * @param {...Array} [values] The values to exclude.
  6374. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6375. * @returns {Array} Returns the new array of filtered values.
  6376. * @example
  6377. *
  6378. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6379. * // => [1.2]
  6380. *
  6381. * // The `_.property` iteratee shorthand.
  6382. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6383. * // => [{ 'x': 2 }]
  6384. */
  6385. var differenceBy = baseRest(function(array, values) {
  6386. var iteratee = last(values);
  6387. if (isArrayLikeObject(iteratee)) {
  6388. iteratee = undefined;
  6389. }
  6390. return isArrayLikeObject(array)
  6391. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6392. : [];
  6393. });
  6394. /**
  6395. * This method is like `_.difference` except that it accepts `comparator`
  6396. * which is invoked to compare elements of `array` to `values`. The order and
  6397. * references of result values are determined by the first array. The comparator
  6398. * is invoked with two arguments: (arrVal, othVal).
  6399. *
  6400. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6401. *
  6402. * @static
  6403. * @memberOf _
  6404. * @since 4.0.0
  6405. * @category Array
  6406. * @param {Array} array The array to inspect.
  6407. * @param {...Array} [values] The values to exclude.
  6408. * @param {Function} [comparator] The comparator invoked per element.
  6409. * @returns {Array} Returns the new array of filtered values.
  6410. * @example
  6411. *
  6412. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6413. *
  6414. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6415. * // => [{ 'x': 2, 'y': 1 }]
  6416. */
  6417. var differenceWith = baseRest(function(array, values) {
  6418. var comparator = last(values);
  6419. if (isArrayLikeObject(comparator)) {
  6420. comparator = undefined;
  6421. }
  6422. return isArrayLikeObject(array)
  6423. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6424. : [];
  6425. });
  6426. /**
  6427. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6428. *
  6429. * @static
  6430. * @memberOf _
  6431. * @since 0.5.0
  6432. * @category Array
  6433. * @param {Array} array The array to query.
  6434. * @param {number} [n=1] The number of elements to drop.
  6435. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6436. * @returns {Array} Returns the slice of `array`.
  6437. * @example
  6438. *
  6439. * _.drop([1, 2, 3]);
  6440. * // => [2, 3]
  6441. *
  6442. * _.drop([1, 2, 3], 2);
  6443. * // => [3]
  6444. *
  6445. * _.drop([1, 2, 3], 5);
  6446. * // => []
  6447. *
  6448. * _.drop([1, 2, 3], 0);
  6449. * // => [1, 2, 3]
  6450. */
  6451. function drop(array, n, guard) {
  6452. var length = array == null ? 0 : array.length;
  6453. if (!length) {
  6454. return [];
  6455. }
  6456. n = (guard || n === undefined) ? 1 : toInteger(n);
  6457. return baseSlice(array, n < 0 ? 0 : n, length);
  6458. }
  6459. /**
  6460. * Creates a slice of `array` with `n` elements dropped from the end.
  6461. *
  6462. * @static
  6463. * @memberOf _
  6464. * @since 3.0.0
  6465. * @category Array
  6466. * @param {Array} array The array to query.
  6467. * @param {number} [n=1] The number of elements to drop.
  6468. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6469. * @returns {Array} Returns the slice of `array`.
  6470. * @example
  6471. *
  6472. * _.dropRight([1, 2, 3]);
  6473. * // => [1, 2]
  6474. *
  6475. * _.dropRight([1, 2, 3], 2);
  6476. * // => [1]
  6477. *
  6478. * _.dropRight([1, 2, 3], 5);
  6479. * // => []
  6480. *
  6481. * _.dropRight([1, 2, 3], 0);
  6482. * // => [1, 2, 3]
  6483. */
  6484. function dropRight(array, n, guard) {
  6485. var length = array == null ? 0 : array.length;
  6486. if (!length) {
  6487. return [];
  6488. }
  6489. n = (guard || n === undefined) ? 1 : toInteger(n);
  6490. n = length - n;
  6491. return baseSlice(array, 0, n < 0 ? 0 : n);
  6492. }
  6493. /**
  6494. * Creates a slice of `array` excluding elements dropped from the end.
  6495. * Elements are dropped until `predicate` returns falsey. The predicate is
  6496. * invoked with three arguments: (value, index, array).
  6497. *
  6498. * @static
  6499. * @memberOf _
  6500. * @since 3.0.0
  6501. * @category Array
  6502. * @param {Array} array The array to query.
  6503. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6504. * @returns {Array} Returns the slice of `array`.
  6505. * @example
  6506. *
  6507. * var users = [
  6508. * { 'user': 'barney', 'active': true },
  6509. * { 'user': 'fred', 'active': false },
  6510. * { 'user': 'pebbles', 'active': false }
  6511. * ];
  6512. *
  6513. * _.dropRightWhile(users, function(o) { return !o.active; });
  6514. * // => objects for ['barney']
  6515. *
  6516. * // The `_.matches` iteratee shorthand.
  6517. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6518. * // => objects for ['barney', 'fred']
  6519. *
  6520. * // The `_.matchesProperty` iteratee shorthand.
  6521. * _.dropRightWhile(users, ['active', false]);
  6522. * // => objects for ['barney']
  6523. *
  6524. * // The `_.property` iteratee shorthand.
  6525. * _.dropRightWhile(users, 'active');
  6526. * // => objects for ['barney', 'fred', 'pebbles']
  6527. */
  6528. function dropRightWhile(array, predicate) {
  6529. return (array && array.length)
  6530. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6531. : [];
  6532. }
  6533. /**
  6534. * Creates a slice of `array` excluding elements dropped from the beginning.
  6535. * Elements are dropped until `predicate` returns falsey. The predicate is
  6536. * invoked with three arguments: (value, index, array).
  6537. *
  6538. * @static
  6539. * @memberOf _
  6540. * @since 3.0.0
  6541. * @category Array
  6542. * @param {Array} array The array to query.
  6543. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6544. * @returns {Array} Returns the slice of `array`.
  6545. * @example
  6546. *
  6547. * var users = [
  6548. * { 'user': 'barney', 'active': false },
  6549. * { 'user': 'fred', 'active': false },
  6550. * { 'user': 'pebbles', 'active': true }
  6551. * ];
  6552. *
  6553. * _.dropWhile(users, function(o) { return !o.active; });
  6554. * // => objects for ['pebbles']
  6555. *
  6556. * // The `_.matches` iteratee shorthand.
  6557. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6558. * // => objects for ['fred', 'pebbles']
  6559. *
  6560. * // The `_.matchesProperty` iteratee shorthand.
  6561. * _.dropWhile(users, ['active', false]);
  6562. * // => objects for ['pebbles']
  6563. *
  6564. * // The `_.property` iteratee shorthand.
  6565. * _.dropWhile(users, 'active');
  6566. * // => objects for ['barney', 'fred', 'pebbles']
  6567. */
  6568. function dropWhile(array, predicate) {
  6569. return (array && array.length)
  6570. ? baseWhile(array, getIteratee(predicate, 3), true)
  6571. : [];
  6572. }
  6573. /**
  6574. * Fills elements of `array` with `value` from `start` up to, but not
  6575. * including, `end`.
  6576. *
  6577. * **Note:** This method mutates `array`.
  6578. *
  6579. * @static
  6580. * @memberOf _
  6581. * @since 3.2.0
  6582. * @category Array
  6583. * @param {Array} array The array to fill.
  6584. * @param {*} value The value to fill `array` with.
  6585. * @param {number} [start=0] The start position.
  6586. * @param {number} [end=array.length] The end position.
  6587. * @returns {Array} Returns `array`.
  6588. * @example
  6589. *
  6590. * var array = [1, 2, 3];
  6591. *
  6592. * _.fill(array, 'a');
  6593. * console.log(array);
  6594. * // => ['a', 'a', 'a']
  6595. *
  6596. * _.fill(Array(3), 2);
  6597. * // => [2, 2, 2]
  6598. *
  6599. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6600. * // => [4, '*', '*', 10]
  6601. */
  6602. function fill(array, value, start, end) {
  6603. var length = array == null ? 0 : array.length;
  6604. if (!length) {
  6605. return [];
  6606. }
  6607. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6608. start = 0;
  6609. end = length;
  6610. }
  6611. return baseFill(array, value, start, end);
  6612. }
  6613. /**
  6614. * This method is like `_.find` except that it returns the index of the first
  6615. * element `predicate` returns truthy for instead of the element itself.
  6616. *
  6617. * @static
  6618. * @memberOf _
  6619. * @since 1.1.0
  6620. * @category Array
  6621. * @param {Array} array The array to inspect.
  6622. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6623. * @param {number} [fromIndex=0] The index to search from.
  6624. * @returns {number} Returns the index of the found element, else `-1`.
  6625. * @example
  6626. *
  6627. * var users = [
  6628. * { 'user': 'barney', 'active': false },
  6629. * { 'user': 'fred', 'active': false },
  6630. * { 'user': 'pebbles', 'active': true }
  6631. * ];
  6632. *
  6633. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6634. * // => 0
  6635. *
  6636. * // The `_.matches` iteratee shorthand.
  6637. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6638. * // => 1
  6639. *
  6640. * // The `_.matchesProperty` iteratee shorthand.
  6641. * _.findIndex(users, ['active', false]);
  6642. * // => 0
  6643. *
  6644. * // The `_.property` iteratee shorthand.
  6645. * _.findIndex(users, 'active');
  6646. * // => 2
  6647. */
  6648. function findIndex(array, predicate, fromIndex) {
  6649. var length = array == null ? 0 : array.length;
  6650. if (!length) {
  6651. return -1;
  6652. }
  6653. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6654. if (index < 0) {
  6655. index = nativeMax(length + index, 0);
  6656. }
  6657. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6658. }
  6659. /**
  6660. * This method is like `_.findIndex` except that it iterates over elements
  6661. * of `collection` from right to left.
  6662. *
  6663. * @static
  6664. * @memberOf _
  6665. * @since 2.0.0
  6666. * @category Array
  6667. * @param {Array} array The array to inspect.
  6668. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6669. * @param {number} [fromIndex=array.length-1] The index to search from.
  6670. * @returns {number} Returns the index of the found element, else `-1`.
  6671. * @example
  6672. *
  6673. * var users = [
  6674. * { 'user': 'barney', 'active': true },
  6675. * { 'user': 'fred', 'active': false },
  6676. * { 'user': 'pebbles', 'active': false }
  6677. * ];
  6678. *
  6679. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6680. * // => 2
  6681. *
  6682. * // The `_.matches` iteratee shorthand.
  6683. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6684. * // => 0
  6685. *
  6686. * // The `_.matchesProperty` iteratee shorthand.
  6687. * _.findLastIndex(users, ['active', false]);
  6688. * // => 2
  6689. *
  6690. * // The `_.property` iteratee shorthand.
  6691. * _.findLastIndex(users, 'active');
  6692. * // => 0
  6693. */
  6694. function findLastIndex(array, predicate, fromIndex) {
  6695. var length = array == null ? 0 : array.length;
  6696. if (!length) {
  6697. return -1;
  6698. }
  6699. var index = length - 1;
  6700. if (fromIndex !== undefined) {
  6701. index = toInteger(fromIndex);
  6702. index = fromIndex < 0
  6703. ? nativeMax(length + index, 0)
  6704. : nativeMin(index, length - 1);
  6705. }
  6706. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6707. }
  6708. /**
  6709. * Flattens `array` a single level deep.
  6710. *
  6711. * @static
  6712. * @memberOf _
  6713. * @since 0.1.0
  6714. * @category Array
  6715. * @param {Array} array The array to flatten.
  6716. * @returns {Array} Returns the new flattened array.
  6717. * @example
  6718. *
  6719. * _.flatten([1, [2, [3, [4]], 5]]);
  6720. * // => [1, 2, [3, [4]], 5]
  6721. */
  6722. function flatten(array) {
  6723. var length = array == null ? 0 : array.length;
  6724. return length ? baseFlatten(array, 1) : [];
  6725. }
  6726. /**
  6727. * Recursively flattens `array`.
  6728. *
  6729. * @static
  6730. * @memberOf _
  6731. * @since 3.0.0
  6732. * @category Array
  6733. * @param {Array} array The array to flatten.
  6734. * @returns {Array} Returns the new flattened array.
  6735. * @example
  6736. *
  6737. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6738. * // => [1, 2, 3, 4, 5]
  6739. */
  6740. function flattenDeep(array) {
  6741. var length = array == null ? 0 : array.length;
  6742. return length ? baseFlatten(array, INFINITY) : [];
  6743. }
  6744. /**
  6745. * Recursively flatten `array` up to `depth` times.
  6746. *
  6747. * @static
  6748. * @memberOf _
  6749. * @since 4.4.0
  6750. * @category Array
  6751. * @param {Array} array The array to flatten.
  6752. * @param {number} [depth=1] The maximum recursion depth.
  6753. * @returns {Array} Returns the new flattened array.
  6754. * @example
  6755. *
  6756. * var array = [1, [2, [3, [4]], 5]];
  6757. *
  6758. * _.flattenDepth(array, 1);
  6759. * // => [1, 2, [3, [4]], 5]
  6760. *
  6761. * _.flattenDepth(array, 2);
  6762. * // => [1, 2, 3, [4], 5]
  6763. */
  6764. function flattenDepth(array, depth) {
  6765. var length = array == null ? 0 : array.length;
  6766. if (!length) {
  6767. return [];
  6768. }
  6769. depth = depth === undefined ? 1 : toInteger(depth);
  6770. return baseFlatten(array, depth);
  6771. }
  6772. /**
  6773. * The inverse of `_.toPairs`; this method returns an object composed
  6774. * from key-value `pairs`.
  6775. *
  6776. * @static
  6777. * @memberOf _
  6778. * @since 4.0.0
  6779. * @category Array
  6780. * @param {Array} pairs The key-value pairs.
  6781. * @returns {Object} Returns the new object.
  6782. * @example
  6783. *
  6784. * _.fromPairs([['a', 1], ['b', 2]]);
  6785. * // => { 'a': 1, 'b': 2 }
  6786. */
  6787. function fromPairs(pairs) {
  6788. var index = -1,
  6789. length = pairs == null ? 0 : pairs.length,
  6790. result = {};
  6791. while (++index < length) {
  6792. var pair = pairs[index];
  6793. result[pair[0]] = pair[1];
  6794. }
  6795. return result;
  6796. }
  6797. /**
  6798. * Gets the first element of `array`.
  6799. *
  6800. * @static
  6801. * @memberOf _
  6802. * @since 0.1.0
  6803. * @alias first
  6804. * @category Array
  6805. * @param {Array} array The array to query.
  6806. * @returns {*} Returns the first element of `array`.
  6807. * @example
  6808. *
  6809. * _.head([1, 2, 3]);
  6810. * // => 1
  6811. *
  6812. * _.head([]);
  6813. * // => undefined
  6814. */
  6815. function head(array) {
  6816. return (array && array.length) ? array[0] : undefined;
  6817. }
  6818. /**
  6819. * Gets the index at which the first occurrence of `value` is found in `array`
  6820. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6821. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6822. * offset from the end of `array`.
  6823. *
  6824. * @static
  6825. * @memberOf _
  6826. * @since 0.1.0
  6827. * @category Array
  6828. * @param {Array} array The array to inspect.
  6829. * @param {*} value The value to search for.
  6830. * @param {number} [fromIndex=0] The index to search from.
  6831. * @returns {number} Returns the index of the matched value, else `-1`.
  6832. * @example
  6833. *
  6834. * _.indexOf([1, 2, 1, 2], 2);
  6835. * // => 1
  6836. *
  6837. * // Search from the `fromIndex`.
  6838. * _.indexOf([1, 2, 1, 2], 2, 2);
  6839. * // => 3
  6840. */
  6841. function indexOf(array, value, fromIndex) {
  6842. var length = array == null ? 0 : array.length;
  6843. if (!length) {
  6844. return -1;
  6845. }
  6846. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6847. if (index < 0) {
  6848. index = nativeMax(length + index, 0);
  6849. }
  6850. return baseIndexOf(array, value, index);
  6851. }
  6852. /**
  6853. * Gets all but the last element of `array`.
  6854. *
  6855. * @static
  6856. * @memberOf _
  6857. * @since 0.1.0
  6858. * @category Array
  6859. * @param {Array} array The array to query.
  6860. * @returns {Array} Returns the slice of `array`.
  6861. * @example
  6862. *
  6863. * _.initial([1, 2, 3]);
  6864. * // => [1, 2]
  6865. */
  6866. function initial(array) {
  6867. var length = array == null ? 0 : array.length;
  6868. return length ? baseSlice(array, 0, -1) : [];
  6869. }
  6870. /**
  6871. * Creates an array of unique values that are included in all given arrays
  6872. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6873. * for equality comparisons. The order and references of result values are
  6874. * determined by the first array.
  6875. *
  6876. * @static
  6877. * @memberOf _
  6878. * @since 0.1.0
  6879. * @category Array
  6880. * @param {...Array} [arrays] The arrays to inspect.
  6881. * @returns {Array} Returns the new array of intersecting values.
  6882. * @example
  6883. *
  6884. * _.intersection([2, 1], [2, 3]);
  6885. * // => [2]
  6886. */
  6887. var intersection = baseRest(function(arrays) {
  6888. var mapped = arrayMap(arrays, castArrayLikeObject);
  6889. return (mapped.length && mapped[0] === arrays[0])
  6890. ? baseIntersection(mapped)
  6891. : [];
  6892. });
  6893. /**
  6894. * This method is like `_.intersection` except that it accepts `iteratee`
  6895. * which is invoked for each element of each `arrays` to generate the criterion
  6896. * by which they're compared. The order and references of result values are
  6897. * determined by the first array. The iteratee is invoked with one argument:
  6898. * (value).
  6899. *
  6900. * @static
  6901. * @memberOf _
  6902. * @since 4.0.0
  6903. * @category Array
  6904. * @param {...Array} [arrays] The arrays to inspect.
  6905. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6906. * @returns {Array} Returns the new array of intersecting values.
  6907. * @example
  6908. *
  6909. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6910. * // => [2.1]
  6911. *
  6912. * // The `_.property` iteratee shorthand.
  6913. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6914. * // => [{ 'x': 1 }]
  6915. */
  6916. var intersectionBy = baseRest(function(arrays) {
  6917. var iteratee = last(arrays),
  6918. mapped = arrayMap(arrays, castArrayLikeObject);
  6919. if (iteratee === last(mapped)) {
  6920. iteratee = undefined;
  6921. } else {
  6922. mapped.pop();
  6923. }
  6924. return (mapped.length && mapped[0] === arrays[0])
  6925. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6926. : [];
  6927. });
  6928. /**
  6929. * This method is like `_.intersection` except that it accepts `comparator`
  6930. * which is invoked to compare elements of `arrays`. The order and references
  6931. * of result values are determined by the first array. The comparator is
  6932. * invoked with two arguments: (arrVal, othVal).
  6933. *
  6934. * @static
  6935. * @memberOf _
  6936. * @since 4.0.0
  6937. * @category Array
  6938. * @param {...Array} [arrays] The arrays to inspect.
  6939. * @param {Function} [comparator] The comparator invoked per element.
  6940. * @returns {Array} Returns the new array of intersecting values.
  6941. * @example
  6942. *
  6943. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6944. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6945. *
  6946. * _.intersectionWith(objects, others, _.isEqual);
  6947. * // => [{ 'x': 1, 'y': 2 }]
  6948. */
  6949. var intersectionWith = baseRest(function(arrays) {
  6950. var comparator = last(arrays),
  6951. mapped = arrayMap(arrays, castArrayLikeObject);
  6952. comparator = typeof comparator == 'function' ? comparator : undefined;
  6953. if (comparator) {
  6954. mapped.pop();
  6955. }
  6956. return (mapped.length && mapped[0] === arrays[0])
  6957. ? baseIntersection(mapped, undefined, comparator)
  6958. : [];
  6959. });
  6960. /**
  6961. * Converts all elements in `array` into a string separated by `separator`.
  6962. *
  6963. * @static
  6964. * @memberOf _
  6965. * @since 4.0.0
  6966. * @category Array
  6967. * @param {Array} array The array to convert.
  6968. * @param {string} [separator=','] The element separator.
  6969. * @returns {string} Returns the joined string.
  6970. * @example
  6971. *
  6972. * _.join(['a', 'b', 'c'], '~');
  6973. * // => 'a~b~c'
  6974. */
  6975. function join(array, separator) {
  6976. return array == null ? '' : nativeJoin.call(array, separator);
  6977. }
  6978. /**
  6979. * Gets the last element of `array`.
  6980. *
  6981. * @static
  6982. * @memberOf _
  6983. * @since 0.1.0
  6984. * @category Array
  6985. * @param {Array} array The array to query.
  6986. * @returns {*} Returns the last element of `array`.
  6987. * @example
  6988. *
  6989. * _.last([1, 2, 3]);
  6990. * // => 3
  6991. */
  6992. function last(array) {
  6993. var length = array == null ? 0 : array.length;
  6994. return length ? array[length - 1] : undefined;
  6995. }
  6996. /**
  6997. * This method is like `_.indexOf` except that it iterates over elements of
  6998. * `array` from right to left.
  6999. *
  7000. * @static
  7001. * @memberOf _
  7002. * @since 0.1.0
  7003. * @category Array
  7004. * @param {Array} array The array to inspect.
  7005. * @param {*} value The value to search for.
  7006. * @param {number} [fromIndex=array.length-1] The index to search from.
  7007. * @returns {number} Returns the index of the matched value, else `-1`.
  7008. * @example
  7009. *
  7010. * _.lastIndexOf([1, 2, 1, 2], 2);
  7011. * // => 3
  7012. *
  7013. * // Search from the `fromIndex`.
  7014. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7015. * // => 1
  7016. */
  7017. function lastIndexOf(array, value, fromIndex) {
  7018. var length = array == null ? 0 : array.length;
  7019. if (!length) {
  7020. return -1;
  7021. }
  7022. var index = length;
  7023. if (fromIndex !== undefined) {
  7024. index = toInteger(fromIndex);
  7025. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7026. }
  7027. return value === value
  7028. ? strictLastIndexOf(array, value, index)
  7029. : baseFindIndex(array, baseIsNaN, index, true);
  7030. }
  7031. /**
  7032. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7033. * element from the end is returned.
  7034. *
  7035. * @static
  7036. * @memberOf _
  7037. * @since 4.11.0
  7038. * @category Array
  7039. * @param {Array} array The array to query.
  7040. * @param {number} [n=0] The index of the element to return.
  7041. * @returns {*} Returns the nth element of `array`.
  7042. * @example
  7043. *
  7044. * var array = ['a', 'b', 'c', 'd'];
  7045. *
  7046. * _.nth(array, 1);
  7047. * // => 'b'
  7048. *
  7049. * _.nth(array, -2);
  7050. * // => 'c';
  7051. */
  7052. function nth(array, n) {
  7053. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7054. }
  7055. /**
  7056. * Removes all given values from `array` using
  7057. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7058. * for equality comparisons.
  7059. *
  7060. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7061. * to remove elements from an array by predicate.
  7062. *
  7063. * @static
  7064. * @memberOf _
  7065. * @since 2.0.0
  7066. * @category Array
  7067. * @param {Array} array The array to modify.
  7068. * @param {...*} [values] The values to remove.
  7069. * @returns {Array} Returns `array`.
  7070. * @example
  7071. *
  7072. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7073. *
  7074. * _.pull(array, 'a', 'c');
  7075. * console.log(array);
  7076. * // => ['b', 'b']
  7077. */
  7078. var pull = baseRest(pullAll);
  7079. /**
  7080. * This method is like `_.pull` except that it accepts an array of values to remove.
  7081. *
  7082. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7083. *
  7084. * @static
  7085. * @memberOf _
  7086. * @since 4.0.0
  7087. * @category Array
  7088. * @param {Array} array The array to modify.
  7089. * @param {Array} values The values to remove.
  7090. * @returns {Array} Returns `array`.
  7091. * @example
  7092. *
  7093. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7094. *
  7095. * _.pullAll(array, ['a', 'c']);
  7096. * console.log(array);
  7097. * // => ['b', 'b']
  7098. */
  7099. function pullAll(array, values) {
  7100. return (array && array.length && values && values.length)
  7101. ? basePullAll(array, values)
  7102. : array;
  7103. }
  7104. /**
  7105. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7106. * invoked for each element of `array` and `values` to generate the criterion
  7107. * by which they're compared. The iteratee is invoked with one argument: (value).
  7108. *
  7109. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7110. *
  7111. * @static
  7112. * @memberOf _
  7113. * @since 4.0.0
  7114. * @category Array
  7115. * @param {Array} array The array to modify.
  7116. * @param {Array} values The values to remove.
  7117. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7118. * @returns {Array} Returns `array`.
  7119. * @example
  7120. *
  7121. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7122. *
  7123. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7124. * console.log(array);
  7125. * // => [{ 'x': 2 }]
  7126. */
  7127. function pullAllBy(array, values, iteratee) {
  7128. return (array && array.length && values && values.length)
  7129. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7130. : array;
  7131. }
  7132. /**
  7133. * This method is like `_.pullAll` except that it accepts `comparator` which
  7134. * is invoked to compare elements of `array` to `values`. The comparator is
  7135. * invoked with two arguments: (arrVal, othVal).
  7136. *
  7137. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7138. *
  7139. * @static
  7140. * @memberOf _
  7141. * @since 4.6.0
  7142. * @category Array
  7143. * @param {Array} array The array to modify.
  7144. * @param {Array} values The values to remove.
  7145. * @param {Function} [comparator] The comparator invoked per element.
  7146. * @returns {Array} Returns `array`.
  7147. * @example
  7148. *
  7149. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7150. *
  7151. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7152. * console.log(array);
  7153. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7154. */
  7155. function pullAllWith(array, values, comparator) {
  7156. return (array && array.length && values && values.length)
  7157. ? basePullAll(array, values, undefined, comparator)
  7158. : array;
  7159. }
  7160. /**
  7161. * Removes elements from `array` corresponding to `indexes` and returns an
  7162. * array of removed elements.
  7163. *
  7164. * **Note:** Unlike `_.at`, this method mutates `array`.
  7165. *
  7166. * @static
  7167. * @memberOf _
  7168. * @since 3.0.0
  7169. * @category Array
  7170. * @param {Array} array The array to modify.
  7171. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7172. * @returns {Array} Returns the new array of removed elements.
  7173. * @example
  7174. *
  7175. * var array = ['a', 'b', 'c', 'd'];
  7176. * var pulled = _.pullAt(array, [1, 3]);
  7177. *
  7178. * console.log(array);
  7179. * // => ['a', 'c']
  7180. *
  7181. * console.log(pulled);
  7182. * // => ['b', 'd']
  7183. */
  7184. var pullAt = flatRest(function(array, indexes) {
  7185. var length = array == null ? 0 : array.length,
  7186. result = baseAt(array, indexes);
  7187. basePullAt(array, arrayMap(indexes, function(index) {
  7188. return isIndex(index, length) ? +index : index;
  7189. }).sort(compareAscending));
  7190. return result;
  7191. });
  7192. /**
  7193. * Removes all elements from `array` that `predicate` returns truthy for
  7194. * and returns an array of the removed elements. The predicate is invoked
  7195. * with three arguments: (value, index, array).
  7196. *
  7197. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7198. * to pull elements from an array by value.
  7199. *
  7200. * @static
  7201. * @memberOf _
  7202. * @since 2.0.0
  7203. * @category Array
  7204. * @param {Array} array The array to modify.
  7205. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7206. * @returns {Array} Returns the new array of removed elements.
  7207. * @example
  7208. *
  7209. * var array = [1, 2, 3, 4];
  7210. * var evens = _.remove(array, function(n) {
  7211. * return n % 2 == 0;
  7212. * });
  7213. *
  7214. * console.log(array);
  7215. * // => [1, 3]
  7216. *
  7217. * console.log(evens);
  7218. * // => [2, 4]
  7219. */
  7220. function remove(array, predicate) {
  7221. var result = [];
  7222. if (!(array && array.length)) {
  7223. return result;
  7224. }
  7225. var index = -1,
  7226. indexes = [],
  7227. length = array.length;
  7228. predicate = getIteratee(predicate, 3);
  7229. while (++index < length) {
  7230. var value = array[index];
  7231. if (predicate(value, index, array)) {
  7232. result.push(value);
  7233. indexes.push(index);
  7234. }
  7235. }
  7236. basePullAt(array, indexes);
  7237. return result;
  7238. }
  7239. /**
  7240. * Reverses `array` so that the first element becomes the last, the second
  7241. * element becomes the second to last, and so on.
  7242. *
  7243. * **Note:** This method mutates `array` and is based on
  7244. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7245. *
  7246. * @static
  7247. * @memberOf _
  7248. * @since 4.0.0
  7249. * @category Array
  7250. * @param {Array} array The array to modify.
  7251. * @returns {Array} Returns `array`.
  7252. * @example
  7253. *
  7254. * var array = [1, 2, 3];
  7255. *
  7256. * _.reverse(array);
  7257. * // => [3, 2, 1]
  7258. *
  7259. * console.log(array);
  7260. * // => [3, 2, 1]
  7261. */
  7262. function reverse(array) {
  7263. return array == null ? array : nativeReverse.call(array);
  7264. }
  7265. /**
  7266. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7267. *
  7268. * **Note:** This method is used instead of
  7269. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7270. * returned.
  7271. *
  7272. * @static
  7273. * @memberOf _
  7274. * @since 3.0.0
  7275. * @category Array
  7276. * @param {Array} array The array to slice.
  7277. * @param {number} [start=0] The start position.
  7278. * @param {number} [end=array.length] The end position.
  7279. * @returns {Array} Returns the slice of `array`.
  7280. */
  7281. function slice(array, start, end) {
  7282. var length = array == null ? 0 : array.length;
  7283. if (!length) {
  7284. return [];
  7285. }
  7286. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7287. start = 0;
  7288. end = length;
  7289. }
  7290. else {
  7291. start = start == null ? 0 : toInteger(start);
  7292. end = end === undefined ? length : toInteger(end);
  7293. }
  7294. return baseSlice(array, start, end);
  7295. }
  7296. /**
  7297. * Uses a binary search to determine the lowest index at which `value`
  7298. * should be inserted into `array` in order to maintain its sort order.
  7299. *
  7300. * @static
  7301. * @memberOf _
  7302. * @since 0.1.0
  7303. * @category Array
  7304. * @param {Array} array The sorted array to inspect.
  7305. * @param {*} value The value to evaluate.
  7306. * @returns {number} Returns the index at which `value` should be inserted
  7307. * into `array`.
  7308. * @example
  7309. *
  7310. * _.sortedIndex([30, 50], 40);
  7311. * // => 1
  7312. */
  7313. function sortedIndex(array, value) {
  7314. return baseSortedIndex(array, value);
  7315. }
  7316. /**
  7317. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7318. * which is invoked for `value` and each element of `array` to compute their
  7319. * sort ranking. The iteratee is invoked with one argument: (value).
  7320. *
  7321. * @static
  7322. * @memberOf _
  7323. * @since 4.0.0
  7324. * @category Array
  7325. * @param {Array} array The sorted array to inspect.
  7326. * @param {*} value The value to evaluate.
  7327. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7328. * @returns {number} Returns the index at which `value` should be inserted
  7329. * into `array`.
  7330. * @example
  7331. *
  7332. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7333. *
  7334. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7335. * // => 0
  7336. *
  7337. * // The `_.property` iteratee shorthand.
  7338. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7339. * // => 0
  7340. */
  7341. function sortedIndexBy(array, value, iteratee) {
  7342. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7343. }
  7344. /**
  7345. * This method is like `_.indexOf` except that it performs a binary
  7346. * search on a sorted `array`.
  7347. *
  7348. * @static
  7349. * @memberOf _
  7350. * @since 4.0.0
  7351. * @category Array
  7352. * @param {Array} array The array to inspect.
  7353. * @param {*} value The value to search for.
  7354. * @returns {number} Returns the index of the matched value, else `-1`.
  7355. * @example
  7356. *
  7357. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7358. * // => 1
  7359. */
  7360. function sortedIndexOf(array, value) {
  7361. var length = array == null ? 0 : array.length;
  7362. if (length) {
  7363. var index = baseSortedIndex(array, value);
  7364. if (index < length && eq(array[index], value)) {
  7365. return index;
  7366. }
  7367. }
  7368. return -1;
  7369. }
  7370. /**
  7371. * This method is like `_.sortedIndex` except that it returns the highest
  7372. * index at which `value` should be inserted into `array` in order to
  7373. * maintain its sort order.
  7374. *
  7375. * @static
  7376. * @memberOf _
  7377. * @since 3.0.0
  7378. * @category Array
  7379. * @param {Array} array The sorted array to inspect.
  7380. * @param {*} value The value to evaluate.
  7381. * @returns {number} Returns the index at which `value` should be inserted
  7382. * into `array`.
  7383. * @example
  7384. *
  7385. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7386. * // => 4
  7387. */
  7388. function sortedLastIndex(array, value) {
  7389. return baseSortedIndex(array, value, true);
  7390. }
  7391. /**
  7392. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7393. * which is invoked for `value` and each element of `array` to compute their
  7394. * sort ranking. The iteratee is invoked with one argument: (value).
  7395. *
  7396. * @static
  7397. * @memberOf _
  7398. * @since 4.0.0
  7399. * @category Array
  7400. * @param {Array} array The sorted array to inspect.
  7401. * @param {*} value The value to evaluate.
  7402. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7403. * @returns {number} Returns the index at which `value` should be inserted
  7404. * into `array`.
  7405. * @example
  7406. *
  7407. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7408. *
  7409. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7410. * // => 1
  7411. *
  7412. * // The `_.property` iteratee shorthand.
  7413. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7414. * // => 1
  7415. */
  7416. function sortedLastIndexBy(array, value, iteratee) {
  7417. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7418. }
  7419. /**
  7420. * This method is like `_.lastIndexOf` except that it performs a binary
  7421. * search on a sorted `array`.
  7422. *
  7423. * @static
  7424. * @memberOf _
  7425. * @since 4.0.0
  7426. * @category Array
  7427. * @param {Array} array The array to inspect.
  7428. * @param {*} value The value to search for.
  7429. * @returns {number} Returns the index of the matched value, else `-1`.
  7430. * @example
  7431. *
  7432. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7433. * // => 3
  7434. */
  7435. function sortedLastIndexOf(array, value) {
  7436. var length = array == null ? 0 : array.length;
  7437. if (length) {
  7438. var index = baseSortedIndex(array, value, true) - 1;
  7439. if (eq(array[index], value)) {
  7440. return index;
  7441. }
  7442. }
  7443. return -1;
  7444. }
  7445. /**
  7446. * This method is like `_.uniq` except that it's designed and optimized
  7447. * for sorted arrays.
  7448. *
  7449. * @static
  7450. * @memberOf _
  7451. * @since 4.0.0
  7452. * @category Array
  7453. * @param {Array} array The array to inspect.
  7454. * @returns {Array} Returns the new duplicate free array.
  7455. * @example
  7456. *
  7457. * _.sortedUniq([1, 1, 2]);
  7458. * // => [1, 2]
  7459. */
  7460. function sortedUniq(array) {
  7461. return (array && array.length)
  7462. ? baseSortedUniq(array)
  7463. : [];
  7464. }
  7465. /**
  7466. * This method is like `_.uniqBy` except that it's designed and optimized
  7467. * for sorted arrays.
  7468. *
  7469. * @static
  7470. * @memberOf _
  7471. * @since 4.0.0
  7472. * @category Array
  7473. * @param {Array} array The array to inspect.
  7474. * @param {Function} [iteratee] The iteratee invoked per element.
  7475. * @returns {Array} Returns the new duplicate free array.
  7476. * @example
  7477. *
  7478. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7479. * // => [1.1, 2.3]
  7480. */
  7481. function sortedUniqBy(array, iteratee) {
  7482. return (array && array.length)
  7483. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7484. : [];
  7485. }
  7486. /**
  7487. * Gets all but the first element of `array`.
  7488. *
  7489. * @static
  7490. * @memberOf _
  7491. * @since 4.0.0
  7492. * @category Array
  7493. * @param {Array} array The array to query.
  7494. * @returns {Array} Returns the slice of `array`.
  7495. * @example
  7496. *
  7497. * _.tail([1, 2, 3]);
  7498. * // => [2, 3]
  7499. */
  7500. function tail(array) {
  7501. var length = array == null ? 0 : array.length;
  7502. return length ? baseSlice(array, 1, length) : [];
  7503. }
  7504. /**
  7505. * Creates a slice of `array` with `n` elements taken from the beginning.
  7506. *
  7507. * @static
  7508. * @memberOf _
  7509. * @since 0.1.0
  7510. * @category Array
  7511. * @param {Array} array The array to query.
  7512. * @param {number} [n=1] The number of elements to take.
  7513. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7514. * @returns {Array} Returns the slice of `array`.
  7515. * @example
  7516. *
  7517. * _.take([1, 2, 3]);
  7518. * // => [1]
  7519. *
  7520. * _.take([1, 2, 3], 2);
  7521. * // => [1, 2]
  7522. *
  7523. * _.take([1, 2, 3], 5);
  7524. * // => [1, 2, 3]
  7525. *
  7526. * _.take([1, 2, 3], 0);
  7527. * // => []
  7528. */
  7529. function take(array, n, guard) {
  7530. if (!(array && array.length)) {
  7531. return [];
  7532. }
  7533. n = (guard || n === undefined) ? 1 : toInteger(n);
  7534. return baseSlice(array, 0, n < 0 ? 0 : n);
  7535. }
  7536. /**
  7537. * Creates a slice of `array` with `n` elements taken from the end.
  7538. *
  7539. * @static
  7540. * @memberOf _
  7541. * @since 3.0.0
  7542. * @category Array
  7543. * @param {Array} array The array to query.
  7544. * @param {number} [n=1] The number of elements to take.
  7545. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7546. * @returns {Array} Returns the slice of `array`.
  7547. * @example
  7548. *
  7549. * _.takeRight([1, 2, 3]);
  7550. * // => [3]
  7551. *
  7552. * _.takeRight([1, 2, 3], 2);
  7553. * // => [2, 3]
  7554. *
  7555. * _.takeRight([1, 2, 3], 5);
  7556. * // => [1, 2, 3]
  7557. *
  7558. * _.takeRight([1, 2, 3], 0);
  7559. * // => []
  7560. */
  7561. function takeRight(array, n, guard) {
  7562. var length = array == null ? 0 : array.length;
  7563. if (!length) {
  7564. return [];
  7565. }
  7566. n = (guard || n === undefined) ? 1 : toInteger(n);
  7567. n = length - n;
  7568. return baseSlice(array, n < 0 ? 0 : n, length);
  7569. }
  7570. /**
  7571. * Creates a slice of `array` with elements taken from the end. Elements are
  7572. * taken until `predicate` returns falsey. The predicate is invoked with
  7573. * three arguments: (value, index, array).
  7574. *
  7575. * @static
  7576. * @memberOf _
  7577. * @since 3.0.0
  7578. * @category Array
  7579. * @param {Array} array The array to query.
  7580. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7581. * @returns {Array} Returns the slice of `array`.
  7582. * @example
  7583. *
  7584. * var users = [
  7585. * { 'user': 'barney', 'active': true },
  7586. * { 'user': 'fred', 'active': false },
  7587. * { 'user': 'pebbles', 'active': false }
  7588. * ];
  7589. *
  7590. * _.takeRightWhile(users, function(o) { return !o.active; });
  7591. * // => objects for ['fred', 'pebbles']
  7592. *
  7593. * // The `_.matches` iteratee shorthand.
  7594. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7595. * // => objects for ['pebbles']
  7596. *
  7597. * // The `_.matchesProperty` iteratee shorthand.
  7598. * _.takeRightWhile(users, ['active', false]);
  7599. * // => objects for ['fred', 'pebbles']
  7600. *
  7601. * // The `_.property` iteratee shorthand.
  7602. * _.takeRightWhile(users, 'active');
  7603. * // => []
  7604. */
  7605. function takeRightWhile(array, predicate) {
  7606. return (array && array.length)
  7607. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7608. : [];
  7609. }
  7610. /**
  7611. * Creates a slice of `array` with elements taken from the beginning. Elements
  7612. * are taken until `predicate` returns falsey. The predicate is invoked with
  7613. * three arguments: (value, index, array).
  7614. *
  7615. * @static
  7616. * @memberOf _
  7617. * @since 3.0.0
  7618. * @category Array
  7619. * @param {Array} array The array to query.
  7620. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7621. * @returns {Array} Returns the slice of `array`.
  7622. * @example
  7623. *
  7624. * var users = [
  7625. * { 'user': 'barney', 'active': false },
  7626. * { 'user': 'fred', 'active': false },
  7627. * { 'user': 'pebbles', 'active': true }
  7628. * ];
  7629. *
  7630. * _.takeWhile(users, function(o) { return !o.active; });
  7631. * // => objects for ['barney', 'fred']
  7632. *
  7633. * // The `_.matches` iteratee shorthand.
  7634. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7635. * // => objects for ['barney']
  7636. *
  7637. * // The `_.matchesProperty` iteratee shorthand.
  7638. * _.takeWhile(users, ['active', false]);
  7639. * // => objects for ['barney', 'fred']
  7640. *
  7641. * // The `_.property` iteratee shorthand.
  7642. * _.takeWhile(users, 'active');
  7643. * // => []
  7644. */
  7645. function takeWhile(array, predicate) {
  7646. return (array && array.length)
  7647. ? baseWhile(array, getIteratee(predicate, 3))
  7648. : [];
  7649. }
  7650. /**
  7651. * Creates an array of unique values, in order, from all given arrays using
  7652. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7653. * for equality comparisons.
  7654. *
  7655. * @static
  7656. * @memberOf _
  7657. * @since 0.1.0
  7658. * @category Array
  7659. * @param {...Array} [arrays] The arrays to inspect.
  7660. * @returns {Array} Returns the new array of combined values.
  7661. * @example
  7662. *
  7663. * _.union([2], [1, 2]);
  7664. * // => [2, 1]
  7665. */
  7666. var union = baseRest(function(arrays) {
  7667. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7668. });
  7669. /**
  7670. * This method is like `_.union` except that it accepts `iteratee` which is
  7671. * invoked for each element of each `arrays` to generate the criterion by
  7672. * which uniqueness is computed. Result values are chosen from the first
  7673. * array in which the value occurs. The iteratee is invoked with one argument:
  7674. * (value).
  7675. *
  7676. * @static
  7677. * @memberOf _
  7678. * @since 4.0.0
  7679. * @category Array
  7680. * @param {...Array} [arrays] The arrays to inspect.
  7681. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7682. * @returns {Array} Returns the new array of combined values.
  7683. * @example
  7684. *
  7685. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7686. * // => [2.1, 1.2]
  7687. *
  7688. * // The `_.property` iteratee shorthand.
  7689. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7690. * // => [{ 'x': 1 }, { 'x': 2 }]
  7691. */
  7692. var unionBy = baseRest(function(arrays) {
  7693. var iteratee = last(arrays);
  7694. if (isArrayLikeObject(iteratee)) {
  7695. iteratee = undefined;
  7696. }
  7697. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7698. });
  7699. /**
  7700. * This method is like `_.union` except that it accepts `comparator` which
  7701. * is invoked to compare elements of `arrays`. Result values are chosen from
  7702. * the first array in which the value occurs. The comparator is invoked
  7703. * with two arguments: (arrVal, othVal).
  7704. *
  7705. * @static
  7706. * @memberOf _
  7707. * @since 4.0.0
  7708. * @category Array
  7709. * @param {...Array} [arrays] The arrays to inspect.
  7710. * @param {Function} [comparator] The comparator invoked per element.
  7711. * @returns {Array} Returns the new array of combined values.
  7712. * @example
  7713. *
  7714. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7715. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7716. *
  7717. * _.unionWith(objects, others, _.isEqual);
  7718. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7719. */
  7720. var unionWith = baseRest(function(arrays) {
  7721. var comparator = last(arrays);
  7722. comparator = typeof comparator == 'function' ? comparator : undefined;
  7723. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7724. });
  7725. /**
  7726. * Creates a duplicate-free version of an array, using
  7727. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7728. * for equality comparisons, in which only the first occurrence of each element
  7729. * is kept. The order of result values is determined by the order they occur
  7730. * in the array.
  7731. *
  7732. * @static
  7733. * @memberOf _
  7734. * @since 0.1.0
  7735. * @category Array
  7736. * @param {Array} array The array to inspect.
  7737. * @returns {Array} Returns the new duplicate free array.
  7738. * @example
  7739. *
  7740. * _.uniq([2, 1, 2]);
  7741. * // => [2, 1]
  7742. */
  7743. function uniq(array) {
  7744. return (array && array.length) ? baseUniq(array) : [];
  7745. }
  7746. /**
  7747. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7748. * invoked for each element in `array` to generate the criterion by which
  7749. * uniqueness is computed. The order of result values is determined by the
  7750. * order they occur in the array. The iteratee is invoked with one argument:
  7751. * (value).
  7752. *
  7753. * @static
  7754. * @memberOf _
  7755. * @since 4.0.0
  7756. * @category Array
  7757. * @param {Array} array The array to inspect.
  7758. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7759. * @returns {Array} Returns the new duplicate free array.
  7760. * @example
  7761. *
  7762. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7763. * // => [2.1, 1.2]
  7764. *
  7765. * // The `_.property` iteratee shorthand.
  7766. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7767. * // => [{ 'x': 1 }, { 'x': 2 }]
  7768. */
  7769. function uniqBy(array, iteratee) {
  7770. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7771. }
  7772. /**
  7773. * This method is like `_.uniq` except that it accepts `comparator` which
  7774. * is invoked to compare elements of `array`. The order of result values is
  7775. * determined by the order they occur in the array.The comparator is invoked
  7776. * with two arguments: (arrVal, othVal).
  7777. *
  7778. * @static
  7779. * @memberOf _
  7780. * @since 4.0.0
  7781. * @category Array
  7782. * @param {Array} array The array to inspect.
  7783. * @param {Function} [comparator] The comparator invoked per element.
  7784. * @returns {Array} Returns the new duplicate free array.
  7785. * @example
  7786. *
  7787. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7788. *
  7789. * _.uniqWith(objects, _.isEqual);
  7790. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7791. */
  7792. function uniqWith(array, comparator) {
  7793. comparator = typeof comparator == 'function' ? comparator : undefined;
  7794. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7795. }
  7796. /**
  7797. * This method is like `_.zip` except that it accepts an array of grouped
  7798. * elements and creates an array regrouping the elements to their pre-zip
  7799. * configuration.
  7800. *
  7801. * @static
  7802. * @memberOf _
  7803. * @since 1.2.0
  7804. * @category Array
  7805. * @param {Array} array The array of grouped elements to process.
  7806. * @returns {Array} Returns the new array of regrouped elements.
  7807. * @example
  7808. *
  7809. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7810. * // => [['a', 1, true], ['b', 2, false]]
  7811. *
  7812. * _.unzip(zipped);
  7813. * // => [['a', 'b'], [1, 2], [true, false]]
  7814. */
  7815. function unzip(array) {
  7816. if (!(array && array.length)) {
  7817. return [];
  7818. }
  7819. var length = 0;
  7820. array = arrayFilter(array, function(group) {
  7821. if (isArrayLikeObject(group)) {
  7822. length = nativeMax(group.length, length);
  7823. return true;
  7824. }
  7825. });
  7826. return baseTimes(length, function(index) {
  7827. return arrayMap(array, baseProperty(index));
  7828. });
  7829. }
  7830. /**
  7831. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7832. * how regrouped values should be combined. The iteratee is invoked with the
  7833. * elements of each group: (...group).
  7834. *
  7835. * @static
  7836. * @memberOf _
  7837. * @since 3.8.0
  7838. * @category Array
  7839. * @param {Array} array The array of grouped elements to process.
  7840. * @param {Function} [iteratee=_.identity] The function to combine
  7841. * regrouped values.
  7842. * @returns {Array} Returns the new array of regrouped elements.
  7843. * @example
  7844. *
  7845. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7846. * // => [[1, 10, 100], [2, 20, 200]]
  7847. *
  7848. * _.unzipWith(zipped, _.add);
  7849. * // => [3, 30, 300]
  7850. */
  7851. function unzipWith(array, iteratee) {
  7852. if (!(array && array.length)) {
  7853. return [];
  7854. }
  7855. var result = unzip(array);
  7856. if (iteratee == null) {
  7857. return result;
  7858. }
  7859. return arrayMap(result, function(group) {
  7860. return apply(iteratee, undefined, group);
  7861. });
  7862. }
  7863. /**
  7864. * Creates an array excluding all given values using
  7865. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7866. * for equality comparisons.
  7867. *
  7868. * **Note:** Unlike `_.pull`, this method returns a new array.
  7869. *
  7870. * @static
  7871. * @memberOf _
  7872. * @since 0.1.0
  7873. * @category Array
  7874. * @param {Array} array The array to inspect.
  7875. * @param {...*} [values] The values to exclude.
  7876. * @returns {Array} Returns the new array of filtered values.
  7877. * @see _.difference, _.xor
  7878. * @example
  7879. *
  7880. * _.without([2, 1, 2, 3], 1, 2);
  7881. * // => [3]
  7882. */
  7883. var without = baseRest(function(array, values) {
  7884. return isArrayLikeObject(array)
  7885. ? baseDifference(array, values)
  7886. : [];
  7887. });
  7888. /**
  7889. * Creates an array of unique values that is the
  7890. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7891. * of the given arrays. The order of result values is determined by the order
  7892. * they occur in the arrays.
  7893. *
  7894. * @static
  7895. * @memberOf _
  7896. * @since 2.4.0
  7897. * @category Array
  7898. * @param {...Array} [arrays] The arrays to inspect.
  7899. * @returns {Array} Returns the new array of filtered values.
  7900. * @see _.difference, _.without
  7901. * @example
  7902. *
  7903. * _.xor([2, 1], [2, 3]);
  7904. * // => [1, 3]
  7905. */
  7906. var xor = baseRest(function(arrays) {
  7907. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7908. });
  7909. /**
  7910. * This method is like `_.xor` except that it accepts `iteratee` which is
  7911. * invoked for each element of each `arrays` to generate the criterion by
  7912. * which by which they're compared. The order of result values is determined
  7913. * by the order they occur in the arrays. The iteratee is invoked with one
  7914. * argument: (value).
  7915. *
  7916. * @static
  7917. * @memberOf _
  7918. * @since 4.0.0
  7919. * @category Array
  7920. * @param {...Array} [arrays] The arrays to inspect.
  7921. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7922. * @returns {Array} Returns the new array of filtered values.
  7923. * @example
  7924. *
  7925. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7926. * // => [1.2, 3.4]
  7927. *
  7928. * // The `_.property` iteratee shorthand.
  7929. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7930. * // => [{ 'x': 2 }]
  7931. */
  7932. var xorBy = baseRest(function(arrays) {
  7933. var iteratee = last(arrays);
  7934. if (isArrayLikeObject(iteratee)) {
  7935. iteratee = undefined;
  7936. }
  7937. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7938. });
  7939. /**
  7940. * This method is like `_.xor` except that it accepts `comparator` which is
  7941. * invoked to compare elements of `arrays`. The order of result values is
  7942. * determined by the order they occur in the arrays. The comparator is invoked
  7943. * with two arguments: (arrVal, othVal).
  7944. *
  7945. * @static
  7946. * @memberOf _
  7947. * @since 4.0.0
  7948. * @category Array
  7949. * @param {...Array} [arrays] The arrays to inspect.
  7950. * @param {Function} [comparator] The comparator invoked per element.
  7951. * @returns {Array} Returns the new array of filtered values.
  7952. * @example
  7953. *
  7954. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7955. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7956. *
  7957. * _.xorWith(objects, others, _.isEqual);
  7958. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7959. */
  7960. var xorWith = baseRest(function(arrays) {
  7961. var comparator = last(arrays);
  7962. comparator = typeof comparator == 'function' ? comparator : undefined;
  7963. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7964. });
  7965. /**
  7966. * Creates an array of grouped elements, the first of which contains the
  7967. * first elements of the given arrays, the second of which contains the
  7968. * second elements of the given arrays, and so on.
  7969. *
  7970. * @static
  7971. * @memberOf _
  7972. * @since 0.1.0
  7973. * @category Array
  7974. * @param {...Array} [arrays] The arrays to process.
  7975. * @returns {Array} Returns the new array of grouped elements.
  7976. * @example
  7977. *
  7978. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7979. * // => [['a', 1, true], ['b', 2, false]]
  7980. */
  7981. var zip = baseRest(unzip);
  7982. /**
  7983. * This method is like `_.fromPairs` except that it accepts two arrays,
  7984. * one of property identifiers and one of corresponding values.
  7985. *
  7986. * @static
  7987. * @memberOf _
  7988. * @since 0.4.0
  7989. * @category Array
  7990. * @param {Array} [props=[]] The property identifiers.
  7991. * @param {Array} [values=[]] The property values.
  7992. * @returns {Object} Returns the new object.
  7993. * @example
  7994. *
  7995. * _.zipObject(['a', 'b'], [1, 2]);
  7996. * // => { 'a': 1, 'b': 2 }
  7997. */
  7998. function zipObject(props, values) {
  7999. return baseZipObject(props || [], values || [], assignValue);
  8000. }
  8001. /**
  8002. * This method is like `_.zipObject` except that it supports property paths.
  8003. *
  8004. * @static
  8005. * @memberOf _
  8006. * @since 4.1.0
  8007. * @category Array
  8008. * @param {Array} [props=[]] The property identifiers.
  8009. * @param {Array} [values=[]] The property values.
  8010. * @returns {Object} Returns the new object.
  8011. * @example
  8012. *
  8013. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8014. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8015. */
  8016. function zipObjectDeep(props, values) {
  8017. return baseZipObject(props || [], values || [], baseSet);
  8018. }
  8019. /**
  8020. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8021. * how grouped values should be combined. The iteratee is invoked with the
  8022. * elements of each group: (...group).
  8023. *
  8024. * @static
  8025. * @memberOf _
  8026. * @since 3.8.0
  8027. * @category Array
  8028. * @param {...Array} [arrays] The arrays to process.
  8029. * @param {Function} [iteratee=_.identity] The function to combine
  8030. * grouped values.
  8031. * @returns {Array} Returns the new array of grouped elements.
  8032. * @example
  8033. *
  8034. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8035. * return a + b + c;
  8036. * });
  8037. * // => [111, 222]
  8038. */
  8039. var zipWith = baseRest(function(arrays) {
  8040. var length = arrays.length,
  8041. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8042. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8043. return unzipWith(arrays, iteratee);
  8044. });
  8045. /*------------------------------------------------------------------------*/
  8046. /**
  8047. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8048. * chain sequences enabled. The result of such sequences must be unwrapped
  8049. * with `_#value`.
  8050. *
  8051. * @static
  8052. * @memberOf _
  8053. * @since 1.3.0
  8054. * @category Seq
  8055. * @param {*} value The value to wrap.
  8056. * @returns {Object} Returns the new `lodash` wrapper instance.
  8057. * @example
  8058. *
  8059. * var users = [
  8060. * { 'user': 'barney', 'age': 36 },
  8061. * { 'user': 'fred', 'age': 40 },
  8062. * { 'user': 'pebbles', 'age': 1 }
  8063. * ];
  8064. *
  8065. * var youngest = _
  8066. * .chain(users)
  8067. * .sortBy('age')
  8068. * .map(function(o) {
  8069. * return o.user + ' is ' + o.age;
  8070. * })
  8071. * .head()
  8072. * .value();
  8073. * // => 'pebbles is 1'
  8074. */
  8075. function chain(value) {
  8076. var result = lodash(value);
  8077. result.__chain__ = true;
  8078. return result;
  8079. }
  8080. /**
  8081. * This method invokes `interceptor` and returns `value`. The interceptor
  8082. * is invoked with one argument; (value). The purpose of this method is to
  8083. * "tap into" a method chain sequence in order to modify intermediate results.
  8084. *
  8085. * @static
  8086. * @memberOf _
  8087. * @since 0.1.0
  8088. * @category Seq
  8089. * @param {*} value The value to provide to `interceptor`.
  8090. * @param {Function} interceptor The function to invoke.
  8091. * @returns {*} Returns `value`.
  8092. * @example
  8093. *
  8094. * _([1, 2, 3])
  8095. * .tap(function(array) {
  8096. * // Mutate input array.
  8097. * array.pop();
  8098. * })
  8099. * .reverse()
  8100. * .value();
  8101. * // => [2, 1]
  8102. */
  8103. function tap(value, interceptor) {
  8104. interceptor(value);
  8105. return value;
  8106. }
  8107. /**
  8108. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8109. * The purpose of this method is to "pass thru" values replacing intermediate
  8110. * results in a method chain sequence.
  8111. *
  8112. * @static
  8113. * @memberOf _
  8114. * @since 3.0.0
  8115. * @category Seq
  8116. * @param {*} value The value to provide to `interceptor`.
  8117. * @param {Function} interceptor The function to invoke.
  8118. * @returns {*} Returns the result of `interceptor`.
  8119. * @example
  8120. *
  8121. * _(' abc ')
  8122. * .chain()
  8123. * .trim()
  8124. * .thru(function(value) {
  8125. * return [value];
  8126. * })
  8127. * .value();
  8128. * // => ['abc']
  8129. */
  8130. function thru(value, interceptor) {
  8131. return interceptor(value);
  8132. }
  8133. /**
  8134. * This method is the wrapper version of `_.at`.
  8135. *
  8136. * @name at
  8137. * @memberOf _
  8138. * @since 1.0.0
  8139. * @category Seq
  8140. * @param {...(string|string[])} [paths] The property paths to pick.
  8141. * @returns {Object} Returns the new `lodash` wrapper instance.
  8142. * @example
  8143. *
  8144. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8145. *
  8146. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8147. * // => [3, 4]
  8148. */
  8149. var wrapperAt = flatRest(function(paths) {
  8150. var length = paths.length,
  8151. start = length ? paths[0] : 0,
  8152. value = this.__wrapped__,
  8153. interceptor = function(object) { return baseAt(object, paths); };
  8154. if (length > 1 || this.__actions__.length ||
  8155. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8156. return this.thru(interceptor);
  8157. }
  8158. value = value.slice(start, +start + (length ? 1 : 0));
  8159. value.__actions__.push({
  8160. 'func': thru,
  8161. 'args': [interceptor],
  8162. 'thisArg': undefined
  8163. });
  8164. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8165. if (length && !array.length) {
  8166. array.push(undefined);
  8167. }
  8168. return array;
  8169. });
  8170. });
  8171. /**
  8172. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8173. *
  8174. * @name chain
  8175. * @memberOf _
  8176. * @since 0.1.0
  8177. * @category Seq
  8178. * @returns {Object} Returns the new `lodash` wrapper instance.
  8179. * @example
  8180. *
  8181. * var users = [
  8182. * { 'user': 'barney', 'age': 36 },
  8183. * { 'user': 'fred', 'age': 40 }
  8184. * ];
  8185. *
  8186. * // A sequence without explicit chaining.
  8187. * _(users).head();
  8188. * // => { 'user': 'barney', 'age': 36 }
  8189. *
  8190. * // A sequence with explicit chaining.
  8191. * _(users)
  8192. * .chain()
  8193. * .head()
  8194. * .pick('user')
  8195. * .value();
  8196. * // => { 'user': 'barney' }
  8197. */
  8198. function wrapperChain() {
  8199. return chain(this);
  8200. }
  8201. /**
  8202. * Executes the chain sequence and returns the wrapped result.
  8203. *
  8204. * @name commit
  8205. * @memberOf _
  8206. * @since 3.2.0
  8207. * @category Seq
  8208. * @returns {Object} Returns the new `lodash` wrapper instance.
  8209. * @example
  8210. *
  8211. * var array = [1, 2];
  8212. * var wrapped = _(array).push(3);
  8213. *
  8214. * console.log(array);
  8215. * // => [1, 2]
  8216. *
  8217. * wrapped = wrapped.commit();
  8218. * console.log(array);
  8219. * // => [1, 2, 3]
  8220. *
  8221. * wrapped.last();
  8222. * // => 3
  8223. *
  8224. * console.log(array);
  8225. * // => [1, 2, 3]
  8226. */
  8227. function wrapperCommit() {
  8228. return new LodashWrapper(this.value(), this.__chain__);
  8229. }
  8230. /**
  8231. * Gets the next value on a wrapped object following the
  8232. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8233. *
  8234. * @name next
  8235. * @memberOf _
  8236. * @since 4.0.0
  8237. * @category Seq
  8238. * @returns {Object} Returns the next iterator value.
  8239. * @example
  8240. *
  8241. * var wrapped = _([1, 2]);
  8242. *
  8243. * wrapped.next();
  8244. * // => { 'done': false, 'value': 1 }
  8245. *
  8246. * wrapped.next();
  8247. * // => { 'done': false, 'value': 2 }
  8248. *
  8249. * wrapped.next();
  8250. * // => { 'done': true, 'value': undefined }
  8251. */
  8252. function wrapperNext() {
  8253. if (this.__values__ === undefined) {
  8254. this.__values__ = toArray(this.value());
  8255. }
  8256. var done = this.__index__ >= this.__values__.length,
  8257. value = done ? undefined : this.__values__[this.__index__++];
  8258. return { 'done': done, 'value': value };
  8259. }
  8260. /**
  8261. * Enables the wrapper to be iterable.
  8262. *
  8263. * @name Symbol.iterator
  8264. * @memberOf _
  8265. * @since 4.0.0
  8266. * @category Seq
  8267. * @returns {Object} Returns the wrapper object.
  8268. * @example
  8269. *
  8270. * var wrapped = _([1, 2]);
  8271. *
  8272. * wrapped[Symbol.iterator]() === wrapped;
  8273. * // => true
  8274. *
  8275. * Array.from(wrapped);
  8276. * // => [1, 2]
  8277. */
  8278. function wrapperToIterator() {
  8279. return this;
  8280. }
  8281. /**
  8282. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8283. *
  8284. * @name plant
  8285. * @memberOf _
  8286. * @since 3.2.0
  8287. * @category Seq
  8288. * @param {*} value The value to plant.
  8289. * @returns {Object} Returns the new `lodash` wrapper instance.
  8290. * @example
  8291. *
  8292. * function square(n) {
  8293. * return n * n;
  8294. * }
  8295. *
  8296. * var wrapped = _([1, 2]).map(square);
  8297. * var other = wrapped.plant([3, 4]);
  8298. *
  8299. * other.value();
  8300. * // => [9, 16]
  8301. *
  8302. * wrapped.value();
  8303. * // => [1, 4]
  8304. */
  8305. function wrapperPlant(value) {
  8306. var result,
  8307. parent = this;
  8308. while (parent instanceof baseLodash) {
  8309. var clone = wrapperClone(parent);
  8310. clone.__index__ = 0;
  8311. clone.__values__ = undefined;
  8312. if (result) {
  8313. previous.__wrapped__ = clone;
  8314. } else {
  8315. result = clone;
  8316. }
  8317. var previous = clone;
  8318. parent = parent.__wrapped__;
  8319. }
  8320. previous.__wrapped__ = value;
  8321. return result;
  8322. }
  8323. /**
  8324. * This method is the wrapper version of `_.reverse`.
  8325. *
  8326. * **Note:** This method mutates the wrapped array.
  8327. *
  8328. * @name reverse
  8329. * @memberOf _
  8330. * @since 0.1.0
  8331. * @category Seq
  8332. * @returns {Object} Returns the new `lodash` wrapper instance.
  8333. * @example
  8334. *
  8335. * var array = [1, 2, 3];
  8336. *
  8337. * _(array).reverse().value()
  8338. * // => [3, 2, 1]
  8339. *
  8340. * console.log(array);
  8341. * // => [3, 2, 1]
  8342. */
  8343. function wrapperReverse() {
  8344. var value = this.__wrapped__;
  8345. if (value instanceof LazyWrapper) {
  8346. var wrapped = value;
  8347. if (this.__actions__.length) {
  8348. wrapped = new LazyWrapper(this);
  8349. }
  8350. wrapped = wrapped.reverse();
  8351. wrapped.__actions__.push({
  8352. 'func': thru,
  8353. 'args': [reverse],
  8354. 'thisArg': undefined
  8355. });
  8356. return new LodashWrapper(wrapped, this.__chain__);
  8357. }
  8358. return this.thru(reverse);
  8359. }
  8360. /**
  8361. * Executes the chain sequence to resolve the unwrapped value.
  8362. *
  8363. * @name value
  8364. * @memberOf _
  8365. * @since 0.1.0
  8366. * @alias toJSON, valueOf
  8367. * @category Seq
  8368. * @returns {*} Returns the resolved unwrapped value.
  8369. * @example
  8370. *
  8371. * _([1, 2, 3]).value();
  8372. * // => [1, 2, 3]
  8373. */
  8374. function wrapperValue() {
  8375. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8376. }
  8377. /*------------------------------------------------------------------------*/
  8378. /**
  8379. * Creates an object composed of keys generated from the results of running
  8380. * each element of `collection` thru `iteratee`. The corresponding value of
  8381. * each key is the number of times the key was returned by `iteratee`. The
  8382. * iteratee is invoked with one argument: (value).
  8383. *
  8384. * @static
  8385. * @memberOf _
  8386. * @since 0.5.0
  8387. * @category Collection
  8388. * @param {Array|Object} collection The collection to iterate over.
  8389. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8390. * @returns {Object} Returns the composed aggregate object.
  8391. * @example
  8392. *
  8393. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8394. * // => { '4': 1, '6': 2 }
  8395. *
  8396. * // The `_.property` iteratee shorthand.
  8397. * _.countBy(['one', 'two', 'three'], 'length');
  8398. * // => { '3': 2, '5': 1 }
  8399. */
  8400. var countBy = createAggregator(function(result, value, key) {
  8401. if (hasOwnProperty.call(result, key)) {
  8402. ++result[key];
  8403. } else {
  8404. baseAssignValue(result, key, 1);
  8405. }
  8406. });
  8407. /**
  8408. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8409. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8410. * invoked with three arguments: (value, index|key, collection).
  8411. *
  8412. * **Note:** This method returns `true` for
  8413. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8414. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8415. * elements of empty collections.
  8416. *
  8417. * @static
  8418. * @memberOf _
  8419. * @since 0.1.0
  8420. * @category Collection
  8421. * @param {Array|Object} collection The collection to iterate over.
  8422. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8423. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8424. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8425. * else `false`.
  8426. * @example
  8427. *
  8428. * _.every([true, 1, null, 'yes'], Boolean);
  8429. * // => false
  8430. *
  8431. * var users = [
  8432. * { 'user': 'barney', 'age': 36, 'active': false },
  8433. * { 'user': 'fred', 'age': 40, 'active': false }
  8434. * ];
  8435. *
  8436. * // The `_.matches` iteratee shorthand.
  8437. * _.every(users, { 'user': 'barney', 'active': false });
  8438. * // => false
  8439. *
  8440. * // The `_.matchesProperty` iteratee shorthand.
  8441. * _.every(users, ['active', false]);
  8442. * // => true
  8443. *
  8444. * // The `_.property` iteratee shorthand.
  8445. * _.every(users, 'active');
  8446. * // => false
  8447. */
  8448. function every(collection, predicate, guard) {
  8449. var func = isArray(collection) ? arrayEvery : baseEvery;
  8450. if (guard && isIterateeCall(collection, predicate, guard)) {
  8451. predicate = undefined;
  8452. }
  8453. return func(collection, getIteratee(predicate, 3));
  8454. }
  8455. /**
  8456. * Iterates over elements of `collection`, returning an array of all elements
  8457. * `predicate` returns truthy for. The predicate is invoked with three
  8458. * arguments: (value, index|key, collection).
  8459. *
  8460. * **Note:** Unlike `_.remove`, this method returns a new array.
  8461. *
  8462. * @static
  8463. * @memberOf _
  8464. * @since 0.1.0
  8465. * @category Collection
  8466. * @param {Array|Object} collection The collection to iterate over.
  8467. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8468. * @returns {Array} Returns the new filtered array.
  8469. * @see _.reject
  8470. * @example
  8471. *
  8472. * var users = [
  8473. * { 'user': 'barney', 'age': 36, 'active': true },
  8474. * { 'user': 'fred', 'age': 40, 'active': false }
  8475. * ];
  8476. *
  8477. * _.filter(users, function(o) { return !o.active; });
  8478. * // => objects for ['fred']
  8479. *
  8480. * // The `_.matches` iteratee shorthand.
  8481. * _.filter(users, { 'age': 36, 'active': true });
  8482. * // => objects for ['barney']
  8483. *
  8484. * // The `_.matchesProperty` iteratee shorthand.
  8485. * _.filter(users, ['active', false]);
  8486. * // => objects for ['fred']
  8487. *
  8488. * // The `_.property` iteratee shorthand.
  8489. * _.filter(users, 'active');
  8490. * // => objects for ['barney']
  8491. */
  8492. function filter(collection, predicate) {
  8493. var func = isArray(collection) ? arrayFilter : baseFilter;
  8494. return func(collection, getIteratee(predicate, 3));
  8495. }
  8496. /**
  8497. * Iterates over elements of `collection`, returning the first element
  8498. * `predicate` returns truthy for. The predicate is invoked with three
  8499. * arguments: (value, index|key, collection).
  8500. *
  8501. * @static
  8502. * @memberOf _
  8503. * @since 0.1.0
  8504. * @category Collection
  8505. * @param {Array|Object} collection The collection to inspect.
  8506. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8507. * @param {number} [fromIndex=0] The index to search from.
  8508. * @returns {*} Returns the matched element, else `undefined`.
  8509. * @example
  8510. *
  8511. * var users = [
  8512. * { 'user': 'barney', 'age': 36, 'active': true },
  8513. * { 'user': 'fred', 'age': 40, 'active': false },
  8514. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8515. * ];
  8516. *
  8517. * _.find(users, function(o) { return o.age < 40; });
  8518. * // => object for 'barney'
  8519. *
  8520. * // The `_.matches` iteratee shorthand.
  8521. * _.find(users, { 'age': 1, 'active': true });
  8522. * // => object for 'pebbles'
  8523. *
  8524. * // The `_.matchesProperty` iteratee shorthand.
  8525. * _.find(users, ['active', false]);
  8526. * // => object for 'fred'
  8527. *
  8528. * // The `_.property` iteratee shorthand.
  8529. * _.find(users, 'active');
  8530. * // => object for 'barney'
  8531. */
  8532. var find = createFind(findIndex);
  8533. /**
  8534. * This method is like `_.find` except that it iterates over elements of
  8535. * `collection` from right to left.
  8536. *
  8537. * @static
  8538. * @memberOf _
  8539. * @since 2.0.0
  8540. * @category Collection
  8541. * @param {Array|Object} collection The collection to inspect.
  8542. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8543. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8544. * @returns {*} Returns the matched element, else `undefined`.
  8545. * @example
  8546. *
  8547. * _.findLast([1, 2, 3, 4], function(n) {
  8548. * return n % 2 == 1;
  8549. * });
  8550. * // => 3
  8551. */
  8552. var findLast = createFind(findLastIndex);
  8553. /**
  8554. * Creates a flattened array of values by running each element in `collection`
  8555. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8556. * with three arguments: (value, index|key, collection).
  8557. *
  8558. * @static
  8559. * @memberOf _
  8560. * @since 4.0.0
  8561. * @category Collection
  8562. * @param {Array|Object} collection The collection to iterate over.
  8563. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8564. * @returns {Array} Returns the new flattened array.
  8565. * @example
  8566. *
  8567. * function duplicate(n) {
  8568. * return [n, n];
  8569. * }
  8570. *
  8571. * _.flatMap([1, 2], duplicate);
  8572. * // => [1, 1, 2, 2]
  8573. */
  8574. function flatMap(collection, iteratee) {
  8575. return baseFlatten(map(collection, iteratee), 1);
  8576. }
  8577. /**
  8578. * This method is like `_.flatMap` except that it recursively flattens the
  8579. * mapped results.
  8580. *
  8581. * @static
  8582. * @memberOf _
  8583. * @since 4.7.0
  8584. * @category Collection
  8585. * @param {Array|Object} collection The collection to iterate over.
  8586. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8587. * @returns {Array} Returns the new flattened array.
  8588. * @example
  8589. *
  8590. * function duplicate(n) {
  8591. * return [[[n, n]]];
  8592. * }
  8593. *
  8594. * _.flatMapDeep([1, 2], duplicate);
  8595. * // => [1, 1, 2, 2]
  8596. */
  8597. function flatMapDeep(collection, iteratee) {
  8598. return baseFlatten(map(collection, iteratee), INFINITY);
  8599. }
  8600. /**
  8601. * This method is like `_.flatMap` except that it recursively flattens the
  8602. * mapped results up to `depth` times.
  8603. *
  8604. * @static
  8605. * @memberOf _
  8606. * @since 4.7.0
  8607. * @category Collection
  8608. * @param {Array|Object} collection The collection to iterate over.
  8609. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8610. * @param {number} [depth=1] The maximum recursion depth.
  8611. * @returns {Array} Returns the new flattened array.
  8612. * @example
  8613. *
  8614. * function duplicate(n) {
  8615. * return [[[n, n]]];
  8616. * }
  8617. *
  8618. * _.flatMapDepth([1, 2], duplicate, 2);
  8619. * // => [[1, 1], [2, 2]]
  8620. */
  8621. function flatMapDepth(collection, iteratee, depth) {
  8622. depth = depth === undefined ? 1 : toInteger(depth);
  8623. return baseFlatten(map(collection, iteratee), depth);
  8624. }
  8625. /**
  8626. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8627. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8628. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8629. *
  8630. * **Note:** As with other "Collections" methods, objects with a "length"
  8631. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8632. * or `_.forOwn` for object iteration.
  8633. *
  8634. * @static
  8635. * @memberOf _
  8636. * @since 0.1.0
  8637. * @alias each
  8638. * @category Collection
  8639. * @param {Array|Object} collection The collection to iterate over.
  8640. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8641. * @returns {Array|Object} Returns `collection`.
  8642. * @see _.forEachRight
  8643. * @example
  8644. *
  8645. * _.forEach([1, 2], function(value) {
  8646. * console.log(value);
  8647. * });
  8648. * // => Logs `1` then `2`.
  8649. *
  8650. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8651. * console.log(key);
  8652. * });
  8653. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8654. */
  8655. function forEach(collection, iteratee) {
  8656. var func = isArray(collection) ? arrayEach : baseEach;
  8657. return func(collection, getIteratee(iteratee, 3));
  8658. }
  8659. /**
  8660. * This method is like `_.forEach` except that it iterates over elements of
  8661. * `collection` from right to left.
  8662. *
  8663. * @static
  8664. * @memberOf _
  8665. * @since 2.0.0
  8666. * @alias eachRight
  8667. * @category Collection
  8668. * @param {Array|Object} collection The collection to iterate over.
  8669. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8670. * @returns {Array|Object} Returns `collection`.
  8671. * @see _.forEach
  8672. * @example
  8673. *
  8674. * _.forEachRight([1, 2], function(value) {
  8675. * console.log(value);
  8676. * });
  8677. * // => Logs `2` then `1`.
  8678. */
  8679. function forEachRight(collection, iteratee) {
  8680. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8681. return func(collection, getIteratee(iteratee, 3));
  8682. }
  8683. /**
  8684. * Creates an object composed of keys generated from the results of running
  8685. * each element of `collection` thru `iteratee`. The order of grouped values
  8686. * is determined by the order they occur in `collection`. The corresponding
  8687. * value of each key is an array of elements responsible for generating the
  8688. * key. The iteratee is invoked with one argument: (value).
  8689. *
  8690. * @static
  8691. * @memberOf _
  8692. * @since 0.1.0
  8693. * @category Collection
  8694. * @param {Array|Object} collection The collection to iterate over.
  8695. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8696. * @returns {Object} Returns the composed aggregate object.
  8697. * @example
  8698. *
  8699. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8700. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8701. *
  8702. * // The `_.property` iteratee shorthand.
  8703. * _.groupBy(['one', 'two', 'three'], 'length');
  8704. * // => { '3': ['one', 'two'], '5': ['three'] }
  8705. */
  8706. var groupBy = createAggregator(function(result, value, key) {
  8707. if (hasOwnProperty.call(result, key)) {
  8708. result[key].push(value);
  8709. } else {
  8710. baseAssignValue(result, key, [value]);
  8711. }
  8712. });
  8713. /**
  8714. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8715. * checked for a substring of `value`, otherwise
  8716. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8717. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8718. * the offset from the end of `collection`.
  8719. *
  8720. * @static
  8721. * @memberOf _
  8722. * @since 0.1.0
  8723. * @category Collection
  8724. * @param {Array|Object|string} collection The collection to inspect.
  8725. * @param {*} value The value to search for.
  8726. * @param {number} [fromIndex=0] The index to search from.
  8727. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8728. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8729. * @example
  8730. *
  8731. * _.includes([1, 2, 3], 1);
  8732. * // => true
  8733. *
  8734. * _.includes([1, 2, 3], 1, 2);
  8735. * // => false
  8736. *
  8737. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8738. * // => true
  8739. *
  8740. * _.includes('abcd', 'bc');
  8741. * // => true
  8742. */
  8743. function includes(collection, value, fromIndex, guard) {
  8744. collection = isArrayLike(collection) ? collection : values(collection);
  8745. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8746. var length = collection.length;
  8747. if (fromIndex < 0) {
  8748. fromIndex = nativeMax(length + fromIndex, 0);
  8749. }
  8750. return isString(collection)
  8751. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8752. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8753. }
  8754. /**
  8755. * Invokes the method at `path` of each element in `collection`, returning
  8756. * an array of the results of each invoked method. Any additional arguments
  8757. * are provided to each invoked method. If `path` is a function, it's invoked
  8758. * for, and `this` bound to, each element in `collection`.
  8759. *
  8760. * @static
  8761. * @memberOf _
  8762. * @since 4.0.0
  8763. * @category Collection
  8764. * @param {Array|Object} collection The collection to iterate over.
  8765. * @param {Array|Function|string} path The path of the method to invoke or
  8766. * the function invoked per iteration.
  8767. * @param {...*} [args] The arguments to invoke each method with.
  8768. * @returns {Array} Returns the array of results.
  8769. * @example
  8770. *
  8771. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8772. * // => [[1, 5, 7], [1, 2, 3]]
  8773. *
  8774. * _.invokeMap([123, 456], String.prototype.split, '');
  8775. * // => [['1', '2', '3'], ['4', '5', '6']]
  8776. */
  8777. var invokeMap = baseRest(function(collection, path, args) {
  8778. var index = -1,
  8779. isFunc = typeof path == 'function',
  8780. result = isArrayLike(collection) ? Array(collection.length) : [];
  8781. baseEach(collection, function(value) {
  8782. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8783. });
  8784. return result;
  8785. });
  8786. /**
  8787. * Creates an object composed of keys generated from the results of running
  8788. * each element of `collection` thru `iteratee`. The corresponding value of
  8789. * each key is the last element responsible for generating the key. The
  8790. * iteratee is invoked with one argument: (value).
  8791. *
  8792. * @static
  8793. * @memberOf _
  8794. * @since 4.0.0
  8795. * @category Collection
  8796. * @param {Array|Object} collection The collection to iterate over.
  8797. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8798. * @returns {Object} Returns the composed aggregate object.
  8799. * @example
  8800. *
  8801. * var array = [
  8802. * { 'dir': 'left', 'code': 97 },
  8803. * { 'dir': 'right', 'code': 100 }
  8804. * ];
  8805. *
  8806. * _.keyBy(array, function(o) {
  8807. * return String.fromCharCode(o.code);
  8808. * });
  8809. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8810. *
  8811. * _.keyBy(array, 'dir');
  8812. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8813. */
  8814. var keyBy = createAggregator(function(result, value, key) {
  8815. baseAssignValue(result, key, value);
  8816. });
  8817. /**
  8818. * Creates an array of values by running each element in `collection` thru
  8819. * `iteratee`. The iteratee is invoked with three arguments:
  8820. * (value, index|key, collection).
  8821. *
  8822. * Many lodash methods are guarded to work as iteratees for methods like
  8823. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8824. *
  8825. * The guarded methods are:
  8826. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8827. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8828. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8829. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8830. *
  8831. * @static
  8832. * @memberOf _
  8833. * @since 0.1.0
  8834. * @category Collection
  8835. * @param {Array|Object} collection The collection to iterate over.
  8836. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8837. * @returns {Array} Returns the new mapped array.
  8838. * @example
  8839. *
  8840. * function square(n) {
  8841. * return n * n;
  8842. * }
  8843. *
  8844. * _.map([4, 8], square);
  8845. * // => [16, 64]
  8846. *
  8847. * _.map({ 'a': 4, 'b': 8 }, square);
  8848. * // => [16, 64] (iteration order is not guaranteed)
  8849. *
  8850. * var users = [
  8851. * { 'user': 'barney' },
  8852. * { 'user': 'fred' }
  8853. * ];
  8854. *
  8855. * // The `_.property` iteratee shorthand.
  8856. * _.map(users, 'user');
  8857. * // => ['barney', 'fred']
  8858. */
  8859. function map(collection, iteratee) {
  8860. var func = isArray(collection) ? arrayMap : baseMap;
  8861. return func(collection, getIteratee(iteratee, 3));
  8862. }
  8863. /**
  8864. * This method is like `_.sortBy` except that it allows specifying the sort
  8865. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8866. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8867. * descending or "asc" for ascending sort order of corresponding values.
  8868. *
  8869. * @static
  8870. * @memberOf _
  8871. * @since 4.0.0
  8872. * @category Collection
  8873. * @param {Array|Object} collection The collection to iterate over.
  8874. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8875. * The iteratees to sort by.
  8876. * @param {string[]} [orders] The sort orders of `iteratees`.
  8877. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8878. * @returns {Array} Returns the new sorted array.
  8879. * @example
  8880. *
  8881. * var users = [
  8882. * { 'user': 'fred', 'age': 48 },
  8883. * { 'user': 'barney', 'age': 34 },
  8884. * { 'user': 'fred', 'age': 40 },
  8885. * { 'user': 'barney', 'age': 36 }
  8886. * ];
  8887. *
  8888. * // Sort by `user` in ascending order and by `age` in descending order.
  8889. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8890. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8891. */
  8892. function orderBy(collection, iteratees, orders, guard) {
  8893. if (collection == null) {
  8894. return [];
  8895. }
  8896. if (!isArray(iteratees)) {
  8897. iteratees = iteratees == null ? [] : [iteratees];
  8898. }
  8899. orders = guard ? undefined : orders;
  8900. if (!isArray(orders)) {
  8901. orders = orders == null ? [] : [orders];
  8902. }
  8903. return baseOrderBy(collection, iteratees, orders);
  8904. }
  8905. /**
  8906. * Creates an array of elements split into two groups, the first of which
  8907. * contains elements `predicate` returns truthy for, the second of which
  8908. * contains elements `predicate` returns falsey for. The predicate is
  8909. * invoked with one argument: (value).
  8910. *
  8911. * @static
  8912. * @memberOf _
  8913. * @since 3.0.0
  8914. * @category Collection
  8915. * @param {Array|Object} collection The collection to iterate over.
  8916. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8917. * @returns {Array} Returns the array of grouped elements.
  8918. * @example
  8919. *
  8920. * var users = [
  8921. * { 'user': 'barney', 'age': 36, 'active': false },
  8922. * { 'user': 'fred', 'age': 40, 'active': true },
  8923. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8924. * ];
  8925. *
  8926. * _.partition(users, function(o) { return o.active; });
  8927. * // => objects for [['fred'], ['barney', 'pebbles']]
  8928. *
  8929. * // The `_.matches` iteratee shorthand.
  8930. * _.partition(users, { 'age': 1, 'active': false });
  8931. * // => objects for [['pebbles'], ['barney', 'fred']]
  8932. *
  8933. * // The `_.matchesProperty` iteratee shorthand.
  8934. * _.partition(users, ['active', false]);
  8935. * // => objects for [['barney', 'pebbles'], ['fred']]
  8936. *
  8937. * // The `_.property` iteratee shorthand.
  8938. * _.partition(users, 'active');
  8939. * // => objects for [['fred'], ['barney', 'pebbles']]
  8940. */
  8941. var partition = createAggregator(function(result, value, key) {
  8942. result[key ? 0 : 1].push(value);
  8943. }, function() { return [[], []]; });
  8944. /**
  8945. * Reduces `collection` to a value which is the accumulated result of running
  8946. * each element in `collection` thru `iteratee`, where each successive
  8947. * invocation is supplied the return value of the previous. If `accumulator`
  8948. * is not given, the first element of `collection` is used as the initial
  8949. * value. The iteratee is invoked with four arguments:
  8950. * (accumulator, value, index|key, collection).
  8951. *
  8952. * Many lodash methods are guarded to work as iteratees for methods like
  8953. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8954. *
  8955. * The guarded methods are:
  8956. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8957. * and `sortBy`
  8958. *
  8959. * @static
  8960. * @memberOf _
  8961. * @since 0.1.0
  8962. * @category Collection
  8963. * @param {Array|Object} collection The collection to iterate over.
  8964. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8965. * @param {*} [accumulator] The initial value.
  8966. * @returns {*} Returns the accumulated value.
  8967. * @see _.reduceRight
  8968. * @example
  8969. *
  8970. * _.reduce([1, 2], function(sum, n) {
  8971. * return sum + n;
  8972. * }, 0);
  8973. * // => 3
  8974. *
  8975. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8976. * (result[value] || (result[value] = [])).push(key);
  8977. * return result;
  8978. * }, {});
  8979. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8980. */
  8981. function reduce(collection, iteratee, accumulator) {
  8982. var func = isArray(collection) ? arrayReduce : baseReduce,
  8983. initAccum = arguments.length < 3;
  8984. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8985. }
  8986. /**
  8987. * This method is like `_.reduce` except that it iterates over elements of
  8988. * `collection` from right to left.
  8989. *
  8990. * @static
  8991. * @memberOf _
  8992. * @since 0.1.0
  8993. * @category Collection
  8994. * @param {Array|Object} collection The collection to iterate over.
  8995. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8996. * @param {*} [accumulator] The initial value.
  8997. * @returns {*} Returns the accumulated value.
  8998. * @see _.reduce
  8999. * @example
  9000. *
  9001. * var array = [[0, 1], [2, 3], [4, 5]];
  9002. *
  9003. * _.reduceRight(array, function(flattened, other) {
  9004. * return flattened.concat(other);
  9005. * }, []);
  9006. * // => [4, 5, 2, 3, 0, 1]
  9007. */
  9008. function reduceRight(collection, iteratee, accumulator) {
  9009. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9010. initAccum = arguments.length < 3;
  9011. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9012. }
  9013. /**
  9014. * The opposite of `_.filter`; this method returns the elements of `collection`
  9015. * that `predicate` does **not** return truthy for.
  9016. *
  9017. * @static
  9018. * @memberOf _
  9019. * @since 0.1.0
  9020. * @category Collection
  9021. * @param {Array|Object} collection The collection to iterate over.
  9022. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9023. * @returns {Array} Returns the new filtered array.
  9024. * @see _.filter
  9025. * @example
  9026. *
  9027. * var users = [
  9028. * { 'user': 'barney', 'age': 36, 'active': false },
  9029. * { 'user': 'fred', 'age': 40, 'active': true }
  9030. * ];
  9031. *
  9032. * _.reject(users, function(o) { return !o.active; });
  9033. * // => objects for ['fred']
  9034. *
  9035. * // The `_.matches` iteratee shorthand.
  9036. * _.reject(users, { 'age': 40, 'active': true });
  9037. * // => objects for ['barney']
  9038. *
  9039. * // The `_.matchesProperty` iteratee shorthand.
  9040. * _.reject(users, ['active', false]);
  9041. * // => objects for ['fred']
  9042. *
  9043. * // The `_.property` iteratee shorthand.
  9044. * _.reject(users, 'active');
  9045. * // => objects for ['barney']
  9046. */
  9047. function reject(collection, predicate) {
  9048. var func = isArray(collection) ? arrayFilter : baseFilter;
  9049. return func(collection, negate(getIteratee(predicate, 3)));
  9050. }
  9051. /**
  9052. * Gets a random element from `collection`.
  9053. *
  9054. * @static
  9055. * @memberOf _
  9056. * @since 2.0.0
  9057. * @category Collection
  9058. * @param {Array|Object} collection The collection to sample.
  9059. * @returns {*} Returns the random element.
  9060. * @example
  9061. *
  9062. * _.sample([1, 2, 3, 4]);
  9063. * // => 2
  9064. */
  9065. function sample(collection) {
  9066. var func = isArray(collection) ? arraySample : baseSample;
  9067. return func(collection);
  9068. }
  9069. /**
  9070. * Gets `n` random elements at unique keys from `collection` up to the
  9071. * size of `collection`.
  9072. *
  9073. * @static
  9074. * @memberOf _
  9075. * @since 4.0.0
  9076. * @category Collection
  9077. * @param {Array|Object} collection The collection to sample.
  9078. * @param {number} [n=1] The number of elements to sample.
  9079. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9080. * @returns {Array} Returns the random elements.
  9081. * @example
  9082. *
  9083. * _.sampleSize([1, 2, 3], 2);
  9084. * // => [3, 1]
  9085. *
  9086. * _.sampleSize([1, 2, 3], 4);
  9087. * // => [2, 3, 1]
  9088. */
  9089. function sampleSize(collection, n, guard) {
  9090. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9091. n = 1;
  9092. } else {
  9093. n = toInteger(n);
  9094. }
  9095. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9096. return func(collection, n);
  9097. }
  9098. /**
  9099. * Creates an array of shuffled values, using a version of the
  9100. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9101. *
  9102. * @static
  9103. * @memberOf _
  9104. * @since 0.1.0
  9105. * @category Collection
  9106. * @param {Array|Object} collection The collection to shuffle.
  9107. * @returns {Array} Returns the new shuffled array.
  9108. * @example
  9109. *
  9110. * _.shuffle([1, 2, 3, 4]);
  9111. * // => [4, 1, 3, 2]
  9112. */
  9113. function shuffle(collection) {
  9114. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9115. return func(collection);
  9116. }
  9117. /**
  9118. * Gets the size of `collection` by returning its length for array-like
  9119. * values or the number of own enumerable string keyed properties for objects.
  9120. *
  9121. * @static
  9122. * @memberOf _
  9123. * @since 0.1.0
  9124. * @category Collection
  9125. * @param {Array|Object|string} collection The collection to inspect.
  9126. * @returns {number} Returns the collection size.
  9127. * @example
  9128. *
  9129. * _.size([1, 2, 3]);
  9130. * // => 3
  9131. *
  9132. * _.size({ 'a': 1, 'b': 2 });
  9133. * // => 2
  9134. *
  9135. * _.size('pebbles');
  9136. * // => 7
  9137. */
  9138. function size(collection) {
  9139. if (collection == null) {
  9140. return 0;
  9141. }
  9142. if (isArrayLike(collection)) {
  9143. return isString(collection) ? stringSize(collection) : collection.length;
  9144. }
  9145. var tag = getTag(collection);
  9146. if (tag == mapTag || tag == setTag) {
  9147. return collection.size;
  9148. }
  9149. return baseKeys(collection).length;
  9150. }
  9151. /**
  9152. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9153. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9154. * invoked with three arguments: (value, index|key, collection).
  9155. *
  9156. * @static
  9157. * @memberOf _
  9158. * @since 0.1.0
  9159. * @category Collection
  9160. * @param {Array|Object} collection The collection to iterate over.
  9161. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9162. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9163. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9164. * else `false`.
  9165. * @example
  9166. *
  9167. * _.some([null, 0, 'yes', false], Boolean);
  9168. * // => true
  9169. *
  9170. * var users = [
  9171. * { 'user': 'barney', 'active': true },
  9172. * { 'user': 'fred', 'active': false }
  9173. * ];
  9174. *
  9175. * // The `_.matches` iteratee shorthand.
  9176. * _.some(users, { 'user': 'barney', 'active': false });
  9177. * // => false
  9178. *
  9179. * // The `_.matchesProperty` iteratee shorthand.
  9180. * _.some(users, ['active', false]);
  9181. * // => true
  9182. *
  9183. * // The `_.property` iteratee shorthand.
  9184. * _.some(users, 'active');
  9185. * // => true
  9186. */
  9187. function some(collection, predicate, guard) {
  9188. var func = isArray(collection) ? arraySome : baseSome;
  9189. if (guard && isIterateeCall(collection, predicate, guard)) {
  9190. predicate = undefined;
  9191. }
  9192. return func(collection, getIteratee(predicate, 3));
  9193. }
  9194. /**
  9195. * Creates an array of elements, sorted in ascending order by the results of
  9196. * running each element in a collection thru each iteratee. This method
  9197. * performs a stable sort, that is, it preserves the original sort order of
  9198. * equal elements. The iteratees are invoked with one argument: (value).
  9199. *
  9200. * @static
  9201. * @memberOf _
  9202. * @since 0.1.0
  9203. * @category Collection
  9204. * @param {Array|Object} collection The collection to iterate over.
  9205. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9206. * The iteratees to sort by.
  9207. * @returns {Array} Returns the new sorted array.
  9208. * @example
  9209. *
  9210. * var users = [
  9211. * { 'user': 'fred', 'age': 48 },
  9212. * { 'user': 'barney', 'age': 36 },
  9213. * { 'user': 'fred', 'age': 40 },
  9214. * { 'user': 'barney', 'age': 34 }
  9215. * ];
  9216. *
  9217. * _.sortBy(users, [function(o) { return o.user; }]);
  9218. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9219. *
  9220. * _.sortBy(users, ['user', 'age']);
  9221. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9222. */
  9223. var sortBy = baseRest(function(collection, iteratees) {
  9224. if (collection == null) {
  9225. return [];
  9226. }
  9227. var length = iteratees.length;
  9228. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9229. iteratees = [];
  9230. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9231. iteratees = [iteratees[0]];
  9232. }
  9233. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9234. });
  9235. /*------------------------------------------------------------------------*/
  9236. /**
  9237. * Gets the timestamp of the number of milliseconds that have elapsed since
  9238. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9239. *
  9240. * @static
  9241. * @memberOf _
  9242. * @since 2.4.0
  9243. * @category Date
  9244. * @returns {number} Returns the timestamp.
  9245. * @example
  9246. *
  9247. * _.defer(function(stamp) {
  9248. * console.log(_.now() - stamp);
  9249. * }, _.now());
  9250. * // => Logs the number of milliseconds it took for the deferred invocation.
  9251. */
  9252. var now = ctxNow || function() {
  9253. return root.Date.now();
  9254. };
  9255. /*------------------------------------------------------------------------*/
  9256. /**
  9257. * The opposite of `_.before`; this method creates a function that invokes
  9258. * `func` once it's called `n` or more times.
  9259. *
  9260. * @static
  9261. * @memberOf _
  9262. * @since 0.1.0
  9263. * @category Function
  9264. * @param {number} n The number of calls before `func` is invoked.
  9265. * @param {Function} func The function to restrict.
  9266. * @returns {Function} Returns the new restricted function.
  9267. * @example
  9268. *
  9269. * var saves = ['profile', 'settings'];
  9270. *
  9271. * var done = _.after(saves.length, function() {
  9272. * console.log('done saving!');
  9273. * });
  9274. *
  9275. * _.forEach(saves, function(type) {
  9276. * asyncSave({ 'type': type, 'complete': done });
  9277. * });
  9278. * // => Logs 'done saving!' after the two async saves have completed.
  9279. */
  9280. function after(n, func) {
  9281. if (typeof func != 'function') {
  9282. throw new TypeError(FUNC_ERROR_TEXT);
  9283. }
  9284. n = toInteger(n);
  9285. return function() {
  9286. if (--n < 1) {
  9287. return func.apply(this, arguments);
  9288. }
  9289. };
  9290. }
  9291. /**
  9292. * Creates a function that invokes `func`, with up to `n` arguments,
  9293. * ignoring any additional arguments.
  9294. *
  9295. * @static
  9296. * @memberOf _
  9297. * @since 3.0.0
  9298. * @category Function
  9299. * @param {Function} func The function to cap arguments for.
  9300. * @param {number} [n=func.length] The arity cap.
  9301. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9302. * @returns {Function} Returns the new capped function.
  9303. * @example
  9304. *
  9305. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9306. * // => [6, 8, 10]
  9307. */
  9308. function ary(func, n, guard) {
  9309. n = guard ? undefined : n;
  9310. n = (func && n == null) ? func.length : n;
  9311. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9312. }
  9313. /**
  9314. * Creates a function that invokes `func`, with the `this` binding and arguments
  9315. * of the created function, while it's called less than `n` times. Subsequent
  9316. * calls to the created function return the result of the last `func` invocation.
  9317. *
  9318. * @static
  9319. * @memberOf _
  9320. * @since 3.0.0
  9321. * @category Function
  9322. * @param {number} n The number of calls at which `func` is no longer invoked.
  9323. * @param {Function} func The function to restrict.
  9324. * @returns {Function} Returns the new restricted function.
  9325. * @example
  9326. *
  9327. * jQuery(element).on('click', _.before(5, addContactToList));
  9328. * // => Allows adding up to 4 contacts to the list.
  9329. */
  9330. function before(n, func) {
  9331. var result;
  9332. if (typeof func != 'function') {
  9333. throw new TypeError(FUNC_ERROR_TEXT);
  9334. }
  9335. n = toInteger(n);
  9336. return function() {
  9337. if (--n > 0) {
  9338. result = func.apply(this, arguments);
  9339. }
  9340. if (n <= 1) {
  9341. func = undefined;
  9342. }
  9343. return result;
  9344. };
  9345. }
  9346. /**
  9347. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9348. * and `partials` prepended to the arguments it receives.
  9349. *
  9350. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9351. * may be used as a placeholder for partially applied arguments.
  9352. *
  9353. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9354. * property of bound functions.
  9355. *
  9356. * @static
  9357. * @memberOf _
  9358. * @since 0.1.0
  9359. * @category Function
  9360. * @param {Function} func The function to bind.
  9361. * @param {*} thisArg The `this` binding of `func`.
  9362. * @param {...*} [partials] The arguments to be partially applied.
  9363. * @returns {Function} Returns the new bound function.
  9364. * @example
  9365. *
  9366. * function greet(greeting, punctuation) {
  9367. * return greeting + ' ' + this.user + punctuation;
  9368. * }
  9369. *
  9370. * var object = { 'user': 'fred' };
  9371. *
  9372. * var bound = _.bind(greet, object, 'hi');
  9373. * bound('!');
  9374. * // => 'hi fred!'
  9375. *
  9376. * // Bound with placeholders.
  9377. * var bound = _.bind(greet, object, _, '!');
  9378. * bound('hi');
  9379. * // => 'hi fred!'
  9380. */
  9381. var bind = baseRest(function(func, thisArg, partials) {
  9382. var bitmask = WRAP_BIND_FLAG;
  9383. if (partials.length) {
  9384. var holders = replaceHolders(partials, getHolder(bind));
  9385. bitmask |= WRAP_PARTIAL_FLAG;
  9386. }
  9387. return createWrap(func, bitmask, thisArg, partials, holders);
  9388. });
  9389. /**
  9390. * Creates a function that invokes the method at `object[key]` with `partials`
  9391. * prepended to the arguments it receives.
  9392. *
  9393. * This method differs from `_.bind` by allowing bound functions to reference
  9394. * methods that may be redefined or don't yet exist. See
  9395. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9396. * for more details.
  9397. *
  9398. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9399. * builds, may be used as a placeholder for partially applied arguments.
  9400. *
  9401. * @static
  9402. * @memberOf _
  9403. * @since 0.10.0
  9404. * @category Function
  9405. * @param {Object} object The object to invoke the method on.
  9406. * @param {string} key The key of the method.
  9407. * @param {...*} [partials] The arguments to be partially applied.
  9408. * @returns {Function} Returns the new bound function.
  9409. * @example
  9410. *
  9411. * var object = {
  9412. * 'user': 'fred',
  9413. * 'greet': function(greeting, punctuation) {
  9414. * return greeting + ' ' + this.user + punctuation;
  9415. * }
  9416. * };
  9417. *
  9418. * var bound = _.bindKey(object, 'greet', 'hi');
  9419. * bound('!');
  9420. * // => 'hi fred!'
  9421. *
  9422. * object.greet = function(greeting, punctuation) {
  9423. * return greeting + 'ya ' + this.user + punctuation;
  9424. * };
  9425. *
  9426. * bound('!');
  9427. * // => 'hiya fred!'
  9428. *
  9429. * // Bound with placeholders.
  9430. * var bound = _.bindKey(object, 'greet', _, '!');
  9431. * bound('hi');
  9432. * // => 'hiya fred!'
  9433. */
  9434. var bindKey = baseRest(function(object, key, partials) {
  9435. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9436. if (partials.length) {
  9437. var holders = replaceHolders(partials, getHolder(bindKey));
  9438. bitmask |= WRAP_PARTIAL_FLAG;
  9439. }
  9440. return createWrap(key, bitmask, object, partials, holders);
  9441. });
  9442. /**
  9443. * Creates a function that accepts arguments of `func` and either invokes
  9444. * `func` returning its result, if at least `arity` number of arguments have
  9445. * been provided, or returns a function that accepts the remaining `func`
  9446. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9447. * is not sufficient.
  9448. *
  9449. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9450. * may be used as a placeholder for provided arguments.
  9451. *
  9452. * **Note:** This method doesn't set the "length" property of curried functions.
  9453. *
  9454. * @static
  9455. * @memberOf _
  9456. * @since 2.0.0
  9457. * @category Function
  9458. * @param {Function} func The function to curry.
  9459. * @param {number} [arity=func.length] The arity of `func`.
  9460. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9461. * @returns {Function} Returns the new curried function.
  9462. * @example
  9463. *
  9464. * var abc = function(a, b, c) {
  9465. * return [a, b, c];
  9466. * };
  9467. *
  9468. * var curried = _.curry(abc);
  9469. *
  9470. * curried(1)(2)(3);
  9471. * // => [1, 2, 3]
  9472. *
  9473. * curried(1, 2)(3);
  9474. * // => [1, 2, 3]
  9475. *
  9476. * curried(1, 2, 3);
  9477. * // => [1, 2, 3]
  9478. *
  9479. * // Curried with placeholders.
  9480. * curried(1)(_, 3)(2);
  9481. * // => [1, 2, 3]
  9482. */
  9483. function curry(func, arity, guard) {
  9484. arity = guard ? undefined : arity;
  9485. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9486. result.placeholder = curry.placeholder;
  9487. return result;
  9488. }
  9489. /**
  9490. * This method is like `_.curry` except that arguments are applied to `func`
  9491. * in the manner of `_.partialRight` instead of `_.partial`.
  9492. *
  9493. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9494. * builds, may be used as a placeholder for provided arguments.
  9495. *
  9496. * **Note:** This method doesn't set the "length" property of curried functions.
  9497. *
  9498. * @static
  9499. * @memberOf _
  9500. * @since 3.0.0
  9501. * @category Function
  9502. * @param {Function} func The function to curry.
  9503. * @param {number} [arity=func.length] The arity of `func`.
  9504. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9505. * @returns {Function} Returns the new curried function.
  9506. * @example
  9507. *
  9508. * var abc = function(a, b, c) {
  9509. * return [a, b, c];
  9510. * };
  9511. *
  9512. * var curried = _.curryRight(abc);
  9513. *
  9514. * curried(3)(2)(1);
  9515. * // => [1, 2, 3]
  9516. *
  9517. * curried(2, 3)(1);
  9518. * // => [1, 2, 3]
  9519. *
  9520. * curried(1, 2, 3);
  9521. * // => [1, 2, 3]
  9522. *
  9523. * // Curried with placeholders.
  9524. * curried(3)(1, _)(2);
  9525. * // => [1, 2, 3]
  9526. */
  9527. function curryRight(func, arity, guard) {
  9528. arity = guard ? undefined : arity;
  9529. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9530. result.placeholder = curryRight.placeholder;
  9531. return result;
  9532. }
  9533. /**
  9534. * Creates a debounced function that delays invoking `func` until after `wait`
  9535. * milliseconds have elapsed since the last time the debounced function was
  9536. * invoked. The debounced function comes with a `cancel` method to cancel
  9537. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9538. * Provide `options` to indicate whether `func` should be invoked on the
  9539. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9540. * with the last arguments provided to the debounced function. Subsequent
  9541. * calls to the debounced function return the result of the last `func`
  9542. * invocation.
  9543. *
  9544. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9545. * invoked on the trailing edge of the timeout only if the debounced function
  9546. * is invoked more than once during the `wait` timeout.
  9547. *
  9548. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9549. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9550. *
  9551. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9552. * for details over the differences between `_.debounce` and `_.throttle`.
  9553. *
  9554. * @static
  9555. * @memberOf _
  9556. * @since 0.1.0
  9557. * @category Function
  9558. * @param {Function} func The function to debounce.
  9559. * @param {number} [wait=0] The number of milliseconds to delay.
  9560. * @param {Object} [options={}] The options object.
  9561. * @param {boolean} [options.leading=false]
  9562. * Specify invoking on the leading edge of the timeout.
  9563. * @param {number} [options.maxWait]
  9564. * The maximum time `func` is allowed to be delayed before it's invoked.
  9565. * @param {boolean} [options.trailing=true]
  9566. * Specify invoking on the trailing edge of the timeout.
  9567. * @returns {Function} Returns the new debounced function.
  9568. * @example
  9569. *
  9570. * // Avoid costly calculations while the window size is in flux.
  9571. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9572. *
  9573. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9574. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9575. * 'leading': true,
  9576. * 'trailing': false
  9577. * }));
  9578. *
  9579. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9580. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9581. * var source = new EventSource('/stream');
  9582. * jQuery(source).on('message', debounced);
  9583. *
  9584. * // Cancel the trailing debounced invocation.
  9585. * jQuery(window).on('popstate', debounced.cancel);
  9586. */
  9587. function debounce(func, wait, options) {
  9588. var lastArgs,
  9589. lastThis,
  9590. maxWait,
  9591. result,
  9592. timerId,
  9593. lastCallTime,
  9594. lastInvokeTime = 0,
  9595. leading = false,
  9596. maxing = false,
  9597. trailing = true;
  9598. if (typeof func != 'function') {
  9599. throw new TypeError(FUNC_ERROR_TEXT);
  9600. }
  9601. wait = toNumber(wait) || 0;
  9602. if (isObject(options)) {
  9603. leading = !!options.leading;
  9604. maxing = 'maxWait' in options;
  9605. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9606. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9607. }
  9608. function invokeFunc(time) {
  9609. var args = lastArgs,
  9610. thisArg = lastThis;
  9611. lastArgs = lastThis = undefined;
  9612. lastInvokeTime = time;
  9613. result = func.apply(thisArg, args);
  9614. return result;
  9615. }
  9616. function leadingEdge(time) {
  9617. // Reset any `maxWait` timer.
  9618. lastInvokeTime = time;
  9619. // Start the timer for the trailing edge.
  9620. timerId = setTimeout(timerExpired, wait);
  9621. // Invoke the leading edge.
  9622. return leading ? invokeFunc(time) : result;
  9623. }
  9624. function remainingWait(time) {
  9625. var timeSinceLastCall = time - lastCallTime,
  9626. timeSinceLastInvoke = time - lastInvokeTime,
  9627. timeWaiting = wait - timeSinceLastCall;
  9628. return maxing
  9629. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9630. : timeWaiting;
  9631. }
  9632. function shouldInvoke(time) {
  9633. var timeSinceLastCall = time - lastCallTime,
  9634. timeSinceLastInvoke = time - lastInvokeTime;
  9635. // Either this is the first call, activity has stopped and we're at the
  9636. // trailing edge, the system time has gone backwards and we're treating
  9637. // it as the trailing edge, or we've hit the `maxWait` limit.
  9638. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9639. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9640. }
  9641. function timerExpired() {
  9642. var time = now();
  9643. if (shouldInvoke(time)) {
  9644. return trailingEdge(time);
  9645. }
  9646. // Restart the timer.
  9647. timerId = setTimeout(timerExpired, remainingWait(time));
  9648. }
  9649. function trailingEdge(time) {
  9650. timerId = undefined;
  9651. // Only invoke if we have `lastArgs` which means `func` has been
  9652. // debounced at least once.
  9653. if (trailing && lastArgs) {
  9654. return invokeFunc(time);
  9655. }
  9656. lastArgs = lastThis = undefined;
  9657. return result;
  9658. }
  9659. function cancel() {
  9660. if (timerId !== undefined) {
  9661. clearTimeout(timerId);
  9662. }
  9663. lastInvokeTime = 0;
  9664. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9665. }
  9666. function flush() {
  9667. return timerId === undefined ? result : trailingEdge(now());
  9668. }
  9669. function debounced() {
  9670. var time = now(),
  9671. isInvoking = shouldInvoke(time);
  9672. lastArgs = arguments;
  9673. lastThis = this;
  9674. lastCallTime = time;
  9675. if (isInvoking) {
  9676. if (timerId === undefined) {
  9677. return leadingEdge(lastCallTime);
  9678. }
  9679. if (maxing) {
  9680. // Handle invocations in a tight loop.
  9681. clearTimeout(timerId);
  9682. timerId = setTimeout(timerExpired, wait);
  9683. return invokeFunc(lastCallTime);
  9684. }
  9685. }
  9686. if (timerId === undefined) {
  9687. timerId = setTimeout(timerExpired, wait);
  9688. }
  9689. return result;
  9690. }
  9691. debounced.cancel = cancel;
  9692. debounced.flush = flush;
  9693. return debounced;
  9694. }
  9695. /**
  9696. * Defers invoking the `func` until the current call stack has cleared. Any
  9697. * additional arguments are provided to `func` when it's invoked.
  9698. *
  9699. * @static
  9700. * @memberOf _
  9701. * @since 0.1.0
  9702. * @category Function
  9703. * @param {Function} func The function to defer.
  9704. * @param {...*} [args] The arguments to invoke `func` with.
  9705. * @returns {number} Returns the timer id.
  9706. * @example
  9707. *
  9708. * _.defer(function(text) {
  9709. * console.log(text);
  9710. * }, 'deferred');
  9711. * // => Logs 'deferred' after one millisecond.
  9712. */
  9713. var defer = baseRest(function(func, args) {
  9714. return baseDelay(func, 1, args);
  9715. });
  9716. /**
  9717. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9718. * provided to `func` when it's invoked.
  9719. *
  9720. * @static
  9721. * @memberOf _
  9722. * @since 0.1.0
  9723. * @category Function
  9724. * @param {Function} func The function to delay.
  9725. * @param {number} wait The number of milliseconds to delay invocation.
  9726. * @param {...*} [args] The arguments to invoke `func` with.
  9727. * @returns {number} Returns the timer id.
  9728. * @example
  9729. *
  9730. * _.delay(function(text) {
  9731. * console.log(text);
  9732. * }, 1000, 'later');
  9733. * // => Logs 'later' after one second.
  9734. */
  9735. var delay = baseRest(function(func, wait, args) {
  9736. return baseDelay(func, toNumber(wait) || 0, args);
  9737. });
  9738. /**
  9739. * Creates a function that invokes `func` with arguments reversed.
  9740. *
  9741. * @static
  9742. * @memberOf _
  9743. * @since 4.0.0
  9744. * @category Function
  9745. * @param {Function} func The function to flip arguments for.
  9746. * @returns {Function} Returns the new flipped function.
  9747. * @example
  9748. *
  9749. * var flipped = _.flip(function() {
  9750. * return _.toArray(arguments);
  9751. * });
  9752. *
  9753. * flipped('a', 'b', 'c', 'd');
  9754. * // => ['d', 'c', 'b', 'a']
  9755. */
  9756. function flip(func) {
  9757. return createWrap(func, WRAP_FLIP_FLAG);
  9758. }
  9759. /**
  9760. * Creates a function that memoizes the result of `func`. If `resolver` is
  9761. * provided, it determines the cache key for storing the result based on the
  9762. * arguments provided to the memoized function. By default, the first argument
  9763. * provided to the memoized function is used as the map cache key. The `func`
  9764. * is invoked with the `this` binding of the memoized function.
  9765. *
  9766. * **Note:** The cache is exposed as the `cache` property on the memoized
  9767. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9768. * constructor with one whose instances implement the
  9769. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9770. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9771. *
  9772. * @static
  9773. * @memberOf _
  9774. * @since 0.1.0
  9775. * @category Function
  9776. * @param {Function} func The function to have its output memoized.
  9777. * @param {Function} [resolver] The function to resolve the cache key.
  9778. * @returns {Function} Returns the new memoized function.
  9779. * @example
  9780. *
  9781. * var object = { 'a': 1, 'b': 2 };
  9782. * var other = { 'c': 3, 'd': 4 };
  9783. *
  9784. * var values = _.memoize(_.values);
  9785. * values(object);
  9786. * // => [1, 2]
  9787. *
  9788. * values(other);
  9789. * // => [3, 4]
  9790. *
  9791. * object.a = 2;
  9792. * values(object);
  9793. * // => [1, 2]
  9794. *
  9795. * // Modify the result cache.
  9796. * values.cache.set(object, ['a', 'b']);
  9797. * values(object);
  9798. * // => ['a', 'b']
  9799. *
  9800. * // Replace `_.memoize.Cache`.
  9801. * _.memoize.Cache = WeakMap;
  9802. */
  9803. function memoize(func, resolver) {
  9804. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9805. throw new TypeError(FUNC_ERROR_TEXT);
  9806. }
  9807. var memoized = function() {
  9808. var args = arguments,
  9809. key = resolver ? resolver.apply(this, args) : args[0],
  9810. cache = memoized.cache;
  9811. if (cache.has(key)) {
  9812. return cache.get(key);
  9813. }
  9814. var result = func.apply(this, args);
  9815. memoized.cache = cache.set(key, result) || cache;
  9816. return result;
  9817. };
  9818. memoized.cache = new (memoize.Cache || MapCache);
  9819. return memoized;
  9820. }
  9821. // Expose `MapCache`.
  9822. memoize.Cache = MapCache;
  9823. /**
  9824. * Creates a function that negates the result of the predicate `func`. The
  9825. * `func` predicate is invoked with the `this` binding and arguments of the
  9826. * created function.
  9827. *
  9828. * @static
  9829. * @memberOf _
  9830. * @since 3.0.0
  9831. * @category Function
  9832. * @param {Function} predicate The predicate to negate.
  9833. * @returns {Function} Returns the new negated function.
  9834. * @example
  9835. *
  9836. * function isEven(n) {
  9837. * return n % 2 == 0;
  9838. * }
  9839. *
  9840. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9841. * // => [1, 3, 5]
  9842. */
  9843. function negate(predicate) {
  9844. if (typeof predicate != 'function') {
  9845. throw new TypeError(FUNC_ERROR_TEXT);
  9846. }
  9847. return function() {
  9848. var args = arguments;
  9849. switch (args.length) {
  9850. case 0: return !predicate.call(this);
  9851. case 1: return !predicate.call(this, args[0]);
  9852. case 2: return !predicate.call(this, args[0], args[1]);
  9853. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9854. }
  9855. return !predicate.apply(this, args);
  9856. };
  9857. }
  9858. /**
  9859. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9860. * to the function return the value of the first invocation. The `func` is
  9861. * invoked with the `this` binding and arguments of the created function.
  9862. *
  9863. * @static
  9864. * @memberOf _
  9865. * @since 0.1.0
  9866. * @category Function
  9867. * @param {Function} func The function to restrict.
  9868. * @returns {Function} Returns the new restricted function.
  9869. * @example
  9870. *
  9871. * var initialize = _.once(createApplication);
  9872. * initialize();
  9873. * initialize();
  9874. * // => `createApplication` is invoked once
  9875. */
  9876. function once(func) {
  9877. return before(2, func);
  9878. }
  9879. /**
  9880. * Creates a function that invokes `func` with its arguments transformed.
  9881. *
  9882. * @static
  9883. * @since 4.0.0
  9884. * @memberOf _
  9885. * @category Function
  9886. * @param {Function} func The function to wrap.
  9887. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9888. * The argument transforms.
  9889. * @returns {Function} Returns the new function.
  9890. * @example
  9891. *
  9892. * function doubled(n) {
  9893. * return n * 2;
  9894. * }
  9895. *
  9896. * function square(n) {
  9897. * return n * n;
  9898. * }
  9899. *
  9900. * var func = _.overArgs(function(x, y) {
  9901. * return [x, y];
  9902. * }, [square, doubled]);
  9903. *
  9904. * func(9, 3);
  9905. * // => [81, 6]
  9906. *
  9907. * func(10, 5);
  9908. * // => [100, 10]
  9909. */
  9910. var overArgs = castRest(function(func, transforms) {
  9911. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9912. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9913. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9914. var funcsLength = transforms.length;
  9915. return baseRest(function(args) {
  9916. var index = -1,
  9917. length = nativeMin(args.length, funcsLength);
  9918. while (++index < length) {
  9919. args[index] = transforms[index].call(this, args[index]);
  9920. }
  9921. return apply(func, this, args);
  9922. });
  9923. });
  9924. /**
  9925. * Creates a function that invokes `func` with `partials` prepended to the
  9926. * arguments it receives. This method is like `_.bind` except it does **not**
  9927. * alter the `this` binding.
  9928. *
  9929. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9930. * builds, may be used as a placeholder for partially applied arguments.
  9931. *
  9932. * **Note:** This method doesn't set the "length" property of partially
  9933. * applied functions.
  9934. *
  9935. * @static
  9936. * @memberOf _
  9937. * @since 0.2.0
  9938. * @category Function
  9939. * @param {Function} func The function to partially apply arguments to.
  9940. * @param {...*} [partials] The arguments to be partially applied.
  9941. * @returns {Function} Returns the new partially applied function.
  9942. * @example
  9943. *
  9944. * function greet(greeting, name) {
  9945. * return greeting + ' ' + name;
  9946. * }
  9947. *
  9948. * var sayHelloTo = _.partial(greet, 'hello');
  9949. * sayHelloTo('fred');
  9950. * // => 'hello fred'
  9951. *
  9952. * // Partially applied with placeholders.
  9953. * var greetFred = _.partial(greet, _, 'fred');
  9954. * greetFred('hi');
  9955. * // => 'hi fred'
  9956. */
  9957. var partial = baseRest(function(func, partials) {
  9958. var holders = replaceHolders(partials, getHolder(partial));
  9959. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9960. });
  9961. /**
  9962. * This method is like `_.partial` except that partially applied arguments
  9963. * are appended to the arguments it receives.
  9964. *
  9965. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9966. * builds, may be used as a placeholder for partially applied arguments.
  9967. *
  9968. * **Note:** This method doesn't set the "length" property of partially
  9969. * applied functions.
  9970. *
  9971. * @static
  9972. * @memberOf _
  9973. * @since 1.0.0
  9974. * @category Function
  9975. * @param {Function} func The function to partially apply arguments to.
  9976. * @param {...*} [partials] The arguments to be partially applied.
  9977. * @returns {Function} Returns the new partially applied function.
  9978. * @example
  9979. *
  9980. * function greet(greeting, name) {
  9981. * return greeting + ' ' + name;
  9982. * }
  9983. *
  9984. * var greetFred = _.partialRight(greet, 'fred');
  9985. * greetFred('hi');
  9986. * // => 'hi fred'
  9987. *
  9988. * // Partially applied with placeholders.
  9989. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9990. * sayHelloTo('fred');
  9991. * // => 'hello fred'
  9992. */
  9993. var partialRight = baseRest(function(func, partials) {
  9994. var holders = replaceHolders(partials, getHolder(partialRight));
  9995. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9996. });
  9997. /**
  9998. * Creates a function that invokes `func` with arguments arranged according
  9999. * to the specified `indexes` where the argument value at the first index is
  10000. * provided as the first argument, the argument value at the second index is
  10001. * provided as the second argument, and so on.
  10002. *
  10003. * @static
  10004. * @memberOf _
  10005. * @since 3.0.0
  10006. * @category Function
  10007. * @param {Function} func The function to rearrange arguments for.
  10008. * @param {...(number|number[])} indexes The arranged argument indexes.
  10009. * @returns {Function} Returns the new function.
  10010. * @example
  10011. *
  10012. * var rearged = _.rearg(function(a, b, c) {
  10013. * return [a, b, c];
  10014. * }, [2, 0, 1]);
  10015. *
  10016. * rearged('b', 'c', 'a')
  10017. * // => ['a', 'b', 'c']
  10018. */
  10019. var rearg = flatRest(function(func, indexes) {
  10020. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10021. });
  10022. /**
  10023. * Creates a function that invokes `func` with the `this` binding of the
  10024. * created function and arguments from `start` and beyond provided as
  10025. * an array.
  10026. *
  10027. * **Note:** This method is based on the
  10028. * [rest parameter](https://mdn.io/rest_parameters).
  10029. *
  10030. * @static
  10031. * @memberOf _
  10032. * @since 4.0.0
  10033. * @category Function
  10034. * @param {Function} func The function to apply a rest parameter to.
  10035. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10036. * @returns {Function} Returns the new function.
  10037. * @example
  10038. *
  10039. * var say = _.rest(function(what, names) {
  10040. * return what + ' ' + _.initial(names).join(', ') +
  10041. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10042. * });
  10043. *
  10044. * say('hello', 'fred', 'barney', 'pebbles');
  10045. * // => 'hello fred, barney, & pebbles'
  10046. */
  10047. function rest(func, start) {
  10048. if (typeof func != 'function') {
  10049. throw new TypeError(FUNC_ERROR_TEXT);
  10050. }
  10051. start = start === undefined ? start : toInteger(start);
  10052. return baseRest(func, start);
  10053. }
  10054. /**
  10055. * Creates a function that invokes `func` with the `this` binding of the
  10056. * create function and an array of arguments much like
  10057. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10058. *
  10059. * **Note:** This method is based on the
  10060. * [spread operator](https://mdn.io/spread_operator).
  10061. *
  10062. * @static
  10063. * @memberOf _
  10064. * @since 3.2.0
  10065. * @category Function
  10066. * @param {Function} func The function to spread arguments over.
  10067. * @param {number} [start=0] The start position of the spread.
  10068. * @returns {Function} Returns the new function.
  10069. * @example
  10070. *
  10071. * var say = _.spread(function(who, what) {
  10072. * return who + ' says ' + what;
  10073. * });
  10074. *
  10075. * say(['fred', 'hello']);
  10076. * // => 'fred says hello'
  10077. *
  10078. * var numbers = Promise.all([
  10079. * Promise.resolve(40),
  10080. * Promise.resolve(36)
  10081. * ]);
  10082. *
  10083. * numbers.then(_.spread(function(x, y) {
  10084. * return x + y;
  10085. * }));
  10086. * // => a Promise of 76
  10087. */
  10088. function spread(func, start) {
  10089. if (typeof func != 'function') {
  10090. throw new TypeError(FUNC_ERROR_TEXT);
  10091. }
  10092. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10093. return baseRest(function(args) {
  10094. var array = args[start],
  10095. otherArgs = castSlice(args, 0, start);
  10096. if (array) {
  10097. arrayPush(otherArgs, array);
  10098. }
  10099. return apply(func, this, otherArgs);
  10100. });
  10101. }
  10102. /**
  10103. * Creates a throttled function that only invokes `func` at most once per
  10104. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10105. * method to cancel delayed `func` invocations and a `flush` method to
  10106. * immediately invoke them. Provide `options` to indicate whether `func`
  10107. * should be invoked on the leading and/or trailing edge of the `wait`
  10108. * timeout. The `func` is invoked with the last arguments provided to the
  10109. * throttled function. Subsequent calls to the throttled function return the
  10110. * result of the last `func` invocation.
  10111. *
  10112. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10113. * invoked on the trailing edge of the timeout only if the throttled function
  10114. * is invoked more than once during the `wait` timeout.
  10115. *
  10116. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10117. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10118. *
  10119. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10120. * for details over the differences between `_.throttle` and `_.debounce`.
  10121. *
  10122. * @static
  10123. * @memberOf _
  10124. * @since 0.1.0
  10125. * @category Function
  10126. * @param {Function} func The function to throttle.
  10127. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10128. * @param {Object} [options={}] The options object.
  10129. * @param {boolean} [options.leading=true]
  10130. * Specify invoking on the leading edge of the timeout.
  10131. * @param {boolean} [options.trailing=true]
  10132. * Specify invoking on the trailing edge of the timeout.
  10133. * @returns {Function} Returns the new throttled function.
  10134. * @example
  10135. *
  10136. * // Avoid excessively updating the position while scrolling.
  10137. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10138. *
  10139. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10140. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10141. * jQuery(element).on('click', throttled);
  10142. *
  10143. * // Cancel the trailing throttled invocation.
  10144. * jQuery(window).on('popstate', throttled.cancel);
  10145. */
  10146. function throttle(func, wait, options) {
  10147. var leading = true,
  10148. trailing = true;
  10149. if (typeof func != 'function') {
  10150. throw new TypeError(FUNC_ERROR_TEXT);
  10151. }
  10152. if (isObject(options)) {
  10153. leading = 'leading' in options ? !!options.leading : leading;
  10154. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10155. }
  10156. return debounce(func, wait, {
  10157. 'leading': leading,
  10158. 'maxWait': wait,
  10159. 'trailing': trailing
  10160. });
  10161. }
  10162. /**
  10163. * Creates a function that accepts up to one argument, ignoring any
  10164. * additional arguments.
  10165. *
  10166. * @static
  10167. * @memberOf _
  10168. * @since 4.0.0
  10169. * @category Function
  10170. * @param {Function} func The function to cap arguments for.
  10171. * @returns {Function} Returns the new capped function.
  10172. * @example
  10173. *
  10174. * _.map(['6', '8', '10'], _.unary(parseInt));
  10175. * // => [6, 8, 10]
  10176. */
  10177. function unary(func) {
  10178. return ary(func, 1);
  10179. }
  10180. /**
  10181. * Creates a function that provides `value` to `wrapper` as its first
  10182. * argument. Any additional arguments provided to the function are appended
  10183. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10184. * binding of the created function.
  10185. *
  10186. * @static
  10187. * @memberOf _
  10188. * @since 0.1.0
  10189. * @category Function
  10190. * @param {*} value The value to wrap.
  10191. * @param {Function} [wrapper=identity] The wrapper function.
  10192. * @returns {Function} Returns the new function.
  10193. * @example
  10194. *
  10195. * var p = _.wrap(_.escape, function(func, text) {
  10196. * return '<p>' + func(text) + '</p>';
  10197. * });
  10198. *
  10199. * p('fred, barney, & pebbles');
  10200. * // => '<p>fred, barney, &amp; pebbles</p>'
  10201. */
  10202. function wrap(value, wrapper) {
  10203. return partial(castFunction(wrapper), value);
  10204. }
  10205. /*------------------------------------------------------------------------*/
  10206. /**
  10207. * Casts `value` as an array if it's not one.
  10208. *
  10209. * @static
  10210. * @memberOf _
  10211. * @since 4.4.0
  10212. * @category Lang
  10213. * @param {*} value The value to inspect.
  10214. * @returns {Array} Returns the cast array.
  10215. * @example
  10216. *
  10217. * _.castArray(1);
  10218. * // => [1]
  10219. *
  10220. * _.castArray({ 'a': 1 });
  10221. * // => [{ 'a': 1 }]
  10222. *
  10223. * _.castArray('abc');
  10224. * // => ['abc']
  10225. *
  10226. * _.castArray(null);
  10227. * // => [null]
  10228. *
  10229. * _.castArray(undefined);
  10230. * // => [undefined]
  10231. *
  10232. * _.castArray();
  10233. * // => []
  10234. *
  10235. * var array = [1, 2, 3];
  10236. * console.log(_.castArray(array) === array);
  10237. * // => true
  10238. */
  10239. function castArray() {
  10240. if (!arguments.length) {
  10241. return [];
  10242. }
  10243. var value = arguments[0];
  10244. return isArray(value) ? value : [value];
  10245. }
  10246. /**
  10247. * Creates a shallow clone of `value`.
  10248. *
  10249. * **Note:** This method is loosely based on the
  10250. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10251. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10252. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10253. * arrays. The own enumerable properties of `arguments` objects are cloned
  10254. * as plain objects. An empty object is returned for uncloneable values such
  10255. * as error objects, functions, DOM nodes, and WeakMaps.
  10256. *
  10257. * @static
  10258. * @memberOf _
  10259. * @since 0.1.0
  10260. * @category Lang
  10261. * @param {*} value The value to clone.
  10262. * @returns {*} Returns the cloned value.
  10263. * @see _.cloneDeep
  10264. * @example
  10265. *
  10266. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10267. *
  10268. * var shallow = _.clone(objects);
  10269. * console.log(shallow[0] === objects[0]);
  10270. * // => true
  10271. */
  10272. function clone(value) {
  10273. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10274. }
  10275. /**
  10276. * This method is like `_.clone` except that it accepts `customizer` which
  10277. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10278. * cloning is handled by the method instead. The `customizer` is invoked with
  10279. * up to four arguments; (value [, index|key, object, stack]).
  10280. *
  10281. * @static
  10282. * @memberOf _
  10283. * @since 4.0.0
  10284. * @category Lang
  10285. * @param {*} value The value to clone.
  10286. * @param {Function} [customizer] The function to customize cloning.
  10287. * @returns {*} Returns the cloned value.
  10288. * @see _.cloneDeepWith
  10289. * @example
  10290. *
  10291. * function customizer(value) {
  10292. * if (_.isElement(value)) {
  10293. * return value.cloneNode(false);
  10294. * }
  10295. * }
  10296. *
  10297. * var el = _.cloneWith(document.body, customizer);
  10298. *
  10299. * console.log(el === document.body);
  10300. * // => false
  10301. * console.log(el.nodeName);
  10302. * // => 'BODY'
  10303. * console.log(el.childNodes.length);
  10304. * // => 0
  10305. */
  10306. function cloneWith(value, customizer) {
  10307. customizer = typeof customizer == 'function' ? customizer : undefined;
  10308. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10309. }
  10310. /**
  10311. * This method is like `_.clone` except that it recursively clones `value`.
  10312. *
  10313. * @static
  10314. * @memberOf _
  10315. * @since 1.0.0
  10316. * @category Lang
  10317. * @param {*} value The value to recursively clone.
  10318. * @returns {*} Returns the deep cloned value.
  10319. * @see _.clone
  10320. * @example
  10321. *
  10322. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10323. *
  10324. * var deep = _.cloneDeep(objects);
  10325. * console.log(deep[0] === objects[0]);
  10326. * // => false
  10327. */
  10328. function cloneDeep(value) {
  10329. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10330. }
  10331. /**
  10332. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10333. *
  10334. * @static
  10335. * @memberOf _
  10336. * @since 4.0.0
  10337. * @category Lang
  10338. * @param {*} value The value to recursively clone.
  10339. * @param {Function} [customizer] The function to customize cloning.
  10340. * @returns {*} Returns the deep cloned value.
  10341. * @see _.cloneWith
  10342. * @example
  10343. *
  10344. * function customizer(value) {
  10345. * if (_.isElement(value)) {
  10346. * return value.cloneNode(true);
  10347. * }
  10348. * }
  10349. *
  10350. * var el = _.cloneDeepWith(document.body, customizer);
  10351. *
  10352. * console.log(el === document.body);
  10353. * // => false
  10354. * console.log(el.nodeName);
  10355. * // => 'BODY'
  10356. * console.log(el.childNodes.length);
  10357. * // => 20
  10358. */
  10359. function cloneDeepWith(value, customizer) {
  10360. customizer = typeof customizer == 'function' ? customizer : undefined;
  10361. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10362. }
  10363. /**
  10364. * Checks if `object` conforms to `source` by invoking the predicate
  10365. * properties of `source` with the corresponding property values of `object`.
  10366. *
  10367. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10368. * partially applied.
  10369. *
  10370. * @static
  10371. * @memberOf _
  10372. * @since 4.14.0
  10373. * @category Lang
  10374. * @param {Object} object The object to inspect.
  10375. * @param {Object} source The object of property predicates to conform to.
  10376. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10377. * @example
  10378. *
  10379. * var object = { 'a': 1, 'b': 2 };
  10380. *
  10381. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10382. * // => true
  10383. *
  10384. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10385. * // => false
  10386. */
  10387. function conformsTo(object, source) {
  10388. return source == null || baseConformsTo(object, source, keys(source));
  10389. }
  10390. /**
  10391. * Performs a
  10392. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10393. * comparison between two values to determine if they are equivalent.
  10394. *
  10395. * @static
  10396. * @memberOf _
  10397. * @since 4.0.0
  10398. * @category Lang
  10399. * @param {*} value The value to compare.
  10400. * @param {*} other The other value to compare.
  10401. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10402. * @example
  10403. *
  10404. * var object = { 'a': 1 };
  10405. * var other = { 'a': 1 };
  10406. *
  10407. * _.eq(object, object);
  10408. * // => true
  10409. *
  10410. * _.eq(object, other);
  10411. * // => false
  10412. *
  10413. * _.eq('a', 'a');
  10414. * // => true
  10415. *
  10416. * _.eq('a', Object('a'));
  10417. * // => false
  10418. *
  10419. * _.eq(NaN, NaN);
  10420. * // => true
  10421. */
  10422. function eq(value, other) {
  10423. return value === other || (value !== value && other !== other);
  10424. }
  10425. /**
  10426. * Checks if `value` is greater than `other`.
  10427. *
  10428. * @static
  10429. * @memberOf _
  10430. * @since 3.9.0
  10431. * @category Lang
  10432. * @param {*} value The value to compare.
  10433. * @param {*} other The other value to compare.
  10434. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10435. * else `false`.
  10436. * @see _.lt
  10437. * @example
  10438. *
  10439. * _.gt(3, 1);
  10440. * // => true
  10441. *
  10442. * _.gt(3, 3);
  10443. * // => false
  10444. *
  10445. * _.gt(1, 3);
  10446. * // => false
  10447. */
  10448. var gt = createRelationalOperation(baseGt);
  10449. /**
  10450. * Checks if `value` is greater than or equal to `other`.
  10451. *
  10452. * @static
  10453. * @memberOf _
  10454. * @since 3.9.0
  10455. * @category Lang
  10456. * @param {*} value The value to compare.
  10457. * @param {*} other The other value to compare.
  10458. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10459. * `other`, else `false`.
  10460. * @see _.lte
  10461. * @example
  10462. *
  10463. * _.gte(3, 1);
  10464. * // => true
  10465. *
  10466. * _.gte(3, 3);
  10467. * // => true
  10468. *
  10469. * _.gte(1, 3);
  10470. * // => false
  10471. */
  10472. var gte = createRelationalOperation(function(value, other) {
  10473. return value >= other;
  10474. });
  10475. /**
  10476. * Checks if `value` is likely an `arguments` object.
  10477. *
  10478. * @static
  10479. * @memberOf _
  10480. * @since 0.1.0
  10481. * @category Lang
  10482. * @param {*} value The value to check.
  10483. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10484. * else `false`.
  10485. * @example
  10486. *
  10487. * _.isArguments(function() { return arguments; }());
  10488. * // => true
  10489. *
  10490. * _.isArguments([1, 2, 3]);
  10491. * // => false
  10492. */
  10493. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10494. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10495. !propertyIsEnumerable.call(value, 'callee');
  10496. };
  10497. /**
  10498. * Checks if `value` is classified as an `Array` object.
  10499. *
  10500. * @static
  10501. * @memberOf _
  10502. * @since 0.1.0
  10503. * @category Lang
  10504. * @param {*} value The value to check.
  10505. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10506. * @example
  10507. *
  10508. * _.isArray([1, 2, 3]);
  10509. * // => true
  10510. *
  10511. * _.isArray(document.body.children);
  10512. * // => false
  10513. *
  10514. * _.isArray('abc');
  10515. * // => false
  10516. *
  10517. * _.isArray(_.noop);
  10518. * // => false
  10519. */
  10520. var isArray = Array.isArray;
  10521. /**
  10522. * Checks if `value` is classified as an `ArrayBuffer` object.
  10523. *
  10524. * @static
  10525. * @memberOf _
  10526. * @since 4.3.0
  10527. * @category Lang
  10528. * @param {*} value The value to check.
  10529. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10530. * @example
  10531. *
  10532. * _.isArrayBuffer(new ArrayBuffer(2));
  10533. * // => true
  10534. *
  10535. * _.isArrayBuffer(new Array(2));
  10536. * // => false
  10537. */
  10538. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10539. /**
  10540. * Checks if `value` is array-like. A value is considered array-like if it's
  10541. * not a function and has a `value.length` that's an integer greater than or
  10542. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10543. *
  10544. * @static
  10545. * @memberOf _
  10546. * @since 4.0.0
  10547. * @category Lang
  10548. * @param {*} value The value to check.
  10549. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10550. * @example
  10551. *
  10552. * _.isArrayLike([1, 2, 3]);
  10553. * // => true
  10554. *
  10555. * _.isArrayLike(document.body.children);
  10556. * // => true
  10557. *
  10558. * _.isArrayLike('abc');
  10559. * // => true
  10560. *
  10561. * _.isArrayLike(_.noop);
  10562. * // => false
  10563. */
  10564. function isArrayLike(value) {
  10565. return value != null && isLength(value.length) && !isFunction(value);
  10566. }
  10567. /**
  10568. * This method is like `_.isArrayLike` except that it also checks if `value`
  10569. * is an object.
  10570. *
  10571. * @static
  10572. * @memberOf _
  10573. * @since 4.0.0
  10574. * @category Lang
  10575. * @param {*} value The value to check.
  10576. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10577. * else `false`.
  10578. * @example
  10579. *
  10580. * _.isArrayLikeObject([1, 2, 3]);
  10581. * // => true
  10582. *
  10583. * _.isArrayLikeObject(document.body.children);
  10584. * // => true
  10585. *
  10586. * _.isArrayLikeObject('abc');
  10587. * // => false
  10588. *
  10589. * _.isArrayLikeObject(_.noop);
  10590. * // => false
  10591. */
  10592. function isArrayLikeObject(value) {
  10593. return isObjectLike(value) && isArrayLike(value);
  10594. }
  10595. /**
  10596. * Checks if `value` is classified as a boolean primitive or object.
  10597. *
  10598. * @static
  10599. * @memberOf _
  10600. * @since 0.1.0
  10601. * @category Lang
  10602. * @param {*} value The value to check.
  10603. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10604. * @example
  10605. *
  10606. * _.isBoolean(false);
  10607. * // => true
  10608. *
  10609. * _.isBoolean(null);
  10610. * // => false
  10611. */
  10612. function isBoolean(value) {
  10613. return value === true || value === false ||
  10614. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10615. }
  10616. /**
  10617. * Checks if `value` is a buffer.
  10618. *
  10619. * @static
  10620. * @memberOf _
  10621. * @since 4.3.0
  10622. * @category Lang
  10623. * @param {*} value The value to check.
  10624. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10625. * @example
  10626. *
  10627. * _.isBuffer(new Buffer(2));
  10628. * // => true
  10629. *
  10630. * _.isBuffer(new Uint8Array(2));
  10631. * // => false
  10632. */
  10633. var isBuffer = nativeIsBuffer || stubFalse;
  10634. /**
  10635. * Checks if `value` is classified as a `Date` object.
  10636. *
  10637. * @static
  10638. * @memberOf _
  10639. * @since 0.1.0
  10640. * @category Lang
  10641. * @param {*} value The value to check.
  10642. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10643. * @example
  10644. *
  10645. * _.isDate(new Date);
  10646. * // => true
  10647. *
  10648. * _.isDate('Mon April 23 2012');
  10649. * // => false
  10650. */
  10651. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10652. /**
  10653. * Checks if `value` is likely a DOM element.
  10654. *
  10655. * @static
  10656. * @memberOf _
  10657. * @since 0.1.0
  10658. * @category Lang
  10659. * @param {*} value The value to check.
  10660. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10661. * @example
  10662. *
  10663. * _.isElement(document.body);
  10664. * // => true
  10665. *
  10666. * _.isElement('<body>');
  10667. * // => false
  10668. */
  10669. function isElement(value) {
  10670. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10671. }
  10672. /**
  10673. * Checks if `value` is an empty object, collection, map, or set.
  10674. *
  10675. * Objects are considered empty if they have no own enumerable string keyed
  10676. * properties.
  10677. *
  10678. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10679. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10680. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10681. *
  10682. * @static
  10683. * @memberOf _
  10684. * @since 0.1.0
  10685. * @category Lang
  10686. * @param {*} value The value to check.
  10687. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10688. * @example
  10689. *
  10690. * _.isEmpty(null);
  10691. * // => true
  10692. *
  10693. * _.isEmpty(true);
  10694. * // => true
  10695. *
  10696. * _.isEmpty(1);
  10697. * // => true
  10698. *
  10699. * _.isEmpty([1, 2, 3]);
  10700. * // => false
  10701. *
  10702. * _.isEmpty({ 'a': 1 });
  10703. * // => false
  10704. */
  10705. function isEmpty(value) {
  10706. if (value == null) {
  10707. return true;
  10708. }
  10709. if (isArrayLike(value) &&
  10710. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10711. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10712. return !value.length;
  10713. }
  10714. var tag = getTag(value);
  10715. if (tag == mapTag || tag == setTag) {
  10716. return !value.size;
  10717. }
  10718. if (isPrototype(value)) {
  10719. return !baseKeys(value).length;
  10720. }
  10721. for (var key in value) {
  10722. if (hasOwnProperty.call(value, key)) {
  10723. return false;
  10724. }
  10725. }
  10726. return true;
  10727. }
  10728. /**
  10729. * Performs a deep comparison between two values to determine if they are
  10730. * equivalent.
  10731. *
  10732. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10733. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10734. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10735. * by their own, not inherited, enumerable properties. Functions and DOM
  10736. * nodes are compared by strict equality, i.e. `===`.
  10737. *
  10738. * @static
  10739. * @memberOf _
  10740. * @since 0.1.0
  10741. * @category Lang
  10742. * @param {*} value The value to compare.
  10743. * @param {*} other The other value to compare.
  10744. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10745. * @example
  10746. *
  10747. * var object = { 'a': 1 };
  10748. * var other = { 'a': 1 };
  10749. *
  10750. * _.isEqual(object, other);
  10751. * // => true
  10752. *
  10753. * object === other;
  10754. * // => false
  10755. */
  10756. function isEqual(value, other) {
  10757. return baseIsEqual(value, other);
  10758. }
  10759. /**
  10760. * This method is like `_.isEqual` except that it accepts `customizer` which
  10761. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10762. * are handled by the method instead. The `customizer` is invoked with up to
  10763. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10764. *
  10765. * @static
  10766. * @memberOf _
  10767. * @since 4.0.0
  10768. * @category Lang
  10769. * @param {*} value The value to compare.
  10770. * @param {*} other The other value to compare.
  10771. * @param {Function} [customizer] The function to customize comparisons.
  10772. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10773. * @example
  10774. *
  10775. * function isGreeting(value) {
  10776. * return /^h(?:i|ello)$/.test(value);
  10777. * }
  10778. *
  10779. * function customizer(objValue, othValue) {
  10780. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10781. * return true;
  10782. * }
  10783. * }
  10784. *
  10785. * var array = ['hello', 'goodbye'];
  10786. * var other = ['hi', 'goodbye'];
  10787. *
  10788. * _.isEqualWith(array, other, customizer);
  10789. * // => true
  10790. */
  10791. function isEqualWith(value, other, customizer) {
  10792. customizer = typeof customizer == 'function' ? customizer : undefined;
  10793. var result = customizer ? customizer(value, other) : undefined;
  10794. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10795. }
  10796. /**
  10797. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10798. * `SyntaxError`, `TypeError`, or `URIError` object.
  10799. *
  10800. * @static
  10801. * @memberOf _
  10802. * @since 3.0.0
  10803. * @category Lang
  10804. * @param {*} value The value to check.
  10805. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10806. * @example
  10807. *
  10808. * _.isError(new Error);
  10809. * // => true
  10810. *
  10811. * _.isError(Error);
  10812. * // => false
  10813. */
  10814. function isError(value) {
  10815. if (!isObjectLike(value)) {
  10816. return false;
  10817. }
  10818. var tag = baseGetTag(value);
  10819. return tag == errorTag || tag == domExcTag ||
  10820. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10821. }
  10822. /**
  10823. * Checks if `value` is a finite primitive number.
  10824. *
  10825. * **Note:** This method is based on
  10826. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10827. *
  10828. * @static
  10829. * @memberOf _
  10830. * @since 0.1.0
  10831. * @category Lang
  10832. * @param {*} value The value to check.
  10833. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10834. * @example
  10835. *
  10836. * _.isFinite(3);
  10837. * // => true
  10838. *
  10839. * _.isFinite(Number.MIN_VALUE);
  10840. * // => true
  10841. *
  10842. * _.isFinite(Infinity);
  10843. * // => false
  10844. *
  10845. * _.isFinite('3');
  10846. * // => false
  10847. */
  10848. function isFinite(value) {
  10849. return typeof value == 'number' && nativeIsFinite(value);
  10850. }
  10851. /**
  10852. * Checks if `value` is classified as a `Function` object.
  10853. *
  10854. * @static
  10855. * @memberOf _
  10856. * @since 0.1.0
  10857. * @category Lang
  10858. * @param {*} value The value to check.
  10859. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10860. * @example
  10861. *
  10862. * _.isFunction(_);
  10863. * // => true
  10864. *
  10865. * _.isFunction(/abc/);
  10866. * // => false
  10867. */
  10868. function isFunction(value) {
  10869. if (!isObject(value)) {
  10870. return false;
  10871. }
  10872. // The use of `Object#toString` avoids issues with the `typeof` operator
  10873. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10874. var tag = baseGetTag(value);
  10875. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10876. }
  10877. /**
  10878. * Checks if `value` is an integer.
  10879. *
  10880. * **Note:** This method is based on
  10881. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10882. *
  10883. * @static
  10884. * @memberOf _
  10885. * @since 4.0.0
  10886. * @category Lang
  10887. * @param {*} value The value to check.
  10888. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10889. * @example
  10890. *
  10891. * _.isInteger(3);
  10892. * // => true
  10893. *
  10894. * _.isInteger(Number.MIN_VALUE);
  10895. * // => false
  10896. *
  10897. * _.isInteger(Infinity);
  10898. * // => false
  10899. *
  10900. * _.isInteger('3');
  10901. * // => false
  10902. */
  10903. function isInteger(value) {
  10904. return typeof value == 'number' && value == toInteger(value);
  10905. }
  10906. /**
  10907. * Checks if `value` is a valid array-like length.
  10908. *
  10909. * **Note:** This method is loosely based on
  10910. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10911. *
  10912. * @static
  10913. * @memberOf _
  10914. * @since 4.0.0
  10915. * @category Lang
  10916. * @param {*} value The value to check.
  10917. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10918. * @example
  10919. *
  10920. * _.isLength(3);
  10921. * // => true
  10922. *
  10923. * _.isLength(Number.MIN_VALUE);
  10924. * // => false
  10925. *
  10926. * _.isLength(Infinity);
  10927. * // => false
  10928. *
  10929. * _.isLength('3');
  10930. * // => false
  10931. */
  10932. function isLength(value) {
  10933. return typeof value == 'number' &&
  10934. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10935. }
  10936. /**
  10937. * Checks if `value` is the
  10938. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10939. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10940. *
  10941. * @static
  10942. * @memberOf _
  10943. * @since 0.1.0
  10944. * @category Lang
  10945. * @param {*} value The value to check.
  10946. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10947. * @example
  10948. *
  10949. * _.isObject({});
  10950. * // => true
  10951. *
  10952. * _.isObject([1, 2, 3]);
  10953. * // => true
  10954. *
  10955. * _.isObject(_.noop);
  10956. * // => true
  10957. *
  10958. * _.isObject(null);
  10959. * // => false
  10960. */
  10961. function isObject(value) {
  10962. var type = typeof value;
  10963. return value != null && (type == 'object' || type == 'function');
  10964. }
  10965. /**
  10966. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10967. * and has a `typeof` result of "object".
  10968. *
  10969. * @static
  10970. * @memberOf _
  10971. * @since 4.0.0
  10972. * @category Lang
  10973. * @param {*} value The value to check.
  10974. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10975. * @example
  10976. *
  10977. * _.isObjectLike({});
  10978. * // => true
  10979. *
  10980. * _.isObjectLike([1, 2, 3]);
  10981. * // => true
  10982. *
  10983. * _.isObjectLike(_.noop);
  10984. * // => false
  10985. *
  10986. * _.isObjectLike(null);
  10987. * // => false
  10988. */
  10989. function isObjectLike(value) {
  10990. return value != null && typeof value == 'object';
  10991. }
  10992. /**
  10993. * Checks if `value` is classified as a `Map` object.
  10994. *
  10995. * @static
  10996. * @memberOf _
  10997. * @since 4.3.0
  10998. * @category Lang
  10999. * @param {*} value The value to check.
  11000. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11001. * @example
  11002. *
  11003. * _.isMap(new Map);
  11004. * // => true
  11005. *
  11006. * _.isMap(new WeakMap);
  11007. * // => false
  11008. */
  11009. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11010. /**
  11011. * Performs a partial deep comparison between `object` and `source` to
  11012. * determine if `object` contains equivalent property values.
  11013. *
  11014. * **Note:** This method is equivalent to `_.matches` when `source` is
  11015. * partially applied.
  11016. *
  11017. * Partial comparisons will match empty array and empty object `source`
  11018. * values against any array or object value, respectively. See `_.isEqual`
  11019. * for a list of supported value comparisons.
  11020. *
  11021. * @static
  11022. * @memberOf _
  11023. * @since 3.0.0
  11024. * @category Lang
  11025. * @param {Object} object The object to inspect.
  11026. * @param {Object} source The object of property values to match.
  11027. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11028. * @example
  11029. *
  11030. * var object = { 'a': 1, 'b': 2 };
  11031. *
  11032. * _.isMatch(object, { 'b': 2 });
  11033. * // => true
  11034. *
  11035. * _.isMatch(object, { 'b': 1 });
  11036. * // => false
  11037. */
  11038. function isMatch(object, source) {
  11039. return object === source || baseIsMatch(object, source, getMatchData(source));
  11040. }
  11041. /**
  11042. * This method is like `_.isMatch` except that it accepts `customizer` which
  11043. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11044. * are handled by the method instead. The `customizer` is invoked with five
  11045. * arguments: (objValue, srcValue, index|key, object, source).
  11046. *
  11047. * @static
  11048. * @memberOf _
  11049. * @since 4.0.0
  11050. * @category Lang
  11051. * @param {Object} object The object to inspect.
  11052. * @param {Object} source The object of property values to match.
  11053. * @param {Function} [customizer] The function to customize comparisons.
  11054. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11055. * @example
  11056. *
  11057. * function isGreeting(value) {
  11058. * return /^h(?:i|ello)$/.test(value);
  11059. * }
  11060. *
  11061. * function customizer(objValue, srcValue) {
  11062. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11063. * return true;
  11064. * }
  11065. * }
  11066. *
  11067. * var object = { 'greeting': 'hello' };
  11068. * var source = { 'greeting': 'hi' };
  11069. *
  11070. * _.isMatchWith(object, source, customizer);
  11071. * // => true
  11072. */
  11073. function isMatchWith(object, source, customizer) {
  11074. customizer = typeof customizer == 'function' ? customizer : undefined;
  11075. return baseIsMatch(object, source, getMatchData(source), customizer);
  11076. }
  11077. /**
  11078. * Checks if `value` is `NaN`.
  11079. *
  11080. * **Note:** This method is based on
  11081. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11082. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11083. * `undefined` and other non-number values.
  11084. *
  11085. * @static
  11086. * @memberOf _
  11087. * @since 0.1.0
  11088. * @category Lang
  11089. * @param {*} value The value to check.
  11090. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11091. * @example
  11092. *
  11093. * _.isNaN(NaN);
  11094. * // => true
  11095. *
  11096. * _.isNaN(new Number(NaN));
  11097. * // => true
  11098. *
  11099. * isNaN(undefined);
  11100. * // => true
  11101. *
  11102. * _.isNaN(undefined);
  11103. * // => false
  11104. */
  11105. function isNaN(value) {
  11106. // An `NaN` primitive is the only value that is not equal to itself.
  11107. // Perform the `toStringTag` check first to avoid errors with some
  11108. // ActiveX objects in IE.
  11109. return isNumber(value) && value != +value;
  11110. }
  11111. /**
  11112. * Checks if `value` is a pristine native function.
  11113. *
  11114. * **Note:** This method can't reliably detect native functions in the presence
  11115. * of the core-js package because core-js circumvents this kind of detection.
  11116. * Despite multiple requests, the core-js maintainer has made it clear: any
  11117. * attempt to fix the detection will be obstructed. As a result, we're left
  11118. * with little choice but to throw an error. Unfortunately, this also affects
  11119. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11120. * which rely on core-js.
  11121. *
  11122. * @static
  11123. * @memberOf _
  11124. * @since 3.0.0
  11125. * @category Lang
  11126. * @param {*} value The value to check.
  11127. * @returns {boolean} Returns `true` if `value` is a native function,
  11128. * else `false`.
  11129. * @example
  11130. *
  11131. * _.isNative(Array.prototype.push);
  11132. * // => true
  11133. *
  11134. * _.isNative(_);
  11135. * // => false
  11136. */
  11137. function isNative(value) {
  11138. if (isMaskable(value)) {
  11139. throw new Error(CORE_ERROR_TEXT);
  11140. }
  11141. return baseIsNative(value);
  11142. }
  11143. /**
  11144. * Checks if `value` is `null`.
  11145. *
  11146. * @static
  11147. * @memberOf _
  11148. * @since 0.1.0
  11149. * @category Lang
  11150. * @param {*} value The value to check.
  11151. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11152. * @example
  11153. *
  11154. * _.isNull(null);
  11155. * // => true
  11156. *
  11157. * _.isNull(void 0);
  11158. * // => false
  11159. */
  11160. function isNull(value) {
  11161. return value === null;
  11162. }
  11163. /**
  11164. * Checks if `value` is `null` or `undefined`.
  11165. *
  11166. * @static
  11167. * @memberOf _
  11168. * @since 4.0.0
  11169. * @category Lang
  11170. * @param {*} value The value to check.
  11171. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11172. * @example
  11173. *
  11174. * _.isNil(null);
  11175. * // => true
  11176. *
  11177. * _.isNil(void 0);
  11178. * // => true
  11179. *
  11180. * _.isNil(NaN);
  11181. * // => false
  11182. */
  11183. function isNil(value) {
  11184. return value == null;
  11185. }
  11186. /**
  11187. * Checks if `value` is classified as a `Number` primitive or object.
  11188. *
  11189. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11190. * classified as numbers, use the `_.isFinite` method.
  11191. *
  11192. * @static
  11193. * @memberOf _
  11194. * @since 0.1.0
  11195. * @category Lang
  11196. * @param {*} value The value to check.
  11197. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11198. * @example
  11199. *
  11200. * _.isNumber(3);
  11201. * // => true
  11202. *
  11203. * _.isNumber(Number.MIN_VALUE);
  11204. * // => true
  11205. *
  11206. * _.isNumber(Infinity);
  11207. * // => true
  11208. *
  11209. * _.isNumber('3');
  11210. * // => false
  11211. */
  11212. function isNumber(value) {
  11213. return typeof value == 'number' ||
  11214. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11215. }
  11216. /**
  11217. * Checks if `value` is a plain object, that is, an object created by the
  11218. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11219. *
  11220. * @static
  11221. * @memberOf _
  11222. * @since 0.8.0
  11223. * @category Lang
  11224. * @param {*} value The value to check.
  11225. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11226. * @example
  11227. *
  11228. * function Foo() {
  11229. * this.a = 1;
  11230. * }
  11231. *
  11232. * _.isPlainObject(new Foo);
  11233. * // => false
  11234. *
  11235. * _.isPlainObject([1, 2, 3]);
  11236. * // => false
  11237. *
  11238. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11239. * // => true
  11240. *
  11241. * _.isPlainObject(Object.create(null));
  11242. * // => true
  11243. */
  11244. function isPlainObject(value) {
  11245. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11246. return false;
  11247. }
  11248. var proto = getPrototype(value);
  11249. if (proto === null) {
  11250. return true;
  11251. }
  11252. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11253. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11254. funcToString.call(Ctor) == objectCtorString;
  11255. }
  11256. /**
  11257. * Checks if `value` is classified as a `RegExp` object.
  11258. *
  11259. * @static
  11260. * @memberOf _
  11261. * @since 0.1.0
  11262. * @category Lang
  11263. * @param {*} value The value to check.
  11264. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11265. * @example
  11266. *
  11267. * _.isRegExp(/abc/);
  11268. * // => true
  11269. *
  11270. * _.isRegExp('/abc/');
  11271. * // => false
  11272. */
  11273. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11274. /**
  11275. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11276. * double precision number which isn't the result of a rounded unsafe integer.
  11277. *
  11278. * **Note:** This method is based on
  11279. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11280. *
  11281. * @static
  11282. * @memberOf _
  11283. * @since 4.0.0
  11284. * @category Lang
  11285. * @param {*} value The value to check.
  11286. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11287. * @example
  11288. *
  11289. * _.isSafeInteger(3);
  11290. * // => true
  11291. *
  11292. * _.isSafeInteger(Number.MIN_VALUE);
  11293. * // => false
  11294. *
  11295. * _.isSafeInteger(Infinity);
  11296. * // => false
  11297. *
  11298. * _.isSafeInteger('3');
  11299. * // => false
  11300. */
  11301. function isSafeInteger(value) {
  11302. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11303. }
  11304. /**
  11305. * Checks if `value` is classified as a `Set` object.
  11306. *
  11307. * @static
  11308. * @memberOf _
  11309. * @since 4.3.0
  11310. * @category Lang
  11311. * @param {*} value The value to check.
  11312. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11313. * @example
  11314. *
  11315. * _.isSet(new Set);
  11316. * // => true
  11317. *
  11318. * _.isSet(new WeakSet);
  11319. * // => false
  11320. */
  11321. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11322. /**
  11323. * Checks if `value` is classified as a `String` primitive or object.
  11324. *
  11325. * @static
  11326. * @since 0.1.0
  11327. * @memberOf _
  11328. * @category Lang
  11329. * @param {*} value The value to check.
  11330. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11331. * @example
  11332. *
  11333. * _.isString('abc');
  11334. * // => true
  11335. *
  11336. * _.isString(1);
  11337. * // => false
  11338. */
  11339. function isString(value) {
  11340. return typeof value == 'string' ||
  11341. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11342. }
  11343. /**
  11344. * Checks if `value` is classified as a `Symbol` primitive or object.
  11345. *
  11346. * @static
  11347. * @memberOf _
  11348. * @since 4.0.0
  11349. * @category Lang
  11350. * @param {*} value The value to check.
  11351. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11352. * @example
  11353. *
  11354. * _.isSymbol(Symbol.iterator);
  11355. * // => true
  11356. *
  11357. * _.isSymbol('abc');
  11358. * // => false
  11359. */
  11360. function isSymbol(value) {
  11361. return typeof value == 'symbol' ||
  11362. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11363. }
  11364. /**
  11365. * Checks if `value` is classified as a typed array.
  11366. *
  11367. * @static
  11368. * @memberOf _
  11369. * @since 3.0.0
  11370. * @category Lang
  11371. * @param {*} value The value to check.
  11372. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11373. * @example
  11374. *
  11375. * _.isTypedArray(new Uint8Array);
  11376. * // => true
  11377. *
  11378. * _.isTypedArray([]);
  11379. * // => false
  11380. */
  11381. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11382. /**
  11383. * Checks if `value` is `undefined`.
  11384. *
  11385. * @static
  11386. * @since 0.1.0
  11387. * @memberOf _
  11388. * @category Lang
  11389. * @param {*} value The value to check.
  11390. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11391. * @example
  11392. *
  11393. * _.isUndefined(void 0);
  11394. * // => true
  11395. *
  11396. * _.isUndefined(null);
  11397. * // => false
  11398. */
  11399. function isUndefined(value) {
  11400. return value === undefined;
  11401. }
  11402. /**
  11403. * Checks if `value` is classified as a `WeakMap` object.
  11404. *
  11405. * @static
  11406. * @memberOf _
  11407. * @since 4.3.0
  11408. * @category Lang
  11409. * @param {*} value The value to check.
  11410. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11411. * @example
  11412. *
  11413. * _.isWeakMap(new WeakMap);
  11414. * // => true
  11415. *
  11416. * _.isWeakMap(new Map);
  11417. * // => false
  11418. */
  11419. function isWeakMap(value) {
  11420. return isObjectLike(value) && getTag(value) == weakMapTag;
  11421. }
  11422. /**
  11423. * Checks if `value` is classified as a `WeakSet` object.
  11424. *
  11425. * @static
  11426. * @memberOf _
  11427. * @since 4.3.0
  11428. * @category Lang
  11429. * @param {*} value The value to check.
  11430. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11431. * @example
  11432. *
  11433. * _.isWeakSet(new WeakSet);
  11434. * // => true
  11435. *
  11436. * _.isWeakSet(new Set);
  11437. * // => false
  11438. */
  11439. function isWeakSet(value) {
  11440. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11441. }
  11442. /**
  11443. * Checks if `value` is less than `other`.
  11444. *
  11445. * @static
  11446. * @memberOf _
  11447. * @since 3.9.0
  11448. * @category Lang
  11449. * @param {*} value The value to compare.
  11450. * @param {*} other The other value to compare.
  11451. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11452. * else `false`.
  11453. * @see _.gt
  11454. * @example
  11455. *
  11456. * _.lt(1, 3);
  11457. * // => true
  11458. *
  11459. * _.lt(3, 3);
  11460. * // => false
  11461. *
  11462. * _.lt(3, 1);
  11463. * // => false
  11464. */
  11465. var lt = createRelationalOperation(baseLt);
  11466. /**
  11467. * Checks if `value` is less than or equal to `other`.
  11468. *
  11469. * @static
  11470. * @memberOf _
  11471. * @since 3.9.0
  11472. * @category Lang
  11473. * @param {*} value The value to compare.
  11474. * @param {*} other The other value to compare.
  11475. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11476. * `other`, else `false`.
  11477. * @see _.gte
  11478. * @example
  11479. *
  11480. * _.lte(1, 3);
  11481. * // => true
  11482. *
  11483. * _.lte(3, 3);
  11484. * // => true
  11485. *
  11486. * _.lte(3, 1);
  11487. * // => false
  11488. */
  11489. var lte = createRelationalOperation(function(value, other) {
  11490. return value <= other;
  11491. });
  11492. /**
  11493. * Converts `value` to an array.
  11494. *
  11495. * @static
  11496. * @since 0.1.0
  11497. * @memberOf _
  11498. * @category Lang
  11499. * @param {*} value The value to convert.
  11500. * @returns {Array} Returns the converted array.
  11501. * @example
  11502. *
  11503. * _.toArray({ 'a': 1, 'b': 2 });
  11504. * // => [1, 2]
  11505. *
  11506. * _.toArray('abc');
  11507. * // => ['a', 'b', 'c']
  11508. *
  11509. * _.toArray(1);
  11510. * // => []
  11511. *
  11512. * _.toArray(null);
  11513. * // => []
  11514. */
  11515. function toArray(value) {
  11516. if (!value) {
  11517. return [];
  11518. }
  11519. if (isArrayLike(value)) {
  11520. return isString(value) ? stringToArray(value) : copyArray(value);
  11521. }
  11522. if (symIterator && value[symIterator]) {
  11523. return iteratorToArray(value[symIterator]());
  11524. }
  11525. var tag = getTag(value),
  11526. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11527. return func(value);
  11528. }
  11529. /**
  11530. * Converts `value` to a finite number.
  11531. *
  11532. * @static
  11533. * @memberOf _
  11534. * @since 4.12.0
  11535. * @category Lang
  11536. * @param {*} value The value to convert.
  11537. * @returns {number} Returns the converted number.
  11538. * @example
  11539. *
  11540. * _.toFinite(3.2);
  11541. * // => 3.2
  11542. *
  11543. * _.toFinite(Number.MIN_VALUE);
  11544. * // => 5e-324
  11545. *
  11546. * _.toFinite(Infinity);
  11547. * // => 1.7976931348623157e+308
  11548. *
  11549. * _.toFinite('3.2');
  11550. * // => 3.2
  11551. */
  11552. function toFinite(value) {
  11553. if (!value) {
  11554. return value === 0 ? value : 0;
  11555. }
  11556. value = toNumber(value);
  11557. if (value === INFINITY || value === -INFINITY) {
  11558. var sign = (value < 0 ? -1 : 1);
  11559. return sign * MAX_INTEGER;
  11560. }
  11561. return value === value ? value : 0;
  11562. }
  11563. /**
  11564. * Converts `value` to an integer.
  11565. *
  11566. * **Note:** This method is loosely based on
  11567. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11568. *
  11569. * @static
  11570. * @memberOf _
  11571. * @since 4.0.0
  11572. * @category Lang
  11573. * @param {*} value The value to convert.
  11574. * @returns {number} Returns the converted integer.
  11575. * @example
  11576. *
  11577. * _.toInteger(3.2);
  11578. * // => 3
  11579. *
  11580. * _.toInteger(Number.MIN_VALUE);
  11581. * // => 0
  11582. *
  11583. * _.toInteger(Infinity);
  11584. * // => 1.7976931348623157e+308
  11585. *
  11586. * _.toInteger('3.2');
  11587. * // => 3
  11588. */
  11589. function toInteger(value) {
  11590. var result = toFinite(value),
  11591. remainder = result % 1;
  11592. return result === result ? (remainder ? result - remainder : result) : 0;
  11593. }
  11594. /**
  11595. * Converts `value` to an integer suitable for use as the length of an
  11596. * array-like object.
  11597. *
  11598. * **Note:** This method is based on
  11599. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11600. *
  11601. * @static
  11602. * @memberOf _
  11603. * @since 4.0.0
  11604. * @category Lang
  11605. * @param {*} value The value to convert.
  11606. * @returns {number} Returns the converted integer.
  11607. * @example
  11608. *
  11609. * _.toLength(3.2);
  11610. * // => 3
  11611. *
  11612. * _.toLength(Number.MIN_VALUE);
  11613. * // => 0
  11614. *
  11615. * _.toLength(Infinity);
  11616. * // => 4294967295
  11617. *
  11618. * _.toLength('3.2');
  11619. * // => 3
  11620. */
  11621. function toLength(value) {
  11622. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11623. }
  11624. /**
  11625. * Converts `value` to a number.
  11626. *
  11627. * @static
  11628. * @memberOf _
  11629. * @since 4.0.0
  11630. * @category Lang
  11631. * @param {*} value The value to process.
  11632. * @returns {number} Returns the number.
  11633. * @example
  11634. *
  11635. * _.toNumber(3.2);
  11636. * // => 3.2
  11637. *
  11638. * _.toNumber(Number.MIN_VALUE);
  11639. * // => 5e-324
  11640. *
  11641. * _.toNumber(Infinity);
  11642. * // => Infinity
  11643. *
  11644. * _.toNumber('3.2');
  11645. * // => 3.2
  11646. */
  11647. function toNumber(value) {
  11648. if (typeof value == 'number') {
  11649. return value;
  11650. }
  11651. if (isSymbol(value)) {
  11652. return NAN;
  11653. }
  11654. if (isObject(value)) {
  11655. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11656. value = isObject(other) ? (other + '') : other;
  11657. }
  11658. if (typeof value != 'string') {
  11659. return value === 0 ? value : +value;
  11660. }
  11661. value = value.replace(reTrim, '');
  11662. var isBinary = reIsBinary.test(value);
  11663. return (isBinary || reIsOctal.test(value))
  11664. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11665. : (reIsBadHex.test(value) ? NAN : +value);
  11666. }
  11667. /**
  11668. * Converts `value` to a plain object flattening inherited enumerable string
  11669. * keyed properties of `value` to own properties of the plain object.
  11670. *
  11671. * @static
  11672. * @memberOf _
  11673. * @since 3.0.0
  11674. * @category Lang
  11675. * @param {*} value The value to convert.
  11676. * @returns {Object} Returns the converted plain object.
  11677. * @example
  11678. *
  11679. * function Foo() {
  11680. * this.b = 2;
  11681. * }
  11682. *
  11683. * Foo.prototype.c = 3;
  11684. *
  11685. * _.assign({ 'a': 1 }, new Foo);
  11686. * // => { 'a': 1, 'b': 2 }
  11687. *
  11688. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11689. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11690. */
  11691. function toPlainObject(value) {
  11692. return copyObject(value, keysIn(value));
  11693. }
  11694. /**
  11695. * Converts `value` to a safe integer. A safe integer can be compared and
  11696. * represented correctly.
  11697. *
  11698. * @static
  11699. * @memberOf _
  11700. * @since 4.0.0
  11701. * @category Lang
  11702. * @param {*} value The value to convert.
  11703. * @returns {number} Returns the converted integer.
  11704. * @example
  11705. *
  11706. * _.toSafeInteger(3.2);
  11707. * // => 3
  11708. *
  11709. * _.toSafeInteger(Number.MIN_VALUE);
  11710. * // => 0
  11711. *
  11712. * _.toSafeInteger(Infinity);
  11713. * // => 9007199254740991
  11714. *
  11715. * _.toSafeInteger('3.2');
  11716. * // => 3
  11717. */
  11718. function toSafeInteger(value) {
  11719. return value
  11720. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11721. : (value === 0 ? value : 0);
  11722. }
  11723. /**
  11724. * Converts `value` to a string. An empty string is returned for `null`
  11725. * and `undefined` values. The sign of `-0` is preserved.
  11726. *
  11727. * @static
  11728. * @memberOf _
  11729. * @since 4.0.0
  11730. * @category Lang
  11731. * @param {*} value The value to convert.
  11732. * @returns {string} Returns the converted string.
  11733. * @example
  11734. *
  11735. * _.toString(null);
  11736. * // => ''
  11737. *
  11738. * _.toString(-0);
  11739. * // => '-0'
  11740. *
  11741. * _.toString([1, 2, 3]);
  11742. * // => '1,2,3'
  11743. */
  11744. function toString(value) {
  11745. return value == null ? '' : baseToString(value);
  11746. }
  11747. /*------------------------------------------------------------------------*/
  11748. /**
  11749. * Assigns own enumerable string keyed properties of source objects to the
  11750. * destination object. Source objects are applied from left to right.
  11751. * Subsequent sources overwrite property assignments of previous sources.
  11752. *
  11753. * **Note:** This method mutates `object` and is loosely based on
  11754. * [`Object.assign`](https://mdn.io/Object/assign).
  11755. *
  11756. * @static
  11757. * @memberOf _
  11758. * @since 0.10.0
  11759. * @category Object
  11760. * @param {Object} object The destination object.
  11761. * @param {...Object} [sources] The source objects.
  11762. * @returns {Object} Returns `object`.
  11763. * @see _.assignIn
  11764. * @example
  11765. *
  11766. * function Foo() {
  11767. * this.a = 1;
  11768. * }
  11769. *
  11770. * function Bar() {
  11771. * this.c = 3;
  11772. * }
  11773. *
  11774. * Foo.prototype.b = 2;
  11775. * Bar.prototype.d = 4;
  11776. *
  11777. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11778. * // => { 'a': 1, 'c': 3 }
  11779. */
  11780. var assign = createAssigner(function(object, source) {
  11781. if (isPrototype(source) || isArrayLike(source)) {
  11782. copyObject(source, keys(source), object);
  11783. return;
  11784. }
  11785. for (var key in source) {
  11786. if (hasOwnProperty.call(source, key)) {
  11787. assignValue(object, key, source[key]);
  11788. }
  11789. }
  11790. });
  11791. /**
  11792. * This method is like `_.assign` except that it iterates over own and
  11793. * inherited source properties.
  11794. *
  11795. * **Note:** This method mutates `object`.
  11796. *
  11797. * @static
  11798. * @memberOf _
  11799. * @since 4.0.0
  11800. * @alias extend
  11801. * @category Object
  11802. * @param {Object} object The destination object.
  11803. * @param {...Object} [sources] The source objects.
  11804. * @returns {Object} Returns `object`.
  11805. * @see _.assign
  11806. * @example
  11807. *
  11808. * function Foo() {
  11809. * this.a = 1;
  11810. * }
  11811. *
  11812. * function Bar() {
  11813. * this.c = 3;
  11814. * }
  11815. *
  11816. * Foo.prototype.b = 2;
  11817. * Bar.prototype.d = 4;
  11818. *
  11819. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11820. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11821. */
  11822. var assignIn = createAssigner(function(object, source) {
  11823. copyObject(source, keysIn(source), object);
  11824. });
  11825. /**
  11826. * This method is like `_.assignIn` except that it accepts `customizer`
  11827. * which is invoked to produce the assigned values. If `customizer` returns
  11828. * `undefined`, assignment is handled by the method instead. The `customizer`
  11829. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11830. *
  11831. * **Note:** This method mutates `object`.
  11832. *
  11833. * @static
  11834. * @memberOf _
  11835. * @since 4.0.0
  11836. * @alias extendWith
  11837. * @category Object
  11838. * @param {Object} object The destination object.
  11839. * @param {...Object} sources The source objects.
  11840. * @param {Function} [customizer] The function to customize assigned values.
  11841. * @returns {Object} Returns `object`.
  11842. * @see _.assignWith
  11843. * @example
  11844. *
  11845. * function customizer(objValue, srcValue) {
  11846. * return _.isUndefined(objValue) ? srcValue : objValue;
  11847. * }
  11848. *
  11849. * var defaults = _.partialRight(_.assignInWith, customizer);
  11850. *
  11851. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11852. * // => { 'a': 1, 'b': 2 }
  11853. */
  11854. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11855. copyObject(source, keysIn(source), object, customizer);
  11856. });
  11857. /**
  11858. * This method is like `_.assign` except that it accepts `customizer`
  11859. * which is invoked to produce the assigned values. If `customizer` returns
  11860. * `undefined`, assignment is handled by the method instead. The `customizer`
  11861. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11862. *
  11863. * **Note:** This method mutates `object`.
  11864. *
  11865. * @static
  11866. * @memberOf _
  11867. * @since 4.0.0
  11868. * @category Object
  11869. * @param {Object} object The destination object.
  11870. * @param {...Object} sources The source objects.
  11871. * @param {Function} [customizer] The function to customize assigned values.
  11872. * @returns {Object} Returns `object`.
  11873. * @see _.assignInWith
  11874. * @example
  11875. *
  11876. * function customizer(objValue, srcValue) {
  11877. * return _.isUndefined(objValue) ? srcValue : objValue;
  11878. * }
  11879. *
  11880. * var defaults = _.partialRight(_.assignWith, customizer);
  11881. *
  11882. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11883. * // => { 'a': 1, 'b': 2 }
  11884. */
  11885. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11886. copyObject(source, keys(source), object, customizer);
  11887. });
  11888. /**
  11889. * Creates an array of values corresponding to `paths` of `object`.
  11890. *
  11891. * @static
  11892. * @memberOf _
  11893. * @since 1.0.0
  11894. * @category Object
  11895. * @param {Object} object The object to iterate over.
  11896. * @param {...(string|string[])} [paths] The property paths to pick.
  11897. * @returns {Array} Returns the picked values.
  11898. * @example
  11899. *
  11900. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11901. *
  11902. * _.at(object, ['a[0].b.c', 'a[1]']);
  11903. * // => [3, 4]
  11904. */
  11905. var at = flatRest(baseAt);
  11906. /**
  11907. * Creates an object that inherits from the `prototype` object. If a
  11908. * `properties` object is given, its own enumerable string keyed properties
  11909. * are assigned to the created object.
  11910. *
  11911. * @static
  11912. * @memberOf _
  11913. * @since 2.3.0
  11914. * @category Object
  11915. * @param {Object} prototype The object to inherit from.
  11916. * @param {Object} [properties] The properties to assign to the object.
  11917. * @returns {Object} Returns the new object.
  11918. * @example
  11919. *
  11920. * function Shape() {
  11921. * this.x = 0;
  11922. * this.y = 0;
  11923. * }
  11924. *
  11925. * function Circle() {
  11926. * Shape.call(this);
  11927. * }
  11928. *
  11929. * Circle.prototype = _.create(Shape.prototype, {
  11930. * 'constructor': Circle
  11931. * });
  11932. *
  11933. * var circle = new Circle;
  11934. * circle instanceof Circle;
  11935. * // => true
  11936. *
  11937. * circle instanceof Shape;
  11938. * // => true
  11939. */
  11940. function create(prototype, properties) {
  11941. var result = baseCreate(prototype);
  11942. return properties == null ? result : baseAssign(result, properties);
  11943. }
  11944. /**
  11945. * Assigns own and inherited enumerable string keyed properties of source
  11946. * objects to the destination object for all destination properties that
  11947. * resolve to `undefined`. Source objects are applied from left to right.
  11948. * Once a property is set, additional values of the same property are ignored.
  11949. *
  11950. * **Note:** This method mutates `object`.
  11951. *
  11952. * @static
  11953. * @since 0.1.0
  11954. * @memberOf _
  11955. * @category Object
  11956. * @param {Object} object The destination object.
  11957. * @param {...Object} [sources] The source objects.
  11958. * @returns {Object} Returns `object`.
  11959. * @see _.defaultsDeep
  11960. * @example
  11961. *
  11962. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11963. * // => { 'a': 1, 'b': 2 }
  11964. */
  11965. var defaults = baseRest(function(object, sources) {
  11966. object = Object(object);
  11967. var index = -1;
  11968. var length = sources.length;
  11969. var guard = length > 2 ? sources[2] : undefined;
  11970. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11971. length = 1;
  11972. }
  11973. while (++index < length) {
  11974. var source = sources[index];
  11975. var props = keysIn(source);
  11976. var propsIndex = -1;
  11977. var propsLength = props.length;
  11978. while (++propsIndex < propsLength) {
  11979. var key = props[propsIndex];
  11980. var value = object[key];
  11981. if (value === undefined ||
  11982. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11983. object[key] = source[key];
  11984. }
  11985. }
  11986. }
  11987. return object;
  11988. });
  11989. /**
  11990. * This method is like `_.defaults` except that it recursively assigns
  11991. * default properties.
  11992. *
  11993. * **Note:** This method mutates `object`.
  11994. *
  11995. * @static
  11996. * @memberOf _
  11997. * @since 3.10.0
  11998. * @category Object
  11999. * @param {Object} object The destination object.
  12000. * @param {...Object} [sources] The source objects.
  12001. * @returns {Object} Returns `object`.
  12002. * @see _.defaults
  12003. * @example
  12004. *
  12005. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12006. * // => { 'a': { 'b': 2, 'c': 3 } }
  12007. */
  12008. var defaultsDeep = baseRest(function(args) {
  12009. args.push(undefined, customDefaultsMerge);
  12010. return apply(mergeWith, undefined, args);
  12011. });
  12012. /**
  12013. * This method is like `_.find` except that it returns the key of the first
  12014. * element `predicate` returns truthy for instead of the element itself.
  12015. *
  12016. * @static
  12017. * @memberOf _
  12018. * @since 1.1.0
  12019. * @category Object
  12020. * @param {Object} object The object to inspect.
  12021. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12022. * @returns {string|undefined} Returns the key of the matched element,
  12023. * else `undefined`.
  12024. * @example
  12025. *
  12026. * var users = {
  12027. * 'barney': { 'age': 36, 'active': true },
  12028. * 'fred': { 'age': 40, 'active': false },
  12029. * 'pebbles': { 'age': 1, 'active': true }
  12030. * };
  12031. *
  12032. * _.findKey(users, function(o) { return o.age < 40; });
  12033. * // => 'barney' (iteration order is not guaranteed)
  12034. *
  12035. * // The `_.matches` iteratee shorthand.
  12036. * _.findKey(users, { 'age': 1, 'active': true });
  12037. * // => 'pebbles'
  12038. *
  12039. * // The `_.matchesProperty` iteratee shorthand.
  12040. * _.findKey(users, ['active', false]);
  12041. * // => 'fred'
  12042. *
  12043. * // The `_.property` iteratee shorthand.
  12044. * _.findKey(users, 'active');
  12045. * // => 'barney'
  12046. */
  12047. function findKey(object, predicate) {
  12048. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12049. }
  12050. /**
  12051. * This method is like `_.findKey` except that it iterates over elements of
  12052. * a collection in the opposite order.
  12053. *
  12054. * @static
  12055. * @memberOf _
  12056. * @since 2.0.0
  12057. * @category Object
  12058. * @param {Object} object The object to inspect.
  12059. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12060. * @returns {string|undefined} Returns the key of the matched element,
  12061. * else `undefined`.
  12062. * @example
  12063. *
  12064. * var users = {
  12065. * 'barney': { 'age': 36, 'active': true },
  12066. * 'fred': { 'age': 40, 'active': false },
  12067. * 'pebbles': { 'age': 1, 'active': true }
  12068. * };
  12069. *
  12070. * _.findLastKey(users, function(o) { return o.age < 40; });
  12071. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12072. *
  12073. * // The `_.matches` iteratee shorthand.
  12074. * _.findLastKey(users, { 'age': 36, 'active': true });
  12075. * // => 'barney'
  12076. *
  12077. * // The `_.matchesProperty` iteratee shorthand.
  12078. * _.findLastKey(users, ['active', false]);
  12079. * // => 'fred'
  12080. *
  12081. * // The `_.property` iteratee shorthand.
  12082. * _.findLastKey(users, 'active');
  12083. * // => 'pebbles'
  12084. */
  12085. function findLastKey(object, predicate) {
  12086. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12087. }
  12088. /**
  12089. * Iterates over own and inherited enumerable string keyed properties of an
  12090. * object and invokes `iteratee` for each property. The iteratee is invoked
  12091. * with three arguments: (value, key, object). Iteratee functions may exit
  12092. * iteration early by explicitly returning `false`.
  12093. *
  12094. * @static
  12095. * @memberOf _
  12096. * @since 0.3.0
  12097. * @category Object
  12098. * @param {Object} object The object to iterate over.
  12099. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12100. * @returns {Object} Returns `object`.
  12101. * @see _.forInRight
  12102. * @example
  12103. *
  12104. * function Foo() {
  12105. * this.a = 1;
  12106. * this.b = 2;
  12107. * }
  12108. *
  12109. * Foo.prototype.c = 3;
  12110. *
  12111. * _.forIn(new Foo, function(value, key) {
  12112. * console.log(key);
  12113. * });
  12114. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12115. */
  12116. function forIn(object, iteratee) {
  12117. return object == null
  12118. ? object
  12119. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12120. }
  12121. /**
  12122. * This method is like `_.forIn` except that it iterates over properties of
  12123. * `object` in the opposite order.
  12124. *
  12125. * @static
  12126. * @memberOf _
  12127. * @since 2.0.0
  12128. * @category Object
  12129. * @param {Object} object The object to iterate over.
  12130. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12131. * @returns {Object} Returns `object`.
  12132. * @see _.forIn
  12133. * @example
  12134. *
  12135. * function Foo() {
  12136. * this.a = 1;
  12137. * this.b = 2;
  12138. * }
  12139. *
  12140. * Foo.prototype.c = 3;
  12141. *
  12142. * _.forInRight(new Foo, function(value, key) {
  12143. * console.log(key);
  12144. * });
  12145. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12146. */
  12147. function forInRight(object, iteratee) {
  12148. return object == null
  12149. ? object
  12150. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12151. }
  12152. /**
  12153. * Iterates over own enumerable string keyed properties of an object and
  12154. * invokes `iteratee` for each property. The iteratee is invoked with three
  12155. * arguments: (value, key, object). Iteratee functions may exit iteration
  12156. * early by explicitly returning `false`.
  12157. *
  12158. * @static
  12159. * @memberOf _
  12160. * @since 0.3.0
  12161. * @category Object
  12162. * @param {Object} object The object to iterate over.
  12163. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12164. * @returns {Object} Returns `object`.
  12165. * @see _.forOwnRight
  12166. * @example
  12167. *
  12168. * function Foo() {
  12169. * this.a = 1;
  12170. * this.b = 2;
  12171. * }
  12172. *
  12173. * Foo.prototype.c = 3;
  12174. *
  12175. * _.forOwn(new Foo, function(value, key) {
  12176. * console.log(key);
  12177. * });
  12178. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12179. */
  12180. function forOwn(object, iteratee) {
  12181. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12182. }
  12183. /**
  12184. * This method is like `_.forOwn` except that it iterates over properties of
  12185. * `object` in the opposite order.
  12186. *
  12187. * @static
  12188. * @memberOf _
  12189. * @since 2.0.0
  12190. * @category Object
  12191. * @param {Object} object The object to iterate over.
  12192. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12193. * @returns {Object} Returns `object`.
  12194. * @see _.forOwn
  12195. * @example
  12196. *
  12197. * function Foo() {
  12198. * this.a = 1;
  12199. * this.b = 2;
  12200. * }
  12201. *
  12202. * Foo.prototype.c = 3;
  12203. *
  12204. * _.forOwnRight(new Foo, function(value, key) {
  12205. * console.log(key);
  12206. * });
  12207. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12208. */
  12209. function forOwnRight(object, iteratee) {
  12210. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12211. }
  12212. /**
  12213. * Creates an array of function property names from own enumerable properties
  12214. * of `object`.
  12215. *
  12216. * @static
  12217. * @since 0.1.0
  12218. * @memberOf _
  12219. * @category Object
  12220. * @param {Object} object The object to inspect.
  12221. * @returns {Array} Returns the function names.
  12222. * @see _.functionsIn
  12223. * @example
  12224. *
  12225. * function Foo() {
  12226. * this.a = _.constant('a');
  12227. * this.b = _.constant('b');
  12228. * }
  12229. *
  12230. * Foo.prototype.c = _.constant('c');
  12231. *
  12232. * _.functions(new Foo);
  12233. * // => ['a', 'b']
  12234. */
  12235. function functions(object) {
  12236. return object == null ? [] : baseFunctions(object, keys(object));
  12237. }
  12238. /**
  12239. * Creates an array of function property names from own and inherited
  12240. * enumerable properties of `object`.
  12241. *
  12242. * @static
  12243. * @memberOf _
  12244. * @since 4.0.0
  12245. * @category Object
  12246. * @param {Object} object The object to inspect.
  12247. * @returns {Array} Returns the function names.
  12248. * @see _.functions
  12249. * @example
  12250. *
  12251. * function Foo() {
  12252. * this.a = _.constant('a');
  12253. * this.b = _.constant('b');
  12254. * }
  12255. *
  12256. * Foo.prototype.c = _.constant('c');
  12257. *
  12258. * _.functionsIn(new Foo);
  12259. * // => ['a', 'b', 'c']
  12260. */
  12261. function functionsIn(object) {
  12262. return object == null ? [] : baseFunctions(object, keysIn(object));
  12263. }
  12264. /**
  12265. * Gets the value at `path` of `object`. If the resolved value is
  12266. * `undefined`, the `defaultValue` is returned in its place.
  12267. *
  12268. * @static
  12269. * @memberOf _
  12270. * @since 3.7.0
  12271. * @category Object
  12272. * @param {Object} object The object to query.
  12273. * @param {Array|string} path The path of the property to get.
  12274. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12275. * @returns {*} Returns the resolved value.
  12276. * @example
  12277. *
  12278. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12279. *
  12280. * _.get(object, 'a[0].b.c');
  12281. * // => 3
  12282. *
  12283. * _.get(object, ['a', '0', 'b', 'c']);
  12284. * // => 3
  12285. *
  12286. * _.get(object, 'a.b.c', 'default');
  12287. * // => 'default'
  12288. */
  12289. function get(object, path, defaultValue) {
  12290. var result = object == null ? undefined : baseGet(object, path);
  12291. return result === undefined ? defaultValue : result;
  12292. }
  12293. /**
  12294. * Checks if `path` is a direct property of `object`.
  12295. *
  12296. * @static
  12297. * @since 0.1.0
  12298. * @memberOf _
  12299. * @category Object
  12300. * @param {Object} object The object to query.
  12301. * @param {Array|string} path The path to check.
  12302. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12303. * @example
  12304. *
  12305. * var object = { 'a': { 'b': 2 } };
  12306. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12307. *
  12308. * _.has(object, 'a');
  12309. * // => true
  12310. *
  12311. * _.has(object, 'a.b');
  12312. * // => true
  12313. *
  12314. * _.has(object, ['a', 'b']);
  12315. * // => true
  12316. *
  12317. * _.has(other, 'a');
  12318. * // => false
  12319. */
  12320. function has(object, path) {
  12321. return object != null && hasPath(object, path, baseHas);
  12322. }
  12323. /**
  12324. * Checks if `path` is a direct or inherited property of `object`.
  12325. *
  12326. * @static
  12327. * @memberOf _
  12328. * @since 4.0.0
  12329. * @category Object
  12330. * @param {Object} object The object to query.
  12331. * @param {Array|string} path The path to check.
  12332. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12333. * @example
  12334. *
  12335. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12336. *
  12337. * _.hasIn(object, 'a');
  12338. * // => true
  12339. *
  12340. * _.hasIn(object, 'a.b');
  12341. * // => true
  12342. *
  12343. * _.hasIn(object, ['a', 'b']);
  12344. * // => true
  12345. *
  12346. * _.hasIn(object, 'b');
  12347. * // => false
  12348. */
  12349. function hasIn(object, path) {
  12350. return object != null && hasPath(object, path, baseHasIn);
  12351. }
  12352. /**
  12353. * Creates an object composed of the inverted keys and values of `object`.
  12354. * If `object` contains duplicate values, subsequent values overwrite
  12355. * property assignments of previous values.
  12356. *
  12357. * @static
  12358. * @memberOf _
  12359. * @since 0.7.0
  12360. * @category Object
  12361. * @param {Object} object The object to invert.
  12362. * @returns {Object} Returns the new inverted object.
  12363. * @example
  12364. *
  12365. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12366. *
  12367. * _.invert(object);
  12368. * // => { '1': 'c', '2': 'b' }
  12369. */
  12370. var invert = createInverter(function(result, value, key) {
  12371. if (value != null &&
  12372. typeof value.toString != 'function') {
  12373. value = nativeObjectToString.call(value);
  12374. }
  12375. result[value] = key;
  12376. }, constant(identity));
  12377. /**
  12378. * This method is like `_.invert` except that the inverted object is generated
  12379. * from the results of running each element of `object` thru `iteratee`. The
  12380. * corresponding inverted value of each inverted key is an array of keys
  12381. * responsible for generating the inverted value. The iteratee is invoked
  12382. * with one argument: (value).
  12383. *
  12384. * @static
  12385. * @memberOf _
  12386. * @since 4.1.0
  12387. * @category Object
  12388. * @param {Object} object The object to invert.
  12389. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12390. * @returns {Object} Returns the new inverted object.
  12391. * @example
  12392. *
  12393. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12394. *
  12395. * _.invertBy(object);
  12396. * // => { '1': ['a', 'c'], '2': ['b'] }
  12397. *
  12398. * _.invertBy(object, function(value) {
  12399. * return 'group' + value;
  12400. * });
  12401. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12402. */
  12403. var invertBy = createInverter(function(result, value, key) {
  12404. if (value != null &&
  12405. typeof value.toString != 'function') {
  12406. value = nativeObjectToString.call(value);
  12407. }
  12408. if (hasOwnProperty.call(result, value)) {
  12409. result[value].push(key);
  12410. } else {
  12411. result[value] = [key];
  12412. }
  12413. }, getIteratee);
  12414. /**
  12415. * Invokes the method at `path` of `object`.
  12416. *
  12417. * @static
  12418. * @memberOf _
  12419. * @since 4.0.0
  12420. * @category Object
  12421. * @param {Object} object The object to query.
  12422. * @param {Array|string} path The path of the method to invoke.
  12423. * @param {...*} [args] The arguments to invoke the method with.
  12424. * @returns {*} Returns the result of the invoked method.
  12425. * @example
  12426. *
  12427. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12428. *
  12429. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12430. * // => [2, 3]
  12431. */
  12432. var invoke = baseRest(baseInvoke);
  12433. /**
  12434. * Creates an array of the own enumerable property names of `object`.
  12435. *
  12436. * **Note:** Non-object values are coerced to objects. See the
  12437. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12438. * for more details.
  12439. *
  12440. * @static
  12441. * @since 0.1.0
  12442. * @memberOf _
  12443. * @category Object
  12444. * @param {Object} object The object to query.
  12445. * @returns {Array} Returns the array of property names.
  12446. * @example
  12447. *
  12448. * function Foo() {
  12449. * this.a = 1;
  12450. * this.b = 2;
  12451. * }
  12452. *
  12453. * Foo.prototype.c = 3;
  12454. *
  12455. * _.keys(new Foo);
  12456. * // => ['a', 'b'] (iteration order is not guaranteed)
  12457. *
  12458. * _.keys('hi');
  12459. * // => ['0', '1']
  12460. */
  12461. function keys(object) {
  12462. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12463. }
  12464. /**
  12465. * Creates an array of the own and inherited enumerable property names of `object`.
  12466. *
  12467. * **Note:** Non-object values are coerced to objects.
  12468. *
  12469. * @static
  12470. * @memberOf _
  12471. * @since 3.0.0
  12472. * @category Object
  12473. * @param {Object} object The object to query.
  12474. * @returns {Array} Returns the array of property names.
  12475. * @example
  12476. *
  12477. * function Foo() {
  12478. * this.a = 1;
  12479. * this.b = 2;
  12480. * }
  12481. *
  12482. * Foo.prototype.c = 3;
  12483. *
  12484. * _.keysIn(new Foo);
  12485. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12486. */
  12487. function keysIn(object) {
  12488. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12489. }
  12490. /**
  12491. * The opposite of `_.mapValues`; this method creates an object with the
  12492. * same values as `object` and keys generated by running each own enumerable
  12493. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12494. * with three arguments: (value, key, object).
  12495. *
  12496. * @static
  12497. * @memberOf _
  12498. * @since 3.8.0
  12499. * @category Object
  12500. * @param {Object} object The object to iterate over.
  12501. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12502. * @returns {Object} Returns the new mapped object.
  12503. * @see _.mapValues
  12504. * @example
  12505. *
  12506. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12507. * return key + value;
  12508. * });
  12509. * // => { 'a1': 1, 'b2': 2 }
  12510. */
  12511. function mapKeys(object, iteratee) {
  12512. var result = {};
  12513. iteratee = getIteratee(iteratee, 3);
  12514. baseForOwn(object, function(value, key, object) {
  12515. baseAssignValue(result, iteratee(value, key, object), value);
  12516. });
  12517. return result;
  12518. }
  12519. /**
  12520. * Creates an object with the same keys as `object` and values generated
  12521. * by running each own enumerable string keyed property of `object` thru
  12522. * `iteratee`. The iteratee is invoked with three arguments:
  12523. * (value, key, object).
  12524. *
  12525. * @static
  12526. * @memberOf _
  12527. * @since 2.4.0
  12528. * @category Object
  12529. * @param {Object} object The object to iterate over.
  12530. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12531. * @returns {Object} Returns the new mapped object.
  12532. * @see _.mapKeys
  12533. * @example
  12534. *
  12535. * var users = {
  12536. * 'fred': { 'user': 'fred', 'age': 40 },
  12537. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12538. * };
  12539. *
  12540. * _.mapValues(users, function(o) { return o.age; });
  12541. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12542. *
  12543. * // The `_.property` iteratee shorthand.
  12544. * _.mapValues(users, 'age');
  12545. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12546. */
  12547. function mapValues(object, iteratee) {
  12548. var result = {};
  12549. iteratee = getIteratee(iteratee, 3);
  12550. baseForOwn(object, function(value, key, object) {
  12551. baseAssignValue(result, key, iteratee(value, key, object));
  12552. });
  12553. return result;
  12554. }
  12555. /**
  12556. * This method is like `_.assign` except that it recursively merges own and
  12557. * inherited enumerable string keyed properties of source objects into the
  12558. * destination object. Source properties that resolve to `undefined` are
  12559. * skipped if a destination value exists. Array and plain object properties
  12560. * are merged recursively. Other objects and value types are overridden by
  12561. * assignment. Source objects are applied from left to right. Subsequent
  12562. * sources overwrite property assignments of previous sources.
  12563. *
  12564. * **Note:** This method mutates `object`.
  12565. *
  12566. * @static
  12567. * @memberOf _
  12568. * @since 0.5.0
  12569. * @category Object
  12570. * @param {Object} object The destination object.
  12571. * @param {...Object} [sources] The source objects.
  12572. * @returns {Object} Returns `object`.
  12573. * @example
  12574. *
  12575. * var object = {
  12576. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12577. * };
  12578. *
  12579. * var other = {
  12580. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12581. * };
  12582. *
  12583. * _.merge(object, other);
  12584. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12585. */
  12586. var merge = createAssigner(function(object, source, srcIndex) {
  12587. baseMerge(object, source, srcIndex);
  12588. });
  12589. /**
  12590. * This method is like `_.merge` except that it accepts `customizer` which
  12591. * is invoked to produce the merged values of the destination and source
  12592. * properties. If `customizer` returns `undefined`, merging is handled by the
  12593. * method instead. The `customizer` is invoked with six arguments:
  12594. * (objValue, srcValue, key, object, source, stack).
  12595. *
  12596. * **Note:** This method mutates `object`.
  12597. *
  12598. * @static
  12599. * @memberOf _
  12600. * @since 4.0.0
  12601. * @category Object
  12602. * @param {Object} object The destination object.
  12603. * @param {...Object} sources The source objects.
  12604. * @param {Function} customizer The function to customize assigned values.
  12605. * @returns {Object} Returns `object`.
  12606. * @example
  12607. *
  12608. * function customizer(objValue, srcValue) {
  12609. * if (_.isArray(objValue)) {
  12610. * return objValue.concat(srcValue);
  12611. * }
  12612. * }
  12613. *
  12614. * var object = { 'a': [1], 'b': [2] };
  12615. * var other = { 'a': [3], 'b': [4] };
  12616. *
  12617. * _.mergeWith(object, other, customizer);
  12618. * // => { 'a': [1, 3], 'b': [2, 4] }
  12619. */
  12620. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12621. baseMerge(object, source, srcIndex, customizer);
  12622. });
  12623. /**
  12624. * The opposite of `_.pick`; this method creates an object composed of the
  12625. * own and inherited enumerable property paths of `object` that are not omitted.
  12626. *
  12627. * **Note:** This method is considerably slower than `_.pick`.
  12628. *
  12629. * @static
  12630. * @since 0.1.0
  12631. * @memberOf _
  12632. * @category Object
  12633. * @param {Object} object The source object.
  12634. * @param {...(string|string[])} [paths] The property paths to omit.
  12635. * @returns {Object} Returns the new object.
  12636. * @example
  12637. *
  12638. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12639. *
  12640. * _.omit(object, ['a', 'c']);
  12641. * // => { 'b': '2' }
  12642. */
  12643. var omit = flatRest(function(object, paths) {
  12644. var result = {};
  12645. if (object == null) {
  12646. return result;
  12647. }
  12648. var isDeep = false;
  12649. paths = arrayMap(paths, function(path) {
  12650. path = castPath(path, object);
  12651. isDeep || (isDeep = path.length > 1);
  12652. return path;
  12653. });
  12654. copyObject(object, getAllKeysIn(object), result);
  12655. if (isDeep) {
  12656. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12657. }
  12658. var length = paths.length;
  12659. while (length--) {
  12660. baseUnset(result, paths[length]);
  12661. }
  12662. return result;
  12663. });
  12664. /**
  12665. * The opposite of `_.pickBy`; this method creates an object composed of
  12666. * the own and inherited enumerable string keyed properties of `object` that
  12667. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12668. * arguments: (value, key).
  12669. *
  12670. * @static
  12671. * @memberOf _
  12672. * @since 4.0.0
  12673. * @category Object
  12674. * @param {Object} object The source object.
  12675. * @param {Function} [predicate=_.identity] The function invoked per property.
  12676. * @returns {Object} Returns the new object.
  12677. * @example
  12678. *
  12679. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12680. *
  12681. * _.omitBy(object, _.isNumber);
  12682. * // => { 'b': '2' }
  12683. */
  12684. function omitBy(object, predicate) {
  12685. return pickBy(object, negate(getIteratee(predicate)));
  12686. }
  12687. /**
  12688. * Creates an object composed of the picked `object` properties.
  12689. *
  12690. * @static
  12691. * @since 0.1.0
  12692. * @memberOf _
  12693. * @category Object
  12694. * @param {Object} object The source object.
  12695. * @param {...(string|string[])} [paths] The property paths to pick.
  12696. * @returns {Object} Returns the new object.
  12697. * @example
  12698. *
  12699. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12700. *
  12701. * _.pick(object, ['a', 'c']);
  12702. * // => { 'a': 1, 'c': 3 }
  12703. */
  12704. var pick = flatRest(function(object, paths) {
  12705. return object == null ? {} : basePick(object, paths);
  12706. });
  12707. /**
  12708. * Creates an object composed of the `object` properties `predicate` returns
  12709. * truthy for. The predicate is invoked with two arguments: (value, key).
  12710. *
  12711. * @static
  12712. * @memberOf _
  12713. * @since 4.0.0
  12714. * @category Object
  12715. * @param {Object} object The source object.
  12716. * @param {Function} [predicate=_.identity] The function invoked per property.
  12717. * @returns {Object} Returns the new object.
  12718. * @example
  12719. *
  12720. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12721. *
  12722. * _.pickBy(object, _.isNumber);
  12723. * // => { 'a': 1, 'c': 3 }
  12724. */
  12725. function pickBy(object, predicate) {
  12726. if (object == null) {
  12727. return {};
  12728. }
  12729. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12730. return [prop];
  12731. });
  12732. predicate = getIteratee(predicate);
  12733. return basePickBy(object, props, function(value, path) {
  12734. return predicate(value, path[0]);
  12735. });
  12736. }
  12737. /**
  12738. * This method is like `_.get` except that if the resolved value is a
  12739. * function it's invoked with the `this` binding of its parent object and
  12740. * its result is returned.
  12741. *
  12742. * @static
  12743. * @since 0.1.0
  12744. * @memberOf _
  12745. * @category Object
  12746. * @param {Object} object The object to query.
  12747. * @param {Array|string} path The path of the property to resolve.
  12748. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12749. * @returns {*} Returns the resolved value.
  12750. * @example
  12751. *
  12752. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12753. *
  12754. * _.result(object, 'a[0].b.c1');
  12755. * // => 3
  12756. *
  12757. * _.result(object, 'a[0].b.c2');
  12758. * // => 4
  12759. *
  12760. * _.result(object, 'a[0].b.c3', 'default');
  12761. * // => 'default'
  12762. *
  12763. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12764. * // => 'default'
  12765. */
  12766. function result(object, path, defaultValue) {
  12767. path = castPath(path, object);
  12768. var index = -1,
  12769. length = path.length;
  12770. // Ensure the loop is entered when path is empty.
  12771. if (!length) {
  12772. length = 1;
  12773. object = undefined;
  12774. }
  12775. while (++index < length) {
  12776. var value = object == null ? undefined : object[toKey(path[index])];
  12777. if (value === undefined) {
  12778. index = length;
  12779. value = defaultValue;
  12780. }
  12781. object = isFunction(value) ? value.call(object) : value;
  12782. }
  12783. return object;
  12784. }
  12785. /**
  12786. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12787. * it's created. Arrays are created for missing index properties while objects
  12788. * are created for all other missing properties. Use `_.setWith` to customize
  12789. * `path` creation.
  12790. *
  12791. * **Note:** This method mutates `object`.
  12792. *
  12793. * @static
  12794. * @memberOf _
  12795. * @since 3.7.0
  12796. * @category Object
  12797. * @param {Object} object The object to modify.
  12798. * @param {Array|string} path The path of the property to set.
  12799. * @param {*} value The value to set.
  12800. * @returns {Object} Returns `object`.
  12801. * @example
  12802. *
  12803. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12804. *
  12805. * _.set(object, 'a[0].b.c', 4);
  12806. * console.log(object.a[0].b.c);
  12807. * // => 4
  12808. *
  12809. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12810. * console.log(object.x[0].y.z);
  12811. * // => 5
  12812. */
  12813. function set(object, path, value) {
  12814. return object == null ? object : baseSet(object, path, value);
  12815. }
  12816. /**
  12817. * This method is like `_.set` except that it accepts `customizer` which is
  12818. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12819. * path creation is handled by the method instead. The `customizer` is invoked
  12820. * with three arguments: (nsValue, key, nsObject).
  12821. *
  12822. * **Note:** This method mutates `object`.
  12823. *
  12824. * @static
  12825. * @memberOf _
  12826. * @since 4.0.0
  12827. * @category Object
  12828. * @param {Object} object The object to modify.
  12829. * @param {Array|string} path The path of the property to set.
  12830. * @param {*} value The value to set.
  12831. * @param {Function} [customizer] The function to customize assigned values.
  12832. * @returns {Object} Returns `object`.
  12833. * @example
  12834. *
  12835. * var object = {};
  12836. *
  12837. * _.setWith(object, '[0][1]', 'a', Object);
  12838. * // => { '0': { '1': 'a' } }
  12839. */
  12840. function setWith(object, path, value, customizer) {
  12841. customizer = typeof customizer == 'function' ? customizer : undefined;
  12842. return object == null ? object : baseSet(object, path, value, customizer);
  12843. }
  12844. /**
  12845. * Creates an array of own enumerable string keyed-value pairs for `object`
  12846. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12847. * entries are returned.
  12848. *
  12849. * @static
  12850. * @memberOf _
  12851. * @since 4.0.0
  12852. * @alias entries
  12853. * @category Object
  12854. * @param {Object} object The object to query.
  12855. * @returns {Array} Returns the key-value pairs.
  12856. * @example
  12857. *
  12858. * function Foo() {
  12859. * this.a = 1;
  12860. * this.b = 2;
  12861. * }
  12862. *
  12863. * Foo.prototype.c = 3;
  12864. *
  12865. * _.toPairs(new Foo);
  12866. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12867. */
  12868. var toPairs = createToPairs(keys);
  12869. /**
  12870. * Creates an array of own and inherited enumerable string keyed-value pairs
  12871. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12872. * or set, its entries are returned.
  12873. *
  12874. * @static
  12875. * @memberOf _
  12876. * @since 4.0.0
  12877. * @alias entriesIn
  12878. * @category Object
  12879. * @param {Object} object The object to query.
  12880. * @returns {Array} Returns the key-value pairs.
  12881. * @example
  12882. *
  12883. * function Foo() {
  12884. * this.a = 1;
  12885. * this.b = 2;
  12886. * }
  12887. *
  12888. * Foo.prototype.c = 3;
  12889. *
  12890. * _.toPairsIn(new Foo);
  12891. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12892. */
  12893. var toPairsIn = createToPairs(keysIn);
  12894. /**
  12895. * An alternative to `_.reduce`; this method transforms `object` to a new
  12896. * `accumulator` object which is the result of running each of its own
  12897. * enumerable string keyed properties thru `iteratee`, with each invocation
  12898. * potentially mutating the `accumulator` object. If `accumulator` is not
  12899. * provided, a new object with the same `[[Prototype]]` will be used. The
  12900. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12901. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12902. *
  12903. * @static
  12904. * @memberOf _
  12905. * @since 1.3.0
  12906. * @category Object
  12907. * @param {Object} object The object to iterate over.
  12908. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12909. * @param {*} [accumulator] The custom accumulator value.
  12910. * @returns {*} Returns the accumulated value.
  12911. * @example
  12912. *
  12913. * _.transform([2, 3, 4], function(result, n) {
  12914. * result.push(n *= n);
  12915. * return n % 2 == 0;
  12916. * }, []);
  12917. * // => [4, 9]
  12918. *
  12919. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12920. * (result[value] || (result[value] = [])).push(key);
  12921. * }, {});
  12922. * // => { '1': ['a', 'c'], '2': ['b'] }
  12923. */
  12924. function transform(object, iteratee, accumulator) {
  12925. var isArr = isArray(object),
  12926. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12927. iteratee = getIteratee(iteratee, 4);
  12928. if (accumulator == null) {
  12929. var Ctor = object && object.constructor;
  12930. if (isArrLike) {
  12931. accumulator = isArr ? new Ctor : [];
  12932. }
  12933. else if (isObject(object)) {
  12934. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12935. }
  12936. else {
  12937. accumulator = {};
  12938. }
  12939. }
  12940. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12941. return iteratee(accumulator, value, index, object);
  12942. });
  12943. return accumulator;
  12944. }
  12945. /**
  12946. * Removes the property at `path` of `object`.
  12947. *
  12948. * **Note:** This method mutates `object`.
  12949. *
  12950. * @static
  12951. * @memberOf _
  12952. * @since 4.0.0
  12953. * @category Object
  12954. * @param {Object} object The object to modify.
  12955. * @param {Array|string} path The path of the property to unset.
  12956. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12957. * @example
  12958. *
  12959. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12960. * _.unset(object, 'a[0].b.c');
  12961. * // => true
  12962. *
  12963. * console.log(object);
  12964. * // => { 'a': [{ 'b': {} }] };
  12965. *
  12966. * _.unset(object, ['a', '0', 'b', 'c']);
  12967. * // => true
  12968. *
  12969. * console.log(object);
  12970. * // => { 'a': [{ 'b': {} }] };
  12971. */
  12972. function unset(object, path) {
  12973. return object == null ? true : baseUnset(object, path);
  12974. }
  12975. /**
  12976. * This method is like `_.set` except that accepts `updater` to produce the
  12977. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12978. * is invoked with one argument: (value).
  12979. *
  12980. * **Note:** This method mutates `object`.
  12981. *
  12982. * @static
  12983. * @memberOf _
  12984. * @since 4.6.0
  12985. * @category Object
  12986. * @param {Object} object The object to modify.
  12987. * @param {Array|string} path The path of the property to set.
  12988. * @param {Function} updater The function to produce the updated value.
  12989. * @returns {Object} Returns `object`.
  12990. * @example
  12991. *
  12992. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12993. *
  12994. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12995. * console.log(object.a[0].b.c);
  12996. * // => 9
  12997. *
  12998. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12999. * console.log(object.x[0].y.z);
  13000. * // => 0
  13001. */
  13002. function update(object, path, updater) {
  13003. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13004. }
  13005. /**
  13006. * This method is like `_.update` except that it accepts `customizer` which is
  13007. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13008. * path creation is handled by the method instead. The `customizer` is invoked
  13009. * with three arguments: (nsValue, key, nsObject).
  13010. *
  13011. * **Note:** This method mutates `object`.
  13012. *
  13013. * @static
  13014. * @memberOf _
  13015. * @since 4.6.0
  13016. * @category Object
  13017. * @param {Object} object The object to modify.
  13018. * @param {Array|string} path The path of the property to set.
  13019. * @param {Function} updater The function to produce the updated value.
  13020. * @param {Function} [customizer] The function to customize assigned values.
  13021. * @returns {Object} Returns `object`.
  13022. * @example
  13023. *
  13024. * var object = {};
  13025. *
  13026. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13027. * // => { '0': { '1': 'a' } }
  13028. */
  13029. function updateWith(object, path, updater, customizer) {
  13030. customizer = typeof customizer == 'function' ? customizer : undefined;
  13031. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13032. }
  13033. /**
  13034. * Creates an array of the own enumerable string keyed property values of `object`.
  13035. *
  13036. * **Note:** Non-object values are coerced to objects.
  13037. *
  13038. * @static
  13039. * @since 0.1.0
  13040. * @memberOf _
  13041. * @category Object
  13042. * @param {Object} object The object to query.
  13043. * @returns {Array} Returns the array of property values.
  13044. * @example
  13045. *
  13046. * function Foo() {
  13047. * this.a = 1;
  13048. * this.b = 2;
  13049. * }
  13050. *
  13051. * Foo.prototype.c = 3;
  13052. *
  13053. * _.values(new Foo);
  13054. * // => [1, 2] (iteration order is not guaranteed)
  13055. *
  13056. * _.values('hi');
  13057. * // => ['h', 'i']
  13058. */
  13059. function values(object) {
  13060. return object == null ? [] : baseValues(object, keys(object));
  13061. }
  13062. /**
  13063. * Creates an array of the own and inherited enumerable string keyed property
  13064. * values of `object`.
  13065. *
  13066. * **Note:** Non-object values are coerced to objects.
  13067. *
  13068. * @static
  13069. * @memberOf _
  13070. * @since 3.0.0
  13071. * @category Object
  13072. * @param {Object} object The object to query.
  13073. * @returns {Array} Returns the array of property values.
  13074. * @example
  13075. *
  13076. * function Foo() {
  13077. * this.a = 1;
  13078. * this.b = 2;
  13079. * }
  13080. *
  13081. * Foo.prototype.c = 3;
  13082. *
  13083. * _.valuesIn(new Foo);
  13084. * // => [1, 2, 3] (iteration order is not guaranteed)
  13085. */
  13086. function valuesIn(object) {
  13087. return object == null ? [] : baseValues(object, keysIn(object));
  13088. }
  13089. /*------------------------------------------------------------------------*/
  13090. /**
  13091. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13092. *
  13093. * @static
  13094. * @memberOf _
  13095. * @since 4.0.0
  13096. * @category Number
  13097. * @param {number} number The number to clamp.
  13098. * @param {number} [lower] The lower bound.
  13099. * @param {number} upper The upper bound.
  13100. * @returns {number} Returns the clamped number.
  13101. * @example
  13102. *
  13103. * _.clamp(-10, -5, 5);
  13104. * // => -5
  13105. *
  13106. * _.clamp(10, -5, 5);
  13107. * // => 5
  13108. */
  13109. function clamp(number, lower, upper) {
  13110. if (upper === undefined) {
  13111. upper = lower;
  13112. lower = undefined;
  13113. }
  13114. if (upper !== undefined) {
  13115. upper = toNumber(upper);
  13116. upper = upper === upper ? upper : 0;
  13117. }
  13118. if (lower !== undefined) {
  13119. lower = toNumber(lower);
  13120. lower = lower === lower ? lower : 0;
  13121. }
  13122. return baseClamp(toNumber(number), lower, upper);
  13123. }
  13124. /**
  13125. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13126. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13127. * If `start` is greater than `end` the params are swapped to support
  13128. * negative ranges.
  13129. *
  13130. * @static
  13131. * @memberOf _
  13132. * @since 3.3.0
  13133. * @category Number
  13134. * @param {number} number The number to check.
  13135. * @param {number} [start=0] The start of the range.
  13136. * @param {number} end The end of the range.
  13137. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13138. * @see _.range, _.rangeRight
  13139. * @example
  13140. *
  13141. * _.inRange(3, 2, 4);
  13142. * // => true
  13143. *
  13144. * _.inRange(4, 8);
  13145. * // => true
  13146. *
  13147. * _.inRange(4, 2);
  13148. * // => false
  13149. *
  13150. * _.inRange(2, 2);
  13151. * // => false
  13152. *
  13153. * _.inRange(1.2, 2);
  13154. * // => true
  13155. *
  13156. * _.inRange(5.2, 4);
  13157. * // => false
  13158. *
  13159. * _.inRange(-3, -2, -6);
  13160. * // => true
  13161. */
  13162. function inRange(number, start, end) {
  13163. start = toFinite(start);
  13164. if (end === undefined) {
  13165. end = start;
  13166. start = 0;
  13167. } else {
  13168. end = toFinite(end);
  13169. }
  13170. number = toNumber(number);
  13171. return baseInRange(number, start, end);
  13172. }
  13173. /**
  13174. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13175. * If only one argument is provided a number between `0` and the given number
  13176. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13177. * floats, a floating-point number is returned instead of an integer.
  13178. *
  13179. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13180. * floating-point values which can produce unexpected results.
  13181. *
  13182. * @static
  13183. * @memberOf _
  13184. * @since 0.7.0
  13185. * @category Number
  13186. * @param {number} [lower=0] The lower bound.
  13187. * @param {number} [upper=1] The upper bound.
  13188. * @param {boolean} [floating] Specify returning a floating-point number.
  13189. * @returns {number} Returns the random number.
  13190. * @example
  13191. *
  13192. * _.random(0, 5);
  13193. * // => an integer between 0 and 5
  13194. *
  13195. * _.random(5);
  13196. * // => also an integer between 0 and 5
  13197. *
  13198. * _.random(5, true);
  13199. * // => a floating-point number between 0 and 5
  13200. *
  13201. * _.random(1.2, 5.2);
  13202. * // => a floating-point number between 1.2 and 5.2
  13203. */
  13204. function random(lower, upper, floating) {
  13205. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13206. upper = floating = undefined;
  13207. }
  13208. if (floating === undefined) {
  13209. if (typeof upper == 'boolean') {
  13210. floating = upper;
  13211. upper = undefined;
  13212. }
  13213. else if (typeof lower == 'boolean') {
  13214. floating = lower;
  13215. lower = undefined;
  13216. }
  13217. }
  13218. if (lower === undefined && upper === undefined) {
  13219. lower = 0;
  13220. upper = 1;
  13221. }
  13222. else {
  13223. lower = toFinite(lower);
  13224. if (upper === undefined) {
  13225. upper = lower;
  13226. lower = 0;
  13227. } else {
  13228. upper = toFinite(upper);
  13229. }
  13230. }
  13231. if (lower > upper) {
  13232. var temp = lower;
  13233. lower = upper;
  13234. upper = temp;
  13235. }
  13236. if (floating || lower % 1 || upper % 1) {
  13237. var rand = nativeRandom();
  13238. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13239. }
  13240. return baseRandom(lower, upper);
  13241. }
  13242. /*------------------------------------------------------------------------*/
  13243. /**
  13244. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13245. *
  13246. * @static
  13247. * @memberOf _
  13248. * @since 3.0.0
  13249. * @category String
  13250. * @param {string} [string=''] The string to convert.
  13251. * @returns {string} Returns the camel cased string.
  13252. * @example
  13253. *
  13254. * _.camelCase('Foo Bar');
  13255. * // => 'fooBar'
  13256. *
  13257. * _.camelCase('--foo-bar--');
  13258. * // => 'fooBar'
  13259. *
  13260. * _.camelCase('__FOO_BAR__');
  13261. * // => 'fooBar'
  13262. */
  13263. var camelCase = createCompounder(function(result, word, index) {
  13264. word = word.toLowerCase();
  13265. return result + (index ? capitalize(word) : word);
  13266. });
  13267. /**
  13268. * Converts the first character of `string` to upper case and the remaining
  13269. * to lower case.
  13270. *
  13271. * @static
  13272. * @memberOf _
  13273. * @since 3.0.0
  13274. * @category String
  13275. * @param {string} [string=''] The string to capitalize.
  13276. * @returns {string} Returns the capitalized string.
  13277. * @example
  13278. *
  13279. * _.capitalize('FRED');
  13280. * // => 'Fred'
  13281. */
  13282. function capitalize(string) {
  13283. return upperFirst(toString(string).toLowerCase());
  13284. }
  13285. /**
  13286. * Deburrs `string` by converting
  13287. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13288. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13289. * letters to basic Latin letters and removing
  13290. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13291. *
  13292. * @static
  13293. * @memberOf _
  13294. * @since 3.0.0
  13295. * @category String
  13296. * @param {string} [string=''] The string to deburr.
  13297. * @returns {string} Returns the deburred string.
  13298. * @example
  13299. *
  13300. * _.deburr('déjà vu');
  13301. * // => 'deja vu'
  13302. */
  13303. function deburr(string) {
  13304. string = toString(string);
  13305. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13306. }
  13307. /**
  13308. * Checks if `string` ends with the given target string.
  13309. *
  13310. * @static
  13311. * @memberOf _
  13312. * @since 3.0.0
  13313. * @category String
  13314. * @param {string} [string=''] The string to inspect.
  13315. * @param {string} [target] The string to search for.
  13316. * @param {number} [position=string.length] The position to search up to.
  13317. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13318. * else `false`.
  13319. * @example
  13320. *
  13321. * _.endsWith('abc', 'c');
  13322. * // => true
  13323. *
  13324. * _.endsWith('abc', 'b');
  13325. * // => false
  13326. *
  13327. * _.endsWith('abc', 'b', 2);
  13328. * // => true
  13329. */
  13330. function endsWith(string, target, position) {
  13331. string = toString(string);
  13332. target = baseToString(target);
  13333. var length = string.length;
  13334. position = position === undefined
  13335. ? length
  13336. : baseClamp(toInteger(position), 0, length);
  13337. var end = position;
  13338. position -= target.length;
  13339. return position >= 0 && string.slice(position, end) == target;
  13340. }
  13341. /**
  13342. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13343. * corresponding HTML entities.
  13344. *
  13345. * **Note:** No other characters are escaped. To escape additional
  13346. * characters use a third-party library like [_he_](https://mths.be/he).
  13347. *
  13348. * Though the ">" character is escaped for symmetry, characters like
  13349. * ">" and "/" don't need escaping in HTML and have no special meaning
  13350. * unless they're part of a tag or unquoted attribute value. See
  13351. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13352. * (under "semi-related fun fact") for more details.
  13353. *
  13354. * When working with HTML you should always
  13355. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13356. * XSS vectors.
  13357. *
  13358. * @static
  13359. * @since 0.1.0
  13360. * @memberOf _
  13361. * @category String
  13362. * @param {string} [string=''] The string to escape.
  13363. * @returns {string} Returns the escaped string.
  13364. * @example
  13365. *
  13366. * _.escape('fred, barney, & pebbles');
  13367. * // => 'fred, barney, &amp; pebbles'
  13368. */
  13369. function escape(string) {
  13370. string = toString(string);
  13371. return (string && reHasUnescapedHtml.test(string))
  13372. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13373. : string;
  13374. }
  13375. /**
  13376. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13377. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13378. *
  13379. * @static
  13380. * @memberOf _
  13381. * @since 3.0.0
  13382. * @category String
  13383. * @param {string} [string=''] The string to escape.
  13384. * @returns {string} Returns the escaped string.
  13385. * @example
  13386. *
  13387. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13388. * // => '\[lodash\]\(https://lodash\.com/\)'
  13389. */
  13390. function escapeRegExp(string) {
  13391. string = toString(string);
  13392. return (string && reHasRegExpChar.test(string))
  13393. ? string.replace(reRegExpChar, '\\$&')
  13394. : string;
  13395. }
  13396. /**
  13397. * Converts `string` to
  13398. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13399. *
  13400. * @static
  13401. * @memberOf _
  13402. * @since 3.0.0
  13403. * @category String
  13404. * @param {string} [string=''] The string to convert.
  13405. * @returns {string} Returns the kebab cased string.
  13406. * @example
  13407. *
  13408. * _.kebabCase('Foo Bar');
  13409. * // => 'foo-bar'
  13410. *
  13411. * _.kebabCase('fooBar');
  13412. * // => 'foo-bar'
  13413. *
  13414. * _.kebabCase('__FOO_BAR__');
  13415. * // => 'foo-bar'
  13416. */
  13417. var kebabCase = createCompounder(function(result, word, index) {
  13418. return result + (index ? '-' : '') + word.toLowerCase();
  13419. });
  13420. /**
  13421. * Converts `string`, as space separated words, to lower case.
  13422. *
  13423. * @static
  13424. * @memberOf _
  13425. * @since 4.0.0
  13426. * @category String
  13427. * @param {string} [string=''] The string to convert.
  13428. * @returns {string} Returns the lower cased string.
  13429. * @example
  13430. *
  13431. * _.lowerCase('--Foo-Bar--');
  13432. * // => 'foo bar'
  13433. *
  13434. * _.lowerCase('fooBar');
  13435. * // => 'foo bar'
  13436. *
  13437. * _.lowerCase('__FOO_BAR__');
  13438. * // => 'foo bar'
  13439. */
  13440. var lowerCase = createCompounder(function(result, word, index) {
  13441. return result + (index ? ' ' : '') + word.toLowerCase();
  13442. });
  13443. /**
  13444. * Converts the first character of `string` to lower case.
  13445. *
  13446. * @static
  13447. * @memberOf _
  13448. * @since 4.0.0
  13449. * @category String
  13450. * @param {string} [string=''] The string to convert.
  13451. * @returns {string} Returns the converted string.
  13452. * @example
  13453. *
  13454. * _.lowerFirst('Fred');
  13455. * // => 'fred'
  13456. *
  13457. * _.lowerFirst('FRED');
  13458. * // => 'fRED'
  13459. */
  13460. var lowerFirst = createCaseFirst('toLowerCase');
  13461. /**
  13462. * Pads `string` on the left and right sides if it's shorter than `length`.
  13463. * Padding characters are truncated if they can't be evenly divided by `length`.
  13464. *
  13465. * @static
  13466. * @memberOf _
  13467. * @since 3.0.0
  13468. * @category String
  13469. * @param {string} [string=''] The string to pad.
  13470. * @param {number} [length=0] The padding length.
  13471. * @param {string} [chars=' '] The string used as padding.
  13472. * @returns {string} Returns the padded string.
  13473. * @example
  13474. *
  13475. * _.pad('abc', 8);
  13476. * // => ' abc '
  13477. *
  13478. * _.pad('abc', 8, '_-');
  13479. * // => '_-abc_-_'
  13480. *
  13481. * _.pad('abc', 3);
  13482. * // => 'abc'
  13483. */
  13484. function pad(string, length, chars) {
  13485. string = toString(string);
  13486. length = toInteger(length);
  13487. var strLength = length ? stringSize(string) : 0;
  13488. if (!length || strLength >= length) {
  13489. return string;
  13490. }
  13491. var mid = (length - strLength) / 2;
  13492. return (
  13493. createPadding(nativeFloor(mid), chars) +
  13494. string +
  13495. createPadding(nativeCeil(mid), chars)
  13496. );
  13497. }
  13498. /**
  13499. * Pads `string` on the right side if it's shorter than `length`. Padding
  13500. * characters are truncated if they exceed `length`.
  13501. *
  13502. * @static
  13503. * @memberOf _
  13504. * @since 4.0.0
  13505. * @category String
  13506. * @param {string} [string=''] The string to pad.
  13507. * @param {number} [length=0] The padding length.
  13508. * @param {string} [chars=' '] The string used as padding.
  13509. * @returns {string} Returns the padded string.
  13510. * @example
  13511. *
  13512. * _.padEnd('abc', 6);
  13513. * // => 'abc '
  13514. *
  13515. * _.padEnd('abc', 6, '_-');
  13516. * // => 'abc_-_'
  13517. *
  13518. * _.padEnd('abc', 3);
  13519. * // => 'abc'
  13520. */
  13521. function padEnd(string, length, chars) {
  13522. string = toString(string);
  13523. length = toInteger(length);
  13524. var strLength = length ? stringSize(string) : 0;
  13525. return (length && strLength < length)
  13526. ? (string + createPadding(length - strLength, chars))
  13527. : string;
  13528. }
  13529. /**
  13530. * Pads `string` on the left side if it's shorter than `length`. Padding
  13531. * characters are truncated if they exceed `length`.
  13532. *
  13533. * @static
  13534. * @memberOf _
  13535. * @since 4.0.0
  13536. * @category String
  13537. * @param {string} [string=''] The string to pad.
  13538. * @param {number} [length=0] The padding length.
  13539. * @param {string} [chars=' '] The string used as padding.
  13540. * @returns {string} Returns the padded string.
  13541. * @example
  13542. *
  13543. * _.padStart('abc', 6);
  13544. * // => ' abc'
  13545. *
  13546. * _.padStart('abc', 6, '_-');
  13547. * // => '_-_abc'
  13548. *
  13549. * _.padStart('abc', 3);
  13550. * // => 'abc'
  13551. */
  13552. function padStart(string, length, chars) {
  13553. string = toString(string);
  13554. length = toInteger(length);
  13555. var strLength = length ? stringSize(string) : 0;
  13556. return (length && strLength < length)
  13557. ? (createPadding(length - strLength, chars) + string)
  13558. : string;
  13559. }
  13560. /**
  13561. * Converts `string` to an integer of the specified radix. If `radix` is
  13562. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13563. * hexadecimal, in which case a `radix` of `16` is used.
  13564. *
  13565. * **Note:** This method aligns with the
  13566. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13567. *
  13568. * @static
  13569. * @memberOf _
  13570. * @since 1.1.0
  13571. * @category String
  13572. * @param {string} string The string to convert.
  13573. * @param {number} [radix=10] The radix to interpret `value` by.
  13574. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13575. * @returns {number} Returns the converted integer.
  13576. * @example
  13577. *
  13578. * _.parseInt('08');
  13579. * // => 8
  13580. *
  13581. * _.map(['6', '08', '10'], _.parseInt);
  13582. * // => [6, 8, 10]
  13583. */
  13584. function parseInt(string, radix, guard) {
  13585. if (guard || radix == null) {
  13586. radix = 0;
  13587. } else if (radix) {
  13588. radix = +radix;
  13589. }
  13590. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13591. }
  13592. /**
  13593. * Repeats the given string `n` times.
  13594. *
  13595. * @static
  13596. * @memberOf _
  13597. * @since 3.0.0
  13598. * @category String
  13599. * @param {string} [string=''] The string to repeat.
  13600. * @param {number} [n=1] The number of times to repeat the string.
  13601. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13602. * @returns {string} Returns the repeated string.
  13603. * @example
  13604. *
  13605. * _.repeat('*', 3);
  13606. * // => '***'
  13607. *
  13608. * _.repeat('abc', 2);
  13609. * // => 'abcabc'
  13610. *
  13611. * _.repeat('abc', 0);
  13612. * // => ''
  13613. */
  13614. function repeat(string, n, guard) {
  13615. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13616. n = 1;
  13617. } else {
  13618. n = toInteger(n);
  13619. }
  13620. return baseRepeat(toString(string), n);
  13621. }
  13622. /**
  13623. * Replaces matches for `pattern` in `string` with `replacement`.
  13624. *
  13625. * **Note:** This method is based on
  13626. * [`String#replace`](https://mdn.io/String/replace).
  13627. *
  13628. * @static
  13629. * @memberOf _
  13630. * @since 4.0.0
  13631. * @category String
  13632. * @param {string} [string=''] The string to modify.
  13633. * @param {RegExp|string} pattern The pattern to replace.
  13634. * @param {Function|string} replacement The match replacement.
  13635. * @returns {string} Returns the modified string.
  13636. * @example
  13637. *
  13638. * _.replace('Hi Fred', 'Fred', 'Barney');
  13639. * // => 'Hi Barney'
  13640. */
  13641. function replace() {
  13642. var args = arguments,
  13643. string = toString(args[0]);
  13644. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13645. }
  13646. /**
  13647. * Converts `string` to
  13648. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13649. *
  13650. * @static
  13651. * @memberOf _
  13652. * @since 3.0.0
  13653. * @category String
  13654. * @param {string} [string=''] The string to convert.
  13655. * @returns {string} Returns the snake cased string.
  13656. * @example
  13657. *
  13658. * _.snakeCase('Foo Bar');
  13659. * // => 'foo_bar'
  13660. *
  13661. * _.snakeCase('fooBar');
  13662. * // => 'foo_bar'
  13663. *
  13664. * _.snakeCase('--FOO-BAR--');
  13665. * // => 'foo_bar'
  13666. */
  13667. var snakeCase = createCompounder(function(result, word, index) {
  13668. return result + (index ? '_' : '') + word.toLowerCase();
  13669. });
  13670. /**
  13671. * Splits `string` by `separator`.
  13672. *
  13673. * **Note:** This method is based on
  13674. * [`String#split`](https://mdn.io/String/split).
  13675. *
  13676. * @static
  13677. * @memberOf _
  13678. * @since 4.0.0
  13679. * @category String
  13680. * @param {string} [string=''] The string to split.
  13681. * @param {RegExp|string} separator The separator pattern to split by.
  13682. * @param {number} [limit] The length to truncate results to.
  13683. * @returns {Array} Returns the string segments.
  13684. * @example
  13685. *
  13686. * _.split('a-b-c', '-', 2);
  13687. * // => ['a', 'b']
  13688. */
  13689. function split(string, separator, limit) {
  13690. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13691. separator = limit = undefined;
  13692. }
  13693. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13694. if (!limit) {
  13695. return [];
  13696. }
  13697. string = toString(string);
  13698. if (string && (
  13699. typeof separator == 'string' ||
  13700. (separator != null && !isRegExp(separator))
  13701. )) {
  13702. separator = baseToString(separator);
  13703. if (!separator && hasUnicode(string)) {
  13704. return castSlice(stringToArray(string), 0, limit);
  13705. }
  13706. }
  13707. return string.split(separator, limit);
  13708. }
  13709. /**
  13710. * Converts `string` to
  13711. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13712. *
  13713. * @static
  13714. * @memberOf _
  13715. * @since 3.1.0
  13716. * @category String
  13717. * @param {string} [string=''] The string to convert.
  13718. * @returns {string} Returns the start cased string.
  13719. * @example
  13720. *
  13721. * _.startCase('--foo-bar--');
  13722. * // => 'Foo Bar'
  13723. *
  13724. * _.startCase('fooBar');
  13725. * // => 'Foo Bar'
  13726. *
  13727. * _.startCase('__FOO_BAR__');
  13728. * // => 'FOO BAR'
  13729. */
  13730. var startCase = createCompounder(function(result, word, index) {
  13731. return result + (index ? ' ' : '') + upperFirst(word);
  13732. });
  13733. /**
  13734. * Checks if `string` starts with the given target string.
  13735. *
  13736. * @static
  13737. * @memberOf _
  13738. * @since 3.0.0
  13739. * @category String
  13740. * @param {string} [string=''] The string to inspect.
  13741. * @param {string} [target] The string to search for.
  13742. * @param {number} [position=0] The position to search from.
  13743. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13744. * else `false`.
  13745. * @example
  13746. *
  13747. * _.startsWith('abc', 'a');
  13748. * // => true
  13749. *
  13750. * _.startsWith('abc', 'b');
  13751. * // => false
  13752. *
  13753. * _.startsWith('abc', 'b', 1);
  13754. * // => true
  13755. */
  13756. function startsWith(string, target, position) {
  13757. string = toString(string);
  13758. position = position == null
  13759. ? 0
  13760. : baseClamp(toInteger(position), 0, string.length);
  13761. target = baseToString(target);
  13762. return string.slice(position, position + target.length) == target;
  13763. }
  13764. /**
  13765. * Creates a compiled template function that can interpolate data properties
  13766. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13767. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13768. * properties may be accessed as free variables in the template. If a setting
  13769. * object is given, it takes precedence over `_.templateSettings` values.
  13770. *
  13771. * **Note:** In the development build `_.template` utilizes
  13772. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13773. * for easier debugging.
  13774. *
  13775. * For more information on precompiling templates see
  13776. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13777. *
  13778. * For more information on Chrome extension sandboxes see
  13779. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13780. *
  13781. * @static
  13782. * @since 0.1.0
  13783. * @memberOf _
  13784. * @category String
  13785. * @param {string} [string=''] The template string.
  13786. * @param {Object} [options={}] The options object.
  13787. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13788. * The HTML "escape" delimiter.
  13789. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13790. * The "evaluate" delimiter.
  13791. * @param {Object} [options.imports=_.templateSettings.imports]
  13792. * An object to import into the template as free variables.
  13793. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13794. * The "interpolate" delimiter.
  13795. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13796. * The sourceURL of the compiled template.
  13797. * @param {string} [options.variable='obj']
  13798. * The data object variable name.
  13799. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13800. * @returns {Function} Returns the compiled template function.
  13801. * @example
  13802. *
  13803. * // Use the "interpolate" delimiter to create a compiled template.
  13804. * var compiled = _.template('hello <%= user %>!');
  13805. * compiled({ 'user': 'fred' });
  13806. * // => 'hello fred!'
  13807. *
  13808. * // Use the HTML "escape" delimiter to escape data property values.
  13809. * var compiled = _.template('<b><%- value %></b>');
  13810. * compiled({ 'value': '<script>' });
  13811. * // => '<b>&lt;script&gt;</b>'
  13812. *
  13813. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13814. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13815. * compiled({ 'users': ['fred', 'barney'] });
  13816. * // => '<li>fred</li><li>barney</li>'
  13817. *
  13818. * // Use the internal `print` function in "evaluate" delimiters.
  13819. * var compiled = _.template('<% print("hello " + user); %>!');
  13820. * compiled({ 'user': 'barney' });
  13821. * // => 'hello barney!'
  13822. *
  13823. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13824. * // Disable support by replacing the "interpolate" delimiter.
  13825. * var compiled = _.template('hello ${ user }!');
  13826. * compiled({ 'user': 'pebbles' });
  13827. * // => 'hello pebbles!'
  13828. *
  13829. * // Use backslashes to treat delimiters as plain text.
  13830. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13831. * compiled({ 'value': 'ignored' });
  13832. * // => '<%- value %>'
  13833. *
  13834. * // Use the `imports` option to import `jQuery` as `jq`.
  13835. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13836. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13837. * compiled({ 'users': ['fred', 'barney'] });
  13838. * // => '<li>fred</li><li>barney</li>'
  13839. *
  13840. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13841. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13842. * compiled(data);
  13843. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13844. *
  13845. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13846. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13847. * compiled.source;
  13848. * // => function(data) {
  13849. * // var __t, __p = '';
  13850. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13851. * // return __p;
  13852. * // }
  13853. *
  13854. * // Use custom template delimiters.
  13855. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13856. * var compiled = _.template('hello {{ user }}!');
  13857. * compiled({ 'user': 'mustache' });
  13858. * // => 'hello mustache!'
  13859. *
  13860. * // Use the `source` property to inline compiled templates for meaningful
  13861. * // line numbers in error messages and stack traces.
  13862. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13863. * var JST = {\
  13864. * "main": ' + _.template(mainText).source + '\
  13865. * };\
  13866. * ');
  13867. */
  13868. function template(string, options, guard) {
  13869. // Based on John Resig's `tmpl` implementation
  13870. // (http://ejohn.org/blog/javascript-micro-templating/)
  13871. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13872. var settings = lodash.templateSettings;
  13873. if (guard && isIterateeCall(string, options, guard)) {
  13874. options = undefined;
  13875. }
  13876. string = toString(string);
  13877. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13878. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13879. importsKeys = keys(imports),
  13880. importsValues = baseValues(imports, importsKeys);
  13881. var isEscaping,
  13882. isEvaluating,
  13883. index = 0,
  13884. interpolate = options.interpolate || reNoMatch,
  13885. source = "__p += '";
  13886. // Compile the regexp to match each delimiter.
  13887. var reDelimiters = RegExp(
  13888. (options.escape || reNoMatch).source + '|' +
  13889. interpolate.source + '|' +
  13890. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13891. (options.evaluate || reNoMatch).source + '|$'
  13892. , 'g');
  13893. // Use a sourceURL for easier debugging.
  13894. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13895. // with lookup (in case of e.g. prototype pollution), and strip newlines if any.
  13896. // A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
  13897. var sourceURL = '//# sourceURL=' +
  13898. (hasOwnProperty.call(options, 'sourceURL')
  13899. ? (options.sourceURL + '').replace(/[\r\n]/g, ' ')
  13900. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13901. ) + '\n';
  13902. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13903. interpolateValue || (interpolateValue = esTemplateValue);
  13904. // Escape characters that can't be included in string literals.
  13905. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13906. // Replace delimiters with snippets.
  13907. if (escapeValue) {
  13908. isEscaping = true;
  13909. source += "' +\n__e(" + escapeValue + ") +\n'";
  13910. }
  13911. if (evaluateValue) {
  13912. isEvaluating = true;
  13913. source += "';\n" + evaluateValue + ";\n__p += '";
  13914. }
  13915. if (interpolateValue) {
  13916. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13917. }
  13918. index = offset + match.length;
  13919. // The JS engine embedded in Adobe products needs `match` returned in
  13920. // order to produce the correct `offset` value.
  13921. return match;
  13922. });
  13923. source += "';\n";
  13924. // If `variable` is not specified wrap a with-statement around the generated
  13925. // code to add the data object to the top of the scope chain.
  13926. // Like with sourceURL, we take care to not check the option's prototype,
  13927. // as this configuration is a code injection vector.
  13928. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13929. if (!variable) {
  13930. source = 'with (obj) {\n' + source + '\n}\n';
  13931. }
  13932. // Cleanup code by stripping empty strings.
  13933. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13934. .replace(reEmptyStringMiddle, '$1')
  13935. .replace(reEmptyStringTrailing, '$1;');
  13936. // Frame code as the function body.
  13937. source = 'function(' + (variable || 'obj') + ') {\n' +
  13938. (variable
  13939. ? ''
  13940. : 'obj || (obj = {});\n'
  13941. ) +
  13942. "var __t, __p = ''" +
  13943. (isEscaping
  13944. ? ', __e = _.escape'
  13945. : ''
  13946. ) +
  13947. (isEvaluating
  13948. ? ', __j = Array.prototype.join;\n' +
  13949. "function print() { __p += __j.call(arguments, '') }\n"
  13950. : ';\n'
  13951. ) +
  13952. source +
  13953. 'return __p\n}';
  13954. var result = attempt(function() {
  13955. return Function(importsKeys, sourceURL + 'return ' + source)
  13956. .apply(undefined, importsValues);
  13957. });
  13958. // Provide the compiled function's source by its `toString` method or
  13959. // the `source` property as a convenience for inlining compiled templates.
  13960. result.source = source;
  13961. if (isError(result)) {
  13962. throw result;
  13963. }
  13964. return result;
  13965. }
  13966. /**
  13967. * Converts `string`, as a whole, to lower case just like
  13968. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13969. *
  13970. * @static
  13971. * @memberOf _
  13972. * @since 4.0.0
  13973. * @category String
  13974. * @param {string} [string=''] The string to convert.
  13975. * @returns {string} Returns the lower cased string.
  13976. * @example
  13977. *
  13978. * _.toLower('--Foo-Bar--');
  13979. * // => '--foo-bar--'
  13980. *
  13981. * _.toLower('fooBar');
  13982. * // => 'foobar'
  13983. *
  13984. * _.toLower('__FOO_BAR__');
  13985. * // => '__foo_bar__'
  13986. */
  13987. function toLower(value) {
  13988. return toString(value).toLowerCase();
  13989. }
  13990. /**
  13991. * Converts `string`, as a whole, to upper case just like
  13992. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13993. *
  13994. * @static
  13995. * @memberOf _
  13996. * @since 4.0.0
  13997. * @category String
  13998. * @param {string} [string=''] The string to convert.
  13999. * @returns {string} Returns the upper cased string.
  14000. * @example
  14001. *
  14002. * _.toUpper('--foo-bar--');
  14003. * // => '--FOO-BAR--'
  14004. *
  14005. * _.toUpper('fooBar');
  14006. * // => 'FOOBAR'
  14007. *
  14008. * _.toUpper('__foo_bar__');
  14009. * // => '__FOO_BAR__'
  14010. */
  14011. function toUpper(value) {
  14012. return toString(value).toUpperCase();
  14013. }
  14014. /**
  14015. * Removes leading and trailing whitespace or specified characters from `string`.
  14016. *
  14017. * @static
  14018. * @memberOf _
  14019. * @since 3.0.0
  14020. * @category String
  14021. * @param {string} [string=''] The string to trim.
  14022. * @param {string} [chars=whitespace] The characters to trim.
  14023. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14024. * @returns {string} Returns the trimmed string.
  14025. * @example
  14026. *
  14027. * _.trim(' abc ');
  14028. * // => 'abc'
  14029. *
  14030. * _.trim('-_-abc-_-', '_-');
  14031. * // => 'abc'
  14032. *
  14033. * _.map([' foo ', ' bar '], _.trim);
  14034. * // => ['foo', 'bar']
  14035. */
  14036. function trim(string, chars, guard) {
  14037. string = toString(string);
  14038. if (string && (guard || chars === undefined)) {
  14039. return string.replace(reTrim, '');
  14040. }
  14041. if (!string || !(chars = baseToString(chars))) {
  14042. return string;
  14043. }
  14044. var strSymbols = stringToArray(string),
  14045. chrSymbols = stringToArray(chars),
  14046. start = charsStartIndex(strSymbols, chrSymbols),
  14047. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14048. return castSlice(strSymbols, start, end).join('');
  14049. }
  14050. /**
  14051. * Removes trailing whitespace or specified characters from `string`.
  14052. *
  14053. * @static
  14054. * @memberOf _
  14055. * @since 4.0.0
  14056. * @category String
  14057. * @param {string} [string=''] The string to trim.
  14058. * @param {string} [chars=whitespace] The characters to trim.
  14059. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14060. * @returns {string} Returns the trimmed string.
  14061. * @example
  14062. *
  14063. * _.trimEnd(' abc ');
  14064. * // => ' abc'
  14065. *
  14066. * _.trimEnd('-_-abc-_-', '_-');
  14067. * // => '-_-abc'
  14068. */
  14069. function trimEnd(string, chars, guard) {
  14070. string = toString(string);
  14071. if (string && (guard || chars === undefined)) {
  14072. return string.replace(reTrimEnd, '');
  14073. }
  14074. if (!string || !(chars = baseToString(chars))) {
  14075. return string;
  14076. }
  14077. var strSymbols = stringToArray(string),
  14078. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14079. return castSlice(strSymbols, 0, end).join('');
  14080. }
  14081. /**
  14082. * Removes leading whitespace or specified characters from `string`.
  14083. *
  14084. * @static
  14085. * @memberOf _
  14086. * @since 4.0.0
  14087. * @category String
  14088. * @param {string} [string=''] The string to trim.
  14089. * @param {string} [chars=whitespace] The characters to trim.
  14090. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14091. * @returns {string} Returns the trimmed string.
  14092. * @example
  14093. *
  14094. * _.trimStart(' abc ');
  14095. * // => 'abc '
  14096. *
  14097. * _.trimStart('-_-abc-_-', '_-');
  14098. * // => 'abc-_-'
  14099. */
  14100. function trimStart(string, chars, guard) {
  14101. string = toString(string);
  14102. if (string && (guard || chars === undefined)) {
  14103. return string.replace(reTrimStart, '');
  14104. }
  14105. if (!string || !(chars = baseToString(chars))) {
  14106. return string;
  14107. }
  14108. var strSymbols = stringToArray(string),
  14109. start = charsStartIndex(strSymbols, stringToArray(chars));
  14110. return castSlice(strSymbols, start).join('');
  14111. }
  14112. /**
  14113. * Truncates `string` if it's longer than the given maximum string length.
  14114. * The last characters of the truncated string are replaced with the omission
  14115. * string which defaults to "...".
  14116. *
  14117. * @static
  14118. * @memberOf _
  14119. * @since 4.0.0
  14120. * @category String
  14121. * @param {string} [string=''] The string to truncate.
  14122. * @param {Object} [options={}] The options object.
  14123. * @param {number} [options.length=30] The maximum string length.
  14124. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14125. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14126. * @returns {string} Returns the truncated string.
  14127. * @example
  14128. *
  14129. * _.truncate('hi-diddly-ho there, neighborino');
  14130. * // => 'hi-diddly-ho there, neighbo...'
  14131. *
  14132. * _.truncate('hi-diddly-ho there, neighborino', {
  14133. * 'length': 24,
  14134. * 'separator': ' '
  14135. * });
  14136. * // => 'hi-diddly-ho there,...'
  14137. *
  14138. * _.truncate('hi-diddly-ho there, neighborino', {
  14139. * 'length': 24,
  14140. * 'separator': /,? +/
  14141. * });
  14142. * // => 'hi-diddly-ho there...'
  14143. *
  14144. * _.truncate('hi-diddly-ho there, neighborino', {
  14145. * 'omission': ' [...]'
  14146. * });
  14147. * // => 'hi-diddly-ho there, neig [...]'
  14148. */
  14149. function truncate(string, options) {
  14150. var length = DEFAULT_TRUNC_LENGTH,
  14151. omission = DEFAULT_TRUNC_OMISSION;
  14152. if (isObject(options)) {
  14153. var separator = 'separator' in options ? options.separator : separator;
  14154. length = 'length' in options ? toInteger(options.length) : length;
  14155. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14156. }
  14157. string = toString(string);
  14158. var strLength = string.length;
  14159. if (hasUnicode(string)) {
  14160. var strSymbols = stringToArray(string);
  14161. strLength = strSymbols.length;
  14162. }
  14163. if (length >= strLength) {
  14164. return string;
  14165. }
  14166. var end = length - stringSize(omission);
  14167. if (end < 1) {
  14168. return omission;
  14169. }
  14170. var result = strSymbols
  14171. ? castSlice(strSymbols, 0, end).join('')
  14172. : string.slice(0, end);
  14173. if (separator === undefined) {
  14174. return result + omission;
  14175. }
  14176. if (strSymbols) {
  14177. end += (result.length - end);
  14178. }
  14179. if (isRegExp(separator)) {
  14180. if (string.slice(end).search(separator)) {
  14181. var match,
  14182. substring = result;
  14183. if (!separator.global) {
  14184. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14185. }
  14186. separator.lastIndex = 0;
  14187. while ((match = separator.exec(substring))) {
  14188. var newEnd = match.index;
  14189. }
  14190. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14191. }
  14192. } else if (string.indexOf(baseToString(separator), end) != end) {
  14193. var index = result.lastIndexOf(separator);
  14194. if (index > -1) {
  14195. result = result.slice(0, index);
  14196. }
  14197. }
  14198. return result + omission;
  14199. }
  14200. /**
  14201. * The inverse of `_.escape`; this method converts the HTML entities
  14202. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14203. * their corresponding characters.
  14204. *
  14205. * **Note:** No other HTML entities are unescaped. To unescape additional
  14206. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14207. *
  14208. * @static
  14209. * @memberOf _
  14210. * @since 0.6.0
  14211. * @category String
  14212. * @param {string} [string=''] The string to unescape.
  14213. * @returns {string} Returns the unescaped string.
  14214. * @example
  14215. *
  14216. * _.unescape('fred, barney, &amp; pebbles');
  14217. * // => 'fred, barney, & pebbles'
  14218. */
  14219. function unescape(string) {
  14220. string = toString(string);
  14221. return (string && reHasEscapedHtml.test(string))
  14222. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14223. : string;
  14224. }
  14225. /**
  14226. * Converts `string`, as space separated words, to upper case.
  14227. *
  14228. * @static
  14229. * @memberOf _
  14230. * @since 4.0.0
  14231. * @category String
  14232. * @param {string} [string=''] The string to convert.
  14233. * @returns {string} Returns the upper cased string.
  14234. * @example
  14235. *
  14236. * _.upperCase('--foo-bar');
  14237. * // => 'FOO BAR'
  14238. *
  14239. * _.upperCase('fooBar');
  14240. * // => 'FOO BAR'
  14241. *
  14242. * _.upperCase('__foo_bar__');
  14243. * // => 'FOO BAR'
  14244. */
  14245. var upperCase = createCompounder(function(result, word, index) {
  14246. return result + (index ? ' ' : '') + word.toUpperCase();
  14247. });
  14248. /**
  14249. * Converts the first character of `string` to upper case.
  14250. *
  14251. * @static
  14252. * @memberOf _
  14253. * @since 4.0.0
  14254. * @category String
  14255. * @param {string} [string=''] The string to convert.
  14256. * @returns {string} Returns the converted string.
  14257. * @example
  14258. *
  14259. * _.upperFirst('fred');
  14260. * // => 'Fred'
  14261. *
  14262. * _.upperFirst('FRED');
  14263. * // => 'FRED'
  14264. */
  14265. var upperFirst = createCaseFirst('toUpperCase');
  14266. /**
  14267. * Splits `string` into an array of its words.
  14268. *
  14269. * @static
  14270. * @memberOf _
  14271. * @since 3.0.0
  14272. * @category String
  14273. * @param {string} [string=''] The string to inspect.
  14274. * @param {RegExp|string} [pattern] The pattern to match words.
  14275. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14276. * @returns {Array} Returns the words of `string`.
  14277. * @example
  14278. *
  14279. * _.words('fred, barney, & pebbles');
  14280. * // => ['fred', 'barney', 'pebbles']
  14281. *
  14282. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14283. * // => ['fred', 'barney', '&', 'pebbles']
  14284. */
  14285. function words(string, pattern, guard) {
  14286. string = toString(string);
  14287. pattern = guard ? undefined : pattern;
  14288. if (pattern === undefined) {
  14289. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14290. }
  14291. return string.match(pattern) || [];
  14292. }
  14293. /*------------------------------------------------------------------------*/
  14294. /**
  14295. * Attempts to invoke `func`, returning either the result or the caught error
  14296. * object. Any additional arguments are provided to `func` when it's invoked.
  14297. *
  14298. * @static
  14299. * @memberOf _
  14300. * @since 3.0.0
  14301. * @category Util
  14302. * @param {Function} func The function to attempt.
  14303. * @param {...*} [args] The arguments to invoke `func` with.
  14304. * @returns {*} Returns the `func` result or error object.
  14305. * @example
  14306. *
  14307. * // Avoid throwing errors for invalid selectors.
  14308. * var elements = _.attempt(function(selector) {
  14309. * return document.querySelectorAll(selector);
  14310. * }, '>_>');
  14311. *
  14312. * if (_.isError(elements)) {
  14313. * elements = [];
  14314. * }
  14315. */
  14316. var attempt = baseRest(function(func, args) {
  14317. try {
  14318. return apply(func, undefined, args);
  14319. } catch (e) {
  14320. return isError(e) ? e : new Error(e);
  14321. }
  14322. });
  14323. /**
  14324. * Binds methods of an object to the object itself, overwriting the existing
  14325. * method.
  14326. *
  14327. * **Note:** This method doesn't set the "length" property of bound functions.
  14328. *
  14329. * @static
  14330. * @since 0.1.0
  14331. * @memberOf _
  14332. * @category Util
  14333. * @param {Object} object The object to bind and assign the bound methods to.
  14334. * @param {...(string|string[])} methodNames The object method names to bind.
  14335. * @returns {Object} Returns `object`.
  14336. * @example
  14337. *
  14338. * var view = {
  14339. * 'label': 'docs',
  14340. * 'click': function() {
  14341. * console.log('clicked ' + this.label);
  14342. * }
  14343. * };
  14344. *
  14345. * _.bindAll(view, ['click']);
  14346. * jQuery(element).on('click', view.click);
  14347. * // => Logs 'clicked docs' when clicked.
  14348. */
  14349. var bindAll = flatRest(function(object, methodNames) {
  14350. arrayEach(methodNames, function(key) {
  14351. key = toKey(key);
  14352. baseAssignValue(object, key, bind(object[key], object));
  14353. });
  14354. return object;
  14355. });
  14356. /**
  14357. * Creates a function that iterates over `pairs` and invokes the corresponding
  14358. * function of the first predicate to return truthy. The predicate-function
  14359. * pairs are invoked with the `this` binding and arguments of the created
  14360. * function.
  14361. *
  14362. * @static
  14363. * @memberOf _
  14364. * @since 4.0.0
  14365. * @category Util
  14366. * @param {Array} pairs The predicate-function pairs.
  14367. * @returns {Function} Returns the new composite function.
  14368. * @example
  14369. *
  14370. * var func = _.cond([
  14371. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14372. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14373. * [_.stubTrue, _.constant('no match')]
  14374. * ]);
  14375. *
  14376. * func({ 'a': 1, 'b': 2 });
  14377. * // => 'matches A'
  14378. *
  14379. * func({ 'a': 0, 'b': 1 });
  14380. * // => 'matches B'
  14381. *
  14382. * func({ 'a': '1', 'b': '2' });
  14383. * // => 'no match'
  14384. */
  14385. function cond(pairs) {
  14386. var length = pairs == null ? 0 : pairs.length,
  14387. toIteratee = getIteratee();
  14388. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14389. if (typeof pair[1] != 'function') {
  14390. throw new TypeError(FUNC_ERROR_TEXT);
  14391. }
  14392. return [toIteratee(pair[0]), pair[1]];
  14393. });
  14394. return baseRest(function(args) {
  14395. var index = -1;
  14396. while (++index < length) {
  14397. var pair = pairs[index];
  14398. if (apply(pair[0], this, args)) {
  14399. return apply(pair[1], this, args);
  14400. }
  14401. }
  14402. });
  14403. }
  14404. /**
  14405. * Creates a function that invokes the predicate properties of `source` with
  14406. * the corresponding property values of a given object, returning `true` if
  14407. * all predicates return truthy, else `false`.
  14408. *
  14409. * **Note:** The created function is equivalent to `_.conformsTo` with
  14410. * `source` partially applied.
  14411. *
  14412. * @static
  14413. * @memberOf _
  14414. * @since 4.0.0
  14415. * @category Util
  14416. * @param {Object} source The object of property predicates to conform to.
  14417. * @returns {Function} Returns the new spec function.
  14418. * @example
  14419. *
  14420. * var objects = [
  14421. * { 'a': 2, 'b': 1 },
  14422. * { 'a': 1, 'b': 2 }
  14423. * ];
  14424. *
  14425. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14426. * // => [{ 'a': 1, 'b': 2 }]
  14427. */
  14428. function conforms(source) {
  14429. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14430. }
  14431. /**
  14432. * Creates a function that returns `value`.
  14433. *
  14434. * @static
  14435. * @memberOf _
  14436. * @since 2.4.0
  14437. * @category Util
  14438. * @param {*} value The value to return from the new function.
  14439. * @returns {Function} Returns the new constant function.
  14440. * @example
  14441. *
  14442. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14443. *
  14444. * console.log(objects);
  14445. * // => [{ 'a': 1 }, { 'a': 1 }]
  14446. *
  14447. * console.log(objects[0] === objects[1]);
  14448. * // => true
  14449. */
  14450. function constant(value) {
  14451. return function() {
  14452. return value;
  14453. };
  14454. }
  14455. /**
  14456. * Checks `value` to determine whether a default value should be returned in
  14457. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14458. * or `undefined`.
  14459. *
  14460. * @static
  14461. * @memberOf _
  14462. * @since 4.14.0
  14463. * @category Util
  14464. * @param {*} value The value to check.
  14465. * @param {*} defaultValue The default value.
  14466. * @returns {*} Returns the resolved value.
  14467. * @example
  14468. *
  14469. * _.defaultTo(1, 10);
  14470. * // => 1
  14471. *
  14472. * _.defaultTo(undefined, 10);
  14473. * // => 10
  14474. */
  14475. function defaultTo(value, defaultValue) {
  14476. return (value == null || value !== value) ? defaultValue : value;
  14477. }
  14478. /**
  14479. * Creates a function that returns the result of invoking the given functions
  14480. * with the `this` binding of the created function, where each successive
  14481. * invocation is supplied the return value of the previous.
  14482. *
  14483. * @static
  14484. * @memberOf _
  14485. * @since 3.0.0
  14486. * @category Util
  14487. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14488. * @returns {Function} Returns the new composite function.
  14489. * @see _.flowRight
  14490. * @example
  14491. *
  14492. * function square(n) {
  14493. * return n * n;
  14494. * }
  14495. *
  14496. * var addSquare = _.flow([_.add, square]);
  14497. * addSquare(1, 2);
  14498. * // => 9
  14499. */
  14500. var flow = createFlow();
  14501. /**
  14502. * This method is like `_.flow` except that it creates a function that
  14503. * invokes the given functions from right to left.
  14504. *
  14505. * @static
  14506. * @since 3.0.0
  14507. * @memberOf _
  14508. * @category Util
  14509. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14510. * @returns {Function} Returns the new composite function.
  14511. * @see _.flow
  14512. * @example
  14513. *
  14514. * function square(n) {
  14515. * return n * n;
  14516. * }
  14517. *
  14518. * var addSquare = _.flowRight([square, _.add]);
  14519. * addSquare(1, 2);
  14520. * // => 9
  14521. */
  14522. var flowRight = createFlow(true);
  14523. /**
  14524. * This method returns the first argument it receives.
  14525. *
  14526. * @static
  14527. * @since 0.1.0
  14528. * @memberOf _
  14529. * @category Util
  14530. * @param {*} value Any value.
  14531. * @returns {*} Returns `value`.
  14532. * @example
  14533. *
  14534. * var object = { 'a': 1 };
  14535. *
  14536. * console.log(_.identity(object) === object);
  14537. * // => true
  14538. */
  14539. function identity(value) {
  14540. return value;
  14541. }
  14542. /**
  14543. * Creates a function that invokes `func` with the arguments of the created
  14544. * function. If `func` is a property name, the created function returns the
  14545. * property value for a given element. If `func` is an array or object, the
  14546. * created function returns `true` for elements that contain the equivalent
  14547. * source properties, otherwise it returns `false`.
  14548. *
  14549. * @static
  14550. * @since 4.0.0
  14551. * @memberOf _
  14552. * @category Util
  14553. * @param {*} [func=_.identity] The value to convert to a callback.
  14554. * @returns {Function} Returns the callback.
  14555. * @example
  14556. *
  14557. * var users = [
  14558. * { 'user': 'barney', 'age': 36, 'active': true },
  14559. * { 'user': 'fred', 'age': 40, 'active': false }
  14560. * ];
  14561. *
  14562. * // The `_.matches` iteratee shorthand.
  14563. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14564. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14565. *
  14566. * // The `_.matchesProperty` iteratee shorthand.
  14567. * _.filter(users, _.iteratee(['user', 'fred']));
  14568. * // => [{ 'user': 'fred', 'age': 40 }]
  14569. *
  14570. * // The `_.property` iteratee shorthand.
  14571. * _.map(users, _.iteratee('user'));
  14572. * // => ['barney', 'fred']
  14573. *
  14574. * // Create custom iteratee shorthands.
  14575. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14576. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14577. * return func.test(string);
  14578. * };
  14579. * });
  14580. *
  14581. * _.filter(['abc', 'def'], /ef/);
  14582. * // => ['def']
  14583. */
  14584. function iteratee(func) {
  14585. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14586. }
  14587. /**
  14588. * Creates a function that performs a partial deep comparison between a given
  14589. * object and `source`, returning `true` if the given object has equivalent
  14590. * property values, else `false`.
  14591. *
  14592. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14593. * partially applied.
  14594. *
  14595. * Partial comparisons will match empty array and empty object `source`
  14596. * values against any array or object value, respectively. See `_.isEqual`
  14597. * for a list of supported value comparisons.
  14598. *
  14599. * @static
  14600. * @memberOf _
  14601. * @since 3.0.0
  14602. * @category Util
  14603. * @param {Object} source The object of property values to match.
  14604. * @returns {Function} Returns the new spec function.
  14605. * @example
  14606. *
  14607. * var objects = [
  14608. * { 'a': 1, 'b': 2, 'c': 3 },
  14609. * { 'a': 4, 'b': 5, 'c': 6 }
  14610. * ];
  14611. *
  14612. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14613. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14614. */
  14615. function matches(source) {
  14616. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14617. }
  14618. /**
  14619. * Creates a function that performs a partial deep comparison between the
  14620. * value at `path` of a given object to `srcValue`, returning `true` if the
  14621. * object value is equivalent, else `false`.
  14622. *
  14623. * **Note:** Partial comparisons will match empty array and empty object
  14624. * `srcValue` values against any array or object value, respectively. See
  14625. * `_.isEqual` for a list of supported value comparisons.
  14626. *
  14627. * @static
  14628. * @memberOf _
  14629. * @since 3.2.0
  14630. * @category Util
  14631. * @param {Array|string} path The path of the property to get.
  14632. * @param {*} srcValue The value to match.
  14633. * @returns {Function} Returns the new spec function.
  14634. * @example
  14635. *
  14636. * var objects = [
  14637. * { 'a': 1, 'b': 2, 'c': 3 },
  14638. * { 'a': 4, 'b': 5, 'c': 6 }
  14639. * ];
  14640. *
  14641. * _.find(objects, _.matchesProperty('a', 4));
  14642. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14643. */
  14644. function matchesProperty(path, srcValue) {
  14645. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14646. }
  14647. /**
  14648. * Creates a function that invokes the method at `path` of a given object.
  14649. * Any additional arguments are provided to the invoked method.
  14650. *
  14651. * @static
  14652. * @memberOf _
  14653. * @since 3.7.0
  14654. * @category Util
  14655. * @param {Array|string} path The path of the method to invoke.
  14656. * @param {...*} [args] The arguments to invoke the method with.
  14657. * @returns {Function} Returns the new invoker function.
  14658. * @example
  14659. *
  14660. * var objects = [
  14661. * { 'a': { 'b': _.constant(2) } },
  14662. * { 'a': { 'b': _.constant(1) } }
  14663. * ];
  14664. *
  14665. * _.map(objects, _.method('a.b'));
  14666. * // => [2, 1]
  14667. *
  14668. * _.map(objects, _.method(['a', 'b']));
  14669. * // => [2, 1]
  14670. */
  14671. var method = baseRest(function(path, args) {
  14672. return function(object) {
  14673. return baseInvoke(object, path, args);
  14674. };
  14675. });
  14676. /**
  14677. * The opposite of `_.method`; this method creates a function that invokes
  14678. * the method at a given path of `object`. Any additional arguments are
  14679. * provided to the invoked method.
  14680. *
  14681. * @static
  14682. * @memberOf _
  14683. * @since 3.7.0
  14684. * @category Util
  14685. * @param {Object} object The object to query.
  14686. * @param {...*} [args] The arguments to invoke the method with.
  14687. * @returns {Function} Returns the new invoker function.
  14688. * @example
  14689. *
  14690. * var array = _.times(3, _.constant),
  14691. * object = { 'a': array, 'b': array, 'c': array };
  14692. *
  14693. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14694. * // => [2, 0]
  14695. *
  14696. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14697. * // => [2, 0]
  14698. */
  14699. var methodOf = baseRest(function(object, args) {
  14700. return function(path) {
  14701. return baseInvoke(object, path, args);
  14702. };
  14703. });
  14704. /**
  14705. * Adds all own enumerable string keyed function properties of a source
  14706. * object to the destination object. If `object` is a function, then methods
  14707. * are added to its prototype as well.
  14708. *
  14709. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14710. * avoid conflicts caused by modifying the original.
  14711. *
  14712. * @static
  14713. * @since 0.1.0
  14714. * @memberOf _
  14715. * @category Util
  14716. * @param {Function|Object} [object=lodash] The destination object.
  14717. * @param {Object} source The object of functions to add.
  14718. * @param {Object} [options={}] The options object.
  14719. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14720. * @returns {Function|Object} Returns `object`.
  14721. * @example
  14722. *
  14723. * function vowels(string) {
  14724. * return _.filter(string, function(v) {
  14725. * return /[aeiou]/i.test(v);
  14726. * });
  14727. * }
  14728. *
  14729. * _.mixin({ 'vowels': vowels });
  14730. * _.vowels('fred');
  14731. * // => ['e']
  14732. *
  14733. * _('fred').vowels().value();
  14734. * // => ['e']
  14735. *
  14736. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14737. * _('fred').vowels();
  14738. * // => ['e']
  14739. */
  14740. function mixin(object, source, options) {
  14741. var props = keys(source),
  14742. methodNames = baseFunctions(source, props);
  14743. if (options == null &&
  14744. !(isObject(source) && (methodNames.length || !props.length))) {
  14745. options = source;
  14746. source = object;
  14747. object = this;
  14748. methodNames = baseFunctions(source, keys(source));
  14749. }
  14750. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14751. isFunc = isFunction(object);
  14752. arrayEach(methodNames, function(methodName) {
  14753. var func = source[methodName];
  14754. object[methodName] = func;
  14755. if (isFunc) {
  14756. object.prototype[methodName] = function() {
  14757. var chainAll = this.__chain__;
  14758. if (chain || chainAll) {
  14759. var result = object(this.__wrapped__),
  14760. actions = result.__actions__ = copyArray(this.__actions__);
  14761. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14762. result.__chain__ = chainAll;
  14763. return result;
  14764. }
  14765. return func.apply(object, arrayPush([this.value()], arguments));
  14766. };
  14767. }
  14768. });
  14769. return object;
  14770. }
  14771. /**
  14772. * Reverts the `_` variable to its previous value and returns a reference to
  14773. * the `lodash` function.
  14774. *
  14775. * @static
  14776. * @since 0.1.0
  14777. * @memberOf _
  14778. * @category Util
  14779. * @returns {Function} Returns the `lodash` function.
  14780. * @example
  14781. *
  14782. * var lodash = _.noConflict();
  14783. */
  14784. function noConflict() {
  14785. if (root._ === this) {
  14786. root._ = oldDash;
  14787. }
  14788. return this;
  14789. }
  14790. /**
  14791. * This method returns `undefined`.
  14792. *
  14793. * @static
  14794. * @memberOf _
  14795. * @since 2.3.0
  14796. * @category Util
  14797. * @example
  14798. *
  14799. * _.times(2, _.noop);
  14800. * // => [undefined, undefined]
  14801. */
  14802. function noop() {
  14803. // No operation performed.
  14804. }
  14805. /**
  14806. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14807. * the nth argument from the end is returned.
  14808. *
  14809. * @static
  14810. * @memberOf _
  14811. * @since 4.0.0
  14812. * @category Util
  14813. * @param {number} [n=0] The index of the argument to return.
  14814. * @returns {Function} Returns the new pass-thru function.
  14815. * @example
  14816. *
  14817. * var func = _.nthArg(1);
  14818. * func('a', 'b', 'c', 'd');
  14819. * // => 'b'
  14820. *
  14821. * var func = _.nthArg(-2);
  14822. * func('a', 'b', 'c', 'd');
  14823. * // => 'c'
  14824. */
  14825. function nthArg(n) {
  14826. n = toInteger(n);
  14827. return baseRest(function(args) {
  14828. return baseNth(args, n);
  14829. });
  14830. }
  14831. /**
  14832. * Creates a function that invokes `iteratees` with the arguments it receives
  14833. * and returns their results.
  14834. *
  14835. * @static
  14836. * @memberOf _
  14837. * @since 4.0.0
  14838. * @category Util
  14839. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14840. * The iteratees to invoke.
  14841. * @returns {Function} Returns the new function.
  14842. * @example
  14843. *
  14844. * var func = _.over([Math.max, Math.min]);
  14845. *
  14846. * func(1, 2, 3, 4);
  14847. * // => [4, 1]
  14848. */
  14849. var over = createOver(arrayMap);
  14850. /**
  14851. * Creates a function that checks if **all** of the `predicates` return
  14852. * truthy when invoked with the arguments it receives.
  14853. *
  14854. * @static
  14855. * @memberOf _
  14856. * @since 4.0.0
  14857. * @category Util
  14858. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14859. * The predicates to check.
  14860. * @returns {Function} Returns the new function.
  14861. * @example
  14862. *
  14863. * var func = _.overEvery([Boolean, isFinite]);
  14864. *
  14865. * func('1');
  14866. * // => true
  14867. *
  14868. * func(null);
  14869. * // => false
  14870. *
  14871. * func(NaN);
  14872. * // => false
  14873. */
  14874. var overEvery = createOver(arrayEvery);
  14875. /**
  14876. * Creates a function that checks if **any** of the `predicates` return
  14877. * truthy when invoked with the arguments it receives.
  14878. *
  14879. * @static
  14880. * @memberOf _
  14881. * @since 4.0.0
  14882. * @category Util
  14883. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14884. * The predicates to check.
  14885. * @returns {Function} Returns the new function.
  14886. * @example
  14887. *
  14888. * var func = _.overSome([Boolean, isFinite]);
  14889. *
  14890. * func('1');
  14891. * // => true
  14892. *
  14893. * func(null);
  14894. * // => true
  14895. *
  14896. * func(NaN);
  14897. * // => false
  14898. */
  14899. var overSome = createOver(arraySome);
  14900. /**
  14901. * Creates a function that returns the value at `path` of a given object.
  14902. *
  14903. * @static
  14904. * @memberOf _
  14905. * @since 2.4.0
  14906. * @category Util
  14907. * @param {Array|string} path The path of the property to get.
  14908. * @returns {Function} Returns the new accessor function.
  14909. * @example
  14910. *
  14911. * var objects = [
  14912. * { 'a': { 'b': 2 } },
  14913. * { 'a': { 'b': 1 } }
  14914. * ];
  14915. *
  14916. * _.map(objects, _.property('a.b'));
  14917. * // => [2, 1]
  14918. *
  14919. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14920. * // => [1, 2]
  14921. */
  14922. function property(path) {
  14923. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14924. }
  14925. /**
  14926. * The opposite of `_.property`; this method creates a function that returns
  14927. * the value at a given path of `object`.
  14928. *
  14929. * @static
  14930. * @memberOf _
  14931. * @since 3.0.0
  14932. * @category Util
  14933. * @param {Object} object The object to query.
  14934. * @returns {Function} Returns the new accessor function.
  14935. * @example
  14936. *
  14937. * var array = [0, 1, 2],
  14938. * object = { 'a': array, 'b': array, 'c': array };
  14939. *
  14940. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14941. * // => [2, 0]
  14942. *
  14943. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14944. * // => [2, 0]
  14945. */
  14946. function propertyOf(object) {
  14947. return function(path) {
  14948. return object == null ? undefined : baseGet(object, path);
  14949. };
  14950. }
  14951. /**
  14952. * Creates an array of numbers (positive and/or negative) progressing from
  14953. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14954. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14955. * it's set to `start` with `start` then set to `0`.
  14956. *
  14957. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14958. * floating-point values which can produce unexpected results.
  14959. *
  14960. * @static
  14961. * @since 0.1.0
  14962. * @memberOf _
  14963. * @category Util
  14964. * @param {number} [start=0] The start of the range.
  14965. * @param {number} end The end of the range.
  14966. * @param {number} [step=1] The value to increment or decrement by.
  14967. * @returns {Array} Returns the range of numbers.
  14968. * @see _.inRange, _.rangeRight
  14969. * @example
  14970. *
  14971. * _.range(4);
  14972. * // => [0, 1, 2, 3]
  14973. *
  14974. * _.range(-4);
  14975. * // => [0, -1, -2, -3]
  14976. *
  14977. * _.range(1, 5);
  14978. * // => [1, 2, 3, 4]
  14979. *
  14980. * _.range(0, 20, 5);
  14981. * // => [0, 5, 10, 15]
  14982. *
  14983. * _.range(0, -4, -1);
  14984. * // => [0, -1, -2, -3]
  14985. *
  14986. * _.range(1, 4, 0);
  14987. * // => [1, 1, 1]
  14988. *
  14989. * _.range(0);
  14990. * // => []
  14991. */
  14992. var range = createRange();
  14993. /**
  14994. * This method is like `_.range` except that it populates values in
  14995. * descending order.
  14996. *
  14997. * @static
  14998. * @memberOf _
  14999. * @since 4.0.0
  15000. * @category Util
  15001. * @param {number} [start=0] The start of the range.
  15002. * @param {number} end The end of the range.
  15003. * @param {number} [step=1] The value to increment or decrement by.
  15004. * @returns {Array} Returns the range of numbers.
  15005. * @see _.inRange, _.range
  15006. * @example
  15007. *
  15008. * _.rangeRight(4);
  15009. * // => [3, 2, 1, 0]
  15010. *
  15011. * _.rangeRight(-4);
  15012. * // => [-3, -2, -1, 0]
  15013. *
  15014. * _.rangeRight(1, 5);
  15015. * // => [4, 3, 2, 1]
  15016. *
  15017. * _.rangeRight(0, 20, 5);
  15018. * // => [15, 10, 5, 0]
  15019. *
  15020. * _.rangeRight(0, -4, -1);
  15021. * // => [-3, -2, -1, 0]
  15022. *
  15023. * _.rangeRight(1, 4, 0);
  15024. * // => [1, 1, 1]
  15025. *
  15026. * _.rangeRight(0);
  15027. * // => []
  15028. */
  15029. var rangeRight = createRange(true);
  15030. /**
  15031. * This method returns a new empty array.
  15032. *
  15033. * @static
  15034. * @memberOf _
  15035. * @since 4.13.0
  15036. * @category Util
  15037. * @returns {Array} Returns the new empty array.
  15038. * @example
  15039. *
  15040. * var arrays = _.times(2, _.stubArray);
  15041. *
  15042. * console.log(arrays);
  15043. * // => [[], []]
  15044. *
  15045. * console.log(arrays[0] === arrays[1]);
  15046. * // => false
  15047. */
  15048. function stubArray() {
  15049. return [];
  15050. }
  15051. /**
  15052. * This method returns `false`.
  15053. *
  15054. * @static
  15055. * @memberOf _
  15056. * @since 4.13.0
  15057. * @category Util
  15058. * @returns {boolean} Returns `false`.
  15059. * @example
  15060. *
  15061. * _.times(2, _.stubFalse);
  15062. * // => [false, false]
  15063. */
  15064. function stubFalse() {
  15065. return false;
  15066. }
  15067. /**
  15068. * This method returns a new empty object.
  15069. *
  15070. * @static
  15071. * @memberOf _
  15072. * @since 4.13.0
  15073. * @category Util
  15074. * @returns {Object} Returns the new empty object.
  15075. * @example
  15076. *
  15077. * var objects = _.times(2, _.stubObject);
  15078. *
  15079. * console.log(objects);
  15080. * // => [{}, {}]
  15081. *
  15082. * console.log(objects[0] === objects[1]);
  15083. * // => false
  15084. */
  15085. function stubObject() {
  15086. return {};
  15087. }
  15088. /**
  15089. * This method returns an empty string.
  15090. *
  15091. * @static
  15092. * @memberOf _
  15093. * @since 4.13.0
  15094. * @category Util
  15095. * @returns {string} Returns the empty string.
  15096. * @example
  15097. *
  15098. * _.times(2, _.stubString);
  15099. * // => ['', '']
  15100. */
  15101. function stubString() {
  15102. return '';
  15103. }
  15104. /**
  15105. * This method returns `true`.
  15106. *
  15107. * @static
  15108. * @memberOf _
  15109. * @since 4.13.0
  15110. * @category Util
  15111. * @returns {boolean} Returns `true`.
  15112. * @example
  15113. *
  15114. * _.times(2, _.stubTrue);
  15115. * // => [true, true]
  15116. */
  15117. function stubTrue() {
  15118. return true;
  15119. }
  15120. /**
  15121. * Invokes the iteratee `n` times, returning an array of the results of
  15122. * each invocation. The iteratee is invoked with one argument; (index).
  15123. *
  15124. * @static
  15125. * @since 0.1.0
  15126. * @memberOf _
  15127. * @category Util
  15128. * @param {number} n The number of times to invoke `iteratee`.
  15129. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15130. * @returns {Array} Returns the array of results.
  15131. * @example
  15132. *
  15133. * _.times(3, String);
  15134. * // => ['0', '1', '2']
  15135. *
  15136. * _.times(4, _.constant(0));
  15137. * // => [0, 0, 0, 0]
  15138. */
  15139. function times(n, iteratee) {
  15140. n = toInteger(n);
  15141. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15142. return [];
  15143. }
  15144. var index = MAX_ARRAY_LENGTH,
  15145. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15146. iteratee = getIteratee(iteratee);
  15147. n -= MAX_ARRAY_LENGTH;
  15148. var result = baseTimes(length, iteratee);
  15149. while (++index < n) {
  15150. iteratee(index);
  15151. }
  15152. return result;
  15153. }
  15154. /**
  15155. * Converts `value` to a property path array.
  15156. *
  15157. * @static
  15158. * @memberOf _
  15159. * @since 4.0.0
  15160. * @category Util
  15161. * @param {*} value The value to convert.
  15162. * @returns {Array} Returns the new property path array.
  15163. * @example
  15164. *
  15165. * _.toPath('a.b.c');
  15166. * // => ['a', 'b', 'c']
  15167. *
  15168. * _.toPath('a[0].b.c');
  15169. * // => ['a', '0', 'b', 'c']
  15170. */
  15171. function toPath(value) {
  15172. if (isArray(value)) {
  15173. return arrayMap(value, toKey);
  15174. }
  15175. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15176. }
  15177. /**
  15178. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15179. *
  15180. * @static
  15181. * @since 0.1.0
  15182. * @memberOf _
  15183. * @category Util
  15184. * @param {string} [prefix=''] The value to prefix the ID with.
  15185. * @returns {string} Returns the unique ID.
  15186. * @example
  15187. *
  15188. * _.uniqueId('contact_');
  15189. * // => 'contact_104'
  15190. *
  15191. * _.uniqueId();
  15192. * // => '105'
  15193. */
  15194. function uniqueId(prefix) {
  15195. var id = ++idCounter;
  15196. return toString(prefix) + id;
  15197. }
  15198. /*------------------------------------------------------------------------*/
  15199. /**
  15200. * Adds two numbers.
  15201. *
  15202. * @static
  15203. * @memberOf _
  15204. * @since 3.4.0
  15205. * @category Math
  15206. * @param {number} augend The first number in an addition.
  15207. * @param {number} addend The second number in an addition.
  15208. * @returns {number} Returns the total.
  15209. * @example
  15210. *
  15211. * _.add(6, 4);
  15212. * // => 10
  15213. */
  15214. var add = createMathOperation(function(augend, addend) {
  15215. return augend + addend;
  15216. }, 0);
  15217. /**
  15218. * Computes `number` rounded up to `precision`.
  15219. *
  15220. * @static
  15221. * @memberOf _
  15222. * @since 3.10.0
  15223. * @category Math
  15224. * @param {number} number The number to round up.
  15225. * @param {number} [precision=0] The precision to round up to.
  15226. * @returns {number} Returns the rounded up number.
  15227. * @example
  15228. *
  15229. * _.ceil(4.006);
  15230. * // => 5
  15231. *
  15232. * _.ceil(6.004, 2);
  15233. * // => 6.01
  15234. *
  15235. * _.ceil(6040, -2);
  15236. * // => 6100
  15237. */
  15238. var ceil = createRound('ceil');
  15239. /**
  15240. * Divide two numbers.
  15241. *
  15242. * @static
  15243. * @memberOf _
  15244. * @since 4.7.0
  15245. * @category Math
  15246. * @param {number} dividend The first number in a division.
  15247. * @param {number} divisor The second number in a division.
  15248. * @returns {number} Returns the quotient.
  15249. * @example
  15250. *
  15251. * _.divide(6, 4);
  15252. * // => 1.5
  15253. */
  15254. var divide = createMathOperation(function(dividend, divisor) {
  15255. return dividend / divisor;
  15256. }, 1);
  15257. /**
  15258. * Computes `number` rounded down to `precision`.
  15259. *
  15260. * @static
  15261. * @memberOf _
  15262. * @since 3.10.0
  15263. * @category Math
  15264. * @param {number} number The number to round down.
  15265. * @param {number} [precision=0] The precision to round down to.
  15266. * @returns {number} Returns the rounded down number.
  15267. * @example
  15268. *
  15269. * _.floor(4.006);
  15270. * // => 4
  15271. *
  15272. * _.floor(0.046, 2);
  15273. * // => 0.04
  15274. *
  15275. * _.floor(4060, -2);
  15276. * // => 4000
  15277. */
  15278. var floor = createRound('floor');
  15279. /**
  15280. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15281. * `undefined` is returned.
  15282. *
  15283. * @static
  15284. * @since 0.1.0
  15285. * @memberOf _
  15286. * @category Math
  15287. * @param {Array} array The array to iterate over.
  15288. * @returns {*} Returns the maximum value.
  15289. * @example
  15290. *
  15291. * _.max([4, 2, 8, 6]);
  15292. * // => 8
  15293. *
  15294. * _.max([]);
  15295. * // => undefined
  15296. */
  15297. function max(array) {
  15298. return (array && array.length)
  15299. ? baseExtremum(array, identity, baseGt)
  15300. : undefined;
  15301. }
  15302. /**
  15303. * This method is like `_.max` except that it accepts `iteratee` which is
  15304. * invoked for each element in `array` to generate the criterion by which
  15305. * the value is ranked. The iteratee is invoked with one argument: (value).
  15306. *
  15307. * @static
  15308. * @memberOf _
  15309. * @since 4.0.0
  15310. * @category Math
  15311. * @param {Array} array The array to iterate over.
  15312. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15313. * @returns {*} Returns the maximum value.
  15314. * @example
  15315. *
  15316. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15317. *
  15318. * _.maxBy(objects, function(o) { return o.n; });
  15319. * // => { 'n': 2 }
  15320. *
  15321. * // The `_.property` iteratee shorthand.
  15322. * _.maxBy(objects, 'n');
  15323. * // => { 'n': 2 }
  15324. */
  15325. function maxBy(array, iteratee) {
  15326. return (array && array.length)
  15327. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15328. : undefined;
  15329. }
  15330. /**
  15331. * Computes the mean of the values in `array`.
  15332. *
  15333. * @static
  15334. * @memberOf _
  15335. * @since 4.0.0
  15336. * @category Math
  15337. * @param {Array} array The array to iterate over.
  15338. * @returns {number} Returns the mean.
  15339. * @example
  15340. *
  15341. * _.mean([4, 2, 8, 6]);
  15342. * // => 5
  15343. */
  15344. function mean(array) {
  15345. return baseMean(array, identity);
  15346. }
  15347. /**
  15348. * This method is like `_.mean` except that it accepts `iteratee` which is
  15349. * invoked for each element in `array` to generate the value to be averaged.
  15350. * The iteratee is invoked with one argument: (value).
  15351. *
  15352. * @static
  15353. * @memberOf _
  15354. * @since 4.7.0
  15355. * @category Math
  15356. * @param {Array} array The array to iterate over.
  15357. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15358. * @returns {number} Returns the mean.
  15359. * @example
  15360. *
  15361. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15362. *
  15363. * _.meanBy(objects, function(o) { return o.n; });
  15364. * // => 5
  15365. *
  15366. * // The `_.property` iteratee shorthand.
  15367. * _.meanBy(objects, 'n');
  15368. * // => 5
  15369. */
  15370. function meanBy(array, iteratee) {
  15371. return baseMean(array, getIteratee(iteratee, 2));
  15372. }
  15373. /**
  15374. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15375. * `undefined` is returned.
  15376. *
  15377. * @static
  15378. * @since 0.1.0
  15379. * @memberOf _
  15380. * @category Math
  15381. * @param {Array} array The array to iterate over.
  15382. * @returns {*} Returns the minimum value.
  15383. * @example
  15384. *
  15385. * _.min([4, 2, 8, 6]);
  15386. * // => 2
  15387. *
  15388. * _.min([]);
  15389. * // => undefined
  15390. */
  15391. function min(array) {
  15392. return (array && array.length)
  15393. ? baseExtremum(array, identity, baseLt)
  15394. : undefined;
  15395. }
  15396. /**
  15397. * This method is like `_.min` except that it accepts `iteratee` which is
  15398. * invoked for each element in `array` to generate the criterion by which
  15399. * the value is ranked. The iteratee is invoked with one argument: (value).
  15400. *
  15401. * @static
  15402. * @memberOf _
  15403. * @since 4.0.0
  15404. * @category Math
  15405. * @param {Array} array The array to iterate over.
  15406. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15407. * @returns {*} Returns the minimum value.
  15408. * @example
  15409. *
  15410. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15411. *
  15412. * _.minBy(objects, function(o) { return o.n; });
  15413. * // => { 'n': 1 }
  15414. *
  15415. * // The `_.property` iteratee shorthand.
  15416. * _.minBy(objects, 'n');
  15417. * // => { 'n': 1 }
  15418. */
  15419. function minBy(array, iteratee) {
  15420. return (array && array.length)
  15421. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15422. : undefined;
  15423. }
  15424. /**
  15425. * Multiply two numbers.
  15426. *
  15427. * @static
  15428. * @memberOf _
  15429. * @since 4.7.0
  15430. * @category Math
  15431. * @param {number} multiplier The first number in a multiplication.
  15432. * @param {number} multiplicand The second number in a multiplication.
  15433. * @returns {number} Returns the product.
  15434. * @example
  15435. *
  15436. * _.multiply(6, 4);
  15437. * // => 24
  15438. */
  15439. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15440. return multiplier * multiplicand;
  15441. }, 1);
  15442. /**
  15443. * Computes `number` rounded to `precision`.
  15444. *
  15445. * @static
  15446. * @memberOf _
  15447. * @since 3.10.0
  15448. * @category Math
  15449. * @param {number} number The number to round.
  15450. * @param {number} [precision=0] The precision to round to.
  15451. * @returns {number} Returns the rounded number.
  15452. * @example
  15453. *
  15454. * _.round(4.006);
  15455. * // => 4
  15456. *
  15457. * _.round(4.006, 2);
  15458. * // => 4.01
  15459. *
  15460. * _.round(4060, -2);
  15461. * // => 4100
  15462. */
  15463. var round = createRound('round');
  15464. /**
  15465. * Subtract two numbers.
  15466. *
  15467. * @static
  15468. * @memberOf _
  15469. * @since 4.0.0
  15470. * @category Math
  15471. * @param {number} minuend The first number in a subtraction.
  15472. * @param {number} subtrahend The second number in a subtraction.
  15473. * @returns {number} Returns the difference.
  15474. * @example
  15475. *
  15476. * _.subtract(6, 4);
  15477. * // => 2
  15478. */
  15479. var subtract = createMathOperation(function(minuend, subtrahend) {
  15480. return minuend - subtrahend;
  15481. }, 0);
  15482. /**
  15483. * Computes the sum of the values in `array`.
  15484. *
  15485. * @static
  15486. * @memberOf _
  15487. * @since 3.4.0
  15488. * @category Math
  15489. * @param {Array} array The array to iterate over.
  15490. * @returns {number} Returns the sum.
  15491. * @example
  15492. *
  15493. * _.sum([4, 2, 8, 6]);
  15494. * // => 20
  15495. */
  15496. function sum(array) {
  15497. return (array && array.length)
  15498. ? baseSum(array, identity)
  15499. : 0;
  15500. }
  15501. /**
  15502. * This method is like `_.sum` except that it accepts `iteratee` which is
  15503. * invoked for each element in `array` to generate the value to be summed.
  15504. * The iteratee is invoked with one argument: (value).
  15505. *
  15506. * @static
  15507. * @memberOf _
  15508. * @since 4.0.0
  15509. * @category Math
  15510. * @param {Array} array The array to iterate over.
  15511. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15512. * @returns {number} Returns the sum.
  15513. * @example
  15514. *
  15515. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15516. *
  15517. * _.sumBy(objects, function(o) { return o.n; });
  15518. * // => 20
  15519. *
  15520. * // The `_.property` iteratee shorthand.
  15521. * _.sumBy(objects, 'n');
  15522. * // => 20
  15523. */
  15524. function sumBy(array, iteratee) {
  15525. return (array && array.length)
  15526. ? baseSum(array, getIteratee(iteratee, 2))
  15527. : 0;
  15528. }
  15529. /*------------------------------------------------------------------------*/
  15530. // Add methods that return wrapped values in chain sequences.
  15531. lodash.after = after;
  15532. lodash.ary = ary;
  15533. lodash.assign = assign;
  15534. lodash.assignIn = assignIn;
  15535. lodash.assignInWith = assignInWith;
  15536. lodash.assignWith = assignWith;
  15537. lodash.at = at;
  15538. lodash.before = before;
  15539. lodash.bind = bind;
  15540. lodash.bindAll = bindAll;
  15541. lodash.bindKey = bindKey;
  15542. lodash.castArray = castArray;
  15543. lodash.chain = chain;
  15544. lodash.chunk = chunk;
  15545. lodash.compact = compact;
  15546. lodash.concat = concat;
  15547. lodash.cond = cond;
  15548. lodash.conforms = conforms;
  15549. lodash.constant = constant;
  15550. lodash.countBy = countBy;
  15551. lodash.create = create;
  15552. lodash.curry = curry;
  15553. lodash.curryRight = curryRight;
  15554. lodash.debounce = debounce;
  15555. lodash.defaults = defaults;
  15556. lodash.defaultsDeep = defaultsDeep;
  15557. lodash.defer = defer;
  15558. lodash.delay = delay;
  15559. lodash.difference = difference;
  15560. lodash.differenceBy = differenceBy;
  15561. lodash.differenceWith = differenceWith;
  15562. lodash.drop = drop;
  15563. lodash.dropRight = dropRight;
  15564. lodash.dropRightWhile = dropRightWhile;
  15565. lodash.dropWhile = dropWhile;
  15566. lodash.fill = fill;
  15567. lodash.filter = filter;
  15568. lodash.flatMap = flatMap;
  15569. lodash.flatMapDeep = flatMapDeep;
  15570. lodash.flatMapDepth = flatMapDepth;
  15571. lodash.flatten = flatten;
  15572. lodash.flattenDeep = flattenDeep;
  15573. lodash.flattenDepth = flattenDepth;
  15574. lodash.flip = flip;
  15575. lodash.flow = flow;
  15576. lodash.flowRight = flowRight;
  15577. lodash.fromPairs = fromPairs;
  15578. lodash.functions = functions;
  15579. lodash.functionsIn = functionsIn;
  15580. lodash.groupBy = groupBy;
  15581. lodash.initial = initial;
  15582. lodash.intersection = intersection;
  15583. lodash.intersectionBy = intersectionBy;
  15584. lodash.intersectionWith = intersectionWith;
  15585. lodash.invert = invert;
  15586. lodash.invertBy = invertBy;
  15587. lodash.invokeMap = invokeMap;
  15588. lodash.iteratee = iteratee;
  15589. lodash.keyBy = keyBy;
  15590. lodash.keys = keys;
  15591. lodash.keysIn = keysIn;
  15592. lodash.map = map;
  15593. lodash.mapKeys = mapKeys;
  15594. lodash.mapValues = mapValues;
  15595. lodash.matches = matches;
  15596. lodash.matchesProperty = matchesProperty;
  15597. lodash.memoize = memoize;
  15598. lodash.merge = merge;
  15599. lodash.mergeWith = mergeWith;
  15600. lodash.method = method;
  15601. lodash.methodOf = methodOf;
  15602. lodash.mixin = mixin;
  15603. lodash.negate = negate;
  15604. lodash.nthArg = nthArg;
  15605. lodash.omit = omit;
  15606. lodash.omitBy = omitBy;
  15607. lodash.once = once;
  15608. lodash.orderBy = orderBy;
  15609. lodash.over = over;
  15610. lodash.overArgs = overArgs;
  15611. lodash.overEvery = overEvery;
  15612. lodash.overSome = overSome;
  15613. lodash.partial = partial;
  15614. lodash.partialRight = partialRight;
  15615. lodash.partition = partition;
  15616. lodash.pick = pick;
  15617. lodash.pickBy = pickBy;
  15618. lodash.property = property;
  15619. lodash.propertyOf = propertyOf;
  15620. lodash.pull = pull;
  15621. lodash.pullAll = pullAll;
  15622. lodash.pullAllBy = pullAllBy;
  15623. lodash.pullAllWith = pullAllWith;
  15624. lodash.pullAt = pullAt;
  15625. lodash.range = range;
  15626. lodash.rangeRight = rangeRight;
  15627. lodash.rearg = rearg;
  15628. lodash.reject = reject;
  15629. lodash.remove = remove;
  15630. lodash.rest = rest;
  15631. lodash.reverse = reverse;
  15632. lodash.sampleSize = sampleSize;
  15633. lodash.set = set;
  15634. lodash.setWith = setWith;
  15635. lodash.shuffle = shuffle;
  15636. lodash.slice = slice;
  15637. lodash.sortBy = sortBy;
  15638. lodash.sortedUniq = sortedUniq;
  15639. lodash.sortedUniqBy = sortedUniqBy;
  15640. lodash.split = split;
  15641. lodash.spread = spread;
  15642. lodash.tail = tail;
  15643. lodash.take = take;
  15644. lodash.takeRight = takeRight;
  15645. lodash.takeRightWhile = takeRightWhile;
  15646. lodash.takeWhile = takeWhile;
  15647. lodash.tap = tap;
  15648. lodash.throttle = throttle;
  15649. lodash.thru = thru;
  15650. lodash.toArray = toArray;
  15651. lodash.toPairs = toPairs;
  15652. lodash.toPairsIn = toPairsIn;
  15653. lodash.toPath = toPath;
  15654. lodash.toPlainObject = toPlainObject;
  15655. lodash.transform = transform;
  15656. lodash.unary = unary;
  15657. lodash.union = union;
  15658. lodash.unionBy = unionBy;
  15659. lodash.unionWith = unionWith;
  15660. lodash.uniq = uniq;
  15661. lodash.uniqBy = uniqBy;
  15662. lodash.uniqWith = uniqWith;
  15663. lodash.unset = unset;
  15664. lodash.unzip = unzip;
  15665. lodash.unzipWith = unzipWith;
  15666. lodash.update = update;
  15667. lodash.updateWith = updateWith;
  15668. lodash.values = values;
  15669. lodash.valuesIn = valuesIn;
  15670. lodash.without = without;
  15671. lodash.words = words;
  15672. lodash.wrap = wrap;
  15673. lodash.xor = xor;
  15674. lodash.xorBy = xorBy;
  15675. lodash.xorWith = xorWith;
  15676. lodash.zip = zip;
  15677. lodash.zipObject = zipObject;
  15678. lodash.zipObjectDeep = zipObjectDeep;
  15679. lodash.zipWith = zipWith;
  15680. // Add aliases.
  15681. lodash.entries = toPairs;
  15682. lodash.entriesIn = toPairsIn;
  15683. lodash.extend = assignIn;
  15684. lodash.extendWith = assignInWith;
  15685. // Add methods to `lodash.prototype`.
  15686. mixin(lodash, lodash);
  15687. /*------------------------------------------------------------------------*/
  15688. // Add methods that return unwrapped values in chain sequences.
  15689. lodash.add = add;
  15690. lodash.attempt = attempt;
  15691. lodash.camelCase = camelCase;
  15692. lodash.capitalize = capitalize;
  15693. lodash.ceil = ceil;
  15694. lodash.clamp = clamp;
  15695. lodash.clone = clone;
  15696. lodash.cloneDeep = cloneDeep;
  15697. lodash.cloneDeepWith = cloneDeepWith;
  15698. lodash.cloneWith = cloneWith;
  15699. lodash.conformsTo = conformsTo;
  15700. lodash.deburr = deburr;
  15701. lodash.defaultTo = defaultTo;
  15702. lodash.divide = divide;
  15703. lodash.endsWith = endsWith;
  15704. lodash.eq = eq;
  15705. lodash.escape = escape;
  15706. lodash.escapeRegExp = escapeRegExp;
  15707. lodash.every = every;
  15708. lodash.find = find;
  15709. lodash.findIndex = findIndex;
  15710. lodash.findKey = findKey;
  15711. lodash.findLast = findLast;
  15712. lodash.findLastIndex = findLastIndex;
  15713. lodash.findLastKey = findLastKey;
  15714. lodash.floor = floor;
  15715. lodash.forEach = forEach;
  15716. lodash.forEachRight = forEachRight;
  15717. lodash.forIn = forIn;
  15718. lodash.forInRight = forInRight;
  15719. lodash.forOwn = forOwn;
  15720. lodash.forOwnRight = forOwnRight;
  15721. lodash.get = get;
  15722. lodash.gt = gt;
  15723. lodash.gte = gte;
  15724. lodash.has = has;
  15725. lodash.hasIn = hasIn;
  15726. lodash.head = head;
  15727. lodash.identity = identity;
  15728. lodash.includes = includes;
  15729. lodash.indexOf = indexOf;
  15730. lodash.inRange = inRange;
  15731. lodash.invoke = invoke;
  15732. lodash.isArguments = isArguments;
  15733. lodash.isArray = isArray;
  15734. lodash.isArrayBuffer = isArrayBuffer;
  15735. lodash.isArrayLike = isArrayLike;
  15736. lodash.isArrayLikeObject = isArrayLikeObject;
  15737. lodash.isBoolean = isBoolean;
  15738. lodash.isBuffer = isBuffer;
  15739. lodash.isDate = isDate;
  15740. lodash.isElement = isElement;
  15741. lodash.isEmpty = isEmpty;
  15742. lodash.isEqual = isEqual;
  15743. lodash.isEqualWith = isEqualWith;
  15744. lodash.isError = isError;
  15745. lodash.isFinite = isFinite;
  15746. lodash.isFunction = isFunction;
  15747. lodash.isInteger = isInteger;
  15748. lodash.isLength = isLength;
  15749. lodash.isMap = isMap;
  15750. lodash.isMatch = isMatch;
  15751. lodash.isMatchWith = isMatchWith;
  15752. lodash.isNaN = isNaN;
  15753. lodash.isNative = isNative;
  15754. lodash.isNil = isNil;
  15755. lodash.isNull = isNull;
  15756. lodash.isNumber = isNumber;
  15757. lodash.isObject = isObject;
  15758. lodash.isObjectLike = isObjectLike;
  15759. lodash.isPlainObject = isPlainObject;
  15760. lodash.isRegExp = isRegExp;
  15761. lodash.isSafeInteger = isSafeInteger;
  15762. lodash.isSet = isSet;
  15763. lodash.isString = isString;
  15764. lodash.isSymbol = isSymbol;
  15765. lodash.isTypedArray = isTypedArray;
  15766. lodash.isUndefined = isUndefined;
  15767. lodash.isWeakMap = isWeakMap;
  15768. lodash.isWeakSet = isWeakSet;
  15769. lodash.join = join;
  15770. lodash.kebabCase = kebabCase;
  15771. lodash.last = last;
  15772. lodash.lastIndexOf = lastIndexOf;
  15773. lodash.lowerCase = lowerCase;
  15774. lodash.lowerFirst = lowerFirst;
  15775. lodash.lt = lt;
  15776. lodash.lte = lte;
  15777. lodash.max = max;
  15778. lodash.maxBy = maxBy;
  15779. lodash.mean = mean;
  15780. lodash.meanBy = meanBy;
  15781. lodash.min = min;
  15782. lodash.minBy = minBy;
  15783. lodash.stubArray = stubArray;
  15784. lodash.stubFalse = stubFalse;
  15785. lodash.stubObject = stubObject;
  15786. lodash.stubString = stubString;
  15787. lodash.stubTrue = stubTrue;
  15788. lodash.multiply = multiply;
  15789. lodash.nth = nth;
  15790. lodash.noConflict = noConflict;
  15791. lodash.noop = noop;
  15792. lodash.now = now;
  15793. lodash.pad = pad;
  15794. lodash.padEnd = padEnd;
  15795. lodash.padStart = padStart;
  15796. lodash.parseInt = parseInt;
  15797. lodash.random = random;
  15798. lodash.reduce = reduce;
  15799. lodash.reduceRight = reduceRight;
  15800. lodash.repeat = repeat;
  15801. lodash.replace = replace;
  15802. lodash.result = result;
  15803. lodash.round = round;
  15804. lodash.runInContext = runInContext;
  15805. lodash.sample = sample;
  15806. lodash.size = size;
  15807. lodash.snakeCase = snakeCase;
  15808. lodash.some = some;
  15809. lodash.sortedIndex = sortedIndex;
  15810. lodash.sortedIndexBy = sortedIndexBy;
  15811. lodash.sortedIndexOf = sortedIndexOf;
  15812. lodash.sortedLastIndex = sortedLastIndex;
  15813. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15814. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15815. lodash.startCase = startCase;
  15816. lodash.startsWith = startsWith;
  15817. lodash.subtract = subtract;
  15818. lodash.sum = sum;
  15819. lodash.sumBy = sumBy;
  15820. lodash.template = template;
  15821. lodash.times = times;
  15822. lodash.toFinite = toFinite;
  15823. lodash.toInteger = toInteger;
  15824. lodash.toLength = toLength;
  15825. lodash.toLower = toLower;
  15826. lodash.toNumber = toNumber;
  15827. lodash.toSafeInteger = toSafeInteger;
  15828. lodash.toString = toString;
  15829. lodash.toUpper = toUpper;
  15830. lodash.trim = trim;
  15831. lodash.trimEnd = trimEnd;
  15832. lodash.trimStart = trimStart;
  15833. lodash.truncate = truncate;
  15834. lodash.unescape = unescape;
  15835. lodash.uniqueId = uniqueId;
  15836. lodash.upperCase = upperCase;
  15837. lodash.upperFirst = upperFirst;
  15838. // Add aliases.
  15839. lodash.each = forEach;
  15840. lodash.eachRight = forEachRight;
  15841. lodash.first = head;
  15842. mixin(lodash, (function() {
  15843. var source = {};
  15844. baseForOwn(lodash, function(func, methodName) {
  15845. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15846. source[methodName] = func;
  15847. }
  15848. });
  15849. return source;
  15850. }()), { 'chain': false });
  15851. /*------------------------------------------------------------------------*/
  15852. /**
  15853. * The semantic version number.
  15854. *
  15855. * @static
  15856. * @memberOf _
  15857. * @type {string}
  15858. */
  15859. lodash.VERSION = VERSION;
  15860. // Assign default placeholders.
  15861. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15862. lodash[methodName].placeholder = lodash;
  15863. });
  15864. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15865. arrayEach(['drop', 'take'], function(methodName, index) {
  15866. LazyWrapper.prototype[methodName] = function(n) {
  15867. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15868. var result = (this.__filtered__ && !index)
  15869. ? new LazyWrapper(this)
  15870. : this.clone();
  15871. if (result.__filtered__) {
  15872. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15873. } else {
  15874. result.__views__.push({
  15875. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15876. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15877. });
  15878. }
  15879. return result;
  15880. };
  15881. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15882. return this.reverse()[methodName](n).reverse();
  15883. };
  15884. });
  15885. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15886. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15887. var type = index + 1,
  15888. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15889. LazyWrapper.prototype[methodName] = function(iteratee) {
  15890. var result = this.clone();
  15891. result.__iteratees__.push({
  15892. 'iteratee': getIteratee(iteratee, 3),
  15893. 'type': type
  15894. });
  15895. result.__filtered__ = result.__filtered__ || isFilter;
  15896. return result;
  15897. };
  15898. });
  15899. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15900. arrayEach(['head', 'last'], function(methodName, index) {
  15901. var takeName = 'take' + (index ? 'Right' : '');
  15902. LazyWrapper.prototype[methodName] = function() {
  15903. return this[takeName](1).value()[0];
  15904. };
  15905. });
  15906. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15907. arrayEach(['initial', 'tail'], function(methodName, index) {
  15908. var dropName = 'drop' + (index ? '' : 'Right');
  15909. LazyWrapper.prototype[methodName] = function() {
  15910. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15911. };
  15912. });
  15913. LazyWrapper.prototype.compact = function() {
  15914. return this.filter(identity);
  15915. };
  15916. LazyWrapper.prototype.find = function(predicate) {
  15917. return this.filter(predicate).head();
  15918. };
  15919. LazyWrapper.prototype.findLast = function(predicate) {
  15920. return this.reverse().find(predicate);
  15921. };
  15922. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15923. if (typeof path == 'function') {
  15924. return new LazyWrapper(this);
  15925. }
  15926. return this.map(function(value) {
  15927. return baseInvoke(value, path, args);
  15928. });
  15929. });
  15930. LazyWrapper.prototype.reject = function(predicate) {
  15931. return this.filter(negate(getIteratee(predicate)));
  15932. };
  15933. LazyWrapper.prototype.slice = function(start, end) {
  15934. start = toInteger(start);
  15935. var result = this;
  15936. if (result.__filtered__ && (start > 0 || end < 0)) {
  15937. return new LazyWrapper(result);
  15938. }
  15939. if (start < 0) {
  15940. result = result.takeRight(-start);
  15941. } else if (start) {
  15942. result = result.drop(start);
  15943. }
  15944. if (end !== undefined) {
  15945. end = toInteger(end);
  15946. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15947. }
  15948. return result;
  15949. };
  15950. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15951. return this.reverse().takeWhile(predicate).reverse();
  15952. };
  15953. LazyWrapper.prototype.toArray = function() {
  15954. return this.take(MAX_ARRAY_LENGTH);
  15955. };
  15956. // Add `LazyWrapper` methods to `lodash.prototype`.
  15957. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15958. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15959. isTaker = /^(?:head|last)$/.test(methodName),
  15960. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15961. retUnwrapped = isTaker || /^find/.test(methodName);
  15962. if (!lodashFunc) {
  15963. return;
  15964. }
  15965. lodash.prototype[methodName] = function() {
  15966. var value = this.__wrapped__,
  15967. args = isTaker ? [1] : arguments,
  15968. isLazy = value instanceof LazyWrapper,
  15969. iteratee = args[0],
  15970. useLazy = isLazy || isArray(value);
  15971. var interceptor = function(value) {
  15972. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15973. return (isTaker && chainAll) ? result[0] : result;
  15974. };
  15975. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15976. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15977. isLazy = useLazy = false;
  15978. }
  15979. var chainAll = this.__chain__,
  15980. isHybrid = !!this.__actions__.length,
  15981. isUnwrapped = retUnwrapped && !chainAll,
  15982. onlyLazy = isLazy && !isHybrid;
  15983. if (!retUnwrapped && useLazy) {
  15984. value = onlyLazy ? value : new LazyWrapper(this);
  15985. var result = func.apply(value, args);
  15986. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15987. return new LodashWrapper(result, chainAll);
  15988. }
  15989. if (isUnwrapped && onlyLazy) {
  15990. return func.apply(this, args);
  15991. }
  15992. result = this.thru(interceptor);
  15993. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15994. };
  15995. });
  15996. // Add `Array` methods to `lodash.prototype`.
  15997. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15998. var func = arrayProto[methodName],
  15999. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16000. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16001. lodash.prototype[methodName] = function() {
  16002. var args = arguments;
  16003. if (retUnwrapped && !this.__chain__) {
  16004. var value = this.value();
  16005. return func.apply(isArray(value) ? value : [], args);
  16006. }
  16007. return this[chainName](function(value) {
  16008. return func.apply(isArray(value) ? value : [], args);
  16009. });
  16010. };
  16011. });
  16012. // Map minified method names to their real names.
  16013. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16014. var lodashFunc = lodash[methodName];
  16015. if (lodashFunc) {
  16016. var key = lodashFunc.name + '';
  16017. if (!hasOwnProperty.call(realNames, key)) {
  16018. realNames[key] = [];
  16019. }
  16020. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16021. }
  16022. });
  16023. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16024. 'name': 'wrapper',
  16025. 'func': undefined
  16026. }];
  16027. // Add methods to `LazyWrapper`.
  16028. LazyWrapper.prototype.clone = lazyClone;
  16029. LazyWrapper.prototype.reverse = lazyReverse;
  16030. LazyWrapper.prototype.value = lazyValue;
  16031. // Add chain sequence methods to the `lodash` wrapper.
  16032. lodash.prototype.at = wrapperAt;
  16033. lodash.prototype.chain = wrapperChain;
  16034. lodash.prototype.commit = wrapperCommit;
  16035. lodash.prototype.next = wrapperNext;
  16036. lodash.prototype.plant = wrapperPlant;
  16037. lodash.prototype.reverse = wrapperReverse;
  16038. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16039. // Add lazy aliases.
  16040. lodash.prototype.first = lodash.prototype.head;
  16041. if (symIterator) {
  16042. lodash.prototype[symIterator] = wrapperToIterator;
  16043. }
  16044. return lodash;
  16045. });
  16046. /*--------------------------------------------------------------------------*/
  16047. // Export lodash.
  16048. var _ = runInContext();
  16049. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16050. if (true) {
  16051. // Expose Lodash on the global object to prevent errors when Lodash is
  16052. // loaded by a script tag in the presence of an AMD loader.
  16053. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16054. // Use `_.noConflict` to remove Lodash from the global object.
  16055. root._ = _;
  16056. // Define as an anonymous module so, through path mapping, it can be
  16057. // referenced as the "underscore" module.
  16058. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  16059. return _;
  16060. }).call(exports, __webpack_require__, exports, module),
  16061. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  16062. }
  16063. // Check for `exports` after `define` in case a build optimizer adds it.
  16064. else {}
  16065. }.call(this));
  16066. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module)))
  16067. /***/ }),
  16068. /***/ "./node_modules/webpack/buildin/module.js":
  16069. /*!***********************************!*\
  16070. !*** (webpack)/buildin/module.js ***!
  16071. \***********************************/
  16072. /*! no static exports found */
  16073. /*! all exports used */
  16074. /***/ (function(module, exports) {
  16075. module.exports = function(module) {
  16076. if (!module.webpackPolyfill) {
  16077. module.deprecate = function() {};
  16078. module.paths = [];
  16079. // module.parent = undefined by default
  16080. if (!module.children) module.children = [];
  16081. Object.defineProperty(module, "loaded", {
  16082. enumerable: true,
  16083. get: function() {
  16084. return module.l;
  16085. }
  16086. });
  16087. Object.defineProperty(module, "id", {
  16088. enumerable: true,
  16089. get: function() {
  16090. return module.i;
  16091. }
  16092. });
  16093. module.webpackPolyfill = 1;
  16094. }
  16095. return module;
  16096. };
  16097. /***/ })
  16098. }]);