lodash.js 527 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.17.11';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function';
  19. /** Used to stand-in for `undefined` hash values. */
  20. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21. /** Used as the maximum memoize cache size. */
  22. var MAX_MEMOIZE_SIZE = 500;
  23. /** Used as the internal argument placeholder. */
  24. var PLACEHOLDER = '__lodash_placeholder__';
  25. /** Used to compose bitmasks for cloning. */
  26. var CLONE_DEEP_FLAG = 1,
  27. CLONE_FLAT_FLAG = 2,
  28. CLONE_SYMBOLS_FLAG = 4;
  29. /** Used to compose bitmasks for value comparisons. */
  30. var COMPARE_PARTIAL_FLAG = 1,
  31. COMPARE_UNORDERED_FLAG = 2;
  32. /** Used to compose bitmasks for function metadata. */
  33. var WRAP_BIND_FLAG = 1,
  34. WRAP_BIND_KEY_FLAG = 2,
  35. WRAP_CURRY_BOUND_FLAG = 4,
  36. WRAP_CURRY_FLAG = 8,
  37. WRAP_CURRY_RIGHT_FLAG = 16,
  38. WRAP_PARTIAL_FLAG = 32,
  39. WRAP_PARTIAL_RIGHT_FLAG = 64,
  40. WRAP_ARY_FLAG = 128,
  41. WRAP_REARG_FLAG = 256,
  42. WRAP_FLIP_FLAG = 512;
  43. /** Used as default options for `_.truncate`. */
  44. var DEFAULT_TRUNC_LENGTH = 30,
  45. DEFAULT_TRUNC_OMISSION = '...';
  46. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  47. var HOT_COUNT = 800,
  48. HOT_SPAN = 16;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for various `Number` constants. */
  54. var INFINITY = 1 / 0,
  55. MAX_SAFE_INTEGER = 9007199254740991,
  56. MAX_INTEGER = 1.7976931348623157e+308,
  57. NAN = 0 / 0;
  58. /** Used as references for the maximum length and index of an array. */
  59. var MAX_ARRAY_LENGTH = 4294967295,
  60. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  61. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  62. /** Used to associate wrap methods with their bit flags. */
  63. var wrapFlags = [
  64. ['ary', WRAP_ARY_FLAG],
  65. ['bind', WRAP_BIND_FLAG],
  66. ['bindKey', WRAP_BIND_KEY_FLAG],
  67. ['curry', WRAP_CURRY_FLAG],
  68. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  69. ['flip', WRAP_FLIP_FLAG],
  70. ['partial', WRAP_PARTIAL_FLAG],
  71. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  72. ['rearg', WRAP_REARG_FLAG]
  73. ];
  74. /** `Object#toString` result references. */
  75. var argsTag = '[object Arguments]',
  76. arrayTag = '[object Array]',
  77. asyncTag = '[object AsyncFunction]',
  78. boolTag = '[object Boolean]',
  79. dateTag = '[object Date]',
  80. domExcTag = '[object DOMException]',
  81. errorTag = '[object Error]',
  82. funcTag = '[object Function]',
  83. genTag = '[object GeneratorFunction]',
  84. mapTag = '[object Map]',
  85. numberTag = '[object Number]',
  86. nullTag = '[object Null]',
  87. objectTag = '[object Object]',
  88. promiseTag = '[object Promise]',
  89. proxyTag = '[object Proxy]',
  90. regexpTag = '[object RegExp]',
  91. setTag = '[object Set]',
  92. stringTag = '[object String]',
  93. symbolTag = '[object Symbol]',
  94. undefinedTag = '[object Undefined]',
  95. weakMapTag = '[object WeakMap]',
  96. weakSetTag = '[object WeakSet]';
  97. var arrayBufferTag = '[object ArrayBuffer]',
  98. dataViewTag = '[object DataView]',
  99. float32Tag = '[object Float32Array]',
  100. float64Tag = '[object Float64Array]',
  101. int8Tag = '[object Int8Array]',
  102. int16Tag = '[object Int16Array]',
  103. int32Tag = '[object Int32Array]',
  104. uint8Tag = '[object Uint8Array]',
  105. uint8ClampedTag = '[object Uint8ClampedArray]',
  106. uint16Tag = '[object Uint16Array]',
  107. uint32Tag = '[object Uint32Array]';
  108. /** Used to match empty string literals in compiled template source. */
  109. var reEmptyStringLeading = /\b__p \+= '';/g,
  110. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  111. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  112. /** Used to match HTML entities and HTML characters. */
  113. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  114. reUnescapedHtml = /[&<>"']/g,
  115. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  116. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  117. /** Used to match template delimiters. */
  118. var reEscape = /<%-([\s\S]+?)%>/g,
  119. reEvaluate = /<%([\s\S]+?)%>/g,
  120. reInterpolate = /<%=([\s\S]+?)%>/g;
  121. /** Used to match property names within property paths. */
  122. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  123. reIsPlainProp = /^\w*$/,
  124. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  125. /**
  126. * Used to match `RegExp`
  127. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  128. */
  129. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  130. reHasRegExpChar = RegExp(reRegExpChar.source);
  131. /** Used to match leading and trailing whitespace. */
  132. var reTrim = /^\s+|\s+$/g,
  133. reTrimStart = /^\s+/,
  134. reTrimEnd = /\s+$/;
  135. /** Used to match wrap detail comments. */
  136. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  137. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  138. reSplitDetails = /,? & /;
  139. /** Used to match words composed of alphanumeric characters. */
  140. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  141. /** Used to match backslashes in property paths. */
  142. var reEscapeChar = /\\(\\)?/g;
  143. /**
  144. * Used to match
  145. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  146. */
  147. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  148. /** Used to match `RegExp` flags from their coerced string values. */
  149. var reFlags = /\w*$/;
  150. /** Used to detect bad signed hexadecimal string values. */
  151. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  152. /** Used to detect binary string values. */
  153. var reIsBinary = /^0b[01]+$/i;
  154. /** Used to detect host constructors (Safari). */
  155. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  156. /** Used to detect octal string values. */
  157. var reIsOctal = /^0o[0-7]+$/i;
  158. /** Used to detect unsigned integer values. */
  159. var reIsUint = /^(?:0|[1-9]\d*)$/;
  160. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  161. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  162. /** Used to ensure capturing order of template delimiters. */
  163. var reNoMatch = /($^)/;
  164. /** Used to match unescaped characters in compiled string literals. */
  165. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  166. /** Used to compose unicode character classes. */
  167. var rsAstralRange = '\\ud800-\\udfff',
  168. rsComboMarksRange = '\\u0300-\\u036f',
  169. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  170. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  171. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  172. rsDingbatRange = '\\u2700-\\u27bf',
  173. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  174. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  175. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  176. rsPunctuationRange = '\\u2000-\\u206f',
  177. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  178. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  179. rsVarRange = '\\ufe0e\\ufe0f',
  180. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  181. /** Used to compose unicode capture groups. */
  182. var rsApos = "['\u2019]",
  183. rsAstral = '[' + rsAstralRange + ']',
  184. rsBreak = '[' + rsBreakRange + ']',
  185. rsCombo = '[' + rsComboRange + ']',
  186. rsDigits = '\\d+',
  187. rsDingbat = '[' + rsDingbatRange + ']',
  188. rsLower = '[' + rsLowerRange + ']',
  189. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  190. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  191. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  192. rsNonAstral = '[^' + rsAstralRange + ']',
  193. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  194. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  195. rsUpper = '[' + rsUpperRange + ']',
  196. rsZWJ = '\\u200d';
  197. /** Used to compose unicode regexes. */
  198. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  199. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  200. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  201. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  202. reOptMod = rsModifier + '?',
  203. rsOptVar = '[' + rsVarRange + ']?',
  204. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  205. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  206. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  207. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  208. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  209. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  210. /** Used to match apostrophes. */
  211. var reApos = RegExp(rsApos, 'g');
  212. /**
  213. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  214. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  215. */
  216. var reComboMark = RegExp(rsCombo, 'g');
  217. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  218. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  219. /** Used to match complex or compound words. */
  220. var reUnicodeWord = RegExp([
  221. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  222. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  223. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  224. rsUpper + '+' + rsOptContrUpper,
  225. rsOrdUpper,
  226. rsOrdLower,
  227. rsDigits,
  228. rsEmoji
  229. ].join('|'), 'g');
  230. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  231. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  232. /** Used to detect strings that need a more robust regexp to match words. */
  233. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  234. /** Used to assign default `context` object properties. */
  235. var contextProps = [
  236. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  237. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  238. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  239. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  240. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  241. ];
  242. /** Used to make template sourceURLs easier to identify. */
  243. var templateCounter = -1;
  244. /** Used to identify `toStringTag` values of typed arrays. */
  245. var typedArrayTags = {};
  246. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  247. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  248. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  249. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  250. typedArrayTags[uint32Tag] = true;
  251. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  252. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  253. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  254. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  255. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  256. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  257. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  258. typedArrayTags[weakMapTag] = false;
  259. /** Used to identify `toStringTag` values supported by `_.clone`. */
  260. var cloneableTags = {};
  261. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  262. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  263. cloneableTags[boolTag] = cloneableTags[dateTag] =
  264. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  265. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  266. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  267. cloneableTags[numberTag] = cloneableTags[objectTag] =
  268. cloneableTags[regexpTag] = cloneableTags[setTag] =
  269. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  270. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  271. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  272. cloneableTags[errorTag] = cloneableTags[funcTag] =
  273. cloneableTags[weakMapTag] = false;
  274. /** Used to map Latin Unicode letters to basic Latin letters. */
  275. var deburredLetters = {
  276. // Latin-1 Supplement block.
  277. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  278. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  279. '\xc7': 'C', '\xe7': 'c',
  280. '\xd0': 'D', '\xf0': 'd',
  281. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  282. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  283. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  284. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  285. '\xd1': 'N', '\xf1': 'n',
  286. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  287. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  288. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  289. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  290. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  291. '\xc6': 'Ae', '\xe6': 'ae',
  292. '\xde': 'Th', '\xfe': 'th',
  293. '\xdf': 'ss',
  294. // Latin Extended-A block.
  295. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  296. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  297. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  298. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  299. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  300. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  301. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  302. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  303. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  304. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  305. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  306. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  307. '\u0134': 'J', '\u0135': 'j',
  308. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  309. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  310. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  311. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  312. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  313. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  314. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  315. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  316. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  317. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  318. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  319. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  320. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  321. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  322. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  323. '\u0174': 'W', '\u0175': 'w',
  324. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  325. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  326. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  327. '\u0132': 'IJ', '\u0133': 'ij',
  328. '\u0152': 'Oe', '\u0153': 'oe',
  329. '\u0149': "'n", '\u017f': 's'
  330. };
  331. /** Used to map characters to HTML entities. */
  332. var htmlEscapes = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '"': '&quot;',
  337. "'": '&#39;'
  338. };
  339. /** Used to map HTML entities to characters. */
  340. var htmlUnescapes = {
  341. '&amp;': '&',
  342. '&lt;': '<',
  343. '&gt;': '>',
  344. '&quot;': '"',
  345. '&#39;': "'"
  346. };
  347. /** Used to escape characters for inclusion in compiled string literals. */
  348. var stringEscapes = {
  349. '\\': '\\',
  350. "'": "'",
  351. '\n': 'n',
  352. '\r': 'r',
  353. '\u2028': 'u2028',
  354. '\u2029': 'u2029'
  355. };
  356. /** Built-in method references without a dependency on `root`. */
  357. var freeParseFloat = parseFloat,
  358. freeParseInt = parseInt;
  359. /** Detect free variable `global` from Node.js. */
  360. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  361. /** Detect free variable `self`. */
  362. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  363. /** Used as a reference to the global object. */
  364. var root = freeGlobal || freeSelf || Function('return this')();
  365. /** Detect free variable `exports`. */
  366. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  367. /** Detect free variable `module`. */
  368. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  369. /** Detect the popular CommonJS extension `module.exports`. */
  370. var moduleExports = freeModule && freeModule.exports === freeExports;
  371. /** Detect free variable `process` from Node.js. */
  372. var freeProcess = moduleExports && freeGlobal.process;
  373. /** Used to access faster Node.js helpers. */
  374. var nodeUtil = (function() {
  375. try {
  376. // Use `util.types` for Node.js 10+.
  377. var types = freeModule && freeModule.require && freeModule.require('util').types;
  378. if (types) {
  379. return types;
  380. }
  381. // Legacy `process.binding('util')` for Node.js < 10.
  382. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  383. } catch (e) {}
  384. }());
  385. /* Node.js helper references. */
  386. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  387. nodeIsDate = nodeUtil && nodeUtil.isDate,
  388. nodeIsMap = nodeUtil && nodeUtil.isMap,
  389. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  390. nodeIsSet = nodeUtil && nodeUtil.isSet,
  391. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  392. /*--------------------------------------------------------------------------*/
  393. /**
  394. * A faster alternative to `Function#apply`, this function invokes `func`
  395. * with the `this` binding of `thisArg` and the arguments of `args`.
  396. *
  397. * @private
  398. * @param {Function} func The function to invoke.
  399. * @param {*} thisArg The `this` binding of `func`.
  400. * @param {Array} args The arguments to invoke `func` with.
  401. * @returns {*} Returns the result of `func`.
  402. */
  403. function apply(func, thisArg, args) {
  404. switch (args.length) {
  405. case 0: return func.call(thisArg);
  406. case 1: return func.call(thisArg, args[0]);
  407. case 2: return func.call(thisArg, args[0], args[1]);
  408. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  409. }
  410. return func.apply(thisArg, args);
  411. }
  412. /**
  413. * A specialized version of `baseAggregator` for arrays.
  414. *
  415. * @private
  416. * @param {Array} [array] The array to iterate over.
  417. * @param {Function} setter The function to set `accumulator` values.
  418. * @param {Function} iteratee The iteratee to transform keys.
  419. * @param {Object} accumulator The initial aggregated object.
  420. * @returns {Function} Returns `accumulator`.
  421. */
  422. function arrayAggregator(array, setter, iteratee, accumulator) {
  423. var index = -1,
  424. length = array == null ? 0 : array.length;
  425. while (++index < length) {
  426. var value = array[index];
  427. setter(accumulator, value, iteratee(value), array);
  428. }
  429. return accumulator;
  430. }
  431. /**
  432. * A specialized version of `_.forEach` for arrays without support for
  433. * iteratee shorthands.
  434. *
  435. * @private
  436. * @param {Array} [array] The array to iterate over.
  437. * @param {Function} iteratee The function invoked per iteration.
  438. * @returns {Array} Returns `array`.
  439. */
  440. function arrayEach(array, iteratee) {
  441. var index = -1,
  442. length = array == null ? 0 : array.length;
  443. while (++index < length) {
  444. if (iteratee(array[index], index, array) === false) {
  445. break;
  446. }
  447. }
  448. return array;
  449. }
  450. /**
  451. * A specialized version of `_.forEachRight` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEachRight(array, iteratee) {
  460. var length = array == null ? 0 : array.length;
  461. while (length--) {
  462. if (iteratee(array[length], length, array) === false) {
  463. break;
  464. }
  465. }
  466. return array;
  467. }
  468. /**
  469. * A specialized version of `_.every` for arrays without support for
  470. * iteratee shorthands.
  471. *
  472. * @private
  473. * @param {Array} [array] The array to iterate over.
  474. * @param {Function} predicate The function invoked per iteration.
  475. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  476. * else `false`.
  477. */
  478. function arrayEvery(array, predicate) {
  479. var index = -1,
  480. length = array == null ? 0 : array.length;
  481. while (++index < length) {
  482. if (!predicate(array[index], index, array)) {
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. /**
  489. * A specialized version of `_.filter` for arrays without support for
  490. * iteratee shorthands.
  491. *
  492. * @private
  493. * @param {Array} [array] The array to iterate over.
  494. * @param {Function} predicate The function invoked per iteration.
  495. * @returns {Array} Returns the new filtered array.
  496. */
  497. function arrayFilter(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length,
  500. resIndex = 0,
  501. result = [];
  502. while (++index < length) {
  503. var value = array[index];
  504. if (predicate(value, index, array)) {
  505. result[resIndex++] = value;
  506. }
  507. }
  508. return result;
  509. }
  510. /**
  511. * A specialized version of `_.includes` for arrays without support for
  512. * specifying an index to search from.
  513. *
  514. * @private
  515. * @param {Array} [array] The array to inspect.
  516. * @param {*} target The value to search for.
  517. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  518. */
  519. function arrayIncludes(array, value) {
  520. var length = array == null ? 0 : array.length;
  521. return !!length && baseIndexOf(array, value, 0) > -1;
  522. }
  523. /**
  524. * This function is like `arrayIncludes` except that it accepts a comparator.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @param {Function} comparator The comparator invoked per element.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludesWith(array, value, comparator) {
  533. var index = -1,
  534. length = array == null ? 0 : array.length;
  535. while (++index < length) {
  536. if (comparator(value, array[index])) {
  537. return true;
  538. }
  539. }
  540. return false;
  541. }
  542. /**
  543. * A specialized version of `_.map` for arrays without support for iteratee
  544. * shorthands.
  545. *
  546. * @private
  547. * @param {Array} [array] The array to iterate over.
  548. * @param {Function} iteratee The function invoked per iteration.
  549. * @returns {Array} Returns the new mapped array.
  550. */
  551. function arrayMap(array, iteratee) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length,
  554. result = Array(length);
  555. while (++index < length) {
  556. result[index] = iteratee(array[index], index, array);
  557. }
  558. return result;
  559. }
  560. /**
  561. * Appends the elements of `values` to `array`.
  562. *
  563. * @private
  564. * @param {Array} array The array to modify.
  565. * @param {Array} values The values to append.
  566. * @returns {Array} Returns `array`.
  567. */
  568. function arrayPush(array, values) {
  569. var index = -1,
  570. length = values.length,
  571. offset = array.length;
  572. while (++index < length) {
  573. array[offset + index] = values[index];
  574. }
  575. return array;
  576. }
  577. /**
  578. * A specialized version of `_.reduce` for arrays without support for
  579. * iteratee shorthands.
  580. *
  581. * @private
  582. * @param {Array} [array] The array to iterate over.
  583. * @param {Function} iteratee The function invoked per iteration.
  584. * @param {*} [accumulator] The initial value.
  585. * @param {boolean} [initAccum] Specify using the first element of `array` as
  586. * the initial value.
  587. * @returns {*} Returns the accumulated value.
  588. */
  589. function arrayReduce(array, iteratee, accumulator, initAccum) {
  590. var index = -1,
  591. length = array == null ? 0 : array.length;
  592. if (initAccum && length) {
  593. accumulator = array[++index];
  594. }
  595. while (++index < length) {
  596. accumulator = iteratee(accumulator, array[index], index, array);
  597. }
  598. return accumulator;
  599. }
  600. /**
  601. * A specialized version of `_.reduceRight` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} iteratee The function invoked per iteration.
  607. * @param {*} [accumulator] The initial value.
  608. * @param {boolean} [initAccum] Specify using the last element of `array` as
  609. * the initial value.
  610. * @returns {*} Returns the accumulated value.
  611. */
  612. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  613. var length = array == null ? 0 : array.length;
  614. if (initAccum && length) {
  615. accumulator = array[--length];
  616. }
  617. while (length--) {
  618. accumulator = iteratee(accumulator, array[length], length, array);
  619. }
  620. return accumulator;
  621. }
  622. /**
  623. * A specialized version of `_.some` for arrays without support for iteratee
  624. * shorthands.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to iterate over.
  628. * @param {Function} predicate The function invoked per iteration.
  629. * @returns {boolean} Returns `true` if any element passes the predicate check,
  630. * else `false`.
  631. */
  632. function arraySome(array, predicate) {
  633. var index = -1,
  634. length = array == null ? 0 : array.length;
  635. while (++index < length) {
  636. if (predicate(array[index], index, array)) {
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642. /**
  643. * Gets the size of an ASCII `string`.
  644. *
  645. * @private
  646. * @param {string} string The string inspect.
  647. * @returns {number} Returns the string size.
  648. */
  649. var asciiSize = baseProperty('length');
  650. /**
  651. * Converts an ASCII `string` to an array.
  652. *
  653. * @private
  654. * @param {string} string The string to convert.
  655. * @returns {Array} Returns the converted array.
  656. */
  657. function asciiToArray(string) {
  658. return string.split('');
  659. }
  660. /**
  661. * Splits an ASCII `string` into an array of its words.
  662. *
  663. * @private
  664. * @param {string} The string to inspect.
  665. * @returns {Array} Returns the words of `string`.
  666. */
  667. function asciiWords(string) {
  668. return string.match(reAsciiWord) || [];
  669. }
  670. /**
  671. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  672. * without support for iteratee shorthands, which iterates over `collection`
  673. * using `eachFunc`.
  674. *
  675. * @private
  676. * @param {Array|Object} collection The collection to inspect.
  677. * @param {Function} predicate The function invoked per iteration.
  678. * @param {Function} eachFunc The function to iterate over `collection`.
  679. * @returns {*} Returns the found element or its key, else `undefined`.
  680. */
  681. function baseFindKey(collection, predicate, eachFunc) {
  682. var result;
  683. eachFunc(collection, function(value, key, collection) {
  684. if (predicate(value, key, collection)) {
  685. result = key;
  686. return false;
  687. }
  688. });
  689. return result;
  690. }
  691. /**
  692. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  693. * support for iteratee shorthands.
  694. *
  695. * @private
  696. * @param {Array} array The array to inspect.
  697. * @param {Function} predicate The function invoked per iteration.
  698. * @param {number} fromIndex The index to search from.
  699. * @param {boolean} [fromRight] Specify iterating from right to left.
  700. * @returns {number} Returns the index of the matched value, else `-1`.
  701. */
  702. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  703. var length = array.length,
  704. index = fromIndex + (fromRight ? 1 : -1);
  705. while ((fromRight ? index-- : ++index < length)) {
  706. if (predicate(array[index], index, array)) {
  707. return index;
  708. }
  709. }
  710. return -1;
  711. }
  712. /**
  713. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} value The value to search for.
  718. * @param {number} fromIndex The index to search from.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseIndexOf(array, value, fromIndex) {
  722. return value === value
  723. ? strictIndexOf(array, value, fromIndex)
  724. : baseFindIndex(array, baseIsNaN, fromIndex);
  725. }
  726. /**
  727. * This function is like `baseIndexOf` except that it accepts a comparator.
  728. *
  729. * @private
  730. * @param {Array} array The array to inspect.
  731. * @param {*} value The value to search for.
  732. * @param {number} fromIndex The index to search from.
  733. * @param {Function} comparator The comparator invoked per element.
  734. * @returns {number} Returns the index of the matched value, else `-1`.
  735. */
  736. function baseIndexOfWith(array, value, fromIndex, comparator) {
  737. var index = fromIndex - 1,
  738. length = array.length;
  739. while (++index < length) {
  740. if (comparator(array[index], value)) {
  741. return index;
  742. }
  743. }
  744. return -1;
  745. }
  746. /**
  747. * The base implementation of `_.isNaN` without support for number objects.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  752. */
  753. function baseIsNaN(value) {
  754. return value !== value;
  755. }
  756. /**
  757. * The base implementation of `_.mean` and `_.meanBy` without support for
  758. * iteratee shorthands.
  759. *
  760. * @private
  761. * @param {Array} array The array to iterate over.
  762. * @param {Function} iteratee The function invoked per iteration.
  763. * @returns {number} Returns the mean.
  764. */
  765. function baseMean(array, iteratee) {
  766. var length = array == null ? 0 : array.length;
  767. return length ? (baseSum(array, iteratee) / length) : NAN;
  768. }
  769. /**
  770. * The base implementation of `_.property` without support for deep paths.
  771. *
  772. * @private
  773. * @param {string} key The key of the property to get.
  774. * @returns {Function} Returns the new accessor function.
  775. */
  776. function baseProperty(key) {
  777. return function(object) {
  778. return object == null ? undefined : object[key];
  779. };
  780. }
  781. /**
  782. * The base implementation of `_.propertyOf` without support for deep paths.
  783. *
  784. * @private
  785. * @param {Object} object The object to query.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function basePropertyOf(object) {
  789. return function(key) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  795. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  796. *
  797. * @private
  798. * @param {Array|Object} collection The collection to iterate over.
  799. * @param {Function} iteratee The function invoked per iteration.
  800. * @param {*} accumulator The initial value.
  801. * @param {boolean} initAccum Specify using the first or last element of
  802. * `collection` as the initial value.
  803. * @param {Function} eachFunc The function to iterate over `collection`.
  804. * @returns {*} Returns the accumulated value.
  805. */
  806. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  807. eachFunc(collection, function(value, index, collection) {
  808. accumulator = initAccum
  809. ? (initAccum = false, value)
  810. : iteratee(accumulator, value, index, collection);
  811. });
  812. return accumulator;
  813. }
  814. /**
  815. * The base implementation of `_.sortBy` which uses `comparer` to define the
  816. * sort order of `array` and replaces criteria objects with their corresponding
  817. * values.
  818. *
  819. * @private
  820. * @param {Array} array The array to sort.
  821. * @param {Function} comparer The function to define sort order.
  822. * @returns {Array} Returns `array`.
  823. */
  824. function baseSortBy(array, comparer) {
  825. var length = array.length;
  826. array.sort(comparer);
  827. while (length--) {
  828. array[length] = array[length].value;
  829. }
  830. return array;
  831. }
  832. /**
  833. * The base implementation of `_.sum` and `_.sumBy` without support for
  834. * iteratee shorthands.
  835. *
  836. * @private
  837. * @param {Array} array The array to iterate over.
  838. * @param {Function} iteratee The function invoked per iteration.
  839. * @returns {number} Returns the sum.
  840. */
  841. function baseSum(array, iteratee) {
  842. var result,
  843. index = -1,
  844. length = array.length;
  845. while (++index < length) {
  846. var current = iteratee(array[index]);
  847. if (current !== undefined) {
  848. result = result === undefined ? current : (result + current);
  849. }
  850. }
  851. return result;
  852. }
  853. /**
  854. * The base implementation of `_.times` without support for iteratee shorthands
  855. * or max array length checks.
  856. *
  857. * @private
  858. * @param {number} n The number of times to invoke `iteratee`.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {Array} Returns the array of results.
  861. */
  862. function baseTimes(n, iteratee) {
  863. var index = -1,
  864. result = Array(n);
  865. while (++index < n) {
  866. result[index] = iteratee(index);
  867. }
  868. return result;
  869. }
  870. /**
  871. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  872. * of key-value pairs for `object` corresponding to the property names of `props`.
  873. *
  874. * @private
  875. * @param {Object} object The object to query.
  876. * @param {Array} props The property names to get values for.
  877. * @returns {Object} Returns the key-value pairs.
  878. */
  879. function baseToPairs(object, props) {
  880. return arrayMap(props, function(key) {
  881. return [key, object[key]];
  882. });
  883. }
  884. /**
  885. * The base implementation of `_.unary` without support for storing metadata.
  886. *
  887. * @private
  888. * @param {Function} func The function to cap arguments for.
  889. * @returns {Function} Returns the new capped function.
  890. */
  891. function baseUnary(func) {
  892. return function(value) {
  893. return func(value);
  894. };
  895. }
  896. /**
  897. * The base implementation of `_.values` and `_.valuesIn` which creates an
  898. * array of `object` property values corresponding to the property names
  899. * of `props`.
  900. *
  901. * @private
  902. * @param {Object} object The object to query.
  903. * @param {Array} props The property names to get values for.
  904. * @returns {Object} Returns the array of property values.
  905. */
  906. function baseValues(object, props) {
  907. return arrayMap(props, function(key) {
  908. return object[key];
  909. });
  910. }
  911. /**
  912. * Checks if a `cache` value for `key` exists.
  913. *
  914. * @private
  915. * @param {Object} cache The cache to query.
  916. * @param {string} key The key of the entry to check.
  917. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  918. */
  919. function cacheHas(cache, key) {
  920. return cache.has(key);
  921. }
  922. /**
  923. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  924. * that is not found in the character symbols.
  925. *
  926. * @private
  927. * @param {Array} strSymbols The string symbols to inspect.
  928. * @param {Array} chrSymbols The character symbols to find.
  929. * @returns {number} Returns the index of the first unmatched string symbol.
  930. */
  931. function charsStartIndex(strSymbols, chrSymbols) {
  932. var index = -1,
  933. length = strSymbols.length;
  934. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  935. return index;
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the last unmatched string symbol.
  945. */
  946. function charsEndIndex(strSymbols, chrSymbols) {
  947. var index = strSymbols.length;
  948. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  949. return index;
  950. }
  951. /**
  952. * Gets the number of `placeholder` occurrences in `array`.
  953. *
  954. * @private
  955. * @param {Array} array The array to inspect.
  956. * @param {*} placeholder The placeholder to search for.
  957. * @returns {number} Returns the placeholder count.
  958. */
  959. function countHolders(array, placeholder) {
  960. var length = array.length,
  961. result = 0;
  962. while (length--) {
  963. if (array[length] === placeholder) {
  964. ++result;
  965. }
  966. }
  967. return result;
  968. }
  969. /**
  970. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  971. * letters to basic Latin letters.
  972. *
  973. * @private
  974. * @param {string} letter The matched letter to deburr.
  975. * @returns {string} Returns the deburred letter.
  976. */
  977. var deburrLetter = basePropertyOf(deburredLetters);
  978. /**
  979. * Used by `_.escape` to convert characters to HTML entities.
  980. *
  981. * @private
  982. * @param {string} chr The matched character to escape.
  983. * @returns {string} Returns the escaped character.
  984. */
  985. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  986. /**
  987. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. function escapeStringChar(chr) {
  994. return '\\' + stringEscapes[chr];
  995. }
  996. /**
  997. * Gets the value at `key` of `object`.
  998. *
  999. * @private
  1000. * @param {Object} [object] The object to query.
  1001. * @param {string} key The key of the property to get.
  1002. * @returns {*} Returns the property value.
  1003. */
  1004. function getValue(object, key) {
  1005. return object == null ? undefined : object[key];
  1006. }
  1007. /**
  1008. * Checks if `string` contains Unicode symbols.
  1009. *
  1010. * @private
  1011. * @param {string} string The string to inspect.
  1012. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1013. */
  1014. function hasUnicode(string) {
  1015. return reHasUnicode.test(string);
  1016. }
  1017. /**
  1018. * Checks if `string` contains a word composed of Unicode symbols.
  1019. *
  1020. * @private
  1021. * @param {string} string The string to inspect.
  1022. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1023. */
  1024. function hasUnicodeWord(string) {
  1025. return reHasUnicodeWord.test(string);
  1026. }
  1027. /**
  1028. * Converts `iterator` to an array.
  1029. *
  1030. * @private
  1031. * @param {Object} iterator The iterator to convert.
  1032. * @returns {Array} Returns the converted array.
  1033. */
  1034. function iteratorToArray(iterator) {
  1035. var data,
  1036. result = [];
  1037. while (!(data = iterator.next()).done) {
  1038. result.push(data.value);
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. * Converts `map` to its key-value pairs.
  1044. *
  1045. * @private
  1046. * @param {Object} map The map to convert.
  1047. * @returns {Array} Returns the key-value pairs.
  1048. */
  1049. function mapToArray(map) {
  1050. var index = -1,
  1051. result = Array(map.size);
  1052. map.forEach(function(value, key) {
  1053. result[++index] = [key, value];
  1054. });
  1055. return result;
  1056. }
  1057. /**
  1058. * Creates a unary function that invokes `func` with its argument transformed.
  1059. *
  1060. * @private
  1061. * @param {Function} func The function to wrap.
  1062. * @param {Function} transform The argument transform.
  1063. * @returns {Function} Returns the new function.
  1064. */
  1065. function overArg(func, transform) {
  1066. return function(arg) {
  1067. return func(transform(arg));
  1068. };
  1069. }
  1070. /**
  1071. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1072. * and returns an array of their indexes.
  1073. *
  1074. * @private
  1075. * @param {Array} array The array to modify.
  1076. * @param {*} placeholder The placeholder to replace.
  1077. * @returns {Array} Returns the new array of placeholder indexes.
  1078. */
  1079. function replaceHolders(array, placeholder) {
  1080. var index = -1,
  1081. length = array.length,
  1082. resIndex = 0,
  1083. result = [];
  1084. while (++index < length) {
  1085. var value = array[index];
  1086. if (value === placeholder || value === PLACEHOLDER) {
  1087. array[index] = PLACEHOLDER;
  1088. result[resIndex++] = index;
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * Converts `set` to an array of its values.
  1095. *
  1096. * @private
  1097. * @param {Object} set The set to convert.
  1098. * @returns {Array} Returns the values.
  1099. */
  1100. function setToArray(set) {
  1101. var index = -1,
  1102. result = Array(set.size);
  1103. set.forEach(function(value) {
  1104. result[++index] = value;
  1105. });
  1106. return result;
  1107. }
  1108. /**
  1109. * Converts `set` to its value-value pairs.
  1110. *
  1111. * @private
  1112. * @param {Object} set The set to convert.
  1113. * @returns {Array} Returns the value-value pairs.
  1114. */
  1115. function setToPairs(set) {
  1116. var index = -1,
  1117. result = Array(set.size);
  1118. set.forEach(function(value) {
  1119. result[++index] = [value, value];
  1120. });
  1121. return result;
  1122. }
  1123. /**
  1124. * A specialized version of `_.indexOf` which performs strict equality
  1125. * comparisons of values, i.e. `===`.
  1126. *
  1127. * @private
  1128. * @param {Array} array The array to inspect.
  1129. * @param {*} value The value to search for.
  1130. * @param {number} fromIndex The index to search from.
  1131. * @returns {number} Returns the index of the matched value, else `-1`.
  1132. */
  1133. function strictIndexOf(array, value, fromIndex) {
  1134. var index = fromIndex - 1,
  1135. length = array.length;
  1136. while (++index < length) {
  1137. if (array[index] === value) {
  1138. return index;
  1139. }
  1140. }
  1141. return -1;
  1142. }
  1143. /**
  1144. * A specialized version of `_.lastIndexOf` which performs strict equality
  1145. * comparisons of values, i.e. `===`.
  1146. *
  1147. * @private
  1148. * @param {Array} array The array to inspect.
  1149. * @param {*} value The value to search for.
  1150. * @param {number} fromIndex The index to search from.
  1151. * @returns {number} Returns the index of the matched value, else `-1`.
  1152. */
  1153. function strictLastIndexOf(array, value, fromIndex) {
  1154. var index = fromIndex + 1;
  1155. while (index--) {
  1156. if (array[index] === value) {
  1157. return index;
  1158. }
  1159. }
  1160. return index;
  1161. }
  1162. /**
  1163. * Gets the number of symbols in `string`.
  1164. *
  1165. * @private
  1166. * @param {string} string The string to inspect.
  1167. * @returns {number} Returns the string size.
  1168. */
  1169. function stringSize(string) {
  1170. return hasUnicode(string)
  1171. ? unicodeSize(string)
  1172. : asciiSize(string);
  1173. }
  1174. /**
  1175. * Converts `string` to an array.
  1176. *
  1177. * @private
  1178. * @param {string} string The string to convert.
  1179. * @returns {Array} Returns the converted array.
  1180. */
  1181. function stringToArray(string) {
  1182. return hasUnicode(string)
  1183. ? unicodeToArray(string)
  1184. : asciiToArray(string);
  1185. }
  1186. /**
  1187. * Used by `_.unescape` to convert HTML entities to characters.
  1188. *
  1189. * @private
  1190. * @param {string} chr The matched character to unescape.
  1191. * @returns {string} Returns the unescaped character.
  1192. */
  1193. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1194. /**
  1195. * Gets the size of a Unicode `string`.
  1196. *
  1197. * @private
  1198. * @param {string} string The string inspect.
  1199. * @returns {number} Returns the string size.
  1200. */
  1201. function unicodeSize(string) {
  1202. var result = reUnicode.lastIndex = 0;
  1203. while (reUnicode.test(string)) {
  1204. ++result;
  1205. }
  1206. return result;
  1207. }
  1208. /**
  1209. * Converts a Unicode `string` to an array.
  1210. *
  1211. * @private
  1212. * @param {string} string The string to convert.
  1213. * @returns {Array} Returns the converted array.
  1214. */
  1215. function unicodeToArray(string) {
  1216. return string.match(reUnicode) || [];
  1217. }
  1218. /**
  1219. * Splits a Unicode `string` into an array of its words.
  1220. *
  1221. * @private
  1222. * @param {string} The string to inspect.
  1223. * @returns {Array} Returns the words of `string`.
  1224. */
  1225. function unicodeWords(string) {
  1226. return string.match(reUnicodeWord) || [];
  1227. }
  1228. /*--------------------------------------------------------------------------*/
  1229. /**
  1230. * Create a new pristine `lodash` function using the `context` object.
  1231. *
  1232. * @static
  1233. * @memberOf _
  1234. * @since 1.1.0
  1235. * @category Util
  1236. * @param {Object} [context=root] The context object.
  1237. * @returns {Function} Returns a new `lodash` function.
  1238. * @example
  1239. *
  1240. * _.mixin({ 'foo': _.constant('foo') });
  1241. *
  1242. * var lodash = _.runInContext();
  1243. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1244. *
  1245. * _.isFunction(_.foo);
  1246. * // => true
  1247. * _.isFunction(_.bar);
  1248. * // => false
  1249. *
  1250. * lodash.isFunction(lodash.foo);
  1251. * // => false
  1252. * lodash.isFunction(lodash.bar);
  1253. * // => true
  1254. *
  1255. * // Create a suped-up `defer` in Node.js.
  1256. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1257. */
  1258. var runInContext = (function runInContext(context) {
  1259. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1260. /** Built-in constructor references. */
  1261. var Array = context.Array,
  1262. Date = context.Date,
  1263. Error = context.Error,
  1264. Function = context.Function,
  1265. Math = context.Math,
  1266. Object = context.Object,
  1267. RegExp = context.RegExp,
  1268. String = context.String,
  1269. TypeError = context.TypeError;
  1270. /** Used for built-in method references. */
  1271. var arrayProto = Array.prototype,
  1272. funcProto = Function.prototype,
  1273. objectProto = Object.prototype;
  1274. /** Used to detect overreaching core-js shims. */
  1275. var coreJsData = context['__core-js_shared__'];
  1276. /** Used to resolve the decompiled source of functions. */
  1277. var funcToString = funcProto.toString;
  1278. /** Used to check objects for own properties. */
  1279. var hasOwnProperty = objectProto.hasOwnProperty;
  1280. /** Used to generate unique IDs. */
  1281. var idCounter = 0;
  1282. /** Used to detect methods masquerading as native. */
  1283. var maskSrcKey = (function() {
  1284. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1285. return uid ? ('Symbol(src)_1.' + uid) : '';
  1286. }());
  1287. /**
  1288. * Used to resolve the
  1289. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1290. * of values.
  1291. */
  1292. var nativeObjectToString = objectProto.toString;
  1293. /** Used to infer the `Object` constructor. */
  1294. var objectCtorString = funcToString.call(Object);
  1295. /** Used to restore the original `_` reference in `_.noConflict`. */
  1296. var oldDash = root._;
  1297. /** Used to detect if a method is native. */
  1298. var reIsNative = RegExp('^' +
  1299. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1300. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1301. );
  1302. /** Built-in value references. */
  1303. var Buffer = moduleExports ? context.Buffer : undefined,
  1304. Symbol = context.Symbol,
  1305. Uint8Array = context.Uint8Array,
  1306. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1307. getPrototype = overArg(Object.getPrototypeOf, Object),
  1308. objectCreate = Object.create,
  1309. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1310. splice = arrayProto.splice,
  1311. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1312. symIterator = Symbol ? Symbol.iterator : undefined,
  1313. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1314. var defineProperty = (function() {
  1315. try {
  1316. var func = getNative(Object, 'defineProperty');
  1317. func({}, '', {});
  1318. return func;
  1319. } catch (e) {}
  1320. }());
  1321. /** Mocked built-ins. */
  1322. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1323. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1324. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1325. /* Built-in method references for those with the same name as other `lodash` methods. */
  1326. var nativeCeil = Math.ceil,
  1327. nativeFloor = Math.floor,
  1328. nativeGetSymbols = Object.getOwnPropertySymbols,
  1329. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1330. nativeIsFinite = context.isFinite,
  1331. nativeJoin = arrayProto.join,
  1332. nativeKeys = overArg(Object.keys, Object),
  1333. nativeMax = Math.max,
  1334. nativeMin = Math.min,
  1335. nativeNow = Date.now,
  1336. nativeParseInt = context.parseInt,
  1337. nativeRandom = Math.random,
  1338. nativeReverse = arrayProto.reverse;
  1339. /* Built-in method references that are verified to be native. */
  1340. var DataView = getNative(context, 'DataView'),
  1341. Map = getNative(context, 'Map'),
  1342. Promise = getNative(context, 'Promise'),
  1343. Set = getNative(context, 'Set'),
  1344. WeakMap = getNative(context, 'WeakMap'),
  1345. nativeCreate = getNative(Object, 'create');
  1346. /** Used to store function metadata. */
  1347. var metaMap = WeakMap && new WeakMap;
  1348. /** Used to lookup unminified function names. */
  1349. var realNames = {};
  1350. /** Used to detect maps, sets, and weakmaps. */
  1351. var dataViewCtorString = toSource(DataView),
  1352. mapCtorString = toSource(Map),
  1353. promiseCtorString = toSource(Promise),
  1354. setCtorString = toSource(Set),
  1355. weakMapCtorString = toSource(WeakMap);
  1356. /** Used to convert symbols to primitives and strings. */
  1357. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1358. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1359. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1360. /*------------------------------------------------------------------------*/
  1361. /**
  1362. * Creates a `lodash` object which wraps `value` to enable implicit method
  1363. * chain sequences. Methods that operate on and return arrays, collections,
  1364. * and functions can be chained together. Methods that retrieve a single value
  1365. * or may return a primitive value will automatically end the chain sequence
  1366. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1367. * with `_#value`.
  1368. *
  1369. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1370. * enabled using `_.chain`.
  1371. *
  1372. * The execution of chained methods is lazy, that is, it's deferred until
  1373. * `_#value` is implicitly or explicitly called.
  1374. *
  1375. * Lazy evaluation allows several methods to support shortcut fusion.
  1376. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1377. * the creation of intermediate arrays and can greatly reduce the number of
  1378. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1379. * fusion if the section is applied to an array and iteratees accept only
  1380. * one argument. The heuristic for whether a section qualifies for shortcut
  1381. * fusion is subject to change.
  1382. *
  1383. * Chaining is supported in custom builds as long as the `_#value` method is
  1384. * directly or indirectly included in the build.
  1385. *
  1386. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1387. *
  1388. * The wrapper `Array` methods are:
  1389. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1390. *
  1391. * The wrapper `String` methods are:
  1392. * `replace` and `split`
  1393. *
  1394. * The wrapper methods that support shortcut fusion are:
  1395. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1396. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1397. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1398. *
  1399. * The chainable wrapper methods are:
  1400. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1401. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1402. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1403. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1404. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1405. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1406. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1407. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1408. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1409. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1410. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1411. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1412. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1413. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1414. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1415. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1416. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1417. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1418. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1419. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1420. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1421. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1422. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1423. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1424. *
  1425. * The wrapper methods that are **not** chainable by default are:
  1426. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1427. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1428. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1429. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1430. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1431. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1432. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1433. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1434. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1435. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1436. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1437. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1438. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1439. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1440. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1441. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1442. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1443. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1444. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1445. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1446. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1447. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1448. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1449. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1450. * `upperFirst`, `value`, and `words`
  1451. *
  1452. * @name _
  1453. * @constructor
  1454. * @category Seq
  1455. * @param {*} value The value to wrap in a `lodash` instance.
  1456. * @returns {Object} Returns the new `lodash` wrapper instance.
  1457. * @example
  1458. *
  1459. * function square(n) {
  1460. * return n * n;
  1461. * }
  1462. *
  1463. * var wrapped = _([1, 2, 3]);
  1464. *
  1465. * // Returns an unwrapped value.
  1466. * wrapped.reduce(_.add);
  1467. * // => 6
  1468. *
  1469. * // Returns a wrapped value.
  1470. * var squares = wrapped.map(square);
  1471. *
  1472. * _.isArray(squares);
  1473. * // => false
  1474. *
  1475. * _.isArray(squares.value());
  1476. * // => true
  1477. */
  1478. function lodash(value) {
  1479. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1480. if (value instanceof LodashWrapper) {
  1481. return value;
  1482. }
  1483. if (hasOwnProperty.call(value, '__wrapped__')) {
  1484. return wrapperClone(value);
  1485. }
  1486. }
  1487. return new LodashWrapper(value);
  1488. }
  1489. /**
  1490. * The base implementation of `_.create` without support for assigning
  1491. * properties to the created object.
  1492. *
  1493. * @private
  1494. * @param {Object} proto The object to inherit from.
  1495. * @returns {Object} Returns the new object.
  1496. */
  1497. var baseCreate = (function() {
  1498. function object() {}
  1499. return function(proto) {
  1500. if (!isObject(proto)) {
  1501. return {};
  1502. }
  1503. if (objectCreate) {
  1504. return objectCreate(proto);
  1505. }
  1506. object.prototype = proto;
  1507. var result = new object;
  1508. object.prototype = undefined;
  1509. return result;
  1510. };
  1511. }());
  1512. /**
  1513. * The function whose prototype chain sequence wrappers inherit from.
  1514. *
  1515. * @private
  1516. */
  1517. function baseLodash() {
  1518. // No operation performed.
  1519. }
  1520. /**
  1521. * The base constructor for creating `lodash` wrapper objects.
  1522. *
  1523. * @private
  1524. * @param {*} value The value to wrap.
  1525. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1526. */
  1527. function LodashWrapper(value, chainAll) {
  1528. this.__wrapped__ = value;
  1529. this.__actions__ = [];
  1530. this.__chain__ = !!chainAll;
  1531. this.__index__ = 0;
  1532. this.__values__ = undefined;
  1533. }
  1534. /**
  1535. * By default, the template delimiters used by lodash are like those in
  1536. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1537. * following template settings to use alternative delimiters.
  1538. *
  1539. * @static
  1540. * @memberOf _
  1541. * @type {Object}
  1542. */
  1543. lodash.templateSettings = {
  1544. /**
  1545. * Used to detect `data` property values to be HTML-escaped.
  1546. *
  1547. * @memberOf _.templateSettings
  1548. * @type {RegExp}
  1549. */
  1550. 'escape': reEscape,
  1551. /**
  1552. * Used to detect code to be evaluated.
  1553. *
  1554. * @memberOf _.templateSettings
  1555. * @type {RegExp}
  1556. */
  1557. 'evaluate': reEvaluate,
  1558. /**
  1559. * Used to detect `data` property values to inject.
  1560. *
  1561. * @memberOf _.templateSettings
  1562. * @type {RegExp}
  1563. */
  1564. 'interpolate': reInterpolate,
  1565. /**
  1566. * Used to reference the data object in the template text.
  1567. *
  1568. * @memberOf _.templateSettings
  1569. * @type {string}
  1570. */
  1571. 'variable': '',
  1572. /**
  1573. * Used to import variables into the compiled template.
  1574. *
  1575. * @memberOf _.templateSettings
  1576. * @type {Object}
  1577. */
  1578. 'imports': {
  1579. /**
  1580. * A reference to the `lodash` function.
  1581. *
  1582. * @memberOf _.templateSettings.imports
  1583. * @type {Function}
  1584. */
  1585. '_': lodash
  1586. }
  1587. };
  1588. // Ensure wrappers are instances of `baseLodash`.
  1589. lodash.prototype = baseLodash.prototype;
  1590. lodash.prototype.constructor = lodash;
  1591. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1592. LodashWrapper.prototype.constructor = LodashWrapper;
  1593. /*------------------------------------------------------------------------*/
  1594. /**
  1595. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1596. *
  1597. * @private
  1598. * @constructor
  1599. * @param {*} value The value to wrap.
  1600. */
  1601. function LazyWrapper(value) {
  1602. this.__wrapped__ = value;
  1603. this.__actions__ = [];
  1604. this.__dir__ = 1;
  1605. this.__filtered__ = false;
  1606. this.__iteratees__ = [];
  1607. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1608. this.__views__ = [];
  1609. }
  1610. /**
  1611. * Creates a clone of the lazy wrapper object.
  1612. *
  1613. * @private
  1614. * @name clone
  1615. * @memberOf LazyWrapper
  1616. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1617. */
  1618. function lazyClone() {
  1619. var result = new LazyWrapper(this.__wrapped__);
  1620. result.__actions__ = copyArray(this.__actions__);
  1621. result.__dir__ = this.__dir__;
  1622. result.__filtered__ = this.__filtered__;
  1623. result.__iteratees__ = copyArray(this.__iteratees__);
  1624. result.__takeCount__ = this.__takeCount__;
  1625. result.__views__ = copyArray(this.__views__);
  1626. return result;
  1627. }
  1628. /**
  1629. * Reverses the direction of lazy iteration.
  1630. *
  1631. * @private
  1632. * @name reverse
  1633. * @memberOf LazyWrapper
  1634. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1635. */
  1636. function lazyReverse() {
  1637. if (this.__filtered__) {
  1638. var result = new LazyWrapper(this);
  1639. result.__dir__ = -1;
  1640. result.__filtered__ = true;
  1641. } else {
  1642. result = this.clone();
  1643. result.__dir__ *= -1;
  1644. }
  1645. return result;
  1646. }
  1647. /**
  1648. * Extracts the unwrapped value from its lazy wrapper.
  1649. *
  1650. * @private
  1651. * @name value
  1652. * @memberOf LazyWrapper
  1653. * @returns {*} Returns the unwrapped value.
  1654. */
  1655. function lazyValue() {
  1656. var array = this.__wrapped__.value(),
  1657. dir = this.__dir__,
  1658. isArr = isArray(array),
  1659. isRight = dir < 0,
  1660. arrLength = isArr ? array.length : 0,
  1661. view = getView(0, arrLength, this.__views__),
  1662. start = view.start,
  1663. end = view.end,
  1664. length = end - start,
  1665. index = isRight ? end : (start - 1),
  1666. iteratees = this.__iteratees__,
  1667. iterLength = iteratees.length,
  1668. resIndex = 0,
  1669. takeCount = nativeMin(length, this.__takeCount__);
  1670. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1671. return baseWrapperValue(array, this.__actions__);
  1672. }
  1673. var result = [];
  1674. outer:
  1675. while (length-- && resIndex < takeCount) {
  1676. index += dir;
  1677. var iterIndex = -1,
  1678. value = array[index];
  1679. while (++iterIndex < iterLength) {
  1680. var data = iteratees[iterIndex],
  1681. iteratee = data.iteratee,
  1682. type = data.type,
  1683. computed = iteratee(value);
  1684. if (type == LAZY_MAP_FLAG) {
  1685. value = computed;
  1686. } else if (!computed) {
  1687. if (type == LAZY_FILTER_FLAG) {
  1688. continue outer;
  1689. } else {
  1690. break outer;
  1691. }
  1692. }
  1693. }
  1694. result[resIndex++] = value;
  1695. }
  1696. return result;
  1697. }
  1698. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1699. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1700. LazyWrapper.prototype.constructor = LazyWrapper;
  1701. /*------------------------------------------------------------------------*/
  1702. /**
  1703. * Creates a hash object.
  1704. *
  1705. * @private
  1706. * @constructor
  1707. * @param {Array} [entries] The key-value pairs to cache.
  1708. */
  1709. function Hash(entries) {
  1710. var index = -1,
  1711. length = entries == null ? 0 : entries.length;
  1712. this.clear();
  1713. while (++index < length) {
  1714. var entry = entries[index];
  1715. this.set(entry[0], entry[1]);
  1716. }
  1717. }
  1718. /**
  1719. * Removes all key-value entries from the hash.
  1720. *
  1721. * @private
  1722. * @name clear
  1723. * @memberOf Hash
  1724. */
  1725. function hashClear() {
  1726. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1727. this.size = 0;
  1728. }
  1729. /**
  1730. * Removes `key` and its value from the hash.
  1731. *
  1732. * @private
  1733. * @name delete
  1734. * @memberOf Hash
  1735. * @param {Object} hash The hash to modify.
  1736. * @param {string} key The key of the value to remove.
  1737. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1738. */
  1739. function hashDelete(key) {
  1740. var result = this.has(key) && delete this.__data__[key];
  1741. this.size -= result ? 1 : 0;
  1742. return result;
  1743. }
  1744. /**
  1745. * Gets the hash value for `key`.
  1746. *
  1747. * @private
  1748. * @name get
  1749. * @memberOf Hash
  1750. * @param {string} key The key of the value to get.
  1751. * @returns {*} Returns the entry value.
  1752. */
  1753. function hashGet(key) {
  1754. var data = this.__data__;
  1755. if (nativeCreate) {
  1756. var result = data[key];
  1757. return result === HASH_UNDEFINED ? undefined : result;
  1758. }
  1759. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1760. }
  1761. /**
  1762. * Checks if a hash value for `key` exists.
  1763. *
  1764. * @private
  1765. * @name has
  1766. * @memberOf Hash
  1767. * @param {string} key The key of the entry to check.
  1768. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1769. */
  1770. function hashHas(key) {
  1771. var data = this.__data__;
  1772. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1773. }
  1774. /**
  1775. * Sets the hash `key` to `value`.
  1776. *
  1777. * @private
  1778. * @name set
  1779. * @memberOf Hash
  1780. * @param {string} key The key of the value to set.
  1781. * @param {*} value The value to set.
  1782. * @returns {Object} Returns the hash instance.
  1783. */
  1784. function hashSet(key, value) {
  1785. var data = this.__data__;
  1786. this.size += this.has(key) ? 0 : 1;
  1787. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1788. return this;
  1789. }
  1790. // Add methods to `Hash`.
  1791. Hash.prototype.clear = hashClear;
  1792. Hash.prototype['delete'] = hashDelete;
  1793. Hash.prototype.get = hashGet;
  1794. Hash.prototype.has = hashHas;
  1795. Hash.prototype.set = hashSet;
  1796. /*------------------------------------------------------------------------*/
  1797. /**
  1798. * Creates an list cache object.
  1799. *
  1800. * @private
  1801. * @constructor
  1802. * @param {Array} [entries] The key-value pairs to cache.
  1803. */
  1804. function ListCache(entries) {
  1805. var index = -1,
  1806. length = entries == null ? 0 : entries.length;
  1807. this.clear();
  1808. while (++index < length) {
  1809. var entry = entries[index];
  1810. this.set(entry[0], entry[1]);
  1811. }
  1812. }
  1813. /**
  1814. * Removes all key-value entries from the list cache.
  1815. *
  1816. * @private
  1817. * @name clear
  1818. * @memberOf ListCache
  1819. */
  1820. function listCacheClear() {
  1821. this.__data__ = [];
  1822. this.size = 0;
  1823. }
  1824. /**
  1825. * Removes `key` and its value from the list cache.
  1826. *
  1827. * @private
  1828. * @name delete
  1829. * @memberOf ListCache
  1830. * @param {string} key The key of the value to remove.
  1831. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1832. */
  1833. function listCacheDelete(key) {
  1834. var data = this.__data__,
  1835. index = assocIndexOf(data, key);
  1836. if (index < 0) {
  1837. return false;
  1838. }
  1839. var lastIndex = data.length - 1;
  1840. if (index == lastIndex) {
  1841. data.pop();
  1842. } else {
  1843. splice.call(data, index, 1);
  1844. }
  1845. --this.size;
  1846. return true;
  1847. }
  1848. /**
  1849. * Gets the list cache value for `key`.
  1850. *
  1851. * @private
  1852. * @name get
  1853. * @memberOf ListCache
  1854. * @param {string} key The key of the value to get.
  1855. * @returns {*} Returns the entry value.
  1856. */
  1857. function listCacheGet(key) {
  1858. var data = this.__data__,
  1859. index = assocIndexOf(data, key);
  1860. return index < 0 ? undefined : data[index][1];
  1861. }
  1862. /**
  1863. * Checks if a list cache value for `key` exists.
  1864. *
  1865. * @private
  1866. * @name has
  1867. * @memberOf ListCache
  1868. * @param {string} key The key of the entry to check.
  1869. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1870. */
  1871. function listCacheHas(key) {
  1872. return assocIndexOf(this.__data__, key) > -1;
  1873. }
  1874. /**
  1875. * Sets the list cache `key` to `value`.
  1876. *
  1877. * @private
  1878. * @name set
  1879. * @memberOf ListCache
  1880. * @param {string} key The key of the value to set.
  1881. * @param {*} value The value to set.
  1882. * @returns {Object} Returns the list cache instance.
  1883. */
  1884. function listCacheSet(key, value) {
  1885. var data = this.__data__,
  1886. index = assocIndexOf(data, key);
  1887. if (index < 0) {
  1888. ++this.size;
  1889. data.push([key, value]);
  1890. } else {
  1891. data[index][1] = value;
  1892. }
  1893. return this;
  1894. }
  1895. // Add methods to `ListCache`.
  1896. ListCache.prototype.clear = listCacheClear;
  1897. ListCache.prototype['delete'] = listCacheDelete;
  1898. ListCache.prototype.get = listCacheGet;
  1899. ListCache.prototype.has = listCacheHas;
  1900. ListCache.prototype.set = listCacheSet;
  1901. /*------------------------------------------------------------------------*/
  1902. /**
  1903. * Creates a map cache object to store key-value pairs.
  1904. *
  1905. * @private
  1906. * @constructor
  1907. * @param {Array} [entries] The key-value pairs to cache.
  1908. */
  1909. function MapCache(entries) {
  1910. var index = -1,
  1911. length = entries == null ? 0 : entries.length;
  1912. this.clear();
  1913. while (++index < length) {
  1914. var entry = entries[index];
  1915. this.set(entry[0], entry[1]);
  1916. }
  1917. }
  1918. /**
  1919. * Removes all key-value entries from the map.
  1920. *
  1921. * @private
  1922. * @name clear
  1923. * @memberOf MapCache
  1924. */
  1925. function mapCacheClear() {
  1926. this.size = 0;
  1927. this.__data__ = {
  1928. 'hash': new Hash,
  1929. 'map': new (Map || ListCache),
  1930. 'string': new Hash
  1931. };
  1932. }
  1933. /**
  1934. * Removes `key` and its value from the map.
  1935. *
  1936. * @private
  1937. * @name delete
  1938. * @memberOf MapCache
  1939. * @param {string} key The key of the value to remove.
  1940. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1941. */
  1942. function mapCacheDelete(key) {
  1943. var result = getMapData(this, key)['delete'](key);
  1944. this.size -= result ? 1 : 0;
  1945. return result;
  1946. }
  1947. /**
  1948. * Gets the map value for `key`.
  1949. *
  1950. * @private
  1951. * @name get
  1952. * @memberOf MapCache
  1953. * @param {string} key The key of the value to get.
  1954. * @returns {*} Returns the entry value.
  1955. */
  1956. function mapCacheGet(key) {
  1957. return getMapData(this, key).get(key);
  1958. }
  1959. /**
  1960. * Checks if a map value for `key` exists.
  1961. *
  1962. * @private
  1963. * @name has
  1964. * @memberOf MapCache
  1965. * @param {string} key The key of the entry to check.
  1966. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1967. */
  1968. function mapCacheHas(key) {
  1969. return getMapData(this, key).has(key);
  1970. }
  1971. /**
  1972. * Sets the map `key` to `value`.
  1973. *
  1974. * @private
  1975. * @name set
  1976. * @memberOf MapCache
  1977. * @param {string} key The key of the value to set.
  1978. * @param {*} value The value to set.
  1979. * @returns {Object} Returns the map cache instance.
  1980. */
  1981. function mapCacheSet(key, value) {
  1982. var data = getMapData(this, key),
  1983. size = data.size;
  1984. data.set(key, value);
  1985. this.size += data.size == size ? 0 : 1;
  1986. return this;
  1987. }
  1988. // Add methods to `MapCache`.
  1989. MapCache.prototype.clear = mapCacheClear;
  1990. MapCache.prototype['delete'] = mapCacheDelete;
  1991. MapCache.prototype.get = mapCacheGet;
  1992. MapCache.prototype.has = mapCacheHas;
  1993. MapCache.prototype.set = mapCacheSet;
  1994. /*------------------------------------------------------------------------*/
  1995. /**
  1996. *
  1997. * Creates an array cache object to store unique values.
  1998. *
  1999. * @private
  2000. * @constructor
  2001. * @param {Array} [values] The values to cache.
  2002. */
  2003. function SetCache(values) {
  2004. var index = -1,
  2005. length = values == null ? 0 : values.length;
  2006. this.__data__ = new MapCache;
  2007. while (++index < length) {
  2008. this.add(values[index]);
  2009. }
  2010. }
  2011. /**
  2012. * Adds `value` to the array cache.
  2013. *
  2014. * @private
  2015. * @name add
  2016. * @memberOf SetCache
  2017. * @alias push
  2018. * @param {*} value The value to cache.
  2019. * @returns {Object} Returns the cache instance.
  2020. */
  2021. function setCacheAdd(value) {
  2022. this.__data__.set(value, HASH_UNDEFINED);
  2023. return this;
  2024. }
  2025. /**
  2026. * Checks if `value` is in the array cache.
  2027. *
  2028. * @private
  2029. * @name has
  2030. * @memberOf SetCache
  2031. * @param {*} value The value to search for.
  2032. * @returns {number} Returns `true` if `value` is found, else `false`.
  2033. */
  2034. function setCacheHas(value) {
  2035. return this.__data__.has(value);
  2036. }
  2037. // Add methods to `SetCache`.
  2038. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2039. SetCache.prototype.has = setCacheHas;
  2040. /*------------------------------------------------------------------------*/
  2041. /**
  2042. * Creates a stack cache object to store key-value pairs.
  2043. *
  2044. * @private
  2045. * @constructor
  2046. * @param {Array} [entries] The key-value pairs to cache.
  2047. */
  2048. function Stack(entries) {
  2049. var data = this.__data__ = new ListCache(entries);
  2050. this.size = data.size;
  2051. }
  2052. /**
  2053. * Removes all key-value entries from the stack.
  2054. *
  2055. * @private
  2056. * @name clear
  2057. * @memberOf Stack
  2058. */
  2059. function stackClear() {
  2060. this.__data__ = new ListCache;
  2061. this.size = 0;
  2062. }
  2063. /**
  2064. * Removes `key` and its value from the stack.
  2065. *
  2066. * @private
  2067. * @name delete
  2068. * @memberOf Stack
  2069. * @param {string} key The key of the value to remove.
  2070. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2071. */
  2072. function stackDelete(key) {
  2073. var data = this.__data__,
  2074. result = data['delete'](key);
  2075. this.size = data.size;
  2076. return result;
  2077. }
  2078. /**
  2079. * Gets the stack value for `key`.
  2080. *
  2081. * @private
  2082. * @name get
  2083. * @memberOf Stack
  2084. * @param {string} key The key of the value to get.
  2085. * @returns {*} Returns the entry value.
  2086. */
  2087. function stackGet(key) {
  2088. return this.__data__.get(key);
  2089. }
  2090. /**
  2091. * Checks if a stack value for `key` exists.
  2092. *
  2093. * @private
  2094. * @name has
  2095. * @memberOf Stack
  2096. * @param {string} key The key of the entry to check.
  2097. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2098. */
  2099. function stackHas(key) {
  2100. return this.__data__.has(key);
  2101. }
  2102. /**
  2103. * Sets the stack `key` to `value`.
  2104. *
  2105. * @private
  2106. * @name set
  2107. * @memberOf Stack
  2108. * @param {string} key The key of the value to set.
  2109. * @param {*} value The value to set.
  2110. * @returns {Object} Returns the stack cache instance.
  2111. */
  2112. function stackSet(key, value) {
  2113. var data = this.__data__;
  2114. if (data instanceof ListCache) {
  2115. var pairs = data.__data__;
  2116. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2117. pairs.push([key, value]);
  2118. this.size = ++data.size;
  2119. return this;
  2120. }
  2121. data = this.__data__ = new MapCache(pairs);
  2122. }
  2123. data.set(key, value);
  2124. this.size = data.size;
  2125. return this;
  2126. }
  2127. // Add methods to `Stack`.
  2128. Stack.prototype.clear = stackClear;
  2129. Stack.prototype['delete'] = stackDelete;
  2130. Stack.prototype.get = stackGet;
  2131. Stack.prototype.has = stackHas;
  2132. Stack.prototype.set = stackSet;
  2133. /*------------------------------------------------------------------------*/
  2134. /**
  2135. * Creates an array of the enumerable property names of the array-like `value`.
  2136. *
  2137. * @private
  2138. * @param {*} value The value to query.
  2139. * @param {boolean} inherited Specify returning inherited property names.
  2140. * @returns {Array} Returns the array of property names.
  2141. */
  2142. function arrayLikeKeys(value, inherited) {
  2143. var isArr = isArray(value),
  2144. isArg = !isArr && isArguments(value),
  2145. isBuff = !isArr && !isArg && isBuffer(value),
  2146. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2147. skipIndexes = isArr || isArg || isBuff || isType,
  2148. result = skipIndexes ? baseTimes(value.length, String) : [],
  2149. length = result.length;
  2150. for (var key in value) {
  2151. if ((inherited || hasOwnProperty.call(value, key)) &&
  2152. !(skipIndexes && (
  2153. // Safari 9 has enumerable `arguments.length` in strict mode.
  2154. key == 'length' ||
  2155. // Node.js 0.10 has enumerable non-index properties on buffers.
  2156. (isBuff && (key == 'offset' || key == 'parent')) ||
  2157. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2158. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2159. // Skip index properties.
  2160. isIndex(key, length)
  2161. ))) {
  2162. result.push(key);
  2163. }
  2164. }
  2165. return result;
  2166. }
  2167. /**
  2168. * A specialized version of `_.sample` for arrays.
  2169. *
  2170. * @private
  2171. * @param {Array} array The array to sample.
  2172. * @returns {*} Returns the random element.
  2173. */
  2174. function arraySample(array) {
  2175. var length = array.length;
  2176. return length ? array[baseRandom(0, length - 1)] : undefined;
  2177. }
  2178. /**
  2179. * A specialized version of `_.sampleSize` for arrays.
  2180. *
  2181. * @private
  2182. * @param {Array} array The array to sample.
  2183. * @param {number} n The number of elements to sample.
  2184. * @returns {Array} Returns the random elements.
  2185. */
  2186. function arraySampleSize(array, n) {
  2187. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2188. }
  2189. /**
  2190. * A specialized version of `_.shuffle` for arrays.
  2191. *
  2192. * @private
  2193. * @param {Array} array The array to shuffle.
  2194. * @returns {Array} Returns the new shuffled array.
  2195. */
  2196. function arrayShuffle(array) {
  2197. return shuffleSelf(copyArray(array));
  2198. }
  2199. /**
  2200. * This function is like `assignValue` except that it doesn't assign
  2201. * `undefined` values.
  2202. *
  2203. * @private
  2204. * @param {Object} object The object to modify.
  2205. * @param {string} key The key of the property to assign.
  2206. * @param {*} value The value to assign.
  2207. */
  2208. function assignMergeValue(object, key, value) {
  2209. if ((value !== undefined && !eq(object[key], value)) ||
  2210. (value === undefined && !(key in object))) {
  2211. baseAssignValue(object, key, value);
  2212. }
  2213. }
  2214. /**
  2215. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2216. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2217. * for equality comparisons.
  2218. *
  2219. * @private
  2220. * @param {Object} object The object to modify.
  2221. * @param {string} key The key of the property to assign.
  2222. * @param {*} value The value to assign.
  2223. */
  2224. function assignValue(object, key, value) {
  2225. var objValue = object[key];
  2226. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2227. (value === undefined && !(key in object))) {
  2228. baseAssignValue(object, key, value);
  2229. }
  2230. }
  2231. /**
  2232. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2233. *
  2234. * @private
  2235. * @param {Array} array The array to inspect.
  2236. * @param {*} key The key to search for.
  2237. * @returns {number} Returns the index of the matched value, else `-1`.
  2238. */
  2239. function assocIndexOf(array, key) {
  2240. var length = array.length;
  2241. while (length--) {
  2242. if (eq(array[length][0], key)) {
  2243. return length;
  2244. }
  2245. }
  2246. return -1;
  2247. }
  2248. /**
  2249. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2250. * by `iteratee` and values set by `setter`.
  2251. *
  2252. * @private
  2253. * @param {Array|Object} collection The collection to iterate over.
  2254. * @param {Function} setter The function to set `accumulator` values.
  2255. * @param {Function} iteratee The iteratee to transform keys.
  2256. * @param {Object} accumulator The initial aggregated object.
  2257. * @returns {Function} Returns `accumulator`.
  2258. */
  2259. function baseAggregator(collection, setter, iteratee, accumulator) {
  2260. baseEach(collection, function(value, key, collection) {
  2261. setter(accumulator, value, iteratee(value), collection);
  2262. });
  2263. return accumulator;
  2264. }
  2265. /**
  2266. * The base implementation of `_.assign` without support for multiple sources
  2267. * or `customizer` functions.
  2268. *
  2269. * @private
  2270. * @param {Object} object The destination object.
  2271. * @param {Object} source The source object.
  2272. * @returns {Object} Returns `object`.
  2273. */
  2274. function baseAssign(object, source) {
  2275. return object && copyObject(source, keys(source), object);
  2276. }
  2277. /**
  2278. * The base implementation of `_.assignIn` without support for multiple sources
  2279. * or `customizer` functions.
  2280. *
  2281. * @private
  2282. * @param {Object} object The destination object.
  2283. * @param {Object} source The source object.
  2284. * @returns {Object} Returns `object`.
  2285. */
  2286. function baseAssignIn(object, source) {
  2287. return object && copyObject(source, keysIn(source), object);
  2288. }
  2289. /**
  2290. * The base implementation of `assignValue` and `assignMergeValue` without
  2291. * value checks.
  2292. *
  2293. * @private
  2294. * @param {Object} object The object to modify.
  2295. * @param {string} key The key of the property to assign.
  2296. * @param {*} value The value to assign.
  2297. */
  2298. function baseAssignValue(object, key, value) {
  2299. if (key == '__proto__' && defineProperty) {
  2300. defineProperty(object, key, {
  2301. 'configurable': true,
  2302. 'enumerable': true,
  2303. 'value': value,
  2304. 'writable': true
  2305. });
  2306. } else {
  2307. object[key] = value;
  2308. }
  2309. }
  2310. /**
  2311. * The base implementation of `_.at` without support for individual paths.
  2312. *
  2313. * @private
  2314. * @param {Object} object The object to iterate over.
  2315. * @param {string[]} paths The property paths to pick.
  2316. * @returns {Array} Returns the picked elements.
  2317. */
  2318. function baseAt(object, paths) {
  2319. var index = -1,
  2320. length = paths.length,
  2321. result = Array(length),
  2322. skip = object == null;
  2323. while (++index < length) {
  2324. result[index] = skip ? undefined : get(object, paths[index]);
  2325. }
  2326. return result;
  2327. }
  2328. /**
  2329. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2330. *
  2331. * @private
  2332. * @param {number} number The number to clamp.
  2333. * @param {number} [lower] The lower bound.
  2334. * @param {number} upper The upper bound.
  2335. * @returns {number} Returns the clamped number.
  2336. */
  2337. function baseClamp(number, lower, upper) {
  2338. if (number === number) {
  2339. if (upper !== undefined) {
  2340. number = number <= upper ? number : upper;
  2341. }
  2342. if (lower !== undefined) {
  2343. number = number >= lower ? number : lower;
  2344. }
  2345. }
  2346. return number;
  2347. }
  2348. /**
  2349. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2350. * traversed objects.
  2351. *
  2352. * @private
  2353. * @param {*} value The value to clone.
  2354. * @param {boolean} bitmask The bitmask flags.
  2355. * 1 - Deep clone
  2356. * 2 - Flatten inherited properties
  2357. * 4 - Clone symbols
  2358. * @param {Function} [customizer] The function to customize cloning.
  2359. * @param {string} [key] The key of `value`.
  2360. * @param {Object} [object] The parent object of `value`.
  2361. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2362. * @returns {*} Returns the cloned value.
  2363. */
  2364. function baseClone(value, bitmask, customizer, key, object, stack) {
  2365. var result,
  2366. isDeep = bitmask & CLONE_DEEP_FLAG,
  2367. isFlat = bitmask & CLONE_FLAT_FLAG,
  2368. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2369. if (customizer) {
  2370. result = object ? customizer(value, key, object, stack) : customizer(value);
  2371. }
  2372. if (result !== undefined) {
  2373. return result;
  2374. }
  2375. if (!isObject(value)) {
  2376. return value;
  2377. }
  2378. var isArr = isArray(value);
  2379. if (isArr) {
  2380. result = initCloneArray(value);
  2381. if (!isDeep) {
  2382. return copyArray(value, result);
  2383. }
  2384. } else {
  2385. var tag = getTag(value),
  2386. isFunc = tag == funcTag || tag == genTag;
  2387. if (isBuffer(value)) {
  2388. return cloneBuffer(value, isDeep);
  2389. }
  2390. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2391. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2392. if (!isDeep) {
  2393. return isFlat
  2394. ? copySymbolsIn(value, baseAssignIn(result, value))
  2395. : copySymbols(value, baseAssign(result, value));
  2396. }
  2397. } else {
  2398. if (!cloneableTags[tag]) {
  2399. return object ? value : {};
  2400. }
  2401. result = initCloneByTag(value, tag, isDeep);
  2402. }
  2403. }
  2404. // Check for circular references and return its corresponding clone.
  2405. stack || (stack = new Stack);
  2406. var stacked = stack.get(value);
  2407. if (stacked) {
  2408. return stacked;
  2409. }
  2410. stack.set(value, result);
  2411. if (isSet(value)) {
  2412. value.forEach(function(subValue) {
  2413. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2414. });
  2415. return result;
  2416. }
  2417. if (isMap(value)) {
  2418. value.forEach(function(subValue, key) {
  2419. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2420. });
  2421. return result;
  2422. }
  2423. var keysFunc = isFull
  2424. ? (isFlat ? getAllKeysIn : getAllKeys)
  2425. : (isFlat ? keysIn : keys);
  2426. var props = isArr ? undefined : keysFunc(value);
  2427. arrayEach(props || value, function(subValue, key) {
  2428. if (props) {
  2429. key = subValue;
  2430. subValue = value[key];
  2431. }
  2432. // Recursively populate clone (susceptible to call stack limits).
  2433. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2434. });
  2435. return result;
  2436. }
  2437. /**
  2438. * The base implementation of `_.conforms` which doesn't clone `source`.
  2439. *
  2440. * @private
  2441. * @param {Object} source The object of property predicates to conform to.
  2442. * @returns {Function} Returns the new spec function.
  2443. */
  2444. function baseConforms(source) {
  2445. var props = keys(source);
  2446. return function(object) {
  2447. return baseConformsTo(object, source, props);
  2448. };
  2449. }
  2450. /**
  2451. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2452. *
  2453. * @private
  2454. * @param {Object} object The object to inspect.
  2455. * @param {Object} source The object of property predicates to conform to.
  2456. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2457. */
  2458. function baseConformsTo(object, source, props) {
  2459. var length = props.length;
  2460. if (object == null) {
  2461. return !length;
  2462. }
  2463. object = Object(object);
  2464. while (length--) {
  2465. var key = props[length],
  2466. predicate = source[key],
  2467. value = object[key];
  2468. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2469. return false;
  2470. }
  2471. }
  2472. return true;
  2473. }
  2474. /**
  2475. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2476. * to provide to `func`.
  2477. *
  2478. * @private
  2479. * @param {Function} func The function to delay.
  2480. * @param {number} wait The number of milliseconds to delay invocation.
  2481. * @param {Array} args The arguments to provide to `func`.
  2482. * @returns {number|Object} Returns the timer id or timeout object.
  2483. */
  2484. function baseDelay(func, wait, args) {
  2485. if (typeof func != 'function') {
  2486. throw new TypeError(FUNC_ERROR_TEXT);
  2487. }
  2488. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2489. }
  2490. /**
  2491. * The base implementation of methods like `_.difference` without support
  2492. * for excluding multiple arrays or iteratee shorthands.
  2493. *
  2494. * @private
  2495. * @param {Array} array The array to inspect.
  2496. * @param {Array} values The values to exclude.
  2497. * @param {Function} [iteratee] The iteratee invoked per element.
  2498. * @param {Function} [comparator] The comparator invoked per element.
  2499. * @returns {Array} Returns the new array of filtered values.
  2500. */
  2501. function baseDifference(array, values, iteratee, comparator) {
  2502. var index = -1,
  2503. includes = arrayIncludes,
  2504. isCommon = true,
  2505. length = array.length,
  2506. result = [],
  2507. valuesLength = values.length;
  2508. if (!length) {
  2509. return result;
  2510. }
  2511. if (iteratee) {
  2512. values = arrayMap(values, baseUnary(iteratee));
  2513. }
  2514. if (comparator) {
  2515. includes = arrayIncludesWith;
  2516. isCommon = false;
  2517. }
  2518. else if (values.length >= LARGE_ARRAY_SIZE) {
  2519. includes = cacheHas;
  2520. isCommon = false;
  2521. values = new SetCache(values);
  2522. }
  2523. outer:
  2524. while (++index < length) {
  2525. var value = array[index],
  2526. computed = iteratee == null ? value : iteratee(value);
  2527. value = (comparator || value !== 0) ? value : 0;
  2528. if (isCommon && computed === computed) {
  2529. var valuesIndex = valuesLength;
  2530. while (valuesIndex--) {
  2531. if (values[valuesIndex] === computed) {
  2532. continue outer;
  2533. }
  2534. }
  2535. result.push(value);
  2536. }
  2537. else if (!includes(values, computed, comparator)) {
  2538. result.push(value);
  2539. }
  2540. }
  2541. return result;
  2542. }
  2543. /**
  2544. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2545. *
  2546. * @private
  2547. * @param {Array|Object} collection The collection to iterate over.
  2548. * @param {Function} iteratee The function invoked per iteration.
  2549. * @returns {Array|Object} Returns `collection`.
  2550. */
  2551. var baseEach = createBaseEach(baseForOwn);
  2552. /**
  2553. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2554. *
  2555. * @private
  2556. * @param {Array|Object} collection The collection to iterate over.
  2557. * @param {Function} iteratee The function invoked per iteration.
  2558. * @returns {Array|Object} Returns `collection`.
  2559. */
  2560. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2561. /**
  2562. * The base implementation of `_.every` without support for iteratee shorthands.
  2563. *
  2564. * @private
  2565. * @param {Array|Object} collection The collection to iterate over.
  2566. * @param {Function} predicate The function invoked per iteration.
  2567. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2568. * else `false`
  2569. */
  2570. function baseEvery(collection, predicate) {
  2571. var result = true;
  2572. baseEach(collection, function(value, index, collection) {
  2573. result = !!predicate(value, index, collection);
  2574. return result;
  2575. });
  2576. return result;
  2577. }
  2578. /**
  2579. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2580. * `comparator` to determine the extremum value.
  2581. *
  2582. * @private
  2583. * @param {Array} array The array to iterate over.
  2584. * @param {Function} iteratee The iteratee invoked per iteration.
  2585. * @param {Function} comparator The comparator used to compare values.
  2586. * @returns {*} Returns the extremum value.
  2587. */
  2588. function baseExtremum(array, iteratee, comparator) {
  2589. var index = -1,
  2590. length = array.length;
  2591. while (++index < length) {
  2592. var value = array[index],
  2593. current = iteratee(value);
  2594. if (current != null && (computed === undefined
  2595. ? (current === current && !isSymbol(current))
  2596. : comparator(current, computed)
  2597. )) {
  2598. var computed = current,
  2599. result = value;
  2600. }
  2601. }
  2602. return result;
  2603. }
  2604. /**
  2605. * The base implementation of `_.fill` without an iteratee call guard.
  2606. *
  2607. * @private
  2608. * @param {Array} array The array to fill.
  2609. * @param {*} value The value to fill `array` with.
  2610. * @param {number} [start=0] The start position.
  2611. * @param {number} [end=array.length] The end position.
  2612. * @returns {Array} Returns `array`.
  2613. */
  2614. function baseFill(array, value, start, end) {
  2615. var length = array.length;
  2616. start = toInteger(start);
  2617. if (start < 0) {
  2618. start = -start > length ? 0 : (length + start);
  2619. }
  2620. end = (end === undefined || end > length) ? length : toInteger(end);
  2621. if (end < 0) {
  2622. end += length;
  2623. }
  2624. end = start > end ? 0 : toLength(end);
  2625. while (start < end) {
  2626. array[start++] = value;
  2627. }
  2628. return array;
  2629. }
  2630. /**
  2631. * The base implementation of `_.filter` without support for iteratee shorthands.
  2632. *
  2633. * @private
  2634. * @param {Array|Object} collection The collection to iterate over.
  2635. * @param {Function} predicate The function invoked per iteration.
  2636. * @returns {Array} Returns the new filtered array.
  2637. */
  2638. function baseFilter(collection, predicate) {
  2639. var result = [];
  2640. baseEach(collection, function(value, index, collection) {
  2641. if (predicate(value, index, collection)) {
  2642. result.push(value);
  2643. }
  2644. });
  2645. return result;
  2646. }
  2647. /**
  2648. * The base implementation of `_.flatten` with support for restricting flattening.
  2649. *
  2650. * @private
  2651. * @param {Array} array The array to flatten.
  2652. * @param {number} depth The maximum recursion depth.
  2653. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2654. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2655. * @param {Array} [result=[]] The initial result value.
  2656. * @returns {Array} Returns the new flattened array.
  2657. */
  2658. function baseFlatten(array, depth, predicate, isStrict, result) {
  2659. var index = -1,
  2660. length = array.length;
  2661. predicate || (predicate = isFlattenable);
  2662. result || (result = []);
  2663. while (++index < length) {
  2664. var value = array[index];
  2665. if (depth > 0 && predicate(value)) {
  2666. if (depth > 1) {
  2667. // Recursively flatten arrays (susceptible to call stack limits).
  2668. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2669. } else {
  2670. arrayPush(result, value);
  2671. }
  2672. } else if (!isStrict) {
  2673. result[result.length] = value;
  2674. }
  2675. }
  2676. return result;
  2677. }
  2678. /**
  2679. * The base implementation of `baseForOwn` which iterates over `object`
  2680. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2681. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2682. *
  2683. * @private
  2684. * @param {Object} object The object to iterate over.
  2685. * @param {Function} iteratee The function invoked per iteration.
  2686. * @param {Function} keysFunc The function to get the keys of `object`.
  2687. * @returns {Object} Returns `object`.
  2688. */
  2689. var baseFor = createBaseFor();
  2690. /**
  2691. * This function is like `baseFor` except that it iterates over properties
  2692. * in the opposite order.
  2693. *
  2694. * @private
  2695. * @param {Object} object The object to iterate over.
  2696. * @param {Function} iteratee The function invoked per iteration.
  2697. * @param {Function} keysFunc The function to get the keys of `object`.
  2698. * @returns {Object} Returns `object`.
  2699. */
  2700. var baseForRight = createBaseFor(true);
  2701. /**
  2702. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2703. *
  2704. * @private
  2705. * @param {Object} object The object to iterate over.
  2706. * @param {Function} iteratee The function invoked per iteration.
  2707. * @returns {Object} Returns `object`.
  2708. */
  2709. function baseForOwn(object, iteratee) {
  2710. return object && baseFor(object, iteratee, keys);
  2711. }
  2712. /**
  2713. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2714. *
  2715. * @private
  2716. * @param {Object} object The object to iterate over.
  2717. * @param {Function} iteratee The function invoked per iteration.
  2718. * @returns {Object} Returns `object`.
  2719. */
  2720. function baseForOwnRight(object, iteratee) {
  2721. return object && baseForRight(object, iteratee, keys);
  2722. }
  2723. /**
  2724. * The base implementation of `_.functions` which creates an array of
  2725. * `object` function property names filtered from `props`.
  2726. *
  2727. * @private
  2728. * @param {Object} object The object to inspect.
  2729. * @param {Array} props The property names to filter.
  2730. * @returns {Array} Returns the function names.
  2731. */
  2732. function baseFunctions(object, props) {
  2733. return arrayFilter(props, function(key) {
  2734. return isFunction(object[key]);
  2735. });
  2736. }
  2737. /**
  2738. * The base implementation of `_.get` without support for default values.
  2739. *
  2740. * @private
  2741. * @param {Object} object The object to query.
  2742. * @param {Array|string} path The path of the property to get.
  2743. * @returns {*} Returns the resolved value.
  2744. */
  2745. function baseGet(object, path) {
  2746. path = castPath(path, object);
  2747. var index = 0,
  2748. length = path.length;
  2749. while (object != null && index < length) {
  2750. object = object[toKey(path[index++])];
  2751. }
  2752. return (index && index == length) ? object : undefined;
  2753. }
  2754. /**
  2755. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2756. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2757. * symbols of `object`.
  2758. *
  2759. * @private
  2760. * @param {Object} object The object to query.
  2761. * @param {Function} keysFunc The function to get the keys of `object`.
  2762. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2763. * @returns {Array} Returns the array of property names and symbols.
  2764. */
  2765. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2766. var result = keysFunc(object);
  2767. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2768. }
  2769. /**
  2770. * The base implementation of `getTag` without fallbacks for buggy environments.
  2771. *
  2772. * @private
  2773. * @param {*} value The value to query.
  2774. * @returns {string} Returns the `toStringTag`.
  2775. */
  2776. function baseGetTag(value) {
  2777. if (value == null) {
  2778. return value === undefined ? undefinedTag : nullTag;
  2779. }
  2780. return (symToStringTag && symToStringTag in Object(value))
  2781. ? getRawTag(value)
  2782. : objectToString(value);
  2783. }
  2784. /**
  2785. * The base implementation of `_.gt` which doesn't coerce arguments.
  2786. *
  2787. * @private
  2788. * @param {*} value The value to compare.
  2789. * @param {*} other The other value to compare.
  2790. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2791. * else `false`.
  2792. */
  2793. function baseGt(value, other) {
  2794. return value > other;
  2795. }
  2796. /**
  2797. * The base implementation of `_.has` without support for deep paths.
  2798. *
  2799. * @private
  2800. * @param {Object} [object] The object to query.
  2801. * @param {Array|string} key The key to check.
  2802. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2803. */
  2804. function baseHas(object, key) {
  2805. return object != null && hasOwnProperty.call(object, key);
  2806. }
  2807. /**
  2808. * The base implementation of `_.hasIn` without support for deep paths.
  2809. *
  2810. * @private
  2811. * @param {Object} [object] The object to query.
  2812. * @param {Array|string} key The key to check.
  2813. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2814. */
  2815. function baseHasIn(object, key) {
  2816. return object != null && key in Object(object);
  2817. }
  2818. /**
  2819. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2820. *
  2821. * @private
  2822. * @param {number} number The number to check.
  2823. * @param {number} start The start of the range.
  2824. * @param {number} end The end of the range.
  2825. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2826. */
  2827. function baseInRange(number, start, end) {
  2828. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2829. }
  2830. /**
  2831. * The base implementation of methods like `_.intersection`, without support
  2832. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2833. *
  2834. * @private
  2835. * @param {Array} arrays The arrays to inspect.
  2836. * @param {Function} [iteratee] The iteratee invoked per element.
  2837. * @param {Function} [comparator] The comparator invoked per element.
  2838. * @returns {Array} Returns the new array of shared values.
  2839. */
  2840. function baseIntersection(arrays, iteratee, comparator) {
  2841. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2842. length = arrays[0].length,
  2843. othLength = arrays.length,
  2844. othIndex = othLength,
  2845. caches = Array(othLength),
  2846. maxLength = Infinity,
  2847. result = [];
  2848. while (othIndex--) {
  2849. var array = arrays[othIndex];
  2850. if (othIndex && iteratee) {
  2851. array = arrayMap(array, baseUnary(iteratee));
  2852. }
  2853. maxLength = nativeMin(array.length, maxLength);
  2854. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2855. ? new SetCache(othIndex && array)
  2856. : undefined;
  2857. }
  2858. array = arrays[0];
  2859. var index = -1,
  2860. seen = caches[0];
  2861. outer:
  2862. while (++index < length && result.length < maxLength) {
  2863. var value = array[index],
  2864. computed = iteratee ? iteratee(value) : value;
  2865. value = (comparator || value !== 0) ? value : 0;
  2866. if (!(seen
  2867. ? cacheHas(seen, computed)
  2868. : includes(result, computed, comparator)
  2869. )) {
  2870. othIndex = othLength;
  2871. while (--othIndex) {
  2872. var cache = caches[othIndex];
  2873. if (!(cache
  2874. ? cacheHas(cache, computed)
  2875. : includes(arrays[othIndex], computed, comparator))
  2876. ) {
  2877. continue outer;
  2878. }
  2879. }
  2880. if (seen) {
  2881. seen.push(computed);
  2882. }
  2883. result.push(value);
  2884. }
  2885. }
  2886. return result;
  2887. }
  2888. /**
  2889. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2890. * `object` with values transformed by `iteratee` and set by `setter`.
  2891. *
  2892. * @private
  2893. * @param {Object} object The object to iterate over.
  2894. * @param {Function} setter The function to set `accumulator` values.
  2895. * @param {Function} iteratee The iteratee to transform values.
  2896. * @param {Object} accumulator The initial inverted object.
  2897. * @returns {Function} Returns `accumulator`.
  2898. */
  2899. function baseInverter(object, setter, iteratee, accumulator) {
  2900. baseForOwn(object, function(value, key, object) {
  2901. setter(accumulator, iteratee(value), key, object);
  2902. });
  2903. return accumulator;
  2904. }
  2905. /**
  2906. * The base implementation of `_.invoke` without support for individual
  2907. * method arguments.
  2908. *
  2909. * @private
  2910. * @param {Object} object The object to query.
  2911. * @param {Array|string} path The path of the method to invoke.
  2912. * @param {Array} args The arguments to invoke the method with.
  2913. * @returns {*} Returns the result of the invoked method.
  2914. */
  2915. function baseInvoke(object, path, args) {
  2916. path = castPath(path, object);
  2917. object = parent(object, path);
  2918. var func = object == null ? object : object[toKey(last(path))];
  2919. return func == null ? undefined : apply(func, object, args);
  2920. }
  2921. /**
  2922. * The base implementation of `_.isArguments`.
  2923. *
  2924. * @private
  2925. * @param {*} value The value to check.
  2926. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2927. */
  2928. function baseIsArguments(value) {
  2929. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2930. }
  2931. /**
  2932. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2933. *
  2934. * @private
  2935. * @param {*} value The value to check.
  2936. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2937. */
  2938. function baseIsArrayBuffer(value) {
  2939. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2940. }
  2941. /**
  2942. * The base implementation of `_.isDate` without Node.js optimizations.
  2943. *
  2944. * @private
  2945. * @param {*} value The value to check.
  2946. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2947. */
  2948. function baseIsDate(value) {
  2949. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2950. }
  2951. /**
  2952. * The base implementation of `_.isEqual` which supports partial comparisons
  2953. * and tracks traversed objects.
  2954. *
  2955. * @private
  2956. * @param {*} value The value to compare.
  2957. * @param {*} other The other value to compare.
  2958. * @param {boolean} bitmask The bitmask flags.
  2959. * 1 - Unordered comparison
  2960. * 2 - Partial comparison
  2961. * @param {Function} [customizer] The function to customize comparisons.
  2962. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2963. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2964. */
  2965. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2966. if (value === other) {
  2967. return true;
  2968. }
  2969. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2970. return value !== value && other !== other;
  2971. }
  2972. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2973. }
  2974. /**
  2975. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2976. * deep comparisons and tracks traversed objects enabling objects with circular
  2977. * references to be compared.
  2978. *
  2979. * @private
  2980. * @param {Object} object The object to compare.
  2981. * @param {Object} other The other object to compare.
  2982. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2983. * @param {Function} customizer The function to customize comparisons.
  2984. * @param {Function} equalFunc The function to determine equivalents of values.
  2985. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2986. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2987. */
  2988. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2989. var objIsArr = isArray(object),
  2990. othIsArr = isArray(other),
  2991. objTag = objIsArr ? arrayTag : getTag(object),
  2992. othTag = othIsArr ? arrayTag : getTag(other);
  2993. objTag = objTag == argsTag ? objectTag : objTag;
  2994. othTag = othTag == argsTag ? objectTag : othTag;
  2995. var objIsObj = objTag == objectTag,
  2996. othIsObj = othTag == objectTag,
  2997. isSameTag = objTag == othTag;
  2998. if (isSameTag && isBuffer(object)) {
  2999. if (!isBuffer(other)) {
  3000. return false;
  3001. }
  3002. objIsArr = true;
  3003. objIsObj = false;
  3004. }
  3005. if (isSameTag && !objIsObj) {
  3006. stack || (stack = new Stack);
  3007. return (objIsArr || isTypedArray(object))
  3008. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3009. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3010. }
  3011. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3012. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3013. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3014. if (objIsWrapped || othIsWrapped) {
  3015. var objUnwrapped = objIsWrapped ? object.value() : object,
  3016. othUnwrapped = othIsWrapped ? other.value() : other;
  3017. stack || (stack = new Stack);
  3018. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3019. }
  3020. }
  3021. if (!isSameTag) {
  3022. return false;
  3023. }
  3024. stack || (stack = new Stack);
  3025. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3026. }
  3027. /**
  3028. * The base implementation of `_.isMap` without Node.js optimizations.
  3029. *
  3030. * @private
  3031. * @param {*} value The value to check.
  3032. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3033. */
  3034. function baseIsMap(value) {
  3035. return isObjectLike(value) && getTag(value) == mapTag;
  3036. }
  3037. /**
  3038. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3039. *
  3040. * @private
  3041. * @param {Object} object The object to inspect.
  3042. * @param {Object} source The object of property values to match.
  3043. * @param {Array} matchData The property names, values, and compare flags to match.
  3044. * @param {Function} [customizer] The function to customize comparisons.
  3045. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3046. */
  3047. function baseIsMatch(object, source, matchData, customizer) {
  3048. var index = matchData.length,
  3049. length = index,
  3050. noCustomizer = !customizer;
  3051. if (object == null) {
  3052. return !length;
  3053. }
  3054. object = Object(object);
  3055. while (index--) {
  3056. var data = matchData[index];
  3057. if ((noCustomizer && data[2])
  3058. ? data[1] !== object[data[0]]
  3059. : !(data[0] in object)
  3060. ) {
  3061. return false;
  3062. }
  3063. }
  3064. while (++index < length) {
  3065. data = matchData[index];
  3066. var key = data[0],
  3067. objValue = object[key],
  3068. srcValue = data[1];
  3069. if (noCustomizer && data[2]) {
  3070. if (objValue === undefined && !(key in object)) {
  3071. return false;
  3072. }
  3073. } else {
  3074. var stack = new Stack;
  3075. if (customizer) {
  3076. var result = customizer(objValue, srcValue, key, object, source, stack);
  3077. }
  3078. if (!(result === undefined
  3079. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3080. : result
  3081. )) {
  3082. return false;
  3083. }
  3084. }
  3085. }
  3086. return true;
  3087. }
  3088. /**
  3089. * The base implementation of `_.isNative` without bad shim checks.
  3090. *
  3091. * @private
  3092. * @param {*} value The value to check.
  3093. * @returns {boolean} Returns `true` if `value` is a native function,
  3094. * else `false`.
  3095. */
  3096. function baseIsNative(value) {
  3097. if (!isObject(value) || isMasked(value)) {
  3098. return false;
  3099. }
  3100. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3101. return pattern.test(toSource(value));
  3102. }
  3103. /**
  3104. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3105. *
  3106. * @private
  3107. * @param {*} value The value to check.
  3108. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3109. */
  3110. function baseIsRegExp(value) {
  3111. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3112. }
  3113. /**
  3114. * The base implementation of `_.isSet` without Node.js optimizations.
  3115. *
  3116. * @private
  3117. * @param {*} value The value to check.
  3118. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3119. */
  3120. function baseIsSet(value) {
  3121. return isObjectLike(value) && getTag(value) == setTag;
  3122. }
  3123. /**
  3124. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3125. *
  3126. * @private
  3127. * @param {*} value The value to check.
  3128. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3129. */
  3130. function baseIsTypedArray(value) {
  3131. return isObjectLike(value) &&
  3132. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3133. }
  3134. /**
  3135. * The base implementation of `_.iteratee`.
  3136. *
  3137. * @private
  3138. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3139. * @returns {Function} Returns the iteratee.
  3140. */
  3141. function baseIteratee(value) {
  3142. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3143. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3144. if (typeof value == 'function') {
  3145. return value;
  3146. }
  3147. if (value == null) {
  3148. return identity;
  3149. }
  3150. if (typeof value == 'object') {
  3151. return isArray(value)
  3152. ? baseMatchesProperty(value[0], value[1])
  3153. : baseMatches(value);
  3154. }
  3155. return property(value);
  3156. }
  3157. /**
  3158. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3159. *
  3160. * @private
  3161. * @param {Object} object The object to query.
  3162. * @returns {Array} Returns the array of property names.
  3163. */
  3164. function baseKeys(object) {
  3165. if (!isPrototype(object)) {
  3166. return nativeKeys(object);
  3167. }
  3168. var result = [];
  3169. for (var key in Object(object)) {
  3170. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3171. result.push(key);
  3172. }
  3173. }
  3174. return result;
  3175. }
  3176. /**
  3177. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3178. *
  3179. * @private
  3180. * @param {Object} object The object to query.
  3181. * @returns {Array} Returns the array of property names.
  3182. */
  3183. function baseKeysIn(object) {
  3184. if (!isObject(object)) {
  3185. return nativeKeysIn(object);
  3186. }
  3187. var isProto = isPrototype(object),
  3188. result = [];
  3189. for (var key in object) {
  3190. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3191. result.push(key);
  3192. }
  3193. }
  3194. return result;
  3195. }
  3196. /**
  3197. * The base implementation of `_.lt` which doesn't coerce arguments.
  3198. *
  3199. * @private
  3200. * @param {*} value The value to compare.
  3201. * @param {*} other The other value to compare.
  3202. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3203. * else `false`.
  3204. */
  3205. function baseLt(value, other) {
  3206. return value < other;
  3207. }
  3208. /**
  3209. * The base implementation of `_.map` without support for iteratee shorthands.
  3210. *
  3211. * @private
  3212. * @param {Array|Object} collection The collection to iterate over.
  3213. * @param {Function} iteratee The function invoked per iteration.
  3214. * @returns {Array} Returns the new mapped array.
  3215. */
  3216. function baseMap(collection, iteratee) {
  3217. var index = -1,
  3218. result = isArrayLike(collection) ? Array(collection.length) : [];
  3219. baseEach(collection, function(value, key, collection) {
  3220. result[++index] = iteratee(value, key, collection);
  3221. });
  3222. return result;
  3223. }
  3224. /**
  3225. * The base implementation of `_.matches` which doesn't clone `source`.
  3226. *
  3227. * @private
  3228. * @param {Object} source The object of property values to match.
  3229. * @returns {Function} Returns the new spec function.
  3230. */
  3231. function baseMatches(source) {
  3232. var matchData = getMatchData(source);
  3233. if (matchData.length == 1 && matchData[0][2]) {
  3234. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3235. }
  3236. return function(object) {
  3237. return object === source || baseIsMatch(object, source, matchData);
  3238. };
  3239. }
  3240. /**
  3241. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3242. *
  3243. * @private
  3244. * @param {string} path The path of the property to get.
  3245. * @param {*} srcValue The value to match.
  3246. * @returns {Function} Returns the new spec function.
  3247. */
  3248. function baseMatchesProperty(path, srcValue) {
  3249. if (isKey(path) && isStrictComparable(srcValue)) {
  3250. return matchesStrictComparable(toKey(path), srcValue);
  3251. }
  3252. return function(object) {
  3253. var objValue = get(object, path);
  3254. return (objValue === undefined && objValue === srcValue)
  3255. ? hasIn(object, path)
  3256. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3257. };
  3258. }
  3259. /**
  3260. * The base implementation of `_.merge` without support for multiple sources.
  3261. *
  3262. * @private
  3263. * @param {Object} object The destination object.
  3264. * @param {Object} source The source object.
  3265. * @param {number} srcIndex The index of `source`.
  3266. * @param {Function} [customizer] The function to customize merged values.
  3267. * @param {Object} [stack] Tracks traversed source values and their merged
  3268. * counterparts.
  3269. */
  3270. function baseMerge(object, source, srcIndex, customizer, stack) {
  3271. if (object === source) {
  3272. return;
  3273. }
  3274. baseFor(source, function(srcValue, key) {
  3275. if (isObject(srcValue)) {
  3276. stack || (stack = new Stack);
  3277. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3278. }
  3279. else {
  3280. var newValue = customizer
  3281. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3282. : undefined;
  3283. if (newValue === undefined) {
  3284. newValue = srcValue;
  3285. }
  3286. assignMergeValue(object, key, newValue);
  3287. }
  3288. }, keysIn);
  3289. }
  3290. /**
  3291. * A specialized version of `baseMerge` for arrays and objects which performs
  3292. * deep merges and tracks traversed objects enabling objects with circular
  3293. * references to be merged.
  3294. *
  3295. * @private
  3296. * @param {Object} object The destination object.
  3297. * @param {Object} source The source object.
  3298. * @param {string} key The key of the value to merge.
  3299. * @param {number} srcIndex The index of `source`.
  3300. * @param {Function} mergeFunc The function to merge values.
  3301. * @param {Function} [customizer] The function to customize assigned values.
  3302. * @param {Object} [stack] Tracks traversed source values and their merged
  3303. * counterparts.
  3304. */
  3305. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3306. var objValue = safeGet(object, key),
  3307. srcValue = safeGet(source, key),
  3308. stacked = stack.get(srcValue);
  3309. if (stacked) {
  3310. assignMergeValue(object, key, stacked);
  3311. return;
  3312. }
  3313. var newValue = customizer
  3314. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3315. : undefined;
  3316. var isCommon = newValue === undefined;
  3317. if (isCommon) {
  3318. var isArr = isArray(srcValue),
  3319. isBuff = !isArr && isBuffer(srcValue),
  3320. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3321. newValue = srcValue;
  3322. if (isArr || isBuff || isTyped) {
  3323. if (isArray(objValue)) {
  3324. newValue = objValue;
  3325. }
  3326. else if (isArrayLikeObject(objValue)) {
  3327. newValue = copyArray(objValue);
  3328. }
  3329. else if (isBuff) {
  3330. isCommon = false;
  3331. newValue = cloneBuffer(srcValue, true);
  3332. }
  3333. else if (isTyped) {
  3334. isCommon = false;
  3335. newValue = cloneTypedArray(srcValue, true);
  3336. }
  3337. else {
  3338. newValue = [];
  3339. }
  3340. }
  3341. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3342. newValue = objValue;
  3343. if (isArguments(objValue)) {
  3344. newValue = toPlainObject(objValue);
  3345. }
  3346. else if (!isObject(objValue) || isFunction(objValue)) {
  3347. newValue = initCloneObject(srcValue);
  3348. }
  3349. }
  3350. else {
  3351. isCommon = false;
  3352. }
  3353. }
  3354. if (isCommon) {
  3355. // Recursively merge objects and arrays (susceptible to call stack limits).
  3356. stack.set(srcValue, newValue);
  3357. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3358. stack['delete'](srcValue);
  3359. }
  3360. assignMergeValue(object, key, newValue);
  3361. }
  3362. /**
  3363. * The base implementation of `_.nth` which doesn't coerce arguments.
  3364. *
  3365. * @private
  3366. * @param {Array} array The array to query.
  3367. * @param {number} n The index of the element to return.
  3368. * @returns {*} Returns the nth element of `array`.
  3369. */
  3370. function baseNth(array, n) {
  3371. var length = array.length;
  3372. if (!length) {
  3373. return;
  3374. }
  3375. n += n < 0 ? length : 0;
  3376. return isIndex(n, length) ? array[n] : undefined;
  3377. }
  3378. /**
  3379. * The base implementation of `_.orderBy` without param guards.
  3380. *
  3381. * @private
  3382. * @param {Array|Object} collection The collection to iterate over.
  3383. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3384. * @param {string[]} orders The sort orders of `iteratees`.
  3385. * @returns {Array} Returns the new sorted array.
  3386. */
  3387. function baseOrderBy(collection, iteratees, orders) {
  3388. var index = -1;
  3389. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3390. var result = baseMap(collection, function(value, key, collection) {
  3391. var criteria = arrayMap(iteratees, function(iteratee) {
  3392. return iteratee(value);
  3393. });
  3394. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3395. });
  3396. return baseSortBy(result, function(object, other) {
  3397. return compareMultiple(object, other, orders);
  3398. });
  3399. }
  3400. /**
  3401. * The base implementation of `_.pick` without support for individual
  3402. * property identifiers.
  3403. *
  3404. * @private
  3405. * @param {Object} object The source object.
  3406. * @param {string[]} paths The property paths to pick.
  3407. * @returns {Object} Returns the new object.
  3408. */
  3409. function basePick(object, paths) {
  3410. return basePickBy(object, paths, function(value, path) {
  3411. return hasIn(object, path);
  3412. });
  3413. }
  3414. /**
  3415. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3416. *
  3417. * @private
  3418. * @param {Object} object The source object.
  3419. * @param {string[]} paths The property paths to pick.
  3420. * @param {Function} predicate The function invoked per property.
  3421. * @returns {Object} Returns the new object.
  3422. */
  3423. function basePickBy(object, paths, predicate) {
  3424. var index = -1,
  3425. length = paths.length,
  3426. result = {};
  3427. while (++index < length) {
  3428. var path = paths[index],
  3429. value = baseGet(object, path);
  3430. if (predicate(value, path)) {
  3431. baseSet(result, castPath(path, object), value);
  3432. }
  3433. }
  3434. return result;
  3435. }
  3436. /**
  3437. * A specialized version of `baseProperty` which supports deep paths.
  3438. *
  3439. * @private
  3440. * @param {Array|string} path The path of the property to get.
  3441. * @returns {Function} Returns the new accessor function.
  3442. */
  3443. function basePropertyDeep(path) {
  3444. return function(object) {
  3445. return baseGet(object, path);
  3446. };
  3447. }
  3448. /**
  3449. * The base implementation of `_.pullAllBy` without support for iteratee
  3450. * shorthands.
  3451. *
  3452. * @private
  3453. * @param {Array} array The array to modify.
  3454. * @param {Array} values The values to remove.
  3455. * @param {Function} [iteratee] The iteratee invoked per element.
  3456. * @param {Function} [comparator] The comparator invoked per element.
  3457. * @returns {Array} Returns `array`.
  3458. */
  3459. function basePullAll(array, values, iteratee, comparator) {
  3460. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3461. index = -1,
  3462. length = values.length,
  3463. seen = array;
  3464. if (array === values) {
  3465. values = copyArray(values);
  3466. }
  3467. if (iteratee) {
  3468. seen = arrayMap(array, baseUnary(iteratee));
  3469. }
  3470. while (++index < length) {
  3471. var fromIndex = 0,
  3472. value = values[index],
  3473. computed = iteratee ? iteratee(value) : value;
  3474. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3475. if (seen !== array) {
  3476. splice.call(seen, fromIndex, 1);
  3477. }
  3478. splice.call(array, fromIndex, 1);
  3479. }
  3480. }
  3481. return array;
  3482. }
  3483. /**
  3484. * The base implementation of `_.pullAt` without support for individual
  3485. * indexes or capturing the removed elements.
  3486. *
  3487. * @private
  3488. * @param {Array} array The array to modify.
  3489. * @param {number[]} indexes The indexes of elements to remove.
  3490. * @returns {Array} Returns `array`.
  3491. */
  3492. function basePullAt(array, indexes) {
  3493. var length = array ? indexes.length : 0,
  3494. lastIndex = length - 1;
  3495. while (length--) {
  3496. var index = indexes[length];
  3497. if (length == lastIndex || index !== previous) {
  3498. var previous = index;
  3499. if (isIndex(index)) {
  3500. splice.call(array, index, 1);
  3501. } else {
  3502. baseUnset(array, index);
  3503. }
  3504. }
  3505. }
  3506. return array;
  3507. }
  3508. /**
  3509. * The base implementation of `_.random` without support for returning
  3510. * floating-point numbers.
  3511. *
  3512. * @private
  3513. * @param {number} lower The lower bound.
  3514. * @param {number} upper The upper bound.
  3515. * @returns {number} Returns the random number.
  3516. */
  3517. function baseRandom(lower, upper) {
  3518. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3519. }
  3520. /**
  3521. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3522. * coerce arguments.
  3523. *
  3524. * @private
  3525. * @param {number} start The start of the range.
  3526. * @param {number} end The end of the range.
  3527. * @param {number} step The value to increment or decrement by.
  3528. * @param {boolean} [fromRight] Specify iterating from right to left.
  3529. * @returns {Array} Returns the range of numbers.
  3530. */
  3531. function baseRange(start, end, step, fromRight) {
  3532. var index = -1,
  3533. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3534. result = Array(length);
  3535. while (length--) {
  3536. result[fromRight ? length : ++index] = start;
  3537. start += step;
  3538. }
  3539. return result;
  3540. }
  3541. /**
  3542. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3543. *
  3544. * @private
  3545. * @param {string} string The string to repeat.
  3546. * @param {number} n The number of times to repeat the string.
  3547. * @returns {string} Returns the repeated string.
  3548. */
  3549. function baseRepeat(string, n) {
  3550. var result = '';
  3551. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3552. return result;
  3553. }
  3554. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3555. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3556. do {
  3557. if (n % 2) {
  3558. result += string;
  3559. }
  3560. n = nativeFloor(n / 2);
  3561. if (n) {
  3562. string += string;
  3563. }
  3564. } while (n);
  3565. return result;
  3566. }
  3567. /**
  3568. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3569. *
  3570. * @private
  3571. * @param {Function} func The function to apply a rest parameter to.
  3572. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3573. * @returns {Function} Returns the new function.
  3574. */
  3575. function baseRest(func, start) {
  3576. return setToString(overRest(func, start, identity), func + '');
  3577. }
  3578. /**
  3579. * The base implementation of `_.sample`.
  3580. *
  3581. * @private
  3582. * @param {Array|Object} collection The collection to sample.
  3583. * @returns {*} Returns the random element.
  3584. */
  3585. function baseSample(collection) {
  3586. return arraySample(values(collection));
  3587. }
  3588. /**
  3589. * The base implementation of `_.sampleSize` without param guards.
  3590. *
  3591. * @private
  3592. * @param {Array|Object} collection The collection to sample.
  3593. * @param {number} n The number of elements to sample.
  3594. * @returns {Array} Returns the random elements.
  3595. */
  3596. function baseSampleSize(collection, n) {
  3597. var array = values(collection);
  3598. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3599. }
  3600. /**
  3601. * The base implementation of `_.set`.
  3602. *
  3603. * @private
  3604. * @param {Object} object The object to modify.
  3605. * @param {Array|string} path The path of the property to set.
  3606. * @param {*} value The value to set.
  3607. * @param {Function} [customizer] The function to customize path creation.
  3608. * @returns {Object} Returns `object`.
  3609. */
  3610. function baseSet(object, path, value, customizer) {
  3611. if (!isObject(object)) {
  3612. return object;
  3613. }
  3614. path = castPath(path, object);
  3615. var index = -1,
  3616. length = path.length,
  3617. lastIndex = length - 1,
  3618. nested = object;
  3619. while (nested != null && ++index < length) {
  3620. var key = toKey(path[index]),
  3621. newValue = value;
  3622. if (index != lastIndex) {
  3623. var objValue = nested[key];
  3624. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3625. if (newValue === undefined) {
  3626. newValue = isObject(objValue)
  3627. ? objValue
  3628. : (isIndex(path[index + 1]) ? [] : {});
  3629. }
  3630. }
  3631. assignValue(nested, key, newValue);
  3632. nested = nested[key];
  3633. }
  3634. return object;
  3635. }
  3636. /**
  3637. * The base implementation of `setData` without support for hot loop shorting.
  3638. *
  3639. * @private
  3640. * @param {Function} func The function to associate metadata with.
  3641. * @param {*} data The metadata.
  3642. * @returns {Function} Returns `func`.
  3643. */
  3644. var baseSetData = !metaMap ? identity : function(func, data) {
  3645. metaMap.set(func, data);
  3646. return func;
  3647. };
  3648. /**
  3649. * The base implementation of `setToString` without support for hot loop shorting.
  3650. *
  3651. * @private
  3652. * @param {Function} func The function to modify.
  3653. * @param {Function} string The `toString` result.
  3654. * @returns {Function} Returns `func`.
  3655. */
  3656. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3657. return defineProperty(func, 'toString', {
  3658. 'configurable': true,
  3659. 'enumerable': false,
  3660. 'value': constant(string),
  3661. 'writable': true
  3662. });
  3663. };
  3664. /**
  3665. * The base implementation of `_.shuffle`.
  3666. *
  3667. * @private
  3668. * @param {Array|Object} collection The collection to shuffle.
  3669. * @returns {Array} Returns the new shuffled array.
  3670. */
  3671. function baseShuffle(collection) {
  3672. return shuffleSelf(values(collection));
  3673. }
  3674. /**
  3675. * The base implementation of `_.slice` without an iteratee call guard.
  3676. *
  3677. * @private
  3678. * @param {Array} array The array to slice.
  3679. * @param {number} [start=0] The start position.
  3680. * @param {number} [end=array.length] The end position.
  3681. * @returns {Array} Returns the slice of `array`.
  3682. */
  3683. function baseSlice(array, start, end) {
  3684. var index = -1,
  3685. length = array.length;
  3686. if (start < 0) {
  3687. start = -start > length ? 0 : (length + start);
  3688. }
  3689. end = end > length ? length : end;
  3690. if (end < 0) {
  3691. end += length;
  3692. }
  3693. length = start > end ? 0 : ((end - start) >>> 0);
  3694. start >>>= 0;
  3695. var result = Array(length);
  3696. while (++index < length) {
  3697. result[index] = array[index + start];
  3698. }
  3699. return result;
  3700. }
  3701. /**
  3702. * The base implementation of `_.some` without support for iteratee shorthands.
  3703. *
  3704. * @private
  3705. * @param {Array|Object} collection The collection to iterate over.
  3706. * @param {Function} predicate The function invoked per iteration.
  3707. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3708. * else `false`.
  3709. */
  3710. function baseSome(collection, predicate) {
  3711. var result;
  3712. baseEach(collection, function(value, index, collection) {
  3713. result = predicate(value, index, collection);
  3714. return !result;
  3715. });
  3716. return !!result;
  3717. }
  3718. /**
  3719. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3720. * performs a binary search of `array` to determine the index at which `value`
  3721. * should be inserted into `array` in order to maintain its sort order.
  3722. *
  3723. * @private
  3724. * @param {Array} array The sorted array to inspect.
  3725. * @param {*} value The value to evaluate.
  3726. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3727. * @returns {number} Returns the index at which `value` should be inserted
  3728. * into `array`.
  3729. */
  3730. function baseSortedIndex(array, value, retHighest) {
  3731. var low = 0,
  3732. high = array == null ? low : array.length;
  3733. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3734. while (low < high) {
  3735. var mid = (low + high) >>> 1,
  3736. computed = array[mid];
  3737. if (computed !== null && !isSymbol(computed) &&
  3738. (retHighest ? (computed <= value) : (computed < value))) {
  3739. low = mid + 1;
  3740. } else {
  3741. high = mid;
  3742. }
  3743. }
  3744. return high;
  3745. }
  3746. return baseSortedIndexBy(array, value, identity, retHighest);
  3747. }
  3748. /**
  3749. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3750. * which invokes `iteratee` for `value` and each element of `array` to compute
  3751. * their sort ranking. The iteratee is invoked with one argument; (value).
  3752. *
  3753. * @private
  3754. * @param {Array} array The sorted array to inspect.
  3755. * @param {*} value The value to evaluate.
  3756. * @param {Function} iteratee The iteratee invoked per element.
  3757. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3758. * @returns {number} Returns the index at which `value` should be inserted
  3759. * into `array`.
  3760. */
  3761. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3762. value = iteratee(value);
  3763. var low = 0,
  3764. high = array == null ? 0 : array.length,
  3765. valIsNaN = value !== value,
  3766. valIsNull = value === null,
  3767. valIsSymbol = isSymbol(value),
  3768. valIsUndefined = value === undefined;
  3769. while (low < high) {
  3770. var mid = nativeFloor((low + high) / 2),
  3771. computed = iteratee(array[mid]),
  3772. othIsDefined = computed !== undefined,
  3773. othIsNull = computed === null,
  3774. othIsReflexive = computed === computed,
  3775. othIsSymbol = isSymbol(computed);
  3776. if (valIsNaN) {
  3777. var setLow = retHighest || othIsReflexive;
  3778. } else if (valIsUndefined) {
  3779. setLow = othIsReflexive && (retHighest || othIsDefined);
  3780. } else if (valIsNull) {
  3781. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3782. } else if (valIsSymbol) {
  3783. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3784. } else if (othIsNull || othIsSymbol) {
  3785. setLow = false;
  3786. } else {
  3787. setLow = retHighest ? (computed <= value) : (computed < value);
  3788. }
  3789. if (setLow) {
  3790. low = mid + 1;
  3791. } else {
  3792. high = mid;
  3793. }
  3794. }
  3795. return nativeMin(high, MAX_ARRAY_INDEX);
  3796. }
  3797. /**
  3798. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3799. * support for iteratee shorthands.
  3800. *
  3801. * @private
  3802. * @param {Array} array The array to inspect.
  3803. * @param {Function} [iteratee] The iteratee invoked per element.
  3804. * @returns {Array} Returns the new duplicate free array.
  3805. */
  3806. function baseSortedUniq(array, iteratee) {
  3807. var index = -1,
  3808. length = array.length,
  3809. resIndex = 0,
  3810. result = [];
  3811. while (++index < length) {
  3812. var value = array[index],
  3813. computed = iteratee ? iteratee(value) : value;
  3814. if (!index || !eq(computed, seen)) {
  3815. var seen = computed;
  3816. result[resIndex++] = value === 0 ? 0 : value;
  3817. }
  3818. }
  3819. return result;
  3820. }
  3821. /**
  3822. * The base implementation of `_.toNumber` which doesn't ensure correct
  3823. * conversions of binary, hexadecimal, or octal string values.
  3824. *
  3825. * @private
  3826. * @param {*} value The value to process.
  3827. * @returns {number} Returns the number.
  3828. */
  3829. function baseToNumber(value) {
  3830. if (typeof value == 'number') {
  3831. return value;
  3832. }
  3833. if (isSymbol(value)) {
  3834. return NAN;
  3835. }
  3836. return +value;
  3837. }
  3838. /**
  3839. * The base implementation of `_.toString` which doesn't convert nullish
  3840. * values to empty strings.
  3841. *
  3842. * @private
  3843. * @param {*} value The value to process.
  3844. * @returns {string} Returns the string.
  3845. */
  3846. function baseToString(value) {
  3847. // Exit early for strings to avoid a performance hit in some environments.
  3848. if (typeof value == 'string') {
  3849. return value;
  3850. }
  3851. if (isArray(value)) {
  3852. // Recursively convert values (susceptible to call stack limits).
  3853. return arrayMap(value, baseToString) + '';
  3854. }
  3855. if (isSymbol(value)) {
  3856. return symbolToString ? symbolToString.call(value) : '';
  3857. }
  3858. var result = (value + '');
  3859. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3860. }
  3861. /**
  3862. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3863. *
  3864. * @private
  3865. * @param {Array} array The array to inspect.
  3866. * @param {Function} [iteratee] The iteratee invoked per element.
  3867. * @param {Function} [comparator] The comparator invoked per element.
  3868. * @returns {Array} Returns the new duplicate free array.
  3869. */
  3870. function baseUniq(array, iteratee, comparator) {
  3871. var index = -1,
  3872. includes = arrayIncludes,
  3873. length = array.length,
  3874. isCommon = true,
  3875. result = [],
  3876. seen = result;
  3877. if (comparator) {
  3878. isCommon = false;
  3879. includes = arrayIncludesWith;
  3880. }
  3881. else if (length >= LARGE_ARRAY_SIZE) {
  3882. var set = iteratee ? null : createSet(array);
  3883. if (set) {
  3884. return setToArray(set);
  3885. }
  3886. isCommon = false;
  3887. includes = cacheHas;
  3888. seen = new SetCache;
  3889. }
  3890. else {
  3891. seen = iteratee ? [] : result;
  3892. }
  3893. outer:
  3894. while (++index < length) {
  3895. var value = array[index],
  3896. computed = iteratee ? iteratee(value) : value;
  3897. value = (comparator || value !== 0) ? value : 0;
  3898. if (isCommon && computed === computed) {
  3899. var seenIndex = seen.length;
  3900. while (seenIndex--) {
  3901. if (seen[seenIndex] === computed) {
  3902. continue outer;
  3903. }
  3904. }
  3905. if (iteratee) {
  3906. seen.push(computed);
  3907. }
  3908. result.push(value);
  3909. }
  3910. else if (!includes(seen, computed, comparator)) {
  3911. if (seen !== result) {
  3912. seen.push(computed);
  3913. }
  3914. result.push(value);
  3915. }
  3916. }
  3917. return result;
  3918. }
  3919. /**
  3920. * The base implementation of `_.unset`.
  3921. *
  3922. * @private
  3923. * @param {Object} object The object to modify.
  3924. * @param {Array|string} path The property path to unset.
  3925. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3926. */
  3927. function baseUnset(object, path) {
  3928. path = castPath(path, object);
  3929. object = parent(object, path);
  3930. return object == null || delete object[toKey(last(path))];
  3931. }
  3932. /**
  3933. * The base implementation of `_.update`.
  3934. *
  3935. * @private
  3936. * @param {Object} object The object to modify.
  3937. * @param {Array|string} path The path of the property to update.
  3938. * @param {Function} updater The function to produce the updated value.
  3939. * @param {Function} [customizer] The function to customize path creation.
  3940. * @returns {Object} Returns `object`.
  3941. */
  3942. function baseUpdate(object, path, updater, customizer) {
  3943. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3944. }
  3945. /**
  3946. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3947. * without support for iteratee shorthands.
  3948. *
  3949. * @private
  3950. * @param {Array} array The array to query.
  3951. * @param {Function} predicate The function invoked per iteration.
  3952. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3953. * @param {boolean} [fromRight] Specify iterating from right to left.
  3954. * @returns {Array} Returns the slice of `array`.
  3955. */
  3956. function baseWhile(array, predicate, isDrop, fromRight) {
  3957. var length = array.length,
  3958. index = fromRight ? length : -1;
  3959. while ((fromRight ? index-- : ++index < length) &&
  3960. predicate(array[index], index, array)) {}
  3961. return isDrop
  3962. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3963. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3964. }
  3965. /**
  3966. * The base implementation of `wrapperValue` which returns the result of
  3967. * performing a sequence of actions on the unwrapped `value`, where each
  3968. * successive action is supplied the return value of the previous.
  3969. *
  3970. * @private
  3971. * @param {*} value The unwrapped value.
  3972. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3973. * @returns {*} Returns the resolved value.
  3974. */
  3975. function baseWrapperValue(value, actions) {
  3976. var result = value;
  3977. if (result instanceof LazyWrapper) {
  3978. result = result.value();
  3979. }
  3980. return arrayReduce(actions, function(result, action) {
  3981. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3982. }, result);
  3983. }
  3984. /**
  3985. * The base implementation of methods like `_.xor`, without support for
  3986. * iteratee shorthands, that accepts an array of arrays to inspect.
  3987. *
  3988. * @private
  3989. * @param {Array} arrays The arrays to inspect.
  3990. * @param {Function} [iteratee] The iteratee invoked per element.
  3991. * @param {Function} [comparator] The comparator invoked per element.
  3992. * @returns {Array} Returns the new array of values.
  3993. */
  3994. function baseXor(arrays, iteratee, comparator) {
  3995. var length = arrays.length;
  3996. if (length < 2) {
  3997. return length ? baseUniq(arrays[0]) : [];
  3998. }
  3999. var index = -1,
  4000. result = Array(length);
  4001. while (++index < length) {
  4002. var array = arrays[index],
  4003. othIndex = -1;
  4004. while (++othIndex < length) {
  4005. if (othIndex != index) {
  4006. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4007. }
  4008. }
  4009. }
  4010. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4011. }
  4012. /**
  4013. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4014. *
  4015. * @private
  4016. * @param {Array} props The property identifiers.
  4017. * @param {Array} values The property values.
  4018. * @param {Function} assignFunc The function to assign values.
  4019. * @returns {Object} Returns the new object.
  4020. */
  4021. function baseZipObject(props, values, assignFunc) {
  4022. var index = -1,
  4023. length = props.length,
  4024. valsLength = values.length,
  4025. result = {};
  4026. while (++index < length) {
  4027. var value = index < valsLength ? values[index] : undefined;
  4028. assignFunc(result, props[index], value);
  4029. }
  4030. return result;
  4031. }
  4032. /**
  4033. * Casts `value` to an empty array if it's not an array like object.
  4034. *
  4035. * @private
  4036. * @param {*} value The value to inspect.
  4037. * @returns {Array|Object} Returns the cast array-like object.
  4038. */
  4039. function castArrayLikeObject(value) {
  4040. return isArrayLikeObject(value) ? value : [];
  4041. }
  4042. /**
  4043. * Casts `value` to `identity` if it's not a function.
  4044. *
  4045. * @private
  4046. * @param {*} value The value to inspect.
  4047. * @returns {Function} Returns cast function.
  4048. */
  4049. function castFunction(value) {
  4050. return typeof value == 'function' ? value : identity;
  4051. }
  4052. /**
  4053. * Casts `value` to a path array if it's not one.
  4054. *
  4055. * @private
  4056. * @param {*} value The value to inspect.
  4057. * @param {Object} [object] The object to query keys on.
  4058. * @returns {Array} Returns the cast property path array.
  4059. */
  4060. function castPath(value, object) {
  4061. if (isArray(value)) {
  4062. return value;
  4063. }
  4064. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4065. }
  4066. /**
  4067. * A `baseRest` alias which can be replaced with `identity` by module
  4068. * replacement plugins.
  4069. *
  4070. * @private
  4071. * @type {Function}
  4072. * @param {Function} func The function to apply a rest parameter to.
  4073. * @returns {Function} Returns the new function.
  4074. */
  4075. var castRest = baseRest;
  4076. /**
  4077. * Casts `array` to a slice if it's needed.
  4078. *
  4079. * @private
  4080. * @param {Array} array The array to inspect.
  4081. * @param {number} start The start position.
  4082. * @param {number} [end=array.length] The end position.
  4083. * @returns {Array} Returns the cast slice.
  4084. */
  4085. function castSlice(array, start, end) {
  4086. var length = array.length;
  4087. end = end === undefined ? length : end;
  4088. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4089. }
  4090. /**
  4091. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4092. *
  4093. * @private
  4094. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4095. */
  4096. var clearTimeout = ctxClearTimeout || function(id) {
  4097. return root.clearTimeout(id);
  4098. };
  4099. /**
  4100. * Creates a clone of `buffer`.
  4101. *
  4102. * @private
  4103. * @param {Buffer} buffer The buffer to clone.
  4104. * @param {boolean} [isDeep] Specify a deep clone.
  4105. * @returns {Buffer} Returns the cloned buffer.
  4106. */
  4107. function cloneBuffer(buffer, isDeep) {
  4108. if (isDeep) {
  4109. return buffer.slice();
  4110. }
  4111. var length = buffer.length,
  4112. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4113. buffer.copy(result);
  4114. return result;
  4115. }
  4116. /**
  4117. * Creates a clone of `arrayBuffer`.
  4118. *
  4119. * @private
  4120. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4121. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4122. */
  4123. function cloneArrayBuffer(arrayBuffer) {
  4124. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4125. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4126. return result;
  4127. }
  4128. /**
  4129. * Creates a clone of `dataView`.
  4130. *
  4131. * @private
  4132. * @param {Object} dataView The data view to clone.
  4133. * @param {boolean} [isDeep] Specify a deep clone.
  4134. * @returns {Object} Returns the cloned data view.
  4135. */
  4136. function cloneDataView(dataView, isDeep) {
  4137. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4138. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4139. }
  4140. /**
  4141. * Creates a clone of `regexp`.
  4142. *
  4143. * @private
  4144. * @param {Object} regexp The regexp to clone.
  4145. * @returns {Object} Returns the cloned regexp.
  4146. */
  4147. function cloneRegExp(regexp) {
  4148. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4149. result.lastIndex = regexp.lastIndex;
  4150. return result;
  4151. }
  4152. /**
  4153. * Creates a clone of the `symbol` object.
  4154. *
  4155. * @private
  4156. * @param {Object} symbol The symbol object to clone.
  4157. * @returns {Object} Returns the cloned symbol object.
  4158. */
  4159. function cloneSymbol(symbol) {
  4160. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4161. }
  4162. /**
  4163. * Creates a clone of `typedArray`.
  4164. *
  4165. * @private
  4166. * @param {Object} typedArray The typed array to clone.
  4167. * @param {boolean} [isDeep] Specify a deep clone.
  4168. * @returns {Object} Returns the cloned typed array.
  4169. */
  4170. function cloneTypedArray(typedArray, isDeep) {
  4171. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4172. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4173. }
  4174. /**
  4175. * Compares values to sort them in ascending order.
  4176. *
  4177. * @private
  4178. * @param {*} value The value to compare.
  4179. * @param {*} other The other value to compare.
  4180. * @returns {number} Returns the sort order indicator for `value`.
  4181. */
  4182. function compareAscending(value, other) {
  4183. if (value !== other) {
  4184. var valIsDefined = value !== undefined,
  4185. valIsNull = value === null,
  4186. valIsReflexive = value === value,
  4187. valIsSymbol = isSymbol(value);
  4188. var othIsDefined = other !== undefined,
  4189. othIsNull = other === null,
  4190. othIsReflexive = other === other,
  4191. othIsSymbol = isSymbol(other);
  4192. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4193. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4194. (valIsNull && othIsDefined && othIsReflexive) ||
  4195. (!valIsDefined && othIsReflexive) ||
  4196. !valIsReflexive) {
  4197. return 1;
  4198. }
  4199. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4200. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4201. (othIsNull && valIsDefined && valIsReflexive) ||
  4202. (!othIsDefined && valIsReflexive) ||
  4203. !othIsReflexive) {
  4204. return -1;
  4205. }
  4206. }
  4207. return 0;
  4208. }
  4209. /**
  4210. * Used by `_.orderBy` to compare multiple properties of a value to another
  4211. * and stable sort them.
  4212. *
  4213. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4214. * specify an order of "desc" for descending or "asc" for ascending sort order
  4215. * of corresponding values.
  4216. *
  4217. * @private
  4218. * @param {Object} object The object to compare.
  4219. * @param {Object} other The other object to compare.
  4220. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4221. * @returns {number} Returns the sort order indicator for `object`.
  4222. */
  4223. function compareMultiple(object, other, orders) {
  4224. var index = -1,
  4225. objCriteria = object.criteria,
  4226. othCriteria = other.criteria,
  4227. length = objCriteria.length,
  4228. ordersLength = orders.length;
  4229. while (++index < length) {
  4230. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4231. if (result) {
  4232. if (index >= ordersLength) {
  4233. return result;
  4234. }
  4235. var order = orders[index];
  4236. return result * (order == 'desc' ? -1 : 1);
  4237. }
  4238. }
  4239. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4240. // that causes it, under certain circumstances, to provide the same value for
  4241. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4242. // for more details.
  4243. //
  4244. // This also ensures a stable sort in V8 and other engines.
  4245. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4246. return object.index - other.index;
  4247. }
  4248. /**
  4249. * Creates an array that is the composition of partially applied arguments,
  4250. * placeholders, and provided arguments into a single array of arguments.
  4251. *
  4252. * @private
  4253. * @param {Array} args The provided arguments.
  4254. * @param {Array} partials The arguments to prepend to those provided.
  4255. * @param {Array} holders The `partials` placeholder indexes.
  4256. * @params {boolean} [isCurried] Specify composing for a curried function.
  4257. * @returns {Array} Returns the new array of composed arguments.
  4258. */
  4259. function composeArgs(args, partials, holders, isCurried) {
  4260. var argsIndex = -1,
  4261. argsLength = args.length,
  4262. holdersLength = holders.length,
  4263. leftIndex = -1,
  4264. leftLength = partials.length,
  4265. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4266. result = Array(leftLength + rangeLength),
  4267. isUncurried = !isCurried;
  4268. while (++leftIndex < leftLength) {
  4269. result[leftIndex] = partials[leftIndex];
  4270. }
  4271. while (++argsIndex < holdersLength) {
  4272. if (isUncurried || argsIndex < argsLength) {
  4273. result[holders[argsIndex]] = args[argsIndex];
  4274. }
  4275. }
  4276. while (rangeLength--) {
  4277. result[leftIndex++] = args[argsIndex++];
  4278. }
  4279. return result;
  4280. }
  4281. /**
  4282. * This function is like `composeArgs` except that the arguments composition
  4283. * is tailored for `_.partialRight`.
  4284. *
  4285. * @private
  4286. * @param {Array} args The provided arguments.
  4287. * @param {Array} partials The arguments to append to those provided.
  4288. * @param {Array} holders The `partials` placeholder indexes.
  4289. * @params {boolean} [isCurried] Specify composing for a curried function.
  4290. * @returns {Array} Returns the new array of composed arguments.
  4291. */
  4292. function composeArgsRight(args, partials, holders, isCurried) {
  4293. var argsIndex = -1,
  4294. argsLength = args.length,
  4295. holdersIndex = -1,
  4296. holdersLength = holders.length,
  4297. rightIndex = -1,
  4298. rightLength = partials.length,
  4299. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4300. result = Array(rangeLength + rightLength),
  4301. isUncurried = !isCurried;
  4302. while (++argsIndex < rangeLength) {
  4303. result[argsIndex] = args[argsIndex];
  4304. }
  4305. var offset = argsIndex;
  4306. while (++rightIndex < rightLength) {
  4307. result[offset + rightIndex] = partials[rightIndex];
  4308. }
  4309. while (++holdersIndex < holdersLength) {
  4310. if (isUncurried || argsIndex < argsLength) {
  4311. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4312. }
  4313. }
  4314. return result;
  4315. }
  4316. /**
  4317. * Copies the values of `source` to `array`.
  4318. *
  4319. * @private
  4320. * @param {Array} source The array to copy values from.
  4321. * @param {Array} [array=[]] The array to copy values to.
  4322. * @returns {Array} Returns `array`.
  4323. */
  4324. function copyArray(source, array) {
  4325. var index = -1,
  4326. length = source.length;
  4327. array || (array = Array(length));
  4328. while (++index < length) {
  4329. array[index] = source[index];
  4330. }
  4331. return array;
  4332. }
  4333. /**
  4334. * Copies properties of `source` to `object`.
  4335. *
  4336. * @private
  4337. * @param {Object} source The object to copy properties from.
  4338. * @param {Array} props The property identifiers to copy.
  4339. * @param {Object} [object={}] The object to copy properties to.
  4340. * @param {Function} [customizer] The function to customize copied values.
  4341. * @returns {Object} Returns `object`.
  4342. */
  4343. function copyObject(source, props, object, customizer) {
  4344. var isNew = !object;
  4345. object || (object = {});
  4346. var index = -1,
  4347. length = props.length;
  4348. while (++index < length) {
  4349. var key = props[index];
  4350. var newValue = customizer
  4351. ? customizer(object[key], source[key], key, object, source)
  4352. : undefined;
  4353. if (newValue === undefined) {
  4354. newValue = source[key];
  4355. }
  4356. if (isNew) {
  4357. baseAssignValue(object, key, newValue);
  4358. } else {
  4359. assignValue(object, key, newValue);
  4360. }
  4361. }
  4362. return object;
  4363. }
  4364. /**
  4365. * Copies own symbols of `source` to `object`.
  4366. *
  4367. * @private
  4368. * @param {Object} source The object to copy symbols from.
  4369. * @param {Object} [object={}] The object to copy symbols to.
  4370. * @returns {Object} Returns `object`.
  4371. */
  4372. function copySymbols(source, object) {
  4373. return copyObject(source, getSymbols(source), object);
  4374. }
  4375. /**
  4376. * Copies own and inherited symbols of `source` to `object`.
  4377. *
  4378. * @private
  4379. * @param {Object} source The object to copy symbols from.
  4380. * @param {Object} [object={}] The object to copy symbols to.
  4381. * @returns {Object} Returns `object`.
  4382. */
  4383. function copySymbolsIn(source, object) {
  4384. return copyObject(source, getSymbolsIn(source), object);
  4385. }
  4386. /**
  4387. * Creates a function like `_.groupBy`.
  4388. *
  4389. * @private
  4390. * @param {Function} setter The function to set accumulator values.
  4391. * @param {Function} [initializer] The accumulator object initializer.
  4392. * @returns {Function} Returns the new aggregator function.
  4393. */
  4394. function createAggregator(setter, initializer) {
  4395. return function(collection, iteratee) {
  4396. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4397. accumulator = initializer ? initializer() : {};
  4398. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4399. };
  4400. }
  4401. /**
  4402. * Creates a function like `_.assign`.
  4403. *
  4404. * @private
  4405. * @param {Function} assigner The function to assign values.
  4406. * @returns {Function} Returns the new assigner function.
  4407. */
  4408. function createAssigner(assigner) {
  4409. return baseRest(function(object, sources) {
  4410. var index = -1,
  4411. length = sources.length,
  4412. customizer = length > 1 ? sources[length - 1] : undefined,
  4413. guard = length > 2 ? sources[2] : undefined;
  4414. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4415. ? (length--, customizer)
  4416. : undefined;
  4417. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4418. customizer = length < 3 ? undefined : customizer;
  4419. length = 1;
  4420. }
  4421. object = Object(object);
  4422. while (++index < length) {
  4423. var source = sources[index];
  4424. if (source) {
  4425. assigner(object, source, index, customizer);
  4426. }
  4427. }
  4428. return object;
  4429. });
  4430. }
  4431. /**
  4432. * Creates a `baseEach` or `baseEachRight` function.
  4433. *
  4434. * @private
  4435. * @param {Function} eachFunc The function to iterate over a collection.
  4436. * @param {boolean} [fromRight] Specify iterating from right to left.
  4437. * @returns {Function} Returns the new base function.
  4438. */
  4439. function createBaseEach(eachFunc, fromRight) {
  4440. return function(collection, iteratee) {
  4441. if (collection == null) {
  4442. return collection;
  4443. }
  4444. if (!isArrayLike(collection)) {
  4445. return eachFunc(collection, iteratee);
  4446. }
  4447. var length = collection.length,
  4448. index = fromRight ? length : -1,
  4449. iterable = Object(collection);
  4450. while ((fromRight ? index-- : ++index < length)) {
  4451. if (iteratee(iterable[index], index, iterable) === false) {
  4452. break;
  4453. }
  4454. }
  4455. return collection;
  4456. };
  4457. }
  4458. /**
  4459. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4460. *
  4461. * @private
  4462. * @param {boolean} [fromRight] Specify iterating from right to left.
  4463. * @returns {Function} Returns the new base function.
  4464. */
  4465. function createBaseFor(fromRight) {
  4466. return function(object, iteratee, keysFunc) {
  4467. var index = -1,
  4468. iterable = Object(object),
  4469. props = keysFunc(object),
  4470. length = props.length;
  4471. while (length--) {
  4472. var key = props[fromRight ? length : ++index];
  4473. if (iteratee(iterable[key], key, iterable) === false) {
  4474. break;
  4475. }
  4476. }
  4477. return object;
  4478. };
  4479. }
  4480. /**
  4481. * Creates a function that wraps `func` to invoke it with the optional `this`
  4482. * binding of `thisArg`.
  4483. *
  4484. * @private
  4485. * @param {Function} func The function to wrap.
  4486. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4487. * @param {*} [thisArg] The `this` binding of `func`.
  4488. * @returns {Function} Returns the new wrapped function.
  4489. */
  4490. function createBind(func, bitmask, thisArg) {
  4491. var isBind = bitmask & WRAP_BIND_FLAG,
  4492. Ctor = createCtor(func);
  4493. function wrapper() {
  4494. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4495. return fn.apply(isBind ? thisArg : this, arguments);
  4496. }
  4497. return wrapper;
  4498. }
  4499. /**
  4500. * Creates a function like `_.lowerFirst`.
  4501. *
  4502. * @private
  4503. * @param {string} methodName The name of the `String` case method to use.
  4504. * @returns {Function} Returns the new case function.
  4505. */
  4506. function createCaseFirst(methodName) {
  4507. return function(string) {
  4508. string = toString(string);
  4509. var strSymbols = hasUnicode(string)
  4510. ? stringToArray(string)
  4511. : undefined;
  4512. var chr = strSymbols
  4513. ? strSymbols[0]
  4514. : string.charAt(0);
  4515. var trailing = strSymbols
  4516. ? castSlice(strSymbols, 1).join('')
  4517. : string.slice(1);
  4518. return chr[methodName]() + trailing;
  4519. };
  4520. }
  4521. /**
  4522. * Creates a function like `_.camelCase`.
  4523. *
  4524. * @private
  4525. * @param {Function} callback The function to combine each word.
  4526. * @returns {Function} Returns the new compounder function.
  4527. */
  4528. function createCompounder(callback) {
  4529. return function(string) {
  4530. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4531. };
  4532. }
  4533. /**
  4534. * Creates a function that produces an instance of `Ctor` regardless of
  4535. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4536. *
  4537. * @private
  4538. * @param {Function} Ctor The constructor to wrap.
  4539. * @returns {Function} Returns the new wrapped function.
  4540. */
  4541. function createCtor(Ctor) {
  4542. return function() {
  4543. // Use a `switch` statement to work with class constructors. See
  4544. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4545. // for more details.
  4546. var args = arguments;
  4547. switch (args.length) {
  4548. case 0: return new Ctor;
  4549. case 1: return new Ctor(args[0]);
  4550. case 2: return new Ctor(args[0], args[1]);
  4551. case 3: return new Ctor(args[0], args[1], args[2]);
  4552. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4553. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4554. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4555. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4556. }
  4557. var thisBinding = baseCreate(Ctor.prototype),
  4558. result = Ctor.apply(thisBinding, args);
  4559. // Mimic the constructor's `return` behavior.
  4560. // See https://es5.github.io/#x13.2.2 for more details.
  4561. return isObject(result) ? result : thisBinding;
  4562. };
  4563. }
  4564. /**
  4565. * Creates a function that wraps `func` to enable currying.
  4566. *
  4567. * @private
  4568. * @param {Function} func The function to wrap.
  4569. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4570. * @param {number} arity The arity of `func`.
  4571. * @returns {Function} Returns the new wrapped function.
  4572. */
  4573. function createCurry(func, bitmask, arity) {
  4574. var Ctor = createCtor(func);
  4575. function wrapper() {
  4576. var length = arguments.length,
  4577. args = Array(length),
  4578. index = length,
  4579. placeholder = getHolder(wrapper);
  4580. while (index--) {
  4581. args[index] = arguments[index];
  4582. }
  4583. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4584. ? []
  4585. : replaceHolders(args, placeholder);
  4586. length -= holders.length;
  4587. if (length < arity) {
  4588. return createRecurry(
  4589. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4590. args, holders, undefined, undefined, arity - length);
  4591. }
  4592. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4593. return apply(fn, this, args);
  4594. }
  4595. return wrapper;
  4596. }
  4597. /**
  4598. * Creates a `_.find` or `_.findLast` function.
  4599. *
  4600. * @private
  4601. * @param {Function} findIndexFunc The function to find the collection index.
  4602. * @returns {Function} Returns the new find function.
  4603. */
  4604. function createFind(findIndexFunc) {
  4605. return function(collection, predicate, fromIndex) {
  4606. var iterable = Object(collection);
  4607. if (!isArrayLike(collection)) {
  4608. var iteratee = getIteratee(predicate, 3);
  4609. collection = keys(collection);
  4610. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4611. }
  4612. var index = findIndexFunc(collection, predicate, fromIndex);
  4613. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4614. };
  4615. }
  4616. /**
  4617. * Creates a `_.flow` or `_.flowRight` function.
  4618. *
  4619. * @private
  4620. * @param {boolean} [fromRight] Specify iterating from right to left.
  4621. * @returns {Function} Returns the new flow function.
  4622. */
  4623. function createFlow(fromRight) {
  4624. return flatRest(function(funcs) {
  4625. var length = funcs.length,
  4626. index = length,
  4627. prereq = LodashWrapper.prototype.thru;
  4628. if (fromRight) {
  4629. funcs.reverse();
  4630. }
  4631. while (index--) {
  4632. var func = funcs[index];
  4633. if (typeof func != 'function') {
  4634. throw new TypeError(FUNC_ERROR_TEXT);
  4635. }
  4636. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4637. var wrapper = new LodashWrapper([], true);
  4638. }
  4639. }
  4640. index = wrapper ? index : length;
  4641. while (++index < length) {
  4642. func = funcs[index];
  4643. var funcName = getFuncName(func),
  4644. data = funcName == 'wrapper' ? getData(func) : undefined;
  4645. if (data && isLaziable(data[0]) &&
  4646. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4647. !data[4].length && data[9] == 1
  4648. ) {
  4649. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4650. } else {
  4651. wrapper = (func.length == 1 && isLaziable(func))
  4652. ? wrapper[funcName]()
  4653. : wrapper.thru(func);
  4654. }
  4655. }
  4656. return function() {
  4657. var args = arguments,
  4658. value = args[0];
  4659. if (wrapper && args.length == 1 && isArray(value)) {
  4660. return wrapper.plant(value).value();
  4661. }
  4662. var index = 0,
  4663. result = length ? funcs[index].apply(this, args) : value;
  4664. while (++index < length) {
  4665. result = funcs[index].call(this, result);
  4666. }
  4667. return result;
  4668. };
  4669. });
  4670. }
  4671. /**
  4672. * Creates a function that wraps `func` to invoke it with optional `this`
  4673. * binding of `thisArg`, partial application, and currying.
  4674. *
  4675. * @private
  4676. * @param {Function|string} func The function or method name to wrap.
  4677. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4678. * @param {*} [thisArg] The `this` binding of `func`.
  4679. * @param {Array} [partials] The arguments to prepend to those provided to
  4680. * the new function.
  4681. * @param {Array} [holders] The `partials` placeholder indexes.
  4682. * @param {Array} [partialsRight] The arguments to append to those provided
  4683. * to the new function.
  4684. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4685. * @param {Array} [argPos] The argument positions of the new function.
  4686. * @param {number} [ary] The arity cap of `func`.
  4687. * @param {number} [arity] The arity of `func`.
  4688. * @returns {Function} Returns the new wrapped function.
  4689. */
  4690. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4691. var isAry = bitmask & WRAP_ARY_FLAG,
  4692. isBind = bitmask & WRAP_BIND_FLAG,
  4693. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4694. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4695. isFlip = bitmask & WRAP_FLIP_FLAG,
  4696. Ctor = isBindKey ? undefined : createCtor(func);
  4697. function wrapper() {
  4698. var length = arguments.length,
  4699. args = Array(length),
  4700. index = length;
  4701. while (index--) {
  4702. args[index] = arguments[index];
  4703. }
  4704. if (isCurried) {
  4705. var placeholder = getHolder(wrapper),
  4706. holdersCount = countHolders(args, placeholder);
  4707. }
  4708. if (partials) {
  4709. args = composeArgs(args, partials, holders, isCurried);
  4710. }
  4711. if (partialsRight) {
  4712. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4713. }
  4714. length -= holdersCount;
  4715. if (isCurried && length < arity) {
  4716. var newHolders = replaceHolders(args, placeholder);
  4717. return createRecurry(
  4718. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4719. args, newHolders, argPos, ary, arity - length
  4720. );
  4721. }
  4722. var thisBinding = isBind ? thisArg : this,
  4723. fn = isBindKey ? thisBinding[func] : func;
  4724. length = args.length;
  4725. if (argPos) {
  4726. args = reorder(args, argPos);
  4727. } else if (isFlip && length > 1) {
  4728. args.reverse();
  4729. }
  4730. if (isAry && ary < length) {
  4731. args.length = ary;
  4732. }
  4733. if (this && this !== root && this instanceof wrapper) {
  4734. fn = Ctor || createCtor(fn);
  4735. }
  4736. return fn.apply(thisBinding, args);
  4737. }
  4738. return wrapper;
  4739. }
  4740. /**
  4741. * Creates a function like `_.invertBy`.
  4742. *
  4743. * @private
  4744. * @param {Function} setter The function to set accumulator values.
  4745. * @param {Function} toIteratee The function to resolve iteratees.
  4746. * @returns {Function} Returns the new inverter function.
  4747. */
  4748. function createInverter(setter, toIteratee) {
  4749. return function(object, iteratee) {
  4750. return baseInverter(object, setter, toIteratee(iteratee), {});
  4751. };
  4752. }
  4753. /**
  4754. * Creates a function that performs a mathematical operation on two values.
  4755. *
  4756. * @private
  4757. * @param {Function} operator The function to perform the operation.
  4758. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4759. * @returns {Function} Returns the new mathematical operation function.
  4760. */
  4761. function createMathOperation(operator, defaultValue) {
  4762. return function(value, other) {
  4763. var result;
  4764. if (value === undefined && other === undefined) {
  4765. return defaultValue;
  4766. }
  4767. if (value !== undefined) {
  4768. result = value;
  4769. }
  4770. if (other !== undefined) {
  4771. if (result === undefined) {
  4772. return other;
  4773. }
  4774. if (typeof value == 'string' || typeof other == 'string') {
  4775. value = baseToString(value);
  4776. other = baseToString(other);
  4777. } else {
  4778. value = baseToNumber(value);
  4779. other = baseToNumber(other);
  4780. }
  4781. result = operator(value, other);
  4782. }
  4783. return result;
  4784. };
  4785. }
  4786. /**
  4787. * Creates a function like `_.over`.
  4788. *
  4789. * @private
  4790. * @param {Function} arrayFunc The function to iterate over iteratees.
  4791. * @returns {Function} Returns the new over function.
  4792. */
  4793. function createOver(arrayFunc) {
  4794. return flatRest(function(iteratees) {
  4795. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4796. return baseRest(function(args) {
  4797. var thisArg = this;
  4798. return arrayFunc(iteratees, function(iteratee) {
  4799. return apply(iteratee, thisArg, args);
  4800. });
  4801. });
  4802. });
  4803. }
  4804. /**
  4805. * Creates the padding for `string` based on `length`. The `chars` string
  4806. * is truncated if the number of characters exceeds `length`.
  4807. *
  4808. * @private
  4809. * @param {number} length The padding length.
  4810. * @param {string} [chars=' '] The string used as padding.
  4811. * @returns {string} Returns the padding for `string`.
  4812. */
  4813. function createPadding(length, chars) {
  4814. chars = chars === undefined ? ' ' : baseToString(chars);
  4815. var charsLength = chars.length;
  4816. if (charsLength < 2) {
  4817. return charsLength ? baseRepeat(chars, length) : chars;
  4818. }
  4819. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4820. return hasUnicode(chars)
  4821. ? castSlice(stringToArray(result), 0, length).join('')
  4822. : result.slice(0, length);
  4823. }
  4824. /**
  4825. * Creates a function that wraps `func` to invoke it with the `this` binding
  4826. * of `thisArg` and `partials` prepended to the arguments it receives.
  4827. *
  4828. * @private
  4829. * @param {Function} func The function to wrap.
  4830. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4831. * @param {*} thisArg The `this` binding of `func`.
  4832. * @param {Array} partials The arguments to prepend to those provided to
  4833. * the new function.
  4834. * @returns {Function} Returns the new wrapped function.
  4835. */
  4836. function createPartial(func, bitmask, thisArg, partials) {
  4837. var isBind = bitmask & WRAP_BIND_FLAG,
  4838. Ctor = createCtor(func);
  4839. function wrapper() {
  4840. var argsIndex = -1,
  4841. argsLength = arguments.length,
  4842. leftIndex = -1,
  4843. leftLength = partials.length,
  4844. args = Array(leftLength + argsLength),
  4845. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4846. while (++leftIndex < leftLength) {
  4847. args[leftIndex] = partials[leftIndex];
  4848. }
  4849. while (argsLength--) {
  4850. args[leftIndex++] = arguments[++argsIndex];
  4851. }
  4852. return apply(fn, isBind ? thisArg : this, args);
  4853. }
  4854. return wrapper;
  4855. }
  4856. /**
  4857. * Creates a `_.range` or `_.rangeRight` function.
  4858. *
  4859. * @private
  4860. * @param {boolean} [fromRight] Specify iterating from right to left.
  4861. * @returns {Function} Returns the new range function.
  4862. */
  4863. function createRange(fromRight) {
  4864. return function(start, end, step) {
  4865. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4866. end = step = undefined;
  4867. }
  4868. // Ensure the sign of `-0` is preserved.
  4869. start = toFinite(start);
  4870. if (end === undefined) {
  4871. end = start;
  4872. start = 0;
  4873. } else {
  4874. end = toFinite(end);
  4875. }
  4876. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4877. return baseRange(start, end, step, fromRight);
  4878. };
  4879. }
  4880. /**
  4881. * Creates a function that performs a relational operation on two values.
  4882. *
  4883. * @private
  4884. * @param {Function} operator The function to perform the operation.
  4885. * @returns {Function} Returns the new relational operation function.
  4886. */
  4887. function createRelationalOperation(operator) {
  4888. return function(value, other) {
  4889. if (!(typeof value == 'string' && typeof other == 'string')) {
  4890. value = toNumber(value);
  4891. other = toNumber(other);
  4892. }
  4893. return operator(value, other);
  4894. };
  4895. }
  4896. /**
  4897. * Creates a function that wraps `func` to continue currying.
  4898. *
  4899. * @private
  4900. * @param {Function} func The function to wrap.
  4901. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4902. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4903. * @param {*} placeholder The placeholder value.
  4904. * @param {*} [thisArg] The `this` binding of `func`.
  4905. * @param {Array} [partials] The arguments to prepend to those provided to
  4906. * the new function.
  4907. * @param {Array} [holders] The `partials` placeholder indexes.
  4908. * @param {Array} [argPos] The argument positions of the new function.
  4909. * @param {number} [ary] The arity cap of `func`.
  4910. * @param {number} [arity] The arity of `func`.
  4911. * @returns {Function} Returns the new wrapped function.
  4912. */
  4913. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4914. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4915. newHolders = isCurry ? holders : undefined,
  4916. newHoldersRight = isCurry ? undefined : holders,
  4917. newPartials = isCurry ? partials : undefined,
  4918. newPartialsRight = isCurry ? undefined : partials;
  4919. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4920. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4921. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4922. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4923. }
  4924. var newData = [
  4925. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4926. newHoldersRight, argPos, ary, arity
  4927. ];
  4928. var result = wrapFunc.apply(undefined, newData);
  4929. if (isLaziable(func)) {
  4930. setData(result, newData);
  4931. }
  4932. result.placeholder = placeholder;
  4933. return setWrapToString(result, func, bitmask);
  4934. }
  4935. /**
  4936. * Creates a function like `_.round`.
  4937. *
  4938. * @private
  4939. * @param {string} methodName The name of the `Math` method to use when rounding.
  4940. * @returns {Function} Returns the new round function.
  4941. */
  4942. function createRound(methodName) {
  4943. var func = Math[methodName];
  4944. return function(number, precision) {
  4945. number = toNumber(number);
  4946. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4947. if (precision) {
  4948. // Shift with exponential notation to avoid floating-point issues.
  4949. // See [MDN](https://mdn.io/round#Examples) for more details.
  4950. var pair = (toString(number) + 'e').split('e'),
  4951. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4952. pair = (toString(value) + 'e').split('e');
  4953. return +(pair[0] + 'e' + (+pair[1] - precision));
  4954. }
  4955. return func(number);
  4956. };
  4957. }
  4958. /**
  4959. * Creates a set object of `values`.
  4960. *
  4961. * @private
  4962. * @param {Array} values The values to add to the set.
  4963. * @returns {Object} Returns the new set.
  4964. */
  4965. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4966. return new Set(values);
  4967. };
  4968. /**
  4969. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4970. *
  4971. * @private
  4972. * @param {Function} keysFunc The function to get the keys of a given object.
  4973. * @returns {Function} Returns the new pairs function.
  4974. */
  4975. function createToPairs(keysFunc) {
  4976. return function(object) {
  4977. var tag = getTag(object);
  4978. if (tag == mapTag) {
  4979. return mapToArray(object);
  4980. }
  4981. if (tag == setTag) {
  4982. return setToPairs(object);
  4983. }
  4984. return baseToPairs(object, keysFunc(object));
  4985. };
  4986. }
  4987. /**
  4988. * Creates a function that either curries or invokes `func` with optional
  4989. * `this` binding and partially applied arguments.
  4990. *
  4991. * @private
  4992. * @param {Function|string} func The function or method name to wrap.
  4993. * @param {number} bitmask The bitmask flags.
  4994. * 1 - `_.bind`
  4995. * 2 - `_.bindKey`
  4996. * 4 - `_.curry` or `_.curryRight` of a bound function
  4997. * 8 - `_.curry`
  4998. * 16 - `_.curryRight`
  4999. * 32 - `_.partial`
  5000. * 64 - `_.partialRight`
  5001. * 128 - `_.rearg`
  5002. * 256 - `_.ary`
  5003. * 512 - `_.flip`
  5004. * @param {*} [thisArg] The `this` binding of `func`.
  5005. * @param {Array} [partials] The arguments to be partially applied.
  5006. * @param {Array} [holders] The `partials` placeholder indexes.
  5007. * @param {Array} [argPos] The argument positions of the new function.
  5008. * @param {number} [ary] The arity cap of `func`.
  5009. * @param {number} [arity] The arity of `func`.
  5010. * @returns {Function} Returns the new wrapped function.
  5011. */
  5012. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5013. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5014. if (!isBindKey && typeof func != 'function') {
  5015. throw new TypeError(FUNC_ERROR_TEXT);
  5016. }
  5017. var length = partials ? partials.length : 0;
  5018. if (!length) {
  5019. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5020. partials = holders = undefined;
  5021. }
  5022. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5023. arity = arity === undefined ? arity : toInteger(arity);
  5024. length -= holders ? holders.length : 0;
  5025. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5026. var partialsRight = partials,
  5027. holdersRight = holders;
  5028. partials = holders = undefined;
  5029. }
  5030. var data = isBindKey ? undefined : getData(func);
  5031. var newData = [
  5032. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5033. argPos, ary, arity
  5034. ];
  5035. if (data) {
  5036. mergeData(newData, data);
  5037. }
  5038. func = newData[0];
  5039. bitmask = newData[1];
  5040. thisArg = newData[2];
  5041. partials = newData[3];
  5042. holders = newData[4];
  5043. arity = newData[9] = newData[9] === undefined
  5044. ? (isBindKey ? 0 : func.length)
  5045. : nativeMax(newData[9] - length, 0);
  5046. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5047. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5048. }
  5049. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5050. var result = createBind(func, bitmask, thisArg);
  5051. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5052. result = createCurry(func, bitmask, arity);
  5053. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5054. result = createPartial(func, bitmask, thisArg, partials);
  5055. } else {
  5056. result = createHybrid.apply(undefined, newData);
  5057. }
  5058. var setter = data ? baseSetData : setData;
  5059. return setWrapToString(setter(result, newData), func, bitmask);
  5060. }
  5061. /**
  5062. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5063. * of source objects to the destination object for all destination properties
  5064. * that resolve to `undefined`.
  5065. *
  5066. * @private
  5067. * @param {*} objValue The destination value.
  5068. * @param {*} srcValue The source value.
  5069. * @param {string} key The key of the property to assign.
  5070. * @param {Object} object The parent object of `objValue`.
  5071. * @returns {*} Returns the value to assign.
  5072. */
  5073. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5074. if (objValue === undefined ||
  5075. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5076. return srcValue;
  5077. }
  5078. return objValue;
  5079. }
  5080. /**
  5081. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5082. * objects into destination objects that are passed thru.
  5083. *
  5084. * @private
  5085. * @param {*} objValue The destination value.
  5086. * @param {*} srcValue The source value.
  5087. * @param {string} key The key of the property to merge.
  5088. * @param {Object} object The parent object of `objValue`.
  5089. * @param {Object} source The parent object of `srcValue`.
  5090. * @param {Object} [stack] Tracks traversed source values and their merged
  5091. * counterparts.
  5092. * @returns {*} Returns the value to assign.
  5093. */
  5094. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5095. if (isObject(objValue) && isObject(srcValue)) {
  5096. // Recursively merge objects and arrays (susceptible to call stack limits).
  5097. stack.set(srcValue, objValue);
  5098. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5099. stack['delete'](srcValue);
  5100. }
  5101. return objValue;
  5102. }
  5103. /**
  5104. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5105. * objects.
  5106. *
  5107. * @private
  5108. * @param {*} value The value to inspect.
  5109. * @param {string} key The key of the property to inspect.
  5110. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5111. */
  5112. function customOmitClone(value) {
  5113. return isPlainObject(value) ? undefined : value;
  5114. }
  5115. /**
  5116. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5117. * partial deep comparisons.
  5118. *
  5119. * @private
  5120. * @param {Array} array The array to compare.
  5121. * @param {Array} other The other array to compare.
  5122. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5123. * @param {Function} customizer The function to customize comparisons.
  5124. * @param {Function} equalFunc The function to determine equivalents of values.
  5125. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5126. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5127. */
  5128. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5129. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5130. arrLength = array.length,
  5131. othLength = other.length;
  5132. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5133. return false;
  5134. }
  5135. // Assume cyclic values are equal.
  5136. var stacked = stack.get(array);
  5137. if (stacked && stack.get(other)) {
  5138. return stacked == other;
  5139. }
  5140. var index = -1,
  5141. result = true,
  5142. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5143. stack.set(array, other);
  5144. stack.set(other, array);
  5145. // Ignore non-index properties.
  5146. while (++index < arrLength) {
  5147. var arrValue = array[index],
  5148. othValue = other[index];
  5149. if (customizer) {
  5150. var compared = isPartial
  5151. ? customizer(othValue, arrValue, index, other, array, stack)
  5152. : customizer(arrValue, othValue, index, array, other, stack);
  5153. }
  5154. if (compared !== undefined) {
  5155. if (compared) {
  5156. continue;
  5157. }
  5158. result = false;
  5159. break;
  5160. }
  5161. // Recursively compare arrays (susceptible to call stack limits).
  5162. if (seen) {
  5163. if (!arraySome(other, function(othValue, othIndex) {
  5164. if (!cacheHas(seen, othIndex) &&
  5165. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5166. return seen.push(othIndex);
  5167. }
  5168. })) {
  5169. result = false;
  5170. break;
  5171. }
  5172. } else if (!(
  5173. arrValue === othValue ||
  5174. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5175. )) {
  5176. result = false;
  5177. break;
  5178. }
  5179. }
  5180. stack['delete'](array);
  5181. stack['delete'](other);
  5182. return result;
  5183. }
  5184. /**
  5185. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5186. * the same `toStringTag`.
  5187. *
  5188. * **Note:** This function only supports comparing values with tags of
  5189. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5190. *
  5191. * @private
  5192. * @param {Object} object The object to compare.
  5193. * @param {Object} other The other object to compare.
  5194. * @param {string} tag The `toStringTag` of the objects to compare.
  5195. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5196. * @param {Function} customizer The function to customize comparisons.
  5197. * @param {Function} equalFunc The function to determine equivalents of values.
  5198. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5199. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5200. */
  5201. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5202. switch (tag) {
  5203. case dataViewTag:
  5204. if ((object.byteLength != other.byteLength) ||
  5205. (object.byteOffset != other.byteOffset)) {
  5206. return false;
  5207. }
  5208. object = object.buffer;
  5209. other = other.buffer;
  5210. case arrayBufferTag:
  5211. if ((object.byteLength != other.byteLength) ||
  5212. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5213. return false;
  5214. }
  5215. return true;
  5216. case boolTag:
  5217. case dateTag:
  5218. case numberTag:
  5219. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5220. // Invalid dates are coerced to `NaN`.
  5221. return eq(+object, +other);
  5222. case errorTag:
  5223. return object.name == other.name && object.message == other.message;
  5224. case regexpTag:
  5225. case stringTag:
  5226. // Coerce regexes to strings and treat strings, primitives and objects,
  5227. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5228. // for more details.
  5229. return object == (other + '');
  5230. case mapTag:
  5231. var convert = mapToArray;
  5232. case setTag:
  5233. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5234. convert || (convert = setToArray);
  5235. if (object.size != other.size && !isPartial) {
  5236. return false;
  5237. }
  5238. // Assume cyclic values are equal.
  5239. var stacked = stack.get(object);
  5240. if (stacked) {
  5241. return stacked == other;
  5242. }
  5243. bitmask |= COMPARE_UNORDERED_FLAG;
  5244. // Recursively compare objects (susceptible to call stack limits).
  5245. stack.set(object, other);
  5246. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5247. stack['delete'](object);
  5248. return result;
  5249. case symbolTag:
  5250. if (symbolValueOf) {
  5251. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5252. }
  5253. }
  5254. return false;
  5255. }
  5256. /**
  5257. * A specialized version of `baseIsEqualDeep` for objects with support for
  5258. * partial deep comparisons.
  5259. *
  5260. * @private
  5261. * @param {Object} object The object to compare.
  5262. * @param {Object} other The other object to compare.
  5263. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5264. * @param {Function} customizer The function to customize comparisons.
  5265. * @param {Function} equalFunc The function to determine equivalents of values.
  5266. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5267. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5268. */
  5269. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5270. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5271. objProps = getAllKeys(object),
  5272. objLength = objProps.length,
  5273. othProps = getAllKeys(other),
  5274. othLength = othProps.length;
  5275. if (objLength != othLength && !isPartial) {
  5276. return false;
  5277. }
  5278. var index = objLength;
  5279. while (index--) {
  5280. var key = objProps[index];
  5281. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5282. return false;
  5283. }
  5284. }
  5285. // Assume cyclic values are equal.
  5286. var stacked = stack.get(object);
  5287. if (stacked && stack.get(other)) {
  5288. return stacked == other;
  5289. }
  5290. var result = true;
  5291. stack.set(object, other);
  5292. stack.set(other, object);
  5293. var skipCtor = isPartial;
  5294. while (++index < objLength) {
  5295. key = objProps[index];
  5296. var objValue = object[key],
  5297. othValue = other[key];
  5298. if (customizer) {
  5299. var compared = isPartial
  5300. ? customizer(othValue, objValue, key, other, object, stack)
  5301. : customizer(objValue, othValue, key, object, other, stack);
  5302. }
  5303. // Recursively compare objects (susceptible to call stack limits).
  5304. if (!(compared === undefined
  5305. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5306. : compared
  5307. )) {
  5308. result = false;
  5309. break;
  5310. }
  5311. skipCtor || (skipCtor = key == 'constructor');
  5312. }
  5313. if (result && !skipCtor) {
  5314. var objCtor = object.constructor,
  5315. othCtor = other.constructor;
  5316. // Non `Object` object instances with different constructors are not equal.
  5317. if (objCtor != othCtor &&
  5318. ('constructor' in object && 'constructor' in other) &&
  5319. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5320. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5321. result = false;
  5322. }
  5323. }
  5324. stack['delete'](object);
  5325. stack['delete'](other);
  5326. return result;
  5327. }
  5328. /**
  5329. * A specialized version of `baseRest` which flattens the rest array.
  5330. *
  5331. * @private
  5332. * @param {Function} func The function to apply a rest parameter to.
  5333. * @returns {Function} Returns the new function.
  5334. */
  5335. function flatRest(func) {
  5336. return setToString(overRest(func, undefined, flatten), func + '');
  5337. }
  5338. /**
  5339. * Creates an array of own enumerable property names and symbols of `object`.
  5340. *
  5341. * @private
  5342. * @param {Object} object The object to query.
  5343. * @returns {Array} Returns the array of property names and symbols.
  5344. */
  5345. function getAllKeys(object) {
  5346. return baseGetAllKeys(object, keys, getSymbols);
  5347. }
  5348. /**
  5349. * Creates an array of own and inherited enumerable property names and
  5350. * symbols of `object`.
  5351. *
  5352. * @private
  5353. * @param {Object} object The object to query.
  5354. * @returns {Array} Returns the array of property names and symbols.
  5355. */
  5356. function getAllKeysIn(object) {
  5357. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5358. }
  5359. /**
  5360. * Gets metadata for `func`.
  5361. *
  5362. * @private
  5363. * @param {Function} func The function to query.
  5364. * @returns {*} Returns the metadata for `func`.
  5365. */
  5366. var getData = !metaMap ? noop : function(func) {
  5367. return metaMap.get(func);
  5368. };
  5369. /**
  5370. * Gets the name of `func`.
  5371. *
  5372. * @private
  5373. * @param {Function} func The function to query.
  5374. * @returns {string} Returns the function name.
  5375. */
  5376. function getFuncName(func) {
  5377. var result = (func.name + ''),
  5378. array = realNames[result],
  5379. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5380. while (length--) {
  5381. var data = array[length],
  5382. otherFunc = data.func;
  5383. if (otherFunc == null || otherFunc == func) {
  5384. return data.name;
  5385. }
  5386. }
  5387. return result;
  5388. }
  5389. /**
  5390. * Gets the argument placeholder value for `func`.
  5391. *
  5392. * @private
  5393. * @param {Function} func The function to inspect.
  5394. * @returns {*} Returns the placeholder value.
  5395. */
  5396. function getHolder(func) {
  5397. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5398. return object.placeholder;
  5399. }
  5400. /**
  5401. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5402. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5403. * If arguments are provided, the chosen function is invoked with them and
  5404. * its result is returned.
  5405. *
  5406. * @private
  5407. * @param {*} [value] The value to convert to an iteratee.
  5408. * @param {number} [arity] The arity of the created iteratee.
  5409. * @returns {Function} Returns the chosen function or its result.
  5410. */
  5411. function getIteratee() {
  5412. var result = lodash.iteratee || iteratee;
  5413. result = result === iteratee ? baseIteratee : result;
  5414. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5415. }
  5416. /**
  5417. * Gets the data for `map`.
  5418. *
  5419. * @private
  5420. * @param {Object} map The map to query.
  5421. * @param {string} key The reference key.
  5422. * @returns {*} Returns the map data.
  5423. */
  5424. function getMapData(map, key) {
  5425. var data = map.__data__;
  5426. return isKeyable(key)
  5427. ? data[typeof key == 'string' ? 'string' : 'hash']
  5428. : data.map;
  5429. }
  5430. /**
  5431. * Gets the property names, values, and compare flags of `object`.
  5432. *
  5433. * @private
  5434. * @param {Object} object The object to query.
  5435. * @returns {Array} Returns the match data of `object`.
  5436. */
  5437. function getMatchData(object) {
  5438. var result = keys(object),
  5439. length = result.length;
  5440. while (length--) {
  5441. var key = result[length],
  5442. value = object[key];
  5443. result[length] = [key, value, isStrictComparable(value)];
  5444. }
  5445. return result;
  5446. }
  5447. /**
  5448. * Gets the native function at `key` of `object`.
  5449. *
  5450. * @private
  5451. * @param {Object} object The object to query.
  5452. * @param {string} key The key of the method to get.
  5453. * @returns {*} Returns the function if it's native, else `undefined`.
  5454. */
  5455. function getNative(object, key) {
  5456. var value = getValue(object, key);
  5457. return baseIsNative(value) ? value : undefined;
  5458. }
  5459. /**
  5460. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5461. *
  5462. * @private
  5463. * @param {*} value The value to query.
  5464. * @returns {string} Returns the raw `toStringTag`.
  5465. */
  5466. function getRawTag(value) {
  5467. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5468. tag = value[symToStringTag];
  5469. try {
  5470. value[symToStringTag] = undefined;
  5471. var unmasked = true;
  5472. } catch (e) {}
  5473. var result = nativeObjectToString.call(value);
  5474. if (unmasked) {
  5475. if (isOwn) {
  5476. value[symToStringTag] = tag;
  5477. } else {
  5478. delete value[symToStringTag];
  5479. }
  5480. }
  5481. return result;
  5482. }
  5483. /**
  5484. * Creates an array of the own enumerable symbols of `object`.
  5485. *
  5486. * @private
  5487. * @param {Object} object The object to query.
  5488. * @returns {Array} Returns the array of symbols.
  5489. */
  5490. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5491. if (object == null) {
  5492. return [];
  5493. }
  5494. object = Object(object);
  5495. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5496. return propertyIsEnumerable.call(object, symbol);
  5497. });
  5498. };
  5499. /**
  5500. * Creates an array of the own and inherited enumerable symbols of `object`.
  5501. *
  5502. * @private
  5503. * @param {Object} object The object to query.
  5504. * @returns {Array} Returns the array of symbols.
  5505. */
  5506. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5507. var result = [];
  5508. while (object) {
  5509. arrayPush(result, getSymbols(object));
  5510. object = getPrototype(object);
  5511. }
  5512. return result;
  5513. };
  5514. /**
  5515. * Gets the `toStringTag` of `value`.
  5516. *
  5517. * @private
  5518. * @param {*} value The value to query.
  5519. * @returns {string} Returns the `toStringTag`.
  5520. */
  5521. var getTag = baseGetTag;
  5522. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5523. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5524. (Map && getTag(new Map) != mapTag) ||
  5525. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5526. (Set && getTag(new Set) != setTag) ||
  5527. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5528. getTag = function(value) {
  5529. var result = baseGetTag(value),
  5530. Ctor = result == objectTag ? value.constructor : undefined,
  5531. ctorString = Ctor ? toSource(Ctor) : '';
  5532. if (ctorString) {
  5533. switch (ctorString) {
  5534. case dataViewCtorString: return dataViewTag;
  5535. case mapCtorString: return mapTag;
  5536. case promiseCtorString: return promiseTag;
  5537. case setCtorString: return setTag;
  5538. case weakMapCtorString: return weakMapTag;
  5539. }
  5540. }
  5541. return result;
  5542. };
  5543. }
  5544. /**
  5545. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5546. *
  5547. * @private
  5548. * @param {number} start The start of the view.
  5549. * @param {number} end The end of the view.
  5550. * @param {Array} transforms The transformations to apply to the view.
  5551. * @returns {Object} Returns an object containing the `start` and `end`
  5552. * positions of the view.
  5553. */
  5554. function getView(start, end, transforms) {
  5555. var index = -1,
  5556. length = transforms.length;
  5557. while (++index < length) {
  5558. var data = transforms[index],
  5559. size = data.size;
  5560. switch (data.type) {
  5561. case 'drop': start += size; break;
  5562. case 'dropRight': end -= size; break;
  5563. case 'take': end = nativeMin(end, start + size); break;
  5564. case 'takeRight': start = nativeMax(start, end - size); break;
  5565. }
  5566. }
  5567. return { 'start': start, 'end': end };
  5568. }
  5569. /**
  5570. * Extracts wrapper details from the `source` body comment.
  5571. *
  5572. * @private
  5573. * @param {string} source The source to inspect.
  5574. * @returns {Array} Returns the wrapper details.
  5575. */
  5576. function getWrapDetails(source) {
  5577. var match = source.match(reWrapDetails);
  5578. return match ? match[1].split(reSplitDetails) : [];
  5579. }
  5580. /**
  5581. * Checks if `path` exists on `object`.
  5582. *
  5583. * @private
  5584. * @param {Object} object The object to query.
  5585. * @param {Array|string} path The path to check.
  5586. * @param {Function} hasFunc The function to check properties.
  5587. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5588. */
  5589. function hasPath(object, path, hasFunc) {
  5590. path = castPath(path, object);
  5591. var index = -1,
  5592. length = path.length,
  5593. result = false;
  5594. while (++index < length) {
  5595. var key = toKey(path[index]);
  5596. if (!(result = object != null && hasFunc(object, key))) {
  5597. break;
  5598. }
  5599. object = object[key];
  5600. }
  5601. if (result || ++index != length) {
  5602. return result;
  5603. }
  5604. length = object == null ? 0 : object.length;
  5605. return !!length && isLength(length) && isIndex(key, length) &&
  5606. (isArray(object) || isArguments(object));
  5607. }
  5608. /**
  5609. * Initializes an array clone.
  5610. *
  5611. * @private
  5612. * @param {Array} array The array to clone.
  5613. * @returns {Array} Returns the initialized clone.
  5614. */
  5615. function initCloneArray(array) {
  5616. var length = array.length,
  5617. result = new array.constructor(length);
  5618. // Add properties assigned by `RegExp#exec`.
  5619. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5620. result.index = array.index;
  5621. result.input = array.input;
  5622. }
  5623. return result;
  5624. }
  5625. /**
  5626. * Initializes an object clone.
  5627. *
  5628. * @private
  5629. * @param {Object} object The object to clone.
  5630. * @returns {Object} Returns the initialized clone.
  5631. */
  5632. function initCloneObject(object) {
  5633. return (typeof object.constructor == 'function' && !isPrototype(object))
  5634. ? baseCreate(getPrototype(object))
  5635. : {};
  5636. }
  5637. /**
  5638. * Initializes an object clone based on its `toStringTag`.
  5639. *
  5640. * **Note:** This function only supports cloning values with tags of
  5641. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5642. *
  5643. * @private
  5644. * @param {Object} object The object to clone.
  5645. * @param {string} tag The `toStringTag` of the object to clone.
  5646. * @param {boolean} [isDeep] Specify a deep clone.
  5647. * @returns {Object} Returns the initialized clone.
  5648. */
  5649. function initCloneByTag(object, tag, isDeep) {
  5650. var Ctor = object.constructor;
  5651. switch (tag) {
  5652. case arrayBufferTag:
  5653. return cloneArrayBuffer(object);
  5654. case boolTag:
  5655. case dateTag:
  5656. return new Ctor(+object);
  5657. case dataViewTag:
  5658. return cloneDataView(object, isDeep);
  5659. case float32Tag: case float64Tag:
  5660. case int8Tag: case int16Tag: case int32Tag:
  5661. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5662. return cloneTypedArray(object, isDeep);
  5663. case mapTag:
  5664. return new Ctor;
  5665. case numberTag:
  5666. case stringTag:
  5667. return new Ctor(object);
  5668. case regexpTag:
  5669. return cloneRegExp(object);
  5670. case setTag:
  5671. return new Ctor;
  5672. case symbolTag:
  5673. return cloneSymbol(object);
  5674. }
  5675. }
  5676. /**
  5677. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5678. *
  5679. * @private
  5680. * @param {string} source The source to modify.
  5681. * @returns {Array} details The details to insert.
  5682. * @returns {string} Returns the modified source.
  5683. */
  5684. function insertWrapDetails(source, details) {
  5685. var length = details.length;
  5686. if (!length) {
  5687. return source;
  5688. }
  5689. var lastIndex = length - 1;
  5690. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5691. details = details.join(length > 2 ? ', ' : ' ');
  5692. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5693. }
  5694. /**
  5695. * Checks if `value` is a flattenable `arguments` object or array.
  5696. *
  5697. * @private
  5698. * @param {*} value The value to check.
  5699. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5700. */
  5701. function isFlattenable(value) {
  5702. return isArray(value) || isArguments(value) ||
  5703. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5704. }
  5705. /**
  5706. * Checks if `value` is a valid array-like index.
  5707. *
  5708. * @private
  5709. * @param {*} value The value to check.
  5710. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5711. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5712. */
  5713. function isIndex(value, length) {
  5714. var type = typeof value;
  5715. length = length == null ? MAX_SAFE_INTEGER : length;
  5716. return !!length &&
  5717. (type == 'number' ||
  5718. (type != 'symbol' && reIsUint.test(value))) &&
  5719. (value > -1 && value % 1 == 0 && value < length);
  5720. }
  5721. /**
  5722. * Checks if the given arguments are from an iteratee call.
  5723. *
  5724. * @private
  5725. * @param {*} value The potential iteratee value argument.
  5726. * @param {*} index The potential iteratee index or key argument.
  5727. * @param {*} object The potential iteratee object argument.
  5728. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5729. * else `false`.
  5730. */
  5731. function isIterateeCall(value, index, object) {
  5732. if (!isObject(object)) {
  5733. return false;
  5734. }
  5735. var type = typeof index;
  5736. if (type == 'number'
  5737. ? (isArrayLike(object) && isIndex(index, object.length))
  5738. : (type == 'string' && index in object)
  5739. ) {
  5740. return eq(object[index], value);
  5741. }
  5742. return false;
  5743. }
  5744. /**
  5745. * Checks if `value` is a property name and not a property path.
  5746. *
  5747. * @private
  5748. * @param {*} value The value to check.
  5749. * @param {Object} [object] The object to query keys on.
  5750. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5751. */
  5752. function isKey(value, object) {
  5753. if (isArray(value)) {
  5754. return false;
  5755. }
  5756. var type = typeof value;
  5757. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5758. value == null || isSymbol(value)) {
  5759. return true;
  5760. }
  5761. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5762. (object != null && value in Object(object));
  5763. }
  5764. /**
  5765. * Checks if `value` is suitable for use as unique object key.
  5766. *
  5767. * @private
  5768. * @param {*} value The value to check.
  5769. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5770. */
  5771. function isKeyable(value) {
  5772. var type = typeof value;
  5773. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5774. ? (value !== '__proto__')
  5775. : (value === null);
  5776. }
  5777. /**
  5778. * Checks if `func` has a lazy counterpart.
  5779. *
  5780. * @private
  5781. * @param {Function} func The function to check.
  5782. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5783. * else `false`.
  5784. */
  5785. function isLaziable(func) {
  5786. var funcName = getFuncName(func),
  5787. other = lodash[funcName];
  5788. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5789. return false;
  5790. }
  5791. if (func === other) {
  5792. return true;
  5793. }
  5794. var data = getData(other);
  5795. return !!data && func === data[0];
  5796. }
  5797. /**
  5798. * Checks if `func` has its source masked.
  5799. *
  5800. * @private
  5801. * @param {Function} func The function to check.
  5802. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5803. */
  5804. function isMasked(func) {
  5805. return !!maskSrcKey && (maskSrcKey in func);
  5806. }
  5807. /**
  5808. * Checks if `func` is capable of being masked.
  5809. *
  5810. * @private
  5811. * @param {*} value The value to check.
  5812. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5813. */
  5814. var isMaskable = coreJsData ? isFunction : stubFalse;
  5815. /**
  5816. * Checks if `value` is likely a prototype object.
  5817. *
  5818. * @private
  5819. * @param {*} value The value to check.
  5820. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5821. */
  5822. function isPrototype(value) {
  5823. var Ctor = value && value.constructor,
  5824. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5825. return value === proto;
  5826. }
  5827. /**
  5828. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5829. *
  5830. * @private
  5831. * @param {*} value The value to check.
  5832. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5833. * equality comparisons, else `false`.
  5834. */
  5835. function isStrictComparable(value) {
  5836. return value === value && !isObject(value);
  5837. }
  5838. /**
  5839. * A specialized version of `matchesProperty` for source values suitable
  5840. * for strict equality comparisons, i.e. `===`.
  5841. *
  5842. * @private
  5843. * @param {string} key The key of the property to get.
  5844. * @param {*} srcValue The value to match.
  5845. * @returns {Function} Returns the new spec function.
  5846. */
  5847. function matchesStrictComparable(key, srcValue) {
  5848. return function(object) {
  5849. if (object == null) {
  5850. return false;
  5851. }
  5852. return object[key] === srcValue &&
  5853. (srcValue !== undefined || (key in Object(object)));
  5854. };
  5855. }
  5856. /**
  5857. * A specialized version of `_.memoize` which clears the memoized function's
  5858. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5859. *
  5860. * @private
  5861. * @param {Function} func The function to have its output memoized.
  5862. * @returns {Function} Returns the new memoized function.
  5863. */
  5864. function memoizeCapped(func) {
  5865. var result = memoize(func, function(key) {
  5866. if (cache.size === MAX_MEMOIZE_SIZE) {
  5867. cache.clear();
  5868. }
  5869. return key;
  5870. });
  5871. var cache = result.cache;
  5872. return result;
  5873. }
  5874. /**
  5875. * Merges the function metadata of `source` into `data`.
  5876. *
  5877. * Merging metadata reduces the number of wrappers used to invoke a function.
  5878. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5879. * may be applied regardless of execution order. Methods like `_.ary` and
  5880. * `_.rearg` modify function arguments, making the order in which they are
  5881. * executed important, preventing the merging of metadata. However, we make
  5882. * an exception for a safe combined case where curried functions have `_.ary`
  5883. * and or `_.rearg` applied.
  5884. *
  5885. * @private
  5886. * @param {Array} data The destination metadata.
  5887. * @param {Array} source The source metadata.
  5888. * @returns {Array} Returns `data`.
  5889. */
  5890. function mergeData(data, source) {
  5891. var bitmask = data[1],
  5892. srcBitmask = source[1],
  5893. newBitmask = bitmask | srcBitmask,
  5894. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5895. var isCombo =
  5896. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5897. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5898. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5899. // Exit early if metadata can't be merged.
  5900. if (!(isCommon || isCombo)) {
  5901. return data;
  5902. }
  5903. // Use source `thisArg` if available.
  5904. if (srcBitmask & WRAP_BIND_FLAG) {
  5905. data[2] = source[2];
  5906. // Set when currying a bound function.
  5907. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5908. }
  5909. // Compose partial arguments.
  5910. var value = source[3];
  5911. if (value) {
  5912. var partials = data[3];
  5913. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5914. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5915. }
  5916. // Compose partial right arguments.
  5917. value = source[5];
  5918. if (value) {
  5919. partials = data[5];
  5920. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5921. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5922. }
  5923. // Use source `argPos` if available.
  5924. value = source[7];
  5925. if (value) {
  5926. data[7] = value;
  5927. }
  5928. // Use source `ary` if it's smaller.
  5929. if (srcBitmask & WRAP_ARY_FLAG) {
  5930. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5931. }
  5932. // Use source `arity` if one is not provided.
  5933. if (data[9] == null) {
  5934. data[9] = source[9];
  5935. }
  5936. // Use source `func` and merge bitmasks.
  5937. data[0] = source[0];
  5938. data[1] = newBitmask;
  5939. return data;
  5940. }
  5941. /**
  5942. * This function is like
  5943. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5944. * except that it includes inherited enumerable properties.
  5945. *
  5946. * @private
  5947. * @param {Object} object The object to query.
  5948. * @returns {Array} Returns the array of property names.
  5949. */
  5950. function nativeKeysIn(object) {
  5951. var result = [];
  5952. if (object != null) {
  5953. for (var key in Object(object)) {
  5954. result.push(key);
  5955. }
  5956. }
  5957. return result;
  5958. }
  5959. /**
  5960. * Converts `value` to a string using `Object.prototype.toString`.
  5961. *
  5962. * @private
  5963. * @param {*} value The value to convert.
  5964. * @returns {string} Returns the converted string.
  5965. */
  5966. function objectToString(value) {
  5967. return nativeObjectToString.call(value);
  5968. }
  5969. /**
  5970. * A specialized version of `baseRest` which transforms the rest array.
  5971. *
  5972. * @private
  5973. * @param {Function} func The function to apply a rest parameter to.
  5974. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5975. * @param {Function} transform The rest array transform.
  5976. * @returns {Function} Returns the new function.
  5977. */
  5978. function overRest(func, start, transform) {
  5979. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5980. return function() {
  5981. var args = arguments,
  5982. index = -1,
  5983. length = nativeMax(args.length - start, 0),
  5984. array = Array(length);
  5985. while (++index < length) {
  5986. array[index] = args[start + index];
  5987. }
  5988. index = -1;
  5989. var otherArgs = Array(start + 1);
  5990. while (++index < start) {
  5991. otherArgs[index] = args[index];
  5992. }
  5993. otherArgs[start] = transform(array);
  5994. return apply(func, this, otherArgs);
  5995. };
  5996. }
  5997. /**
  5998. * Gets the parent value at `path` of `object`.
  5999. *
  6000. * @private
  6001. * @param {Object} object The object to query.
  6002. * @param {Array} path The path to get the parent value of.
  6003. * @returns {*} Returns the parent value.
  6004. */
  6005. function parent(object, path) {
  6006. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6007. }
  6008. /**
  6009. * Reorder `array` according to the specified indexes where the element at
  6010. * the first index is assigned as the first element, the element at
  6011. * the second index is assigned as the second element, and so on.
  6012. *
  6013. * @private
  6014. * @param {Array} array The array to reorder.
  6015. * @param {Array} indexes The arranged array indexes.
  6016. * @returns {Array} Returns `array`.
  6017. */
  6018. function reorder(array, indexes) {
  6019. var arrLength = array.length,
  6020. length = nativeMin(indexes.length, arrLength),
  6021. oldArray = copyArray(array);
  6022. while (length--) {
  6023. var index = indexes[length];
  6024. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6025. }
  6026. return array;
  6027. }
  6028. /**
  6029. * Gets the value at `key`, unless `key` is "__proto__".
  6030. *
  6031. * @private
  6032. * @param {Object} object The object to query.
  6033. * @param {string} key The key of the property to get.
  6034. * @returns {*} Returns the property value.
  6035. */
  6036. function safeGet(object, key) {
  6037. if (key == '__proto__') {
  6038. return;
  6039. }
  6040. return object[key];
  6041. }
  6042. /**
  6043. * Sets metadata for `func`.
  6044. *
  6045. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6046. * period of time, it will trip its breaker and transition to an identity
  6047. * function to avoid garbage collection pauses in V8. See
  6048. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6049. * for more details.
  6050. *
  6051. * @private
  6052. * @param {Function} func The function to associate metadata with.
  6053. * @param {*} data The metadata.
  6054. * @returns {Function} Returns `func`.
  6055. */
  6056. var setData = shortOut(baseSetData);
  6057. /**
  6058. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6059. *
  6060. * @private
  6061. * @param {Function} func The function to delay.
  6062. * @param {number} wait The number of milliseconds to delay invocation.
  6063. * @returns {number|Object} Returns the timer id or timeout object.
  6064. */
  6065. var setTimeout = ctxSetTimeout || function(func, wait) {
  6066. return root.setTimeout(func, wait);
  6067. };
  6068. /**
  6069. * Sets the `toString` method of `func` to return `string`.
  6070. *
  6071. * @private
  6072. * @param {Function} func The function to modify.
  6073. * @param {Function} string The `toString` result.
  6074. * @returns {Function} Returns `func`.
  6075. */
  6076. var setToString = shortOut(baseSetToString);
  6077. /**
  6078. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6079. * with wrapper details in a comment at the top of the source body.
  6080. *
  6081. * @private
  6082. * @param {Function} wrapper The function to modify.
  6083. * @param {Function} reference The reference function.
  6084. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6085. * @returns {Function} Returns `wrapper`.
  6086. */
  6087. function setWrapToString(wrapper, reference, bitmask) {
  6088. var source = (reference + '');
  6089. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6090. }
  6091. /**
  6092. * Creates a function that'll short out and invoke `identity` instead
  6093. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6094. * milliseconds.
  6095. *
  6096. * @private
  6097. * @param {Function} func The function to restrict.
  6098. * @returns {Function} Returns the new shortable function.
  6099. */
  6100. function shortOut(func) {
  6101. var count = 0,
  6102. lastCalled = 0;
  6103. return function() {
  6104. var stamp = nativeNow(),
  6105. remaining = HOT_SPAN - (stamp - lastCalled);
  6106. lastCalled = stamp;
  6107. if (remaining > 0) {
  6108. if (++count >= HOT_COUNT) {
  6109. return arguments[0];
  6110. }
  6111. } else {
  6112. count = 0;
  6113. }
  6114. return func.apply(undefined, arguments);
  6115. };
  6116. }
  6117. /**
  6118. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6119. *
  6120. * @private
  6121. * @param {Array} array The array to shuffle.
  6122. * @param {number} [size=array.length] The size of `array`.
  6123. * @returns {Array} Returns `array`.
  6124. */
  6125. function shuffleSelf(array, size) {
  6126. var index = -1,
  6127. length = array.length,
  6128. lastIndex = length - 1;
  6129. size = size === undefined ? length : size;
  6130. while (++index < size) {
  6131. var rand = baseRandom(index, lastIndex),
  6132. value = array[rand];
  6133. array[rand] = array[index];
  6134. array[index] = value;
  6135. }
  6136. array.length = size;
  6137. return array;
  6138. }
  6139. /**
  6140. * Converts `string` to a property path array.
  6141. *
  6142. * @private
  6143. * @param {string} string The string to convert.
  6144. * @returns {Array} Returns the property path array.
  6145. */
  6146. var stringToPath = memoizeCapped(function(string) {
  6147. var result = [];
  6148. if (string.charCodeAt(0) === 46 /* . */) {
  6149. result.push('');
  6150. }
  6151. string.replace(rePropName, function(match, number, quote, subString) {
  6152. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6153. });
  6154. return result;
  6155. });
  6156. /**
  6157. * Converts `value` to a string key if it's not a string or symbol.
  6158. *
  6159. * @private
  6160. * @param {*} value The value to inspect.
  6161. * @returns {string|symbol} Returns the key.
  6162. */
  6163. function toKey(value) {
  6164. if (typeof value == 'string' || isSymbol(value)) {
  6165. return value;
  6166. }
  6167. var result = (value + '');
  6168. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6169. }
  6170. /**
  6171. * Converts `func` to its source code.
  6172. *
  6173. * @private
  6174. * @param {Function} func The function to convert.
  6175. * @returns {string} Returns the source code.
  6176. */
  6177. function toSource(func) {
  6178. if (func != null) {
  6179. try {
  6180. return funcToString.call(func);
  6181. } catch (e) {}
  6182. try {
  6183. return (func + '');
  6184. } catch (e) {}
  6185. }
  6186. return '';
  6187. }
  6188. /**
  6189. * Updates wrapper `details` based on `bitmask` flags.
  6190. *
  6191. * @private
  6192. * @returns {Array} details The details to modify.
  6193. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6194. * @returns {Array} Returns `details`.
  6195. */
  6196. function updateWrapDetails(details, bitmask) {
  6197. arrayEach(wrapFlags, function(pair) {
  6198. var value = '_.' + pair[0];
  6199. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6200. details.push(value);
  6201. }
  6202. });
  6203. return details.sort();
  6204. }
  6205. /**
  6206. * Creates a clone of `wrapper`.
  6207. *
  6208. * @private
  6209. * @param {Object} wrapper The wrapper to clone.
  6210. * @returns {Object} Returns the cloned wrapper.
  6211. */
  6212. function wrapperClone(wrapper) {
  6213. if (wrapper instanceof LazyWrapper) {
  6214. return wrapper.clone();
  6215. }
  6216. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6217. result.__actions__ = copyArray(wrapper.__actions__);
  6218. result.__index__ = wrapper.__index__;
  6219. result.__values__ = wrapper.__values__;
  6220. return result;
  6221. }
  6222. /*------------------------------------------------------------------------*/
  6223. /**
  6224. * Creates an array of elements split into groups the length of `size`.
  6225. * If `array` can't be split evenly, the final chunk will be the remaining
  6226. * elements.
  6227. *
  6228. * @static
  6229. * @memberOf _
  6230. * @since 3.0.0
  6231. * @category Array
  6232. * @param {Array} array The array to process.
  6233. * @param {number} [size=1] The length of each chunk
  6234. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6235. * @returns {Array} Returns the new array of chunks.
  6236. * @example
  6237. *
  6238. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6239. * // => [['a', 'b'], ['c', 'd']]
  6240. *
  6241. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6242. * // => [['a', 'b', 'c'], ['d']]
  6243. */
  6244. function chunk(array, size, guard) {
  6245. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6246. size = 1;
  6247. } else {
  6248. size = nativeMax(toInteger(size), 0);
  6249. }
  6250. var length = array == null ? 0 : array.length;
  6251. if (!length || size < 1) {
  6252. return [];
  6253. }
  6254. var index = 0,
  6255. resIndex = 0,
  6256. result = Array(nativeCeil(length / size));
  6257. while (index < length) {
  6258. result[resIndex++] = baseSlice(array, index, (index += size));
  6259. }
  6260. return result;
  6261. }
  6262. /**
  6263. * Creates an array with all falsey values removed. The values `false`, `null`,
  6264. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6265. *
  6266. * @static
  6267. * @memberOf _
  6268. * @since 0.1.0
  6269. * @category Array
  6270. * @param {Array} array The array to compact.
  6271. * @returns {Array} Returns the new array of filtered values.
  6272. * @example
  6273. *
  6274. * _.compact([0, 1, false, 2, '', 3]);
  6275. * // => [1, 2, 3]
  6276. */
  6277. function compact(array) {
  6278. var index = -1,
  6279. length = array == null ? 0 : array.length,
  6280. resIndex = 0,
  6281. result = [];
  6282. while (++index < length) {
  6283. var value = array[index];
  6284. if (value) {
  6285. result[resIndex++] = value;
  6286. }
  6287. }
  6288. return result;
  6289. }
  6290. /**
  6291. * Creates a new array concatenating `array` with any additional arrays
  6292. * and/or values.
  6293. *
  6294. * @static
  6295. * @memberOf _
  6296. * @since 4.0.0
  6297. * @category Array
  6298. * @param {Array} array The array to concatenate.
  6299. * @param {...*} [values] The values to concatenate.
  6300. * @returns {Array} Returns the new concatenated array.
  6301. * @example
  6302. *
  6303. * var array = [1];
  6304. * var other = _.concat(array, 2, [3], [[4]]);
  6305. *
  6306. * console.log(other);
  6307. * // => [1, 2, 3, [4]]
  6308. *
  6309. * console.log(array);
  6310. * // => [1]
  6311. */
  6312. function concat() {
  6313. var length = arguments.length;
  6314. if (!length) {
  6315. return [];
  6316. }
  6317. var args = Array(length - 1),
  6318. array = arguments[0],
  6319. index = length;
  6320. while (index--) {
  6321. args[index - 1] = arguments[index];
  6322. }
  6323. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6324. }
  6325. /**
  6326. * Creates an array of `array` values not included in the other given arrays
  6327. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6328. * for equality comparisons. The order and references of result values are
  6329. * determined by the first array.
  6330. *
  6331. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6332. *
  6333. * @static
  6334. * @memberOf _
  6335. * @since 0.1.0
  6336. * @category Array
  6337. * @param {Array} array The array to inspect.
  6338. * @param {...Array} [values] The values to exclude.
  6339. * @returns {Array} Returns the new array of filtered values.
  6340. * @see _.without, _.xor
  6341. * @example
  6342. *
  6343. * _.difference([2, 1], [2, 3]);
  6344. * // => [1]
  6345. */
  6346. var difference = baseRest(function(array, values) {
  6347. return isArrayLikeObject(array)
  6348. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6349. : [];
  6350. });
  6351. /**
  6352. * This method is like `_.difference` except that it accepts `iteratee` which
  6353. * is invoked for each element of `array` and `values` to generate the criterion
  6354. * by which they're compared. The order and references of result values are
  6355. * determined by the first array. The iteratee is invoked with one argument:
  6356. * (value).
  6357. *
  6358. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6359. *
  6360. * @static
  6361. * @memberOf _
  6362. * @since 4.0.0
  6363. * @category Array
  6364. * @param {Array} array The array to inspect.
  6365. * @param {...Array} [values] The values to exclude.
  6366. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6367. * @returns {Array} Returns the new array of filtered values.
  6368. * @example
  6369. *
  6370. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6371. * // => [1.2]
  6372. *
  6373. * // The `_.property` iteratee shorthand.
  6374. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6375. * // => [{ 'x': 2 }]
  6376. */
  6377. var differenceBy = baseRest(function(array, values) {
  6378. var iteratee = last(values);
  6379. if (isArrayLikeObject(iteratee)) {
  6380. iteratee = undefined;
  6381. }
  6382. return isArrayLikeObject(array)
  6383. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6384. : [];
  6385. });
  6386. /**
  6387. * This method is like `_.difference` except that it accepts `comparator`
  6388. * which is invoked to compare elements of `array` to `values`. The order and
  6389. * references of result values are determined by the first array. The comparator
  6390. * is invoked with two arguments: (arrVal, othVal).
  6391. *
  6392. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6393. *
  6394. * @static
  6395. * @memberOf _
  6396. * @since 4.0.0
  6397. * @category Array
  6398. * @param {Array} array The array to inspect.
  6399. * @param {...Array} [values] The values to exclude.
  6400. * @param {Function} [comparator] The comparator invoked per element.
  6401. * @returns {Array} Returns the new array of filtered values.
  6402. * @example
  6403. *
  6404. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6405. *
  6406. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6407. * // => [{ 'x': 2, 'y': 1 }]
  6408. */
  6409. var differenceWith = baseRest(function(array, values) {
  6410. var comparator = last(values);
  6411. if (isArrayLikeObject(comparator)) {
  6412. comparator = undefined;
  6413. }
  6414. return isArrayLikeObject(array)
  6415. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6416. : [];
  6417. });
  6418. /**
  6419. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6420. *
  6421. * @static
  6422. * @memberOf _
  6423. * @since 0.5.0
  6424. * @category Array
  6425. * @param {Array} array The array to query.
  6426. * @param {number} [n=1] The number of elements to drop.
  6427. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6428. * @returns {Array} Returns the slice of `array`.
  6429. * @example
  6430. *
  6431. * _.drop([1, 2, 3]);
  6432. * // => [2, 3]
  6433. *
  6434. * _.drop([1, 2, 3], 2);
  6435. * // => [3]
  6436. *
  6437. * _.drop([1, 2, 3], 5);
  6438. * // => []
  6439. *
  6440. * _.drop([1, 2, 3], 0);
  6441. * // => [1, 2, 3]
  6442. */
  6443. function drop(array, n, guard) {
  6444. var length = array == null ? 0 : array.length;
  6445. if (!length) {
  6446. return [];
  6447. }
  6448. n = (guard || n === undefined) ? 1 : toInteger(n);
  6449. return baseSlice(array, n < 0 ? 0 : n, length);
  6450. }
  6451. /**
  6452. * Creates a slice of `array` with `n` elements dropped from the end.
  6453. *
  6454. * @static
  6455. * @memberOf _
  6456. * @since 3.0.0
  6457. * @category Array
  6458. * @param {Array} array The array to query.
  6459. * @param {number} [n=1] The number of elements to drop.
  6460. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6461. * @returns {Array} Returns the slice of `array`.
  6462. * @example
  6463. *
  6464. * _.dropRight([1, 2, 3]);
  6465. * // => [1, 2]
  6466. *
  6467. * _.dropRight([1, 2, 3], 2);
  6468. * // => [1]
  6469. *
  6470. * _.dropRight([1, 2, 3], 5);
  6471. * // => []
  6472. *
  6473. * _.dropRight([1, 2, 3], 0);
  6474. * // => [1, 2, 3]
  6475. */
  6476. function dropRight(array, n, guard) {
  6477. var length = array == null ? 0 : array.length;
  6478. if (!length) {
  6479. return [];
  6480. }
  6481. n = (guard || n === undefined) ? 1 : toInteger(n);
  6482. n = length - n;
  6483. return baseSlice(array, 0, n < 0 ? 0 : n);
  6484. }
  6485. /**
  6486. * Creates a slice of `array` excluding elements dropped from the end.
  6487. * Elements are dropped until `predicate` returns falsey. The predicate is
  6488. * invoked with three arguments: (value, index, array).
  6489. *
  6490. * @static
  6491. * @memberOf _
  6492. * @since 3.0.0
  6493. * @category Array
  6494. * @param {Array} array The array to query.
  6495. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6496. * @returns {Array} Returns the slice of `array`.
  6497. * @example
  6498. *
  6499. * var users = [
  6500. * { 'user': 'barney', 'active': true },
  6501. * { 'user': 'fred', 'active': false },
  6502. * { 'user': 'pebbles', 'active': false }
  6503. * ];
  6504. *
  6505. * _.dropRightWhile(users, function(o) { return !o.active; });
  6506. * // => objects for ['barney']
  6507. *
  6508. * // The `_.matches` iteratee shorthand.
  6509. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6510. * // => objects for ['barney', 'fred']
  6511. *
  6512. * // The `_.matchesProperty` iteratee shorthand.
  6513. * _.dropRightWhile(users, ['active', false]);
  6514. * // => objects for ['barney']
  6515. *
  6516. * // The `_.property` iteratee shorthand.
  6517. * _.dropRightWhile(users, 'active');
  6518. * // => objects for ['barney', 'fred', 'pebbles']
  6519. */
  6520. function dropRightWhile(array, predicate) {
  6521. return (array && array.length)
  6522. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6523. : [];
  6524. }
  6525. /**
  6526. * Creates a slice of `array` excluding elements dropped from the beginning.
  6527. * Elements are dropped until `predicate` returns falsey. The predicate is
  6528. * invoked with three arguments: (value, index, array).
  6529. *
  6530. * @static
  6531. * @memberOf _
  6532. * @since 3.0.0
  6533. * @category Array
  6534. * @param {Array} array The array to query.
  6535. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6536. * @returns {Array} Returns the slice of `array`.
  6537. * @example
  6538. *
  6539. * var users = [
  6540. * { 'user': 'barney', 'active': false },
  6541. * { 'user': 'fred', 'active': false },
  6542. * { 'user': 'pebbles', 'active': true }
  6543. * ];
  6544. *
  6545. * _.dropWhile(users, function(o) { return !o.active; });
  6546. * // => objects for ['pebbles']
  6547. *
  6548. * // The `_.matches` iteratee shorthand.
  6549. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6550. * // => objects for ['fred', 'pebbles']
  6551. *
  6552. * // The `_.matchesProperty` iteratee shorthand.
  6553. * _.dropWhile(users, ['active', false]);
  6554. * // => objects for ['pebbles']
  6555. *
  6556. * // The `_.property` iteratee shorthand.
  6557. * _.dropWhile(users, 'active');
  6558. * // => objects for ['barney', 'fred', 'pebbles']
  6559. */
  6560. function dropWhile(array, predicate) {
  6561. return (array && array.length)
  6562. ? baseWhile(array, getIteratee(predicate, 3), true)
  6563. : [];
  6564. }
  6565. /**
  6566. * Fills elements of `array` with `value` from `start` up to, but not
  6567. * including, `end`.
  6568. *
  6569. * **Note:** This method mutates `array`.
  6570. *
  6571. * @static
  6572. * @memberOf _
  6573. * @since 3.2.0
  6574. * @category Array
  6575. * @param {Array} array The array to fill.
  6576. * @param {*} value The value to fill `array` with.
  6577. * @param {number} [start=0] The start position.
  6578. * @param {number} [end=array.length] The end position.
  6579. * @returns {Array} Returns `array`.
  6580. * @example
  6581. *
  6582. * var array = [1, 2, 3];
  6583. *
  6584. * _.fill(array, 'a');
  6585. * console.log(array);
  6586. * // => ['a', 'a', 'a']
  6587. *
  6588. * _.fill(Array(3), 2);
  6589. * // => [2, 2, 2]
  6590. *
  6591. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6592. * // => [4, '*', '*', 10]
  6593. */
  6594. function fill(array, value, start, end) {
  6595. var length = array == null ? 0 : array.length;
  6596. if (!length) {
  6597. return [];
  6598. }
  6599. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6600. start = 0;
  6601. end = length;
  6602. }
  6603. return baseFill(array, value, start, end);
  6604. }
  6605. /**
  6606. * This method is like `_.find` except that it returns the index of the first
  6607. * element `predicate` returns truthy for instead of the element itself.
  6608. *
  6609. * @static
  6610. * @memberOf _
  6611. * @since 1.1.0
  6612. * @category Array
  6613. * @param {Array} array The array to inspect.
  6614. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6615. * @param {number} [fromIndex=0] The index to search from.
  6616. * @returns {number} Returns the index of the found element, else `-1`.
  6617. * @example
  6618. *
  6619. * var users = [
  6620. * { 'user': 'barney', 'active': false },
  6621. * { 'user': 'fred', 'active': false },
  6622. * { 'user': 'pebbles', 'active': true }
  6623. * ];
  6624. *
  6625. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6626. * // => 0
  6627. *
  6628. * // The `_.matches` iteratee shorthand.
  6629. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6630. * // => 1
  6631. *
  6632. * // The `_.matchesProperty` iteratee shorthand.
  6633. * _.findIndex(users, ['active', false]);
  6634. * // => 0
  6635. *
  6636. * // The `_.property` iteratee shorthand.
  6637. * _.findIndex(users, 'active');
  6638. * // => 2
  6639. */
  6640. function findIndex(array, predicate, fromIndex) {
  6641. var length = array == null ? 0 : array.length;
  6642. if (!length) {
  6643. return -1;
  6644. }
  6645. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6646. if (index < 0) {
  6647. index = nativeMax(length + index, 0);
  6648. }
  6649. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6650. }
  6651. /**
  6652. * This method is like `_.findIndex` except that it iterates over elements
  6653. * of `collection` from right to left.
  6654. *
  6655. * @static
  6656. * @memberOf _
  6657. * @since 2.0.0
  6658. * @category Array
  6659. * @param {Array} array The array to inspect.
  6660. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6661. * @param {number} [fromIndex=array.length-1] The index to search from.
  6662. * @returns {number} Returns the index of the found element, else `-1`.
  6663. * @example
  6664. *
  6665. * var users = [
  6666. * { 'user': 'barney', 'active': true },
  6667. * { 'user': 'fred', 'active': false },
  6668. * { 'user': 'pebbles', 'active': false }
  6669. * ];
  6670. *
  6671. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6672. * // => 2
  6673. *
  6674. * // The `_.matches` iteratee shorthand.
  6675. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6676. * // => 0
  6677. *
  6678. * // The `_.matchesProperty` iteratee shorthand.
  6679. * _.findLastIndex(users, ['active', false]);
  6680. * // => 2
  6681. *
  6682. * // The `_.property` iteratee shorthand.
  6683. * _.findLastIndex(users, 'active');
  6684. * // => 0
  6685. */
  6686. function findLastIndex(array, predicate, fromIndex) {
  6687. var length = array == null ? 0 : array.length;
  6688. if (!length) {
  6689. return -1;
  6690. }
  6691. var index = length - 1;
  6692. if (fromIndex !== undefined) {
  6693. index = toInteger(fromIndex);
  6694. index = fromIndex < 0
  6695. ? nativeMax(length + index, 0)
  6696. : nativeMin(index, length - 1);
  6697. }
  6698. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6699. }
  6700. /**
  6701. * Flattens `array` a single level deep.
  6702. *
  6703. * @static
  6704. * @memberOf _
  6705. * @since 0.1.0
  6706. * @category Array
  6707. * @param {Array} array The array to flatten.
  6708. * @returns {Array} Returns the new flattened array.
  6709. * @example
  6710. *
  6711. * _.flatten([1, [2, [3, [4]], 5]]);
  6712. * // => [1, 2, [3, [4]], 5]
  6713. */
  6714. function flatten(array) {
  6715. var length = array == null ? 0 : array.length;
  6716. return length ? baseFlatten(array, 1) : [];
  6717. }
  6718. /**
  6719. * Recursively flattens `array`.
  6720. *
  6721. * @static
  6722. * @memberOf _
  6723. * @since 3.0.0
  6724. * @category Array
  6725. * @param {Array} array The array to flatten.
  6726. * @returns {Array} Returns the new flattened array.
  6727. * @example
  6728. *
  6729. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6730. * // => [1, 2, 3, 4, 5]
  6731. */
  6732. function flattenDeep(array) {
  6733. var length = array == null ? 0 : array.length;
  6734. return length ? baseFlatten(array, INFINITY) : [];
  6735. }
  6736. /**
  6737. * Recursively flatten `array` up to `depth` times.
  6738. *
  6739. * @static
  6740. * @memberOf _
  6741. * @since 4.4.0
  6742. * @category Array
  6743. * @param {Array} array The array to flatten.
  6744. * @param {number} [depth=1] The maximum recursion depth.
  6745. * @returns {Array} Returns the new flattened array.
  6746. * @example
  6747. *
  6748. * var array = [1, [2, [3, [4]], 5]];
  6749. *
  6750. * _.flattenDepth(array, 1);
  6751. * // => [1, 2, [3, [4]], 5]
  6752. *
  6753. * _.flattenDepth(array, 2);
  6754. * // => [1, 2, 3, [4], 5]
  6755. */
  6756. function flattenDepth(array, depth) {
  6757. var length = array == null ? 0 : array.length;
  6758. if (!length) {
  6759. return [];
  6760. }
  6761. depth = depth === undefined ? 1 : toInteger(depth);
  6762. return baseFlatten(array, depth);
  6763. }
  6764. /**
  6765. * The inverse of `_.toPairs`; this method returns an object composed
  6766. * from key-value `pairs`.
  6767. *
  6768. * @static
  6769. * @memberOf _
  6770. * @since 4.0.0
  6771. * @category Array
  6772. * @param {Array} pairs The key-value pairs.
  6773. * @returns {Object} Returns the new object.
  6774. * @example
  6775. *
  6776. * _.fromPairs([['a', 1], ['b', 2]]);
  6777. * // => { 'a': 1, 'b': 2 }
  6778. */
  6779. function fromPairs(pairs) {
  6780. var index = -1,
  6781. length = pairs == null ? 0 : pairs.length,
  6782. result = {};
  6783. while (++index < length) {
  6784. var pair = pairs[index];
  6785. result[pair[0]] = pair[1];
  6786. }
  6787. return result;
  6788. }
  6789. /**
  6790. * Gets the first element of `array`.
  6791. *
  6792. * @static
  6793. * @memberOf _
  6794. * @since 0.1.0
  6795. * @alias first
  6796. * @category Array
  6797. * @param {Array} array The array to query.
  6798. * @returns {*} Returns the first element of `array`.
  6799. * @example
  6800. *
  6801. * _.head([1, 2, 3]);
  6802. * // => 1
  6803. *
  6804. * _.head([]);
  6805. * // => undefined
  6806. */
  6807. function head(array) {
  6808. return (array && array.length) ? array[0] : undefined;
  6809. }
  6810. /**
  6811. * Gets the index at which the first occurrence of `value` is found in `array`
  6812. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6813. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6814. * offset from the end of `array`.
  6815. *
  6816. * @static
  6817. * @memberOf _
  6818. * @since 0.1.0
  6819. * @category Array
  6820. * @param {Array} array The array to inspect.
  6821. * @param {*} value The value to search for.
  6822. * @param {number} [fromIndex=0] The index to search from.
  6823. * @returns {number} Returns the index of the matched value, else `-1`.
  6824. * @example
  6825. *
  6826. * _.indexOf([1, 2, 1, 2], 2);
  6827. * // => 1
  6828. *
  6829. * // Search from the `fromIndex`.
  6830. * _.indexOf([1, 2, 1, 2], 2, 2);
  6831. * // => 3
  6832. */
  6833. function indexOf(array, value, fromIndex) {
  6834. var length = array == null ? 0 : array.length;
  6835. if (!length) {
  6836. return -1;
  6837. }
  6838. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6839. if (index < 0) {
  6840. index = nativeMax(length + index, 0);
  6841. }
  6842. return baseIndexOf(array, value, index);
  6843. }
  6844. /**
  6845. * Gets all but the last element of `array`.
  6846. *
  6847. * @static
  6848. * @memberOf _
  6849. * @since 0.1.0
  6850. * @category Array
  6851. * @param {Array} array The array to query.
  6852. * @returns {Array} Returns the slice of `array`.
  6853. * @example
  6854. *
  6855. * _.initial([1, 2, 3]);
  6856. * // => [1, 2]
  6857. */
  6858. function initial(array) {
  6859. var length = array == null ? 0 : array.length;
  6860. return length ? baseSlice(array, 0, -1) : [];
  6861. }
  6862. /**
  6863. * Creates an array of unique values that are included in all given arrays
  6864. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6865. * for equality comparisons. The order and references of result values are
  6866. * determined by the first array.
  6867. *
  6868. * @static
  6869. * @memberOf _
  6870. * @since 0.1.0
  6871. * @category Array
  6872. * @param {...Array} [arrays] The arrays to inspect.
  6873. * @returns {Array} Returns the new array of intersecting values.
  6874. * @example
  6875. *
  6876. * _.intersection([2, 1], [2, 3]);
  6877. * // => [2]
  6878. */
  6879. var intersection = baseRest(function(arrays) {
  6880. var mapped = arrayMap(arrays, castArrayLikeObject);
  6881. return (mapped.length && mapped[0] === arrays[0])
  6882. ? baseIntersection(mapped)
  6883. : [];
  6884. });
  6885. /**
  6886. * This method is like `_.intersection` except that it accepts `iteratee`
  6887. * which is invoked for each element of each `arrays` to generate the criterion
  6888. * by which they're compared. The order and references of result values are
  6889. * determined by the first array. The iteratee is invoked with one argument:
  6890. * (value).
  6891. *
  6892. * @static
  6893. * @memberOf _
  6894. * @since 4.0.0
  6895. * @category Array
  6896. * @param {...Array} [arrays] The arrays to inspect.
  6897. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6898. * @returns {Array} Returns the new array of intersecting values.
  6899. * @example
  6900. *
  6901. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6902. * // => [2.1]
  6903. *
  6904. * // The `_.property` iteratee shorthand.
  6905. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6906. * // => [{ 'x': 1 }]
  6907. */
  6908. var intersectionBy = baseRest(function(arrays) {
  6909. var iteratee = last(arrays),
  6910. mapped = arrayMap(arrays, castArrayLikeObject);
  6911. if (iteratee === last(mapped)) {
  6912. iteratee = undefined;
  6913. } else {
  6914. mapped.pop();
  6915. }
  6916. return (mapped.length && mapped[0] === arrays[0])
  6917. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6918. : [];
  6919. });
  6920. /**
  6921. * This method is like `_.intersection` except that it accepts `comparator`
  6922. * which is invoked to compare elements of `arrays`. The order and references
  6923. * of result values are determined by the first array. The comparator is
  6924. * invoked with two arguments: (arrVal, othVal).
  6925. *
  6926. * @static
  6927. * @memberOf _
  6928. * @since 4.0.0
  6929. * @category Array
  6930. * @param {...Array} [arrays] The arrays to inspect.
  6931. * @param {Function} [comparator] The comparator invoked per element.
  6932. * @returns {Array} Returns the new array of intersecting values.
  6933. * @example
  6934. *
  6935. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6936. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6937. *
  6938. * _.intersectionWith(objects, others, _.isEqual);
  6939. * // => [{ 'x': 1, 'y': 2 }]
  6940. */
  6941. var intersectionWith = baseRest(function(arrays) {
  6942. var comparator = last(arrays),
  6943. mapped = arrayMap(arrays, castArrayLikeObject);
  6944. comparator = typeof comparator == 'function' ? comparator : undefined;
  6945. if (comparator) {
  6946. mapped.pop();
  6947. }
  6948. return (mapped.length && mapped[0] === arrays[0])
  6949. ? baseIntersection(mapped, undefined, comparator)
  6950. : [];
  6951. });
  6952. /**
  6953. * Converts all elements in `array` into a string separated by `separator`.
  6954. *
  6955. * @static
  6956. * @memberOf _
  6957. * @since 4.0.0
  6958. * @category Array
  6959. * @param {Array} array The array to convert.
  6960. * @param {string} [separator=','] The element separator.
  6961. * @returns {string} Returns the joined string.
  6962. * @example
  6963. *
  6964. * _.join(['a', 'b', 'c'], '~');
  6965. * // => 'a~b~c'
  6966. */
  6967. function join(array, separator) {
  6968. return array == null ? '' : nativeJoin.call(array, separator);
  6969. }
  6970. /**
  6971. * Gets the last element of `array`.
  6972. *
  6973. * @static
  6974. * @memberOf _
  6975. * @since 0.1.0
  6976. * @category Array
  6977. * @param {Array} array The array to query.
  6978. * @returns {*} Returns the last element of `array`.
  6979. * @example
  6980. *
  6981. * _.last([1, 2, 3]);
  6982. * // => 3
  6983. */
  6984. function last(array) {
  6985. var length = array == null ? 0 : array.length;
  6986. return length ? array[length - 1] : undefined;
  6987. }
  6988. /**
  6989. * This method is like `_.indexOf` except that it iterates over elements of
  6990. * `array` from right to left.
  6991. *
  6992. * @static
  6993. * @memberOf _
  6994. * @since 0.1.0
  6995. * @category Array
  6996. * @param {Array} array The array to inspect.
  6997. * @param {*} value The value to search for.
  6998. * @param {number} [fromIndex=array.length-1] The index to search from.
  6999. * @returns {number} Returns the index of the matched value, else `-1`.
  7000. * @example
  7001. *
  7002. * _.lastIndexOf([1, 2, 1, 2], 2);
  7003. * // => 3
  7004. *
  7005. * // Search from the `fromIndex`.
  7006. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7007. * // => 1
  7008. */
  7009. function lastIndexOf(array, value, fromIndex) {
  7010. var length = array == null ? 0 : array.length;
  7011. if (!length) {
  7012. return -1;
  7013. }
  7014. var index = length;
  7015. if (fromIndex !== undefined) {
  7016. index = toInteger(fromIndex);
  7017. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7018. }
  7019. return value === value
  7020. ? strictLastIndexOf(array, value, index)
  7021. : baseFindIndex(array, baseIsNaN, index, true);
  7022. }
  7023. /**
  7024. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7025. * element from the end is returned.
  7026. *
  7027. * @static
  7028. * @memberOf _
  7029. * @since 4.11.0
  7030. * @category Array
  7031. * @param {Array} array The array to query.
  7032. * @param {number} [n=0] The index of the element to return.
  7033. * @returns {*} Returns the nth element of `array`.
  7034. * @example
  7035. *
  7036. * var array = ['a', 'b', 'c', 'd'];
  7037. *
  7038. * _.nth(array, 1);
  7039. * // => 'b'
  7040. *
  7041. * _.nth(array, -2);
  7042. * // => 'c';
  7043. */
  7044. function nth(array, n) {
  7045. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7046. }
  7047. /**
  7048. * Removes all given values from `array` using
  7049. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7050. * for equality comparisons.
  7051. *
  7052. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7053. * to remove elements from an array by predicate.
  7054. *
  7055. * @static
  7056. * @memberOf _
  7057. * @since 2.0.0
  7058. * @category Array
  7059. * @param {Array} array The array to modify.
  7060. * @param {...*} [values] The values to remove.
  7061. * @returns {Array} Returns `array`.
  7062. * @example
  7063. *
  7064. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7065. *
  7066. * _.pull(array, 'a', 'c');
  7067. * console.log(array);
  7068. * // => ['b', 'b']
  7069. */
  7070. var pull = baseRest(pullAll);
  7071. /**
  7072. * This method is like `_.pull` except that it accepts an array of values to remove.
  7073. *
  7074. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7075. *
  7076. * @static
  7077. * @memberOf _
  7078. * @since 4.0.0
  7079. * @category Array
  7080. * @param {Array} array The array to modify.
  7081. * @param {Array} values The values to remove.
  7082. * @returns {Array} Returns `array`.
  7083. * @example
  7084. *
  7085. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7086. *
  7087. * _.pullAll(array, ['a', 'c']);
  7088. * console.log(array);
  7089. * // => ['b', 'b']
  7090. */
  7091. function pullAll(array, values) {
  7092. return (array && array.length && values && values.length)
  7093. ? basePullAll(array, values)
  7094. : array;
  7095. }
  7096. /**
  7097. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7098. * invoked for each element of `array` and `values` to generate the criterion
  7099. * by which they're compared. The iteratee is invoked with one argument: (value).
  7100. *
  7101. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7102. *
  7103. * @static
  7104. * @memberOf _
  7105. * @since 4.0.0
  7106. * @category Array
  7107. * @param {Array} array The array to modify.
  7108. * @param {Array} values The values to remove.
  7109. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7110. * @returns {Array} Returns `array`.
  7111. * @example
  7112. *
  7113. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7114. *
  7115. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7116. * console.log(array);
  7117. * // => [{ 'x': 2 }]
  7118. */
  7119. function pullAllBy(array, values, iteratee) {
  7120. return (array && array.length && values && values.length)
  7121. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7122. : array;
  7123. }
  7124. /**
  7125. * This method is like `_.pullAll` except that it accepts `comparator` which
  7126. * is invoked to compare elements of `array` to `values`. The comparator is
  7127. * invoked with two arguments: (arrVal, othVal).
  7128. *
  7129. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7130. *
  7131. * @static
  7132. * @memberOf _
  7133. * @since 4.6.0
  7134. * @category Array
  7135. * @param {Array} array The array to modify.
  7136. * @param {Array} values The values to remove.
  7137. * @param {Function} [comparator] The comparator invoked per element.
  7138. * @returns {Array} Returns `array`.
  7139. * @example
  7140. *
  7141. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7142. *
  7143. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7144. * console.log(array);
  7145. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7146. */
  7147. function pullAllWith(array, values, comparator) {
  7148. return (array && array.length && values && values.length)
  7149. ? basePullAll(array, values, undefined, comparator)
  7150. : array;
  7151. }
  7152. /**
  7153. * Removes elements from `array` corresponding to `indexes` and returns an
  7154. * array of removed elements.
  7155. *
  7156. * **Note:** Unlike `_.at`, this method mutates `array`.
  7157. *
  7158. * @static
  7159. * @memberOf _
  7160. * @since 3.0.0
  7161. * @category Array
  7162. * @param {Array} array The array to modify.
  7163. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7164. * @returns {Array} Returns the new array of removed elements.
  7165. * @example
  7166. *
  7167. * var array = ['a', 'b', 'c', 'd'];
  7168. * var pulled = _.pullAt(array, [1, 3]);
  7169. *
  7170. * console.log(array);
  7171. * // => ['a', 'c']
  7172. *
  7173. * console.log(pulled);
  7174. * // => ['b', 'd']
  7175. */
  7176. var pullAt = flatRest(function(array, indexes) {
  7177. var length = array == null ? 0 : array.length,
  7178. result = baseAt(array, indexes);
  7179. basePullAt(array, arrayMap(indexes, function(index) {
  7180. return isIndex(index, length) ? +index : index;
  7181. }).sort(compareAscending));
  7182. return result;
  7183. });
  7184. /**
  7185. * Removes all elements from `array` that `predicate` returns truthy for
  7186. * and returns an array of the removed elements. The predicate is invoked
  7187. * with three arguments: (value, index, array).
  7188. *
  7189. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7190. * to pull elements from an array by value.
  7191. *
  7192. * @static
  7193. * @memberOf _
  7194. * @since 2.0.0
  7195. * @category Array
  7196. * @param {Array} array The array to modify.
  7197. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7198. * @returns {Array} Returns the new array of removed elements.
  7199. * @example
  7200. *
  7201. * var array = [1, 2, 3, 4];
  7202. * var evens = _.remove(array, function(n) {
  7203. * return n % 2 == 0;
  7204. * });
  7205. *
  7206. * console.log(array);
  7207. * // => [1, 3]
  7208. *
  7209. * console.log(evens);
  7210. * // => [2, 4]
  7211. */
  7212. function remove(array, predicate) {
  7213. var result = [];
  7214. if (!(array && array.length)) {
  7215. return result;
  7216. }
  7217. var index = -1,
  7218. indexes = [],
  7219. length = array.length;
  7220. predicate = getIteratee(predicate, 3);
  7221. while (++index < length) {
  7222. var value = array[index];
  7223. if (predicate(value, index, array)) {
  7224. result.push(value);
  7225. indexes.push(index);
  7226. }
  7227. }
  7228. basePullAt(array, indexes);
  7229. return result;
  7230. }
  7231. /**
  7232. * Reverses `array` so that the first element becomes the last, the second
  7233. * element becomes the second to last, and so on.
  7234. *
  7235. * **Note:** This method mutates `array` and is based on
  7236. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7237. *
  7238. * @static
  7239. * @memberOf _
  7240. * @since 4.0.0
  7241. * @category Array
  7242. * @param {Array} array The array to modify.
  7243. * @returns {Array} Returns `array`.
  7244. * @example
  7245. *
  7246. * var array = [1, 2, 3];
  7247. *
  7248. * _.reverse(array);
  7249. * // => [3, 2, 1]
  7250. *
  7251. * console.log(array);
  7252. * // => [3, 2, 1]
  7253. */
  7254. function reverse(array) {
  7255. return array == null ? array : nativeReverse.call(array);
  7256. }
  7257. /**
  7258. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7259. *
  7260. * **Note:** This method is used instead of
  7261. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7262. * returned.
  7263. *
  7264. * @static
  7265. * @memberOf _
  7266. * @since 3.0.0
  7267. * @category Array
  7268. * @param {Array} array The array to slice.
  7269. * @param {number} [start=0] The start position.
  7270. * @param {number} [end=array.length] The end position.
  7271. * @returns {Array} Returns the slice of `array`.
  7272. */
  7273. function slice(array, start, end) {
  7274. var length = array == null ? 0 : array.length;
  7275. if (!length) {
  7276. return [];
  7277. }
  7278. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7279. start = 0;
  7280. end = length;
  7281. }
  7282. else {
  7283. start = start == null ? 0 : toInteger(start);
  7284. end = end === undefined ? length : toInteger(end);
  7285. }
  7286. return baseSlice(array, start, end);
  7287. }
  7288. /**
  7289. * Uses a binary search to determine the lowest index at which `value`
  7290. * should be inserted into `array` in order to maintain its sort order.
  7291. *
  7292. * @static
  7293. * @memberOf _
  7294. * @since 0.1.0
  7295. * @category Array
  7296. * @param {Array} array The sorted array to inspect.
  7297. * @param {*} value The value to evaluate.
  7298. * @returns {number} Returns the index at which `value` should be inserted
  7299. * into `array`.
  7300. * @example
  7301. *
  7302. * _.sortedIndex([30, 50], 40);
  7303. * // => 1
  7304. */
  7305. function sortedIndex(array, value) {
  7306. return baseSortedIndex(array, value);
  7307. }
  7308. /**
  7309. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7310. * which is invoked for `value` and each element of `array` to compute their
  7311. * sort ranking. The iteratee is invoked with one argument: (value).
  7312. *
  7313. * @static
  7314. * @memberOf _
  7315. * @since 4.0.0
  7316. * @category Array
  7317. * @param {Array} array The sorted array to inspect.
  7318. * @param {*} value The value to evaluate.
  7319. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7320. * @returns {number} Returns the index at which `value` should be inserted
  7321. * into `array`.
  7322. * @example
  7323. *
  7324. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7325. *
  7326. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7327. * // => 0
  7328. *
  7329. * // The `_.property` iteratee shorthand.
  7330. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7331. * // => 0
  7332. */
  7333. function sortedIndexBy(array, value, iteratee) {
  7334. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7335. }
  7336. /**
  7337. * This method is like `_.indexOf` except that it performs a binary
  7338. * search on a sorted `array`.
  7339. *
  7340. * @static
  7341. * @memberOf _
  7342. * @since 4.0.0
  7343. * @category Array
  7344. * @param {Array} array The array to inspect.
  7345. * @param {*} value The value to search for.
  7346. * @returns {number} Returns the index of the matched value, else `-1`.
  7347. * @example
  7348. *
  7349. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7350. * // => 1
  7351. */
  7352. function sortedIndexOf(array, value) {
  7353. var length = array == null ? 0 : array.length;
  7354. if (length) {
  7355. var index = baseSortedIndex(array, value);
  7356. if (index < length && eq(array[index], value)) {
  7357. return index;
  7358. }
  7359. }
  7360. return -1;
  7361. }
  7362. /**
  7363. * This method is like `_.sortedIndex` except that it returns the highest
  7364. * index at which `value` should be inserted into `array` in order to
  7365. * maintain its sort order.
  7366. *
  7367. * @static
  7368. * @memberOf _
  7369. * @since 3.0.0
  7370. * @category Array
  7371. * @param {Array} array The sorted array to inspect.
  7372. * @param {*} value The value to evaluate.
  7373. * @returns {number} Returns the index at which `value` should be inserted
  7374. * into `array`.
  7375. * @example
  7376. *
  7377. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7378. * // => 4
  7379. */
  7380. function sortedLastIndex(array, value) {
  7381. return baseSortedIndex(array, value, true);
  7382. }
  7383. /**
  7384. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7385. * which is invoked for `value` and each element of `array` to compute their
  7386. * sort ranking. The iteratee is invoked with one argument: (value).
  7387. *
  7388. * @static
  7389. * @memberOf _
  7390. * @since 4.0.0
  7391. * @category Array
  7392. * @param {Array} array The sorted array to inspect.
  7393. * @param {*} value The value to evaluate.
  7394. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7395. * @returns {number} Returns the index at which `value` should be inserted
  7396. * into `array`.
  7397. * @example
  7398. *
  7399. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7400. *
  7401. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7402. * // => 1
  7403. *
  7404. * // The `_.property` iteratee shorthand.
  7405. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7406. * // => 1
  7407. */
  7408. function sortedLastIndexBy(array, value, iteratee) {
  7409. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7410. }
  7411. /**
  7412. * This method is like `_.lastIndexOf` except that it performs a binary
  7413. * search on a sorted `array`.
  7414. *
  7415. * @static
  7416. * @memberOf _
  7417. * @since 4.0.0
  7418. * @category Array
  7419. * @param {Array} array The array to inspect.
  7420. * @param {*} value The value to search for.
  7421. * @returns {number} Returns the index of the matched value, else `-1`.
  7422. * @example
  7423. *
  7424. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7425. * // => 3
  7426. */
  7427. function sortedLastIndexOf(array, value) {
  7428. var length = array == null ? 0 : array.length;
  7429. if (length) {
  7430. var index = baseSortedIndex(array, value, true) - 1;
  7431. if (eq(array[index], value)) {
  7432. return index;
  7433. }
  7434. }
  7435. return -1;
  7436. }
  7437. /**
  7438. * This method is like `_.uniq` except that it's designed and optimized
  7439. * for sorted arrays.
  7440. *
  7441. * @static
  7442. * @memberOf _
  7443. * @since 4.0.0
  7444. * @category Array
  7445. * @param {Array} array The array to inspect.
  7446. * @returns {Array} Returns the new duplicate free array.
  7447. * @example
  7448. *
  7449. * _.sortedUniq([1, 1, 2]);
  7450. * // => [1, 2]
  7451. */
  7452. function sortedUniq(array) {
  7453. return (array && array.length)
  7454. ? baseSortedUniq(array)
  7455. : [];
  7456. }
  7457. /**
  7458. * This method is like `_.uniqBy` except that it's designed and optimized
  7459. * for sorted arrays.
  7460. *
  7461. * @static
  7462. * @memberOf _
  7463. * @since 4.0.0
  7464. * @category Array
  7465. * @param {Array} array The array to inspect.
  7466. * @param {Function} [iteratee] The iteratee invoked per element.
  7467. * @returns {Array} Returns the new duplicate free array.
  7468. * @example
  7469. *
  7470. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7471. * // => [1.1, 2.3]
  7472. */
  7473. function sortedUniqBy(array, iteratee) {
  7474. return (array && array.length)
  7475. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7476. : [];
  7477. }
  7478. /**
  7479. * Gets all but the first element of `array`.
  7480. *
  7481. * @static
  7482. * @memberOf _
  7483. * @since 4.0.0
  7484. * @category Array
  7485. * @param {Array} array The array to query.
  7486. * @returns {Array} Returns the slice of `array`.
  7487. * @example
  7488. *
  7489. * _.tail([1, 2, 3]);
  7490. * // => [2, 3]
  7491. */
  7492. function tail(array) {
  7493. var length = array == null ? 0 : array.length;
  7494. return length ? baseSlice(array, 1, length) : [];
  7495. }
  7496. /**
  7497. * Creates a slice of `array` with `n` elements taken from the beginning.
  7498. *
  7499. * @static
  7500. * @memberOf _
  7501. * @since 0.1.0
  7502. * @category Array
  7503. * @param {Array} array The array to query.
  7504. * @param {number} [n=1] The number of elements to take.
  7505. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7506. * @returns {Array} Returns the slice of `array`.
  7507. * @example
  7508. *
  7509. * _.take([1, 2, 3]);
  7510. * // => [1]
  7511. *
  7512. * _.take([1, 2, 3], 2);
  7513. * // => [1, 2]
  7514. *
  7515. * _.take([1, 2, 3], 5);
  7516. * // => [1, 2, 3]
  7517. *
  7518. * _.take([1, 2, 3], 0);
  7519. * // => []
  7520. */
  7521. function take(array, n, guard) {
  7522. if (!(array && array.length)) {
  7523. return [];
  7524. }
  7525. n = (guard || n === undefined) ? 1 : toInteger(n);
  7526. return baseSlice(array, 0, n < 0 ? 0 : n);
  7527. }
  7528. /**
  7529. * Creates a slice of `array` with `n` elements taken from the end.
  7530. *
  7531. * @static
  7532. * @memberOf _
  7533. * @since 3.0.0
  7534. * @category Array
  7535. * @param {Array} array The array to query.
  7536. * @param {number} [n=1] The number of elements to take.
  7537. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7538. * @returns {Array} Returns the slice of `array`.
  7539. * @example
  7540. *
  7541. * _.takeRight([1, 2, 3]);
  7542. * // => [3]
  7543. *
  7544. * _.takeRight([1, 2, 3], 2);
  7545. * // => [2, 3]
  7546. *
  7547. * _.takeRight([1, 2, 3], 5);
  7548. * // => [1, 2, 3]
  7549. *
  7550. * _.takeRight([1, 2, 3], 0);
  7551. * // => []
  7552. */
  7553. function takeRight(array, n, guard) {
  7554. var length = array == null ? 0 : array.length;
  7555. if (!length) {
  7556. return [];
  7557. }
  7558. n = (guard || n === undefined) ? 1 : toInteger(n);
  7559. n = length - n;
  7560. return baseSlice(array, n < 0 ? 0 : n, length);
  7561. }
  7562. /**
  7563. * Creates a slice of `array` with elements taken from the end. Elements are
  7564. * taken until `predicate` returns falsey. The predicate is invoked with
  7565. * three arguments: (value, index, array).
  7566. *
  7567. * @static
  7568. * @memberOf _
  7569. * @since 3.0.0
  7570. * @category Array
  7571. * @param {Array} array The array to query.
  7572. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7573. * @returns {Array} Returns the slice of `array`.
  7574. * @example
  7575. *
  7576. * var users = [
  7577. * { 'user': 'barney', 'active': true },
  7578. * { 'user': 'fred', 'active': false },
  7579. * { 'user': 'pebbles', 'active': false }
  7580. * ];
  7581. *
  7582. * _.takeRightWhile(users, function(o) { return !o.active; });
  7583. * // => objects for ['fred', 'pebbles']
  7584. *
  7585. * // The `_.matches` iteratee shorthand.
  7586. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7587. * // => objects for ['pebbles']
  7588. *
  7589. * // The `_.matchesProperty` iteratee shorthand.
  7590. * _.takeRightWhile(users, ['active', false]);
  7591. * // => objects for ['fred', 'pebbles']
  7592. *
  7593. * // The `_.property` iteratee shorthand.
  7594. * _.takeRightWhile(users, 'active');
  7595. * // => []
  7596. */
  7597. function takeRightWhile(array, predicate) {
  7598. return (array && array.length)
  7599. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7600. : [];
  7601. }
  7602. /**
  7603. * Creates a slice of `array` with elements taken from the beginning. Elements
  7604. * are taken until `predicate` returns falsey. The predicate is invoked with
  7605. * three arguments: (value, index, array).
  7606. *
  7607. * @static
  7608. * @memberOf _
  7609. * @since 3.0.0
  7610. * @category Array
  7611. * @param {Array} array The array to query.
  7612. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7613. * @returns {Array} Returns the slice of `array`.
  7614. * @example
  7615. *
  7616. * var users = [
  7617. * { 'user': 'barney', 'active': false },
  7618. * { 'user': 'fred', 'active': false },
  7619. * { 'user': 'pebbles', 'active': true }
  7620. * ];
  7621. *
  7622. * _.takeWhile(users, function(o) { return !o.active; });
  7623. * // => objects for ['barney', 'fred']
  7624. *
  7625. * // The `_.matches` iteratee shorthand.
  7626. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7627. * // => objects for ['barney']
  7628. *
  7629. * // The `_.matchesProperty` iteratee shorthand.
  7630. * _.takeWhile(users, ['active', false]);
  7631. * // => objects for ['barney', 'fred']
  7632. *
  7633. * // The `_.property` iteratee shorthand.
  7634. * _.takeWhile(users, 'active');
  7635. * // => []
  7636. */
  7637. function takeWhile(array, predicate) {
  7638. return (array && array.length)
  7639. ? baseWhile(array, getIteratee(predicate, 3))
  7640. : [];
  7641. }
  7642. /**
  7643. * Creates an array of unique values, in order, from all given arrays using
  7644. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7645. * for equality comparisons.
  7646. *
  7647. * @static
  7648. * @memberOf _
  7649. * @since 0.1.0
  7650. * @category Array
  7651. * @param {...Array} [arrays] The arrays to inspect.
  7652. * @returns {Array} Returns the new array of combined values.
  7653. * @example
  7654. *
  7655. * _.union([2], [1, 2]);
  7656. * // => [2, 1]
  7657. */
  7658. var union = baseRest(function(arrays) {
  7659. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7660. });
  7661. /**
  7662. * This method is like `_.union` except that it accepts `iteratee` which is
  7663. * invoked for each element of each `arrays` to generate the criterion by
  7664. * which uniqueness is computed. Result values are chosen from the first
  7665. * array in which the value occurs. The iteratee is invoked with one argument:
  7666. * (value).
  7667. *
  7668. * @static
  7669. * @memberOf _
  7670. * @since 4.0.0
  7671. * @category Array
  7672. * @param {...Array} [arrays] The arrays to inspect.
  7673. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7674. * @returns {Array} Returns the new array of combined values.
  7675. * @example
  7676. *
  7677. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7678. * // => [2.1, 1.2]
  7679. *
  7680. * // The `_.property` iteratee shorthand.
  7681. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7682. * // => [{ 'x': 1 }, { 'x': 2 }]
  7683. */
  7684. var unionBy = baseRest(function(arrays) {
  7685. var iteratee = last(arrays);
  7686. if (isArrayLikeObject(iteratee)) {
  7687. iteratee = undefined;
  7688. }
  7689. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7690. });
  7691. /**
  7692. * This method is like `_.union` except that it accepts `comparator` which
  7693. * is invoked to compare elements of `arrays`. Result values are chosen from
  7694. * the first array in which the value occurs. The comparator is invoked
  7695. * with two arguments: (arrVal, othVal).
  7696. *
  7697. * @static
  7698. * @memberOf _
  7699. * @since 4.0.0
  7700. * @category Array
  7701. * @param {...Array} [arrays] The arrays to inspect.
  7702. * @param {Function} [comparator] The comparator invoked per element.
  7703. * @returns {Array} Returns the new array of combined values.
  7704. * @example
  7705. *
  7706. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7707. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7708. *
  7709. * _.unionWith(objects, others, _.isEqual);
  7710. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7711. */
  7712. var unionWith = baseRest(function(arrays) {
  7713. var comparator = last(arrays);
  7714. comparator = typeof comparator == 'function' ? comparator : undefined;
  7715. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7716. });
  7717. /**
  7718. * Creates a duplicate-free version of an array, using
  7719. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7720. * for equality comparisons, in which only the first occurrence of each element
  7721. * is kept. The order of result values is determined by the order they occur
  7722. * in the array.
  7723. *
  7724. * @static
  7725. * @memberOf _
  7726. * @since 0.1.0
  7727. * @category Array
  7728. * @param {Array} array The array to inspect.
  7729. * @returns {Array} Returns the new duplicate free array.
  7730. * @example
  7731. *
  7732. * _.uniq([2, 1, 2]);
  7733. * // => [2, 1]
  7734. */
  7735. function uniq(array) {
  7736. return (array && array.length) ? baseUniq(array) : [];
  7737. }
  7738. /**
  7739. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7740. * invoked for each element in `array` to generate the criterion by which
  7741. * uniqueness is computed. The order of result values is determined by the
  7742. * order they occur in the array. The iteratee is invoked with one argument:
  7743. * (value).
  7744. *
  7745. * @static
  7746. * @memberOf _
  7747. * @since 4.0.0
  7748. * @category Array
  7749. * @param {Array} array The array to inspect.
  7750. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7751. * @returns {Array} Returns the new duplicate free array.
  7752. * @example
  7753. *
  7754. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7755. * // => [2.1, 1.2]
  7756. *
  7757. * // The `_.property` iteratee shorthand.
  7758. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7759. * // => [{ 'x': 1 }, { 'x': 2 }]
  7760. */
  7761. function uniqBy(array, iteratee) {
  7762. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7763. }
  7764. /**
  7765. * This method is like `_.uniq` except that it accepts `comparator` which
  7766. * is invoked to compare elements of `array`. The order of result values is
  7767. * determined by the order they occur in the array.The comparator is invoked
  7768. * with two arguments: (arrVal, othVal).
  7769. *
  7770. * @static
  7771. * @memberOf _
  7772. * @since 4.0.0
  7773. * @category Array
  7774. * @param {Array} array The array to inspect.
  7775. * @param {Function} [comparator] The comparator invoked per element.
  7776. * @returns {Array} Returns the new duplicate free array.
  7777. * @example
  7778. *
  7779. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7780. *
  7781. * _.uniqWith(objects, _.isEqual);
  7782. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7783. */
  7784. function uniqWith(array, comparator) {
  7785. comparator = typeof comparator == 'function' ? comparator : undefined;
  7786. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7787. }
  7788. /**
  7789. * This method is like `_.zip` except that it accepts an array of grouped
  7790. * elements and creates an array regrouping the elements to their pre-zip
  7791. * configuration.
  7792. *
  7793. * @static
  7794. * @memberOf _
  7795. * @since 1.2.0
  7796. * @category Array
  7797. * @param {Array} array The array of grouped elements to process.
  7798. * @returns {Array} Returns the new array of regrouped elements.
  7799. * @example
  7800. *
  7801. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7802. * // => [['a', 1, true], ['b', 2, false]]
  7803. *
  7804. * _.unzip(zipped);
  7805. * // => [['a', 'b'], [1, 2], [true, false]]
  7806. */
  7807. function unzip(array) {
  7808. if (!(array && array.length)) {
  7809. return [];
  7810. }
  7811. var length = 0;
  7812. array = arrayFilter(array, function(group) {
  7813. if (isArrayLikeObject(group)) {
  7814. length = nativeMax(group.length, length);
  7815. return true;
  7816. }
  7817. });
  7818. return baseTimes(length, function(index) {
  7819. return arrayMap(array, baseProperty(index));
  7820. });
  7821. }
  7822. /**
  7823. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7824. * how regrouped values should be combined. The iteratee is invoked with the
  7825. * elements of each group: (...group).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 3.8.0
  7830. * @category Array
  7831. * @param {Array} array The array of grouped elements to process.
  7832. * @param {Function} [iteratee=_.identity] The function to combine
  7833. * regrouped values.
  7834. * @returns {Array} Returns the new array of regrouped elements.
  7835. * @example
  7836. *
  7837. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7838. * // => [[1, 10, 100], [2, 20, 200]]
  7839. *
  7840. * _.unzipWith(zipped, _.add);
  7841. * // => [3, 30, 300]
  7842. */
  7843. function unzipWith(array, iteratee) {
  7844. if (!(array && array.length)) {
  7845. return [];
  7846. }
  7847. var result = unzip(array);
  7848. if (iteratee == null) {
  7849. return result;
  7850. }
  7851. return arrayMap(result, function(group) {
  7852. return apply(iteratee, undefined, group);
  7853. });
  7854. }
  7855. /**
  7856. * Creates an array excluding all given values using
  7857. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7858. * for equality comparisons.
  7859. *
  7860. * **Note:** Unlike `_.pull`, this method returns a new array.
  7861. *
  7862. * @static
  7863. * @memberOf _
  7864. * @since 0.1.0
  7865. * @category Array
  7866. * @param {Array} array The array to inspect.
  7867. * @param {...*} [values] The values to exclude.
  7868. * @returns {Array} Returns the new array of filtered values.
  7869. * @see _.difference, _.xor
  7870. * @example
  7871. *
  7872. * _.without([2, 1, 2, 3], 1, 2);
  7873. * // => [3]
  7874. */
  7875. var without = baseRest(function(array, values) {
  7876. return isArrayLikeObject(array)
  7877. ? baseDifference(array, values)
  7878. : [];
  7879. });
  7880. /**
  7881. * Creates an array of unique values that is the
  7882. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7883. * of the given arrays. The order of result values is determined by the order
  7884. * they occur in the arrays.
  7885. *
  7886. * @static
  7887. * @memberOf _
  7888. * @since 2.4.0
  7889. * @category Array
  7890. * @param {...Array} [arrays] The arrays to inspect.
  7891. * @returns {Array} Returns the new array of filtered values.
  7892. * @see _.difference, _.without
  7893. * @example
  7894. *
  7895. * _.xor([2, 1], [2, 3]);
  7896. * // => [1, 3]
  7897. */
  7898. var xor = baseRest(function(arrays) {
  7899. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7900. });
  7901. /**
  7902. * This method is like `_.xor` except that it accepts `iteratee` which is
  7903. * invoked for each element of each `arrays` to generate the criterion by
  7904. * which by which they're compared. The order of result values is determined
  7905. * by the order they occur in the arrays. The iteratee is invoked with one
  7906. * argument: (value).
  7907. *
  7908. * @static
  7909. * @memberOf _
  7910. * @since 4.0.0
  7911. * @category Array
  7912. * @param {...Array} [arrays] The arrays to inspect.
  7913. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7914. * @returns {Array} Returns the new array of filtered values.
  7915. * @example
  7916. *
  7917. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7918. * // => [1.2, 3.4]
  7919. *
  7920. * // The `_.property` iteratee shorthand.
  7921. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7922. * // => [{ 'x': 2 }]
  7923. */
  7924. var xorBy = baseRest(function(arrays) {
  7925. var iteratee = last(arrays);
  7926. if (isArrayLikeObject(iteratee)) {
  7927. iteratee = undefined;
  7928. }
  7929. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7930. });
  7931. /**
  7932. * This method is like `_.xor` except that it accepts `comparator` which is
  7933. * invoked to compare elements of `arrays`. The order of result values is
  7934. * determined by the order they occur in the arrays. The comparator is invoked
  7935. * with two arguments: (arrVal, othVal).
  7936. *
  7937. * @static
  7938. * @memberOf _
  7939. * @since 4.0.0
  7940. * @category Array
  7941. * @param {...Array} [arrays] The arrays to inspect.
  7942. * @param {Function} [comparator] The comparator invoked per element.
  7943. * @returns {Array} Returns the new array of filtered values.
  7944. * @example
  7945. *
  7946. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7947. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7948. *
  7949. * _.xorWith(objects, others, _.isEqual);
  7950. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7951. */
  7952. var xorWith = baseRest(function(arrays) {
  7953. var comparator = last(arrays);
  7954. comparator = typeof comparator == 'function' ? comparator : undefined;
  7955. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7956. });
  7957. /**
  7958. * Creates an array of grouped elements, the first of which contains the
  7959. * first elements of the given arrays, the second of which contains the
  7960. * second elements of the given arrays, and so on.
  7961. *
  7962. * @static
  7963. * @memberOf _
  7964. * @since 0.1.0
  7965. * @category Array
  7966. * @param {...Array} [arrays] The arrays to process.
  7967. * @returns {Array} Returns the new array of grouped elements.
  7968. * @example
  7969. *
  7970. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7971. * // => [['a', 1, true], ['b', 2, false]]
  7972. */
  7973. var zip = baseRest(unzip);
  7974. /**
  7975. * This method is like `_.fromPairs` except that it accepts two arrays,
  7976. * one of property identifiers and one of corresponding values.
  7977. *
  7978. * @static
  7979. * @memberOf _
  7980. * @since 0.4.0
  7981. * @category Array
  7982. * @param {Array} [props=[]] The property identifiers.
  7983. * @param {Array} [values=[]] The property values.
  7984. * @returns {Object} Returns the new object.
  7985. * @example
  7986. *
  7987. * _.zipObject(['a', 'b'], [1, 2]);
  7988. * // => { 'a': 1, 'b': 2 }
  7989. */
  7990. function zipObject(props, values) {
  7991. return baseZipObject(props || [], values || [], assignValue);
  7992. }
  7993. /**
  7994. * This method is like `_.zipObject` except that it supports property paths.
  7995. *
  7996. * @static
  7997. * @memberOf _
  7998. * @since 4.1.0
  7999. * @category Array
  8000. * @param {Array} [props=[]] The property identifiers.
  8001. * @param {Array} [values=[]] The property values.
  8002. * @returns {Object} Returns the new object.
  8003. * @example
  8004. *
  8005. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8006. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8007. */
  8008. function zipObjectDeep(props, values) {
  8009. return baseZipObject(props || [], values || [], baseSet);
  8010. }
  8011. /**
  8012. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8013. * how grouped values should be combined. The iteratee is invoked with the
  8014. * elements of each group: (...group).
  8015. *
  8016. * @static
  8017. * @memberOf _
  8018. * @since 3.8.0
  8019. * @category Array
  8020. * @param {...Array} [arrays] The arrays to process.
  8021. * @param {Function} [iteratee=_.identity] The function to combine
  8022. * grouped values.
  8023. * @returns {Array} Returns the new array of grouped elements.
  8024. * @example
  8025. *
  8026. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8027. * return a + b + c;
  8028. * });
  8029. * // => [111, 222]
  8030. */
  8031. var zipWith = baseRest(function(arrays) {
  8032. var length = arrays.length,
  8033. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8034. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8035. return unzipWith(arrays, iteratee);
  8036. });
  8037. /*------------------------------------------------------------------------*/
  8038. /**
  8039. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8040. * chain sequences enabled. The result of such sequences must be unwrapped
  8041. * with `_#value`.
  8042. *
  8043. * @static
  8044. * @memberOf _
  8045. * @since 1.3.0
  8046. * @category Seq
  8047. * @param {*} value The value to wrap.
  8048. * @returns {Object} Returns the new `lodash` wrapper instance.
  8049. * @example
  8050. *
  8051. * var users = [
  8052. * { 'user': 'barney', 'age': 36 },
  8053. * { 'user': 'fred', 'age': 40 },
  8054. * { 'user': 'pebbles', 'age': 1 }
  8055. * ];
  8056. *
  8057. * var youngest = _
  8058. * .chain(users)
  8059. * .sortBy('age')
  8060. * .map(function(o) {
  8061. * return o.user + ' is ' + o.age;
  8062. * })
  8063. * .head()
  8064. * .value();
  8065. * // => 'pebbles is 1'
  8066. */
  8067. function chain(value) {
  8068. var result = lodash(value);
  8069. result.__chain__ = true;
  8070. return result;
  8071. }
  8072. /**
  8073. * This method invokes `interceptor` and returns `value`. The interceptor
  8074. * is invoked with one argument; (value). The purpose of this method is to
  8075. * "tap into" a method chain sequence in order to modify intermediate results.
  8076. *
  8077. * @static
  8078. * @memberOf _
  8079. * @since 0.1.0
  8080. * @category Seq
  8081. * @param {*} value The value to provide to `interceptor`.
  8082. * @param {Function} interceptor The function to invoke.
  8083. * @returns {*} Returns `value`.
  8084. * @example
  8085. *
  8086. * _([1, 2, 3])
  8087. * .tap(function(array) {
  8088. * // Mutate input array.
  8089. * array.pop();
  8090. * })
  8091. * .reverse()
  8092. * .value();
  8093. * // => [2, 1]
  8094. */
  8095. function tap(value, interceptor) {
  8096. interceptor(value);
  8097. return value;
  8098. }
  8099. /**
  8100. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8101. * The purpose of this method is to "pass thru" values replacing intermediate
  8102. * results in a method chain sequence.
  8103. *
  8104. * @static
  8105. * @memberOf _
  8106. * @since 3.0.0
  8107. * @category Seq
  8108. * @param {*} value The value to provide to `interceptor`.
  8109. * @param {Function} interceptor The function to invoke.
  8110. * @returns {*} Returns the result of `interceptor`.
  8111. * @example
  8112. *
  8113. * _(' abc ')
  8114. * .chain()
  8115. * .trim()
  8116. * .thru(function(value) {
  8117. * return [value];
  8118. * })
  8119. * .value();
  8120. * // => ['abc']
  8121. */
  8122. function thru(value, interceptor) {
  8123. return interceptor(value);
  8124. }
  8125. /**
  8126. * This method is the wrapper version of `_.at`.
  8127. *
  8128. * @name at
  8129. * @memberOf _
  8130. * @since 1.0.0
  8131. * @category Seq
  8132. * @param {...(string|string[])} [paths] The property paths to pick.
  8133. * @returns {Object} Returns the new `lodash` wrapper instance.
  8134. * @example
  8135. *
  8136. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8137. *
  8138. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8139. * // => [3, 4]
  8140. */
  8141. var wrapperAt = flatRest(function(paths) {
  8142. var length = paths.length,
  8143. start = length ? paths[0] : 0,
  8144. value = this.__wrapped__,
  8145. interceptor = function(object) { return baseAt(object, paths); };
  8146. if (length > 1 || this.__actions__.length ||
  8147. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8148. return this.thru(interceptor);
  8149. }
  8150. value = value.slice(start, +start + (length ? 1 : 0));
  8151. value.__actions__.push({
  8152. 'func': thru,
  8153. 'args': [interceptor],
  8154. 'thisArg': undefined
  8155. });
  8156. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8157. if (length && !array.length) {
  8158. array.push(undefined);
  8159. }
  8160. return array;
  8161. });
  8162. });
  8163. /**
  8164. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8165. *
  8166. * @name chain
  8167. * @memberOf _
  8168. * @since 0.1.0
  8169. * @category Seq
  8170. * @returns {Object} Returns the new `lodash` wrapper instance.
  8171. * @example
  8172. *
  8173. * var users = [
  8174. * { 'user': 'barney', 'age': 36 },
  8175. * { 'user': 'fred', 'age': 40 }
  8176. * ];
  8177. *
  8178. * // A sequence without explicit chaining.
  8179. * _(users).head();
  8180. * // => { 'user': 'barney', 'age': 36 }
  8181. *
  8182. * // A sequence with explicit chaining.
  8183. * _(users)
  8184. * .chain()
  8185. * .head()
  8186. * .pick('user')
  8187. * .value();
  8188. * // => { 'user': 'barney' }
  8189. */
  8190. function wrapperChain() {
  8191. return chain(this);
  8192. }
  8193. /**
  8194. * Executes the chain sequence and returns the wrapped result.
  8195. *
  8196. * @name commit
  8197. * @memberOf _
  8198. * @since 3.2.0
  8199. * @category Seq
  8200. * @returns {Object} Returns the new `lodash` wrapper instance.
  8201. * @example
  8202. *
  8203. * var array = [1, 2];
  8204. * var wrapped = _(array).push(3);
  8205. *
  8206. * console.log(array);
  8207. * // => [1, 2]
  8208. *
  8209. * wrapped = wrapped.commit();
  8210. * console.log(array);
  8211. * // => [1, 2, 3]
  8212. *
  8213. * wrapped.last();
  8214. * // => 3
  8215. *
  8216. * console.log(array);
  8217. * // => [1, 2, 3]
  8218. */
  8219. function wrapperCommit() {
  8220. return new LodashWrapper(this.value(), this.__chain__);
  8221. }
  8222. /**
  8223. * Gets the next value on a wrapped object following the
  8224. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8225. *
  8226. * @name next
  8227. * @memberOf _
  8228. * @since 4.0.0
  8229. * @category Seq
  8230. * @returns {Object} Returns the next iterator value.
  8231. * @example
  8232. *
  8233. * var wrapped = _([1, 2]);
  8234. *
  8235. * wrapped.next();
  8236. * // => { 'done': false, 'value': 1 }
  8237. *
  8238. * wrapped.next();
  8239. * // => { 'done': false, 'value': 2 }
  8240. *
  8241. * wrapped.next();
  8242. * // => { 'done': true, 'value': undefined }
  8243. */
  8244. function wrapperNext() {
  8245. if (this.__values__ === undefined) {
  8246. this.__values__ = toArray(this.value());
  8247. }
  8248. var done = this.__index__ >= this.__values__.length,
  8249. value = done ? undefined : this.__values__[this.__index__++];
  8250. return { 'done': done, 'value': value };
  8251. }
  8252. /**
  8253. * Enables the wrapper to be iterable.
  8254. *
  8255. * @name Symbol.iterator
  8256. * @memberOf _
  8257. * @since 4.0.0
  8258. * @category Seq
  8259. * @returns {Object} Returns the wrapper object.
  8260. * @example
  8261. *
  8262. * var wrapped = _([1, 2]);
  8263. *
  8264. * wrapped[Symbol.iterator]() === wrapped;
  8265. * // => true
  8266. *
  8267. * Array.from(wrapped);
  8268. * // => [1, 2]
  8269. */
  8270. function wrapperToIterator() {
  8271. return this;
  8272. }
  8273. /**
  8274. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8275. *
  8276. * @name plant
  8277. * @memberOf _
  8278. * @since 3.2.0
  8279. * @category Seq
  8280. * @param {*} value The value to plant.
  8281. * @returns {Object} Returns the new `lodash` wrapper instance.
  8282. * @example
  8283. *
  8284. * function square(n) {
  8285. * return n * n;
  8286. * }
  8287. *
  8288. * var wrapped = _([1, 2]).map(square);
  8289. * var other = wrapped.plant([3, 4]);
  8290. *
  8291. * other.value();
  8292. * // => [9, 16]
  8293. *
  8294. * wrapped.value();
  8295. * // => [1, 4]
  8296. */
  8297. function wrapperPlant(value) {
  8298. var result,
  8299. parent = this;
  8300. while (parent instanceof baseLodash) {
  8301. var clone = wrapperClone(parent);
  8302. clone.__index__ = 0;
  8303. clone.__values__ = undefined;
  8304. if (result) {
  8305. previous.__wrapped__ = clone;
  8306. } else {
  8307. result = clone;
  8308. }
  8309. var previous = clone;
  8310. parent = parent.__wrapped__;
  8311. }
  8312. previous.__wrapped__ = value;
  8313. return result;
  8314. }
  8315. /**
  8316. * This method is the wrapper version of `_.reverse`.
  8317. *
  8318. * **Note:** This method mutates the wrapped array.
  8319. *
  8320. * @name reverse
  8321. * @memberOf _
  8322. * @since 0.1.0
  8323. * @category Seq
  8324. * @returns {Object} Returns the new `lodash` wrapper instance.
  8325. * @example
  8326. *
  8327. * var array = [1, 2, 3];
  8328. *
  8329. * _(array).reverse().value()
  8330. * // => [3, 2, 1]
  8331. *
  8332. * console.log(array);
  8333. * // => [3, 2, 1]
  8334. */
  8335. function wrapperReverse() {
  8336. var value = this.__wrapped__;
  8337. if (value instanceof LazyWrapper) {
  8338. var wrapped = value;
  8339. if (this.__actions__.length) {
  8340. wrapped = new LazyWrapper(this);
  8341. }
  8342. wrapped = wrapped.reverse();
  8343. wrapped.__actions__.push({
  8344. 'func': thru,
  8345. 'args': [reverse],
  8346. 'thisArg': undefined
  8347. });
  8348. return new LodashWrapper(wrapped, this.__chain__);
  8349. }
  8350. return this.thru(reverse);
  8351. }
  8352. /**
  8353. * Executes the chain sequence to resolve the unwrapped value.
  8354. *
  8355. * @name value
  8356. * @memberOf _
  8357. * @since 0.1.0
  8358. * @alias toJSON, valueOf
  8359. * @category Seq
  8360. * @returns {*} Returns the resolved unwrapped value.
  8361. * @example
  8362. *
  8363. * _([1, 2, 3]).value();
  8364. * // => [1, 2, 3]
  8365. */
  8366. function wrapperValue() {
  8367. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8368. }
  8369. /*------------------------------------------------------------------------*/
  8370. /**
  8371. * Creates an object composed of keys generated from the results of running
  8372. * each element of `collection` thru `iteratee`. The corresponding value of
  8373. * each key is the number of times the key was returned by `iteratee`. The
  8374. * iteratee is invoked with one argument: (value).
  8375. *
  8376. * @static
  8377. * @memberOf _
  8378. * @since 0.5.0
  8379. * @category Collection
  8380. * @param {Array|Object} collection The collection to iterate over.
  8381. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8382. * @returns {Object} Returns the composed aggregate object.
  8383. * @example
  8384. *
  8385. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8386. * // => { '4': 1, '6': 2 }
  8387. *
  8388. * // The `_.property` iteratee shorthand.
  8389. * _.countBy(['one', 'two', 'three'], 'length');
  8390. * // => { '3': 2, '5': 1 }
  8391. */
  8392. var countBy = createAggregator(function(result, value, key) {
  8393. if (hasOwnProperty.call(result, key)) {
  8394. ++result[key];
  8395. } else {
  8396. baseAssignValue(result, key, 1);
  8397. }
  8398. });
  8399. /**
  8400. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8401. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8402. * invoked with three arguments: (value, index|key, collection).
  8403. *
  8404. * **Note:** This method returns `true` for
  8405. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8406. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8407. * elements of empty collections.
  8408. *
  8409. * @static
  8410. * @memberOf _
  8411. * @since 0.1.0
  8412. * @category Collection
  8413. * @param {Array|Object} collection The collection to iterate over.
  8414. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8415. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8416. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8417. * else `false`.
  8418. * @example
  8419. *
  8420. * _.every([true, 1, null, 'yes'], Boolean);
  8421. * // => false
  8422. *
  8423. * var users = [
  8424. * { 'user': 'barney', 'age': 36, 'active': false },
  8425. * { 'user': 'fred', 'age': 40, 'active': false }
  8426. * ];
  8427. *
  8428. * // The `_.matches` iteratee shorthand.
  8429. * _.every(users, { 'user': 'barney', 'active': false });
  8430. * // => false
  8431. *
  8432. * // The `_.matchesProperty` iteratee shorthand.
  8433. * _.every(users, ['active', false]);
  8434. * // => true
  8435. *
  8436. * // The `_.property` iteratee shorthand.
  8437. * _.every(users, 'active');
  8438. * // => false
  8439. */
  8440. function every(collection, predicate, guard) {
  8441. var func = isArray(collection) ? arrayEvery : baseEvery;
  8442. if (guard && isIterateeCall(collection, predicate, guard)) {
  8443. predicate = undefined;
  8444. }
  8445. return func(collection, getIteratee(predicate, 3));
  8446. }
  8447. /**
  8448. * Iterates over elements of `collection`, returning an array of all elements
  8449. * `predicate` returns truthy for. The predicate is invoked with three
  8450. * arguments: (value, index|key, collection).
  8451. *
  8452. * **Note:** Unlike `_.remove`, this method returns a new array.
  8453. *
  8454. * @static
  8455. * @memberOf _
  8456. * @since 0.1.0
  8457. * @category Collection
  8458. * @param {Array|Object} collection The collection to iterate over.
  8459. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8460. * @returns {Array} Returns the new filtered array.
  8461. * @see _.reject
  8462. * @example
  8463. *
  8464. * var users = [
  8465. * { 'user': 'barney', 'age': 36, 'active': true },
  8466. * { 'user': 'fred', 'age': 40, 'active': false }
  8467. * ];
  8468. *
  8469. * _.filter(users, function(o) { return !o.active; });
  8470. * // => objects for ['fred']
  8471. *
  8472. * // The `_.matches` iteratee shorthand.
  8473. * _.filter(users, { 'age': 36, 'active': true });
  8474. * // => objects for ['barney']
  8475. *
  8476. * // The `_.matchesProperty` iteratee shorthand.
  8477. * _.filter(users, ['active', false]);
  8478. * // => objects for ['fred']
  8479. *
  8480. * // The `_.property` iteratee shorthand.
  8481. * _.filter(users, 'active');
  8482. * // => objects for ['barney']
  8483. */
  8484. function filter(collection, predicate) {
  8485. var func = isArray(collection) ? arrayFilter : baseFilter;
  8486. return func(collection, getIteratee(predicate, 3));
  8487. }
  8488. /**
  8489. * Iterates over elements of `collection`, returning the first element
  8490. * `predicate` returns truthy for. The predicate is invoked with three
  8491. * arguments: (value, index|key, collection).
  8492. *
  8493. * @static
  8494. * @memberOf _
  8495. * @since 0.1.0
  8496. * @category Collection
  8497. * @param {Array|Object} collection The collection to inspect.
  8498. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8499. * @param {number} [fromIndex=0] The index to search from.
  8500. * @returns {*} Returns the matched element, else `undefined`.
  8501. * @example
  8502. *
  8503. * var users = [
  8504. * { 'user': 'barney', 'age': 36, 'active': true },
  8505. * { 'user': 'fred', 'age': 40, 'active': false },
  8506. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8507. * ];
  8508. *
  8509. * _.find(users, function(o) { return o.age < 40; });
  8510. * // => object for 'barney'
  8511. *
  8512. * // The `_.matches` iteratee shorthand.
  8513. * _.find(users, { 'age': 1, 'active': true });
  8514. * // => object for 'pebbles'
  8515. *
  8516. * // The `_.matchesProperty` iteratee shorthand.
  8517. * _.find(users, ['active', false]);
  8518. * // => object for 'fred'
  8519. *
  8520. * // The `_.property` iteratee shorthand.
  8521. * _.find(users, 'active');
  8522. * // => object for 'barney'
  8523. */
  8524. var find = createFind(findIndex);
  8525. /**
  8526. * This method is like `_.find` except that it iterates over elements of
  8527. * `collection` from right to left.
  8528. *
  8529. * @static
  8530. * @memberOf _
  8531. * @since 2.0.0
  8532. * @category Collection
  8533. * @param {Array|Object} collection The collection to inspect.
  8534. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8535. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8536. * @returns {*} Returns the matched element, else `undefined`.
  8537. * @example
  8538. *
  8539. * _.findLast([1, 2, 3, 4], function(n) {
  8540. * return n % 2 == 1;
  8541. * });
  8542. * // => 3
  8543. */
  8544. var findLast = createFind(findLastIndex);
  8545. /**
  8546. * Creates a flattened array of values by running each element in `collection`
  8547. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8548. * with three arguments: (value, index|key, collection).
  8549. *
  8550. * @static
  8551. * @memberOf _
  8552. * @since 4.0.0
  8553. * @category Collection
  8554. * @param {Array|Object} collection The collection to iterate over.
  8555. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8556. * @returns {Array} Returns the new flattened array.
  8557. * @example
  8558. *
  8559. * function duplicate(n) {
  8560. * return [n, n];
  8561. * }
  8562. *
  8563. * _.flatMap([1, 2], duplicate);
  8564. * // => [1, 1, 2, 2]
  8565. */
  8566. function flatMap(collection, iteratee) {
  8567. return baseFlatten(map(collection, iteratee), 1);
  8568. }
  8569. /**
  8570. * This method is like `_.flatMap` except that it recursively flattens the
  8571. * mapped results.
  8572. *
  8573. * @static
  8574. * @memberOf _
  8575. * @since 4.7.0
  8576. * @category Collection
  8577. * @param {Array|Object} collection The collection to iterate over.
  8578. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8579. * @returns {Array} Returns the new flattened array.
  8580. * @example
  8581. *
  8582. * function duplicate(n) {
  8583. * return [[[n, n]]];
  8584. * }
  8585. *
  8586. * _.flatMapDeep([1, 2], duplicate);
  8587. * // => [1, 1, 2, 2]
  8588. */
  8589. function flatMapDeep(collection, iteratee) {
  8590. return baseFlatten(map(collection, iteratee), INFINITY);
  8591. }
  8592. /**
  8593. * This method is like `_.flatMap` except that it recursively flattens the
  8594. * mapped results up to `depth` times.
  8595. *
  8596. * @static
  8597. * @memberOf _
  8598. * @since 4.7.0
  8599. * @category Collection
  8600. * @param {Array|Object} collection The collection to iterate over.
  8601. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8602. * @param {number} [depth=1] The maximum recursion depth.
  8603. * @returns {Array} Returns the new flattened array.
  8604. * @example
  8605. *
  8606. * function duplicate(n) {
  8607. * return [[[n, n]]];
  8608. * }
  8609. *
  8610. * _.flatMapDepth([1, 2], duplicate, 2);
  8611. * // => [[1, 1], [2, 2]]
  8612. */
  8613. function flatMapDepth(collection, iteratee, depth) {
  8614. depth = depth === undefined ? 1 : toInteger(depth);
  8615. return baseFlatten(map(collection, iteratee), depth);
  8616. }
  8617. /**
  8618. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8619. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8620. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8621. *
  8622. * **Note:** As with other "Collections" methods, objects with a "length"
  8623. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8624. * or `_.forOwn` for object iteration.
  8625. *
  8626. * @static
  8627. * @memberOf _
  8628. * @since 0.1.0
  8629. * @alias each
  8630. * @category Collection
  8631. * @param {Array|Object} collection The collection to iterate over.
  8632. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8633. * @returns {Array|Object} Returns `collection`.
  8634. * @see _.forEachRight
  8635. * @example
  8636. *
  8637. * _.forEach([1, 2], function(value) {
  8638. * console.log(value);
  8639. * });
  8640. * // => Logs `1` then `2`.
  8641. *
  8642. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8643. * console.log(key);
  8644. * });
  8645. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8646. */
  8647. function forEach(collection, iteratee) {
  8648. var func = isArray(collection) ? arrayEach : baseEach;
  8649. return func(collection, getIteratee(iteratee, 3));
  8650. }
  8651. /**
  8652. * This method is like `_.forEach` except that it iterates over elements of
  8653. * `collection` from right to left.
  8654. *
  8655. * @static
  8656. * @memberOf _
  8657. * @since 2.0.0
  8658. * @alias eachRight
  8659. * @category Collection
  8660. * @param {Array|Object} collection The collection to iterate over.
  8661. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8662. * @returns {Array|Object} Returns `collection`.
  8663. * @see _.forEach
  8664. * @example
  8665. *
  8666. * _.forEachRight([1, 2], function(value) {
  8667. * console.log(value);
  8668. * });
  8669. * // => Logs `2` then `1`.
  8670. */
  8671. function forEachRight(collection, iteratee) {
  8672. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8673. return func(collection, getIteratee(iteratee, 3));
  8674. }
  8675. /**
  8676. * Creates an object composed of keys generated from the results of running
  8677. * each element of `collection` thru `iteratee`. The order of grouped values
  8678. * is determined by the order they occur in `collection`. The corresponding
  8679. * value of each key is an array of elements responsible for generating the
  8680. * key. The iteratee is invoked with one argument: (value).
  8681. *
  8682. * @static
  8683. * @memberOf _
  8684. * @since 0.1.0
  8685. * @category Collection
  8686. * @param {Array|Object} collection The collection to iterate over.
  8687. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8688. * @returns {Object} Returns the composed aggregate object.
  8689. * @example
  8690. *
  8691. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8692. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8693. *
  8694. * // The `_.property` iteratee shorthand.
  8695. * _.groupBy(['one', 'two', 'three'], 'length');
  8696. * // => { '3': ['one', 'two'], '5': ['three'] }
  8697. */
  8698. var groupBy = createAggregator(function(result, value, key) {
  8699. if (hasOwnProperty.call(result, key)) {
  8700. result[key].push(value);
  8701. } else {
  8702. baseAssignValue(result, key, [value]);
  8703. }
  8704. });
  8705. /**
  8706. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8707. * checked for a substring of `value`, otherwise
  8708. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8709. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8710. * the offset from the end of `collection`.
  8711. *
  8712. * @static
  8713. * @memberOf _
  8714. * @since 0.1.0
  8715. * @category Collection
  8716. * @param {Array|Object|string} collection The collection to inspect.
  8717. * @param {*} value The value to search for.
  8718. * @param {number} [fromIndex=0] The index to search from.
  8719. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8720. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8721. * @example
  8722. *
  8723. * _.includes([1, 2, 3], 1);
  8724. * // => true
  8725. *
  8726. * _.includes([1, 2, 3], 1, 2);
  8727. * // => false
  8728. *
  8729. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8730. * // => true
  8731. *
  8732. * _.includes('abcd', 'bc');
  8733. * // => true
  8734. */
  8735. function includes(collection, value, fromIndex, guard) {
  8736. collection = isArrayLike(collection) ? collection : values(collection);
  8737. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8738. var length = collection.length;
  8739. if (fromIndex < 0) {
  8740. fromIndex = nativeMax(length + fromIndex, 0);
  8741. }
  8742. return isString(collection)
  8743. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8744. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8745. }
  8746. /**
  8747. * Invokes the method at `path` of each element in `collection`, returning
  8748. * an array of the results of each invoked method. Any additional arguments
  8749. * are provided to each invoked method. If `path` is a function, it's invoked
  8750. * for, and `this` bound to, each element in `collection`.
  8751. *
  8752. * @static
  8753. * @memberOf _
  8754. * @since 4.0.0
  8755. * @category Collection
  8756. * @param {Array|Object} collection The collection to iterate over.
  8757. * @param {Array|Function|string} path The path of the method to invoke or
  8758. * the function invoked per iteration.
  8759. * @param {...*} [args] The arguments to invoke each method with.
  8760. * @returns {Array} Returns the array of results.
  8761. * @example
  8762. *
  8763. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8764. * // => [[1, 5, 7], [1, 2, 3]]
  8765. *
  8766. * _.invokeMap([123, 456], String.prototype.split, '');
  8767. * // => [['1', '2', '3'], ['4', '5', '6']]
  8768. */
  8769. var invokeMap = baseRest(function(collection, path, args) {
  8770. var index = -1,
  8771. isFunc = typeof path == 'function',
  8772. result = isArrayLike(collection) ? Array(collection.length) : [];
  8773. baseEach(collection, function(value) {
  8774. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8775. });
  8776. return result;
  8777. });
  8778. /**
  8779. * Creates an object composed of keys generated from the results of running
  8780. * each element of `collection` thru `iteratee`. The corresponding value of
  8781. * each key is the last element responsible for generating the key. The
  8782. * iteratee is invoked with one argument: (value).
  8783. *
  8784. * @static
  8785. * @memberOf _
  8786. * @since 4.0.0
  8787. * @category Collection
  8788. * @param {Array|Object} collection The collection to iterate over.
  8789. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8790. * @returns {Object} Returns the composed aggregate object.
  8791. * @example
  8792. *
  8793. * var array = [
  8794. * { 'dir': 'left', 'code': 97 },
  8795. * { 'dir': 'right', 'code': 100 }
  8796. * ];
  8797. *
  8798. * _.keyBy(array, function(o) {
  8799. * return String.fromCharCode(o.code);
  8800. * });
  8801. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8802. *
  8803. * _.keyBy(array, 'dir');
  8804. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8805. */
  8806. var keyBy = createAggregator(function(result, value, key) {
  8807. baseAssignValue(result, key, value);
  8808. });
  8809. /**
  8810. * Creates an array of values by running each element in `collection` thru
  8811. * `iteratee`. The iteratee is invoked with three arguments:
  8812. * (value, index|key, collection).
  8813. *
  8814. * Many lodash methods are guarded to work as iteratees for methods like
  8815. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8816. *
  8817. * The guarded methods are:
  8818. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8819. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8820. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8821. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8822. *
  8823. * @static
  8824. * @memberOf _
  8825. * @since 0.1.0
  8826. * @category Collection
  8827. * @param {Array|Object} collection The collection to iterate over.
  8828. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8829. * @returns {Array} Returns the new mapped array.
  8830. * @example
  8831. *
  8832. * function square(n) {
  8833. * return n * n;
  8834. * }
  8835. *
  8836. * _.map([4, 8], square);
  8837. * // => [16, 64]
  8838. *
  8839. * _.map({ 'a': 4, 'b': 8 }, square);
  8840. * // => [16, 64] (iteration order is not guaranteed)
  8841. *
  8842. * var users = [
  8843. * { 'user': 'barney' },
  8844. * { 'user': 'fred' }
  8845. * ];
  8846. *
  8847. * // The `_.property` iteratee shorthand.
  8848. * _.map(users, 'user');
  8849. * // => ['barney', 'fred']
  8850. */
  8851. function map(collection, iteratee) {
  8852. var func = isArray(collection) ? arrayMap : baseMap;
  8853. return func(collection, getIteratee(iteratee, 3));
  8854. }
  8855. /**
  8856. * This method is like `_.sortBy` except that it allows specifying the sort
  8857. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8858. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8859. * descending or "asc" for ascending sort order of corresponding values.
  8860. *
  8861. * @static
  8862. * @memberOf _
  8863. * @since 4.0.0
  8864. * @category Collection
  8865. * @param {Array|Object} collection The collection to iterate over.
  8866. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8867. * The iteratees to sort by.
  8868. * @param {string[]} [orders] The sort orders of `iteratees`.
  8869. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8870. * @returns {Array} Returns the new sorted array.
  8871. * @example
  8872. *
  8873. * var users = [
  8874. * { 'user': 'fred', 'age': 48 },
  8875. * { 'user': 'barney', 'age': 34 },
  8876. * { 'user': 'fred', 'age': 40 },
  8877. * { 'user': 'barney', 'age': 36 }
  8878. * ];
  8879. *
  8880. * // Sort by `user` in ascending order and by `age` in descending order.
  8881. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8882. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8883. */
  8884. function orderBy(collection, iteratees, orders, guard) {
  8885. if (collection == null) {
  8886. return [];
  8887. }
  8888. if (!isArray(iteratees)) {
  8889. iteratees = iteratees == null ? [] : [iteratees];
  8890. }
  8891. orders = guard ? undefined : orders;
  8892. if (!isArray(orders)) {
  8893. orders = orders == null ? [] : [orders];
  8894. }
  8895. return baseOrderBy(collection, iteratees, orders);
  8896. }
  8897. /**
  8898. * Creates an array of elements split into two groups, the first of which
  8899. * contains elements `predicate` returns truthy for, the second of which
  8900. * contains elements `predicate` returns falsey for. The predicate is
  8901. * invoked with one argument: (value).
  8902. *
  8903. * @static
  8904. * @memberOf _
  8905. * @since 3.0.0
  8906. * @category Collection
  8907. * @param {Array|Object} collection The collection to iterate over.
  8908. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8909. * @returns {Array} Returns the array of grouped elements.
  8910. * @example
  8911. *
  8912. * var users = [
  8913. * { 'user': 'barney', 'age': 36, 'active': false },
  8914. * { 'user': 'fred', 'age': 40, 'active': true },
  8915. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8916. * ];
  8917. *
  8918. * _.partition(users, function(o) { return o.active; });
  8919. * // => objects for [['fred'], ['barney', 'pebbles']]
  8920. *
  8921. * // The `_.matches` iteratee shorthand.
  8922. * _.partition(users, { 'age': 1, 'active': false });
  8923. * // => objects for [['pebbles'], ['barney', 'fred']]
  8924. *
  8925. * // The `_.matchesProperty` iteratee shorthand.
  8926. * _.partition(users, ['active', false]);
  8927. * // => objects for [['barney', 'pebbles'], ['fred']]
  8928. *
  8929. * // The `_.property` iteratee shorthand.
  8930. * _.partition(users, 'active');
  8931. * // => objects for [['fred'], ['barney', 'pebbles']]
  8932. */
  8933. var partition = createAggregator(function(result, value, key) {
  8934. result[key ? 0 : 1].push(value);
  8935. }, function() { return [[], []]; });
  8936. /**
  8937. * Reduces `collection` to a value which is the accumulated result of running
  8938. * each element in `collection` thru `iteratee`, where each successive
  8939. * invocation is supplied the return value of the previous. If `accumulator`
  8940. * is not given, the first element of `collection` is used as the initial
  8941. * value. The iteratee is invoked with four arguments:
  8942. * (accumulator, value, index|key, collection).
  8943. *
  8944. * Many lodash methods are guarded to work as iteratees for methods like
  8945. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8946. *
  8947. * The guarded methods are:
  8948. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8949. * and `sortBy`
  8950. *
  8951. * @static
  8952. * @memberOf _
  8953. * @since 0.1.0
  8954. * @category Collection
  8955. * @param {Array|Object} collection The collection to iterate over.
  8956. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8957. * @param {*} [accumulator] The initial value.
  8958. * @returns {*} Returns the accumulated value.
  8959. * @see _.reduceRight
  8960. * @example
  8961. *
  8962. * _.reduce([1, 2], function(sum, n) {
  8963. * return sum + n;
  8964. * }, 0);
  8965. * // => 3
  8966. *
  8967. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8968. * (result[value] || (result[value] = [])).push(key);
  8969. * return result;
  8970. * }, {});
  8971. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8972. */
  8973. function reduce(collection, iteratee, accumulator) {
  8974. var func = isArray(collection) ? arrayReduce : baseReduce,
  8975. initAccum = arguments.length < 3;
  8976. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8977. }
  8978. /**
  8979. * This method is like `_.reduce` except that it iterates over elements of
  8980. * `collection` from right to left.
  8981. *
  8982. * @static
  8983. * @memberOf _
  8984. * @since 0.1.0
  8985. * @category Collection
  8986. * @param {Array|Object} collection The collection to iterate over.
  8987. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8988. * @param {*} [accumulator] The initial value.
  8989. * @returns {*} Returns the accumulated value.
  8990. * @see _.reduce
  8991. * @example
  8992. *
  8993. * var array = [[0, 1], [2, 3], [4, 5]];
  8994. *
  8995. * _.reduceRight(array, function(flattened, other) {
  8996. * return flattened.concat(other);
  8997. * }, []);
  8998. * // => [4, 5, 2, 3, 0, 1]
  8999. */
  9000. function reduceRight(collection, iteratee, accumulator) {
  9001. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9002. initAccum = arguments.length < 3;
  9003. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9004. }
  9005. /**
  9006. * The opposite of `_.filter`; this method returns the elements of `collection`
  9007. * that `predicate` does **not** return truthy for.
  9008. *
  9009. * @static
  9010. * @memberOf _
  9011. * @since 0.1.0
  9012. * @category Collection
  9013. * @param {Array|Object} collection The collection to iterate over.
  9014. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9015. * @returns {Array} Returns the new filtered array.
  9016. * @see _.filter
  9017. * @example
  9018. *
  9019. * var users = [
  9020. * { 'user': 'barney', 'age': 36, 'active': false },
  9021. * { 'user': 'fred', 'age': 40, 'active': true }
  9022. * ];
  9023. *
  9024. * _.reject(users, function(o) { return !o.active; });
  9025. * // => objects for ['fred']
  9026. *
  9027. * // The `_.matches` iteratee shorthand.
  9028. * _.reject(users, { 'age': 40, 'active': true });
  9029. * // => objects for ['barney']
  9030. *
  9031. * // The `_.matchesProperty` iteratee shorthand.
  9032. * _.reject(users, ['active', false]);
  9033. * // => objects for ['fred']
  9034. *
  9035. * // The `_.property` iteratee shorthand.
  9036. * _.reject(users, 'active');
  9037. * // => objects for ['barney']
  9038. */
  9039. function reject(collection, predicate) {
  9040. var func = isArray(collection) ? arrayFilter : baseFilter;
  9041. return func(collection, negate(getIteratee(predicate, 3)));
  9042. }
  9043. /**
  9044. * Gets a random element from `collection`.
  9045. *
  9046. * @static
  9047. * @memberOf _
  9048. * @since 2.0.0
  9049. * @category Collection
  9050. * @param {Array|Object} collection The collection to sample.
  9051. * @returns {*} Returns the random element.
  9052. * @example
  9053. *
  9054. * _.sample([1, 2, 3, 4]);
  9055. * // => 2
  9056. */
  9057. function sample(collection) {
  9058. var func = isArray(collection) ? arraySample : baseSample;
  9059. return func(collection);
  9060. }
  9061. /**
  9062. * Gets `n` random elements at unique keys from `collection` up to the
  9063. * size of `collection`.
  9064. *
  9065. * @static
  9066. * @memberOf _
  9067. * @since 4.0.0
  9068. * @category Collection
  9069. * @param {Array|Object} collection The collection to sample.
  9070. * @param {number} [n=1] The number of elements to sample.
  9071. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9072. * @returns {Array} Returns the random elements.
  9073. * @example
  9074. *
  9075. * _.sampleSize([1, 2, 3], 2);
  9076. * // => [3, 1]
  9077. *
  9078. * _.sampleSize([1, 2, 3], 4);
  9079. * // => [2, 3, 1]
  9080. */
  9081. function sampleSize(collection, n, guard) {
  9082. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9083. n = 1;
  9084. } else {
  9085. n = toInteger(n);
  9086. }
  9087. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9088. return func(collection, n);
  9089. }
  9090. /**
  9091. * Creates an array of shuffled values, using a version of the
  9092. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9093. *
  9094. * @static
  9095. * @memberOf _
  9096. * @since 0.1.0
  9097. * @category Collection
  9098. * @param {Array|Object} collection The collection to shuffle.
  9099. * @returns {Array} Returns the new shuffled array.
  9100. * @example
  9101. *
  9102. * _.shuffle([1, 2, 3, 4]);
  9103. * // => [4, 1, 3, 2]
  9104. */
  9105. function shuffle(collection) {
  9106. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9107. return func(collection);
  9108. }
  9109. /**
  9110. * Gets the size of `collection` by returning its length for array-like
  9111. * values or the number of own enumerable string keyed properties for objects.
  9112. *
  9113. * @static
  9114. * @memberOf _
  9115. * @since 0.1.0
  9116. * @category Collection
  9117. * @param {Array|Object|string} collection The collection to inspect.
  9118. * @returns {number} Returns the collection size.
  9119. * @example
  9120. *
  9121. * _.size([1, 2, 3]);
  9122. * // => 3
  9123. *
  9124. * _.size({ 'a': 1, 'b': 2 });
  9125. * // => 2
  9126. *
  9127. * _.size('pebbles');
  9128. * // => 7
  9129. */
  9130. function size(collection) {
  9131. if (collection == null) {
  9132. return 0;
  9133. }
  9134. if (isArrayLike(collection)) {
  9135. return isString(collection) ? stringSize(collection) : collection.length;
  9136. }
  9137. var tag = getTag(collection);
  9138. if (tag == mapTag || tag == setTag) {
  9139. return collection.size;
  9140. }
  9141. return baseKeys(collection).length;
  9142. }
  9143. /**
  9144. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9145. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9146. * invoked with three arguments: (value, index|key, collection).
  9147. *
  9148. * @static
  9149. * @memberOf _
  9150. * @since 0.1.0
  9151. * @category Collection
  9152. * @param {Array|Object} collection The collection to iterate over.
  9153. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9154. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9155. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9156. * else `false`.
  9157. * @example
  9158. *
  9159. * _.some([null, 0, 'yes', false], Boolean);
  9160. * // => true
  9161. *
  9162. * var users = [
  9163. * { 'user': 'barney', 'active': true },
  9164. * { 'user': 'fred', 'active': false }
  9165. * ];
  9166. *
  9167. * // The `_.matches` iteratee shorthand.
  9168. * _.some(users, { 'user': 'barney', 'active': false });
  9169. * // => false
  9170. *
  9171. * // The `_.matchesProperty` iteratee shorthand.
  9172. * _.some(users, ['active', false]);
  9173. * // => true
  9174. *
  9175. * // The `_.property` iteratee shorthand.
  9176. * _.some(users, 'active');
  9177. * // => true
  9178. */
  9179. function some(collection, predicate, guard) {
  9180. var func = isArray(collection) ? arraySome : baseSome;
  9181. if (guard && isIterateeCall(collection, predicate, guard)) {
  9182. predicate = undefined;
  9183. }
  9184. return func(collection, getIteratee(predicate, 3));
  9185. }
  9186. /**
  9187. * Creates an array of elements, sorted in ascending order by the results of
  9188. * running each element in a collection thru each iteratee. This method
  9189. * performs a stable sort, that is, it preserves the original sort order of
  9190. * equal elements. The iteratees are invoked with one argument: (value).
  9191. *
  9192. * @static
  9193. * @memberOf _
  9194. * @since 0.1.0
  9195. * @category Collection
  9196. * @param {Array|Object} collection The collection to iterate over.
  9197. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9198. * The iteratees to sort by.
  9199. * @returns {Array} Returns the new sorted array.
  9200. * @example
  9201. *
  9202. * var users = [
  9203. * { 'user': 'fred', 'age': 48 },
  9204. * { 'user': 'barney', 'age': 36 },
  9205. * { 'user': 'fred', 'age': 40 },
  9206. * { 'user': 'barney', 'age': 34 }
  9207. * ];
  9208. *
  9209. * _.sortBy(users, [function(o) { return o.user; }]);
  9210. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9211. *
  9212. * _.sortBy(users, ['user', 'age']);
  9213. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9214. */
  9215. var sortBy = baseRest(function(collection, iteratees) {
  9216. if (collection == null) {
  9217. return [];
  9218. }
  9219. var length = iteratees.length;
  9220. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9221. iteratees = [];
  9222. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9223. iteratees = [iteratees[0]];
  9224. }
  9225. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9226. });
  9227. /*------------------------------------------------------------------------*/
  9228. /**
  9229. * Gets the timestamp of the number of milliseconds that have elapsed since
  9230. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9231. *
  9232. * @static
  9233. * @memberOf _
  9234. * @since 2.4.0
  9235. * @category Date
  9236. * @returns {number} Returns the timestamp.
  9237. * @example
  9238. *
  9239. * _.defer(function(stamp) {
  9240. * console.log(_.now() - stamp);
  9241. * }, _.now());
  9242. * // => Logs the number of milliseconds it took for the deferred invocation.
  9243. */
  9244. var now = ctxNow || function() {
  9245. return root.Date.now();
  9246. };
  9247. /*------------------------------------------------------------------------*/
  9248. /**
  9249. * The opposite of `_.before`; this method creates a function that invokes
  9250. * `func` once it's called `n` or more times.
  9251. *
  9252. * @static
  9253. * @memberOf _
  9254. * @since 0.1.0
  9255. * @category Function
  9256. * @param {number} n The number of calls before `func` is invoked.
  9257. * @param {Function} func The function to restrict.
  9258. * @returns {Function} Returns the new restricted function.
  9259. * @example
  9260. *
  9261. * var saves = ['profile', 'settings'];
  9262. *
  9263. * var done = _.after(saves.length, function() {
  9264. * console.log('done saving!');
  9265. * });
  9266. *
  9267. * _.forEach(saves, function(type) {
  9268. * asyncSave({ 'type': type, 'complete': done });
  9269. * });
  9270. * // => Logs 'done saving!' after the two async saves have completed.
  9271. */
  9272. function after(n, func) {
  9273. if (typeof func != 'function') {
  9274. throw new TypeError(FUNC_ERROR_TEXT);
  9275. }
  9276. n = toInteger(n);
  9277. return function() {
  9278. if (--n < 1) {
  9279. return func.apply(this, arguments);
  9280. }
  9281. };
  9282. }
  9283. /**
  9284. * Creates a function that invokes `func`, with up to `n` arguments,
  9285. * ignoring any additional arguments.
  9286. *
  9287. * @static
  9288. * @memberOf _
  9289. * @since 3.0.0
  9290. * @category Function
  9291. * @param {Function} func The function to cap arguments for.
  9292. * @param {number} [n=func.length] The arity cap.
  9293. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9294. * @returns {Function} Returns the new capped function.
  9295. * @example
  9296. *
  9297. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9298. * // => [6, 8, 10]
  9299. */
  9300. function ary(func, n, guard) {
  9301. n = guard ? undefined : n;
  9302. n = (func && n == null) ? func.length : n;
  9303. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9304. }
  9305. /**
  9306. * Creates a function that invokes `func`, with the `this` binding and arguments
  9307. * of the created function, while it's called less than `n` times. Subsequent
  9308. * calls to the created function return the result of the last `func` invocation.
  9309. *
  9310. * @static
  9311. * @memberOf _
  9312. * @since 3.0.0
  9313. * @category Function
  9314. * @param {number} n The number of calls at which `func` is no longer invoked.
  9315. * @param {Function} func The function to restrict.
  9316. * @returns {Function} Returns the new restricted function.
  9317. * @example
  9318. *
  9319. * jQuery(element).on('click', _.before(5, addContactToList));
  9320. * // => Allows adding up to 4 contacts to the list.
  9321. */
  9322. function before(n, func) {
  9323. var result;
  9324. if (typeof func != 'function') {
  9325. throw new TypeError(FUNC_ERROR_TEXT);
  9326. }
  9327. n = toInteger(n);
  9328. return function() {
  9329. if (--n > 0) {
  9330. result = func.apply(this, arguments);
  9331. }
  9332. if (n <= 1) {
  9333. func = undefined;
  9334. }
  9335. return result;
  9336. };
  9337. }
  9338. /**
  9339. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9340. * and `partials` prepended to the arguments it receives.
  9341. *
  9342. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9343. * may be used as a placeholder for partially applied arguments.
  9344. *
  9345. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9346. * property of bound functions.
  9347. *
  9348. * @static
  9349. * @memberOf _
  9350. * @since 0.1.0
  9351. * @category Function
  9352. * @param {Function} func The function to bind.
  9353. * @param {*} thisArg The `this` binding of `func`.
  9354. * @param {...*} [partials] The arguments to be partially applied.
  9355. * @returns {Function} Returns the new bound function.
  9356. * @example
  9357. *
  9358. * function greet(greeting, punctuation) {
  9359. * return greeting + ' ' + this.user + punctuation;
  9360. * }
  9361. *
  9362. * var object = { 'user': 'fred' };
  9363. *
  9364. * var bound = _.bind(greet, object, 'hi');
  9365. * bound('!');
  9366. * // => 'hi fred!'
  9367. *
  9368. * // Bound with placeholders.
  9369. * var bound = _.bind(greet, object, _, '!');
  9370. * bound('hi');
  9371. * // => 'hi fred!'
  9372. */
  9373. var bind = baseRest(function(func, thisArg, partials) {
  9374. var bitmask = WRAP_BIND_FLAG;
  9375. if (partials.length) {
  9376. var holders = replaceHolders(partials, getHolder(bind));
  9377. bitmask |= WRAP_PARTIAL_FLAG;
  9378. }
  9379. return createWrap(func, bitmask, thisArg, partials, holders);
  9380. });
  9381. /**
  9382. * Creates a function that invokes the method at `object[key]` with `partials`
  9383. * prepended to the arguments it receives.
  9384. *
  9385. * This method differs from `_.bind` by allowing bound functions to reference
  9386. * methods that may be redefined or don't yet exist. See
  9387. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9388. * for more details.
  9389. *
  9390. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9391. * builds, may be used as a placeholder for partially applied arguments.
  9392. *
  9393. * @static
  9394. * @memberOf _
  9395. * @since 0.10.0
  9396. * @category Function
  9397. * @param {Object} object The object to invoke the method on.
  9398. * @param {string} key The key of the method.
  9399. * @param {...*} [partials] The arguments to be partially applied.
  9400. * @returns {Function} Returns the new bound function.
  9401. * @example
  9402. *
  9403. * var object = {
  9404. * 'user': 'fred',
  9405. * 'greet': function(greeting, punctuation) {
  9406. * return greeting + ' ' + this.user + punctuation;
  9407. * }
  9408. * };
  9409. *
  9410. * var bound = _.bindKey(object, 'greet', 'hi');
  9411. * bound('!');
  9412. * // => 'hi fred!'
  9413. *
  9414. * object.greet = function(greeting, punctuation) {
  9415. * return greeting + 'ya ' + this.user + punctuation;
  9416. * };
  9417. *
  9418. * bound('!');
  9419. * // => 'hiya fred!'
  9420. *
  9421. * // Bound with placeholders.
  9422. * var bound = _.bindKey(object, 'greet', _, '!');
  9423. * bound('hi');
  9424. * // => 'hiya fred!'
  9425. */
  9426. var bindKey = baseRest(function(object, key, partials) {
  9427. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9428. if (partials.length) {
  9429. var holders = replaceHolders(partials, getHolder(bindKey));
  9430. bitmask |= WRAP_PARTIAL_FLAG;
  9431. }
  9432. return createWrap(key, bitmask, object, partials, holders);
  9433. });
  9434. /**
  9435. * Creates a function that accepts arguments of `func` and either invokes
  9436. * `func` returning its result, if at least `arity` number of arguments have
  9437. * been provided, or returns a function that accepts the remaining `func`
  9438. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9439. * is not sufficient.
  9440. *
  9441. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9442. * may be used as a placeholder for provided arguments.
  9443. *
  9444. * **Note:** This method doesn't set the "length" property of curried functions.
  9445. *
  9446. * @static
  9447. * @memberOf _
  9448. * @since 2.0.0
  9449. * @category Function
  9450. * @param {Function} func The function to curry.
  9451. * @param {number} [arity=func.length] The arity of `func`.
  9452. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9453. * @returns {Function} Returns the new curried function.
  9454. * @example
  9455. *
  9456. * var abc = function(a, b, c) {
  9457. * return [a, b, c];
  9458. * };
  9459. *
  9460. * var curried = _.curry(abc);
  9461. *
  9462. * curried(1)(2)(3);
  9463. * // => [1, 2, 3]
  9464. *
  9465. * curried(1, 2)(3);
  9466. * // => [1, 2, 3]
  9467. *
  9468. * curried(1, 2, 3);
  9469. * // => [1, 2, 3]
  9470. *
  9471. * // Curried with placeholders.
  9472. * curried(1)(_, 3)(2);
  9473. * // => [1, 2, 3]
  9474. */
  9475. function curry(func, arity, guard) {
  9476. arity = guard ? undefined : arity;
  9477. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9478. result.placeholder = curry.placeholder;
  9479. return result;
  9480. }
  9481. /**
  9482. * This method is like `_.curry` except that arguments are applied to `func`
  9483. * in the manner of `_.partialRight` instead of `_.partial`.
  9484. *
  9485. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9486. * builds, may be used as a placeholder for provided arguments.
  9487. *
  9488. * **Note:** This method doesn't set the "length" property of curried functions.
  9489. *
  9490. * @static
  9491. * @memberOf _
  9492. * @since 3.0.0
  9493. * @category Function
  9494. * @param {Function} func The function to curry.
  9495. * @param {number} [arity=func.length] The arity of `func`.
  9496. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9497. * @returns {Function} Returns the new curried function.
  9498. * @example
  9499. *
  9500. * var abc = function(a, b, c) {
  9501. * return [a, b, c];
  9502. * };
  9503. *
  9504. * var curried = _.curryRight(abc);
  9505. *
  9506. * curried(3)(2)(1);
  9507. * // => [1, 2, 3]
  9508. *
  9509. * curried(2, 3)(1);
  9510. * // => [1, 2, 3]
  9511. *
  9512. * curried(1, 2, 3);
  9513. * // => [1, 2, 3]
  9514. *
  9515. * // Curried with placeholders.
  9516. * curried(3)(1, _)(2);
  9517. * // => [1, 2, 3]
  9518. */
  9519. function curryRight(func, arity, guard) {
  9520. arity = guard ? undefined : arity;
  9521. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9522. result.placeholder = curryRight.placeholder;
  9523. return result;
  9524. }
  9525. /**
  9526. * Creates a debounced function that delays invoking `func` until after `wait`
  9527. * milliseconds have elapsed since the last time the debounced function was
  9528. * invoked. The debounced function comes with a `cancel` method to cancel
  9529. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9530. * Provide `options` to indicate whether `func` should be invoked on the
  9531. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9532. * with the last arguments provided to the debounced function. Subsequent
  9533. * calls to the debounced function return the result of the last `func`
  9534. * invocation.
  9535. *
  9536. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9537. * invoked on the trailing edge of the timeout only if the debounced function
  9538. * is invoked more than once during the `wait` timeout.
  9539. *
  9540. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9541. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9542. *
  9543. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9544. * for details over the differences between `_.debounce` and `_.throttle`.
  9545. *
  9546. * @static
  9547. * @memberOf _
  9548. * @since 0.1.0
  9549. * @category Function
  9550. * @param {Function} func The function to debounce.
  9551. * @param {number} [wait=0] The number of milliseconds to delay.
  9552. * @param {Object} [options={}] The options object.
  9553. * @param {boolean} [options.leading=false]
  9554. * Specify invoking on the leading edge of the timeout.
  9555. * @param {number} [options.maxWait]
  9556. * The maximum time `func` is allowed to be delayed before it's invoked.
  9557. * @param {boolean} [options.trailing=true]
  9558. * Specify invoking on the trailing edge of the timeout.
  9559. * @returns {Function} Returns the new debounced function.
  9560. * @example
  9561. *
  9562. * // Avoid costly calculations while the window size is in flux.
  9563. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9564. *
  9565. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9566. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9567. * 'leading': true,
  9568. * 'trailing': false
  9569. * }));
  9570. *
  9571. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9572. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9573. * var source = new EventSource('/stream');
  9574. * jQuery(source).on('message', debounced);
  9575. *
  9576. * // Cancel the trailing debounced invocation.
  9577. * jQuery(window).on('popstate', debounced.cancel);
  9578. */
  9579. function debounce(func, wait, options) {
  9580. var lastArgs,
  9581. lastThis,
  9582. maxWait,
  9583. result,
  9584. timerId,
  9585. lastCallTime,
  9586. lastInvokeTime = 0,
  9587. leading = false,
  9588. maxing = false,
  9589. trailing = true;
  9590. if (typeof func != 'function') {
  9591. throw new TypeError(FUNC_ERROR_TEXT);
  9592. }
  9593. wait = toNumber(wait) || 0;
  9594. if (isObject(options)) {
  9595. leading = !!options.leading;
  9596. maxing = 'maxWait' in options;
  9597. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9598. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9599. }
  9600. function invokeFunc(time) {
  9601. var args = lastArgs,
  9602. thisArg = lastThis;
  9603. lastArgs = lastThis = undefined;
  9604. lastInvokeTime = time;
  9605. result = func.apply(thisArg, args);
  9606. return result;
  9607. }
  9608. function leadingEdge(time) {
  9609. // Reset any `maxWait` timer.
  9610. lastInvokeTime = time;
  9611. // Start the timer for the trailing edge.
  9612. timerId = setTimeout(timerExpired, wait);
  9613. // Invoke the leading edge.
  9614. return leading ? invokeFunc(time) : result;
  9615. }
  9616. function remainingWait(time) {
  9617. var timeSinceLastCall = time - lastCallTime,
  9618. timeSinceLastInvoke = time - lastInvokeTime,
  9619. timeWaiting = wait - timeSinceLastCall;
  9620. return maxing
  9621. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9622. : timeWaiting;
  9623. }
  9624. function shouldInvoke(time) {
  9625. var timeSinceLastCall = time - lastCallTime,
  9626. timeSinceLastInvoke = time - lastInvokeTime;
  9627. // Either this is the first call, activity has stopped and we're at the
  9628. // trailing edge, the system time has gone backwards and we're treating
  9629. // it as the trailing edge, or we've hit the `maxWait` limit.
  9630. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9631. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9632. }
  9633. function timerExpired() {
  9634. var time = now();
  9635. if (shouldInvoke(time)) {
  9636. return trailingEdge(time);
  9637. }
  9638. // Restart the timer.
  9639. timerId = setTimeout(timerExpired, remainingWait(time));
  9640. }
  9641. function trailingEdge(time) {
  9642. timerId = undefined;
  9643. // Only invoke if we have `lastArgs` which means `func` has been
  9644. // debounced at least once.
  9645. if (trailing && lastArgs) {
  9646. return invokeFunc(time);
  9647. }
  9648. lastArgs = lastThis = undefined;
  9649. return result;
  9650. }
  9651. function cancel() {
  9652. if (timerId !== undefined) {
  9653. clearTimeout(timerId);
  9654. }
  9655. lastInvokeTime = 0;
  9656. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9657. }
  9658. function flush() {
  9659. return timerId === undefined ? result : trailingEdge(now());
  9660. }
  9661. function debounced() {
  9662. var time = now(),
  9663. isInvoking = shouldInvoke(time);
  9664. lastArgs = arguments;
  9665. lastThis = this;
  9666. lastCallTime = time;
  9667. if (isInvoking) {
  9668. if (timerId === undefined) {
  9669. return leadingEdge(lastCallTime);
  9670. }
  9671. if (maxing) {
  9672. // Handle invocations in a tight loop.
  9673. timerId = setTimeout(timerExpired, wait);
  9674. return invokeFunc(lastCallTime);
  9675. }
  9676. }
  9677. if (timerId === undefined) {
  9678. timerId = setTimeout(timerExpired, wait);
  9679. }
  9680. return result;
  9681. }
  9682. debounced.cancel = cancel;
  9683. debounced.flush = flush;
  9684. return debounced;
  9685. }
  9686. /**
  9687. * Defers invoking the `func` until the current call stack has cleared. Any
  9688. * additional arguments are provided to `func` when it's invoked.
  9689. *
  9690. * @static
  9691. * @memberOf _
  9692. * @since 0.1.0
  9693. * @category Function
  9694. * @param {Function} func The function to defer.
  9695. * @param {...*} [args] The arguments to invoke `func` with.
  9696. * @returns {number} Returns the timer id.
  9697. * @example
  9698. *
  9699. * _.defer(function(text) {
  9700. * console.log(text);
  9701. * }, 'deferred');
  9702. * // => Logs 'deferred' after one millisecond.
  9703. */
  9704. var defer = baseRest(function(func, args) {
  9705. return baseDelay(func, 1, args);
  9706. });
  9707. /**
  9708. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9709. * provided to `func` when it's invoked.
  9710. *
  9711. * @static
  9712. * @memberOf _
  9713. * @since 0.1.0
  9714. * @category Function
  9715. * @param {Function} func The function to delay.
  9716. * @param {number} wait The number of milliseconds to delay invocation.
  9717. * @param {...*} [args] The arguments to invoke `func` with.
  9718. * @returns {number} Returns the timer id.
  9719. * @example
  9720. *
  9721. * _.delay(function(text) {
  9722. * console.log(text);
  9723. * }, 1000, 'later');
  9724. * // => Logs 'later' after one second.
  9725. */
  9726. var delay = baseRest(function(func, wait, args) {
  9727. return baseDelay(func, toNumber(wait) || 0, args);
  9728. });
  9729. /**
  9730. * Creates a function that invokes `func` with arguments reversed.
  9731. *
  9732. * @static
  9733. * @memberOf _
  9734. * @since 4.0.0
  9735. * @category Function
  9736. * @param {Function} func The function to flip arguments for.
  9737. * @returns {Function} Returns the new flipped function.
  9738. * @example
  9739. *
  9740. * var flipped = _.flip(function() {
  9741. * return _.toArray(arguments);
  9742. * });
  9743. *
  9744. * flipped('a', 'b', 'c', 'd');
  9745. * // => ['d', 'c', 'b', 'a']
  9746. */
  9747. function flip(func) {
  9748. return createWrap(func, WRAP_FLIP_FLAG);
  9749. }
  9750. /**
  9751. * Creates a function that memoizes the result of `func`. If `resolver` is
  9752. * provided, it determines the cache key for storing the result based on the
  9753. * arguments provided to the memoized function. By default, the first argument
  9754. * provided to the memoized function is used as the map cache key. The `func`
  9755. * is invoked with the `this` binding of the memoized function.
  9756. *
  9757. * **Note:** The cache is exposed as the `cache` property on the memoized
  9758. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9759. * constructor with one whose instances implement the
  9760. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9761. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9762. *
  9763. * @static
  9764. * @memberOf _
  9765. * @since 0.1.0
  9766. * @category Function
  9767. * @param {Function} func The function to have its output memoized.
  9768. * @param {Function} [resolver] The function to resolve the cache key.
  9769. * @returns {Function} Returns the new memoized function.
  9770. * @example
  9771. *
  9772. * var object = { 'a': 1, 'b': 2 };
  9773. * var other = { 'c': 3, 'd': 4 };
  9774. *
  9775. * var values = _.memoize(_.values);
  9776. * values(object);
  9777. * // => [1, 2]
  9778. *
  9779. * values(other);
  9780. * // => [3, 4]
  9781. *
  9782. * object.a = 2;
  9783. * values(object);
  9784. * // => [1, 2]
  9785. *
  9786. * // Modify the result cache.
  9787. * values.cache.set(object, ['a', 'b']);
  9788. * values(object);
  9789. * // => ['a', 'b']
  9790. *
  9791. * // Replace `_.memoize.Cache`.
  9792. * _.memoize.Cache = WeakMap;
  9793. */
  9794. function memoize(func, resolver) {
  9795. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9796. throw new TypeError(FUNC_ERROR_TEXT);
  9797. }
  9798. var memoized = function() {
  9799. var args = arguments,
  9800. key = resolver ? resolver.apply(this, args) : args[0],
  9801. cache = memoized.cache;
  9802. if (cache.has(key)) {
  9803. return cache.get(key);
  9804. }
  9805. var result = func.apply(this, args);
  9806. memoized.cache = cache.set(key, result) || cache;
  9807. return result;
  9808. };
  9809. memoized.cache = new (memoize.Cache || MapCache);
  9810. return memoized;
  9811. }
  9812. // Expose `MapCache`.
  9813. memoize.Cache = MapCache;
  9814. /**
  9815. * Creates a function that negates the result of the predicate `func`. The
  9816. * `func` predicate is invoked with the `this` binding and arguments of the
  9817. * created function.
  9818. *
  9819. * @static
  9820. * @memberOf _
  9821. * @since 3.0.0
  9822. * @category Function
  9823. * @param {Function} predicate The predicate to negate.
  9824. * @returns {Function} Returns the new negated function.
  9825. * @example
  9826. *
  9827. * function isEven(n) {
  9828. * return n % 2 == 0;
  9829. * }
  9830. *
  9831. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9832. * // => [1, 3, 5]
  9833. */
  9834. function negate(predicate) {
  9835. if (typeof predicate != 'function') {
  9836. throw new TypeError(FUNC_ERROR_TEXT);
  9837. }
  9838. return function() {
  9839. var args = arguments;
  9840. switch (args.length) {
  9841. case 0: return !predicate.call(this);
  9842. case 1: return !predicate.call(this, args[0]);
  9843. case 2: return !predicate.call(this, args[0], args[1]);
  9844. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9845. }
  9846. return !predicate.apply(this, args);
  9847. };
  9848. }
  9849. /**
  9850. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9851. * to the function return the value of the first invocation. The `func` is
  9852. * invoked with the `this` binding and arguments of the created function.
  9853. *
  9854. * @static
  9855. * @memberOf _
  9856. * @since 0.1.0
  9857. * @category Function
  9858. * @param {Function} func The function to restrict.
  9859. * @returns {Function} Returns the new restricted function.
  9860. * @example
  9861. *
  9862. * var initialize = _.once(createApplication);
  9863. * initialize();
  9864. * initialize();
  9865. * // => `createApplication` is invoked once
  9866. */
  9867. function once(func) {
  9868. return before(2, func);
  9869. }
  9870. /**
  9871. * Creates a function that invokes `func` with its arguments transformed.
  9872. *
  9873. * @static
  9874. * @since 4.0.0
  9875. * @memberOf _
  9876. * @category Function
  9877. * @param {Function} func The function to wrap.
  9878. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9879. * The argument transforms.
  9880. * @returns {Function} Returns the new function.
  9881. * @example
  9882. *
  9883. * function doubled(n) {
  9884. * return n * 2;
  9885. * }
  9886. *
  9887. * function square(n) {
  9888. * return n * n;
  9889. * }
  9890. *
  9891. * var func = _.overArgs(function(x, y) {
  9892. * return [x, y];
  9893. * }, [square, doubled]);
  9894. *
  9895. * func(9, 3);
  9896. * // => [81, 6]
  9897. *
  9898. * func(10, 5);
  9899. * // => [100, 10]
  9900. */
  9901. var overArgs = castRest(function(func, transforms) {
  9902. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9903. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9904. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9905. var funcsLength = transforms.length;
  9906. return baseRest(function(args) {
  9907. var index = -1,
  9908. length = nativeMin(args.length, funcsLength);
  9909. while (++index < length) {
  9910. args[index] = transforms[index].call(this, args[index]);
  9911. }
  9912. return apply(func, this, args);
  9913. });
  9914. });
  9915. /**
  9916. * Creates a function that invokes `func` with `partials` prepended to the
  9917. * arguments it receives. This method is like `_.bind` except it does **not**
  9918. * alter the `this` binding.
  9919. *
  9920. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9921. * builds, may be used as a placeholder for partially applied arguments.
  9922. *
  9923. * **Note:** This method doesn't set the "length" property of partially
  9924. * applied functions.
  9925. *
  9926. * @static
  9927. * @memberOf _
  9928. * @since 0.2.0
  9929. * @category Function
  9930. * @param {Function} func The function to partially apply arguments to.
  9931. * @param {...*} [partials] The arguments to be partially applied.
  9932. * @returns {Function} Returns the new partially applied function.
  9933. * @example
  9934. *
  9935. * function greet(greeting, name) {
  9936. * return greeting + ' ' + name;
  9937. * }
  9938. *
  9939. * var sayHelloTo = _.partial(greet, 'hello');
  9940. * sayHelloTo('fred');
  9941. * // => 'hello fred'
  9942. *
  9943. * // Partially applied with placeholders.
  9944. * var greetFred = _.partial(greet, _, 'fred');
  9945. * greetFred('hi');
  9946. * // => 'hi fred'
  9947. */
  9948. var partial = baseRest(function(func, partials) {
  9949. var holders = replaceHolders(partials, getHolder(partial));
  9950. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9951. });
  9952. /**
  9953. * This method is like `_.partial` except that partially applied arguments
  9954. * are appended to the arguments it receives.
  9955. *
  9956. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9957. * builds, may be used as a placeholder for partially applied arguments.
  9958. *
  9959. * **Note:** This method doesn't set the "length" property of partially
  9960. * applied functions.
  9961. *
  9962. * @static
  9963. * @memberOf _
  9964. * @since 1.0.0
  9965. * @category Function
  9966. * @param {Function} func The function to partially apply arguments to.
  9967. * @param {...*} [partials] The arguments to be partially applied.
  9968. * @returns {Function} Returns the new partially applied function.
  9969. * @example
  9970. *
  9971. * function greet(greeting, name) {
  9972. * return greeting + ' ' + name;
  9973. * }
  9974. *
  9975. * var greetFred = _.partialRight(greet, 'fred');
  9976. * greetFred('hi');
  9977. * // => 'hi fred'
  9978. *
  9979. * // Partially applied with placeholders.
  9980. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9981. * sayHelloTo('fred');
  9982. * // => 'hello fred'
  9983. */
  9984. var partialRight = baseRest(function(func, partials) {
  9985. var holders = replaceHolders(partials, getHolder(partialRight));
  9986. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9987. });
  9988. /**
  9989. * Creates a function that invokes `func` with arguments arranged according
  9990. * to the specified `indexes` where the argument value at the first index is
  9991. * provided as the first argument, the argument value at the second index is
  9992. * provided as the second argument, and so on.
  9993. *
  9994. * @static
  9995. * @memberOf _
  9996. * @since 3.0.0
  9997. * @category Function
  9998. * @param {Function} func The function to rearrange arguments for.
  9999. * @param {...(number|number[])} indexes The arranged argument indexes.
  10000. * @returns {Function} Returns the new function.
  10001. * @example
  10002. *
  10003. * var rearged = _.rearg(function(a, b, c) {
  10004. * return [a, b, c];
  10005. * }, [2, 0, 1]);
  10006. *
  10007. * rearged('b', 'c', 'a')
  10008. * // => ['a', 'b', 'c']
  10009. */
  10010. var rearg = flatRest(function(func, indexes) {
  10011. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10012. });
  10013. /**
  10014. * Creates a function that invokes `func` with the `this` binding of the
  10015. * created function and arguments from `start` and beyond provided as
  10016. * an array.
  10017. *
  10018. * **Note:** This method is based on the
  10019. * [rest parameter](https://mdn.io/rest_parameters).
  10020. *
  10021. * @static
  10022. * @memberOf _
  10023. * @since 4.0.0
  10024. * @category Function
  10025. * @param {Function} func The function to apply a rest parameter to.
  10026. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10027. * @returns {Function} Returns the new function.
  10028. * @example
  10029. *
  10030. * var say = _.rest(function(what, names) {
  10031. * return what + ' ' + _.initial(names).join(', ') +
  10032. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10033. * });
  10034. *
  10035. * say('hello', 'fred', 'barney', 'pebbles');
  10036. * // => 'hello fred, barney, & pebbles'
  10037. */
  10038. function rest(func, start) {
  10039. if (typeof func != 'function') {
  10040. throw new TypeError(FUNC_ERROR_TEXT);
  10041. }
  10042. start = start === undefined ? start : toInteger(start);
  10043. return baseRest(func, start);
  10044. }
  10045. /**
  10046. * Creates a function that invokes `func` with the `this` binding of the
  10047. * create function and an array of arguments much like
  10048. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10049. *
  10050. * **Note:** This method is based on the
  10051. * [spread operator](https://mdn.io/spread_operator).
  10052. *
  10053. * @static
  10054. * @memberOf _
  10055. * @since 3.2.0
  10056. * @category Function
  10057. * @param {Function} func The function to spread arguments over.
  10058. * @param {number} [start=0] The start position of the spread.
  10059. * @returns {Function} Returns the new function.
  10060. * @example
  10061. *
  10062. * var say = _.spread(function(who, what) {
  10063. * return who + ' says ' + what;
  10064. * });
  10065. *
  10066. * say(['fred', 'hello']);
  10067. * // => 'fred says hello'
  10068. *
  10069. * var numbers = Promise.all([
  10070. * Promise.resolve(40),
  10071. * Promise.resolve(36)
  10072. * ]);
  10073. *
  10074. * numbers.then(_.spread(function(x, y) {
  10075. * return x + y;
  10076. * }));
  10077. * // => a Promise of 76
  10078. */
  10079. function spread(func, start) {
  10080. if (typeof func != 'function') {
  10081. throw new TypeError(FUNC_ERROR_TEXT);
  10082. }
  10083. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10084. return baseRest(function(args) {
  10085. var array = args[start],
  10086. otherArgs = castSlice(args, 0, start);
  10087. if (array) {
  10088. arrayPush(otherArgs, array);
  10089. }
  10090. return apply(func, this, otherArgs);
  10091. });
  10092. }
  10093. /**
  10094. * Creates a throttled function that only invokes `func` at most once per
  10095. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10096. * method to cancel delayed `func` invocations and a `flush` method to
  10097. * immediately invoke them. Provide `options` to indicate whether `func`
  10098. * should be invoked on the leading and/or trailing edge of the `wait`
  10099. * timeout. The `func` is invoked with the last arguments provided to the
  10100. * throttled function. Subsequent calls to the throttled function return the
  10101. * result of the last `func` invocation.
  10102. *
  10103. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10104. * invoked on the trailing edge of the timeout only if the throttled function
  10105. * is invoked more than once during the `wait` timeout.
  10106. *
  10107. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10108. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10109. *
  10110. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10111. * for details over the differences between `_.throttle` and `_.debounce`.
  10112. *
  10113. * @static
  10114. * @memberOf _
  10115. * @since 0.1.0
  10116. * @category Function
  10117. * @param {Function} func The function to throttle.
  10118. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10119. * @param {Object} [options={}] The options object.
  10120. * @param {boolean} [options.leading=true]
  10121. * Specify invoking on the leading edge of the timeout.
  10122. * @param {boolean} [options.trailing=true]
  10123. * Specify invoking on the trailing edge of the timeout.
  10124. * @returns {Function} Returns the new throttled function.
  10125. * @example
  10126. *
  10127. * // Avoid excessively updating the position while scrolling.
  10128. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10129. *
  10130. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10131. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10132. * jQuery(element).on('click', throttled);
  10133. *
  10134. * // Cancel the trailing throttled invocation.
  10135. * jQuery(window).on('popstate', throttled.cancel);
  10136. */
  10137. function throttle(func, wait, options) {
  10138. var leading = true,
  10139. trailing = true;
  10140. if (typeof func != 'function') {
  10141. throw new TypeError(FUNC_ERROR_TEXT);
  10142. }
  10143. if (isObject(options)) {
  10144. leading = 'leading' in options ? !!options.leading : leading;
  10145. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10146. }
  10147. return debounce(func, wait, {
  10148. 'leading': leading,
  10149. 'maxWait': wait,
  10150. 'trailing': trailing
  10151. });
  10152. }
  10153. /**
  10154. * Creates a function that accepts up to one argument, ignoring any
  10155. * additional arguments.
  10156. *
  10157. * @static
  10158. * @memberOf _
  10159. * @since 4.0.0
  10160. * @category Function
  10161. * @param {Function} func The function to cap arguments for.
  10162. * @returns {Function} Returns the new capped function.
  10163. * @example
  10164. *
  10165. * _.map(['6', '8', '10'], _.unary(parseInt));
  10166. * // => [6, 8, 10]
  10167. */
  10168. function unary(func) {
  10169. return ary(func, 1);
  10170. }
  10171. /**
  10172. * Creates a function that provides `value` to `wrapper` as its first
  10173. * argument. Any additional arguments provided to the function are appended
  10174. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10175. * binding of the created function.
  10176. *
  10177. * @static
  10178. * @memberOf _
  10179. * @since 0.1.0
  10180. * @category Function
  10181. * @param {*} value The value to wrap.
  10182. * @param {Function} [wrapper=identity] The wrapper function.
  10183. * @returns {Function} Returns the new function.
  10184. * @example
  10185. *
  10186. * var p = _.wrap(_.escape, function(func, text) {
  10187. * return '<p>' + func(text) + '</p>';
  10188. * });
  10189. *
  10190. * p('fred, barney, & pebbles');
  10191. * // => '<p>fred, barney, &amp; pebbles</p>'
  10192. */
  10193. function wrap(value, wrapper) {
  10194. return partial(castFunction(wrapper), value);
  10195. }
  10196. /*------------------------------------------------------------------------*/
  10197. /**
  10198. * Casts `value` as an array if it's not one.
  10199. *
  10200. * @static
  10201. * @memberOf _
  10202. * @since 4.4.0
  10203. * @category Lang
  10204. * @param {*} value The value to inspect.
  10205. * @returns {Array} Returns the cast array.
  10206. * @example
  10207. *
  10208. * _.castArray(1);
  10209. * // => [1]
  10210. *
  10211. * _.castArray({ 'a': 1 });
  10212. * // => [{ 'a': 1 }]
  10213. *
  10214. * _.castArray('abc');
  10215. * // => ['abc']
  10216. *
  10217. * _.castArray(null);
  10218. * // => [null]
  10219. *
  10220. * _.castArray(undefined);
  10221. * // => [undefined]
  10222. *
  10223. * _.castArray();
  10224. * // => []
  10225. *
  10226. * var array = [1, 2, 3];
  10227. * console.log(_.castArray(array) === array);
  10228. * // => true
  10229. */
  10230. function castArray() {
  10231. if (!arguments.length) {
  10232. return [];
  10233. }
  10234. var value = arguments[0];
  10235. return isArray(value) ? value : [value];
  10236. }
  10237. /**
  10238. * Creates a shallow clone of `value`.
  10239. *
  10240. * **Note:** This method is loosely based on the
  10241. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10242. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10243. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10244. * arrays. The own enumerable properties of `arguments` objects are cloned
  10245. * as plain objects. An empty object is returned for uncloneable values such
  10246. * as error objects, functions, DOM nodes, and WeakMaps.
  10247. *
  10248. * @static
  10249. * @memberOf _
  10250. * @since 0.1.0
  10251. * @category Lang
  10252. * @param {*} value The value to clone.
  10253. * @returns {*} Returns the cloned value.
  10254. * @see _.cloneDeep
  10255. * @example
  10256. *
  10257. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10258. *
  10259. * var shallow = _.clone(objects);
  10260. * console.log(shallow[0] === objects[0]);
  10261. * // => true
  10262. */
  10263. function clone(value) {
  10264. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10265. }
  10266. /**
  10267. * This method is like `_.clone` except that it accepts `customizer` which
  10268. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10269. * cloning is handled by the method instead. The `customizer` is invoked with
  10270. * up to four arguments; (value [, index|key, object, stack]).
  10271. *
  10272. * @static
  10273. * @memberOf _
  10274. * @since 4.0.0
  10275. * @category Lang
  10276. * @param {*} value The value to clone.
  10277. * @param {Function} [customizer] The function to customize cloning.
  10278. * @returns {*} Returns the cloned value.
  10279. * @see _.cloneDeepWith
  10280. * @example
  10281. *
  10282. * function customizer(value) {
  10283. * if (_.isElement(value)) {
  10284. * return value.cloneNode(false);
  10285. * }
  10286. * }
  10287. *
  10288. * var el = _.cloneWith(document.body, customizer);
  10289. *
  10290. * console.log(el === document.body);
  10291. * // => false
  10292. * console.log(el.nodeName);
  10293. * // => 'BODY'
  10294. * console.log(el.childNodes.length);
  10295. * // => 0
  10296. */
  10297. function cloneWith(value, customizer) {
  10298. customizer = typeof customizer == 'function' ? customizer : undefined;
  10299. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10300. }
  10301. /**
  10302. * This method is like `_.clone` except that it recursively clones `value`.
  10303. *
  10304. * @static
  10305. * @memberOf _
  10306. * @since 1.0.0
  10307. * @category Lang
  10308. * @param {*} value The value to recursively clone.
  10309. * @returns {*} Returns the deep cloned value.
  10310. * @see _.clone
  10311. * @example
  10312. *
  10313. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10314. *
  10315. * var deep = _.cloneDeep(objects);
  10316. * console.log(deep[0] === objects[0]);
  10317. * // => false
  10318. */
  10319. function cloneDeep(value) {
  10320. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10321. }
  10322. /**
  10323. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10324. *
  10325. * @static
  10326. * @memberOf _
  10327. * @since 4.0.0
  10328. * @category Lang
  10329. * @param {*} value The value to recursively clone.
  10330. * @param {Function} [customizer] The function to customize cloning.
  10331. * @returns {*} Returns the deep cloned value.
  10332. * @see _.cloneWith
  10333. * @example
  10334. *
  10335. * function customizer(value) {
  10336. * if (_.isElement(value)) {
  10337. * return value.cloneNode(true);
  10338. * }
  10339. * }
  10340. *
  10341. * var el = _.cloneDeepWith(document.body, customizer);
  10342. *
  10343. * console.log(el === document.body);
  10344. * // => false
  10345. * console.log(el.nodeName);
  10346. * // => 'BODY'
  10347. * console.log(el.childNodes.length);
  10348. * // => 20
  10349. */
  10350. function cloneDeepWith(value, customizer) {
  10351. customizer = typeof customizer == 'function' ? customizer : undefined;
  10352. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10353. }
  10354. /**
  10355. * Checks if `object` conforms to `source` by invoking the predicate
  10356. * properties of `source` with the corresponding property values of `object`.
  10357. *
  10358. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10359. * partially applied.
  10360. *
  10361. * @static
  10362. * @memberOf _
  10363. * @since 4.14.0
  10364. * @category Lang
  10365. * @param {Object} object The object to inspect.
  10366. * @param {Object} source The object of property predicates to conform to.
  10367. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10368. * @example
  10369. *
  10370. * var object = { 'a': 1, 'b': 2 };
  10371. *
  10372. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10373. * // => true
  10374. *
  10375. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10376. * // => false
  10377. */
  10378. function conformsTo(object, source) {
  10379. return source == null || baseConformsTo(object, source, keys(source));
  10380. }
  10381. /**
  10382. * Performs a
  10383. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10384. * comparison between two values to determine if they are equivalent.
  10385. *
  10386. * @static
  10387. * @memberOf _
  10388. * @since 4.0.0
  10389. * @category Lang
  10390. * @param {*} value The value to compare.
  10391. * @param {*} other The other value to compare.
  10392. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10393. * @example
  10394. *
  10395. * var object = { 'a': 1 };
  10396. * var other = { 'a': 1 };
  10397. *
  10398. * _.eq(object, object);
  10399. * // => true
  10400. *
  10401. * _.eq(object, other);
  10402. * // => false
  10403. *
  10404. * _.eq('a', 'a');
  10405. * // => true
  10406. *
  10407. * _.eq('a', Object('a'));
  10408. * // => false
  10409. *
  10410. * _.eq(NaN, NaN);
  10411. * // => true
  10412. */
  10413. function eq(value, other) {
  10414. return value === other || (value !== value && other !== other);
  10415. }
  10416. /**
  10417. * Checks if `value` is greater than `other`.
  10418. *
  10419. * @static
  10420. * @memberOf _
  10421. * @since 3.9.0
  10422. * @category Lang
  10423. * @param {*} value The value to compare.
  10424. * @param {*} other The other value to compare.
  10425. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10426. * else `false`.
  10427. * @see _.lt
  10428. * @example
  10429. *
  10430. * _.gt(3, 1);
  10431. * // => true
  10432. *
  10433. * _.gt(3, 3);
  10434. * // => false
  10435. *
  10436. * _.gt(1, 3);
  10437. * // => false
  10438. */
  10439. var gt = createRelationalOperation(baseGt);
  10440. /**
  10441. * Checks if `value` is greater than or equal to `other`.
  10442. *
  10443. * @static
  10444. * @memberOf _
  10445. * @since 3.9.0
  10446. * @category Lang
  10447. * @param {*} value The value to compare.
  10448. * @param {*} other The other value to compare.
  10449. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10450. * `other`, else `false`.
  10451. * @see _.lte
  10452. * @example
  10453. *
  10454. * _.gte(3, 1);
  10455. * // => true
  10456. *
  10457. * _.gte(3, 3);
  10458. * // => true
  10459. *
  10460. * _.gte(1, 3);
  10461. * // => false
  10462. */
  10463. var gte = createRelationalOperation(function(value, other) {
  10464. return value >= other;
  10465. });
  10466. /**
  10467. * Checks if `value` is likely an `arguments` object.
  10468. *
  10469. * @static
  10470. * @memberOf _
  10471. * @since 0.1.0
  10472. * @category Lang
  10473. * @param {*} value The value to check.
  10474. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10475. * else `false`.
  10476. * @example
  10477. *
  10478. * _.isArguments(function() { return arguments; }());
  10479. * // => true
  10480. *
  10481. * _.isArguments([1, 2, 3]);
  10482. * // => false
  10483. */
  10484. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10485. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10486. !propertyIsEnumerable.call(value, 'callee');
  10487. };
  10488. /**
  10489. * Checks if `value` is classified as an `Array` object.
  10490. *
  10491. * @static
  10492. * @memberOf _
  10493. * @since 0.1.0
  10494. * @category Lang
  10495. * @param {*} value The value to check.
  10496. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10497. * @example
  10498. *
  10499. * _.isArray([1, 2, 3]);
  10500. * // => true
  10501. *
  10502. * _.isArray(document.body.children);
  10503. * // => false
  10504. *
  10505. * _.isArray('abc');
  10506. * // => false
  10507. *
  10508. * _.isArray(_.noop);
  10509. * // => false
  10510. */
  10511. var isArray = Array.isArray;
  10512. /**
  10513. * Checks if `value` is classified as an `ArrayBuffer` object.
  10514. *
  10515. * @static
  10516. * @memberOf _
  10517. * @since 4.3.0
  10518. * @category Lang
  10519. * @param {*} value The value to check.
  10520. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10521. * @example
  10522. *
  10523. * _.isArrayBuffer(new ArrayBuffer(2));
  10524. * // => true
  10525. *
  10526. * _.isArrayBuffer(new Array(2));
  10527. * // => false
  10528. */
  10529. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10530. /**
  10531. * Checks if `value` is array-like. A value is considered array-like if it's
  10532. * not a function and has a `value.length` that's an integer greater than or
  10533. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10534. *
  10535. * @static
  10536. * @memberOf _
  10537. * @since 4.0.0
  10538. * @category Lang
  10539. * @param {*} value The value to check.
  10540. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10541. * @example
  10542. *
  10543. * _.isArrayLike([1, 2, 3]);
  10544. * // => true
  10545. *
  10546. * _.isArrayLike(document.body.children);
  10547. * // => true
  10548. *
  10549. * _.isArrayLike('abc');
  10550. * // => true
  10551. *
  10552. * _.isArrayLike(_.noop);
  10553. * // => false
  10554. */
  10555. function isArrayLike(value) {
  10556. return value != null && isLength(value.length) && !isFunction(value);
  10557. }
  10558. /**
  10559. * This method is like `_.isArrayLike` except that it also checks if `value`
  10560. * is an object.
  10561. *
  10562. * @static
  10563. * @memberOf _
  10564. * @since 4.0.0
  10565. * @category Lang
  10566. * @param {*} value The value to check.
  10567. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10568. * else `false`.
  10569. * @example
  10570. *
  10571. * _.isArrayLikeObject([1, 2, 3]);
  10572. * // => true
  10573. *
  10574. * _.isArrayLikeObject(document.body.children);
  10575. * // => true
  10576. *
  10577. * _.isArrayLikeObject('abc');
  10578. * // => false
  10579. *
  10580. * _.isArrayLikeObject(_.noop);
  10581. * // => false
  10582. */
  10583. function isArrayLikeObject(value) {
  10584. return isObjectLike(value) && isArrayLike(value);
  10585. }
  10586. /**
  10587. * Checks if `value` is classified as a boolean primitive or object.
  10588. *
  10589. * @static
  10590. * @memberOf _
  10591. * @since 0.1.0
  10592. * @category Lang
  10593. * @param {*} value The value to check.
  10594. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10595. * @example
  10596. *
  10597. * _.isBoolean(false);
  10598. * // => true
  10599. *
  10600. * _.isBoolean(null);
  10601. * // => false
  10602. */
  10603. function isBoolean(value) {
  10604. return value === true || value === false ||
  10605. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10606. }
  10607. /**
  10608. * Checks if `value` is a buffer.
  10609. *
  10610. * @static
  10611. * @memberOf _
  10612. * @since 4.3.0
  10613. * @category Lang
  10614. * @param {*} value The value to check.
  10615. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10616. * @example
  10617. *
  10618. * _.isBuffer(new Buffer(2));
  10619. * // => true
  10620. *
  10621. * _.isBuffer(new Uint8Array(2));
  10622. * // => false
  10623. */
  10624. var isBuffer = nativeIsBuffer || stubFalse;
  10625. /**
  10626. * Checks if `value` is classified as a `Date` object.
  10627. *
  10628. * @static
  10629. * @memberOf _
  10630. * @since 0.1.0
  10631. * @category Lang
  10632. * @param {*} value The value to check.
  10633. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10634. * @example
  10635. *
  10636. * _.isDate(new Date);
  10637. * // => true
  10638. *
  10639. * _.isDate('Mon April 23 2012');
  10640. * // => false
  10641. */
  10642. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10643. /**
  10644. * Checks if `value` is likely a DOM element.
  10645. *
  10646. * @static
  10647. * @memberOf _
  10648. * @since 0.1.0
  10649. * @category Lang
  10650. * @param {*} value The value to check.
  10651. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10652. * @example
  10653. *
  10654. * _.isElement(document.body);
  10655. * // => true
  10656. *
  10657. * _.isElement('<body>');
  10658. * // => false
  10659. */
  10660. function isElement(value) {
  10661. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10662. }
  10663. /**
  10664. * Checks if `value` is an empty object, collection, map, or set.
  10665. *
  10666. * Objects are considered empty if they have no own enumerable string keyed
  10667. * properties.
  10668. *
  10669. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10670. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10671. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10672. *
  10673. * @static
  10674. * @memberOf _
  10675. * @since 0.1.0
  10676. * @category Lang
  10677. * @param {*} value The value to check.
  10678. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10679. * @example
  10680. *
  10681. * _.isEmpty(null);
  10682. * // => true
  10683. *
  10684. * _.isEmpty(true);
  10685. * // => true
  10686. *
  10687. * _.isEmpty(1);
  10688. * // => true
  10689. *
  10690. * _.isEmpty([1, 2, 3]);
  10691. * // => false
  10692. *
  10693. * _.isEmpty({ 'a': 1 });
  10694. * // => false
  10695. */
  10696. function isEmpty(value) {
  10697. if (value == null) {
  10698. return true;
  10699. }
  10700. if (isArrayLike(value) &&
  10701. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10702. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10703. return !value.length;
  10704. }
  10705. var tag = getTag(value);
  10706. if (tag == mapTag || tag == setTag) {
  10707. return !value.size;
  10708. }
  10709. if (isPrototype(value)) {
  10710. return !baseKeys(value).length;
  10711. }
  10712. for (var key in value) {
  10713. if (hasOwnProperty.call(value, key)) {
  10714. return false;
  10715. }
  10716. }
  10717. return true;
  10718. }
  10719. /**
  10720. * Performs a deep comparison between two values to determine if they are
  10721. * equivalent.
  10722. *
  10723. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10724. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10725. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10726. * by their own, not inherited, enumerable properties. Functions and DOM
  10727. * nodes are compared by strict equality, i.e. `===`.
  10728. *
  10729. * @static
  10730. * @memberOf _
  10731. * @since 0.1.0
  10732. * @category Lang
  10733. * @param {*} value The value to compare.
  10734. * @param {*} other The other value to compare.
  10735. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10736. * @example
  10737. *
  10738. * var object = { 'a': 1 };
  10739. * var other = { 'a': 1 };
  10740. *
  10741. * _.isEqual(object, other);
  10742. * // => true
  10743. *
  10744. * object === other;
  10745. * // => false
  10746. */
  10747. function isEqual(value, other) {
  10748. return baseIsEqual(value, other);
  10749. }
  10750. /**
  10751. * This method is like `_.isEqual` except that it accepts `customizer` which
  10752. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10753. * are handled by the method instead. The `customizer` is invoked with up to
  10754. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10755. *
  10756. * @static
  10757. * @memberOf _
  10758. * @since 4.0.0
  10759. * @category Lang
  10760. * @param {*} value The value to compare.
  10761. * @param {*} other The other value to compare.
  10762. * @param {Function} [customizer] The function to customize comparisons.
  10763. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10764. * @example
  10765. *
  10766. * function isGreeting(value) {
  10767. * return /^h(?:i|ello)$/.test(value);
  10768. * }
  10769. *
  10770. * function customizer(objValue, othValue) {
  10771. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10772. * return true;
  10773. * }
  10774. * }
  10775. *
  10776. * var array = ['hello', 'goodbye'];
  10777. * var other = ['hi', 'goodbye'];
  10778. *
  10779. * _.isEqualWith(array, other, customizer);
  10780. * // => true
  10781. */
  10782. function isEqualWith(value, other, customizer) {
  10783. customizer = typeof customizer == 'function' ? customizer : undefined;
  10784. var result = customizer ? customizer(value, other) : undefined;
  10785. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10786. }
  10787. /**
  10788. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10789. * `SyntaxError`, `TypeError`, or `URIError` object.
  10790. *
  10791. * @static
  10792. * @memberOf _
  10793. * @since 3.0.0
  10794. * @category Lang
  10795. * @param {*} value The value to check.
  10796. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10797. * @example
  10798. *
  10799. * _.isError(new Error);
  10800. * // => true
  10801. *
  10802. * _.isError(Error);
  10803. * // => false
  10804. */
  10805. function isError(value) {
  10806. if (!isObjectLike(value)) {
  10807. return false;
  10808. }
  10809. var tag = baseGetTag(value);
  10810. return tag == errorTag || tag == domExcTag ||
  10811. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10812. }
  10813. /**
  10814. * Checks if `value` is a finite primitive number.
  10815. *
  10816. * **Note:** This method is based on
  10817. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10818. *
  10819. * @static
  10820. * @memberOf _
  10821. * @since 0.1.0
  10822. * @category Lang
  10823. * @param {*} value The value to check.
  10824. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10825. * @example
  10826. *
  10827. * _.isFinite(3);
  10828. * // => true
  10829. *
  10830. * _.isFinite(Number.MIN_VALUE);
  10831. * // => true
  10832. *
  10833. * _.isFinite(Infinity);
  10834. * // => false
  10835. *
  10836. * _.isFinite('3');
  10837. * // => false
  10838. */
  10839. function isFinite(value) {
  10840. return typeof value == 'number' && nativeIsFinite(value);
  10841. }
  10842. /**
  10843. * Checks if `value` is classified as a `Function` object.
  10844. *
  10845. * @static
  10846. * @memberOf _
  10847. * @since 0.1.0
  10848. * @category Lang
  10849. * @param {*} value The value to check.
  10850. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10851. * @example
  10852. *
  10853. * _.isFunction(_);
  10854. * // => true
  10855. *
  10856. * _.isFunction(/abc/);
  10857. * // => false
  10858. */
  10859. function isFunction(value) {
  10860. if (!isObject(value)) {
  10861. return false;
  10862. }
  10863. // The use of `Object#toString` avoids issues with the `typeof` operator
  10864. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10865. var tag = baseGetTag(value);
  10866. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10867. }
  10868. /**
  10869. * Checks if `value` is an integer.
  10870. *
  10871. * **Note:** This method is based on
  10872. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10873. *
  10874. * @static
  10875. * @memberOf _
  10876. * @since 4.0.0
  10877. * @category Lang
  10878. * @param {*} value The value to check.
  10879. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10880. * @example
  10881. *
  10882. * _.isInteger(3);
  10883. * // => true
  10884. *
  10885. * _.isInteger(Number.MIN_VALUE);
  10886. * // => false
  10887. *
  10888. * _.isInteger(Infinity);
  10889. * // => false
  10890. *
  10891. * _.isInteger('3');
  10892. * // => false
  10893. */
  10894. function isInteger(value) {
  10895. return typeof value == 'number' && value == toInteger(value);
  10896. }
  10897. /**
  10898. * Checks if `value` is a valid array-like length.
  10899. *
  10900. * **Note:** This method is loosely based on
  10901. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10902. *
  10903. * @static
  10904. * @memberOf _
  10905. * @since 4.0.0
  10906. * @category Lang
  10907. * @param {*} value The value to check.
  10908. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10909. * @example
  10910. *
  10911. * _.isLength(3);
  10912. * // => true
  10913. *
  10914. * _.isLength(Number.MIN_VALUE);
  10915. * // => false
  10916. *
  10917. * _.isLength(Infinity);
  10918. * // => false
  10919. *
  10920. * _.isLength('3');
  10921. * // => false
  10922. */
  10923. function isLength(value) {
  10924. return typeof value == 'number' &&
  10925. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10926. }
  10927. /**
  10928. * Checks if `value` is the
  10929. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10930. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10931. *
  10932. * @static
  10933. * @memberOf _
  10934. * @since 0.1.0
  10935. * @category Lang
  10936. * @param {*} value The value to check.
  10937. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10938. * @example
  10939. *
  10940. * _.isObject({});
  10941. * // => true
  10942. *
  10943. * _.isObject([1, 2, 3]);
  10944. * // => true
  10945. *
  10946. * _.isObject(_.noop);
  10947. * // => true
  10948. *
  10949. * _.isObject(null);
  10950. * // => false
  10951. */
  10952. function isObject(value) {
  10953. var type = typeof value;
  10954. return value != null && (type == 'object' || type == 'function');
  10955. }
  10956. /**
  10957. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10958. * and has a `typeof` result of "object".
  10959. *
  10960. * @static
  10961. * @memberOf _
  10962. * @since 4.0.0
  10963. * @category Lang
  10964. * @param {*} value The value to check.
  10965. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10966. * @example
  10967. *
  10968. * _.isObjectLike({});
  10969. * // => true
  10970. *
  10971. * _.isObjectLike([1, 2, 3]);
  10972. * // => true
  10973. *
  10974. * _.isObjectLike(_.noop);
  10975. * // => false
  10976. *
  10977. * _.isObjectLike(null);
  10978. * // => false
  10979. */
  10980. function isObjectLike(value) {
  10981. return value != null && typeof value == 'object';
  10982. }
  10983. /**
  10984. * Checks if `value` is classified as a `Map` object.
  10985. *
  10986. * @static
  10987. * @memberOf _
  10988. * @since 4.3.0
  10989. * @category Lang
  10990. * @param {*} value The value to check.
  10991. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10992. * @example
  10993. *
  10994. * _.isMap(new Map);
  10995. * // => true
  10996. *
  10997. * _.isMap(new WeakMap);
  10998. * // => false
  10999. */
  11000. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11001. /**
  11002. * Performs a partial deep comparison between `object` and `source` to
  11003. * determine if `object` contains equivalent property values.
  11004. *
  11005. * **Note:** This method is equivalent to `_.matches` when `source` is
  11006. * partially applied.
  11007. *
  11008. * Partial comparisons will match empty array and empty object `source`
  11009. * values against any array or object value, respectively. See `_.isEqual`
  11010. * for a list of supported value comparisons.
  11011. *
  11012. * @static
  11013. * @memberOf _
  11014. * @since 3.0.0
  11015. * @category Lang
  11016. * @param {Object} object The object to inspect.
  11017. * @param {Object} source The object of property values to match.
  11018. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11019. * @example
  11020. *
  11021. * var object = { 'a': 1, 'b': 2 };
  11022. *
  11023. * _.isMatch(object, { 'b': 2 });
  11024. * // => true
  11025. *
  11026. * _.isMatch(object, { 'b': 1 });
  11027. * // => false
  11028. */
  11029. function isMatch(object, source) {
  11030. return object === source || baseIsMatch(object, source, getMatchData(source));
  11031. }
  11032. /**
  11033. * This method is like `_.isMatch` except that it accepts `customizer` which
  11034. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11035. * are handled by the method instead. The `customizer` is invoked with five
  11036. * arguments: (objValue, srcValue, index|key, object, source).
  11037. *
  11038. * @static
  11039. * @memberOf _
  11040. * @since 4.0.0
  11041. * @category Lang
  11042. * @param {Object} object The object to inspect.
  11043. * @param {Object} source The object of property values to match.
  11044. * @param {Function} [customizer] The function to customize comparisons.
  11045. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11046. * @example
  11047. *
  11048. * function isGreeting(value) {
  11049. * return /^h(?:i|ello)$/.test(value);
  11050. * }
  11051. *
  11052. * function customizer(objValue, srcValue) {
  11053. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11054. * return true;
  11055. * }
  11056. * }
  11057. *
  11058. * var object = { 'greeting': 'hello' };
  11059. * var source = { 'greeting': 'hi' };
  11060. *
  11061. * _.isMatchWith(object, source, customizer);
  11062. * // => true
  11063. */
  11064. function isMatchWith(object, source, customizer) {
  11065. customizer = typeof customizer == 'function' ? customizer : undefined;
  11066. return baseIsMatch(object, source, getMatchData(source), customizer);
  11067. }
  11068. /**
  11069. * Checks if `value` is `NaN`.
  11070. *
  11071. * **Note:** This method is based on
  11072. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11073. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11074. * `undefined` and other non-number values.
  11075. *
  11076. * @static
  11077. * @memberOf _
  11078. * @since 0.1.0
  11079. * @category Lang
  11080. * @param {*} value The value to check.
  11081. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11082. * @example
  11083. *
  11084. * _.isNaN(NaN);
  11085. * // => true
  11086. *
  11087. * _.isNaN(new Number(NaN));
  11088. * // => true
  11089. *
  11090. * isNaN(undefined);
  11091. * // => true
  11092. *
  11093. * _.isNaN(undefined);
  11094. * // => false
  11095. */
  11096. function isNaN(value) {
  11097. // An `NaN` primitive is the only value that is not equal to itself.
  11098. // Perform the `toStringTag` check first to avoid errors with some
  11099. // ActiveX objects in IE.
  11100. return isNumber(value) && value != +value;
  11101. }
  11102. /**
  11103. * Checks if `value` is a pristine native function.
  11104. *
  11105. * **Note:** This method can't reliably detect native functions in the presence
  11106. * of the core-js package because core-js circumvents this kind of detection.
  11107. * Despite multiple requests, the core-js maintainer has made it clear: any
  11108. * attempt to fix the detection will be obstructed. As a result, we're left
  11109. * with little choice but to throw an error. Unfortunately, this also affects
  11110. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11111. * which rely on core-js.
  11112. *
  11113. * @static
  11114. * @memberOf _
  11115. * @since 3.0.0
  11116. * @category Lang
  11117. * @param {*} value The value to check.
  11118. * @returns {boolean} Returns `true` if `value` is a native function,
  11119. * else `false`.
  11120. * @example
  11121. *
  11122. * _.isNative(Array.prototype.push);
  11123. * // => true
  11124. *
  11125. * _.isNative(_);
  11126. * // => false
  11127. */
  11128. function isNative(value) {
  11129. if (isMaskable(value)) {
  11130. throw new Error(CORE_ERROR_TEXT);
  11131. }
  11132. return baseIsNative(value);
  11133. }
  11134. /**
  11135. * Checks if `value` is `null`.
  11136. *
  11137. * @static
  11138. * @memberOf _
  11139. * @since 0.1.0
  11140. * @category Lang
  11141. * @param {*} value The value to check.
  11142. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11143. * @example
  11144. *
  11145. * _.isNull(null);
  11146. * // => true
  11147. *
  11148. * _.isNull(void 0);
  11149. * // => false
  11150. */
  11151. function isNull(value) {
  11152. return value === null;
  11153. }
  11154. /**
  11155. * Checks if `value` is `null` or `undefined`.
  11156. *
  11157. * @static
  11158. * @memberOf _
  11159. * @since 4.0.0
  11160. * @category Lang
  11161. * @param {*} value The value to check.
  11162. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11163. * @example
  11164. *
  11165. * _.isNil(null);
  11166. * // => true
  11167. *
  11168. * _.isNil(void 0);
  11169. * // => true
  11170. *
  11171. * _.isNil(NaN);
  11172. * // => false
  11173. */
  11174. function isNil(value) {
  11175. return value == null;
  11176. }
  11177. /**
  11178. * Checks if `value` is classified as a `Number` primitive or object.
  11179. *
  11180. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11181. * classified as numbers, use the `_.isFinite` method.
  11182. *
  11183. * @static
  11184. * @memberOf _
  11185. * @since 0.1.0
  11186. * @category Lang
  11187. * @param {*} value The value to check.
  11188. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11189. * @example
  11190. *
  11191. * _.isNumber(3);
  11192. * // => true
  11193. *
  11194. * _.isNumber(Number.MIN_VALUE);
  11195. * // => true
  11196. *
  11197. * _.isNumber(Infinity);
  11198. * // => true
  11199. *
  11200. * _.isNumber('3');
  11201. * // => false
  11202. */
  11203. function isNumber(value) {
  11204. return typeof value == 'number' ||
  11205. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11206. }
  11207. /**
  11208. * Checks if `value` is a plain object, that is, an object created by the
  11209. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11210. *
  11211. * @static
  11212. * @memberOf _
  11213. * @since 0.8.0
  11214. * @category Lang
  11215. * @param {*} value The value to check.
  11216. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11217. * @example
  11218. *
  11219. * function Foo() {
  11220. * this.a = 1;
  11221. * }
  11222. *
  11223. * _.isPlainObject(new Foo);
  11224. * // => false
  11225. *
  11226. * _.isPlainObject([1, 2, 3]);
  11227. * // => false
  11228. *
  11229. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11230. * // => true
  11231. *
  11232. * _.isPlainObject(Object.create(null));
  11233. * // => true
  11234. */
  11235. function isPlainObject(value) {
  11236. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11237. return false;
  11238. }
  11239. var proto = getPrototype(value);
  11240. if (proto === null) {
  11241. return true;
  11242. }
  11243. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11244. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11245. funcToString.call(Ctor) == objectCtorString;
  11246. }
  11247. /**
  11248. * Checks if `value` is classified as a `RegExp` object.
  11249. *
  11250. * @static
  11251. * @memberOf _
  11252. * @since 0.1.0
  11253. * @category Lang
  11254. * @param {*} value The value to check.
  11255. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11256. * @example
  11257. *
  11258. * _.isRegExp(/abc/);
  11259. * // => true
  11260. *
  11261. * _.isRegExp('/abc/');
  11262. * // => false
  11263. */
  11264. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11265. /**
  11266. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11267. * double precision number which isn't the result of a rounded unsafe integer.
  11268. *
  11269. * **Note:** This method is based on
  11270. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11271. *
  11272. * @static
  11273. * @memberOf _
  11274. * @since 4.0.0
  11275. * @category Lang
  11276. * @param {*} value The value to check.
  11277. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11278. * @example
  11279. *
  11280. * _.isSafeInteger(3);
  11281. * // => true
  11282. *
  11283. * _.isSafeInteger(Number.MIN_VALUE);
  11284. * // => false
  11285. *
  11286. * _.isSafeInteger(Infinity);
  11287. * // => false
  11288. *
  11289. * _.isSafeInteger('3');
  11290. * // => false
  11291. */
  11292. function isSafeInteger(value) {
  11293. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11294. }
  11295. /**
  11296. * Checks if `value` is classified as a `Set` object.
  11297. *
  11298. * @static
  11299. * @memberOf _
  11300. * @since 4.3.0
  11301. * @category Lang
  11302. * @param {*} value The value to check.
  11303. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11304. * @example
  11305. *
  11306. * _.isSet(new Set);
  11307. * // => true
  11308. *
  11309. * _.isSet(new WeakSet);
  11310. * // => false
  11311. */
  11312. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11313. /**
  11314. * Checks if `value` is classified as a `String` primitive or object.
  11315. *
  11316. * @static
  11317. * @since 0.1.0
  11318. * @memberOf _
  11319. * @category Lang
  11320. * @param {*} value The value to check.
  11321. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11322. * @example
  11323. *
  11324. * _.isString('abc');
  11325. * // => true
  11326. *
  11327. * _.isString(1);
  11328. * // => false
  11329. */
  11330. function isString(value) {
  11331. return typeof value == 'string' ||
  11332. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11333. }
  11334. /**
  11335. * Checks if `value` is classified as a `Symbol` primitive or object.
  11336. *
  11337. * @static
  11338. * @memberOf _
  11339. * @since 4.0.0
  11340. * @category Lang
  11341. * @param {*} value The value to check.
  11342. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11343. * @example
  11344. *
  11345. * _.isSymbol(Symbol.iterator);
  11346. * // => true
  11347. *
  11348. * _.isSymbol('abc');
  11349. * // => false
  11350. */
  11351. function isSymbol(value) {
  11352. return typeof value == 'symbol' ||
  11353. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11354. }
  11355. /**
  11356. * Checks if `value` is classified as a typed array.
  11357. *
  11358. * @static
  11359. * @memberOf _
  11360. * @since 3.0.0
  11361. * @category Lang
  11362. * @param {*} value The value to check.
  11363. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11364. * @example
  11365. *
  11366. * _.isTypedArray(new Uint8Array);
  11367. * // => true
  11368. *
  11369. * _.isTypedArray([]);
  11370. * // => false
  11371. */
  11372. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11373. /**
  11374. * Checks if `value` is `undefined`.
  11375. *
  11376. * @static
  11377. * @since 0.1.0
  11378. * @memberOf _
  11379. * @category Lang
  11380. * @param {*} value The value to check.
  11381. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11382. * @example
  11383. *
  11384. * _.isUndefined(void 0);
  11385. * // => true
  11386. *
  11387. * _.isUndefined(null);
  11388. * // => false
  11389. */
  11390. function isUndefined(value) {
  11391. return value === undefined;
  11392. }
  11393. /**
  11394. * Checks if `value` is classified as a `WeakMap` object.
  11395. *
  11396. * @static
  11397. * @memberOf _
  11398. * @since 4.3.0
  11399. * @category Lang
  11400. * @param {*} value The value to check.
  11401. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11402. * @example
  11403. *
  11404. * _.isWeakMap(new WeakMap);
  11405. * // => true
  11406. *
  11407. * _.isWeakMap(new Map);
  11408. * // => false
  11409. */
  11410. function isWeakMap(value) {
  11411. return isObjectLike(value) && getTag(value) == weakMapTag;
  11412. }
  11413. /**
  11414. * Checks if `value` is classified as a `WeakSet` object.
  11415. *
  11416. * @static
  11417. * @memberOf _
  11418. * @since 4.3.0
  11419. * @category Lang
  11420. * @param {*} value The value to check.
  11421. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11422. * @example
  11423. *
  11424. * _.isWeakSet(new WeakSet);
  11425. * // => true
  11426. *
  11427. * _.isWeakSet(new Set);
  11428. * // => false
  11429. */
  11430. function isWeakSet(value) {
  11431. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11432. }
  11433. /**
  11434. * Checks if `value` is less than `other`.
  11435. *
  11436. * @static
  11437. * @memberOf _
  11438. * @since 3.9.0
  11439. * @category Lang
  11440. * @param {*} value The value to compare.
  11441. * @param {*} other The other value to compare.
  11442. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11443. * else `false`.
  11444. * @see _.gt
  11445. * @example
  11446. *
  11447. * _.lt(1, 3);
  11448. * // => true
  11449. *
  11450. * _.lt(3, 3);
  11451. * // => false
  11452. *
  11453. * _.lt(3, 1);
  11454. * // => false
  11455. */
  11456. var lt = createRelationalOperation(baseLt);
  11457. /**
  11458. * Checks if `value` is less than or equal to `other`.
  11459. *
  11460. * @static
  11461. * @memberOf _
  11462. * @since 3.9.0
  11463. * @category Lang
  11464. * @param {*} value The value to compare.
  11465. * @param {*} other The other value to compare.
  11466. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11467. * `other`, else `false`.
  11468. * @see _.gte
  11469. * @example
  11470. *
  11471. * _.lte(1, 3);
  11472. * // => true
  11473. *
  11474. * _.lte(3, 3);
  11475. * // => true
  11476. *
  11477. * _.lte(3, 1);
  11478. * // => false
  11479. */
  11480. var lte = createRelationalOperation(function(value, other) {
  11481. return value <= other;
  11482. });
  11483. /**
  11484. * Converts `value` to an array.
  11485. *
  11486. * @static
  11487. * @since 0.1.0
  11488. * @memberOf _
  11489. * @category Lang
  11490. * @param {*} value The value to convert.
  11491. * @returns {Array} Returns the converted array.
  11492. * @example
  11493. *
  11494. * _.toArray({ 'a': 1, 'b': 2 });
  11495. * // => [1, 2]
  11496. *
  11497. * _.toArray('abc');
  11498. * // => ['a', 'b', 'c']
  11499. *
  11500. * _.toArray(1);
  11501. * // => []
  11502. *
  11503. * _.toArray(null);
  11504. * // => []
  11505. */
  11506. function toArray(value) {
  11507. if (!value) {
  11508. return [];
  11509. }
  11510. if (isArrayLike(value)) {
  11511. return isString(value) ? stringToArray(value) : copyArray(value);
  11512. }
  11513. if (symIterator && value[symIterator]) {
  11514. return iteratorToArray(value[symIterator]());
  11515. }
  11516. var tag = getTag(value),
  11517. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11518. return func(value);
  11519. }
  11520. /**
  11521. * Converts `value` to a finite number.
  11522. *
  11523. * @static
  11524. * @memberOf _
  11525. * @since 4.12.0
  11526. * @category Lang
  11527. * @param {*} value The value to convert.
  11528. * @returns {number} Returns the converted number.
  11529. * @example
  11530. *
  11531. * _.toFinite(3.2);
  11532. * // => 3.2
  11533. *
  11534. * _.toFinite(Number.MIN_VALUE);
  11535. * // => 5e-324
  11536. *
  11537. * _.toFinite(Infinity);
  11538. * // => 1.7976931348623157e+308
  11539. *
  11540. * _.toFinite('3.2');
  11541. * // => 3.2
  11542. */
  11543. function toFinite(value) {
  11544. if (!value) {
  11545. return value === 0 ? value : 0;
  11546. }
  11547. value = toNumber(value);
  11548. if (value === INFINITY || value === -INFINITY) {
  11549. var sign = (value < 0 ? -1 : 1);
  11550. return sign * MAX_INTEGER;
  11551. }
  11552. return value === value ? value : 0;
  11553. }
  11554. /**
  11555. * Converts `value` to an integer.
  11556. *
  11557. * **Note:** This method is loosely based on
  11558. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11559. *
  11560. * @static
  11561. * @memberOf _
  11562. * @since 4.0.0
  11563. * @category Lang
  11564. * @param {*} value The value to convert.
  11565. * @returns {number} Returns the converted integer.
  11566. * @example
  11567. *
  11568. * _.toInteger(3.2);
  11569. * // => 3
  11570. *
  11571. * _.toInteger(Number.MIN_VALUE);
  11572. * // => 0
  11573. *
  11574. * _.toInteger(Infinity);
  11575. * // => 1.7976931348623157e+308
  11576. *
  11577. * _.toInteger('3.2');
  11578. * // => 3
  11579. */
  11580. function toInteger(value) {
  11581. var result = toFinite(value),
  11582. remainder = result % 1;
  11583. return result === result ? (remainder ? result - remainder : result) : 0;
  11584. }
  11585. /**
  11586. * Converts `value` to an integer suitable for use as the length of an
  11587. * array-like object.
  11588. *
  11589. * **Note:** This method is based on
  11590. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11591. *
  11592. * @static
  11593. * @memberOf _
  11594. * @since 4.0.0
  11595. * @category Lang
  11596. * @param {*} value The value to convert.
  11597. * @returns {number} Returns the converted integer.
  11598. * @example
  11599. *
  11600. * _.toLength(3.2);
  11601. * // => 3
  11602. *
  11603. * _.toLength(Number.MIN_VALUE);
  11604. * // => 0
  11605. *
  11606. * _.toLength(Infinity);
  11607. * // => 4294967295
  11608. *
  11609. * _.toLength('3.2');
  11610. * // => 3
  11611. */
  11612. function toLength(value) {
  11613. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11614. }
  11615. /**
  11616. * Converts `value` to a number.
  11617. *
  11618. * @static
  11619. * @memberOf _
  11620. * @since 4.0.0
  11621. * @category Lang
  11622. * @param {*} value The value to process.
  11623. * @returns {number} Returns the number.
  11624. * @example
  11625. *
  11626. * _.toNumber(3.2);
  11627. * // => 3.2
  11628. *
  11629. * _.toNumber(Number.MIN_VALUE);
  11630. * // => 5e-324
  11631. *
  11632. * _.toNumber(Infinity);
  11633. * // => Infinity
  11634. *
  11635. * _.toNumber('3.2');
  11636. * // => 3.2
  11637. */
  11638. function toNumber(value) {
  11639. if (typeof value == 'number') {
  11640. return value;
  11641. }
  11642. if (isSymbol(value)) {
  11643. return NAN;
  11644. }
  11645. if (isObject(value)) {
  11646. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11647. value = isObject(other) ? (other + '') : other;
  11648. }
  11649. if (typeof value != 'string') {
  11650. return value === 0 ? value : +value;
  11651. }
  11652. value = value.replace(reTrim, '');
  11653. var isBinary = reIsBinary.test(value);
  11654. return (isBinary || reIsOctal.test(value))
  11655. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11656. : (reIsBadHex.test(value) ? NAN : +value);
  11657. }
  11658. /**
  11659. * Converts `value` to a plain object flattening inherited enumerable string
  11660. * keyed properties of `value` to own properties of the plain object.
  11661. *
  11662. * @static
  11663. * @memberOf _
  11664. * @since 3.0.0
  11665. * @category Lang
  11666. * @param {*} value The value to convert.
  11667. * @returns {Object} Returns the converted plain object.
  11668. * @example
  11669. *
  11670. * function Foo() {
  11671. * this.b = 2;
  11672. * }
  11673. *
  11674. * Foo.prototype.c = 3;
  11675. *
  11676. * _.assign({ 'a': 1 }, new Foo);
  11677. * // => { 'a': 1, 'b': 2 }
  11678. *
  11679. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11680. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11681. */
  11682. function toPlainObject(value) {
  11683. return copyObject(value, keysIn(value));
  11684. }
  11685. /**
  11686. * Converts `value` to a safe integer. A safe integer can be compared and
  11687. * represented correctly.
  11688. *
  11689. * @static
  11690. * @memberOf _
  11691. * @since 4.0.0
  11692. * @category Lang
  11693. * @param {*} value The value to convert.
  11694. * @returns {number} Returns the converted integer.
  11695. * @example
  11696. *
  11697. * _.toSafeInteger(3.2);
  11698. * // => 3
  11699. *
  11700. * _.toSafeInteger(Number.MIN_VALUE);
  11701. * // => 0
  11702. *
  11703. * _.toSafeInteger(Infinity);
  11704. * // => 9007199254740991
  11705. *
  11706. * _.toSafeInteger('3.2');
  11707. * // => 3
  11708. */
  11709. function toSafeInteger(value) {
  11710. return value
  11711. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11712. : (value === 0 ? value : 0);
  11713. }
  11714. /**
  11715. * Converts `value` to a string. An empty string is returned for `null`
  11716. * and `undefined` values. The sign of `-0` is preserved.
  11717. *
  11718. * @static
  11719. * @memberOf _
  11720. * @since 4.0.0
  11721. * @category Lang
  11722. * @param {*} value The value to convert.
  11723. * @returns {string} Returns the converted string.
  11724. * @example
  11725. *
  11726. * _.toString(null);
  11727. * // => ''
  11728. *
  11729. * _.toString(-0);
  11730. * // => '-0'
  11731. *
  11732. * _.toString([1, 2, 3]);
  11733. * // => '1,2,3'
  11734. */
  11735. function toString(value) {
  11736. return value == null ? '' : baseToString(value);
  11737. }
  11738. /*------------------------------------------------------------------------*/
  11739. /**
  11740. * Assigns own enumerable string keyed properties of source objects to the
  11741. * destination object. Source objects are applied from left to right.
  11742. * Subsequent sources overwrite property assignments of previous sources.
  11743. *
  11744. * **Note:** This method mutates `object` and is loosely based on
  11745. * [`Object.assign`](https://mdn.io/Object/assign).
  11746. *
  11747. * @static
  11748. * @memberOf _
  11749. * @since 0.10.0
  11750. * @category Object
  11751. * @param {Object} object The destination object.
  11752. * @param {...Object} [sources] The source objects.
  11753. * @returns {Object} Returns `object`.
  11754. * @see _.assignIn
  11755. * @example
  11756. *
  11757. * function Foo() {
  11758. * this.a = 1;
  11759. * }
  11760. *
  11761. * function Bar() {
  11762. * this.c = 3;
  11763. * }
  11764. *
  11765. * Foo.prototype.b = 2;
  11766. * Bar.prototype.d = 4;
  11767. *
  11768. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11769. * // => { 'a': 1, 'c': 3 }
  11770. */
  11771. var assign = createAssigner(function(object, source) {
  11772. if (isPrototype(source) || isArrayLike(source)) {
  11773. copyObject(source, keys(source), object);
  11774. return;
  11775. }
  11776. for (var key in source) {
  11777. if (hasOwnProperty.call(source, key)) {
  11778. assignValue(object, key, source[key]);
  11779. }
  11780. }
  11781. });
  11782. /**
  11783. * This method is like `_.assign` except that it iterates over own and
  11784. * inherited source properties.
  11785. *
  11786. * **Note:** This method mutates `object`.
  11787. *
  11788. * @static
  11789. * @memberOf _
  11790. * @since 4.0.0
  11791. * @alias extend
  11792. * @category Object
  11793. * @param {Object} object The destination object.
  11794. * @param {...Object} [sources] The source objects.
  11795. * @returns {Object} Returns `object`.
  11796. * @see _.assign
  11797. * @example
  11798. *
  11799. * function Foo() {
  11800. * this.a = 1;
  11801. * }
  11802. *
  11803. * function Bar() {
  11804. * this.c = 3;
  11805. * }
  11806. *
  11807. * Foo.prototype.b = 2;
  11808. * Bar.prototype.d = 4;
  11809. *
  11810. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11811. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11812. */
  11813. var assignIn = createAssigner(function(object, source) {
  11814. copyObject(source, keysIn(source), object);
  11815. });
  11816. /**
  11817. * This method is like `_.assignIn` except that it accepts `customizer`
  11818. * which is invoked to produce the assigned values. If `customizer` returns
  11819. * `undefined`, assignment is handled by the method instead. The `customizer`
  11820. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11821. *
  11822. * **Note:** This method mutates `object`.
  11823. *
  11824. * @static
  11825. * @memberOf _
  11826. * @since 4.0.0
  11827. * @alias extendWith
  11828. * @category Object
  11829. * @param {Object} object The destination object.
  11830. * @param {...Object} sources The source objects.
  11831. * @param {Function} [customizer] The function to customize assigned values.
  11832. * @returns {Object} Returns `object`.
  11833. * @see _.assignWith
  11834. * @example
  11835. *
  11836. * function customizer(objValue, srcValue) {
  11837. * return _.isUndefined(objValue) ? srcValue : objValue;
  11838. * }
  11839. *
  11840. * var defaults = _.partialRight(_.assignInWith, customizer);
  11841. *
  11842. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11843. * // => { 'a': 1, 'b': 2 }
  11844. */
  11845. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11846. copyObject(source, keysIn(source), object, customizer);
  11847. });
  11848. /**
  11849. * This method is like `_.assign` except that it accepts `customizer`
  11850. * which is invoked to produce the assigned values. If `customizer` returns
  11851. * `undefined`, assignment is handled by the method instead. The `customizer`
  11852. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11853. *
  11854. * **Note:** This method mutates `object`.
  11855. *
  11856. * @static
  11857. * @memberOf _
  11858. * @since 4.0.0
  11859. * @category Object
  11860. * @param {Object} object The destination object.
  11861. * @param {...Object} sources The source objects.
  11862. * @param {Function} [customizer] The function to customize assigned values.
  11863. * @returns {Object} Returns `object`.
  11864. * @see _.assignInWith
  11865. * @example
  11866. *
  11867. * function customizer(objValue, srcValue) {
  11868. * return _.isUndefined(objValue) ? srcValue : objValue;
  11869. * }
  11870. *
  11871. * var defaults = _.partialRight(_.assignWith, customizer);
  11872. *
  11873. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11874. * // => { 'a': 1, 'b': 2 }
  11875. */
  11876. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11877. copyObject(source, keys(source), object, customizer);
  11878. });
  11879. /**
  11880. * Creates an array of values corresponding to `paths` of `object`.
  11881. *
  11882. * @static
  11883. * @memberOf _
  11884. * @since 1.0.0
  11885. * @category Object
  11886. * @param {Object} object The object to iterate over.
  11887. * @param {...(string|string[])} [paths] The property paths to pick.
  11888. * @returns {Array} Returns the picked values.
  11889. * @example
  11890. *
  11891. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11892. *
  11893. * _.at(object, ['a[0].b.c', 'a[1]']);
  11894. * // => [3, 4]
  11895. */
  11896. var at = flatRest(baseAt);
  11897. /**
  11898. * Creates an object that inherits from the `prototype` object. If a
  11899. * `properties` object is given, its own enumerable string keyed properties
  11900. * are assigned to the created object.
  11901. *
  11902. * @static
  11903. * @memberOf _
  11904. * @since 2.3.0
  11905. * @category Object
  11906. * @param {Object} prototype The object to inherit from.
  11907. * @param {Object} [properties] The properties to assign to the object.
  11908. * @returns {Object} Returns the new object.
  11909. * @example
  11910. *
  11911. * function Shape() {
  11912. * this.x = 0;
  11913. * this.y = 0;
  11914. * }
  11915. *
  11916. * function Circle() {
  11917. * Shape.call(this);
  11918. * }
  11919. *
  11920. * Circle.prototype = _.create(Shape.prototype, {
  11921. * 'constructor': Circle
  11922. * });
  11923. *
  11924. * var circle = new Circle;
  11925. * circle instanceof Circle;
  11926. * // => true
  11927. *
  11928. * circle instanceof Shape;
  11929. * // => true
  11930. */
  11931. function create(prototype, properties) {
  11932. var result = baseCreate(prototype);
  11933. return properties == null ? result : baseAssign(result, properties);
  11934. }
  11935. /**
  11936. * Assigns own and inherited enumerable string keyed properties of source
  11937. * objects to the destination object for all destination properties that
  11938. * resolve to `undefined`. Source objects are applied from left to right.
  11939. * Once a property is set, additional values of the same property are ignored.
  11940. *
  11941. * **Note:** This method mutates `object`.
  11942. *
  11943. * @static
  11944. * @since 0.1.0
  11945. * @memberOf _
  11946. * @category Object
  11947. * @param {Object} object The destination object.
  11948. * @param {...Object} [sources] The source objects.
  11949. * @returns {Object} Returns `object`.
  11950. * @see _.defaultsDeep
  11951. * @example
  11952. *
  11953. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11954. * // => { 'a': 1, 'b': 2 }
  11955. */
  11956. var defaults = baseRest(function(object, sources) {
  11957. object = Object(object);
  11958. var index = -1;
  11959. var length = sources.length;
  11960. var guard = length > 2 ? sources[2] : undefined;
  11961. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11962. length = 1;
  11963. }
  11964. while (++index < length) {
  11965. var source = sources[index];
  11966. var props = keysIn(source);
  11967. var propsIndex = -1;
  11968. var propsLength = props.length;
  11969. while (++propsIndex < propsLength) {
  11970. var key = props[propsIndex];
  11971. var value = object[key];
  11972. if (value === undefined ||
  11973. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11974. object[key] = source[key];
  11975. }
  11976. }
  11977. }
  11978. return object;
  11979. });
  11980. /**
  11981. * This method is like `_.defaults` except that it recursively assigns
  11982. * default properties.
  11983. *
  11984. * **Note:** This method mutates `object`.
  11985. *
  11986. * @static
  11987. * @memberOf _
  11988. * @since 3.10.0
  11989. * @category Object
  11990. * @param {Object} object The destination object.
  11991. * @param {...Object} [sources] The source objects.
  11992. * @returns {Object} Returns `object`.
  11993. * @see _.defaults
  11994. * @example
  11995. *
  11996. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11997. * // => { 'a': { 'b': 2, 'c': 3 } }
  11998. */
  11999. var defaultsDeep = baseRest(function(args) {
  12000. args.push(undefined, customDefaultsMerge);
  12001. return apply(mergeWith, undefined, args);
  12002. });
  12003. /**
  12004. * This method is like `_.find` except that it returns the key of the first
  12005. * element `predicate` returns truthy for instead of the element itself.
  12006. *
  12007. * @static
  12008. * @memberOf _
  12009. * @since 1.1.0
  12010. * @category Object
  12011. * @param {Object} object The object to inspect.
  12012. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12013. * @returns {string|undefined} Returns the key of the matched element,
  12014. * else `undefined`.
  12015. * @example
  12016. *
  12017. * var users = {
  12018. * 'barney': { 'age': 36, 'active': true },
  12019. * 'fred': { 'age': 40, 'active': false },
  12020. * 'pebbles': { 'age': 1, 'active': true }
  12021. * };
  12022. *
  12023. * _.findKey(users, function(o) { return o.age < 40; });
  12024. * // => 'barney' (iteration order is not guaranteed)
  12025. *
  12026. * // The `_.matches` iteratee shorthand.
  12027. * _.findKey(users, { 'age': 1, 'active': true });
  12028. * // => 'pebbles'
  12029. *
  12030. * // The `_.matchesProperty` iteratee shorthand.
  12031. * _.findKey(users, ['active', false]);
  12032. * // => 'fred'
  12033. *
  12034. * // The `_.property` iteratee shorthand.
  12035. * _.findKey(users, 'active');
  12036. * // => 'barney'
  12037. */
  12038. function findKey(object, predicate) {
  12039. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12040. }
  12041. /**
  12042. * This method is like `_.findKey` except that it iterates over elements of
  12043. * a collection in the opposite order.
  12044. *
  12045. * @static
  12046. * @memberOf _
  12047. * @since 2.0.0
  12048. * @category Object
  12049. * @param {Object} object The object to inspect.
  12050. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12051. * @returns {string|undefined} Returns the key of the matched element,
  12052. * else `undefined`.
  12053. * @example
  12054. *
  12055. * var users = {
  12056. * 'barney': { 'age': 36, 'active': true },
  12057. * 'fred': { 'age': 40, 'active': false },
  12058. * 'pebbles': { 'age': 1, 'active': true }
  12059. * };
  12060. *
  12061. * _.findLastKey(users, function(o) { return o.age < 40; });
  12062. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12063. *
  12064. * // The `_.matches` iteratee shorthand.
  12065. * _.findLastKey(users, { 'age': 36, 'active': true });
  12066. * // => 'barney'
  12067. *
  12068. * // The `_.matchesProperty` iteratee shorthand.
  12069. * _.findLastKey(users, ['active', false]);
  12070. * // => 'fred'
  12071. *
  12072. * // The `_.property` iteratee shorthand.
  12073. * _.findLastKey(users, 'active');
  12074. * // => 'pebbles'
  12075. */
  12076. function findLastKey(object, predicate) {
  12077. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12078. }
  12079. /**
  12080. * Iterates over own and inherited enumerable string keyed properties of an
  12081. * object and invokes `iteratee` for each property. The iteratee is invoked
  12082. * with three arguments: (value, key, object). Iteratee functions may exit
  12083. * iteration early by explicitly returning `false`.
  12084. *
  12085. * @static
  12086. * @memberOf _
  12087. * @since 0.3.0
  12088. * @category Object
  12089. * @param {Object} object The object to iterate over.
  12090. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12091. * @returns {Object} Returns `object`.
  12092. * @see _.forInRight
  12093. * @example
  12094. *
  12095. * function Foo() {
  12096. * this.a = 1;
  12097. * this.b = 2;
  12098. * }
  12099. *
  12100. * Foo.prototype.c = 3;
  12101. *
  12102. * _.forIn(new Foo, function(value, key) {
  12103. * console.log(key);
  12104. * });
  12105. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12106. */
  12107. function forIn(object, iteratee) {
  12108. return object == null
  12109. ? object
  12110. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12111. }
  12112. /**
  12113. * This method is like `_.forIn` except that it iterates over properties of
  12114. * `object` in the opposite order.
  12115. *
  12116. * @static
  12117. * @memberOf _
  12118. * @since 2.0.0
  12119. * @category Object
  12120. * @param {Object} object The object to iterate over.
  12121. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12122. * @returns {Object} Returns `object`.
  12123. * @see _.forIn
  12124. * @example
  12125. *
  12126. * function Foo() {
  12127. * this.a = 1;
  12128. * this.b = 2;
  12129. * }
  12130. *
  12131. * Foo.prototype.c = 3;
  12132. *
  12133. * _.forInRight(new Foo, function(value, key) {
  12134. * console.log(key);
  12135. * });
  12136. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12137. */
  12138. function forInRight(object, iteratee) {
  12139. return object == null
  12140. ? object
  12141. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12142. }
  12143. /**
  12144. * Iterates over own enumerable string keyed properties of an object and
  12145. * invokes `iteratee` for each property. The iteratee is invoked with three
  12146. * arguments: (value, key, object). Iteratee functions may exit iteration
  12147. * early by explicitly returning `false`.
  12148. *
  12149. * @static
  12150. * @memberOf _
  12151. * @since 0.3.0
  12152. * @category Object
  12153. * @param {Object} object The object to iterate over.
  12154. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12155. * @returns {Object} Returns `object`.
  12156. * @see _.forOwnRight
  12157. * @example
  12158. *
  12159. * function Foo() {
  12160. * this.a = 1;
  12161. * this.b = 2;
  12162. * }
  12163. *
  12164. * Foo.prototype.c = 3;
  12165. *
  12166. * _.forOwn(new Foo, function(value, key) {
  12167. * console.log(key);
  12168. * });
  12169. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12170. */
  12171. function forOwn(object, iteratee) {
  12172. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12173. }
  12174. /**
  12175. * This method is like `_.forOwn` except that it iterates over properties of
  12176. * `object` in the opposite order.
  12177. *
  12178. * @static
  12179. * @memberOf _
  12180. * @since 2.0.0
  12181. * @category Object
  12182. * @param {Object} object The object to iterate over.
  12183. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12184. * @returns {Object} Returns `object`.
  12185. * @see _.forOwn
  12186. * @example
  12187. *
  12188. * function Foo() {
  12189. * this.a = 1;
  12190. * this.b = 2;
  12191. * }
  12192. *
  12193. * Foo.prototype.c = 3;
  12194. *
  12195. * _.forOwnRight(new Foo, function(value, key) {
  12196. * console.log(key);
  12197. * });
  12198. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12199. */
  12200. function forOwnRight(object, iteratee) {
  12201. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12202. }
  12203. /**
  12204. * Creates an array of function property names from own enumerable properties
  12205. * of `object`.
  12206. *
  12207. * @static
  12208. * @since 0.1.0
  12209. * @memberOf _
  12210. * @category Object
  12211. * @param {Object} object The object to inspect.
  12212. * @returns {Array} Returns the function names.
  12213. * @see _.functionsIn
  12214. * @example
  12215. *
  12216. * function Foo() {
  12217. * this.a = _.constant('a');
  12218. * this.b = _.constant('b');
  12219. * }
  12220. *
  12221. * Foo.prototype.c = _.constant('c');
  12222. *
  12223. * _.functions(new Foo);
  12224. * // => ['a', 'b']
  12225. */
  12226. function functions(object) {
  12227. return object == null ? [] : baseFunctions(object, keys(object));
  12228. }
  12229. /**
  12230. * Creates an array of function property names from own and inherited
  12231. * enumerable properties of `object`.
  12232. *
  12233. * @static
  12234. * @memberOf _
  12235. * @since 4.0.0
  12236. * @category Object
  12237. * @param {Object} object The object to inspect.
  12238. * @returns {Array} Returns the function names.
  12239. * @see _.functions
  12240. * @example
  12241. *
  12242. * function Foo() {
  12243. * this.a = _.constant('a');
  12244. * this.b = _.constant('b');
  12245. * }
  12246. *
  12247. * Foo.prototype.c = _.constant('c');
  12248. *
  12249. * _.functionsIn(new Foo);
  12250. * // => ['a', 'b', 'c']
  12251. */
  12252. function functionsIn(object) {
  12253. return object == null ? [] : baseFunctions(object, keysIn(object));
  12254. }
  12255. /**
  12256. * Gets the value at `path` of `object`. If the resolved value is
  12257. * `undefined`, the `defaultValue` is returned in its place.
  12258. *
  12259. * @static
  12260. * @memberOf _
  12261. * @since 3.7.0
  12262. * @category Object
  12263. * @param {Object} object The object to query.
  12264. * @param {Array|string} path The path of the property to get.
  12265. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12266. * @returns {*} Returns the resolved value.
  12267. * @example
  12268. *
  12269. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12270. *
  12271. * _.get(object, 'a[0].b.c');
  12272. * // => 3
  12273. *
  12274. * _.get(object, ['a', '0', 'b', 'c']);
  12275. * // => 3
  12276. *
  12277. * _.get(object, 'a.b.c', 'default');
  12278. * // => 'default'
  12279. */
  12280. function get(object, path, defaultValue) {
  12281. var result = object == null ? undefined : baseGet(object, path);
  12282. return result === undefined ? defaultValue : result;
  12283. }
  12284. /**
  12285. * Checks if `path` is a direct property of `object`.
  12286. *
  12287. * @static
  12288. * @since 0.1.0
  12289. * @memberOf _
  12290. * @category Object
  12291. * @param {Object} object The object to query.
  12292. * @param {Array|string} path The path to check.
  12293. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12294. * @example
  12295. *
  12296. * var object = { 'a': { 'b': 2 } };
  12297. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12298. *
  12299. * _.has(object, 'a');
  12300. * // => true
  12301. *
  12302. * _.has(object, 'a.b');
  12303. * // => true
  12304. *
  12305. * _.has(object, ['a', 'b']);
  12306. * // => true
  12307. *
  12308. * _.has(other, 'a');
  12309. * // => false
  12310. */
  12311. function has(object, path) {
  12312. return object != null && hasPath(object, path, baseHas);
  12313. }
  12314. /**
  12315. * Checks if `path` is a direct or inherited property of `object`.
  12316. *
  12317. * @static
  12318. * @memberOf _
  12319. * @since 4.0.0
  12320. * @category Object
  12321. * @param {Object} object The object to query.
  12322. * @param {Array|string} path The path to check.
  12323. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12324. * @example
  12325. *
  12326. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12327. *
  12328. * _.hasIn(object, 'a');
  12329. * // => true
  12330. *
  12331. * _.hasIn(object, 'a.b');
  12332. * // => true
  12333. *
  12334. * _.hasIn(object, ['a', 'b']);
  12335. * // => true
  12336. *
  12337. * _.hasIn(object, 'b');
  12338. * // => false
  12339. */
  12340. function hasIn(object, path) {
  12341. return object != null && hasPath(object, path, baseHasIn);
  12342. }
  12343. /**
  12344. * Creates an object composed of the inverted keys and values of `object`.
  12345. * If `object` contains duplicate values, subsequent values overwrite
  12346. * property assignments of previous values.
  12347. *
  12348. * @static
  12349. * @memberOf _
  12350. * @since 0.7.0
  12351. * @category Object
  12352. * @param {Object} object The object to invert.
  12353. * @returns {Object} Returns the new inverted object.
  12354. * @example
  12355. *
  12356. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12357. *
  12358. * _.invert(object);
  12359. * // => { '1': 'c', '2': 'b' }
  12360. */
  12361. var invert = createInverter(function(result, value, key) {
  12362. if (value != null &&
  12363. typeof value.toString != 'function') {
  12364. value = nativeObjectToString.call(value);
  12365. }
  12366. result[value] = key;
  12367. }, constant(identity));
  12368. /**
  12369. * This method is like `_.invert` except that the inverted object is generated
  12370. * from the results of running each element of `object` thru `iteratee`. The
  12371. * corresponding inverted value of each inverted key is an array of keys
  12372. * responsible for generating the inverted value. The iteratee is invoked
  12373. * with one argument: (value).
  12374. *
  12375. * @static
  12376. * @memberOf _
  12377. * @since 4.1.0
  12378. * @category Object
  12379. * @param {Object} object The object to invert.
  12380. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12381. * @returns {Object} Returns the new inverted object.
  12382. * @example
  12383. *
  12384. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12385. *
  12386. * _.invertBy(object);
  12387. * // => { '1': ['a', 'c'], '2': ['b'] }
  12388. *
  12389. * _.invertBy(object, function(value) {
  12390. * return 'group' + value;
  12391. * });
  12392. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12393. */
  12394. var invertBy = createInverter(function(result, value, key) {
  12395. if (value != null &&
  12396. typeof value.toString != 'function') {
  12397. value = nativeObjectToString.call(value);
  12398. }
  12399. if (hasOwnProperty.call(result, value)) {
  12400. result[value].push(key);
  12401. } else {
  12402. result[value] = [key];
  12403. }
  12404. }, getIteratee);
  12405. /**
  12406. * Invokes the method at `path` of `object`.
  12407. *
  12408. * @static
  12409. * @memberOf _
  12410. * @since 4.0.0
  12411. * @category Object
  12412. * @param {Object} object The object to query.
  12413. * @param {Array|string} path The path of the method to invoke.
  12414. * @param {...*} [args] The arguments to invoke the method with.
  12415. * @returns {*} Returns the result of the invoked method.
  12416. * @example
  12417. *
  12418. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12419. *
  12420. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12421. * // => [2, 3]
  12422. */
  12423. var invoke = baseRest(baseInvoke);
  12424. /**
  12425. * Creates an array of the own enumerable property names of `object`.
  12426. *
  12427. * **Note:** Non-object values are coerced to objects. See the
  12428. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12429. * for more details.
  12430. *
  12431. * @static
  12432. * @since 0.1.0
  12433. * @memberOf _
  12434. * @category Object
  12435. * @param {Object} object The object to query.
  12436. * @returns {Array} Returns the array of property names.
  12437. * @example
  12438. *
  12439. * function Foo() {
  12440. * this.a = 1;
  12441. * this.b = 2;
  12442. * }
  12443. *
  12444. * Foo.prototype.c = 3;
  12445. *
  12446. * _.keys(new Foo);
  12447. * // => ['a', 'b'] (iteration order is not guaranteed)
  12448. *
  12449. * _.keys('hi');
  12450. * // => ['0', '1']
  12451. */
  12452. function keys(object) {
  12453. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12454. }
  12455. /**
  12456. * Creates an array of the own and inherited enumerable property names of `object`.
  12457. *
  12458. * **Note:** Non-object values are coerced to objects.
  12459. *
  12460. * @static
  12461. * @memberOf _
  12462. * @since 3.0.0
  12463. * @category Object
  12464. * @param {Object} object The object to query.
  12465. * @returns {Array} Returns the array of property names.
  12466. * @example
  12467. *
  12468. * function Foo() {
  12469. * this.a = 1;
  12470. * this.b = 2;
  12471. * }
  12472. *
  12473. * Foo.prototype.c = 3;
  12474. *
  12475. * _.keysIn(new Foo);
  12476. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12477. */
  12478. function keysIn(object) {
  12479. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12480. }
  12481. /**
  12482. * The opposite of `_.mapValues`; this method creates an object with the
  12483. * same values as `object` and keys generated by running each own enumerable
  12484. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12485. * with three arguments: (value, key, object).
  12486. *
  12487. * @static
  12488. * @memberOf _
  12489. * @since 3.8.0
  12490. * @category Object
  12491. * @param {Object} object The object to iterate over.
  12492. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12493. * @returns {Object} Returns the new mapped object.
  12494. * @see _.mapValues
  12495. * @example
  12496. *
  12497. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12498. * return key + value;
  12499. * });
  12500. * // => { 'a1': 1, 'b2': 2 }
  12501. */
  12502. function mapKeys(object, iteratee) {
  12503. var result = {};
  12504. iteratee = getIteratee(iteratee, 3);
  12505. baseForOwn(object, function(value, key, object) {
  12506. baseAssignValue(result, iteratee(value, key, object), value);
  12507. });
  12508. return result;
  12509. }
  12510. /**
  12511. * Creates an object with the same keys as `object` and values generated
  12512. * by running each own enumerable string keyed property of `object` thru
  12513. * `iteratee`. The iteratee is invoked with three arguments:
  12514. * (value, key, object).
  12515. *
  12516. * @static
  12517. * @memberOf _
  12518. * @since 2.4.0
  12519. * @category Object
  12520. * @param {Object} object The object to iterate over.
  12521. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12522. * @returns {Object} Returns the new mapped object.
  12523. * @see _.mapKeys
  12524. * @example
  12525. *
  12526. * var users = {
  12527. * 'fred': { 'user': 'fred', 'age': 40 },
  12528. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12529. * };
  12530. *
  12531. * _.mapValues(users, function(o) { return o.age; });
  12532. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12533. *
  12534. * // The `_.property` iteratee shorthand.
  12535. * _.mapValues(users, 'age');
  12536. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12537. */
  12538. function mapValues(object, iteratee) {
  12539. var result = {};
  12540. iteratee = getIteratee(iteratee, 3);
  12541. baseForOwn(object, function(value, key, object) {
  12542. baseAssignValue(result, key, iteratee(value, key, object));
  12543. });
  12544. return result;
  12545. }
  12546. /**
  12547. * This method is like `_.assign` except that it recursively merges own and
  12548. * inherited enumerable string keyed properties of source objects into the
  12549. * destination object. Source properties that resolve to `undefined` are
  12550. * skipped if a destination value exists. Array and plain object properties
  12551. * are merged recursively. Other objects and value types are overridden by
  12552. * assignment. Source objects are applied from left to right. Subsequent
  12553. * sources overwrite property assignments of previous sources.
  12554. *
  12555. * **Note:** This method mutates `object`.
  12556. *
  12557. * @static
  12558. * @memberOf _
  12559. * @since 0.5.0
  12560. * @category Object
  12561. * @param {Object} object The destination object.
  12562. * @param {...Object} [sources] The source objects.
  12563. * @returns {Object} Returns `object`.
  12564. * @example
  12565. *
  12566. * var object = {
  12567. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12568. * };
  12569. *
  12570. * var other = {
  12571. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12572. * };
  12573. *
  12574. * _.merge(object, other);
  12575. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12576. */
  12577. var merge = createAssigner(function(object, source, srcIndex) {
  12578. baseMerge(object, source, srcIndex);
  12579. });
  12580. /**
  12581. * This method is like `_.merge` except that it accepts `customizer` which
  12582. * is invoked to produce the merged values of the destination and source
  12583. * properties. If `customizer` returns `undefined`, merging is handled by the
  12584. * method instead. The `customizer` is invoked with six arguments:
  12585. * (objValue, srcValue, key, object, source, stack).
  12586. *
  12587. * **Note:** This method mutates `object`.
  12588. *
  12589. * @static
  12590. * @memberOf _
  12591. * @since 4.0.0
  12592. * @category Object
  12593. * @param {Object} object The destination object.
  12594. * @param {...Object} sources The source objects.
  12595. * @param {Function} customizer The function to customize assigned values.
  12596. * @returns {Object} Returns `object`.
  12597. * @example
  12598. *
  12599. * function customizer(objValue, srcValue) {
  12600. * if (_.isArray(objValue)) {
  12601. * return objValue.concat(srcValue);
  12602. * }
  12603. * }
  12604. *
  12605. * var object = { 'a': [1], 'b': [2] };
  12606. * var other = { 'a': [3], 'b': [4] };
  12607. *
  12608. * _.mergeWith(object, other, customizer);
  12609. * // => { 'a': [1, 3], 'b': [2, 4] }
  12610. */
  12611. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12612. baseMerge(object, source, srcIndex, customizer);
  12613. });
  12614. /**
  12615. * The opposite of `_.pick`; this method creates an object composed of the
  12616. * own and inherited enumerable property paths of `object` that are not omitted.
  12617. *
  12618. * **Note:** This method is considerably slower than `_.pick`.
  12619. *
  12620. * @static
  12621. * @since 0.1.0
  12622. * @memberOf _
  12623. * @category Object
  12624. * @param {Object} object The source object.
  12625. * @param {...(string|string[])} [paths] The property paths to omit.
  12626. * @returns {Object} Returns the new object.
  12627. * @example
  12628. *
  12629. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12630. *
  12631. * _.omit(object, ['a', 'c']);
  12632. * // => { 'b': '2' }
  12633. */
  12634. var omit = flatRest(function(object, paths) {
  12635. var result = {};
  12636. if (object == null) {
  12637. return result;
  12638. }
  12639. var isDeep = false;
  12640. paths = arrayMap(paths, function(path) {
  12641. path = castPath(path, object);
  12642. isDeep || (isDeep = path.length > 1);
  12643. return path;
  12644. });
  12645. copyObject(object, getAllKeysIn(object), result);
  12646. if (isDeep) {
  12647. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12648. }
  12649. var length = paths.length;
  12650. while (length--) {
  12651. baseUnset(result, paths[length]);
  12652. }
  12653. return result;
  12654. });
  12655. /**
  12656. * The opposite of `_.pickBy`; this method creates an object composed of
  12657. * the own and inherited enumerable string keyed properties of `object` that
  12658. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12659. * arguments: (value, key).
  12660. *
  12661. * @static
  12662. * @memberOf _
  12663. * @since 4.0.0
  12664. * @category Object
  12665. * @param {Object} object The source object.
  12666. * @param {Function} [predicate=_.identity] The function invoked per property.
  12667. * @returns {Object} Returns the new object.
  12668. * @example
  12669. *
  12670. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12671. *
  12672. * _.omitBy(object, _.isNumber);
  12673. * // => { 'b': '2' }
  12674. */
  12675. function omitBy(object, predicate) {
  12676. return pickBy(object, negate(getIteratee(predicate)));
  12677. }
  12678. /**
  12679. * Creates an object composed of the picked `object` properties.
  12680. *
  12681. * @static
  12682. * @since 0.1.0
  12683. * @memberOf _
  12684. * @category Object
  12685. * @param {Object} object The source object.
  12686. * @param {...(string|string[])} [paths] The property paths to pick.
  12687. * @returns {Object} Returns the new object.
  12688. * @example
  12689. *
  12690. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12691. *
  12692. * _.pick(object, ['a', 'c']);
  12693. * // => { 'a': 1, 'c': 3 }
  12694. */
  12695. var pick = flatRest(function(object, paths) {
  12696. return object == null ? {} : basePick(object, paths);
  12697. });
  12698. /**
  12699. * Creates an object composed of the `object` properties `predicate` returns
  12700. * truthy for. The predicate is invoked with two arguments: (value, key).
  12701. *
  12702. * @static
  12703. * @memberOf _
  12704. * @since 4.0.0
  12705. * @category Object
  12706. * @param {Object} object The source object.
  12707. * @param {Function} [predicate=_.identity] The function invoked per property.
  12708. * @returns {Object} Returns the new object.
  12709. * @example
  12710. *
  12711. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12712. *
  12713. * _.pickBy(object, _.isNumber);
  12714. * // => { 'a': 1, 'c': 3 }
  12715. */
  12716. function pickBy(object, predicate) {
  12717. if (object == null) {
  12718. return {};
  12719. }
  12720. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12721. return [prop];
  12722. });
  12723. predicate = getIteratee(predicate);
  12724. return basePickBy(object, props, function(value, path) {
  12725. return predicate(value, path[0]);
  12726. });
  12727. }
  12728. /**
  12729. * This method is like `_.get` except that if the resolved value is a
  12730. * function it's invoked with the `this` binding of its parent object and
  12731. * its result is returned.
  12732. *
  12733. * @static
  12734. * @since 0.1.0
  12735. * @memberOf _
  12736. * @category Object
  12737. * @param {Object} object The object to query.
  12738. * @param {Array|string} path The path of the property to resolve.
  12739. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12740. * @returns {*} Returns the resolved value.
  12741. * @example
  12742. *
  12743. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12744. *
  12745. * _.result(object, 'a[0].b.c1');
  12746. * // => 3
  12747. *
  12748. * _.result(object, 'a[0].b.c2');
  12749. * // => 4
  12750. *
  12751. * _.result(object, 'a[0].b.c3', 'default');
  12752. * // => 'default'
  12753. *
  12754. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12755. * // => 'default'
  12756. */
  12757. function result(object, path, defaultValue) {
  12758. path = castPath(path, object);
  12759. var index = -1,
  12760. length = path.length;
  12761. // Ensure the loop is entered when path is empty.
  12762. if (!length) {
  12763. length = 1;
  12764. object = undefined;
  12765. }
  12766. while (++index < length) {
  12767. var value = object == null ? undefined : object[toKey(path[index])];
  12768. if (value === undefined) {
  12769. index = length;
  12770. value = defaultValue;
  12771. }
  12772. object = isFunction(value) ? value.call(object) : value;
  12773. }
  12774. return object;
  12775. }
  12776. /**
  12777. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12778. * it's created. Arrays are created for missing index properties while objects
  12779. * are created for all other missing properties. Use `_.setWith` to customize
  12780. * `path` creation.
  12781. *
  12782. * **Note:** This method mutates `object`.
  12783. *
  12784. * @static
  12785. * @memberOf _
  12786. * @since 3.7.0
  12787. * @category Object
  12788. * @param {Object} object The object to modify.
  12789. * @param {Array|string} path The path of the property to set.
  12790. * @param {*} value The value to set.
  12791. * @returns {Object} Returns `object`.
  12792. * @example
  12793. *
  12794. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12795. *
  12796. * _.set(object, 'a[0].b.c', 4);
  12797. * console.log(object.a[0].b.c);
  12798. * // => 4
  12799. *
  12800. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12801. * console.log(object.x[0].y.z);
  12802. * // => 5
  12803. */
  12804. function set(object, path, value) {
  12805. return object == null ? object : baseSet(object, path, value);
  12806. }
  12807. /**
  12808. * This method is like `_.set` except that it accepts `customizer` which is
  12809. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12810. * path creation is handled by the method instead. The `customizer` is invoked
  12811. * with three arguments: (nsValue, key, nsObject).
  12812. *
  12813. * **Note:** This method mutates `object`.
  12814. *
  12815. * @static
  12816. * @memberOf _
  12817. * @since 4.0.0
  12818. * @category Object
  12819. * @param {Object} object The object to modify.
  12820. * @param {Array|string} path The path of the property to set.
  12821. * @param {*} value The value to set.
  12822. * @param {Function} [customizer] The function to customize assigned values.
  12823. * @returns {Object} Returns `object`.
  12824. * @example
  12825. *
  12826. * var object = {};
  12827. *
  12828. * _.setWith(object, '[0][1]', 'a', Object);
  12829. * // => { '0': { '1': 'a' } }
  12830. */
  12831. function setWith(object, path, value, customizer) {
  12832. customizer = typeof customizer == 'function' ? customizer : undefined;
  12833. return object == null ? object : baseSet(object, path, value, customizer);
  12834. }
  12835. /**
  12836. * Creates an array of own enumerable string keyed-value pairs for `object`
  12837. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12838. * entries are returned.
  12839. *
  12840. * @static
  12841. * @memberOf _
  12842. * @since 4.0.0
  12843. * @alias entries
  12844. * @category Object
  12845. * @param {Object} object The object to query.
  12846. * @returns {Array} Returns the key-value pairs.
  12847. * @example
  12848. *
  12849. * function Foo() {
  12850. * this.a = 1;
  12851. * this.b = 2;
  12852. * }
  12853. *
  12854. * Foo.prototype.c = 3;
  12855. *
  12856. * _.toPairs(new Foo);
  12857. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12858. */
  12859. var toPairs = createToPairs(keys);
  12860. /**
  12861. * Creates an array of own and inherited enumerable string keyed-value pairs
  12862. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12863. * or set, its entries are returned.
  12864. *
  12865. * @static
  12866. * @memberOf _
  12867. * @since 4.0.0
  12868. * @alias entriesIn
  12869. * @category Object
  12870. * @param {Object} object The object to query.
  12871. * @returns {Array} Returns the key-value pairs.
  12872. * @example
  12873. *
  12874. * function Foo() {
  12875. * this.a = 1;
  12876. * this.b = 2;
  12877. * }
  12878. *
  12879. * Foo.prototype.c = 3;
  12880. *
  12881. * _.toPairsIn(new Foo);
  12882. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12883. */
  12884. var toPairsIn = createToPairs(keysIn);
  12885. /**
  12886. * An alternative to `_.reduce`; this method transforms `object` to a new
  12887. * `accumulator` object which is the result of running each of its own
  12888. * enumerable string keyed properties thru `iteratee`, with each invocation
  12889. * potentially mutating the `accumulator` object. If `accumulator` is not
  12890. * provided, a new object with the same `[[Prototype]]` will be used. The
  12891. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12892. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12893. *
  12894. * @static
  12895. * @memberOf _
  12896. * @since 1.3.0
  12897. * @category Object
  12898. * @param {Object} object The object to iterate over.
  12899. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12900. * @param {*} [accumulator] The custom accumulator value.
  12901. * @returns {*} Returns the accumulated value.
  12902. * @example
  12903. *
  12904. * _.transform([2, 3, 4], function(result, n) {
  12905. * result.push(n *= n);
  12906. * return n % 2 == 0;
  12907. * }, []);
  12908. * // => [4, 9]
  12909. *
  12910. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12911. * (result[value] || (result[value] = [])).push(key);
  12912. * }, {});
  12913. * // => { '1': ['a', 'c'], '2': ['b'] }
  12914. */
  12915. function transform(object, iteratee, accumulator) {
  12916. var isArr = isArray(object),
  12917. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12918. iteratee = getIteratee(iteratee, 4);
  12919. if (accumulator == null) {
  12920. var Ctor = object && object.constructor;
  12921. if (isArrLike) {
  12922. accumulator = isArr ? new Ctor : [];
  12923. }
  12924. else if (isObject(object)) {
  12925. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12926. }
  12927. else {
  12928. accumulator = {};
  12929. }
  12930. }
  12931. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12932. return iteratee(accumulator, value, index, object);
  12933. });
  12934. return accumulator;
  12935. }
  12936. /**
  12937. * Removes the property at `path` of `object`.
  12938. *
  12939. * **Note:** This method mutates `object`.
  12940. *
  12941. * @static
  12942. * @memberOf _
  12943. * @since 4.0.0
  12944. * @category Object
  12945. * @param {Object} object The object to modify.
  12946. * @param {Array|string} path The path of the property to unset.
  12947. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12948. * @example
  12949. *
  12950. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12951. * _.unset(object, 'a[0].b.c');
  12952. * // => true
  12953. *
  12954. * console.log(object);
  12955. * // => { 'a': [{ 'b': {} }] };
  12956. *
  12957. * _.unset(object, ['a', '0', 'b', 'c']);
  12958. * // => true
  12959. *
  12960. * console.log(object);
  12961. * // => { 'a': [{ 'b': {} }] };
  12962. */
  12963. function unset(object, path) {
  12964. return object == null ? true : baseUnset(object, path);
  12965. }
  12966. /**
  12967. * This method is like `_.set` except that accepts `updater` to produce the
  12968. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12969. * is invoked with one argument: (value).
  12970. *
  12971. * **Note:** This method mutates `object`.
  12972. *
  12973. * @static
  12974. * @memberOf _
  12975. * @since 4.6.0
  12976. * @category Object
  12977. * @param {Object} object The object to modify.
  12978. * @param {Array|string} path The path of the property to set.
  12979. * @param {Function} updater The function to produce the updated value.
  12980. * @returns {Object} Returns `object`.
  12981. * @example
  12982. *
  12983. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12984. *
  12985. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12986. * console.log(object.a[0].b.c);
  12987. * // => 9
  12988. *
  12989. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12990. * console.log(object.x[0].y.z);
  12991. * // => 0
  12992. */
  12993. function update(object, path, updater) {
  12994. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12995. }
  12996. /**
  12997. * This method is like `_.update` except that it accepts `customizer` which is
  12998. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12999. * path creation is handled by the method instead. The `customizer` is invoked
  13000. * with three arguments: (nsValue, key, nsObject).
  13001. *
  13002. * **Note:** This method mutates `object`.
  13003. *
  13004. * @static
  13005. * @memberOf _
  13006. * @since 4.6.0
  13007. * @category Object
  13008. * @param {Object} object The object to modify.
  13009. * @param {Array|string} path The path of the property to set.
  13010. * @param {Function} updater The function to produce the updated value.
  13011. * @param {Function} [customizer] The function to customize assigned values.
  13012. * @returns {Object} Returns `object`.
  13013. * @example
  13014. *
  13015. * var object = {};
  13016. *
  13017. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13018. * // => { '0': { '1': 'a' } }
  13019. */
  13020. function updateWith(object, path, updater, customizer) {
  13021. customizer = typeof customizer == 'function' ? customizer : undefined;
  13022. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13023. }
  13024. /**
  13025. * Creates an array of the own enumerable string keyed property values of `object`.
  13026. *
  13027. * **Note:** Non-object values are coerced to objects.
  13028. *
  13029. * @static
  13030. * @since 0.1.0
  13031. * @memberOf _
  13032. * @category Object
  13033. * @param {Object} object The object to query.
  13034. * @returns {Array} Returns the array of property values.
  13035. * @example
  13036. *
  13037. * function Foo() {
  13038. * this.a = 1;
  13039. * this.b = 2;
  13040. * }
  13041. *
  13042. * Foo.prototype.c = 3;
  13043. *
  13044. * _.values(new Foo);
  13045. * // => [1, 2] (iteration order is not guaranteed)
  13046. *
  13047. * _.values('hi');
  13048. * // => ['h', 'i']
  13049. */
  13050. function values(object) {
  13051. return object == null ? [] : baseValues(object, keys(object));
  13052. }
  13053. /**
  13054. * Creates an array of the own and inherited enumerable string keyed property
  13055. * values of `object`.
  13056. *
  13057. * **Note:** Non-object values are coerced to objects.
  13058. *
  13059. * @static
  13060. * @memberOf _
  13061. * @since 3.0.0
  13062. * @category Object
  13063. * @param {Object} object The object to query.
  13064. * @returns {Array} Returns the array of property values.
  13065. * @example
  13066. *
  13067. * function Foo() {
  13068. * this.a = 1;
  13069. * this.b = 2;
  13070. * }
  13071. *
  13072. * Foo.prototype.c = 3;
  13073. *
  13074. * _.valuesIn(new Foo);
  13075. * // => [1, 2, 3] (iteration order is not guaranteed)
  13076. */
  13077. function valuesIn(object) {
  13078. return object == null ? [] : baseValues(object, keysIn(object));
  13079. }
  13080. /*------------------------------------------------------------------------*/
  13081. /**
  13082. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13083. *
  13084. * @static
  13085. * @memberOf _
  13086. * @since 4.0.0
  13087. * @category Number
  13088. * @param {number} number The number to clamp.
  13089. * @param {number} [lower] The lower bound.
  13090. * @param {number} upper The upper bound.
  13091. * @returns {number} Returns the clamped number.
  13092. * @example
  13093. *
  13094. * _.clamp(-10, -5, 5);
  13095. * // => -5
  13096. *
  13097. * _.clamp(10, -5, 5);
  13098. * // => 5
  13099. */
  13100. function clamp(number, lower, upper) {
  13101. if (upper === undefined) {
  13102. upper = lower;
  13103. lower = undefined;
  13104. }
  13105. if (upper !== undefined) {
  13106. upper = toNumber(upper);
  13107. upper = upper === upper ? upper : 0;
  13108. }
  13109. if (lower !== undefined) {
  13110. lower = toNumber(lower);
  13111. lower = lower === lower ? lower : 0;
  13112. }
  13113. return baseClamp(toNumber(number), lower, upper);
  13114. }
  13115. /**
  13116. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13117. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13118. * If `start` is greater than `end` the params are swapped to support
  13119. * negative ranges.
  13120. *
  13121. * @static
  13122. * @memberOf _
  13123. * @since 3.3.0
  13124. * @category Number
  13125. * @param {number} number The number to check.
  13126. * @param {number} [start=0] The start of the range.
  13127. * @param {number} end The end of the range.
  13128. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13129. * @see _.range, _.rangeRight
  13130. * @example
  13131. *
  13132. * _.inRange(3, 2, 4);
  13133. * // => true
  13134. *
  13135. * _.inRange(4, 8);
  13136. * // => true
  13137. *
  13138. * _.inRange(4, 2);
  13139. * // => false
  13140. *
  13141. * _.inRange(2, 2);
  13142. * // => false
  13143. *
  13144. * _.inRange(1.2, 2);
  13145. * // => true
  13146. *
  13147. * _.inRange(5.2, 4);
  13148. * // => false
  13149. *
  13150. * _.inRange(-3, -2, -6);
  13151. * // => true
  13152. */
  13153. function inRange(number, start, end) {
  13154. start = toFinite(start);
  13155. if (end === undefined) {
  13156. end = start;
  13157. start = 0;
  13158. } else {
  13159. end = toFinite(end);
  13160. }
  13161. number = toNumber(number);
  13162. return baseInRange(number, start, end);
  13163. }
  13164. /**
  13165. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13166. * If only one argument is provided a number between `0` and the given number
  13167. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13168. * floats, a floating-point number is returned instead of an integer.
  13169. *
  13170. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13171. * floating-point values which can produce unexpected results.
  13172. *
  13173. * @static
  13174. * @memberOf _
  13175. * @since 0.7.0
  13176. * @category Number
  13177. * @param {number} [lower=0] The lower bound.
  13178. * @param {number} [upper=1] The upper bound.
  13179. * @param {boolean} [floating] Specify returning a floating-point number.
  13180. * @returns {number} Returns the random number.
  13181. * @example
  13182. *
  13183. * _.random(0, 5);
  13184. * // => an integer between 0 and 5
  13185. *
  13186. * _.random(5);
  13187. * // => also an integer between 0 and 5
  13188. *
  13189. * _.random(5, true);
  13190. * // => a floating-point number between 0 and 5
  13191. *
  13192. * _.random(1.2, 5.2);
  13193. * // => a floating-point number between 1.2 and 5.2
  13194. */
  13195. function random(lower, upper, floating) {
  13196. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13197. upper = floating = undefined;
  13198. }
  13199. if (floating === undefined) {
  13200. if (typeof upper == 'boolean') {
  13201. floating = upper;
  13202. upper = undefined;
  13203. }
  13204. else if (typeof lower == 'boolean') {
  13205. floating = lower;
  13206. lower = undefined;
  13207. }
  13208. }
  13209. if (lower === undefined && upper === undefined) {
  13210. lower = 0;
  13211. upper = 1;
  13212. }
  13213. else {
  13214. lower = toFinite(lower);
  13215. if (upper === undefined) {
  13216. upper = lower;
  13217. lower = 0;
  13218. } else {
  13219. upper = toFinite(upper);
  13220. }
  13221. }
  13222. if (lower > upper) {
  13223. var temp = lower;
  13224. lower = upper;
  13225. upper = temp;
  13226. }
  13227. if (floating || lower % 1 || upper % 1) {
  13228. var rand = nativeRandom();
  13229. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13230. }
  13231. return baseRandom(lower, upper);
  13232. }
  13233. /*------------------------------------------------------------------------*/
  13234. /**
  13235. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13236. *
  13237. * @static
  13238. * @memberOf _
  13239. * @since 3.0.0
  13240. * @category String
  13241. * @param {string} [string=''] The string to convert.
  13242. * @returns {string} Returns the camel cased string.
  13243. * @example
  13244. *
  13245. * _.camelCase('Foo Bar');
  13246. * // => 'fooBar'
  13247. *
  13248. * _.camelCase('--foo-bar--');
  13249. * // => 'fooBar'
  13250. *
  13251. * _.camelCase('__FOO_BAR__');
  13252. * // => 'fooBar'
  13253. */
  13254. var camelCase = createCompounder(function(result, word, index) {
  13255. word = word.toLowerCase();
  13256. return result + (index ? capitalize(word) : word);
  13257. });
  13258. /**
  13259. * Converts the first character of `string` to upper case and the remaining
  13260. * to lower case.
  13261. *
  13262. * @static
  13263. * @memberOf _
  13264. * @since 3.0.0
  13265. * @category String
  13266. * @param {string} [string=''] The string to capitalize.
  13267. * @returns {string} Returns the capitalized string.
  13268. * @example
  13269. *
  13270. * _.capitalize('FRED');
  13271. * // => 'Fred'
  13272. */
  13273. function capitalize(string) {
  13274. return upperFirst(toString(string).toLowerCase());
  13275. }
  13276. /**
  13277. * Deburrs `string` by converting
  13278. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13279. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13280. * letters to basic Latin letters and removing
  13281. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13282. *
  13283. * @static
  13284. * @memberOf _
  13285. * @since 3.0.0
  13286. * @category String
  13287. * @param {string} [string=''] The string to deburr.
  13288. * @returns {string} Returns the deburred string.
  13289. * @example
  13290. *
  13291. * _.deburr('déjà vu');
  13292. * // => 'deja vu'
  13293. */
  13294. function deburr(string) {
  13295. string = toString(string);
  13296. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13297. }
  13298. /**
  13299. * Checks if `string` ends with the given target string.
  13300. *
  13301. * @static
  13302. * @memberOf _
  13303. * @since 3.0.0
  13304. * @category String
  13305. * @param {string} [string=''] The string to inspect.
  13306. * @param {string} [target] The string to search for.
  13307. * @param {number} [position=string.length] The position to search up to.
  13308. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13309. * else `false`.
  13310. * @example
  13311. *
  13312. * _.endsWith('abc', 'c');
  13313. * // => true
  13314. *
  13315. * _.endsWith('abc', 'b');
  13316. * // => false
  13317. *
  13318. * _.endsWith('abc', 'b', 2);
  13319. * // => true
  13320. */
  13321. function endsWith(string, target, position) {
  13322. string = toString(string);
  13323. target = baseToString(target);
  13324. var length = string.length;
  13325. position = position === undefined
  13326. ? length
  13327. : baseClamp(toInteger(position), 0, length);
  13328. var end = position;
  13329. position -= target.length;
  13330. return position >= 0 && string.slice(position, end) == target;
  13331. }
  13332. /**
  13333. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13334. * corresponding HTML entities.
  13335. *
  13336. * **Note:** No other characters are escaped. To escape additional
  13337. * characters use a third-party library like [_he_](https://mths.be/he).
  13338. *
  13339. * Though the ">" character is escaped for symmetry, characters like
  13340. * ">" and "/" don't need escaping in HTML and have no special meaning
  13341. * unless they're part of a tag or unquoted attribute value. See
  13342. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13343. * (under "semi-related fun fact") for more details.
  13344. *
  13345. * When working with HTML you should always
  13346. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13347. * XSS vectors.
  13348. *
  13349. * @static
  13350. * @since 0.1.0
  13351. * @memberOf _
  13352. * @category String
  13353. * @param {string} [string=''] The string to escape.
  13354. * @returns {string} Returns the escaped string.
  13355. * @example
  13356. *
  13357. * _.escape('fred, barney, & pebbles');
  13358. * // => 'fred, barney, &amp; pebbles'
  13359. */
  13360. function escape(string) {
  13361. string = toString(string);
  13362. return (string && reHasUnescapedHtml.test(string))
  13363. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13364. : string;
  13365. }
  13366. /**
  13367. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13368. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13369. *
  13370. * @static
  13371. * @memberOf _
  13372. * @since 3.0.0
  13373. * @category String
  13374. * @param {string} [string=''] The string to escape.
  13375. * @returns {string} Returns the escaped string.
  13376. * @example
  13377. *
  13378. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13379. * // => '\[lodash\]\(https://lodash\.com/\)'
  13380. */
  13381. function escapeRegExp(string) {
  13382. string = toString(string);
  13383. return (string && reHasRegExpChar.test(string))
  13384. ? string.replace(reRegExpChar, '\\$&')
  13385. : string;
  13386. }
  13387. /**
  13388. * Converts `string` to
  13389. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13390. *
  13391. * @static
  13392. * @memberOf _
  13393. * @since 3.0.0
  13394. * @category String
  13395. * @param {string} [string=''] The string to convert.
  13396. * @returns {string} Returns the kebab cased string.
  13397. * @example
  13398. *
  13399. * _.kebabCase('Foo Bar');
  13400. * // => 'foo-bar'
  13401. *
  13402. * _.kebabCase('fooBar');
  13403. * // => 'foo-bar'
  13404. *
  13405. * _.kebabCase('__FOO_BAR__');
  13406. * // => 'foo-bar'
  13407. */
  13408. var kebabCase = createCompounder(function(result, word, index) {
  13409. return result + (index ? '-' : '') + word.toLowerCase();
  13410. });
  13411. /**
  13412. * Converts `string`, as space separated words, to lower case.
  13413. *
  13414. * @static
  13415. * @memberOf _
  13416. * @since 4.0.0
  13417. * @category String
  13418. * @param {string} [string=''] The string to convert.
  13419. * @returns {string} Returns the lower cased string.
  13420. * @example
  13421. *
  13422. * _.lowerCase('--Foo-Bar--');
  13423. * // => 'foo bar'
  13424. *
  13425. * _.lowerCase('fooBar');
  13426. * // => 'foo bar'
  13427. *
  13428. * _.lowerCase('__FOO_BAR__');
  13429. * // => 'foo bar'
  13430. */
  13431. var lowerCase = createCompounder(function(result, word, index) {
  13432. return result + (index ? ' ' : '') + word.toLowerCase();
  13433. });
  13434. /**
  13435. * Converts the first character of `string` to lower case.
  13436. *
  13437. * @static
  13438. * @memberOf _
  13439. * @since 4.0.0
  13440. * @category String
  13441. * @param {string} [string=''] The string to convert.
  13442. * @returns {string} Returns the converted string.
  13443. * @example
  13444. *
  13445. * _.lowerFirst('Fred');
  13446. * // => 'fred'
  13447. *
  13448. * _.lowerFirst('FRED');
  13449. * // => 'fRED'
  13450. */
  13451. var lowerFirst = createCaseFirst('toLowerCase');
  13452. /**
  13453. * Pads `string` on the left and right sides if it's shorter than `length`.
  13454. * Padding characters are truncated if they can't be evenly divided by `length`.
  13455. *
  13456. * @static
  13457. * @memberOf _
  13458. * @since 3.0.0
  13459. * @category String
  13460. * @param {string} [string=''] The string to pad.
  13461. * @param {number} [length=0] The padding length.
  13462. * @param {string} [chars=' '] The string used as padding.
  13463. * @returns {string} Returns the padded string.
  13464. * @example
  13465. *
  13466. * _.pad('abc', 8);
  13467. * // => ' abc '
  13468. *
  13469. * _.pad('abc', 8, '_-');
  13470. * // => '_-abc_-_'
  13471. *
  13472. * _.pad('abc', 3);
  13473. * // => 'abc'
  13474. */
  13475. function pad(string, length, chars) {
  13476. string = toString(string);
  13477. length = toInteger(length);
  13478. var strLength = length ? stringSize(string) : 0;
  13479. if (!length || strLength >= length) {
  13480. return string;
  13481. }
  13482. var mid = (length - strLength) / 2;
  13483. return (
  13484. createPadding(nativeFloor(mid), chars) +
  13485. string +
  13486. createPadding(nativeCeil(mid), chars)
  13487. );
  13488. }
  13489. /**
  13490. * Pads `string` on the right side if it's shorter than `length`. Padding
  13491. * characters are truncated if they exceed `length`.
  13492. *
  13493. * @static
  13494. * @memberOf _
  13495. * @since 4.0.0
  13496. * @category String
  13497. * @param {string} [string=''] The string to pad.
  13498. * @param {number} [length=0] The padding length.
  13499. * @param {string} [chars=' '] The string used as padding.
  13500. * @returns {string} Returns the padded string.
  13501. * @example
  13502. *
  13503. * _.padEnd('abc', 6);
  13504. * // => 'abc '
  13505. *
  13506. * _.padEnd('abc', 6, '_-');
  13507. * // => 'abc_-_'
  13508. *
  13509. * _.padEnd('abc', 3);
  13510. * // => 'abc'
  13511. */
  13512. function padEnd(string, length, chars) {
  13513. string = toString(string);
  13514. length = toInteger(length);
  13515. var strLength = length ? stringSize(string) : 0;
  13516. return (length && strLength < length)
  13517. ? (string + createPadding(length - strLength, chars))
  13518. : string;
  13519. }
  13520. /**
  13521. * Pads `string` on the left side if it's shorter than `length`. Padding
  13522. * characters are truncated if they exceed `length`.
  13523. *
  13524. * @static
  13525. * @memberOf _
  13526. * @since 4.0.0
  13527. * @category String
  13528. * @param {string} [string=''] The string to pad.
  13529. * @param {number} [length=0] The padding length.
  13530. * @param {string} [chars=' '] The string used as padding.
  13531. * @returns {string} Returns the padded string.
  13532. * @example
  13533. *
  13534. * _.padStart('abc', 6);
  13535. * // => ' abc'
  13536. *
  13537. * _.padStart('abc', 6, '_-');
  13538. * // => '_-_abc'
  13539. *
  13540. * _.padStart('abc', 3);
  13541. * // => 'abc'
  13542. */
  13543. function padStart(string, length, chars) {
  13544. string = toString(string);
  13545. length = toInteger(length);
  13546. var strLength = length ? stringSize(string) : 0;
  13547. return (length && strLength < length)
  13548. ? (createPadding(length - strLength, chars) + string)
  13549. : string;
  13550. }
  13551. /**
  13552. * Converts `string` to an integer of the specified radix. If `radix` is
  13553. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13554. * hexadecimal, in which case a `radix` of `16` is used.
  13555. *
  13556. * **Note:** This method aligns with the
  13557. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13558. *
  13559. * @static
  13560. * @memberOf _
  13561. * @since 1.1.0
  13562. * @category String
  13563. * @param {string} string The string to convert.
  13564. * @param {number} [radix=10] The radix to interpret `value` by.
  13565. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13566. * @returns {number} Returns the converted integer.
  13567. * @example
  13568. *
  13569. * _.parseInt('08');
  13570. * // => 8
  13571. *
  13572. * _.map(['6', '08', '10'], _.parseInt);
  13573. * // => [6, 8, 10]
  13574. */
  13575. function parseInt(string, radix, guard) {
  13576. if (guard || radix == null) {
  13577. radix = 0;
  13578. } else if (radix) {
  13579. radix = +radix;
  13580. }
  13581. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13582. }
  13583. /**
  13584. * Repeats the given string `n` times.
  13585. *
  13586. * @static
  13587. * @memberOf _
  13588. * @since 3.0.0
  13589. * @category String
  13590. * @param {string} [string=''] The string to repeat.
  13591. * @param {number} [n=1] The number of times to repeat the string.
  13592. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13593. * @returns {string} Returns the repeated string.
  13594. * @example
  13595. *
  13596. * _.repeat('*', 3);
  13597. * // => '***'
  13598. *
  13599. * _.repeat('abc', 2);
  13600. * // => 'abcabc'
  13601. *
  13602. * _.repeat('abc', 0);
  13603. * // => ''
  13604. */
  13605. function repeat(string, n, guard) {
  13606. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13607. n = 1;
  13608. } else {
  13609. n = toInteger(n);
  13610. }
  13611. return baseRepeat(toString(string), n);
  13612. }
  13613. /**
  13614. * Replaces matches for `pattern` in `string` with `replacement`.
  13615. *
  13616. * **Note:** This method is based on
  13617. * [`String#replace`](https://mdn.io/String/replace).
  13618. *
  13619. * @static
  13620. * @memberOf _
  13621. * @since 4.0.0
  13622. * @category String
  13623. * @param {string} [string=''] The string to modify.
  13624. * @param {RegExp|string} pattern The pattern to replace.
  13625. * @param {Function|string} replacement The match replacement.
  13626. * @returns {string} Returns the modified string.
  13627. * @example
  13628. *
  13629. * _.replace('Hi Fred', 'Fred', 'Barney');
  13630. * // => 'Hi Barney'
  13631. */
  13632. function replace() {
  13633. var args = arguments,
  13634. string = toString(args[0]);
  13635. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13636. }
  13637. /**
  13638. * Converts `string` to
  13639. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13640. *
  13641. * @static
  13642. * @memberOf _
  13643. * @since 3.0.0
  13644. * @category String
  13645. * @param {string} [string=''] The string to convert.
  13646. * @returns {string} Returns the snake cased string.
  13647. * @example
  13648. *
  13649. * _.snakeCase('Foo Bar');
  13650. * // => 'foo_bar'
  13651. *
  13652. * _.snakeCase('fooBar');
  13653. * // => 'foo_bar'
  13654. *
  13655. * _.snakeCase('--FOO-BAR--');
  13656. * // => 'foo_bar'
  13657. */
  13658. var snakeCase = createCompounder(function(result, word, index) {
  13659. return result + (index ? '_' : '') + word.toLowerCase();
  13660. });
  13661. /**
  13662. * Splits `string` by `separator`.
  13663. *
  13664. * **Note:** This method is based on
  13665. * [`String#split`](https://mdn.io/String/split).
  13666. *
  13667. * @static
  13668. * @memberOf _
  13669. * @since 4.0.0
  13670. * @category String
  13671. * @param {string} [string=''] The string to split.
  13672. * @param {RegExp|string} separator The separator pattern to split by.
  13673. * @param {number} [limit] The length to truncate results to.
  13674. * @returns {Array} Returns the string segments.
  13675. * @example
  13676. *
  13677. * _.split('a-b-c', '-', 2);
  13678. * // => ['a', 'b']
  13679. */
  13680. function split(string, separator, limit) {
  13681. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13682. separator = limit = undefined;
  13683. }
  13684. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13685. if (!limit) {
  13686. return [];
  13687. }
  13688. string = toString(string);
  13689. if (string && (
  13690. typeof separator == 'string' ||
  13691. (separator != null && !isRegExp(separator))
  13692. )) {
  13693. separator = baseToString(separator);
  13694. if (!separator && hasUnicode(string)) {
  13695. return castSlice(stringToArray(string), 0, limit);
  13696. }
  13697. }
  13698. return string.split(separator, limit);
  13699. }
  13700. /**
  13701. * Converts `string` to
  13702. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13703. *
  13704. * @static
  13705. * @memberOf _
  13706. * @since 3.1.0
  13707. * @category String
  13708. * @param {string} [string=''] The string to convert.
  13709. * @returns {string} Returns the start cased string.
  13710. * @example
  13711. *
  13712. * _.startCase('--foo-bar--');
  13713. * // => 'Foo Bar'
  13714. *
  13715. * _.startCase('fooBar');
  13716. * // => 'Foo Bar'
  13717. *
  13718. * _.startCase('__FOO_BAR__');
  13719. * // => 'FOO BAR'
  13720. */
  13721. var startCase = createCompounder(function(result, word, index) {
  13722. return result + (index ? ' ' : '') + upperFirst(word);
  13723. });
  13724. /**
  13725. * Checks if `string` starts with the given target string.
  13726. *
  13727. * @static
  13728. * @memberOf _
  13729. * @since 3.0.0
  13730. * @category String
  13731. * @param {string} [string=''] The string to inspect.
  13732. * @param {string} [target] The string to search for.
  13733. * @param {number} [position=0] The position to search from.
  13734. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13735. * else `false`.
  13736. * @example
  13737. *
  13738. * _.startsWith('abc', 'a');
  13739. * // => true
  13740. *
  13741. * _.startsWith('abc', 'b');
  13742. * // => false
  13743. *
  13744. * _.startsWith('abc', 'b', 1);
  13745. * // => true
  13746. */
  13747. function startsWith(string, target, position) {
  13748. string = toString(string);
  13749. position = position == null
  13750. ? 0
  13751. : baseClamp(toInteger(position), 0, string.length);
  13752. target = baseToString(target);
  13753. return string.slice(position, position + target.length) == target;
  13754. }
  13755. /**
  13756. * Creates a compiled template function that can interpolate data properties
  13757. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13758. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13759. * properties may be accessed as free variables in the template. If a setting
  13760. * object is given, it takes precedence over `_.templateSettings` values.
  13761. *
  13762. * **Note:** In the development build `_.template` utilizes
  13763. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13764. * for easier debugging.
  13765. *
  13766. * For more information on precompiling templates see
  13767. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13768. *
  13769. * For more information on Chrome extension sandboxes see
  13770. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13771. *
  13772. * @static
  13773. * @since 0.1.0
  13774. * @memberOf _
  13775. * @category String
  13776. * @param {string} [string=''] The template string.
  13777. * @param {Object} [options={}] The options object.
  13778. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13779. * The HTML "escape" delimiter.
  13780. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13781. * The "evaluate" delimiter.
  13782. * @param {Object} [options.imports=_.templateSettings.imports]
  13783. * An object to import into the template as free variables.
  13784. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13785. * The "interpolate" delimiter.
  13786. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13787. * The sourceURL of the compiled template.
  13788. * @param {string} [options.variable='obj']
  13789. * The data object variable name.
  13790. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13791. * @returns {Function} Returns the compiled template function.
  13792. * @example
  13793. *
  13794. * // Use the "interpolate" delimiter to create a compiled template.
  13795. * var compiled = _.template('hello <%= user %>!');
  13796. * compiled({ 'user': 'fred' });
  13797. * // => 'hello fred!'
  13798. *
  13799. * // Use the HTML "escape" delimiter to escape data property values.
  13800. * var compiled = _.template('<b><%- value %></b>');
  13801. * compiled({ 'value': '<script>' });
  13802. * // => '<b>&lt;script&gt;</b>'
  13803. *
  13804. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13805. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13806. * compiled({ 'users': ['fred', 'barney'] });
  13807. * // => '<li>fred</li><li>barney</li>'
  13808. *
  13809. * // Use the internal `print` function in "evaluate" delimiters.
  13810. * var compiled = _.template('<% print("hello " + user); %>!');
  13811. * compiled({ 'user': 'barney' });
  13812. * // => 'hello barney!'
  13813. *
  13814. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13815. * // Disable support by replacing the "interpolate" delimiter.
  13816. * var compiled = _.template('hello ${ user }!');
  13817. * compiled({ 'user': 'pebbles' });
  13818. * // => 'hello pebbles!'
  13819. *
  13820. * // Use backslashes to treat delimiters as plain text.
  13821. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13822. * compiled({ 'value': 'ignored' });
  13823. * // => '<%- value %>'
  13824. *
  13825. * // Use the `imports` option to import `jQuery` as `jq`.
  13826. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13827. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13828. * compiled({ 'users': ['fred', 'barney'] });
  13829. * // => '<li>fred</li><li>barney</li>'
  13830. *
  13831. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13832. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13833. * compiled(data);
  13834. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13835. *
  13836. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13837. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13838. * compiled.source;
  13839. * // => function(data) {
  13840. * // var __t, __p = '';
  13841. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13842. * // return __p;
  13843. * // }
  13844. *
  13845. * // Use custom template delimiters.
  13846. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13847. * var compiled = _.template('hello {{ user }}!');
  13848. * compiled({ 'user': 'mustache' });
  13849. * // => 'hello mustache!'
  13850. *
  13851. * // Use the `source` property to inline compiled templates for meaningful
  13852. * // line numbers in error messages and stack traces.
  13853. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13854. * var JST = {\
  13855. * "main": ' + _.template(mainText).source + '\
  13856. * };\
  13857. * ');
  13858. */
  13859. function template(string, options, guard) {
  13860. // Based on John Resig's `tmpl` implementation
  13861. // (http://ejohn.org/blog/javascript-micro-templating/)
  13862. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13863. var settings = lodash.templateSettings;
  13864. if (guard && isIterateeCall(string, options, guard)) {
  13865. options = undefined;
  13866. }
  13867. string = toString(string);
  13868. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13869. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13870. importsKeys = keys(imports),
  13871. importsValues = baseValues(imports, importsKeys);
  13872. var isEscaping,
  13873. isEvaluating,
  13874. index = 0,
  13875. interpolate = options.interpolate || reNoMatch,
  13876. source = "__p += '";
  13877. // Compile the regexp to match each delimiter.
  13878. var reDelimiters = RegExp(
  13879. (options.escape || reNoMatch).source + '|' +
  13880. interpolate.source + '|' +
  13881. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13882. (options.evaluate || reNoMatch).source + '|$'
  13883. , 'g');
  13884. // Use a sourceURL for easier debugging.
  13885. var sourceURL = '//# sourceURL=' +
  13886. ('sourceURL' in options
  13887. ? options.sourceURL
  13888. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13889. ) + '\n';
  13890. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13891. interpolateValue || (interpolateValue = esTemplateValue);
  13892. // Escape characters that can't be included in string literals.
  13893. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13894. // Replace delimiters with snippets.
  13895. if (escapeValue) {
  13896. isEscaping = true;
  13897. source += "' +\n__e(" + escapeValue + ") +\n'";
  13898. }
  13899. if (evaluateValue) {
  13900. isEvaluating = true;
  13901. source += "';\n" + evaluateValue + ";\n__p += '";
  13902. }
  13903. if (interpolateValue) {
  13904. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13905. }
  13906. index = offset + match.length;
  13907. // The JS engine embedded in Adobe products needs `match` returned in
  13908. // order to produce the correct `offset` value.
  13909. return match;
  13910. });
  13911. source += "';\n";
  13912. // If `variable` is not specified wrap a with-statement around the generated
  13913. // code to add the data object to the top of the scope chain.
  13914. var variable = options.variable;
  13915. if (!variable) {
  13916. source = 'with (obj) {\n' + source + '\n}\n';
  13917. }
  13918. // Cleanup code by stripping empty strings.
  13919. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13920. .replace(reEmptyStringMiddle, '$1')
  13921. .replace(reEmptyStringTrailing, '$1;');
  13922. // Frame code as the function body.
  13923. source = 'function(' + (variable || 'obj') + ') {\n' +
  13924. (variable
  13925. ? ''
  13926. : 'obj || (obj = {});\n'
  13927. ) +
  13928. "var __t, __p = ''" +
  13929. (isEscaping
  13930. ? ', __e = _.escape'
  13931. : ''
  13932. ) +
  13933. (isEvaluating
  13934. ? ', __j = Array.prototype.join;\n' +
  13935. "function print() { __p += __j.call(arguments, '') }\n"
  13936. : ';\n'
  13937. ) +
  13938. source +
  13939. 'return __p\n}';
  13940. var result = attempt(function() {
  13941. return Function(importsKeys, sourceURL + 'return ' + source)
  13942. .apply(undefined, importsValues);
  13943. });
  13944. // Provide the compiled function's source by its `toString` method or
  13945. // the `source` property as a convenience for inlining compiled templates.
  13946. result.source = source;
  13947. if (isError(result)) {
  13948. throw result;
  13949. }
  13950. return result;
  13951. }
  13952. /**
  13953. * Converts `string`, as a whole, to lower case just like
  13954. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13955. *
  13956. * @static
  13957. * @memberOf _
  13958. * @since 4.0.0
  13959. * @category String
  13960. * @param {string} [string=''] The string to convert.
  13961. * @returns {string} Returns the lower cased string.
  13962. * @example
  13963. *
  13964. * _.toLower('--Foo-Bar--');
  13965. * // => '--foo-bar--'
  13966. *
  13967. * _.toLower('fooBar');
  13968. * // => 'foobar'
  13969. *
  13970. * _.toLower('__FOO_BAR__');
  13971. * // => '__foo_bar__'
  13972. */
  13973. function toLower(value) {
  13974. return toString(value).toLowerCase();
  13975. }
  13976. /**
  13977. * Converts `string`, as a whole, to upper case just like
  13978. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13979. *
  13980. * @static
  13981. * @memberOf _
  13982. * @since 4.0.0
  13983. * @category String
  13984. * @param {string} [string=''] The string to convert.
  13985. * @returns {string} Returns the upper cased string.
  13986. * @example
  13987. *
  13988. * _.toUpper('--foo-bar--');
  13989. * // => '--FOO-BAR--'
  13990. *
  13991. * _.toUpper('fooBar');
  13992. * // => 'FOOBAR'
  13993. *
  13994. * _.toUpper('__foo_bar__');
  13995. * // => '__FOO_BAR__'
  13996. */
  13997. function toUpper(value) {
  13998. return toString(value).toUpperCase();
  13999. }
  14000. /**
  14001. * Removes leading and trailing whitespace or specified characters from `string`.
  14002. *
  14003. * @static
  14004. * @memberOf _
  14005. * @since 3.0.0
  14006. * @category String
  14007. * @param {string} [string=''] The string to trim.
  14008. * @param {string} [chars=whitespace] The characters to trim.
  14009. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14010. * @returns {string} Returns the trimmed string.
  14011. * @example
  14012. *
  14013. * _.trim(' abc ');
  14014. * // => 'abc'
  14015. *
  14016. * _.trim('-_-abc-_-', '_-');
  14017. * // => 'abc'
  14018. *
  14019. * _.map([' foo ', ' bar '], _.trim);
  14020. * // => ['foo', 'bar']
  14021. */
  14022. function trim(string, chars, guard) {
  14023. string = toString(string);
  14024. if (string && (guard || chars === undefined)) {
  14025. return string.replace(reTrim, '');
  14026. }
  14027. if (!string || !(chars = baseToString(chars))) {
  14028. return string;
  14029. }
  14030. var strSymbols = stringToArray(string),
  14031. chrSymbols = stringToArray(chars),
  14032. start = charsStartIndex(strSymbols, chrSymbols),
  14033. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14034. return castSlice(strSymbols, start, end).join('');
  14035. }
  14036. /**
  14037. * Removes trailing whitespace or specified characters from `string`.
  14038. *
  14039. * @static
  14040. * @memberOf _
  14041. * @since 4.0.0
  14042. * @category String
  14043. * @param {string} [string=''] The string to trim.
  14044. * @param {string} [chars=whitespace] The characters to trim.
  14045. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14046. * @returns {string} Returns the trimmed string.
  14047. * @example
  14048. *
  14049. * _.trimEnd(' abc ');
  14050. * // => ' abc'
  14051. *
  14052. * _.trimEnd('-_-abc-_-', '_-');
  14053. * // => '-_-abc'
  14054. */
  14055. function trimEnd(string, chars, guard) {
  14056. string = toString(string);
  14057. if (string && (guard || chars === undefined)) {
  14058. return string.replace(reTrimEnd, '');
  14059. }
  14060. if (!string || !(chars = baseToString(chars))) {
  14061. return string;
  14062. }
  14063. var strSymbols = stringToArray(string),
  14064. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14065. return castSlice(strSymbols, 0, end).join('');
  14066. }
  14067. /**
  14068. * Removes leading whitespace or specified characters from `string`.
  14069. *
  14070. * @static
  14071. * @memberOf _
  14072. * @since 4.0.0
  14073. * @category String
  14074. * @param {string} [string=''] The string to trim.
  14075. * @param {string} [chars=whitespace] The characters to trim.
  14076. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14077. * @returns {string} Returns the trimmed string.
  14078. * @example
  14079. *
  14080. * _.trimStart(' abc ');
  14081. * // => 'abc '
  14082. *
  14083. * _.trimStart('-_-abc-_-', '_-');
  14084. * // => 'abc-_-'
  14085. */
  14086. function trimStart(string, chars, guard) {
  14087. string = toString(string);
  14088. if (string && (guard || chars === undefined)) {
  14089. return string.replace(reTrimStart, '');
  14090. }
  14091. if (!string || !(chars = baseToString(chars))) {
  14092. return string;
  14093. }
  14094. var strSymbols = stringToArray(string),
  14095. start = charsStartIndex(strSymbols, stringToArray(chars));
  14096. return castSlice(strSymbols, start).join('');
  14097. }
  14098. /**
  14099. * Truncates `string` if it's longer than the given maximum string length.
  14100. * The last characters of the truncated string are replaced with the omission
  14101. * string which defaults to "...".
  14102. *
  14103. * @static
  14104. * @memberOf _
  14105. * @since 4.0.0
  14106. * @category String
  14107. * @param {string} [string=''] The string to truncate.
  14108. * @param {Object} [options={}] The options object.
  14109. * @param {number} [options.length=30] The maximum string length.
  14110. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14111. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14112. * @returns {string} Returns the truncated string.
  14113. * @example
  14114. *
  14115. * _.truncate('hi-diddly-ho there, neighborino');
  14116. * // => 'hi-diddly-ho there, neighbo...'
  14117. *
  14118. * _.truncate('hi-diddly-ho there, neighborino', {
  14119. * 'length': 24,
  14120. * 'separator': ' '
  14121. * });
  14122. * // => 'hi-diddly-ho there,...'
  14123. *
  14124. * _.truncate('hi-diddly-ho there, neighborino', {
  14125. * 'length': 24,
  14126. * 'separator': /,? +/
  14127. * });
  14128. * // => 'hi-diddly-ho there...'
  14129. *
  14130. * _.truncate('hi-diddly-ho there, neighborino', {
  14131. * 'omission': ' [...]'
  14132. * });
  14133. * // => 'hi-diddly-ho there, neig [...]'
  14134. */
  14135. function truncate(string, options) {
  14136. var length = DEFAULT_TRUNC_LENGTH,
  14137. omission = DEFAULT_TRUNC_OMISSION;
  14138. if (isObject(options)) {
  14139. var separator = 'separator' in options ? options.separator : separator;
  14140. length = 'length' in options ? toInteger(options.length) : length;
  14141. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14142. }
  14143. string = toString(string);
  14144. var strLength = string.length;
  14145. if (hasUnicode(string)) {
  14146. var strSymbols = stringToArray(string);
  14147. strLength = strSymbols.length;
  14148. }
  14149. if (length >= strLength) {
  14150. return string;
  14151. }
  14152. var end = length - stringSize(omission);
  14153. if (end < 1) {
  14154. return omission;
  14155. }
  14156. var result = strSymbols
  14157. ? castSlice(strSymbols, 0, end).join('')
  14158. : string.slice(0, end);
  14159. if (separator === undefined) {
  14160. return result + omission;
  14161. }
  14162. if (strSymbols) {
  14163. end += (result.length - end);
  14164. }
  14165. if (isRegExp(separator)) {
  14166. if (string.slice(end).search(separator)) {
  14167. var match,
  14168. substring = result;
  14169. if (!separator.global) {
  14170. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14171. }
  14172. separator.lastIndex = 0;
  14173. while ((match = separator.exec(substring))) {
  14174. var newEnd = match.index;
  14175. }
  14176. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14177. }
  14178. } else if (string.indexOf(baseToString(separator), end) != end) {
  14179. var index = result.lastIndexOf(separator);
  14180. if (index > -1) {
  14181. result = result.slice(0, index);
  14182. }
  14183. }
  14184. return result + omission;
  14185. }
  14186. /**
  14187. * The inverse of `_.escape`; this method converts the HTML entities
  14188. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14189. * their corresponding characters.
  14190. *
  14191. * **Note:** No other HTML entities are unescaped. To unescape additional
  14192. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14193. *
  14194. * @static
  14195. * @memberOf _
  14196. * @since 0.6.0
  14197. * @category String
  14198. * @param {string} [string=''] The string to unescape.
  14199. * @returns {string} Returns the unescaped string.
  14200. * @example
  14201. *
  14202. * _.unescape('fred, barney, &amp; pebbles');
  14203. * // => 'fred, barney, & pebbles'
  14204. */
  14205. function unescape(string) {
  14206. string = toString(string);
  14207. return (string && reHasEscapedHtml.test(string))
  14208. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14209. : string;
  14210. }
  14211. /**
  14212. * Converts `string`, as space separated words, to upper case.
  14213. *
  14214. * @static
  14215. * @memberOf _
  14216. * @since 4.0.0
  14217. * @category String
  14218. * @param {string} [string=''] The string to convert.
  14219. * @returns {string} Returns the upper cased string.
  14220. * @example
  14221. *
  14222. * _.upperCase('--foo-bar');
  14223. * // => 'FOO BAR'
  14224. *
  14225. * _.upperCase('fooBar');
  14226. * // => 'FOO BAR'
  14227. *
  14228. * _.upperCase('__foo_bar__');
  14229. * // => 'FOO BAR'
  14230. */
  14231. var upperCase = createCompounder(function(result, word, index) {
  14232. return result + (index ? ' ' : '') + word.toUpperCase();
  14233. });
  14234. /**
  14235. * Converts the first character of `string` to upper case.
  14236. *
  14237. * @static
  14238. * @memberOf _
  14239. * @since 4.0.0
  14240. * @category String
  14241. * @param {string} [string=''] The string to convert.
  14242. * @returns {string} Returns the converted string.
  14243. * @example
  14244. *
  14245. * _.upperFirst('fred');
  14246. * // => 'Fred'
  14247. *
  14248. * _.upperFirst('FRED');
  14249. * // => 'FRED'
  14250. */
  14251. var upperFirst = createCaseFirst('toUpperCase');
  14252. /**
  14253. * Splits `string` into an array of its words.
  14254. *
  14255. * @static
  14256. * @memberOf _
  14257. * @since 3.0.0
  14258. * @category String
  14259. * @param {string} [string=''] The string to inspect.
  14260. * @param {RegExp|string} [pattern] The pattern to match words.
  14261. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14262. * @returns {Array} Returns the words of `string`.
  14263. * @example
  14264. *
  14265. * _.words('fred, barney, & pebbles');
  14266. * // => ['fred', 'barney', 'pebbles']
  14267. *
  14268. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14269. * // => ['fred', 'barney', '&', 'pebbles']
  14270. */
  14271. function words(string, pattern, guard) {
  14272. string = toString(string);
  14273. pattern = guard ? undefined : pattern;
  14274. if (pattern === undefined) {
  14275. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14276. }
  14277. return string.match(pattern) || [];
  14278. }
  14279. /*------------------------------------------------------------------------*/
  14280. /**
  14281. * Attempts to invoke `func`, returning either the result or the caught error
  14282. * object. Any additional arguments are provided to `func` when it's invoked.
  14283. *
  14284. * @static
  14285. * @memberOf _
  14286. * @since 3.0.0
  14287. * @category Util
  14288. * @param {Function} func The function to attempt.
  14289. * @param {...*} [args] The arguments to invoke `func` with.
  14290. * @returns {*} Returns the `func` result or error object.
  14291. * @example
  14292. *
  14293. * // Avoid throwing errors for invalid selectors.
  14294. * var elements = _.attempt(function(selector) {
  14295. * return document.querySelectorAll(selector);
  14296. * }, '>_>');
  14297. *
  14298. * if (_.isError(elements)) {
  14299. * elements = [];
  14300. * }
  14301. */
  14302. var attempt = baseRest(function(func, args) {
  14303. try {
  14304. return apply(func, undefined, args);
  14305. } catch (e) {
  14306. return isError(e) ? e : new Error(e);
  14307. }
  14308. });
  14309. /**
  14310. * Binds methods of an object to the object itself, overwriting the existing
  14311. * method.
  14312. *
  14313. * **Note:** This method doesn't set the "length" property of bound functions.
  14314. *
  14315. * @static
  14316. * @since 0.1.0
  14317. * @memberOf _
  14318. * @category Util
  14319. * @param {Object} object The object to bind and assign the bound methods to.
  14320. * @param {...(string|string[])} methodNames The object method names to bind.
  14321. * @returns {Object} Returns `object`.
  14322. * @example
  14323. *
  14324. * var view = {
  14325. * 'label': 'docs',
  14326. * 'click': function() {
  14327. * console.log('clicked ' + this.label);
  14328. * }
  14329. * };
  14330. *
  14331. * _.bindAll(view, ['click']);
  14332. * jQuery(element).on('click', view.click);
  14333. * // => Logs 'clicked docs' when clicked.
  14334. */
  14335. var bindAll = flatRest(function(object, methodNames) {
  14336. arrayEach(methodNames, function(key) {
  14337. key = toKey(key);
  14338. baseAssignValue(object, key, bind(object[key], object));
  14339. });
  14340. return object;
  14341. });
  14342. /**
  14343. * Creates a function that iterates over `pairs` and invokes the corresponding
  14344. * function of the first predicate to return truthy. The predicate-function
  14345. * pairs are invoked with the `this` binding and arguments of the created
  14346. * function.
  14347. *
  14348. * @static
  14349. * @memberOf _
  14350. * @since 4.0.0
  14351. * @category Util
  14352. * @param {Array} pairs The predicate-function pairs.
  14353. * @returns {Function} Returns the new composite function.
  14354. * @example
  14355. *
  14356. * var func = _.cond([
  14357. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14358. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14359. * [_.stubTrue, _.constant('no match')]
  14360. * ]);
  14361. *
  14362. * func({ 'a': 1, 'b': 2 });
  14363. * // => 'matches A'
  14364. *
  14365. * func({ 'a': 0, 'b': 1 });
  14366. * // => 'matches B'
  14367. *
  14368. * func({ 'a': '1', 'b': '2' });
  14369. * // => 'no match'
  14370. */
  14371. function cond(pairs) {
  14372. var length = pairs == null ? 0 : pairs.length,
  14373. toIteratee = getIteratee();
  14374. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14375. if (typeof pair[1] != 'function') {
  14376. throw new TypeError(FUNC_ERROR_TEXT);
  14377. }
  14378. return [toIteratee(pair[0]), pair[1]];
  14379. });
  14380. return baseRest(function(args) {
  14381. var index = -1;
  14382. while (++index < length) {
  14383. var pair = pairs[index];
  14384. if (apply(pair[0], this, args)) {
  14385. return apply(pair[1], this, args);
  14386. }
  14387. }
  14388. });
  14389. }
  14390. /**
  14391. * Creates a function that invokes the predicate properties of `source` with
  14392. * the corresponding property values of a given object, returning `true` if
  14393. * all predicates return truthy, else `false`.
  14394. *
  14395. * **Note:** The created function is equivalent to `_.conformsTo` with
  14396. * `source` partially applied.
  14397. *
  14398. * @static
  14399. * @memberOf _
  14400. * @since 4.0.0
  14401. * @category Util
  14402. * @param {Object} source The object of property predicates to conform to.
  14403. * @returns {Function} Returns the new spec function.
  14404. * @example
  14405. *
  14406. * var objects = [
  14407. * { 'a': 2, 'b': 1 },
  14408. * { 'a': 1, 'b': 2 }
  14409. * ];
  14410. *
  14411. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14412. * // => [{ 'a': 1, 'b': 2 }]
  14413. */
  14414. function conforms(source) {
  14415. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14416. }
  14417. /**
  14418. * Creates a function that returns `value`.
  14419. *
  14420. * @static
  14421. * @memberOf _
  14422. * @since 2.4.0
  14423. * @category Util
  14424. * @param {*} value The value to return from the new function.
  14425. * @returns {Function} Returns the new constant function.
  14426. * @example
  14427. *
  14428. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14429. *
  14430. * console.log(objects);
  14431. * // => [{ 'a': 1 }, { 'a': 1 }]
  14432. *
  14433. * console.log(objects[0] === objects[1]);
  14434. * // => true
  14435. */
  14436. function constant(value) {
  14437. return function() {
  14438. return value;
  14439. };
  14440. }
  14441. /**
  14442. * Checks `value` to determine whether a default value should be returned in
  14443. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14444. * or `undefined`.
  14445. *
  14446. * @static
  14447. * @memberOf _
  14448. * @since 4.14.0
  14449. * @category Util
  14450. * @param {*} value The value to check.
  14451. * @param {*} defaultValue The default value.
  14452. * @returns {*} Returns the resolved value.
  14453. * @example
  14454. *
  14455. * _.defaultTo(1, 10);
  14456. * // => 1
  14457. *
  14458. * _.defaultTo(undefined, 10);
  14459. * // => 10
  14460. */
  14461. function defaultTo(value, defaultValue) {
  14462. return (value == null || value !== value) ? defaultValue : value;
  14463. }
  14464. /**
  14465. * Creates a function that returns the result of invoking the given functions
  14466. * with the `this` binding of the created function, where each successive
  14467. * invocation is supplied the return value of the previous.
  14468. *
  14469. * @static
  14470. * @memberOf _
  14471. * @since 3.0.0
  14472. * @category Util
  14473. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14474. * @returns {Function} Returns the new composite function.
  14475. * @see _.flowRight
  14476. * @example
  14477. *
  14478. * function square(n) {
  14479. * return n * n;
  14480. * }
  14481. *
  14482. * var addSquare = _.flow([_.add, square]);
  14483. * addSquare(1, 2);
  14484. * // => 9
  14485. */
  14486. var flow = createFlow();
  14487. /**
  14488. * This method is like `_.flow` except that it creates a function that
  14489. * invokes the given functions from right to left.
  14490. *
  14491. * @static
  14492. * @since 3.0.0
  14493. * @memberOf _
  14494. * @category Util
  14495. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14496. * @returns {Function} Returns the new composite function.
  14497. * @see _.flow
  14498. * @example
  14499. *
  14500. * function square(n) {
  14501. * return n * n;
  14502. * }
  14503. *
  14504. * var addSquare = _.flowRight([square, _.add]);
  14505. * addSquare(1, 2);
  14506. * // => 9
  14507. */
  14508. var flowRight = createFlow(true);
  14509. /**
  14510. * This method returns the first argument it receives.
  14511. *
  14512. * @static
  14513. * @since 0.1.0
  14514. * @memberOf _
  14515. * @category Util
  14516. * @param {*} value Any value.
  14517. * @returns {*} Returns `value`.
  14518. * @example
  14519. *
  14520. * var object = { 'a': 1 };
  14521. *
  14522. * console.log(_.identity(object) === object);
  14523. * // => true
  14524. */
  14525. function identity(value) {
  14526. return value;
  14527. }
  14528. /**
  14529. * Creates a function that invokes `func` with the arguments of the created
  14530. * function. If `func` is a property name, the created function returns the
  14531. * property value for a given element. If `func` is an array or object, the
  14532. * created function returns `true` for elements that contain the equivalent
  14533. * source properties, otherwise it returns `false`.
  14534. *
  14535. * @static
  14536. * @since 4.0.0
  14537. * @memberOf _
  14538. * @category Util
  14539. * @param {*} [func=_.identity] The value to convert to a callback.
  14540. * @returns {Function} Returns the callback.
  14541. * @example
  14542. *
  14543. * var users = [
  14544. * { 'user': 'barney', 'age': 36, 'active': true },
  14545. * { 'user': 'fred', 'age': 40, 'active': false }
  14546. * ];
  14547. *
  14548. * // The `_.matches` iteratee shorthand.
  14549. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14550. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14551. *
  14552. * // The `_.matchesProperty` iteratee shorthand.
  14553. * _.filter(users, _.iteratee(['user', 'fred']));
  14554. * // => [{ 'user': 'fred', 'age': 40 }]
  14555. *
  14556. * // The `_.property` iteratee shorthand.
  14557. * _.map(users, _.iteratee('user'));
  14558. * // => ['barney', 'fred']
  14559. *
  14560. * // Create custom iteratee shorthands.
  14561. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14562. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14563. * return func.test(string);
  14564. * };
  14565. * });
  14566. *
  14567. * _.filter(['abc', 'def'], /ef/);
  14568. * // => ['def']
  14569. */
  14570. function iteratee(func) {
  14571. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14572. }
  14573. /**
  14574. * Creates a function that performs a partial deep comparison between a given
  14575. * object and `source`, returning `true` if the given object has equivalent
  14576. * property values, else `false`.
  14577. *
  14578. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14579. * partially applied.
  14580. *
  14581. * Partial comparisons will match empty array and empty object `source`
  14582. * values against any array or object value, respectively. See `_.isEqual`
  14583. * for a list of supported value comparisons.
  14584. *
  14585. * @static
  14586. * @memberOf _
  14587. * @since 3.0.0
  14588. * @category Util
  14589. * @param {Object} source The object of property values to match.
  14590. * @returns {Function} Returns the new spec function.
  14591. * @example
  14592. *
  14593. * var objects = [
  14594. * { 'a': 1, 'b': 2, 'c': 3 },
  14595. * { 'a': 4, 'b': 5, 'c': 6 }
  14596. * ];
  14597. *
  14598. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14599. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14600. */
  14601. function matches(source) {
  14602. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14603. }
  14604. /**
  14605. * Creates a function that performs a partial deep comparison between the
  14606. * value at `path` of a given object to `srcValue`, returning `true` if the
  14607. * object value is equivalent, else `false`.
  14608. *
  14609. * **Note:** Partial comparisons will match empty array and empty object
  14610. * `srcValue` values against any array or object value, respectively. See
  14611. * `_.isEqual` for a list of supported value comparisons.
  14612. *
  14613. * @static
  14614. * @memberOf _
  14615. * @since 3.2.0
  14616. * @category Util
  14617. * @param {Array|string} path The path of the property to get.
  14618. * @param {*} srcValue The value to match.
  14619. * @returns {Function} Returns the new spec function.
  14620. * @example
  14621. *
  14622. * var objects = [
  14623. * { 'a': 1, 'b': 2, 'c': 3 },
  14624. * { 'a': 4, 'b': 5, 'c': 6 }
  14625. * ];
  14626. *
  14627. * _.find(objects, _.matchesProperty('a', 4));
  14628. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14629. */
  14630. function matchesProperty(path, srcValue) {
  14631. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14632. }
  14633. /**
  14634. * Creates a function that invokes the method at `path` of a given object.
  14635. * Any additional arguments are provided to the invoked method.
  14636. *
  14637. * @static
  14638. * @memberOf _
  14639. * @since 3.7.0
  14640. * @category Util
  14641. * @param {Array|string} path The path of the method to invoke.
  14642. * @param {...*} [args] The arguments to invoke the method with.
  14643. * @returns {Function} Returns the new invoker function.
  14644. * @example
  14645. *
  14646. * var objects = [
  14647. * { 'a': { 'b': _.constant(2) } },
  14648. * { 'a': { 'b': _.constant(1) } }
  14649. * ];
  14650. *
  14651. * _.map(objects, _.method('a.b'));
  14652. * // => [2, 1]
  14653. *
  14654. * _.map(objects, _.method(['a', 'b']));
  14655. * // => [2, 1]
  14656. */
  14657. var method = baseRest(function(path, args) {
  14658. return function(object) {
  14659. return baseInvoke(object, path, args);
  14660. };
  14661. });
  14662. /**
  14663. * The opposite of `_.method`; this method creates a function that invokes
  14664. * the method at a given path of `object`. Any additional arguments are
  14665. * provided to the invoked method.
  14666. *
  14667. * @static
  14668. * @memberOf _
  14669. * @since 3.7.0
  14670. * @category Util
  14671. * @param {Object} object The object to query.
  14672. * @param {...*} [args] The arguments to invoke the method with.
  14673. * @returns {Function} Returns the new invoker function.
  14674. * @example
  14675. *
  14676. * var array = _.times(3, _.constant),
  14677. * object = { 'a': array, 'b': array, 'c': array };
  14678. *
  14679. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14680. * // => [2, 0]
  14681. *
  14682. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14683. * // => [2, 0]
  14684. */
  14685. var methodOf = baseRest(function(object, args) {
  14686. return function(path) {
  14687. return baseInvoke(object, path, args);
  14688. };
  14689. });
  14690. /**
  14691. * Adds all own enumerable string keyed function properties of a source
  14692. * object to the destination object. If `object` is a function, then methods
  14693. * are added to its prototype as well.
  14694. *
  14695. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14696. * avoid conflicts caused by modifying the original.
  14697. *
  14698. * @static
  14699. * @since 0.1.0
  14700. * @memberOf _
  14701. * @category Util
  14702. * @param {Function|Object} [object=lodash] The destination object.
  14703. * @param {Object} source The object of functions to add.
  14704. * @param {Object} [options={}] The options object.
  14705. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14706. * @returns {Function|Object} Returns `object`.
  14707. * @example
  14708. *
  14709. * function vowels(string) {
  14710. * return _.filter(string, function(v) {
  14711. * return /[aeiou]/i.test(v);
  14712. * });
  14713. * }
  14714. *
  14715. * _.mixin({ 'vowels': vowels });
  14716. * _.vowels('fred');
  14717. * // => ['e']
  14718. *
  14719. * _('fred').vowels().value();
  14720. * // => ['e']
  14721. *
  14722. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14723. * _('fred').vowels();
  14724. * // => ['e']
  14725. */
  14726. function mixin(object, source, options) {
  14727. var props = keys(source),
  14728. methodNames = baseFunctions(source, props);
  14729. if (options == null &&
  14730. !(isObject(source) && (methodNames.length || !props.length))) {
  14731. options = source;
  14732. source = object;
  14733. object = this;
  14734. methodNames = baseFunctions(source, keys(source));
  14735. }
  14736. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14737. isFunc = isFunction(object);
  14738. arrayEach(methodNames, function(methodName) {
  14739. var func = source[methodName];
  14740. object[methodName] = func;
  14741. if (isFunc) {
  14742. object.prototype[methodName] = function() {
  14743. var chainAll = this.__chain__;
  14744. if (chain || chainAll) {
  14745. var result = object(this.__wrapped__),
  14746. actions = result.__actions__ = copyArray(this.__actions__);
  14747. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14748. result.__chain__ = chainAll;
  14749. return result;
  14750. }
  14751. return func.apply(object, arrayPush([this.value()], arguments));
  14752. };
  14753. }
  14754. });
  14755. return object;
  14756. }
  14757. /**
  14758. * Reverts the `_` variable to its previous value and returns a reference to
  14759. * the `lodash` function.
  14760. *
  14761. * @static
  14762. * @since 0.1.0
  14763. * @memberOf _
  14764. * @category Util
  14765. * @returns {Function} Returns the `lodash` function.
  14766. * @example
  14767. *
  14768. * var lodash = _.noConflict();
  14769. */
  14770. function noConflict() {
  14771. if (root._ === this) {
  14772. root._ = oldDash;
  14773. }
  14774. return this;
  14775. }
  14776. /**
  14777. * This method returns `undefined`.
  14778. *
  14779. * @static
  14780. * @memberOf _
  14781. * @since 2.3.0
  14782. * @category Util
  14783. * @example
  14784. *
  14785. * _.times(2, _.noop);
  14786. * // => [undefined, undefined]
  14787. */
  14788. function noop() {
  14789. // No operation performed.
  14790. }
  14791. /**
  14792. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14793. * the nth argument from the end is returned.
  14794. *
  14795. * @static
  14796. * @memberOf _
  14797. * @since 4.0.0
  14798. * @category Util
  14799. * @param {number} [n=0] The index of the argument to return.
  14800. * @returns {Function} Returns the new pass-thru function.
  14801. * @example
  14802. *
  14803. * var func = _.nthArg(1);
  14804. * func('a', 'b', 'c', 'd');
  14805. * // => 'b'
  14806. *
  14807. * var func = _.nthArg(-2);
  14808. * func('a', 'b', 'c', 'd');
  14809. * // => 'c'
  14810. */
  14811. function nthArg(n) {
  14812. n = toInteger(n);
  14813. return baseRest(function(args) {
  14814. return baseNth(args, n);
  14815. });
  14816. }
  14817. /**
  14818. * Creates a function that invokes `iteratees` with the arguments it receives
  14819. * and returns their results.
  14820. *
  14821. * @static
  14822. * @memberOf _
  14823. * @since 4.0.0
  14824. * @category Util
  14825. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14826. * The iteratees to invoke.
  14827. * @returns {Function} Returns the new function.
  14828. * @example
  14829. *
  14830. * var func = _.over([Math.max, Math.min]);
  14831. *
  14832. * func(1, 2, 3, 4);
  14833. * // => [4, 1]
  14834. */
  14835. var over = createOver(arrayMap);
  14836. /**
  14837. * Creates a function that checks if **all** of the `predicates` return
  14838. * truthy when invoked with the arguments it receives.
  14839. *
  14840. * @static
  14841. * @memberOf _
  14842. * @since 4.0.0
  14843. * @category Util
  14844. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14845. * The predicates to check.
  14846. * @returns {Function} Returns the new function.
  14847. * @example
  14848. *
  14849. * var func = _.overEvery([Boolean, isFinite]);
  14850. *
  14851. * func('1');
  14852. * // => true
  14853. *
  14854. * func(null);
  14855. * // => false
  14856. *
  14857. * func(NaN);
  14858. * // => false
  14859. */
  14860. var overEvery = createOver(arrayEvery);
  14861. /**
  14862. * Creates a function that checks if **any** of the `predicates` return
  14863. * truthy when invoked with the arguments it receives.
  14864. *
  14865. * @static
  14866. * @memberOf _
  14867. * @since 4.0.0
  14868. * @category Util
  14869. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14870. * The predicates to check.
  14871. * @returns {Function} Returns the new function.
  14872. * @example
  14873. *
  14874. * var func = _.overSome([Boolean, isFinite]);
  14875. *
  14876. * func('1');
  14877. * // => true
  14878. *
  14879. * func(null);
  14880. * // => true
  14881. *
  14882. * func(NaN);
  14883. * // => false
  14884. */
  14885. var overSome = createOver(arraySome);
  14886. /**
  14887. * Creates a function that returns the value at `path` of a given object.
  14888. *
  14889. * @static
  14890. * @memberOf _
  14891. * @since 2.4.0
  14892. * @category Util
  14893. * @param {Array|string} path The path of the property to get.
  14894. * @returns {Function} Returns the new accessor function.
  14895. * @example
  14896. *
  14897. * var objects = [
  14898. * { 'a': { 'b': 2 } },
  14899. * { 'a': { 'b': 1 } }
  14900. * ];
  14901. *
  14902. * _.map(objects, _.property('a.b'));
  14903. * // => [2, 1]
  14904. *
  14905. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14906. * // => [1, 2]
  14907. */
  14908. function property(path) {
  14909. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14910. }
  14911. /**
  14912. * The opposite of `_.property`; this method creates a function that returns
  14913. * the value at a given path of `object`.
  14914. *
  14915. * @static
  14916. * @memberOf _
  14917. * @since 3.0.0
  14918. * @category Util
  14919. * @param {Object} object The object to query.
  14920. * @returns {Function} Returns the new accessor function.
  14921. * @example
  14922. *
  14923. * var array = [0, 1, 2],
  14924. * object = { 'a': array, 'b': array, 'c': array };
  14925. *
  14926. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14927. * // => [2, 0]
  14928. *
  14929. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14930. * // => [2, 0]
  14931. */
  14932. function propertyOf(object) {
  14933. return function(path) {
  14934. return object == null ? undefined : baseGet(object, path);
  14935. };
  14936. }
  14937. /**
  14938. * Creates an array of numbers (positive and/or negative) progressing from
  14939. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14940. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14941. * it's set to `start` with `start` then set to `0`.
  14942. *
  14943. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14944. * floating-point values which can produce unexpected results.
  14945. *
  14946. * @static
  14947. * @since 0.1.0
  14948. * @memberOf _
  14949. * @category Util
  14950. * @param {number} [start=0] The start of the range.
  14951. * @param {number} end The end of the range.
  14952. * @param {number} [step=1] The value to increment or decrement by.
  14953. * @returns {Array} Returns the range of numbers.
  14954. * @see _.inRange, _.rangeRight
  14955. * @example
  14956. *
  14957. * _.range(4);
  14958. * // => [0, 1, 2, 3]
  14959. *
  14960. * _.range(-4);
  14961. * // => [0, -1, -2, -3]
  14962. *
  14963. * _.range(1, 5);
  14964. * // => [1, 2, 3, 4]
  14965. *
  14966. * _.range(0, 20, 5);
  14967. * // => [0, 5, 10, 15]
  14968. *
  14969. * _.range(0, -4, -1);
  14970. * // => [0, -1, -2, -3]
  14971. *
  14972. * _.range(1, 4, 0);
  14973. * // => [1, 1, 1]
  14974. *
  14975. * _.range(0);
  14976. * // => []
  14977. */
  14978. var range = createRange();
  14979. /**
  14980. * This method is like `_.range` except that it populates values in
  14981. * descending order.
  14982. *
  14983. * @static
  14984. * @memberOf _
  14985. * @since 4.0.0
  14986. * @category Util
  14987. * @param {number} [start=0] The start of the range.
  14988. * @param {number} end The end of the range.
  14989. * @param {number} [step=1] The value to increment or decrement by.
  14990. * @returns {Array} Returns the range of numbers.
  14991. * @see _.inRange, _.range
  14992. * @example
  14993. *
  14994. * _.rangeRight(4);
  14995. * // => [3, 2, 1, 0]
  14996. *
  14997. * _.rangeRight(-4);
  14998. * // => [-3, -2, -1, 0]
  14999. *
  15000. * _.rangeRight(1, 5);
  15001. * // => [4, 3, 2, 1]
  15002. *
  15003. * _.rangeRight(0, 20, 5);
  15004. * // => [15, 10, 5, 0]
  15005. *
  15006. * _.rangeRight(0, -4, -1);
  15007. * // => [-3, -2, -1, 0]
  15008. *
  15009. * _.rangeRight(1, 4, 0);
  15010. * // => [1, 1, 1]
  15011. *
  15012. * _.rangeRight(0);
  15013. * // => []
  15014. */
  15015. var rangeRight = createRange(true);
  15016. /**
  15017. * This method returns a new empty array.
  15018. *
  15019. * @static
  15020. * @memberOf _
  15021. * @since 4.13.0
  15022. * @category Util
  15023. * @returns {Array} Returns the new empty array.
  15024. * @example
  15025. *
  15026. * var arrays = _.times(2, _.stubArray);
  15027. *
  15028. * console.log(arrays);
  15029. * // => [[], []]
  15030. *
  15031. * console.log(arrays[0] === arrays[1]);
  15032. * // => false
  15033. */
  15034. function stubArray() {
  15035. return [];
  15036. }
  15037. /**
  15038. * This method returns `false`.
  15039. *
  15040. * @static
  15041. * @memberOf _
  15042. * @since 4.13.0
  15043. * @category Util
  15044. * @returns {boolean} Returns `false`.
  15045. * @example
  15046. *
  15047. * _.times(2, _.stubFalse);
  15048. * // => [false, false]
  15049. */
  15050. function stubFalse() {
  15051. return false;
  15052. }
  15053. /**
  15054. * This method returns a new empty object.
  15055. *
  15056. * @static
  15057. * @memberOf _
  15058. * @since 4.13.0
  15059. * @category Util
  15060. * @returns {Object} Returns the new empty object.
  15061. * @example
  15062. *
  15063. * var objects = _.times(2, _.stubObject);
  15064. *
  15065. * console.log(objects);
  15066. * // => [{}, {}]
  15067. *
  15068. * console.log(objects[0] === objects[1]);
  15069. * // => false
  15070. */
  15071. function stubObject() {
  15072. return {};
  15073. }
  15074. /**
  15075. * This method returns an empty string.
  15076. *
  15077. * @static
  15078. * @memberOf _
  15079. * @since 4.13.0
  15080. * @category Util
  15081. * @returns {string} Returns the empty string.
  15082. * @example
  15083. *
  15084. * _.times(2, _.stubString);
  15085. * // => ['', '']
  15086. */
  15087. function stubString() {
  15088. return '';
  15089. }
  15090. /**
  15091. * This method returns `true`.
  15092. *
  15093. * @static
  15094. * @memberOf _
  15095. * @since 4.13.0
  15096. * @category Util
  15097. * @returns {boolean} Returns `true`.
  15098. * @example
  15099. *
  15100. * _.times(2, _.stubTrue);
  15101. * // => [true, true]
  15102. */
  15103. function stubTrue() {
  15104. return true;
  15105. }
  15106. /**
  15107. * Invokes the iteratee `n` times, returning an array of the results of
  15108. * each invocation. The iteratee is invoked with one argument; (index).
  15109. *
  15110. * @static
  15111. * @since 0.1.0
  15112. * @memberOf _
  15113. * @category Util
  15114. * @param {number} n The number of times to invoke `iteratee`.
  15115. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15116. * @returns {Array} Returns the array of results.
  15117. * @example
  15118. *
  15119. * _.times(3, String);
  15120. * // => ['0', '1', '2']
  15121. *
  15122. * _.times(4, _.constant(0));
  15123. * // => [0, 0, 0, 0]
  15124. */
  15125. function times(n, iteratee) {
  15126. n = toInteger(n);
  15127. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15128. return [];
  15129. }
  15130. var index = MAX_ARRAY_LENGTH,
  15131. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15132. iteratee = getIteratee(iteratee);
  15133. n -= MAX_ARRAY_LENGTH;
  15134. var result = baseTimes(length, iteratee);
  15135. while (++index < n) {
  15136. iteratee(index);
  15137. }
  15138. return result;
  15139. }
  15140. /**
  15141. * Converts `value` to a property path array.
  15142. *
  15143. * @static
  15144. * @memberOf _
  15145. * @since 4.0.0
  15146. * @category Util
  15147. * @param {*} value The value to convert.
  15148. * @returns {Array} Returns the new property path array.
  15149. * @example
  15150. *
  15151. * _.toPath('a.b.c');
  15152. * // => ['a', 'b', 'c']
  15153. *
  15154. * _.toPath('a[0].b.c');
  15155. * // => ['a', '0', 'b', 'c']
  15156. */
  15157. function toPath(value) {
  15158. if (isArray(value)) {
  15159. return arrayMap(value, toKey);
  15160. }
  15161. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15162. }
  15163. /**
  15164. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15165. *
  15166. * @static
  15167. * @since 0.1.0
  15168. * @memberOf _
  15169. * @category Util
  15170. * @param {string} [prefix=''] The value to prefix the ID with.
  15171. * @returns {string} Returns the unique ID.
  15172. * @example
  15173. *
  15174. * _.uniqueId('contact_');
  15175. * // => 'contact_104'
  15176. *
  15177. * _.uniqueId();
  15178. * // => '105'
  15179. */
  15180. function uniqueId(prefix) {
  15181. var id = ++idCounter;
  15182. return toString(prefix) + id;
  15183. }
  15184. /*------------------------------------------------------------------------*/
  15185. /**
  15186. * Adds two numbers.
  15187. *
  15188. * @static
  15189. * @memberOf _
  15190. * @since 3.4.0
  15191. * @category Math
  15192. * @param {number} augend The first number in an addition.
  15193. * @param {number} addend The second number in an addition.
  15194. * @returns {number} Returns the total.
  15195. * @example
  15196. *
  15197. * _.add(6, 4);
  15198. * // => 10
  15199. */
  15200. var add = createMathOperation(function(augend, addend) {
  15201. return augend + addend;
  15202. }, 0);
  15203. /**
  15204. * Computes `number` rounded up to `precision`.
  15205. *
  15206. * @static
  15207. * @memberOf _
  15208. * @since 3.10.0
  15209. * @category Math
  15210. * @param {number} number The number to round up.
  15211. * @param {number} [precision=0] The precision to round up to.
  15212. * @returns {number} Returns the rounded up number.
  15213. * @example
  15214. *
  15215. * _.ceil(4.006);
  15216. * // => 5
  15217. *
  15218. * _.ceil(6.004, 2);
  15219. * // => 6.01
  15220. *
  15221. * _.ceil(6040, -2);
  15222. * // => 6100
  15223. */
  15224. var ceil = createRound('ceil');
  15225. /**
  15226. * Divide two numbers.
  15227. *
  15228. * @static
  15229. * @memberOf _
  15230. * @since 4.7.0
  15231. * @category Math
  15232. * @param {number} dividend The first number in a division.
  15233. * @param {number} divisor The second number in a division.
  15234. * @returns {number} Returns the quotient.
  15235. * @example
  15236. *
  15237. * _.divide(6, 4);
  15238. * // => 1.5
  15239. */
  15240. var divide = createMathOperation(function(dividend, divisor) {
  15241. return dividend / divisor;
  15242. }, 1);
  15243. /**
  15244. * Computes `number` rounded down to `precision`.
  15245. *
  15246. * @static
  15247. * @memberOf _
  15248. * @since 3.10.0
  15249. * @category Math
  15250. * @param {number} number The number to round down.
  15251. * @param {number} [precision=0] The precision to round down to.
  15252. * @returns {number} Returns the rounded down number.
  15253. * @example
  15254. *
  15255. * _.floor(4.006);
  15256. * // => 4
  15257. *
  15258. * _.floor(0.046, 2);
  15259. * // => 0.04
  15260. *
  15261. * _.floor(4060, -2);
  15262. * // => 4000
  15263. */
  15264. var floor = createRound('floor');
  15265. /**
  15266. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15267. * `undefined` is returned.
  15268. *
  15269. * @static
  15270. * @since 0.1.0
  15271. * @memberOf _
  15272. * @category Math
  15273. * @param {Array} array The array to iterate over.
  15274. * @returns {*} Returns the maximum value.
  15275. * @example
  15276. *
  15277. * _.max([4, 2, 8, 6]);
  15278. * // => 8
  15279. *
  15280. * _.max([]);
  15281. * // => undefined
  15282. */
  15283. function max(array) {
  15284. return (array && array.length)
  15285. ? baseExtremum(array, identity, baseGt)
  15286. : undefined;
  15287. }
  15288. /**
  15289. * This method is like `_.max` except that it accepts `iteratee` which is
  15290. * invoked for each element in `array` to generate the criterion by which
  15291. * the value is ranked. The iteratee is invoked with one argument: (value).
  15292. *
  15293. * @static
  15294. * @memberOf _
  15295. * @since 4.0.0
  15296. * @category Math
  15297. * @param {Array} array The array to iterate over.
  15298. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15299. * @returns {*} Returns the maximum value.
  15300. * @example
  15301. *
  15302. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15303. *
  15304. * _.maxBy(objects, function(o) { return o.n; });
  15305. * // => { 'n': 2 }
  15306. *
  15307. * // The `_.property` iteratee shorthand.
  15308. * _.maxBy(objects, 'n');
  15309. * // => { 'n': 2 }
  15310. */
  15311. function maxBy(array, iteratee) {
  15312. return (array && array.length)
  15313. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15314. : undefined;
  15315. }
  15316. /**
  15317. * Computes the mean of the values in `array`.
  15318. *
  15319. * @static
  15320. * @memberOf _
  15321. * @since 4.0.0
  15322. * @category Math
  15323. * @param {Array} array The array to iterate over.
  15324. * @returns {number} Returns the mean.
  15325. * @example
  15326. *
  15327. * _.mean([4, 2, 8, 6]);
  15328. * // => 5
  15329. */
  15330. function mean(array) {
  15331. return baseMean(array, identity);
  15332. }
  15333. /**
  15334. * This method is like `_.mean` except that it accepts `iteratee` which is
  15335. * invoked for each element in `array` to generate the value to be averaged.
  15336. * The iteratee is invoked with one argument: (value).
  15337. *
  15338. * @static
  15339. * @memberOf _
  15340. * @since 4.7.0
  15341. * @category Math
  15342. * @param {Array} array The array to iterate over.
  15343. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15344. * @returns {number} Returns the mean.
  15345. * @example
  15346. *
  15347. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15348. *
  15349. * _.meanBy(objects, function(o) { return o.n; });
  15350. * // => 5
  15351. *
  15352. * // The `_.property` iteratee shorthand.
  15353. * _.meanBy(objects, 'n');
  15354. * // => 5
  15355. */
  15356. function meanBy(array, iteratee) {
  15357. return baseMean(array, getIteratee(iteratee, 2));
  15358. }
  15359. /**
  15360. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15361. * `undefined` is returned.
  15362. *
  15363. * @static
  15364. * @since 0.1.0
  15365. * @memberOf _
  15366. * @category Math
  15367. * @param {Array} array The array to iterate over.
  15368. * @returns {*} Returns the minimum value.
  15369. * @example
  15370. *
  15371. * _.min([4, 2, 8, 6]);
  15372. * // => 2
  15373. *
  15374. * _.min([]);
  15375. * // => undefined
  15376. */
  15377. function min(array) {
  15378. return (array && array.length)
  15379. ? baseExtremum(array, identity, baseLt)
  15380. : undefined;
  15381. }
  15382. /**
  15383. * This method is like `_.min` except that it accepts `iteratee` which is
  15384. * invoked for each element in `array` to generate the criterion by which
  15385. * the value is ranked. The iteratee is invoked with one argument: (value).
  15386. *
  15387. * @static
  15388. * @memberOf _
  15389. * @since 4.0.0
  15390. * @category Math
  15391. * @param {Array} array The array to iterate over.
  15392. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15393. * @returns {*} Returns the minimum value.
  15394. * @example
  15395. *
  15396. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15397. *
  15398. * _.minBy(objects, function(o) { return o.n; });
  15399. * // => { 'n': 1 }
  15400. *
  15401. * // The `_.property` iteratee shorthand.
  15402. * _.minBy(objects, 'n');
  15403. * // => { 'n': 1 }
  15404. */
  15405. function minBy(array, iteratee) {
  15406. return (array && array.length)
  15407. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15408. : undefined;
  15409. }
  15410. /**
  15411. * Multiply two numbers.
  15412. *
  15413. * @static
  15414. * @memberOf _
  15415. * @since 4.7.0
  15416. * @category Math
  15417. * @param {number} multiplier The first number in a multiplication.
  15418. * @param {number} multiplicand The second number in a multiplication.
  15419. * @returns {number} Returns the product.
  15420. * @example
  15421. *
  15422. * _.multiply(6, 4);
  15423. * // => 24
  15424. */
  15425. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15426. return multiplier * multiplicand;
  15427. }, 1);
  15428. /**
  15429. * Computes `number` rounded to `precision`.
  15430. *
  15431. * @static
  15432. * @memberOf _
  15433. * @since 3.10.0
  15434. * @category Math
  15435. * @param {number} number The number to round.
  15436. * @param {number} [precision=0] The precision to round to.
  15437. * @returns {number} Returns the rounded number.
  15438. * @example
  15439. *
  15440. * _.round(4.006);
  15441. * // => 4
  15442. *
  15443. * _.round(4.006, 2);
  15444. * // => 4.01
  15445. *
  15446. * _.round(4060, -2);
  15447. * // => 4100
  15448. */
  15449. var round = createRound('round');
  15450. /**
  15451. * Subtract two numbers.
  15452. *
  15453. * @static
  15454. * @memberOf _
  15455. * @since 4.0.0
  15456. * @category Math
  15457. * @param {number} minuend The first number in a subtraction.
  15458. * @param {number} subtrahend The second number in a subtraction.
  15459. * @returns {number} Returns the difference.
  15460. * @example
  15461. *
  15462. * _.subtract(6, 4);
  15463. * // => 2
  15464. */
  15465. var subtract = createMathOperation(function(minuend, subtrahend) {
  15466. return minuend - subtrahend;
  15467. }, 0);
  15468. /**
  15469. * Computes the sum of the values in `array`.
  15470. *
  15471. * @static
  15472. * @memberOf _
  15473. * @since 3.4.0
  15474. * @category Math
  15475. * @param {Array} array The array to iterate over.
  15476. * @returns {number} Returns the sum.
  15477. * @example
  15478. *
  15479. * _.sum([4, 2, 8, 6]);
  15480. * // => 20
  15481. */
  15482. function sum(array) {
  15483. return (array && array.length)
  15484. ? baseSum(array, identity)
  15485. : 0;
  15486. }
  15487. /**
  15488. * This method is like `_.sum` except that it accepts `iteratee` which is
  15489. * invoked for each element in `array` to generate the value to be summed.
  15490. * The iteratee is invoked with one argument: (value).
  15491. *
  15492. * @static
  15493. * @memberOf _
  15494. * @since 4.0.0
  15495. * @category Math
  15496. * @param {Array} array The array to iterate over.
  15497. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15498. * @returns {number} Returns the sum.
  15499. * @example
  15500. *
  15501. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15502. *
  15503. * _.sumBy(objects, function(o) { return o.n; });
  15504. * // => 20
  15505. *
  15506. * // The `_.property` iteratee shorthand.
  15507. * _.sumBy(objects, 'n');
  15508. * // => 20
  15509. */
  15510. function sumBy(array, iteratee) {
  15511. return (array && array.length)
  15512. ? baseSum(array, getIteratee(iteratee, 2))
  15513. : 0;
  15514. }
  15515. /*------------------------------------------------------------------------*/
  15516. // Add methods that return wrapped values in chain sequences.
  15517. lodash.after = after;
  15518. lodash.ary = ary;
  15519. lodash.assign = assign;
  15520. lodash.assignIn = assignIn;
  15521. lodash.assignInWith = assignInWith;
  15522. lodash.assignWith = assignWith;
  15523. lodash.at = at;
  15524. lodash.before = before;
  15525. lodash.bind = bind;
  15526. lodash.bindAll = bindAll;
  15527. lodash.bindKey = bindKey;
  15528. lodash.castArray = castArray;
  15529. lodash.chain = chain;
  15530. lodash.chunk = chunk;
  15531. lodash.compact = compact;
  15532. lodash.concat = concat;
  15533. lodash.cond = cond;
  15534. lodash.conforms = conforms;
  15535. lodash.constant = constant;
  15536. lodash.countBy = countBy;
  15537. lodash.create = create;
  15538. lodash.curry = curry;
  15539. lodash.curryRight = curryRight;
  15540. lodash.debounce = debounce;
  15541. lodash.defaults = defaults;
  15542. lodash.defaultsDeep = defaultsDeep;
  15543. lodash.defer = defer;
  15544. lodash.delay = delay;
  15545. lodash.difference = difference;
  15546. lodash.differenceBy = differenceBy;
  15547. lodash.differenceWith = differenceWith;
  15548. lodash.drop = drop;
  15549. lodash.dropRight = dropRight;
  15550. lodash.dropRightWhile = dropRightWhile;
  15551. lodash.dropWhile = dropWhile;
  15552. lodash.fill = fill;
  15553. lodash.filter = filter;
  15554. lodash.flatMap = flatMap;
  15555. lodash.flatMapDeep = flatMapDeep;
  15556. lodash.flatMapDepth = flatMapDepth;
  15557. lodash.flatten = flatten;
  15558. lodash.flattenDeep = flattenDeep;
  15559. lodash.flattenDepth = flattenDepth;
  15560. lodash.flip = flip;
  15561. lodash.flow = flow;
  15562. lodash.flowRight = flowRight;
  15563. lodash.fromPairs = fromPairs;
  15564. lodash.functions = functions;
  15565. lodash.functionsIn = functionsIn;
  15566. lodash.groupBy = groupBy;
  15567. lodash.initial = initial;
  15568. lodash.intersection = intersection;
  15569. lodash.intersectionBy = intersectionBy;
  15570. lodash.intersectionWith = intersectionWith;
  15571. lodash.invert = invert;
  15572. lodash.invertBy = invertBy;
  15573. lodash.invokeMap = invokeMap;
  15574. lodash.iteratee = iteratee;
  15575. lodash.keyBy = keyBy;
  15576. lodash.keys = keys;
  15577. lodash.keysIn = keysIn;
  15578. lodash.map = map;
  15579. lodash.mapKeys = mapKeys;
  15580. lodash.mapValues = mapValues;
  15581. lodash.matches = matches;
  15582. lodash.matchesProperty = matchesProperty;
  15583. lodash.memoize = memoize;
  15584. lodash.merge = merge;
  15585. lodash.mergeWith = mergeWith;
  15586. lodash.method = method;
  15587. lodash.methodOf = methodOf;
  15588. lodash.mixin = mixin;
  15589. lodash.negate = negate;
  15590. lodash.nthArg = nthArg;
  15591. lodash.omit = omit;
  15592. lodash.omitBy = omitBy;
  15593. lodash.once = once;
  15594. lodash.orderBy = orderBy;
  15595. lodash.over = over;
  15596. lodash.overArgs = overArgs;
  15597. lodash.overEvery = overEvery;
  15598. lodash.overSome = overSome;
  15599. lodash.partial = partial;
  15600. lodash.partialRight = partialRight;
  15601. lodash.partition = partition;
  15602. lodash.pick = pick;
  15603. lodash.pickBy = pickBy;
  15604. lodash.property = property;
  15605. lodash.propertyOf = propertyOf;
  15606. lodash.pull = pull;
  15607. lodash.pullAll = pullAll;
  15608. lodash.pullAllBy = pullAllBy;
  15609. lodash.pullAllWith = pullAllWith;
  15610. lodash.pullAt = pullAt;
  15611. lodash.range = range;
  15612. lodash.rangeRight = rangeRight;
  15613. lodash.rearg = rearg;
  15614. lodash.reject = reject;
  15615. lodash.remove = remove;
  15616. lodash.rest = rest;
  15617. lodash.reverse = reverse;
  15618. lodash.sampleSize = sampleSize;
  15619. lodash.set = set;
  15620. lodash.setWith = setWith;
  15621. lodash.shuffle = shuffle;
  15622. lodash.slice = slice;
  15623. lodash.sortBy = sortBy;
  15624. lodash.sortedUniq = sortedUniq;
  15625. lodash.sortedUniqBy = sortedUniqBy;
  15626. lodash.split = split;
  15627. lodash.spread = spread;
  15628. lodash.tail = tail;
  15629. lodash.take = take;
  15630. lodash.takeRight = takeRight;
  15631. lodash.takeRightWhile = takeRightWhile;
  15632. lodash.takeWhile = takeWhile;
  15633. lodash.tap = tap;
  15634. lodash.throttle = throttle;
  15635. lodash.thru = thru;
  15636. lodash.toArray = toArray;
  15637. lodash.toPairs = toPairs;
  15638. lodash.toPairsIn = toPairsIn;
  15639. lodash.toPath = toPath;
  15640. lodash.toPlainObject = toPlainObject;
  15641. lodash.transform = transform;
  15642. lodash.unary = unary;
  15643. lodash.union = union;
  15644. lodash.unionBy = unionBy;
  15645. lodash.unionWith = unionWith;
  15646. lodash.uniq = uniq;
  15647. lodash.uniqBy = uniqBy;
  15648. lodash.uniqWith = uniqWith;
  15649. lodash.unset = unset;
  15650. lodash.unzip = unzip;
  15651. lodash.unzipWith = unzipWith;
  15652. lodash.update = update;
  15653. lodash.updateWith = updateWith;
  15654. lodash.values = values;
  15655. lodash.valuesIn = valuesIn;
  15656. lodash.without = without;
  15657. lodash.words = words;
  15658. lodash.wrap = wrap;
  15659. lodash.xor = xor;
  15660. lodash.xorBy = xorBy;
  15661. lodash.xorWith = xorWith;
  15662. lodash.zip = zip;
  15663. lodash.zipObject = zipObject;
  15664. lodash.zipObjectDeep = zipObjectDeep;
  15665. lodash.zipWith = zipWith;
  15666. // Add aliases.
  15667. lodash.entries = toPairs;
  15668. lodash.entriesIn = toPairsIn;
  15669. lodash.extend = assignIn;
  15670. lodash.extendWith = assignInWith;
  15671. // Add methods to `lodash.prototype`.
  15672. mixin(lodash, lodash);
  15673. /*------------------------------------------------------------------------*/
  15674. // Add methods that return unwrapped values in chain sequences.
  15675. lodash.add = add;
  15676. lodash.attempt = attempt;
  15677. lodash.camelCase = camelCase;
  15678. lodash.capitalize = capitalize;
  15679. lodash.ceil = ceil;
  15680. lodash.clamp = clamp;
  15681. lodash.clone = clone;
  15682. lodash.cloneDeep = cloneDeep;
  15683. lodash.cloneDeepWith = cloneDeepWith;
  15684. lodash.cloneWith = cloneWith;
  15685. lodash.conformsTo = conformsTo;
  15686. lodash.deburr = deburr;
  15687. lodash.defaultTo = defaultTo;
  15688. lodash.divide = divide;
  15689. lodash.endsWith = endsWith;
  15690. lodash.eq = eq;
  15691. lodash.escape = escape;
  15692. lodash.escapeRegExp = escapeRegExp;
  15693. lodash.every = every;
  15694. lodash.find = find;
  15695. lodash.findIndex = findIndex;
  15696. lodash.findKey = findKey;
  15697. lodash.findLast = findLast;
  15698. lodash.findLastIndex = findLastIndex;
  15699. lodash.findLastKey = findLastKey;
  15700. lodash.floor = floor;
  15701. lodash.forEach = forEach;
  15702. lodash.forEachRight = forEachRight;
  15703. lodash.forIn = forIn;
  15704. lodash.forInRight = forInRight;
  15705. lodash.forOwn = forOwn;
  15706. lodash.forOwnRight = forOwnRight;
  15707. lodash.get = get;
  15708. lodash.gt = gt;
  15709. lodash.gte = gte;
  15710. lodash.has = has;
  15711. lodash.hasIn = hasIn;
  15712. lodash.head = head;
  15713. lodash.identity = identity;
  15714. lodash.includes = includes;
  15715. lodash.indexOf = indexOf;
  15716. lodash.inRange = inRange;
  15717. lodash.invoke = invoke;
  15718. lodash.isArguments = isArguments;
  15719. lodash.isArray = isArray;
  15720. lodash.isArrayBuffer = isArrayBuffer;
  15721. lodash.isArrayLike = isArrayLike;
  15722. lodash.isArrayLikeObject = isArrayLikeObject;
  15723. lodash.isBoolean = isBoolean;
  15724. lodash.isBuffer = isBuffer;
  15725. lodash.isDate = isDate;
  15726. lodash.isElement = isElement;
  15727. lodash.isEmpty = isEmpty;
  15728. lodash.isEqual = isEqual;
  15729. lodash.isEqualWith = isEqualWith;
  15730. lodash.isError = isError;
  15731. lodash.isFinite = isFinite;
  15732. lodash.isFunction = isFunction;
  15733. lodash.isInteger = isInteger;
  15734. lodash.isLength = isLength;
  15735. lodash.isMap = isMap;
  15736. lodash.isMatch = isMatch;
  15737. lodash.isMatchWith = isMatchWith;
  15738. lodash.isNaN = isNaN;
  15739. lodash.isNative = isNative;
  15740. lodash.isNil = isNil;
  15741. lodash.isNull = isNull;
  15742. lodash.isNumber = isNumber;
  15743. lodash.isObject = isObject;
  15744. lodash.isObjectLike = isObjectLike;
  15745. lodash.isPlainObject = isPlainObject;
  15746. lodash.isRegExp = isRegExp;
  15747. lodash.isSafeInteger = isSafeInteger;
  15748. lodash.isSet = isSet;
  15749. lodash.isString = isString;
  15750. lodash.isSymbol = isSymbol;
  15751. lodash.isTypedArray = isTypedArray;
  15752. lodash.isUndefined = isUndefined;
  15753. lodash.isWeakMap = isWeakMap;
  15754. lodash.isWeakSet = isWeakSet;
  15755. lodash.join = join;
  15756. lodash.kebabCase = kebabCase;
  15757. lodash.last = last;
  15758. lodash.lastIndexOf = lastIndexOf;
  15759. lodash.lowerCase = lowerCase;
  15760. lodash.lowerFirst = lowerFirst;
  15761. lodash.lt = lt;
  15762. lodash.lte = lte;
  15763. lodash.max = max;
  15764. lodash.maxBy = maxBy;
  15765. lodash.mean = mean;
  15766. lodash.meanBy = meanBy;
  15767. lodash.min = min;
  15768. lodash.minBy = minBy;
  15769. lodash.stubArray = stubArray;
  15770. lodash.stubFalse = stubFalse;
  15771. lodash.stubObject = stubObject;
  15772. lodash.stubString = stubString;
  15773. lodash.stubTrue = stubTrue;
  15774. lodash.multiply = multiply;
  15775. lodash.nth = nth;
  15776. lodash.noConflict = noConflict;
  15777. lodash.noop = noop;
  15778. lodash.now = now;
  15779. lodash.pad = pad;
  15780. lodash.padEnd = padEnd;
  15781. lodash.padStart = padStart;
  15782. lodash.parseInt = parseInt;
  15783. lodash.random = random;
  15784. lodash.reduce = reduce;
  15785. lodash.reduceRight = reduceRight;
  15786. lodash.repeat = repeat;
  15787. lodash.replace = replace;
  15788. lodash.result = result;
  15789. lodash.round = round;
  15790. lodash.runInContext = runInContext;
  15791. lodash.sample = sample;
  15792. lodash.size = size;
  15793. lodash.snakeCase = snakeCase;
  15794. lodash.some = some;
  15795. lodash.sortedIndex = sortedIndex;
  15796. lodash.sortedIndexBy = sortedIndexBy;
  15797. lodash.sortedIndexOf = sortedIndexOf;
  15798. lodash.sortedLastIndex = sortedLastIndex;
  15799. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15800. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15801. lodash.startCase = startCase;
  15802. lodash.startsWith = startsWith;
  15803. lodash.subtract = subtract;
  15804. lodash.sum = sum;
  15805. lodash.sumBy = sumBy;
  15806. lodash.template = template;
  15807. lodash.times = times;
  15808. lodash.toFinite = toFinite;
  15809. lodash.toInteger = toInteger;
  15810. lodash.toLength = toLength;
  15811. lodash.toLower = toLower;
  15812. lodash.toNumber = toNumber;
  15813. lodash.toSafeInteger = toSafeInteger;
  15814. lodash.toString = toString;
  15815. lodash.toUpper = toUpper;
  15816. lodash.trim = trim;
  15817. lodash.trimEnd = trimEnd;
  15818. lodash.trimStart = trimStart;
  15819. lodash.truncate = truncate;
  15820. lodash.unescape = unescape;
  15821. lodash.uniqueId = uniqueId;
  15822. lodash.upperCase = upperCase;
  15823. lodash.upperFirst = upperFirst;
  15824. // Add aliases.
  15825. lodash.each = forEach;
  15826. lodash.eachRight = forEachRight;
  15827. lodash.first = head;
  15828. mixin(lodash, (function() {
  15829. var source = {};
  15830. baseForOwn(lodash, function(func, methodName) {
  15831. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15832. source[methodName] = func;
  15833. }
  15834. });
  15835. return source;
  15836. }()), { 'chain': false });
  15837. /*------------------------------------------------------------------------*/
  15838. /**
  15839. * The semantic version number.
  15840. *
  15841. * @static
  15842. * @memberOf _
  15843. * @type {string}
  15844. */
  15845. lodash.VERSION = VERSION;
  15846. // Assign default placeholders.
  15847. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15848. lodash[methodName].placeholder = lodash;
  15849. });
  15850. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15851. arrayEach(['drop', 'take'], function(methodName, index) {
  15852. LazyWrapper.prototype[methodName] = function(n) {
  15853. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15854. var result = (this.__filtered__ && !index)
  15855. ? new LazyWrapper(this)
  15856. : this.clone();
  15857. if (result.__filtered__) {
  15858. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15859. } else {
  15860. result.__views__.push({
  15861. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15862. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15863. });
  15864. }
  15865. return result;
  15866. };
  15867. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15868. return this.reverse()[methodName](n).reverse();
  15869. };
  15870. });
  15871. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15872. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15873. var type = index + 1,
  15874. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15875. LazyWrapper.prototype[methodName] = function(iteratee) {
  15876. var result = this.clone();
  15877. result.__iteratees__.push({
  15878. 'iteratee': getIteratee(iteratee, 3),
  15879. 'type': type
  15880. });
  15881. result.__filtered__ = result.__filtered__ || isFilter;
  15882. return result;
  15883. };
  15884. });
  15885. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15886. arrayEach(['head', 'last'], function(methodName, index) {
  15887. var takeName = 'take' + (index ? 'Right' : '');
  15888. LazyWrapper.prototype[methodName] = function() {
  15889. return this[takeName](1).value()[0];
  15890. };
  15891. });
  15892. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15893. arrayEach(['initial', 'tail'], function(methodName, index) {
  15894. var dropName = 'drop' + (index ? '' : 'Right');
  15895. LazyWrapper.prototype[methodName] = function() {
  15896. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15897. };
  15898. });
  15899. LazyWrapper.prototype.compact = function() {
  15900. return this.filter(identity);
  15901. };
  15902. LazyWrapper.prototype.find = function(predicate) {
  15903. return this.filter(predicate).head();
  15904. };
  15905. LazyWrapper.prototype.findLast = function(predicate) {
  15906. return this.reverse().find(predicate);
  15907. };
  15908. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15909. if (typeof path == 'function') {
  15910. return new LazyWrapper(this);
  15911. }
  15912. return this.map(function(value) {
  15913. return baseInvoke(value, path, args);
  15914. });
  15915. });
  15916. LazyWrapper.prototype.reject = function(predicate) {
  15917. return this.filter(negate(getIteratee(predicate)));
  15918. };
  15919. LazyWrapper.prototype.slice = function(start, end) {
  15920. start = toInteger(start);
  15921. var result = this;
  15922. if (result.__filtered__ && (start > 0 || end < 0)) {
  15923. return new LazyWrapper(result);
  15924. }
  15925. if (start < 0) {
  15926. result = result.takeRight(-start);
  15927. } else if (start) {
  15928. result = result.drop(start);
  15929. }
  15930. if (end !== undefined) {
  15931. end = toInteger(end);
  15932. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15933. }
  15934. return result;
  15935. };
  15936. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15937. return this.reverse().takeWhile(predicate).reverse();
  15938. };
  15939. LazyWrapper.prototype.toArray = function() {
  15940. return this.take(MAX_ARRAY_LENGTH);
  15941. };
  15942. // Add `LazyWrapper` methods to `lodash.prototype`.
  15943. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15944. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15945. isTaker = /^(?:head|last)$/.test(methodName),
  15946. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15947. retUnwrapped = isTaker || /^find/.test(methodName);
  15948. if (!lodashFunc) {
  15949. return;
  15950. }
  15951. lodash.prototype[methodName] = function() {
  15952. var value = this.__wrapped__,
  15953. args = isTaker ? [1] : arguments,
  15954. isLazy = value instanceof LazyWrapper,
  15955. iteratee = args[0],
  15956. useLazy = isLazy || isArray(value);
  15957. var interceptor = function(value) {
  15958. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15959. return (isTaker && chainAll) ? result[0] : result;
  15960. };
  15961. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15962. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15963. isLazy = useLazy = false;
  15964. }
  15965. var chainAll = this.__chain__,
  15966. isHybrid = !!this.__actions__.length,
  15967. isUnwrapped = retUnwrapped && !chainAll,
  15968. onlyLazy = isLazy && !isHybrid;
  15969. if (!retUnwrapped && useLazy) {
  15970. value = onlyLazy ? value : new LazyWrapper(this);
  15971. var result = func.apply(value, args);
  15972. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15973. return new LodashWrapper(result, chainAll);
  15974. }
  15975. if (isUnwrapped && onlyLazy) {
  15976. return func.apply(this, args);
  15977. }
  15978. result = this.thru(interceptor);
  15979. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15980. };
  15981. });
  15982. // Add `Array` methods to `lodash.prototype`.
  15983. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15984. var func = arrayProto[methodName],
  15985. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15986. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15987. lodash.prototype[methodName] = function() {
  15988. var args = arguments;
  15989. if (retUnwrapped && !this.__chain__) {
  15990. var value = this.value();
  15991. return func.apply(isArray(value) ? value : [], args);
  15992. }
  15993. return this[chainName](function(value) {
  15994. return func.apply(isArray(value) ? value : [], args);
  15995. });
  15996. };
  15997. });
  15998. // Map minified method names to their real names.
  15999. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16000. var lodashFunc = lodash[methodName];
  16001. if (lodashFunc) {
  16002. var key = (lodashFunc.name + ''),
  16003. names = realNames[key] || (realNames[key] = []);
  16004. names.push({ 'name': methodName, 'func': lodashFunc });
  16005. }
  16006. });
  16007. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16008. 'name': 'wrapper',
  16009. 'func': undefined
  16010. }];
  16011. // Add methods to `LazyWrapper`.
  16012. LazyWrapper.prototype.clone = lazyClone;
  16013. LazyWrapper.prototype.reverse = lazyReverse;
  16014. LazyWrapper.prototype.value = lazyValue;
  16015. // Add chain sequence methods to the `lodash` wrapper.
  16016. lodash.prototype.at = wrapperAt;
  16017. lodash.prototype.chain = wrapperChain;
  16018. lodash.prototype.commit = wrapperCommit;
  16019. lodash.prototype.next = wrapperNext;
  16020. lodash.prototype.plant = wrapperPlant;
  16021. lodash.prototype.reverse = wrapperReverse;
  16022. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16023. // Add lazy aliases.
  16024. lodash.prototype.first = lodash.prototype.head;
  16025. if (symIterator) {
  16026. lodash.prototype[symIterator] = wrapperToIterator;
  16027. }
  16028. return lodash;
  16029. });
  16030. /*--------------------------------------------------------------------------*/
  16031. // Export lodash.
  16032. var _ = runInContext();
  16033. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16034. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16035. // Expose Lodash on the global object to prevent errors when Lodash is
  16036. // loaded by a script tag in the presence of an AMD loader.
  16037. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16038. // Use `_.noConflict` to remove Lodash from the global object.
  16039. root._ = _;
  16040. // Define as an anonymous module so, through path mapping, it can be
  16041. // referenced as the "underscore" module.
  16042. define(function() {
  16043. return _;
  16044. });
  16045. }
  16046. // Check for `exports` after `define` in case a build optimizer adds it.
  16047. else if (freeModule) {
  16048. // Export for Node.js.
  16049. (freeModule.exports = _)._ = _;
  16050. // Export for CommonJS support.
  16051. freeExports._ = _;
  16052. }
  16053. else {
  16054. // Export to the global object.
  16055. root._ = _;
  16056. }
  16057. }.call(this));