lodash.js 527 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.17.10';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function';
  19. /** Used to stand-in for `undefined` hash values. */
  20. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21. /** Used as the maximum memoize cache size. */
  22. var MAX_MEMOIZE_SIZE = 500;
  23. /** Used as the internal argument placeholder. */
  24. var PLACEHOLDER = '__lodash_placeholder__';
  25. /** Used to compose bitmasks for cloning. */
  26. var CLONE_DEEP_FLAG = 1,
  27. CLONE_FLAT_FLAG = 2,
  28. CLONE_SYMBOLS_FLAG = 4;
  29. /** Used to compose bitmasks for value comparisons. */
  30. var COMPARE_PARTIAL_FLAG = 1,
  31. COMPARE_UNORDERED_FLAG = 2;
  32. /** Used to compose bitmasks for function metadata. */
  33. var WRAP_BIND_FLAG = 1,
  34. WRAP_BIND_KEY_FLAG = 2,
  35. WRAP_CURRY_BOUND_FLAG = 4,
  36. WRAP_CURRY_FLAG = 8,
  37. WRAP_CURRY_RIGHT_FLAG = 16,
  38. WRAP_PARTIAL_FLAG = 32,
  39. WRAP_PARTIAL_RIGHT_FLAG = 64,
  40. WRAP_ARY_FLAG = 128,
  41. WRAP_REARG_FLAG = 256,
  42. WRAP_FLIP_FLAG = 512;
  43. /** Used as default options for `_.truncate`. */
  44. var DEFAULT_TRUNC_LENGTH = 30,
  45. DEFAULT_TRUNC_OMISSION = '...';
  46. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  47. var HOT_COUNT = 800,
  48. HOT_SPAN = 16;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for various `Number` constants. */
  54. var INFINITY = 1 / 0,
  55. MAX_SAFE_INTEGER = 9007199254740991,
  56. MAX_INTEGER = 1.7976931348623157e+308,
  57. NAN = 0 / 0;
  58. /** Used as references for the maximum length and index of an array. */
  59. var MAX_ARRAY_LENGTH = 4294967295,
  60. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  61. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  62. /** Used to associate wrap methods with their bit flags. */
  63. var wrapFlags = [
  64. ['ary', WRAP_ARY_FLAG],
  65. ['bind', WRAP_BIND_FLAG],
  66. ['bindKey', WRAP_BIND_KEY_FLAG],
  67. ['curry', WRAP_CURRY_FLAG],
  68. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  69. ['flip', WRAP_FLIP_FLAG],
  70. ['partial', WRAP_PARTIAL_FLAG],
  71. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  72. ['rearg', WRAP_REARG_FLAG]
  73. ];
  74. /** `Object#toString` result references. */
  75. var argsTag = '[object Arguments]',
  76. arrayTag = '[object Array]',
  77. asyncTag = '[object AsyncFunction]',
  78. boolTag = '[object Boolean]',
  79. dateTag = '[object Date]',
  80. domExcTag = '[object DOMException]',
  81. errorTag = '[object Error]',
  82. funcTag = '[object Function]',
  83. genTag = '[object GeneratorFunction]',
  84. mapTag = '[object Map]',
  85. numberTag = '[object Number]',
  86. nullTag = '[object Null]',
  87. objectTag = '[object Object]',
  88. promiseTag = '[object Promise]',
  89. proxyTag = '[object Proxy]',
  90. regexpTag = '[object RegExp]',
  91. setTag = '[object Set]',
  92. stringTag = '[object String]',
  93. symbolTag = '[object Symbol]',
  94. undefinedTag = '[object Undefined]',
  95. weakMapTag = '[object WeakMap]',
  96. weakSetTag = '[object WeakSet]';
  97. var arrayBufferTag = '[object ArrayBuffer]',
  98. dataViewTag = '[object DataView]',
  99. float32Tag = '[object Float32Array]',
  100. float64Tag = '[object Float64Array]',
  101. int8Tag = '[object Int8Array]',
  102. int16Tag = '[object Int16Array]',
  103. int32Tag = '[object Int32Array]',
  104. uint8Tag = '[object Uint8Array]',
  105. uint8ClampedTag = '[object Uint8ClampedArray]',
  106. uint16Tag = '[object Uint16Array]',
  107. uint32Tag = '[object Uint32Array]';
  108. /** Used to match empty string literals in compiled template source. */
  109. var reEmptyStringLeading = /\b__p \+= '';/g,
  110. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  111. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  112. /** Used to match HTML entities and HTML characters. */
  113. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  114. reUnescapedHtml = /[&<>"']/g,
  115. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  116. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  117. /** Used to match template delimiters. */
  118. var reEscape = /<%-([\s\S]+?)%>/g,
  119. reEvaluate = /<%([\s\S]+?)%>/g,
  120. reInterpolate = /<%=([\s\S]+?)%>/g;
  121. /** Used to match property names within property paths. */
  122. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  123. reIsPlainProp = /^\w*$/,
  124. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  125. /**
  126. * Used to match `RegExp`
  127. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  128. */
  129. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  130. reHasRegExpChar = RegExp(reRegExpChar.source);
  131. /** Used to match leading and trailing whitespace. */
  132. var reTrim = /^\s+|\s+$/g,
  133. reTrimStart = /^\s+/,
  134. reTrimEnd = /\s+$/;
  135. /** Used to match wrap detail comments. */
  136. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  137. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  138. reSplitDetails = /,? & /;
  139. /** Used to match words composed of alphanumeric characters. */
  140. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  141. /** Used to match backslashes in property paths. */
  142. var reEscapeChar = /\\(\\)?/g;
  143. /**
  144. * Used to match
  145. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  146. */
  147. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  148. /** Used to match `RegExp` flags from their coerced string values. */
  149. var reFlags = /\w*$/;
  150. /** Used to detect bad signed hexadecimal string values. */
  151. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  152. /** Used to detect binary string values. */
  153. var reIsBinary = /^0b[01]+$/i;
  154. /** Used to detect host constructors (Safari). */
  155. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  156. /** Used to detect octal string values. */
  157. var reIsOctal = /^0o[0-7]+$/i;
  158. /** Used to detect unsigned integer values. */
  159. var reIsUint = /^(?:0|[1-9]\d*)$/;
  160. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  161. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  162. /** Used to ensure capturing order of template delimiters. */
  163. var reNoMatch = /($^)/;
  164. /** Used to match unescaped characters in compiled string literals. */
  165. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  166. /** Used to compose unicode character classes. */
  167. var rsAstralRange = '\\ud800-\\udfff',
  168. rsComboMarksRange = '\\u0300-\\u036f',
  169. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  170. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  171. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  172. rsDingbatRange = '\\u2700-\\u27bf',
  173. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  174. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  175. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  176. rsPunctuationRange = '\\u2000-\\u206f',
  177. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  178. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  179. rsVarRange = '\\ufe0e\\ufe0f',
  180. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  181. /** Used to compose unicode capture groups. */
  182. var rsApos = "['\u2019]",
  183. rsAstral = '[' + rsAstralRange + ']',
  184. rsBreak = '[' + rsBreakRange + ']',
  185. rsCombo = '[' + rsComboRange + ']',
  186. rsDigits = '\\d+',
  187. rsDingbat = '[' + rsDingbatRange + ']',
  188. rsLower = '[' + rsLowerRange + ']',
  189. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  190. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  191. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  192. rsNonAstral = '[^' + rsAstralRange + ']',
  193. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  194. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  195. rsUpper = '[' + rsUpperRange + ']',
  196. rsZWJ = '\\u200d';
  197. /** Used to compose unicode regexes. */
  198. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  199. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  200. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  201. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  202. reOptMod = rsModifier + '?',
  203. rsOptVar = '[' + rsVarRange + ']?',
  204. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  205. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  206. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  207. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  208. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  209. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  210. /** Used to match apostrophes. */
  211. var reApos = RegExp(rsApos, 'g');
  212. /**
  213. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  214. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  215. */
  216. var reComboMark = RegExp(rsCombo, 'g');
  217. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  218. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  219. /** Used to match complex or compound words. */
  220. var reUnicodeWord = RegExp([
  221. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  222. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  223. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  224. rsUpper + '+' + rsOptContrUpper,
  225. rsOrdUpper,
  226. rsOrdLower,
  227. rsDigits,
  228. rsEmoji
  229. ].join('|'), 'g');
  230. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  231. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  232. /** Used to detect strings that need a more robust regexp to match words. */
  233. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  234. /** Used to assign default `context` object properties. */
  235. var contextProps = [
  236. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  237. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  238. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  239. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  240. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  241. ];
  242. /** Used to make template sourceURLs easier to identify. */
  243. var templateCounter = -1;
  244. /** Used to identify `toStringTag` values of typed arrays. */
  245. var typedArrayTags = {};
  246. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  247. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  248. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  249. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  250. typedArrayTags[uint32Tag] = true;
  251. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  252. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  253. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  254. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  255. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  256. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  257. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  258. typedArrayTags[weakMapTag] = false;
  259. /** Used to identify `toStringTag` values supported by `_.clone`. */
  260. var cloneableTags = {};
  261. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  262. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  263. cloneableTags[boolTag] = cloneableTags[dateTag] =
  264. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  265. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  266. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  267. cloneableTags[numberTag] = cloneableTags[objectTag] =
  268. cloneableTags[regexpTag] = cloneableTags[setTag] =
  269. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  270. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  271. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  272. cloneableTags[errorTag] = cloneableTags[funcTag] =
  273. cloneableTags[weakMapTag] = false;
  274. /** Used to map Latin Unicode letters to basic Latin letters. */
  275. var deburredLetters = {
  276. // Latin-1 Supplement block.
  277. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  278. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  279. '\xc7': 'C', '\xe7': 'c',
  280. '\xd0': 'D', '\xf0': 'd',
  281. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  282. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  283. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  284. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  285. '\xd1': 'N', '\xf1': 'n',
  286. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  287. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  288. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  289. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  290. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  291. '\xc6': 'Ae', '\xe6': 'ae',
  292. '\xde': 'Th', '\xfe': 'th',
  293. '\xdf': 'ss',
  294. // Latin Extended-A block.
  295. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  296. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  297. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  298. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  299. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  300. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  301. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  302. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  303. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  304. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  305. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  306. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  307. '\u0134': 'J', '\u0135': 'j',
  308. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  309. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  310. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  311. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  312. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  313. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  314. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  315. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  316. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  317. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  318. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  319. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  320. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  321. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  322. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  323. '\u0174': 'W', '\u0175': 'w',
  324. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  325. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  326. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  327. '\u0132': 'IJ', '\u0133': 'ij',
  328. '\u0152': 'Oe', '\u0153': 'oe',
  329. '\u0149': "'n", '\u017f': 's'
  330. };
  331. /** Used to map characters to HTML entities. */
  332. var htmlEscapes = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '"': '&quot;',
  337. "'": '&#39;'
  338. };
  339. /** Used to map HTML entities to characters. */
  340. var htmlUnescapes = {
  341. '&amp;': '&',
  342. '&lt;': '<',
  343. '&gt;': '>',
  344. '&quot;': '"',
  345. '&#39;': "'"
  346. };
  347. /** Used to escape characters for inclusion in compiled string literals. */
  348. var stringEscapes = {
  349. '\\': '\\',
  350. "'": "'",
  351. '\n': 'n',
  352. '\r': 'r',
  353. '\u2028': 'u2028',
  354. '\u2029': 'u2029'
  355. };
  356. /** Built-in method references without a dependency on `root`. */
  357. var freeParseFloat = parseFloat,
  358. freeParseInt = parseInt;
  359. /** Detect free variable `global` from Node.js. */
  360. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  361. /** Detect free variable `self`. */
  362. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  363. /** Used as a reference to the global object. */
  364. var root = freeGlobal || freeSelf || Function('return this')();
  365. /** Detect free variable `exports`. */
  366. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  367. /** Detect free variable `module`. */
  368. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  369. /** Detect the popular CommonJS extension `module.exports`. */
  370. var moduleExports = freeModule && freeModule.exports === freeExports;
  371. /** Detect free variable `process` from Node.js. */
  372. var freeProcess = moduleExports && freeGlobal.process;
  373. /** Used to access faster Node.js helpers. */
  374. var nodeUtil = (function() {
  375. try {
  376. // Use `util.types` for Node.js 10+.
  377. var types = freeModule && freeModule.require && freeModule.require('util').types;
  378. if (types) {
  379. return types;
  380. }
  381. // Legacy `process.binding('util')` for Node.js < 10.
  382. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  383. } catch (e) {}
  384. }());
  385. /* Node.js helper references. */
  386. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  387. nodeIsDate = nodeUtil && nodeUtil.isDate,
  388. nodeIsMap = nodeUtil && nodeUtil.isMap,
  389. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  390. nodeIsSet = nodeUtil && nodeUtil.isSet,
  391. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  392. /*--------------------------------------------------------------------------*/
  393. /**
  394. * A faster alternative to `Function#apply`, this function invokes `func`
  395. * with the `this` binding of `thisArg` and the arguments of `args`.
  396. *
  397. * @private
  398. * @param {Function} func The function to invoke.
  399. * @param {*} thisArg The `this` binding of `func`.
  400. * @param {Array} args The arguments to invoke `func` with.
  401. * @returns {*} Returns the result of `func`.
  402. */
  403. function apply(func, thisArg, args) {
  404. switch (args.length) {
  405. case 0: return func.call(thisArg);
  406. case 1: return func.call(thisArg, args[0]);
  407. case 2: return func.call(thisArg, args[0], args[1]);
  408. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  409. }
  410. return func.apply(thisArg, args);
  411. }
  412. /**
  413. * A specialized version of `baseAggregator` for arrays.
  414. *
  415. * @private
  416. * @param {Array} [array] The array to iterate over.
  417. * @param {Function} setter The function to set `accumulator` values.
  418. * @param {Function} iteratee The iteratee to transform keys.
  419. * @param {Object} accumulator The initial aggregated object.
  420. * @returns {Function} Returns `accumulator`.
  421. */
  422. function arrayAggregator(array, setter, iteratee, accumulator) {
  423. var index = -1,
  424. length = array == null ? 0 : array.length;
  425. while (++index < length) {
  426. var value = array[index];
  427. setter(accumulator, value, iteratee(value), array);
  428. }
  429. return accumulator;
  430. }
  431. /**
  432. * A specialized version of `_.forEach` for arrays without support for
  433. * iteratee shorthands.
  434. *
  435. * @private
  436. * @param {Array} [array] The array to iterate over.
  437. * @param {Function} iteratee The function invoked per iteration.
  438. * @returns {Array} Returns `array`.
  439. */
  440. function arrayEach(array, iteratee) {
  441. var index = -1,
  442. length = array == null ? 0 : array.length;
  443. while (++index < length) {
  444. if (iteratee(array[index], index, array) === false) {
  445. break;
  446. }
  447. }
  448. return array;
  449. }
  450. /**
  451. * A specialized version of `_.forEachRight` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEachRight(array, iteratee) {
  460. var length = array == null ? 0 : array.length;
  461. while (length--) {
  462. if (iteratee(array[length], length, array) === false) {
  463. break;
  464. }
  465. }
  466. return array;
  467. }
  468. /**
  469. * A specialized version of `_.every` for arrays without support for
  470. * iteratee shorthands.
  471. *
  472. * @private
  473. * @param {Array} [array] The array to iterate over.
  474. * @param {Function} predicate The function invoked per iteration.
  475. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  476. * else `false`.
  477. */
  478. function arrayEvery(array, predicate) {
  479. var index = -1,
  480. length = array == null ? 0 : array.length;
  481. while (++index < length) {
  482. if (!predicate(array[index], index, array)) {
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. /**
  489. * A specialized version of `_.filter` for arrays without support for
  490. * iteratee shorthands.
  491. *
  492. * @private
  493. * @param {Array} [array] The array to iterate over.
  494. * @param {Function} predicate The function invoked per iteration.
  495. * @returns {Array} Returns the new filtered array.
  496. */
  497. function arrayFilter(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length,
  500. resIndex = 0,
  501. result = [];
  502. while (++index < length) {
  503. var value = array[index];
  504. if (predicate(value, index, array)) {
  505. result[resIndex++] = value;
  506. }
  507. }
  508. return result;
  509. }
  510. /**
  511. * A specialized version of `_.includes` for arrays without support for
  512. * specifying an index to search from.
  513. *
  514. * @private
  515. * @param {Array} [array] The array to inspect.
  516. * @param {*} target The value to search for.
  517. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  518. */
  519. function arrayIncludes(array, value) {
  520. var length = array == null ? 0 : array.length;
  521. return !!length && baseIndexOf(array, value, 0) > -1;
  522. }
  523. /**
  524. * This function is like `arrayIncludes` except that it accepts a comparator.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @param {Function} comparator The comparator invoked per element.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludesWith(array, value, comparator) {
  533. var index = -1,
  534. length = array == null ? 0 : array.length;
  535. while (++index < length) {
  536. if (comparator(value, array[index])) {
  537. return true;
  538. }
  539. }
  540. return false;
  541. }
  542. /**
  543. * A specialized version of `_.map` for arrays without support for iteratee
  544. * shorthands.
  545. *
  546. * @private
  547. * @param {Array} [array] The array to iterate over.
  548. * @param {Function} iteratee The function invoked per iteration.
  549. * @returns {Array} Returns the new mapped array.
  550. */
  551. function arrayMap(array, iteratee) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length,
  554. result = Array(length);
  555. while (++index < length) {
  556. result[index] = iteratee(array[index], index, array);
  557. }
  558. return result;
  559. }
  560. /**
  561. * Appends the elements of `values` to `array`.
  562. *
  563. * @private
  564. * @param {Array} array The array to modify.
  565. * @param {Array} values The values to append.
  566. * @returns {Array} Returns `array`.
  567. */
  568. function arrayPush(array, values) {
  569. var index = -1,
  570. length = values.length,
  571. offset = array.length;
  572. while (++index < length) {
  573. array[offset + index] = values[index];
  574. }
  575. return array;
  576. }
  577. /**
  578. * A specialized version of `_.reduce` for arrays without support for
  579. * iteratee shorthands.
  580. *
  581. * @private
  582. * @param {Array} [array] The array to iterate over.
  583. * @param {Function} iteratee The function invoked per iteration.
  584. * @param {*} [accumulator] The initial value.
  585. * @param {boolean} [initAccum] Specify using the first element of `array` as
  586. * the initial value.
  587. * @returns {*} Returns the accumulated value.
  588. */
  589. function arrayReduce(array, iteratee, accumulator, initAccum) {
  590. var index = -1,
  591. length = array == null ? 0 : array.length;
  592. if (initAccum && length) {
  593. accumulator = array[++index];
  594. }
  595. while (++index < length) {
  596. accumulator = iteratee(accumulator, array[index], index, array);
  597. }
  598. return accumulator;
  599. }
  600. /**
  601. * A specialized version of `_.reduceRight` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} iteratee The function invoked per iteration.
  607. * @param {*} [accumulator] The initial value.
  608. * @param {boolean} [initAccum] Specify using the last element of `array` as
  609. * the initial value.
  610. * @returns {*} Returns the accumulated value.
  611. */
  612. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  613. var length = array == null ? 0 : array.length;
  614. if (initAccum && length) {
  615. accumulator = array[--length];
  616. }
  617. while (length--) {
  618. accumulator = iteratee(accumulator, array[length], length, array);
  619. }
  620. return accumulator;
  621. }
  622. /**
  623. * A specialized version of `_.some` for arrays without support for iteratee
  624. * shorthands.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to iterate over.
  628. * @param {Function} predicate The function invoked per iteration.
  629. * @returns {boolean} Returns `true` if any element passes the predicate check,
  630. * else `false`.
  631. */
  632. function arraySome(array, predicate) {
  633. var index = -1,
  634. length = array == null ? 0 : array.length;
  635. while (++index < length) {
  636. if (predicate(array[index], index, array)) {
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642. /**
  643. * Gets the size of an ASCII `string`.
  644. *
  645. * @private
  646. * @param {string} string The string inspect.
  647. * @returns {number} Returns the string size.
  648. */
  649. var asciiSize = baseProperty('length');
  650. /**
  651. * Converts an ASCII `string` to an array.
  652. *
  653. * @private
  654. * @param {string} string The string to convert.
  655. * @returns {Array} Returns the converted array.
  656. */
  657. function asciiToArray(string) {
  658. return string.split('');
  659. }
  660. /**
  661. * Splits an ASCII `string` into an array of its words.
  662. *
  663. * @private
  664. * @param {string} The string to inspect.
  665. * @returns {Array} Returns the words of `string`.
  666. */
  667. function asciiWords(string) {
  668. return string.match(reAsciiWord) || [];
  669. }
  670. /**
  671. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  672. * without support for iteratee shorthands, which iterates over `collection`
  673. * using `eachFunc`.
  674. *
  675. * @private
  676. * @param {Array|Object} collection The collection to inspect.
  677. * @param {Function} predicate The function invoked per iteration.
  678. * @param {Function} eachFunc The function to iterate over `collection`.
  679. * @returns {*} Returns the found element or its key, else `undefined`.
  680. */
  681. function baseFindKey(collection, predicate, eachFunc) {
  682. var result;
  683. eachFunc(collection, function(value, key, collection) {
  684. if (predicate(value, key, collection)) {
  685. result = key;
  686. return false;
  687. }
  688. });
  689. return result;
  690. }
  691. /**
  692. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  693. * support for iteratee shorthands.
  694. *
  695. * @private
  696. * @param {Array} array The array to inspect.
  697. * @param {Function} predicate The function invoked per iteration.
  698. * @param {number} fromIndex The index to search from.
  699. * @param {boolean} [fromRight] Specify iterating from right to left.
  700. * @returns {number} Returns the index of the matched value, else `-1`.
  701. */
  702. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  703. var length = array.length,
  704. index = fromIndex + (fromRight ? 1 : -1);
  705. while ((fromRight ? index-- : ++index < length)) {
  706. if (predicate(array[index], index, array)) {
  707. return index;
  708. }
  709. }
  710. return -1;
  711. }
  712. /**
  713. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} value The value to search for.
  718. * @param {number} fromIndex The index to search from.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseIndexOf(array, value, fromIndex) {
  722. return value === value
  723. ? strictIndexOf(array, value, fromIndex)
  724. : baseFindIndex(array, baseIsNaN, fromIndex);
  725. }
  726. /**
  727. * This function is like `baseIndexOf` except that it accepts a comparator.
  728. *
  729. * @private
  730. * @param {Array} array The array to inspect.
  731. * @param {*} value The value to search for.
  732. * @param {number} fromIndex The index to search from.
  733. * @param {Function} comparator The comparator invoked per element.
  734. * @returns {number} Returns the index of the matched value, else `-1`.
  735. */
  736. function baseIndexOfWith(array, value, fromIndex, comparator) {
  737. var index = fromIndex - 1,
  738. length = array.length;
  739. while (++index < length) {
  740. if (comparator(array[index], value)) {
  741. return index;
  742. }
  743. }
  744. return -1;
  745. }
  746. /**
  747. * The base implementation of `_.isNaN` without support for number objects.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  752. */
  753. function baseIsNaN(value) {
  754. return value !== value;
  755. }
  756. /**
  757. * The base implementation of `_.mean` and `_.meanBy` without support for
  758. * iteratee shorthands.
  759. *
  760. * @private
  761. * @param {Array} array The array to iterate over.
  762. * @param {Function} iteratee The function invoked per iteration.
  763. * @returns {number} Returns the mean.
  764. */
  765. function baseMean(array, iteratee) {
  766. var length = array == null ? 0 : array.length;
  767. return length ? (baseSum(array, iteratee) / length) : NAN;
  768. }
  769. /**
  770. * The base implementation of `_.property` without support for deep paths.
  771. *
  772. * @private
  773. * @param {string} key The key of the property to get.
  774. * @returns {Function} Returns the new accessor function.
  775. */
  776. function baseProperty(key) {
  777. return function(object) {
  778. return object == null ? undefined : object[key];
  779. };
  780. }
  781. /**
  782. * The base implementation of `_.propertyOf` without support for deep paths.
  783. *
  784. * @private
  785. * @param {Object} object The object to query.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function basePropertyOf(object) {
  789. return function(key) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  795. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  796. *
  797. * @private
  798. * @param {Array|Object} collection The collection to iterate over.
  799. * @param {Function} iteratee The function invoked per iteration.
  800. * @param {*} accumulator The initial value.
  801. * @param {boolean} initAccum Specify using the first or last element of
  802. * `collection` as the initial value.
  803. * @param {Function} eachFunc The function to iterate over `collection`.
  804. * @returns {*} Returns the accumulated value.
  805. */
  806. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  807. eachFunc(collection, function(value, index, collection) {
  808. accumulator = initAccum
  809. ? (initAccum = false, value)
  810. : iteratee(accumulator, value, index, collection);
  811. });
  812. return accumulator;
  813. }
  814. /**
  815. * The base implementation of `_.sortBy` which uses `comparer` to define the
  816. * sort order of `array` and replaces criteria objects with their corresponding
  817. * values.
  818. *
  819. * @private
  820. * @param {Array} array The array to sort.
  821. * @param {Function} comparer The function to define sort order.
  822. * @returns {Array} Returns `array`.
  823. */
  824. function baseSortBy(array, comparer) {
  825. var length = array.length;
  826. array.sort(comparer);
  827. while (length--) {
  828. array[length] = array[length].value;
  829. }
  830. return array;
  831. }
  832. /**
  833. * The base implementation of `_.sum` and `_.sumBy` without support for
  834. * iteratee shorthands.
  835. *
  836. * @private
  837. * @param {Array} array The array to iterate over.
  838. * @param {Function} iteratee The function invoked per iteration.
  839. * @returns {number} Returns the sum.
  840. */
  841. function baseSum(array, iteratee) {
  842. var result,
  843. index = -1,
  844. length = array.length;
  845. while (++index < length) {
  846. var current = iteratee(array[index]);
  847. if (current !== undefined) {
  848. result = result === undefined ? current : (result + current);
  849. }
  850. }
  851. return result;
  852. }
  853. /**
  854. * The base implementation of `_.times` without support for iteratee shorthands
  855. * or max array length checks.
  856. *
  857. * @private
  858. * @param {number} n The number of times to invoke `iteratee`.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {Array} Returns the array of results.
  861. */
  862. function baseTimes(n, iteratee) {
  863. var index = -1,
  864. result = Array(n);
  865. while (++index < n) {
  866. result[index] = iteratee(index);
  867. }
  868. return result;
  869. }
  870. /**
  871. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  872. * of key-value pairs for `object` corresponding to the property names of `props`.
  873. *
  874. * @private
  875. * @param {Object} object The object to query.
  876. * @param {Array} props The property names to get values for.
  877. * @returns {Object} Returns the key-value pairs.
  878. */
  879. function baseToPairs(object, props) {
  880. return arrayMap(props, function(key) {
  881. return [key, object[key]];
  882. });
  883. }
  884. /**
  885. * The base implementation of `_.unary` without support for storing metadata.
  886. *
  887. * @private
  888. * @param {Function} func The function to cap arguments for.
  889. * @returns {Function} Returns the new capped function.
  890. */
  891. function baseUnary(func) {
  892. return function(value) {
  893. return func(value);
  894. };
  895. }
  896. /**
  897. * The base implementation of `_.values` and `_.valuesIn` which creates an
  898. * array of `object` property values corresponding to the property names
  899. * of `props`.
  900. *
  901. * @private
  902. * @param {Object} object The object to query.
  903. * @param {Array} props The property names to get values for.
  904. * @returns {Object} Returns the array of property values.
  905. */
  906. function baseValues(object, props) {
  907. return arrayMap(props, function(key) {
  908. return object[key];
  909. });
  910. }
  911. /**
  912. * Checks if a `cache` value for `key` exists.
  913. *
  914. * @private
  915. * @param {Object} cache The cache to query.
  916. * @param {string} key The key of the entry to check.
  917. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  918. */
  919. function cacheHas(cache, key) {
  920. return cache.has(key);
  921. }
  922. /**
  923. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  924. * that is not found in the character symbols.
  925. *
  926. * @private
  927. * @param {Array} strSymbols The string symbols to inspect.
  928. * @param {Array} chrSymbols The character symbols to find.
  929. * @returns {number} Returns the index of the first unmatched string symbol.
  930. */
  931. function charsStartIndex(strSymbols, chrSymbols) {
  932. var index = -1,
  933. length = strSymbols.length;
  934. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  935. return index;
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the last unmatched string symbol.
  945. */
  946. function charsEndIndex(strSymbols, chrSymbols) {
  947. var index = strSymbols.length;
  948. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  949. return index;
  950. }
  951. /**
  952. * Gets the number of `placeholder` occurrences in `array`.
  953. *
  954. * @private
  955. * @param {Array} array The array to inspect.
  956. * @param {*} placeholder The placeholder to search for.
  957. * @returns {number} Returns the placeholder count.
  958. */
  959. function countHolders(array, placeholder) {
  960. var length = array.length,
  961. result = 0;
  962. while (length--) {
  963. if (array[length] === placeholder) {
  964. ++result;
  965. }
  966. }
  967. return result;
  968. }
  969. /**
  970. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  971. * letters to basic Latin letters.
  972. *
  973. * @private
  974. * @param {string} letter The matched letter to deburr.
  975. * @returns {string} Returns the deburred letter.
  976. */
  977. var deburrLetter = basePropertyOf(deburredLetters);
  978. /**
  979. * Used by `_.escape` to convert characters to HTML entities.
  980. *
  981. * @private
  982. * @param {string} chr The matched character to escape.
  983. * @returns {string} Returns the escaped character.
  984. */
  985. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  986. /**
  987. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. function escapeStringChar(chr) {
  994. return '\\' + stringEscapes[chr];
  995. }
  996. /**
  997. * Gets the value at `key` of `object`.
  998. *
  999. * @private
  1000. * @param {Object} [object] The object to query.
  1001. * @param {string} key The key of the property to get.
  1002. * @returns {*} Returns the property value.
  1003. */
  1004. function getValue(object, key) {
  1005. return object == null ? undefined : object[key];
  1006. }
  1007. /**
  1008. * Checks if `string` contains Unicode symbols.
  1009. *
  1010. * @private
  1011. * @param {string} string The string to inspect.
  1012. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1013. */
  1014. function hasUnicode(string) {
  1015. return reHasUnicode.test(string);
  1016. }
  1017. /**
  1018. * Checks if `string` contains a word composed of Unicode symbols.
  1019. *
  1020. * @private
  1021. * @param {string} string The string to inspect.
  1022. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1023. */
  1024. function hasUnicodeWord(string) {
  1025. return reHasUnicodeWord.test(string);
  1026. }
  1027. /**
  1028. * Converts `iterator` to an array.
  1029. *
  1030. * @private
  1031. * @param {Object} iterator The iterator to convert.
  1032. * @returns {Array} Returns the converted array.
  1033. */
  1034. function iteratorToArray(iterator) {
  1035. var data,
  1036. result = [];
  1037. while (!(data = iterator.next()).done) {
  1038. result.push(data.value);
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. * Converts `map` to its key-value pairs.
  1044. *
  1045. * @private
  1046. * @param {Object} map The map to convert.
  1047. * @returns {Array} Returns the key-value pairs.
  1048. */
  1049. function mapToArray(map) {
  1050. var index = -1,
  1051. result = Array(map.size);
  1052. map.forEach(function(value, key) {
  1053. result[++index] = [key, value];
  1054. });
  1055. return result;
  1056. }
  1057. /**
  1058. * Creates a unary function that invokes `func` with its argument transformed.
  1059. *
  1060. * @private
  1061. * @param {Function} func The function to wrap.
  1062. * @param {Function} transform The argument transform.
  1063. * @returns {Function} Returns the new function.
  1064. */
  1065. function overArg(func, transform) {
  1066. return function(arg) {
  1067. return func(transform(arg));
  1068. };
  1069. }
  1070. /**
  1071. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1072. * and returns an array of their indexes.
  1073. *
  1074. * @private
  1075. * @param {Array} array The array to modify.
  1076. * @param {*} placeholder The placeholder to replace.
  1077. * @returns {Array} Returns the new array of placeholder indexes.
  1078. */
  1079. function replaceHolders(array, placeholder) {
  1080. var index = -1,
  1081. length = array.length,
  1082. resIndex = 0,
  1083. result = [];
  1084. while (++index < length) {
  1085. var value = array[index];
  1086. if (value === placeholder || value === PLACEHOLDER) {
  1087. array[index] = PLACEHOLDER;
  1088. result[resIndex++] = index;
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * Gets the value at `key`, unless `key` is "__proto__".
  1095. *
  1096. * @private
  1097. * @param {Object} object The object to query.
  1098. * @param {string} key The key of the property to get.
  1099. * @returns {*} Returns the property value.
  1100. */
  1101. function safeGet(object, key) {
  1102. return key == '__proto__'
  1103. ? undefined
  1104. : object[key];
  1105. }
  1106. /**
  1107. * Converts `set` to an array of its values.
  1108. *
  1109. * @private
  1110. * @param {Object} set The set to convert.
  1111. * @returns {Array} Returns the values.
  1112. */
  1113. function setToArray(set) {
  1114. var index = -1,
  1115. result = Array(set.size);
  1116. set.forEach(function(value) {
  1117. result[++index] = value;
  1118. });
  1119. return result;
  1120. }
  1121. /**
  1122. * Converts `set` to its value-value pairs.
  1123. *
  1124. * @private
  1125. * @param {Object} set The set to convert.
  1126. * @returns {Array} Returns the value-value pairs.
  1127. */
  1128. function setToPairs(set) {
  1129. var index = -1,
  1130. result = Array(set.size);
  1131. set.forEach(function(value) {
  1132. result[++index] = [value, value];
  1133. });
  1134. return result;
  1135. }
  1136. /**
  1137. * A specialized version of `_.indexOf` which performs strict equality
  1138. * comparisons of values, i.e. `===`.
  1139. *
  1140. * @private
  1141. * @param {Array} array The array to inspect.
  1142. * @param {*} value The value to search for.
  1143. * @param {number} fromIndex The index to search from.
  1144. * @returns {number} Returns the index of the matched value, else `-1`.
  1145. */
  1146. function strictIndexOf(array, value, fromIndex) {
  1147. var index = fromIndex - 1,
  1148. length = array.length;
  1149. while (++index < length) {
  1150. if (array[index] === value) {
  1151. return index;
  1152. }
  1153. }
  1154. return -1;
  1155. }
  1156. /**
  1157. * A specialized version of `_.lastIndexOf` which performs strict equality
  1158. * comparisons of values, i.e. `===`.
  1159. *
  1160. * @private
  1161. * @param {Array} array The array to inspect.
  1162. * @param {*} value The value to search for.
  1163. * @param {number} fromIndex The index to search from.
  1164. * @returns {number} Returns the index of the matched value, else `-1`.
  1165. */
  1166. function strictLastIndexOf(array, value, fromIndex) {
  1167. var index = fromIndex + 1;
  1168. while (index--) {
  1169. if (array[index] === value) {
  1170. return index;
  1171. }
  1172. }
  1173. return index;
  1174. }
  1175. /**
  1176. * Gets the number of symbols in `string`.
  1177. *
  1178. * @private
  1179. * @param {string} string The string to inspect.
  1180. * @returns {number} Returns the string size.
  1181. */
  1182. function stringSize(string) {
  1183. return hasUnicode(string)
  1184. ? unicodeSize(string)
  1185. : asciiSize(string);
  1186. }
  1187. /**
  1188. * Converts `string` to an array.
  1189. *
  1190. * @private
  1191. * @param {string} string The string to convert.
  1192. * @returns {Array} Returns the converted array.
  1193. */
  1194. function stringToArray(string) {
  1195. return hasUnicode(string)
  1196. ? unicodeToArray(string)
  1197. : asciiToArray(string);
  1198. }
  1199. /**
  1200. * Used by `_.unescape` to convert HTML entities to characters.
  1201. *
  1202. * @private
  1203. * @param {string} chr The matched character to unescape.
  1204. * @returns {string} Returns the unescaped character.
  1205. */
  1206. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1207. /**
  1208. * Gets the size of a Unicode `string`.
  1209. *
  1210. * @private
  1211. * @param {string} string The string inspect.
  1212. * @returns {number} Returns the string size.
  1213. */
  1214. function unicodeSize(string) {
  1215. var result = reUnicode.lastIndex = 0;
  1216. while (reUnicode.test(string)) {
  1217. ++result;
  1218. }
  1219. return result;
  1220. }
  1221. /**
  1222. * Converts a Unicode `string` to an array.
  1223. *
  1224. * @private
  1225. * @param {string} string The string to convert.
  1226. * @returns {Array} Returns the converted array.
  1227. */
  1228. function unicodeToArray(string) {
  1229. return string.match(reUnicode) || [];
  1230. }
  1231. /**
  1232. * Splits a Unicode `string` into an array of its words.
  1233. *
  1234. * @private
  1235. * @param {string} The string to inspect.
  1236. * @returns {Array} Returns the words of `string`.
  1237. */
  1238. function unicodeWords(string) {
  1239. return string.match(reUnicodeWord) || [];
  1240. }
  1241. /*--------------------------------------------------------------------------*/
  1242. /**
  1243. * Create a new pristine `lodash` function using the `context` object.
  1244. *
  1245. * @static
  1246. * @memberOf _
  1247. * @since 1.1.0
  1248. * @category Util
  1249. * @param {Object} [context=root] The context object.
  1250. * @returns {Function} Returns a new `lodash` function.
  1251. * @example
  1252. *
  1253. * _.mixin({ 'foo': _.constant('foo') });
  1254. *
  1255. * var lodash = _.runInContext();
  1256. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1257. *
  1258. * _.isFunction(_.foo);
  1259. * // => true
  1260. * _.isFunction(_.bar);
  1261. * // => false
  1262. *
  1263. * lodash.isFunction(lodash.foo);
  1264. * // => false
  1265. * lodash.isFunction(lodash.bar);
  1266. * // => true
  1267. *
  1268. * // Create a suped-up `defer` in Node.js.
  1269. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1270. */
  1271. var runInContext = (function runInContext(context) {
  1272. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1273. /** Built-in constructor references. */
  1274. var Array = context.Array,
  1275. Date = context.Date,
  1276. Error = context.Error,
  1277. Function = context.Function,
  1278. Math = context.Math,
  1279. Object = context.Object,
  1280. RegExp = context.RegExp,
  1281. String = context.String,
  1282. TypeError = context.TypeError;
  1283. /** Used for built-in method references. */
  1284. var arrayProto = Array.prototype,
  1285. funcProto = Function.prototype,
  1286. objectProto = Object.prototype;
  1287. /** Used to detect overreaching core-js shims. */
  1288. var coreJsData = context['__core-js_shared__'];
  1289. /** Used to resolve the decompiled source of functions. */
  1290. var funcToString = funcProto.toString;
  1291. /** Used to check objects for own properties. */
  1292. var hasOwnProperty = objectProto.hasOwnProperty;
  1293. /** Used to generate unique IDs. */
  1294. var idCounter = 0;
  1295. /** Used to detect methods masquerading as native. */
  1296. var maskSrcKey = (function() {
  1297. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1298. return uid ? ('Symbol(src)_1.' + uid) : '';
  1299. }());
  1300. /**
  1301. * Used to resolve the
  1302. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1303. * of values.
  1304. */
  1305. var nativeObjectToString = objectProto.toString;
  1306. /** Used to infer the `Object` constructor. */
  1307. var objectCtorString = funcToString.call(Object);
  1308. /** Used to restore the original `_` reference in `_.noConflict`. */
  1309. var oldDash = root._;
  1310. /** Used to detect if a method is native. */
  1311. var reIsNative = RegExp('^' +
  1312. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1313. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1314. );
  1315. /** Built-in value references. */
  1316. var Buffer = moduleExports ? context.Buffer : undefined,
  1317. Symbol = context.Symbol,
  1318. Uint8Array = context.Uint8Array,
  1319. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1320. getPrototype = overArg(Object.getPrototypeOf, Object),
  1321. objectCreate = Object.create,
  1322. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1323. splice = arrayProto.splice,
  1324. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1325. symIterator = Symbol ? Symbol.iterator : undefined,
  1326. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1327. var defineProperty = (function() {
  1328. try {
  1329. var func = getNative(Object, 'defineProperty');
  1330. func({}, '', {});
  1331. return func;
  1332. } catch (e) {}
  1333. }());
  1334. /** Mocked built-ins. */
  1335. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1336. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1337. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1338. /* Built-in method references for those with the same name as other `lodash` methods. */
  1339. var nativeCeil = Math.ceil,
  1340. nativeFloor = Math.floor,
  1341. nativeGetSymbols = Object.getOwnPropertySymbols,
  1342. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1343. nativeIsFinite = context.isFinite,
  1344. nativeJoin = arrayProto.join,
  1345. nativeKeys = overArg(Object.keys, Object),
  1346. nativeMax = Math.max,
  1347. nativeMin = Math.min,
  1348. nativeNow = Date.now,
  1349. nativeParseInt = context.parseInt,
  1350. nativeRandom = Math.random,
  1351. nativeReverse = arrayProto.reverse;
  1352. /* Built-in method references that are verified to be native. */
  1353. var DataView = getNative(context, 'DataView'),
  1354. Map = getNative(context, 'Map'),
  1355. Promise = getNative(context, 'Promise'),
  1356. Set = getNative(context, 'Set'),
  1357. WeakMap = getNative(context, 'WeakMap'),
  1358. nativeCreate = getNative(Object, 'create');
  1359. /** Used to store function metadata. */
  1360. var metaMap = WeakMap && new WeakMap;
  1361. /** Used to lookup unminified function names. */
  1362. var realNames = {};
  1363. /** Used to detect maps, sets, and weakmaps. */
  1364. var dataViewCtorString = toSource(DataView),
  1365. mapCtorString = toSource(Map),
  1366. promiseCtorString = toSource(Promise),
  1367. setCtorString = toSource(Set),
  1368. weakMapCtorString = toSource(WeakMap);
  1369. /** Used to convert symbols to primitives and strings. */
  1370. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1371. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1372. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1373. /*------------------------------------------------------------------------*/
  1374. /**
  1375. * Creates a `lodash` object which wraps `value` to enable implicit method
  1376. * chain sequences. Methods that operate on and return arrays, collections,
  1377. * and functions can be chained together. Methods that retrieve a single value
  1378. * or may return a primitive value will automatically end the chain sequence
  1379. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1380. * with `_#value`.
  1381. *
  1382. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1383. * enabled using `_.chain`.
  1384. *
  1385. * The execution of chained methods is lazy, that is, it's deferred until
  1386. * `_#value` is implicitly or explicitly called.
  1387. *
  1388. * Lazy evaluation allows several methods to support shortcut fusion.
  1389. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1390. * the creation of intermediate arrays and can greatly reduce the number of
  1391. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1392. * fusion if the section is applied to an array and iteratees accept only
  1393. * one argument. The heuristic for whether a section qualifies for shortcut
  1394. * fusion is subject to change.
  1395. *
  1396. * Chaining is supported in custom builds as long as the `_#value` method is
  1397. * directly or indirectly included in the build.
  1398. *
  1399. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1400. *
  1401. * The wrapper `Array` methods are:
  1402. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1403. *
  1404. * The wrapper `String` methods are:
  1405. * `replace` and `split`
  1406. *
  1407. * The wrapper methods that support shortcut fusion are:
  1408. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1409. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1410. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1411. *
  1412. * The chainable wrapper methods are:
  1413. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1414. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1415. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1416. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1417. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1418. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1419. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1420. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1421. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1422. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1423. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1424. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1425. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1426. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1427. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1428. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1429. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1430. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1431. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1432. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1433. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1434. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1435. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1436. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1437. *
  1438. * The wrapper methods that are **not** chainable by default are:
  1439. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1440. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1441. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1442. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1443. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1444. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1445. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1446. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1447. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1448. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1449. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1450. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1451. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1452. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1453. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1454. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1455. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1456. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1457. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1458. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1459. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1460. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1461. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1462. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1463. * `upperFirst`, `value`, and `words`
  1464. *
  1465. * @name _
  1466. * @constructor
  1467. * @category Seq
  1468. * @param {*} value The value to wrap in a `lodash` instance.
  1469. * @returns {Object} Returns the new `lodash` wrapper instance.
  1470. * @example
  1471. *
  1472. * function square(n) {
  1473. * return n * n;
  1474. * }
  1475. *
  1476. * var wrapped = _([1, 2, 3]);
  1477. *
  1478. * // Returns an unwrapped value.
  1479. * wrapped.reduce(_.add);
  1480. * // => 6
  1481. *
  1482. * // Returns a wrapped value.
  1483. * var squares = wrapped.map(square);
  1484. *
  1485. * _.isArray(squares);
  1486. * // => false
  1487. *
  1488. * _.isArray(squares.value());
  1489. * // => true
  1490. */
  1491. function lodash(value) {
  1492. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1493. if (value instanceof LodashWrapper) {
  1494. return value;
  1495. }
  1496. if (hasOwnProperty.call(value, '__wrapped__')) {
  1497. return wrapperClone(value);
  1498. }
  1499. }
  1500. return new LodashWrapper(value);
  1501. }
  1502. /**
  1503. * The base implementation of `_.create` without support for assigning
  1504. * properties to the created object.
  1505. *
  1506. * @private
  1507. * @param {Object} proto The object to inherit from.
  1508. * @returns {Object} Returns the new object.
  1509. */
  1510. var baseCreate = (function() {
  1511. function object() {}
  1512. return function(proto) {
  1513. if (!isObject(proto)) {
  1514. return {};
  1515. }
  1516. if (objectCreate) {
  1517. return objectCreate(proto);
  1518. }
  1519. object.prototype = proto;
  1520. var result = new object;
  1521. object.prototype = undefined;
  1522. return result;
  1523. };
  1524. }());
  1525. /**
  1526. * The function whose prototype chain sequence wrappers inherit from.
  1527. *
  1528. * @private
  1529. */
  1530. function baseLodash() {
  1531. // No operation performed.
  1532. }
  1533. /**
  1534. * The base constructor for creating `lodash` wrapper objects.
  1535. *
  1536. * @private
  1537. * @param {*} value The value to wrap.
  1538. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1539. */
  1540. function LodashWrapper(value, chainAll) {
  1541. this.__wrapped__ = value;
  1542. this.__actions__ = [];
  1543. this.__chain__ = !!chainAll;
  1544. this.__index__ = 0;
  1545. this.__values__ = undefined;
  1546. }
  1547. /**
  1548. * By default, the template delimiters used by lodash are like those in
  1549. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1550. * following template settings to use alternative delimiters.
  1551. *
  1552. * @static
  1553. * @memberOf _
  1554. * @type {Object}
  1555. */
  1556. lodash.templateSettings = {
  1557. /**
  1558. * Used to detect `data` property values to be HTML-escaped.
  1559. *
  1560. * @memberOf _.templateSettings
  1561. * @type {RegExp}
  1562. */
  1563. 'escape': reEscape,
  1564. /**
  1565. * Used to detect code to be evaluated.
  1566. *
  1567. * @memberOf _.templateSettings
  1568. * @type {RegExp}
  1569. */
  1570. 'evaluate': reEvaluate,
  1571. /**
  1572. * Used to detect `data` property values to inject.
  1573. *
  1574. * @memberOf _.templateSettings
  1575. * @type {RegExp}
  1576. */
  1577. 'interpolate': reInterpolate,
  1578. /**
  1579. * Used to reference the data object in the template text.
  1580. *
  1581. * @memberOf _.templateSettings
  1582. * @type {string}
  1583. */
  1584. 'variable': '',
  1585. /**
  1586. * Used to import variables into the compiled template.
  1587. *
  1588. * @memberOf _.templateSettings
  1589. * @type {Object}
  1590. */
  1591. 'imports': {
  1592. /**
  1593. * A reference to the `lodash` function.
  1594. *
  1595. * @memberOf _.templateSettings.imports
  1596. * @type {Function}
  1597. */
  1598. '_': lodash
  1599. }
  1600. };
  1601. // Ensure wrappers are instances of `baseLodash`.
  1602. lodash.prototype = baseLodash.prototype;
  1603. lodash.prototype.constructor = lodash;
  1604. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1605. LodashWrapper.prototype.constructor = LodashWrapper;
  1606. /*------------------------------------------------------------------------*/
  1607. /**
  1608. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1609. *
  1610. * @private
  1611. * @constructor
  1612. * @param {*} value The value to wrap.
  1613. */
  1614. function LazyWrapper(value) {
  1615. this.__wrapped__ = value;
  1616. this.__actions__ = [];
  1617. this.__dir__ = 1;
  1618. this.__filtered__ = false;
  1619. this.__iteratees__ = [];
  1620. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1621. this.__views__ = [];
  1622. }
  1623. /**
  1624. * Creates a clone of the lazy wrapper object.
  1625. *
  1626. * @private
  1627. * @name clone
  1628. * @memberOf LazyWrapper
  1629. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1630. */
  1631. function lazyClone() {
  1632. var result = new LazyWrapper(this.__wrapped__);
  1633. result.__actions__ = copyArray(this.__actions__);
  1634. result.__dir__ = this.__dir__;
  1635. result.__filtered__ = this.__filtered__;
  1636. result.__iteratees__ = copyArray(this.__iteratees__);
  1637. result.__takeCount__ = this.__takeCount__;
  1638. result.__views__ = copyArray(this.__views__);
  1639. return result;
  1640. }
  1641. /**
  1642. * Reverses the direction of lazy iteration.
  1643. *
  1644. * @private
  1645. * @name reverse
  1646. * @memberOf LazyWrapper
  1647. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1648. */
  1649. function lazyReverse() {
  1650. if (this.__filtered__) {
  1651. var result = new LazyWrapper(this);
  1652. result.__dir__ = -1;
  1653. result.__filtered__ = true;
  1654. } else {
  1655. result = this.clone();
  1656. result.__dir__ *= -1;
  1657. }
  1658. return result;
  1659. }
  1660. /**
  1661. * Extracts the unwrapped value from its lazy wrapper.
  1662. *
  1663. * @private
  1664. * @name value
  1665. * @memberOf LazyWrapper
  1666. * @returns {*} Returns the unwrapped value.
  1667. */
  1668. function lazyValue() {
  1669. var array = this.__wrapped__.value(),
  1670. dir = this.__dir__,
  1671. isArr = isArray(array),
  1672. isRight = dir < 0,
  1673. arrLength = isArr ? array.length : 0,
  1674. view = getView(0, arrLength, this.__views__),
  1675. start = view.start,
  1676. end = view.end,
  1677. length = end - start,
  1678. index = isRight ? end : (start - 1),
  1679. iteratees = this.__iteratees__,
  1680. iterLength = iteratees.length,
  1681. resIndex = 0,
  1682. takeCount = nativeMin(length, this.__takeCount__);
  1683. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1684. return baseWrapperValue(array, this.__actions__);
  1685. }
  1686. var result = [];
  1687. outer:
  1688. while (length-- && resIndex < takeCount) {
  1689. index += dir;
  1690. var iterIndex = -1,
  1691. value = array[index];
  1692. while (++iterIndex < iterLength) {
  1693. var data = iteratees[iterIndex],
  1694. iteratee = data.iteratee,
  1695. type = data.type,
  1696. computed = iteratee(value);
  1697. if (type == LAZY_MAP_FLAG) {
  1698. value = computed;
  1699. } else if (!computed) {
  1700. if (type == LAZY_FILTER_FLAG) {
  1701. continue outer;
  1702. } else {
  1703. break outer;
  1704. }
  1705. }
  1706. }
  1707. result[resIndex++] = value;
  1708. }
  1709. return result;
  1710. }
  1711. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1712. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1713. LazyWrapper.prototype.constructor = LazyWrapper;
  1714. /*------------------------------------------------------------------------*/
  1715. /**
  1716. * Creates a hash object.
  1717. *
  1718. * @private
  1719. * @constructor
  1720. * @param {Array} [entries] The key-value pairs to cache.
  1721. */
  1722. function Hash(entries) {
  1723. var index = -1,
  1724. length = entries == null ? 0 : entries.length;
  1725. this.clear();
  1726. while (++index < length) {
  1727. var entry = entries[index];
  1728. this.set(entry[0], entry[1]);
  1729. }
  1730. }
  1731. /**
  1732. * Removes all key-value entries from the hash.
  1733. *
  1734. * @private
  1735. * @name clear
  1736. * @memberOf Hash
  1737. */
  1738. function hashClear() {
  1739. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1740. this.size = 0;
  1741. }
  1742. /**
  1743. * Removes `key` and its value from the hash.
  1744. *
  1745. * @private
  1746. * @name delete
  1747. * @memberOf Hash
  1748. * @param {Object} hash The hash to modify.
  1749. * @param {string} key The key of the value to remove.
  1750. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1751. */
  1752. function hashDelete(key) {
  1753. var result = this.has(key) && delete this.__data__[key];
  1754. this.size -= result ? 1 : 0;
  1755. return result;
  1756. }
  1757. /**
  1758. * Gets the hash value for `key`.
  1759. *
  1760. * @private
  1761. * @name get
  1762. * @memberOf Hash
  1763. * @param {string} key The key of the value to get.
  1764. * @returns {*} Returns the entry value.
  1765. */
  1766. function hashGet(key) {
  1767. var data = this.__data__;
  1768. if (nativeCreate) {
  1769. var result = data[key];
  1770. return result === HASH_UNDEFINED ? undefined : result;
  1771. }
  1772. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1773. }
  1774. /**
  1775. * Checks if a hash value for `key` exists.
  1776. *
  1777. * @private
  1778. * @name has
  1779. * @memberOf Hash
  1780. * @param {string} key The key of the entry to check.
  1781. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1782. */
  1783. function hashHas(key) {
  1784. var data = this.__data__;
  1785. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1786. }
  1787. /**
  1788. * Sets the hash `key` to `value`.
  1789. *
  1790. * @private
  1791. * @name set
  1792. * @memberOf Hash
  1793. * @param {string} key The key of the value to set.
  1794. * @param {*} value The value to set.
  1795. * @returns {Object} Returns the hash instance.
  1796. */
  1797. function hashSet(key, value) {
  1798. var data = this.__data__;
  1799. this.size += this.has(key) ? 0 : 1;
  1800. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1801. return this;
  1802. }
  1803. // Add methods to `Hash`.
  1804. Hash.prototype.clear = hashClear;
  1805. Hash.prototype['delete'] = hashDelete;
  1806. Hash.prototype.get = hashGet;
  1807. Hash.prototype.has = hashHas;
  1808. Hash.prototype.set = hashSet;
  1809. /*------------------------------------------------------------------------*/
  1810. /**
  1811. * Creates an list cache object.
  1812. *
  1813. * @private
  1814. * @constructor
  1815. * @param {Array} [entries] The key-value pairs to cache.
  1816. */
  1817. function ListCache(entries) {
  1818. var index = -1,
  1819. length = entries == null ? 0 : entries.length;
  1820. this.clear();
  1821. while (++index < length) {
  1822. var entry = entries[index];
  1823. this.set(entry[0], entry[1]);
  1824. }
  1825. }
  1826. /**
  1827. * Removes all key-value entries from the list cache.
  1828. *
  1829. * @private
  1830. * @name clear
  1831. * @memberOf ListCache
  1832. */
  1833. function listCacheClear() {
  1834. this.__data__ = [];
  1835. this.size = 0;
  1836. }
  1837. /**
  1838. * Removes `key` and its value from the list cache.
  1839. *
  1840. * @private
  1841. * @name delete
  1842. * @memberOf ListCache
  1843. * @param {string} key The key of the value to remove.
  1844. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1845. */
  1846. function listCacheDelete(key) {
  1847. var data = this.__data__,
  1848. index = assocIndexOf(data, key);
  1849. if (index < 0) {
  1850. return false;
  1851. }
  1852. var lastIndex = data.length - 1;
  1853. if (index == lastIndex) {
  1854. data.pop();
  1855. } else {
  1856. splice.call(data, index, 1);
  1857. }
  1858. --this.size;
  1859. return true;
  1860. }
  1861. /**
  1862. * Gets the list cache value for `key`.
  1863. *
  1864. * @private
  1865. * @name get
  1866. * @memberOf ListCache
  1867. * @param {string} key The key of the value to get.
  1868. * @returns {*} Returns the entry value.
  1869. */
  1870. function listCacheGet(key) {
  1871. var data = this.__data__,
  1872. index = assocIndexOf(data, key);
  1873. return index < 0 ? undefined : data[index][1];
  1874. }
  1875. /**
  1876. * Checks if a list cache value for `key` exists.
  1877. *
  1878. * @private
  1879. * @name has
  1880. * @memberOf ListCache
  1881. * @param {string} key The key of the entry to check.
  1882. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1883. */
  1884. function listCacheHas(key) {
  1885. return assocIndexOf(this.__data__, key) > -1;
  1886. }
  1887. /**
  1888. * Sets the list cache `key` to `value`.
  1889. *
  1890. * @private
  1891. * @name set
  1892. * @memberOf ListCache
  1893. * @param {string} key The key of the value to set.
  1894. * @param {*} value The value to set.
  1895. * @returns {Object} Returns the list cache instance.
  1896. */
  1897. function listCacheSet(key, value) {
  1898. var data = this.__data__,
  1899. index = assocIndexOf(data, key);
  1900. if (index < 0) {
  1901. ++this.size;
  1902. data.push([key, value]);
  1903. } else {
  1904. data[index][1] = value;
  1905. }
  1906. return this;
  1907. }
  1908. // Add methods to `ListCache`.
  1909. ListCache.prototype.clear = listCacheClear;
  1910. ListCache.prototype['delete'] = listCacheDelete;
  1911. ListCache.prototype.get = listCacheGet;
  1912. ListCache.prototype.has = listCacheHas;
  1913. ListCache.prototype.set = listCacheSet;
  1914. /*------------------------------------------------------------------------*/
  1915. /**
  1916. * Creates a map cache object to store key-value pairs.
  1917. *
  1918. * @private
  1919. * @constructor
  1920. * @param {Array} [entries] The key-value pairs to cache.
  1921. */
  1922. function MapCache(entries) {
  1923. var index = -1,
  1924. length = entries == null ? 0 : entries.length;
  1925. this.clear();
  1926. while (++index < length) {
  1927. var entry = entries[index];
  1928. this.set(entry[0], entry[1]);
  1929. }
  1930. }
  1931. /**
  1932. * Removes all key-value entries from the map.
  1933. *
  1934. * @private
  1935. * @name clear
  1936. * @memberOf MapCache
  1937. */
  1938. function mapCacheClear() {
  1939. this.size = 0;
  1940. this.__data__ = {
  1941. 'hash': new Hash,
  1942. 'map': new (Map || ListCache),
  1943. 'string': new Hash
  1944. };
  1945. }
  1946. /**
  1947. * Removes `key` and its value from the map.
  1948. *
  1949. * @private
  1950. * @name delete
  1951. * @memberOf MapCache
  1952. * @param {string} key The key of the value to remove.
  1953. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1954. */
  1955. function mapCacheDelete(key) {
  1956. var result = getMapData(this, key)['delete'](key);
  1957. this.size -= result ? 1 : 0;
  1958. return result;
  1959. }
  1960. /**
  1961. * Gets the map value for `key`.
  1962. *
  1963. * @private
  1964. * @name get
  1965. * @memberOf MapCache
  1966. * @param {string} key The key of the value to get.
  1967. * @returns {*} Returns the entry value.
  1968. */
  1969. function mapCacheGet(key) {
  1970. return getMapData(this, key).get(key);
  1971. }
  1972. /**
  1973. * Checks if a map value for `key` exists.
  1974. *
  1975. * @private
  1976. * @name has
  1977. * @memberOf MapCache
  1978. * @param {string} key The key of the entry to check.
  1979. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1980. */
  1981. function mapCacheHas(key) {
  1982. return getMapData(this, key).has(key);
  1983. }
  1984. /**
  1985. * Sets the map `key` to `value`.
  1986. *
  1987. * @private
  1988. * @name set
  1989. * @memberOf MapCache
  1990. * @param {string} key The key of the value to set.
  1991. * @param {*} value The value to set.
  1992. * @returns {Object} Returns the map cache instance.
  1993. */
  1994. function mapCacheSet(key, value) {
  1995. var data = getMapData(this, key),
  1996. size = data.size;
  1997. data.set(key, value);
  1998. this.size += data.size == size ? 0 : 1;
  1999. return this;
  2000. }
  2001. // Add methods to `MapCache`.
  2002. MapCache.prototype.clear = mapCacheClear;
  2003. MapCache.prototype['delete'] = mapCacheDelete;
  2004. MapCache.prototype.get = mapCacheGet;
  2005. MapCache.prototype.has = mapCacheHas;
  2006. MapCache.prototype.set = mapCacheSet;
  2007. /*------------------------------------------------------------------------*/
  2008. /**
  2009. *
  2010. * Creates an array cache object to store unique values.
  2011. *
  2012. * @private
  2013. * @constructor
  2014. * @param {Array} [values] The values to cache.
  2015. */
  2016. function SetCache(values) {
  2017. var index = -1,
  2018. length = values == null ? 0 : values.length;
  2019. this.__data__ = new MapCache;
  2020. while (++index < length) {
  2021. this.add(values[index]);
  2022. }
  2023. }
  2024. /**
  2025. * Adds `value` to the array cache.
  2026. *
  2027. * @private
  2028. * @name add
  2029. * @memberOf SetCache
  2030. * @alias push
  2031. * @param {*} value The value to cache.
  2032. * @returns {Object} Returns the cache instance.
  2033. */
  2034. function setCacheAdd(value) {
  2035. this.__data__.set(value, HASH_UNDEFINED);
  2036. return this;
  2037. }
  2038. /**
  2039. * Checks if `value` is in the array cache.
  2040. *
  2041. * @private
  2042. * @name has
  2043. * @memberOf SetCache
  2044. * @param {*} value The value to search for.
  2045. * @returns {number} Returns `true` if `value` is found, else `false`.
  2046. */
  2047. function setCacheHas(value) {
  2048. return this.__data__.has(value);
  2049. }
  2050. // Add methods to `SetCache`.
  2051. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2052. SetCache.prototype.has = setCacheHas;
  2053. /*------------------------------------------------------------------------*/
  2054. /**
  2055. * Creates a stack cache object to store key-value pairs.
  2056. *
  2057. * @private
  2058. * @constructor
  2059. * @param {Array} [entries] The key-value pairs to cache.
  2060. */
  2061. function Stack(entries) {
  2062. var data = this.__data__ = new ListCache(entries);
  2063. this.size = data.size;
  2064. }
  2065. /**
  2066. * Removes all key-value entries from the stack.
  2067. *
  2068. * @private
  2069. * @name clear
  2070. * @memberOf Stack
  2071. */
  2072. function stackClear() {
  2073. this.__data__ = new ListCache;
  2074. this.size = 0;
  2075. }
  2076. /**
  2077. * Removes `key` and its value from the stack.
  2078. *
  2079. * @private
  2080. * @name delete
  2081. * @memberOf Stack
  2082. * @param {string} key The key of the value to remove.
  2083. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2084. */
  2085. function stackDelete(key) {
  2086. var data = this.__data__,
  2087. result = data['delete'](key);
  2088. this.size = data.size;
  2089. return result;
  2090. }
  2091. /**
  2092. * Gets the stack value for `key`.
  2093. *
  2094. * @private
  2095. * @name get
  2096. * @memberOf Stack
  2097. * @param {string} key The key of the value to get.
  2098. * @returns {*} Returns the entry value.
  2099. */
  2100. function stackGet(key) {
  2101. return this.__data__.get(key);
  2102. }
  2103. /**
  2104. * Checks if a stack value for `key` exists.
  2105. *
  2106. * @private
  2107. * @name has
  2108. * @memberOf Stack
  2109. * @param {string} key The key of the entry to check.
  2110. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2111. */
  2112. function stackHas(key) {
  2113. return this.__data__.has(key);
  2114. }
  2115. /**
  2116. * Sets the stack `key` to `value`.
  2117. *
  2118. * @private
  2119. * @name set
  2120. * @memberOf Stack
  2121. * @param {string} key The key of the value to set.
  2122. * @param {*} value The value to set.
  2123. * @returns {Object} Returns the stack cache instance.
  2124. */
  2125. function stackSet(key, value) {
  2126. var data = this.__data__;
  2127. if (data instanceof ListCache) {
  2128. var pairs = data.__data__;
  2129. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2130. pairs.push([key, value]);
  2131. this.size = ++data.size;
  2132. return this;
  2133. }
  2134. data = this.__data__ = new MapCache(pairs);
  2135. }
  2136. data.set(key, value);
  2137. this.size = data.size;
  2138. return this;
  2139. }
  2140. // Add methods to `Stack`.
  2141. Stack.prototype.clear = stackClear;
  2142. Stack.prototype['delete'] = stackDelete;
  2143. Stack.prototype.get = stackGet;
  2144. Stack.prototype.has = stackHas;
  2145. Stack.prototype.set = stackSet;
  2146. /*------------------------------------------------------------------------*/
  2147. /**
  2148. * Creates an array of the enumerable property names of the array-like `value`.
  2149. *
  2150. * @private
  2151. * @param {*} value The value to query.
  2152. * @param {boolean} inherited Specify returning inherited property names.
  2153. * @returns {Array} Returns the array of property names.
  2154. */
  2155. function arrayLikeKeys(value, inherited) {
  2156. var isArr = isArray(value),
  2157. isArg = !isArr && isArguments(value),
  2158. isBuff = !isArr && !isArg && isBuffer(value),
  2159. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2160. skipIndexes = isArr || isArg || isBuff || isType,
  2161. result = skipIndexes ? baseTimes(value.length, String) : [],
  2162. length = result.length;
  2163. for (var key in value) {
  2164. if ((inherited || hasOwnProperty.call(value, key)) &&
  2165. !(skipIndexes && (
  2166. // Safari 9 has enumerable `arguments.length` in strict mode.
  2167. key == 'length' ||
  2168. // Node.js 0.10 has enumerable non-index properties on buffers.
  2169. (isBuff && (key == 'offset' || key == 'parent')) ||
  2170. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2171. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2172. // Skip index properties.
  2173. isIndex(key, length)
  2174. ))) {
  2175. result.push(key);
  2176. }
  2177. }
  2178. return result;
  2179. }
  2180. /**
  2181. * A specialized version of `_.sample` for arrays.
  2182. *
  2183. * @private
  2184. * @param {Array} array The array to sample.
  2185. * @returns {*} Returns the random element.
  2186. */
  2187. function arraySample(array) {
  2188. var length = array.length;
  2189. return length ? array[baseRandom(0, length - 1)] : undefined;
  2190. }
  2191. /**
  2192. * A specialized version of `_.sampleSize` for arrays.
  2193. *
  2194. * @private
  2195. * @param {Array} array The array to sample.
  2196. * @param {number} n The number of elements to sample.
  2197. * @returns {Array} Returns the random elements.
  2198. */
  2199. function arraySampleSize(array, n) {
  2200. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2201. }
  2202. /**
  2203. * A specialized version of `_.shuffle` for arrays.
  2204. *
  2205. * @private
  2206. * @param {Array} array The array to shuffle.
  2207. * @returns {Array} Returns the new shuffled array.
  2208. */
  2209. function arrayShuffle(array) {
  2210. return shuffleSelf(copyArray(array));
  2211. }
  2212. /**
  2213. * This function is like `assignValue` except that it doesn't assign
  2214. * `undefined` values.
  2215. *
  2216. * @private
  2217. * @param {Object} object The object to modify.
  2218. * @param {string} key The key of the property to assign.
  2219. * @param {*} value The value to assign.
  2220. */
  2221. function assignMergeValue(object, key, value) {
  2222. if ((value !== undefined && !eq(object[key], value)) ||
  2223. (value === undefined && !(key in object))) {
  2224. baseAssignValue(object, key, value);
  2225. }
  2226. }
  2227. /**
  2228. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2229. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2230. * for equality comparisons.
  2231. *
  2232. * @private
  2233. * @param {Object} object The object to modify.
  2234. * @param {string} key The key of the property to assign.
  2235. * @param {*} value The value to assign.
  2236. */
  2237. function assignValue(object, key, value) {
  2238. var objValue = object[key];
  2239. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2240. (value === undefined && !(key in object))) {
  2241. baseAssignValue(object, key, value);
  2242. }
  2243. }
  2244. /**
  2245. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2246. *
  2247. * @private
  2248. * @param {Array} array The array to inspect.
  2249. * @param {*} key The key to search for.
  2250. * @returns {number} Returns the index of the matched value, else `-1`.
  2251. */
  2252. function assocIndexOf(array, key) {
  2253. var length = array.length;
  2254. while (length--) {
  2255. if (eq(array[length][0], key)) {
  2256. return length;
  2257. }
  2258. }
  2259. return -1;
  2260. }
  2261. /**
  2262. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2263. * by `iteratee` and values set by `setter`.
  2264. *
  2265. * @private
  2266. * @param {Array|Object} collection The collection to iterate over.
  2267. * @param {Function} setter The function to set `accumulator` values.
  2268. * @param {Function} iteratee The iteratee to transform keys.
  2269. * @param {Object} accumulator The initial aggregated object.
  2270. * @returns {Function} Returns `accumulator`.
  2271. */
  2272. function baseAggregator(collection, setter, iteratee, accumulator) {
  2273. baseEach(collection, function(value, key, collection) {
  2274. setter(accumulator, value, iteratee(value), collection);
  2275. });
  2276. return accumulator;
  2277. }
  2278. /**
  2279. * The base implementation of `_.assign` without support for multiple sources
  2280. * or `customizer` functions.
  2281. *
  2282. * @private
  2283. * @param {Object} object The destination object.
  2284. * @param {Object} source The source object.
  2285. * @returns {Object} Returns `object`.
  2286. */
  2287. function baseAssign(object, source) {
  2288. return object && copyObject(source, keys(source), object);
  2289. }
  2290. /**
  2291. * The base implementation of `_.assignIn` without support for multiple sources
  2292. * or `customizer` functions.
  2293. *
  2294. * @private
  2295. * @param {Object} object The destination object.
  2296. * @param {Object} source The source object.
  2297. * @returns {Object} Returns `object`.
  2298. */
  2299. function baseAssignIn(object, source) {
  2300. return object && copyObject(source, keysIn(source), object);
  2301. }
  2302. /**
  2303. * The base implementation of `assignValue` and `assignMergeValue` without
  2304. * value checks.
  2305. *
  2306. * @private
  2307. * @param {Object} object The object to modify.
  2308. * @param {string} key The key of the property to assign.
  2309. * @param {*} value The value to assign.
  2310. */
  2311. function baseAssignValue(object, key, value) {
  2312. if (key == '__proto__' && defineProperty) {
  2313. defineProperty(object, key, {
  2314. 'configurable': true,
  2315. 'enumerable': true,
  2316. 'value': value,
  2317. 'writable': true
  2318. });
  2319. } else {
  2320. object[key] = value;
  2321. }
  2322. }
  2323. /**
  2324. * The base implementation of `_.at` without support for individual paths.
  2325. *
  2326. * @private
  2327. * @param {Object} object The object to iterate over.
  2328. * @param {string[]} paths The property paths to pick.
  2329. * @returns {Array} Returns the picked elements.
  2330. */
  2331. function baseAt(object, paths) {
  2332. var index = -1,
  2333. length = paths.length,
  2334. result = Array(length),
  2335. skip = object == null;
  2336. while (++index < length) {
  2337. result[index] = skip ? undefined : get(object, paths[index]);
  2338. }
  2339. return result;
  2340. }
  2341. /**
  2342. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2343. *
  2344. * @private
  2345. * @param {number} number The number to clamp.
  2346. * @param {number} [lower] The lower bound.
  2347. * @param {number} upper The upper bound.
  2348. * @returns {number} Returns the clamped number.
  2349. */
  2350. function baseClamp(number, lower, upper) {
  2351. if (number === number) {
  2352. if (upper !== undefined) {
  2353. number = number <= upper ? number : upper;
  2354. }
  2355. if (lower !== undefined) {
  2356. number = number >= lower ? number : lower;
  2357. }
  2358. }
  2359. return number;
  2360. }
  2361. /**
  2362. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2363. * traversed objects.
  2364. *
  2365. * @private
  2366. * @param {*} value The value to clone.
  2367. * @param {boolean} bitmask The bitmask flags.
  2368. * 1 - Deep clone
  2369. * 2 - Flatten inherited properties
  2370. * 4 - Clone symbols
  2371. * @param {Function} [customizer] The function to customize cloning.
  2372. * @param {string} [key] The key of `value`.
  2373. * @param {Object} [object] The parent object of `value`.
  2374. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2375. * @returns {*} Returns the cloned value.
  2376. */
  2377. function baseClone(value, bitmask, customizer, key, object, stack) {
  2378. var result,
  2379. isDeep = bitmask & CLONE_DEEP_FLAG,
  2380. isFlat = bitmask & CLONE_FLAT_FLAG,
  2381. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2382. if (customizer) {
  2383. result = object ? customizer(value, key, object, stack) : customizer(value);
  2384. }
  2385. if (result !== undefined) {
  2386. return result;
  2387. }
  2388. if (!isObject(value)) {
  2389. return value;
  2390. }
  2391. var isArr = isArray(value);
  2392. if (isArr) {
  2393. result = initCloneArray(value);
  2394. if (!isDeep) {
  2395. return copyArray(value, result);
  2396. }
  2397. } else {
  2398. var tag = getTag(value),
  2399. isFunc = tag == funcTag || tag == genTag;
  2400. if (isBuffer(value)) {
  2401. return cloneBuffer(value, isDeep);
  2402. }
  2403. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2404. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2405. if (!isDeep) {
  2406. return isFlat
  2407. ? copySymbolsIn(value, baseAssignIn(result, value))
  2408. : copySymbols(value, baseAssign(result, value));
  2409. }
  2410. } else {
  2411. if (!cloneableTags[tag]) {
  2412. return object ? value : {};
  2413. }
  2414. result = initCloneByTag(value, tag, isDeep);
  2415. }
  2416. }
  2417. // Check for circular references and return its corresponding clone.
  2418. stack || (stack = new Stack);
  2419. var stacked = stack.get(value);
  2420. if (stacked) {
  2421. return stacked;
  2422. }
  2423. stack.set(value, result);
  2424. if (isSet(value)) {
  2425. value.forEach(function(subValue) {
  2426. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2427. });
  2428. return result;
  2429. }
  2430. if (isMap(value)) {
  2431. value.forEach(function(subValue, key) {
  2432. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2433. });
  2434. return result;
  2435. }
  2436. var keysFunc = isFull
  2437. ? (isFlat ? getAllKeysIn : getAllKeys)
  2438. : (isFlat ? keysIn : keys);
  2439. var props = isArr ? undefined : keysFunc(value);
  2440. arrayEach(props || value, function(subValue, key) {
  2441. if (props) {
  2442. key = subValue;
  2443. subValue = value[key];
  2444. }
  2445. // Recursively populate clone (susceptible to call stack limits).
  2446. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2447. });
  2448. return result;
  2449. }
  2450. /**
  2451. * The base implementation of `_.conforms` which doesn't clone `source`.
  2452. *
  2453. * @private
  2454. * @param {Object} source The object of property predicates to conform to.
  2455. * @returns {Function} Returns the new spec function.
  2456. */
  2457. function baseConforms(source) {
  2458. var props = keys(source);
  2459. return function(object) {
  2460. return baseConformsTo(object, source, props);
  2461. };
  2462. }
  2463. /**
  2464. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2465. *
  2466. * @private
  2467. * @param {Object} object The object to inspect.
  2468. * @param {Object} source The object of property predicates to conform to.
  2469. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2470. */
  2471. function baseConformsTo(object, source, props) {
  2472. var length = props.length;
  2473. if (object == null) {
  2474. return !length;
  2475. }
  2476. object = Object(object);
  2477. while (length--) {
  2478. var key = props[length],
  2479. predicate = source[key],
  2480. value = object[key];
  2481. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2482. return false;
  2483. }
  2484. }
  2485. return true;
  2486. }
  2487. /**
  2488. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2489. * to provide to `func`.
  2490. *
  2491. * @private
  2492. * @param {Function} func The function to delay.
  2493. * @param {number} wait The number of milliseconds to delay invocation.
  2494. * @param {Array} args The arguments to provide to `func`.
  2495. * @returns {number|Object} Returns the timer id or timeout object.
  2496. */
  2497. function baseDelay(func, wait, args) {
  2498. if (typeof func != 'function') {
  2499. throw new TypeError(FUNC_ERROR_TEXT);
  2500. }
  2501. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2502. }
  2503. /**
  2504. * The base implementation of methods like `_.difference` without support
  2505. * for excluding multiple arrays or iteratee shorthands.
  2506. *
  2507. * @private
  2508. * @param {Array} array The array to inspect.
  2509. * @param {Array} values The values to exclude.
  2510. * @param {Function} [iteratee] The iteratee invoked per element.
  2511. * @param {Function} [comparator] The comparator invoked per element.
  2512. * @returns {Array} Returns the new array of filtered values.
  2513. */
  2514. function baseDifference(array, values, iteratee, comparator) {
  2515. var index = -1,
  2516. includes = arrayIncludes,
  2517. isCommon = true,
  2518. length = array.length,
  2519. result = [],
  2520. valuesLength = values.length;
  2521. if (!length) {
  2522. return result;
  2523. }
  2524. if (iteratee) {
  2525. values = arrayMap(values, baseUnary(iteratee));
  2526. }
  2527. if (comparator) {
  2528. includes = arrayIncludesWith;
  2529. isCommon = false;
  2530. }
  2531. else if (values.length >= LARGE_ARRAY_SIZE) {
  2532. includes = cacheHas;
  2533. isCommon = false;
  2534. values = new SetCache(values);
  2535. }
  2536. outer:
  2537. while (++index < length) {
  2538. var value = array[index],
  2539. computed = iteratee == null ? value : iteratee(value);
  2540. value = (comparator || value !== 0) ? value : 0;
  2541. if (isCommon && computed === computed) {
  2542. var valuesIndex = valuesLength;
  2543. while (valuesIndex--) {
  2544. if (values[valuesIndex] === computed) {
  2545. continue outer;
  2546. }
  2547. }
  2548. result.push(value);
  2549. }
  2550. else if (!includes(values, computed, comparator)) {
  2551. result.push(value);
  2552. }
  2553. }
  2554. return result;
  2555. }
  2556. /**
  2557. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2558. *
  2559. * @private
  2560. * @param {Array|Object} collection The collection to iterate over.
  2561. * @param {Function} iteratee The function invoked per iteration.
  2562. * @returns {Array|Object} Returns `collection`.
  2563. */
  2564. var baseEach = createBaseEach(baseForOwn);
  2565. /**
  2566. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2567. *
  2568. * @private
  2569. * @param {Array|Object} collection The collection to iterate over.
  2570. * @param {Function} iteratee The function invoked per iteration.
  2571. * @returns {Array|Object} Returns `collection`.
  2572. */
  2573. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2574. /**
  2575. * The base implementation of `_.every` without support for iteratee shorthands.
  2576. *
  2577. * @private
  2578. * @param {Array|Object} collection The collection to iterate over.
  2579. * @param {Function} predicate The function invoked per iteration.
  2580. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2581. * else `false`
  2582. */
  2583. function baseEvery(collection, predicate) {
  2584. var result = true;
  2585. baseEach(collection, function(value, index, collection) {
  2586. result = !!predicate(value, index, collection);
  2587. return result;
  2588. });
  2589. return result;
  2590. }
  2591. /**
  2592. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2593. * `comparator` to determine the extremum value.
  2594. *
  2595. * @private
  2596. * @param {Array} array The array to iterate over.
  2597. * @param {Function} iteratee The iteratee invoked per iteration.
  2598. * @param {Function} comparator The comparator used to compare values.
  2599. * @returns {*} Returns the extremum value.
  2600. */
  2601. function baseExtremum(array, iteratee, comparator) {
  2602. var index = -1,
  2603. length = array.length;
  2604. while (++index < length) {
  2605. var value = array[index],
  2606. current = iteratee(value);
  2607. if (current != null && (computed === undefined
  2608. ? (current === current && !isSymbol(current))
  2609. : comparator(current, computed)
  2610. )) {
  2611. var computed = current,
  2612. result = value;
  2613. }
  2614. }
  2615. return result;
  2616. }
  2617. /**
  2618. * The base implementation of `_.fill` without an iteratee call guard.
  2619. *
  2620. * @private
  2621. * @param {Array} array The array to fill.
  2622. * @param {*} value The value to fill `array` with.
  2623. * @param {number} [start=0] The start position.
  2624. * @param {number} [end=array.length] The end position.
  2625. * @returns {Array} Returns `array`.
  2626. */
  2627. function baseFill(array, value, start, end) {
  2628. var length = array.length;
  2629. start = toInteger(start);
  2630. if (start < 0) {
  2631. start = -start > length ? 0 : (length + start);
  2632. }
  2633. end = (end === undefined || end > length) ? length : toInteger(end);
  2634. if (end < 0) {
  2635. end += length;
  2636. }
  2637. end = start > end ? 0 : toLength(end);
  2638. while (start < end) {
  2639. array[start++] = value;
  2640. }
  2641. return array;
  2642. }
  2643. /**
  2644. * The base implementation of `_.filter` without support for iteratee shorthands.
  2645. *
  2646. * @private
  2647. * @param {Array|Object} collection The collection to iterate over.
  2648. * @param {Function} predicate The function invoked per iteration.
  2649. * @returns {Array} Returns the new filtered array.
  2650. */
  2651. function baseFilter(collection, predicate) {
  2652. var result = [];
  2653. baseEach(collection, function(value, index, collection) {
  2654. if (predicate(value, index, collection)) {
  2655. result.push(value);
  2656. }
  2657. });
  2658. return result;
  2659. }
  2660. /**
  2661. * The base implementation of `_.flatten` with support for restricting flattening.
  2662. *
  2663. * @private
  2664. * @param {Array} array The array to flatten.
  2665. * @param {number} depth The maximum recursion depth.
  2666. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2667. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2668. * @param {Array} [result=[]] The initial result value.
  2669. * @returns {Array} Returns the new flattened array.
  2670. */
  2671. function baseFlatten(array, depth, predicate, isStrict, result) {
  2672. var index = -1,
  2673. length = array.length;
  2674. predicate || (predicate = isFlattenable);
  2675. result || (result = []);
  2676. while (++index < length) {
  2677. var value = array[index];
  2678. if (depth > 0 && predicate(value)) {
  2679. if (depth > 1) {
  2680. // Recursively flatten arrays (susceptible to call stack limits).
  2681. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2682. } else {
  2683. arrayPush(result, value);
  2684. }
  2685. } else if (!isStrict) {
  2686. result[result.length] = value;
  2687. }
  2688. }
  2689. return result;
  2690. }
  2691. /**
  2692. * The base implementation of `baseForOwn` which iterates over `object`
  2693. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2694. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2695. *
  2696. * @private
  2697. * @param {Object} object The object to iterate over.
  2698. * @param {Function} iteratee The function invoked per iteration.
  2699. * @param {Function} keysFunc The function to get the keys of `object`.
  2700. * @returns {Object} Returns `object`.
  2701. */
  2702. var baseFor = createBaseFor();
  2703. /**
  2704. * This function is like `baseFor` except that it iterates over properties
  2705. * in the opposite order.
  2706. *
  2707. * @private
  2708. * @param {Object} object The object to iterate over.
  2709. * @param {Function} iteratee The function invoked per iteration.
  2710. * @param {Function} keysFunc The function to get the keys of `object`.
  2711. * @returns {Object} Returns `object`.
  2712. */
  2713. var baseForRight = createBaseFor(true);
  2714. /**
  2715. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2716. *
  2717. * @private
  2718. * @param {Object} object The object to iterate over.
  2719. * @param {Function} iteratee The function invoked per iteration.
  2720. * @returns {Object} Returns `object`.
  2721. */
  2722. function baseForOwn(object, iteratee) {
  2723. return object && baseFor(object, iteratee, keys);
  2724. }
  2725. /**
  2726. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2727. *
  2728. * @private
  2729. * @param {Object} object The object to iterate over.
  2730. * @param {Function} iteratee The function invoked per iteration.
  2731. * @returns {Object} Returns `object`.
  2732. */
  2733. function baseForOwnRight(object, iteratee) {
  2734. return object && baseForRight(object, iteratee, keys);
  2735. }
  2736. /**
  2737. * The base implementation of `_.functions` which creates an array of
  2738. * `object` function property names filtered from `props`.
  2739. *
  2740. * @private
  2741. * @param {Object} object The object to inspect.
  2742. * @param {Array} props The property names to filter.
  2743. * @returns {Array} Returns the function names.
  2744. */
  2745. function baseFunctions(object, props) {
  2746. return arrayFilter(props, function(key) {
  2747. return isFunction(object[key]);
  2748. });
  2749. }
  2750. /**
  2751. * The base implementation of `_.get` without support for default values.
  2752. *
  2753. * @private
  2754. * @param {Object} object The object to query.
  2755. * @param {Array|string} path The path of the property to get.
  2756. * @returns {*} Returns the resolved value.
  2757. */
  2758. function baseGet(object, path) {
  2759. path = castPath(path, object);
  2760. var index = 0,
  2761. length = path.length;
  2762. while (object != null && index < length) {
  2763. object = object[toKey(path[index++])];
  2764. }
  2765. return (index && index == length) ? object : undefined;
  2766. }
  2767. /**
  2768. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2769. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2770. * symbols of `object`.
  2771. *
  2772. * @private
  2773. * @param {Object} object The object to query.
  2774. * @param {Function} keysFunc The function to get the keys of `object`.
  2775. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2776. * @returns {Array} Returns the array of property names and symbols.
  2777. */
  2778. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2779. var result = keysFunc(object);
  2780. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2781. }
  2782. /**
  2783. * The base implementation of `getTag` without fallbacks for buggy environments.
  2784. *
  2785. * @private
  2786. * @param {*} value The value to query.
  2787. * @returns {string} Returns the `toStringTag`.
  2788. */
  2789. function baseGetTag(value) {
  2790. if (value == null) {
  2791. return value === undefined ? undefinedTag : nullTag;
  2792. }
  2793. return (symToStringTag && symToStringTag in Object(value))
  2794. ? getRawTag(value)
  2795. : objectToString(value);
  2796. }
  2797. /**
  2798. * The base implementation of `_.gt` which doesn't coerce arguments.
  2799. *
  2800. * @private
  2801. * @param {*} value The value to compare.
  2802. * @param {*} other The other value to compare.
  2803. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2804. * else `false`.
  2805. */
  2806. function baseGt(value, other) {
  2807. return value > other;
  2808. }
  2809. /**
  2810. * The base implementation of `_.has` without support for deep paths.
  2811. *
  2812. * @private
  2813. * @param {Object} [object] The object to query.
  2814. * @param {Array|string} key The key to check.
  2815. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2816. */
  2817. function baseHas(object, key) {
  2818. return object != null && hasOwnProperty.call(object, key);
  2819. }
  2820. /**
  2821. * The base implementation of `_.hasIn` without support for deep paths.
  2822. *
  2823. * @private
  2824. * @param {Object} [object] The object to query.
  2825. * @param {Array|string} key The key to check.
  2826. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2827. */
  2828. function baseHasIn(object, key) {
  2829. return object != null && key in Object(object);
  2830. }
  2831. /**
  2832. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2833. *
  2834. * @private
  2835. * @param {number} number The number to check.
  2836. * @param {number} start The start of the range.
  2837. * @param {number} end The end of the range.
  2838. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2839. */
  2840. function baseInRange(number, start, end) {
  2841. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2842. }
  2843. /**
  2844. * The base implementation of methods like `_.intersection`, without support
  2845. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2846. *
  2847. * @private
  2848. * @param {Array} arrays The arrays to inspect.
  2849. * @param {Function} [iteratee] The iteratee invoked per element.
  2850. * @param {Function} [comparator] The comparator invoked per element.
  2851. * @returns {Array} Returns the new array of shared values.
  2852. */
  2853. function baseIntersection(arrays, iteratee, comparator) {
  2854. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2855. length = arrays[0].length,
  2856. othLength = arrays.length,
  2857. othIndex = othLength,
  2858. caches = Array(othLength),
  2859. maxLength = Infinity,
  2860. result = [];
  2861. while (othIndex--) {
  2862. var array = arrays[othIndex];
  2863. if (othIndex && iteratee) {
  2864. array = arrayMap(array, baseUnary(iteratee));
  2865. }
  2866. maxLength = nativeMin(array.length, maxLength);
  2867. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2868. ? new SetCache(othIndex && array)
  2869. : undefined;
  2870. }
  2871. array = arrays[0];
  2872. var index = -1,
  2873. seen = caches[0];
  2874. outer:
  2875. while (++index < length && result.length < maxLength) {
  2876. var value = array[index],
  2877. computed = iteratee ? iteratee(value) : value;
  2878. value = (comparator || value !== 0) ? value : 0;
  2879. if (!(seen
  2880. ? cacheHas(seen, computed)
  2881. : includes(result, computed, comparator)
  2882. )) {
  2883. othIndex = othLength;
  2884. while (--othIndex) {
  2885. var cache = caches[othIndex];
  2886. if (!(cache
  2887. ? cacheHas(cache, computed)
  2888. : includes(arrays[othIndex], computed, comparator))
  2889. ) {
  2890. continue outer;
  2891. }
  2892. }
  2893. if (seen) {
  2894. seen.push(computed);
  2895. }
  2896. result.push(value);
  2897. }
  2898. }
  2899. return result;
  2900. }
  2901. /**
  2902. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2903. * `object` with values transformed by `iteratee` and set by `setter`.
  2904. *
  2905. * @private
  2906. * @param {Object} object The object to iterate over.
  2907. * @param {Function} setter The function to set `accumulator` values.
  2908. * @param {Function} iteratee The iteratee to transform values.
  2909. * @param {Object} accumulator The initial inverted object.
  2910. * @returns {Function} Returns `accumulator`.
  2911. */
  2912. function baseInverter(object, setter, iteratee, accumulator) {
  2913. baseForOwn(object, function(value, key, object) {
  2914. setter(accumulator, iteratee(value), key, object);
  2915. });
  2916. return accumulator;
  2917. }
  2918. /**
  2919. * The base implementation of `_.invoke` without support for individual
  2920. * method arguments.
  2921. *
  2922. * @private
  2923. * @param {Object} object The object to query.
  2924. * @param {Array|string} path The path of the method to invoke.
  2925. * @param {Array} args The arguments to invoke the method with.
  2926. * @returns {*} Returns the result of the invoked method.
  2927. */
  2928. function baseInvoke(object, path, args) {
  2929. path = castPath(path, object);
  2930. object = parent(object, path);
  2931. var func = object == null ? object : object[toKey(last(path))];
  2932. return func == null ? undefined : apply(func, object, args);
  2933. }
  2934. /**
  2935. * The base implementation of `_.isArguments`.
  2936. *
  2937. * @private
  2938. * @param {*} value The value to check.
  2939. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2940. */
  2941. function baseIsArguments(value) {
  2942. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2943. }
  2944. /**
  2945. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2946. *
  2947. * @private
  2948. * @param {*} value The value to check.
  2949. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2950. */
  2951. function baseIsArrayBuffer(value) {
  2952. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2953. }
  2954. /**
  2955. * The base implementation of `_.isDate` without Node.js optimizations.
  2956. *
  2957. * @private
  2958. * @param {*} value The value to check.
  2959. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2960. */
  2961. function baseIsDate(value) {
  2962. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2963. }
  2964. /**
  2965. * The base implementation of `_.isEqual` which supports partial comparisons
  2966. * and tracks traversed objects.
  2967. *
  2968. * @private
  2969. * @param {*} value The value to compare.
  2970. * @param {*} other The other value to compare.
  2971. * @param {boolean} bitmask The bitmask flags.
  2972. * 1 - Unordered comparison
  2973. * 2 - Partial comparison
  2974. * @param {Function} [customizer] The function to customize comparisons.
  2975. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2976. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2977. */
  2978. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2979. if (value === other) {
  2980. return true;
  2981. }
  2982. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2983. return value !== value && other !== other;
  2984. }
  2985. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2986. }
  2987. /**
  2988. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2989. * deep comparisons and tracks traversed objects enabling objects with circular
  2990. * references to be compared.
  2991. *
  2992. * @private
  2993. * @param {Object} object The object to compare.
  2994. * @param {Object} other The other object to compare.
  2995. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2996. * @param {Function} customizer The function to customize comparisons.
  2997. * @param {Function} equalFunc The function to determine equivalents of values.
  2998. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2999. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3000. */
  3001. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3002. var objIsArr = isArray(object),
  3003. othIsArr = isArray(other),
  3004. objTag = objIsArr ? arrayTag : getTag(object),
  3005. othTag = othIsArr ? arrayTag : getTag(other);
  3006. objTag = objTag == argsTag ? objectTag : objTag;
  3007. othTag = othTag == argsTag ? objectTag : othTag;
  3008. var objIsObj = objTag == objectTag,
  3009. othIsObj = othTag == objectTag,
  3010. isSameTag = objTag == othTag;
  3011. if (isSameTag && isBuffer(object)) {
  3012. if (!isBuffer(other)) {
  3013. return false;
  3014. }
  3015. objIsArr = true;
  3016. objIsObj = false;
  3017. }
  3018. if (isSameTag && !objIsObj) {
  3019. stack || (stack = new Stack);
  3020. return (objIsArr || isTypedArray(object))
  3021. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3022. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3023. }
  3024. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3025. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3026. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3027. if (objIsWrapped || othIsWrapped) {
  3028. var objUnwrapped = objIsWrapped ? object.value() : object,
  3029. othUnwrapped = othIsWrapped ? other.value() : other;
  3030. stack || (stack = new Stack);
  3031. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3032. }
  3033. }
  3034. if (!isSameTag) {
  3035. return false;
  3036. }
  3037. stack || (stack = new Stack);
  3038. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3039. }
  3040. /**
  3041. * The base implementation of `_.isMap` without Node.js optimizations.
  3042. *
  3043. * @private
  3044. * @param {*} value The value to check.
  3045. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3046. */
  3047. function baseIsMap(value) {
  3048. return isObjectLike(value) && getTag(value) == mapTag;
  3049. }
  3050. /**
  3051. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3052. *
  3053. * @private
  3054. * @param {Object} object The object to inspect.
  3055. * @param {Object} source The object of property values to match.
  3056. * @param {Array} matchData The property names, values, and compare flags to match.
  3057. * @param {Function} [customizer] The function to customize comparisons.
  3058. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3059. */
  3060. function baseIsMatch(object, source, matchData, customizer) {
  3061. var index = matchData.length,
  3062. length = index,
  3063. noCustomizer = !customizer;
  3064. if (object == null) {
  3065. return !length;
  3066. }
  3067. object = Object(object);
  3068. while (index--) {
  3069. var data = matchData[index];
  3070. if ((noCustomizer && data[2])
  3071. ? data[1] !== object[data[0]]
  3072. : !(data[0] in object)
  3073. ) {
  3074. return false;
  3075. }
  3076. }
  3077. while (++index < length) {
  3078. data = matchData[index];
  3079. var key = data[0],
  3080. objValue = object[key],
  3081. srcValue = data[1];
  3082. if (noCustomizer && data[2]) {
  3083. if (objValue === undefined && !(key in object)) {
  3084. return false;
  3085. }
  3086. } else {
  3087. var stack = new Stack;
  3088. if (customizer) {
  3089. var result = customizer(objValue, srcValue, key, object, source, stack);
  3090. }
  3091. if (!(result === undefined
  3092. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3093. : result
  3094. )) {
  3095. return false;
  3096. }
  3097. }
  3098. }
  3099. return true;
  3100. }
  3101. /**
  3102. * The base implementation of `_.isNative` without bad shim checks.
  3103. *
  3104. * @private
  3105. * @param {*} value The value to check.
  3106. * @returns {boolean} Returns `true` if `value` is a native function,
  3107. * else `false`.
  3108. */
  3109. function baseIsNative(value) {
  3110. if (!isObject(value) || isMasked(value)) {
  3111. return false;
  3112. }
  3113. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3114. return pattern.test(toSource(value));
  3115. }
  3116. /**
  3117. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3118. *
  3119. * @private
  3120. * @param {*} value The value to check.
  3121. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3122. */
  3123. function baseIsRegExp(value) {
  3124. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3125. }
  3126. /**
  3127. * The base implementation of `_.isSet` without Node.js optimizations.
  3128. *
  3129. * @private
  3130. * @param {*} value The value to check.
  3131. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3132. */
  3133. function baseIsSet(value) {
  3134. return isObjectLike(value) && getTag(value) == setTag;
  3135. }
  3136. /**
  3137. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3138. *
  3139. * @private
  3140. * @param {*} value The value to check.
  3141. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3142. */
  3143. function baseIsTypedArray(value) {
  3144. return isObjectLike(value) &&
  3145. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3146. }
  3147. /**
  3148. * The base implementation of `_.iteratee`.
  3149. *
  3150. * @private
  3151. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3152. * @returns {Function} Returns the iteratee.
  3153. */
  3154. function baseIteratee(value) {
  3155. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3156. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3157. if (typeof value == 'function') {
  3158. return value;
  3159. }
  3160. if (value == null) {
  3161. return identity;
  3162. }
  3163. if (typeof value == 'object') {
  3164. return isArray(value)
  3165. ? baseMatchesProperty(value[0], value[1])
  3166. : baseMatches(value);
  3167. }
  3168. return property(value);
  3169. }
  3170. /**
  3171. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3172. *
  3173. * @private
  3174. * @param {Object} object The object to query.
  3175. * @returns {Array} Returns the array of property names.
  3176. */
  3177. function baseKeys(object) {
  3178. if (!isPrototype(object)) {
  3179. return nativeKeys(object);
  3180. }
  3181. var result = [];
  3182. for (var key in Object(object)) {
  3183. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3184. result.push(key);
  3185. }
  3186. }
  3187. return result;
  3188. }
  3189. /**
  3190. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3191. *
  3192. * @private
  3193. * @param {Object} object The object to query.
  3194. * @returns {Array} Returns the array of property names.
  3195. */
  3196. function baseKeysIn(object) {
  3197. if (!isObject(object)) {
  3198. return nativeKeysIn(object);
  3199. }
  3200. var isProto = isPrototype(object),
  3201. result = [];
  3202. for (var key in object) {
  3203. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3204. result.push(key);
  3205. }
  3206. }
  3207. return result;
  3208. }
  3209. /**
  3210. * The base implementation of `_.lt` which doesn't coerce arguments.
  3211. *
  3212. * @private
  3213. * @param {*} value The value to compare.
  3214. * @param {*} other The other value to compare.
  3215. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3216. * else `false`.
  3217. */
  3218. function baseLt(value, other) {
  3219. return value < other;
  3220. }
  3221. /**
  3222. * The base implementation of `_.map` without support for iteratee shorthands.
  3223. *
  3224. * @private
  3225. * @param {Array|Object} collection The collection to iterate over.
  3226. * @param {Function} iteratee The function invoked per iteration.
  3227. * @returns {Array} Returns the new mapped array.
  3228. */
  3229. function baseMap(collection, iteratee) {
  3230. var index = -1,
  3231. result = isArrayLike(collection) ? Array(collection.length) : [];
  3232. baseEach(collection, function(value, key, collection) {
  3233. result[++index] = iteratee(value, key, collection);
  3234. });
  3235. return result;
  3236. }
  3237. /**
  3238. * The base implementation of `_.matches` which doesn't clone `source`.
  3239. *
  3240. * @private
  3241. * @param {Object} source The object of property values to match.
  3242. * @returns {Function} Returns the new spec function.
  3243. */
  3244. function baseMatches(source) {
  3245. var matchData = getMatchData(source);
  3246. if (matchData.length == 1 && matchData[0][2]) {
  3247. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3248. }
  3249. return function(object) {
  3250. return object === source || baseIsMatch(object, source, matchData);
  3251. };
  3252. }
  3253. /**
  3254. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3255. *
  3256. * @private
  3257. * @param {string} path The path of the property to get.
  3258. * @param {*} srcValue The value to match.
  3259. * @returns {Function} Returns the new spec function.
  3260. */
  3261. function baseMatchesProperty(path, srcValue) {
  3262. if (isKey(path) && isStrictComparable(srcValue)) {
  3263. return matchesStrictComparable(toKey(path), srcValue);
  3264. }
  3265. return function(object) {
  3266. var objValue = get(object, path);
  3267. return (objValue === undefined && objValue === srcValue)
  3268. ? hasIn(object, path)
  3269. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3270. };
  3271. }
  3272. /**
  3273. * The base implementation of `_.merge` without support for multiple sources.
  3274. *
  3275. * @private
  3276. * @param {Object} object The destination object.
  3277. * @param {Object} source The source object.
  3278. * @param {number} srcIndex The index of `source`.
  3279. * @param {Function} [customizer] The function to customize merged values.
  3280. * @param {Object} [stack] Tracks traversed source values and their merged
  3281. * counterparts.
  3282. */
  3283. function baseMerge(object, source, srcIndex, customizer, stack) {
  3284. if (object === source) {
  3285. return;
  3286. }
  3287. baseFor(source, function(srcValue, key) {
  3288. if (isObject(srcValue)) {
  3289. stack || (stack = new Stack);
  3290. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3291. }
  3292. else {
  3293. var newValue = customizer
  3294. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3295. : undefined;
  3296. if (newValue === undefined) {
  3297. newValue = srcValue;
  3298. }
  3299. assignMergeValue(object, key, newValue);
  3300. }
  3301. }, keysIn);
  3302. }
  3303. /**
  3304. * A specialized version of `baseMerge` for arrays and objects which performs
  3305. * deep merges and tracks traversed objects enabling objects with circular
  3306. * references to be merged.
  3307. *
  3308. * @private
  3309. * @param {Object} object The destination object.
  3310. * @param {Object} source The source object.
  3311. * @param {string} key The key of the value to merge.
  3312. * @param {number} srcIndex The index of `source`.
  3313. * @param {Function} mergeFunc The function to merge values.
  3314. * @param {Function} [customizer] The function to customize assigned values.
  3315. * @param {Object} [stack] Tracks traversed source values and their merged
  3316. * counterparts.
  3317. */
  3318. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3319. var objValue = safeGet(object, key),
  3320. srcValue = safeGet(source, key),
  3321. stacked = stack.get(srcValue);
  3322. if (stacked) {
  3323. assignMergeValue(object, key, stacked);
  3324. return;
  3325. }
  3326. var newValue = customizer
  3327. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3328. : undefined;
  3329. var isCommon = newValue === undefined;
  3330. if (isCommon) {
  3331. var isArr = isArray(srcValue),
  3332. isBuff = !isArr && isBuffer(srcValue),
  3333. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3334. newValue = srcValue;
  3335. if (isArr || isBuff || isTyped) {
  3336. if (isArray(objValue)) {
  3337. newValue = objValue;
  3338. }
  3339. else if (isArrayLikeObject(objValue)) {
  3340. newValue = copyArray(objValue);
  3341. }
  3342. else if (isBuff) {
  3343. isCommon = false;
  3344. newValue = cloneBuffer(srcValue, true);
  3345. }
  3346. else if (isTyped) {
  3347. isCommon = false;
  3348. newValue = cloneTypedArray(srcValue, true);
  3349. }
  3350. else {
  3351. newValue = [];
  3352. }
  3353. }
  3354. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3355. newValue = objValue;
  3356. if (isArguments(objValue)) {
  3357. newValue = toPlainObject(objValue);
  3358. }
  3359. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3360. newValue = initCloneObject(srcValue);
  3361. }
  3362. }
  3363. else {
  3364. isCommon = false;
  3365. }
  3366. }
  3367. if (isCommon) {
  3368. // Recursively merge objects and arrays (susceptible to call stack limits).
  3369. stack.set(srcValue, newValue);
  3370. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3371. stack['delete'](srcValue);
  3372. }
  3373. assignMergeValue(object, key, newValue);
  3374. }
  3375. /**
  3376. * The base implementation of `_.nth` which doesn't coerce arguments.
  3377. *
  3378. * @private
  3379. * @param {Array} array The array to query.
  3380. * @param {number} n The index of the element to return.
  3381. * @returns {*} Returns the nth element of `array`.
  3382. */
  3383. function baseNth(array, n) {
  3384. var length = array.length;
  3385. if (!length) {
  3386. return;
  3387. }
  3388. n += n < 0 ? length : 0;
  3389. return isIndex(n, length) ? array[n] : undefined;
  3390. }
  3391. /**
  3392. * The base implementation of `_.orderBy` without param guards.
  3393. *
  3394. * @private
  3395. * @param {Array|Object} collection The collection to iterate over.
  3396. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3397. * @param {string[]} orders The sort orders of `iteratees`.
  3398. * @returns {Array} Returns the new sorted array.
  3399. */
  3400. function baseOrderBy(collection, iteratees, orders) {
  3401. var index = -1;
  3402. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3403. var result = baseMap(collection, function(value, key, collection) {
  3404. var criteria = arrayMap(iteratees, function(iteratee) {
  3405. return iteratee(value);
  3406. });
  3407. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3408. });
  3409. return baseSortBy(result, function(object, other) {
  3410. return compareMultiple(object, other, orders);
  3411. });
  3412. }
  3413. /**
  3414. * The base implementation of `_.pick` without support for individual
  3415. * property identifiers.
  3416. *
  3417. * @private
  3418. * @param {Object} object The source object.
  3419. * @param {string[]} paths The property paths to pick.
  3420. * @returns {Object} Returns the new object.
  3421. */
  3422. function basePick(object, paths) {
  3423. return basePickBy(object, paths, function(value, path) {
  3424. return hasIn(object, path);
  3425. });
  3426. }
  3427. /**
  3428. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3429. *
  3430. * @private
  3431. * @param {Object} object The source object.
  3432. * @param {string[]} paths The property paths to pick.
  3433. * @param {Function} predicate The function invoked per property.
  3434. * @returns {Object} Returns the new object.
  3435. */
  3436. function basePickBy(object, paths, predicate) {
  3437. var index = -1,
  3438. length = paths.length,
  3439. result = {};
  3440. while (++index < length) {
  3441. var path = paths[index],
  3442. value = baseGet(object, path);
  3443. if (predicate(value, path)) {
  3444. baseSet(result, castPath(path, object), value);
  3445. }
  3446. }
  3447. return result;
  3448. }
  3449. /**
  3450. * A specialized version of `baseProperty` which supports deep paths.
  3451. *
  3452. * @private
  3453. * @param {Array|string} path The path of the property to get.
  3454. * @returns {Function} Returns the new accessor function.
  3455. */
  3456. function basePropertyDeep(path) {
  3457. return function(object) {
  3458. return baseGet(object, path);
  3459. };
  3460. }
  3461. /**
  3462. * The base implementation of `_.pullAllBy` without support for iteratee
  3463. * shorthands.
  3464. *
  3465. * @private
  3466. * @param {Array} array The array to modify.
  3467. * @param {Array} values The values to remove.
  3468. * @param {Function} [iteratee] The iteratee invoked per element.
  3469. * @param {Function} [comparator] The comparator invoked per element.
  3470. * @returns {Array} Returns `array`.
  3471. */
  3472. function basePullAll(array, values, iteratee, comparator) {
  3473. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3474. index = -1,
  3475. length = values.length,
  3476. seen = array;
  3477. if (array === values) {
  3478. values = copyArray(values);
  3479. }
  3480. if (iteratee) {
  3481. seen = arrayMap(array, baseUnary(iteratee));
  3482. }
  3483. while (++index < length) {
  3484. var fromIndex = 0,
  3485. value = values[index],
  3486. computed = iteratee ? iteratee(value) : value;
  3487. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3488. if (seen !== array) {
  3489. splice.call(seen, fromIndex, 1);
  3490. }
  3491. splice.call(array, fromIndex, 1);
  3492. }
  3493. }
  3494. return array;
  3495. }
  3496. /**
  3497. * The base implementation of `_.pullAt` without support for individual
  3498. * indexes or capturing the removed elements.
  3499. *
  3500. * @private
  3501. * @param {Array} array The array to modify.
  3502. * @param {number[]} indexes The indexes of elements to remove.
  3503. * @returns {Array} Returns `array`.
  3504. */
  3505. function basePullAt(array, indexes) {
  3506. var length = array ? indexes.length : 0,
  3507. lastIndex = length - 1;
  3508. while (length--) {
  3509. var index = indexes[length];
  3510. if (length == lastIndex || index !== previous) {
  3511. var previous = index;
  3512. if (isIndex(index)) {
  3513. splice.call(array, index, 1);
  3514. } else {
  3515. baseUnset(array, index);
  3516. }
  3517. }
  3518. }
  3519. return array;
  3520. }
  3521. /**
  3522. * The base implementation of `_.random` without support for returning
  3523. * floating-point numbers.
  3524. *
  3525. * @private
  3526. * @param {number} lower The lower bound.
  3527. * @param {number} upper The upper bound.
  3528. * @returns {number} Returns the random number.
  3529. */
  3530. function baseRandom(lower, upper) {
  3531. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3532. }
  3533. /**
  3534. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3535. * coerce arguments.
  3536. *
  3537. * @private
  3538. * @param {number} start The start of the range.
  3539. * @param {number} end The end of the range.
  3540. * @param {number} step The value to increment or decrement by.
  3541. * @param {boolean} [fromRight] Specify iterating from right to left.
  3542. * @returns {Array} Returns the range of numbers.
  3543. */
  3544. function baseRange(start, end, step, fromRight) {
  3545. var index = -1,
  3546. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3547. result = Array(length);
  3548. while (length--) {
  3549. result[fromRight ? length : ++index] = start;
  3550. start += step;
  3551. }
  3552. return result;
  3553. }
  3554. /**
  3555. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3556. *
  3557. * @private
  3558. * @param {string} string The string to repeat.
  3559. * @param {number} n The number of times to repeat the string.
  3560. * @returns {string} Returns the repeated string.
  3561. */
  3562. function baseRepeat(string, n) {
  3563. var result = '';
  3564. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3565. return result;
  3566. }
  3567. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3568. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3569. do {
  3570. if (n % 2) {
  3571. result += string;
  3572. }
  3573. n = nativeFloor(n / 2);
  3574. if (n) {
  3575. string += string;
  3576. }
  3577. } while (n);
  3578. return result;
  3579. }
  3580. /**
  3581. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3582. *
  3583. * @private
  3584. * @param {Function} func The function to apply a rest parameter to.
  3585. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3586. * @returns {Function} Returns the new function.
  3587. */
  3588. function baseRest(func, start) {
  3589. return setToString(overRest(func, start, identity), func + '');
  3590. }
  3591. /**
  3592. * The base implementation of `_.sample`.
  3593. *
  3594. * @private
  3595. * @param {Array|Object} collection The collection to sample.
  3596. * @returns {*} Returns the random element.
  3597. */
  3598. function baseSample(collection) {
  3599. return arraySample(values(collection));
  3600. }
  3601. /**
  3602. * The base implementation of `_.sampleSize` without param guards.
  3603. *
  3604. * @private
  3605. * @param {Array|Object} collection The collection to sample.
  3606. * @param {number} n The number of elements to sample.
  3607. * @returns {Array} Returns the random elements.
  3608. */
  3609. function baseSampleSize(collection, n) {
  3610. var array = values(collection);
  3611. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3612. }
  3613. /**
  3614. * The base implementation of `_.set`.
  3615. *
  3616. * @private
  3617. * @param {Object} object The object to modify.
  3618. * @param {Array|string} path The path of the property to set.
  3619. * @param {*} value The value to set.
  3620. * @param {Function} [customizer] The function to customize path creation.
  3621. * @returns {Object} Returns `object`.
  3622. */
  3623. function baseSet(object, path, value, customizer) {
  3624. if (!isObject(object)) {
  3625. return object;
  3626. }
  3627. path = castPath(path, object);
  3628. var index = -1,
  3629. length = path.length,
  3630. lastIndex = length - 1,
  3631. nested = object;
  3632. while (nested != null && ++index < length) {
  3633. var key = toKey(path[index]),
  3634. newValue = value;
  3635. if (index != lastIndex) {
  3636. var objValue = nested[key];
  3637. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3638. if (newValue === undefined) {
  3639. newValue = isObject(objValue)
  3640. ? objValue
  3641. : (isIndex(path[index + 1]) ? [] : {});
  3642. }
  3643. }
  3644. assignValue(nested, key, newValue);
  3645. nested = nested[key];
  3646. }
  3647. return object;
  3648. }
  3649. /**
  3650. * The base implementation of `setData` without support for hot loop shorting.
  3651. *
  3652. * @private
  3653. * @param {Function} func The function to associate metadata with.
  3654. * @param {*} data The metadata.
  3655. * @returns {Function} Returns `func`.
  3656. */
  3657. var baseSetData = !metaMap ? identity : function(func, data) {
  3658. metaMap.set(func, data);
  3659. return func;
  3660. };
  3661. /**
  3662. * The base implementation of `setToString` without support for hot loop shorting.
  3663. *
  3664. * @private
  3665. * @param {Function} func The function to modify.
  3666. * @param {Function} string The `toString` result.
  3667. * @returns {Function} Returns `func`.
  3668. */
  3669. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3670. return defineProperty(func, 'toString', {
  3671. 'configurable': true,
  3672. 'enumerable': false,
  3673. 'value': constant(string),
  3674. 'writable': true
  3675. });
  3676. };
  3677. /**
  3678. * The base implementation of `_.shuffle`.
  3679. *
  3680. * @private
  3681. * @param {Array|Object} collection The collection to shuffle.
  3682. * @returns {Array} Returns the new shuffled array.
  3683. */
  3684. function baseShuffle(collection) {
  3685. return shuffleSelf(values(collection));
  3686. }
  3687. /**
  3688. * The base implementation of `_.slice` without an iteratee call guard.
  3689. *
  3690. * @private
  3691. * @param {Array} array The array to slice.
  3692. * @param {number} [start=0] The start position.
  3693. * @param {number} [end=array.length] The end position.
  3694. * @returns {Array} Returns the slice of `array`.
  3695. */
  3696. function baseSlice(array, start, end) {
  3697. var index = -1,
  3698. length = array.length;
  3699. if (start < 0) {
  3700. start = -start > length ? 0 : (length + start);
  3701. }
  3702. end = end > length ? length : end;
  3703. if (end < 0) {
  3704. end += length;
  3705. }
  3706. length = start > end ? 0 : ((end - start) >>> 0);
  3707. start >>>= 0;
  3708. var result = Array(length);
  3709. while (++index < length) {
  3710. result[index] = array[index + start];
  3711. }
  3712. return result;
  3713. }
  3714. /**
  3715. * The base implementation of `_.some` without support for iteratee shorthands.
  3716. *
  3717. * @private
  3718. * @param {Array|Object} collection The collection to iterate over.
  3719. * @param {Function} predicate The function invoked per iteration.
  3720. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3721. * else `false`.
  3722. */
  3723. function baseSome(collection, predicate) {
  3724. var result;
  3725. baseEach(collection, function(value, index, collection) {
  3726. result = predicate(value, index, collection);
  3727. return !result;
  3728. });
  3729. return !!result;
  3730. }
  3731. /**
  3732. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3733. * performs a binary search of `array` to determine the index at which `value`
  3734. * should be inserted into `array` in order to maintain its sort order.
  3735. *
  3736. * @private
  3737. * @param {Array} array The sorted array to inspect.
  3738. * @param {*} value The value to evaluate.
  3739. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3740. * @returns {number} Returns the index at which `value` should be inserted
  3741. * into `array`.
  3742. */
  3743. function baseSortedIndex(array, value, retHighest) {
  3744. var low = 0,
  3745. high = array == null ? low : array.length;
  3746. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3747. while (low < high) {
  3748. var mid = (low + high) >>> 1,
  3749. computed = array[mid];
  3750. if (computed !== null && !isSymbol(computed) &&
  3751. (retHighest ? (computed <= value) : (computed < value))) {
  3752. low = mid + 1;
  3753. } else {
  3754. high = mid;
  3755. }
  3756. }
  3757. return high;
  3758. }
  3759. return baseSortedIndexBy(array, value, identity, retHighest);
  3760. }
  3761. /**
  3762. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3763. * which invokes `iteratee` for `value` and each element of `array` to compute
  3764. * their sort ranking. The iteratee is invoked with one argument; (value).
  3765. *
  3766. * @private
  3767. * @param {Array} array The sorted array to inspect.
  3768. * @param {*} value The value to evaluate.
  3769. * @param {Function} iteratee The iteratee invoked per element.
  3770. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3771. * @returns {number} Returns the index at which `value` should be inserted
  3772. * into `array`.
  3773. */
  3774. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3775. value = iteratee(value);
  3776. var low = 0,
  3777. high = array == null ? 0 : array.length,
  3778. valIsNaN = value !== value,
  3779. valIsNull = value === null,
  3780. valIsSymbol = isSymbol(value),
  3781. valIsUndefined = value === undefined;
  3782. while (low < high) {
  3783. var mid = nativeFloor((low + high) / 2),
  3784. computed = iteratee(array[mid]),
  3785. othIsDefined = computed !== undefined,
  3786. othIsNull = computed === null,
  3787. othIsReflexive = computed === computed,
  3788. othIsSymbol = isSymbol(computed);
  3789. if (valIsNaN) {
  3790. var setLow = retHighest || othIsReflexive;
  3791. } else if (valIsUndefined) {
  3792. setLow = othIsReflexive && (retHighest || othIsDefined);
  3793. } else if (valIsNull) {
  3794. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3795. } else if (valIsSymbol) {
  3796. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3797. } else if (othIsNull || othIsSymbol) {
  3798. setLow = false;
  3799. } else {
  3800. setLow = retHighest ? (computed <= value) : (computed < value);
  3801. }
  3802. if (setLow) {
  3803. low = mid + 1;
  3804. } else {
  3805. high = mid;
  3806. }
  3807. }
  3808. return nativeMin(high, MAX_ARRAY_INDEX);
  3809. }
  3810. /**
  3811. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3812. * support for iteratee shorthands.
  3813. *
  3814. * @private
  3815. * @param {Array} array The array to inspect.
  3816. * @param {Function} [iteratee] The iteratee invoked per element.
  3817. * @returns {Array} Returns the new duplicate free array.
  3818. */
  3819. function baseSortedUniq(array, iteratee) {
  3820. var index = -1,
  3821. length = array.length,
  3822. resIndex = 0,
  3823. result = [];
  3824. while (++index < length) {
  3825. var value = array[index],
  3826. computed = iteratee ? iteratee(value) : value;
  3827. if (!index || !eq(computed, seen)) {
  3828. var seen = computed;
  3829. result[resIndex++] = value === 0 ? 0 : value;
  3830. }
  3831. }
  3832. return result;
  3833. }
  3834. /**
  3835. * The base implementation of `_.toNumber` which doesn't ensure correct
  3836. * conversions of binary, hexadecimal, or octal string values.
  3837. *
  3838. * @private
  3839. * @param {*} value The value to process.
  3840. * @returns {number} Returns the number.
  3841. */
  3842. function baseToNumber(value) {
  3843. if (typeof value == 'number') {
  3844. return value;
  3845. }
  3846. if (isSymbol(value)) {
  3847. return NAN;
  3848. }
  3849. return +value;
  3850. }
  3851. /**
  3852. * The base implementation of `_.toString` which doesn't convert nullish
  3853. * values to empty strings.
  3854. *
  3855. * @private
  3856. * @param {*} value The value to process.
  3857. * @returns {string} Returns the string.
  3858. */
  3859. function baseToString(value) {
  3860. // Exit early for strings to avoid a performance hit in some environments.
  3861. if (typeof value == 'string') {
  3862. return value;
  3863. }
  3864. if (isArray(value)) {
  3865. // Recursively convert values (susceptible to call stack limits).
  3866. return arrayMap(value, baseToString) + '';
  3867. }
  3868. if (isSymbol(value)) {
  3869. return symbolToString ? symbolToString.call(value) : '';
  3870. }
  3871. var result = (value + '');
  3872. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3873. }
  3874. /**
  3875. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3876. *
  3877. * @private
  3878. * @param {Array} array The array to inspect.
  3879. * @param {Function} [iteratee] The iteratee invoked per element.
  3880. * @param {Function} [comparator] The comparator invoked per element.
  3881. * @returns {Array} Returns the new duplicate free array.
  3882. */
  3883. function baseUniq(array, iteratee, comparator) {
  3884. var index = -1,
  3885. includes = arrayIncludes,
  3886. length = array.length,
  3887. isCommon = true,
  3888. result = [],
  3889. seen = result;
  3890. if (comparator) {
  3891. isCommon = false;
  3892. includes = arrayIncludesWith;
  3893. }
  3894. else if (length >= LARGE_ARRAY_SIZE) {
  3895. var set = iteratee ? null : createSet(array);
  3896. if (set) {
  3897. return setToArray(set);
  3898. }
  3899. isCommon = false;
  3900. includes = cacheHas;
  3901. seen = new SetCache;
  3902. }
  3903. else {
  3904. seen = iteratee ? [] : result;
  3905. }
  3906. outer:
  3907. while (++index < length) {
  3908. var value = array[index],
  3909. computed = iteratee ? iteratee(value) : value;
  3910. value = (comparator || value !== 0) ? value : 0;
  3911. if (isCommon && computed === computed) {
  3912. var seenIndex = seen.length;
  3913. while (seenIndex--) {
  3914. if (seen[seenIndex] === computed) {
  3915. continue outer;
  3916. }
  3917. }
  3918. if (iteratee) {
  3919. seen.push(computed);
  3920. }
  3921. result.push(value);
  3922. }
  3923. else if (!includes(seen, computed, comparator)) {
  3924. if (seen !== result) {
  3925. seen.push(computed);
  3926. }
  3927. result.push(value);
  3928. }
  3929. }
  3930. return result;
  3931. }
  3932. /**
  3933. * The base implementation of `_.unset`.
  3934. *
  3935. * @private
  3936. * @param {Object} object The object to modify.
  3937. * @param {Array|string} path The property path to unset.
  3938. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3939. */
  3940. function baseUnset(object, path) {
  3941. path = castPath(path, object);
  3942. object = parent(object, path);
  3943. return object == null || delete object[toKey(last(path))];
  3944. }
  3945. /**
  3946. * The base implementation of `_.update`.
  3947. *
  3948. * @private
  3949. * @param {Object} object The object to modify.
  3950. * @param {Array|string} path The path of the property to update.
  3951. * @param {Function} updater The function to produce the updated value.
  3952. * @param {Function} [customizer] The function to customize path creation.
  3953. * @returns {Object} Returns `object`.
  3954. */
  3955. function baseUpdate(object, path, updater, customizer) {
  3956. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3957. }
  3958. /**
  3959. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3960. * without support for iteratee shorthands.
  3961. *
  3962. * @private
  3963. * @param {Array} array The array to query.
  3964. * @param {Function} predicate The function invoked per iteration.
  3965. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3966. * @param {boolean} [fromRight] Specify iterating from right to left.
  3967. * @returns {Array} Returns the slice of `array`.
  3968. */
  3969. function baseWhile(array, predicate, isDrop, fromRight) {
  3970. var length = array.length,
  3971. index = fromRight ? length : -1;
  3972. while ((fromRight ? index-- : ++index < length) &&
  3973. predicate(array[index], index, array)) {}
  3974. return isDrop
  3975. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3976. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3977. }
  3978. /**
  3979. * The base implementation of `wrapperValue` which returns the result of
  3980. * performing a sequence of actions on the unwrapped `value`, where each
  3981. * successive action is supplied the return value of the previous.
  3982. *
  3983. * @private
  3984. * @param {*} value The unwrapped value.
  3985. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3986. * @returns {*} Returns the resolved value.
  3987. */
  3988. function baseWrapperValue(value, actions) {
  3989. var result = value;
  3990. if (result instanceof LazyWrapper) {
  3991. result = result.value();
  3992. }
  3993. return arrayReduce(actions, function(result, action) {
  3994. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3995. }, result);
  3996. }
  3997. /**
  3998. * The base implementation of methods like `_.xor`, without support for
  3999. * iteratee shorthands, that accepts an array of arrays to inspect.
  4000. *
  4001. * @private
  4002. * @param {Array} arrays The arrays to inspect.
  4003. * @param {Function} [iteratee] The iteratee invoked per element.
  4004. * @param {Function} [comparator] The comparator invoked per element.
  4005. * @returns {Array} Returns the new array of values.
  4006. */
  4007. function baseXor(arrays, iteratee, comparator) {
  4008. var length = arrays.length;
  4009. if (length < 2) {
  4010. return length ? baseUniq(arrays[0]) : [];
  4011. }
  4012. var index = -1,
  4013. result = Array(length);
  4014. while (++index < length) {
  4015. var array = arrays[index],
  4016. othIndex = -1;
  4017. while (++othIndex < length) {
  4018. if (othIndex != index) {
  4019. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4020. }
  4021. }
  4022. }
  4023. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4024. }
  4025. /**
  4026. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4027. *
  4028. * @private
  4029. * @param {Array} props The property identifiers.
  4030. * @param {Array} values The property values.
  4031. * @param {Function} assignFunc The function to assign values.
  4032. * @returns {Object} Returns the new object.
  4033. */
  4034. function baseZipObject(props, values, assignFunc) {
  4035. var index = -1,
  4036. length = props.length,
  4037. valsLength = values.length,
  4038. result = {};
  4039. while (++index < length) {
  4040. var value = index < valsLength ? values[index] : undefined;
  4041. assignFunc(result, props[index], value);
  4042. }
  4043. return result;
  4044. }
  4045. /**
  4046. * Casts `value` to an empty array if it's not an array like object.
  4047. *
  4048. * @private
  4049. * @param {*} value The value to inspect.
  4050. * @returns {Array|Object} Returns the cast array-like object.
  4051. */
  4052. function castArrayLikeObject(value) {
  4053. return isArrayLikeObject(value) ? value : [];
  4054. }
  4055. /**
  4056. * Casts `value` to `identity` if it's not a function.
  4057. *
  4058. * @private
  4059. * @param {*} value The value to inspect.
  4060. * @returns {Function} Returns cast function.
  4061. */
  4062. function castFunction(value) {
  4063. return typeof value == 'function' ? value : identity;
  4064. }
  4065. /**
  4066. * Casts `value` to a path array if it's not one.
  4067. *
  4068. * @private
  4069. * @param {*} value The value to inspect.
  4070. * @param {Object} [object] The object to query keys on.
  4071. * @returns {Array} Returns the cast property path array.
  4072. */
  4073. function castPath(value, object) {
  4074. if (isArray(value)) {
  4075. return value;
  4076. }
  4077. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4078. }
  4079. /**
  4080. * A `baseRest` alias which can be replaced with `identity` by module
  4081. * replacement plugins.
  4082. *
  4083. * @private
  4084. * @type {Function}
  4085. * @param {Function} func The function to apply a rest parameter to.
  4086. * @returns {Function} Returns the new function.
  4087. */
  4088. var castRest = baseRest;
  4089. /**
  4090. * Casts `array` to a slice if it's needed.
  4091. *
  4092. * @private
  4093. * @param {Array} array The array to inspect.
  4094. * @param {number} start The start position.
  4095. * @param {number} [end=array.length] The end position.
  4096. * @returns {Array} Returns the cast slice.
  4097. */
  4098. function castSlice(array, start, end) {
  4099. var length = array.length;
  4100. end = end === undefined ? length : end;
  4101. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4102. }
  4103. /**
  4104. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4105. *
  4106. * @private
  4107. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4108. */
  4109. var clearTimeout = ctxClearTimeout || function(id) {
  4110. return root.clearTimeout(id);
  4111. };
  4112. /**
  4113. * Creates a clone of `buffer`.
  4114. *
  4115. * @private
  4116. * @param {Buffer} buffer The buffer to clone.
  4117. * @param {boolean} [isDeep] Specify a deep clone.
  4118. * @returns {Buffer} Returns the cloned buffer.
  4119. */
  4120. function cloneBuffer(buffer, isDeep) {
  4121. if (isDeep) {
  4122. return buffer.slice();
  4123. }
  4124. var length = buffer.length,
  4125. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4126. buffer.copy(result);
  4127. return result;
  4128. }
  4129. /**
  4130. * Creates a clone of `arrayBuffer`.
  4131. *
  4132. * @private
  4133. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4134. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4135. */
  4136. function cloneArrayBuffer(arrayBuffer) {
  4137. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4138. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4139. return result;
  4140. }
  4141. /**
  4142. * Creates a clone of `dataView`.
  4143. *
  4144. * @private
  4145. * @param {Object} dataView The data view to clone.
  4146. * @param {boolean} [isDeep] Specify a deep clone.
  4147. * @returns {Object} Returns the cloned data view.
  4148. */
  4149. function cloneDataView(dataView, isDeep) {
  4150. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4151. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4152. }
  4153. /**
  4154. * Creates a clone of `regexp`.
  4155. *
  4156. * @private
  4157. * @param {Object} regexp The regexp to clone.
  4158. * @returns {Object} Returns the cloned regexp.
  4159. */
  4160. function cloneRegExp(regexp) {
  4161. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4162. result.lastIndex = regexp.lastIndex;
  4163. return result;
  4164. }
  4165. /**
  4166. * Creates a clone of the `symbol` object.
  4167. *
  4168. * @private
  4169. * @param {Object} symbol The symbol object to clone.
  4170. * @returns {Object} Returns the cloned symbol object.
  4171. */
  4172. function cloneSymbol(symbol) {
  4173. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4174. }
  4175. /**
  4176. * Creates a clone of `typedArray`.
  4177. *
  4178. * @private
  4179. * @param {Object} typedArray The typed array to clone.
  4180. * @param {boolean} [isDeep] Specify a deep clone.
  4181. * @returns {Object} Returns the cloned typed array.
  4182. */
  4183. function cloneTypedArray(typedArray, isDeep) {
  4184. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4185. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4186. }
  4187. /**
  4188. * Compares values to sort them in ascending order.
  4189. *
  4190. * @private
  4191. * @param {*} value The value to compare.
  4192. * @param {*} other The other value to compare.
  4193. * @returns {number} Returns the sort order indicator for `value`.
  4194. */
  4195. function compareAscending(value, other) {
  4196. if (value !== other) {
  4197. var valIsDefined = value !== undefined,
  4198. valIsNull = value === null,
  4199. valIsReflexive = value === value,
  4200. valIsSymbol = isSymbol(value);
  4201. var othIsDefined = other !== undefined,
  4202. othIsNull = other === null,
  4203. othIsReflexive = other === other,
  4204. othIsSymbol = isSymbol(other);
  4205. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4206. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4207. (valIsNull && othIsDefined && othIsReflexive) ||
  4208. (!valIsDefined && othIsReflexive) ||
  4209. !valIsReflexive) {
  4210. return 1;
  4211. }
  4212. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4213. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4214. (othIsNull && valIsDefined && valIsReflexive) ||
  4215. (!othIsDefined && valIsReflexive) ||
  4216. !othIsReflexive) {
  4217. return -1;
  4218. }
  4219. }
  4220. return 0;
  4221. }
  4222. /**
  4223. * Used by `_.orderBy` to compare multiple properties of a value to another
  4224. * and stable sort them.
  4225. *
  4226. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4227. * specify an order of "desc" for descending or "asc" for ascending sort order
  4228. * of corresponding values.
  4229. *
  4230. * @private
  4231. * @param {Object} object The object to compare.
  4232. * @param {Object} other The other object to compare.
  4233. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4234. * @returns {number} Returns the sort order indicator for `object`.
  4235. */
  4236. function compareMultiple(object, other, orders) {
  4237. var index = -1,
  4238. objCriteria = object.criteria,
  4239. othCriteria = other.criteria,
  4240. length = objCriteria.length,
  4241. ordersLength = orders.length;
  4242. while (++index < length) {
  4243. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4244. if (result) {
  4245. if (index >= ordersLength) {
  4246. return result;
  4247. }
  4248. var order = orders[index];
  4249. return result * (order == 'desc' ? -1 : 1);
  4250. }
  4251. }
  4252. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4253. // that causes it, under certain circumstances, to provide the same value for
  4254. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4255. // for more details.
  4256. //
  4257. // This also ensures a stable sort in V8 and other engines.
  4258. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4259. return object.index - other.index;
  4260. }
  4261. /**
  4262. * Creates an array that is the composition of partially applied arguments,
  4263. * placeholders, and provided arguments into a single array of arguments.
  4264. *
  4265. * @private
  4266. * @param {Array} args The provided arguments.
  4267. * @param {Array} partials The arguments to prepend to those provided.
  4268. * @param {Array} holders The `partials` placeholder indexes.
  4269. * @params {boolean} [isCurried] Specify composing for a curried function.
  4270. * @returns {Array} Returns the new array of composed arguments.
  4271. */
  4272. function composeArgs(args, partials, holders, isCurried) {
  4273. var argsIndex = -1,
  4274. argsLength = args.length,
  4275. holdersLength = holders.length,
  4276. leftIndex = -1,
  4277. leftLength = partials.length,
  4278. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4279. result = Array(leftLength + rangeLength),
  4280. isUncurried = !isCurried;
  4281. while (++leftIndex < leftLength) {
  4282. result[leftIndex] = partials[leftIndex];
  4283. }
  4284. while (++argsIndex < holdersLength) {
  4285. if (isUncurried || argsIndex < argsLength) {
  4286. result[holders[argsIndex]] = args[argsIndex];
  4287. }
  4288. }
  4289. while (rangeLength--) {
  4290. result[leftIndex++] = args[argsIndex++];
  4291. }
  4292. return result;
  4293. }
  4294. /**
  4295. * This function is like `composeArgs` except that the arguments composition
  4296. * is tailored for `_.partialRight`.
  4297. *
  4298. * @private
  4299. * @param {Array} args The provided arguments.
  4300. * @param {Array} partials The arguments to append to those provided.
  4301. * @param {Array} holders The `partials` placeholder indexes.
  4302. * @params {boolean} [isCurried] Specify composing for a curried function.
  4303. * @returns {Array} Returns the new array of composed arguments.
  4304. */
  4305. function composeArgsRight(args, partials, holders, isCurried) {
  4306. var argsIndex = -1,
  4307. argsLength = args.length,
  4308. holdersIndex = -1,
  4309. holdersLength = holders.length,
  4310. rightIndex = -1,
  4311. rightLength = partials.length,
  4312. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4313. result = Array(rangeLength + rightLength),
  4314. isUncurried = !isCurried;
  4315. while (++argsIndex < rangeLength) {
  4316. result[argsIndex] = args[argsIndex];
  4317. }
  4318. var offset = argsIndex;
  4319. while (++rightIndex < rightLength) {
  4320. result[offset + rightIndex] = partials[rightIndex];
  4321. }
  4322. while (++holdersIndex < holdersLength) {
  4323. if (isUncurried || argsIndex < argsLength) {
  4324. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4325. }
  4326. }
  4327. return result;
  4328. }
  4329. /**
  4330. * Copies the values of `source` to `array`.
  4331. *
  4332. * @private
  4333. * @param {Array} source The array to copy values from.
  4334. * @param {Array} [array=[]] The array to copy values to.
  4335. * @returns {Array} Returns `array`.
  4336. */
  4337. function copyArray(source, array) {
  4338. var index = -1,
  4339. length = source.length;
  4340. array || (array = Array(length));
  4341. while (++index < length) {
  4342. array[index] = source[index];
  4343. }
  4344. return array;
  4345. }
  4346. /**
  4347. * Copies properties of `source` to `object`.
  4348. *
  4349. * @private
  4350. * @param {Object} source The object to copy properties from.
  4351. * @param {Array} props The property identifiers to copy.
  4352. * @param {Object} [object={}] The object to copy properties to.
  4353. * @param {Function} [customizer] The function to customize copied values.
  4354. * @returns {Object} Returns `object`.
  4355. */
  4356. function copyObject(source, props, object, customizer) {
  4357. var isNew = !object;
  4358. object || (object = {});
  4359. var index = -1,
  4360. length = props.length;
  4361. while (++index < length) {
  4362. var key = props[index];
  4363. var newValue = customizer
  4364. ? customizer(object[key], source[key], key, object, source)
  4365. : undefined;
  4366. if (newValue === undefined) {
  4367. newValue = source[key];
  4368. }
  4369. if (isNew) {
  4370. baseAssignValue(object, key, newValue);
  4371. } else {
  4372. assignValue(object, key, newValue);
  4373. }
  4374. }
  4375. return object;
  4376. }
  4377. /**
  4378. * Copies own symbols of `source` to `object`.
  4379. *
  4380. * @private
  4381. * @param {Object} source The object to copy symbols from.
  4382. * @param {Object} [object={}] The object to copy symbols to.
  4383. * @returns {Object} Returns `object`.
  4384. */
  4385. function copySymbols(source, object) {
  4386. return copyObject(source, getSymbols(source), object);
  4387. }
  4388. /**
  4389. * Copies own and inherited symbols of `source` to `object`.
  4390. *
  4391. * @private
  4392. * @param {Object} source The object to copy symbols from.
  4393. * @param {Object} [object={}] The object to copy symbols to.
  4394. * @returns {Object} Returns `object`.
  4395. */
  4396. function copySymbolsIn(source, object) {
  4397. return copyObject(source, getSymbolsIn(source), object);
  4398. }
  4399. /**
  4400. * Creates a function like `_.groupBy`.
  4401. *
  4402. * @private
  4403. * @param {Function} setter The function to set accumulator values.
  4404. * @param {Function} [initializer] The accumulator object initializer.
  4405. * @returns {Function} Returns the new aggregator function.
  4406. */
  4407. function createAggregator(setter, initializer) {
  4408. return function(collection, iteratee) {
  4409. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4410. accumulator = initializer ? initializer() : {};
  4411. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4412. };
  4413. }
  4414. /**
  4415. * Creates a function like `_.assign`.
  4416. *
  4417. * @private
  4418. * @param {Function} assigner The function to assign values.
  4419. * @returns {Function} Returns the new assigner function.
  4420. */
  4421. function createAssigner(assigner) {
  4422. return baseRest(function(object, sources) {
  4423. var index = -1,
  4424. length = sources.length,
  4425. customizer = length > 1 ? sources[length - 1] : undefined,
  4426. guard = length > 2 ? sources[2] : undefined;
  4427. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4428. ? (length--, customizer)
  4429. : undefined;
  4430. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4431. customizer = length < 3 ? undefined : customizer;
  4432. length = 1;
  4433. }
  4434. object = Object(object);
  4435. while (++index < length) {
  4436. var source = sources[index];
  4437. if (source) {
  4438. assigner(object, source, index, customizer);
  4439. }
  4440. }
  4441. return object;
  4442. });
  4443. }
  4444. /**
  4445. * Creates a `baseEach` or `baseEachRight` function.
  4446. *
  4447. * @private
  4448. * @param {Function} eachFunc The function to iterate over a collection.
  4449. * @param {boolean} [fromRight] Specify iterating from right to left.
  4450. * @returns {Function} Returns the new base function.
  4451. */
  4452. function createBaseEach(eachFunc, fromRight) {
  4453. return function(collection, iteratee) {
  4454. if (collection == null) {
  4455. return collection;
  4456. }
  4457. if (!isArrayLike(collection)) {
  4458. return eachFunc(collection, iteratee);
  4459. }
  4460. var length = collection.length,
  4461. index = fromRight ? length : -1,
  4462. iterable = Object(collection);
  4463. while ((fromRight ? index-- : ++index < length)) {
  4464. if (iteratee(iterable[index], index, iterable) === false) {
  4465. break;
  4466. }
  4467. }
  4468. return collection;
  4469. };
  4470. }
  4471. /**
  4472. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4473. *
  4474. * @private
  4475. * @param {boolean} [fromRight] Specify iterating from right to left.
  4476. * @returns {Function} Returns the new base function.
  4477. */
  4478. function createBaseFor(fromRight) {
  4479. return function(object, iteratee, keysFunc) {
  4480. var index = -1,
  4481. iterable = Object(object),
  4482. props = keysFunc(object),
  4483. length = props.length;
  4484. while (length--) {
  4485. var key = props[fromRight ? length : ++index];
  4486. if (iteratee(iterable[key], key, iterable) === false) {
  4487. break;
  4488. }
  4489. }
  4490. return object;
  4491. };
  4492. }
  4493. /**
  4494. * Creates a function that wraps `func` to invoke it with the optional `this`
  4495. * binding of `thisArg`.
  4496. *
  4497. * @private
  4498. * @param {Function} func The function to wrap.
  4499. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4500. * @param {*} [thisArg] The `this` binding of `func`.
  4501. * @returns {Function} Returns the new wrapped function.
  4502. */
  4503. function createBind(func, bitmask, thisArg) {
  4504. var isBind = bitmask & WRAP_BIND_FLAG,
  4505. Ctor = createCtor(func);
  4506. function wrapper() {
  4507. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4508. return fn.apply(isBind ? thisArg : this, arguments);
  4509. }
  4510. return wrapper;
  4511. }
  4512. /**
  4513. * Creates a function like `_.lowerFirst`.
  4514. *
  4515. * @private
  4516. * @param {string} methodName The name of the `String` case method to use.
  4517. * @returns {Function} Returns the new case function.
  4518. */
  4519. function createCaseFirst(methodName) {
  4520. return function(string) {
  4521. string = toString(string);
  4522. var strSymbols = hasUnicode(string)
  4523. ? stringToArray(string)
  4524. : undefined;
  4525. var chr = strSymbols
  4526. ? strSymbols[0]
  4527. : string.charAt(0);
  4528. var trailing = strSymbols
  4529. ? castSlice(strSymbols, 1).join('')
  4530. : string.slice(1);
  4531. return chr[methodName]() + trailing;
  4532. };
  4533. }
  4534. /**
  4535. * Creates a function like `_.camelCase`.
  4536. *
  4537. * @private
  4538. * @param {Function} callback The function to combine each word.
  4539. * @returns {Function} Returns the new compounder function.
  4540. */
  4541. function createCompounder(callback) {
  4542. return function(string) {
  4543. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4544. };
  4545. }
  4546. /**
  4547. * Creates a function that produces an instance of `Ctor` regardless of
  4548. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4549. *
  4550. * @private
  4551. * @param {Function} Ctor The constructor to wrap.
  4552. * @returns {Function} Returns the new wrapped function.
  4553. */
  4554. function createCtor(Ctor) {
  4555. return function() {
  4556. // Use a `switch` statement to work with class constructors. See
  4557. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4558. // for more details.
  4559. var args = arguments;
  4560. switch (args.length) {
  4561. case 0: return new Ctor;
  4562. case 1: return new Ctor(args[0]);
  4563. case 2: return new Ctor(args[0], args[1]);
  4564. case 3: return new Ctor(args[0], args[1], args[2]);
  4565. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4566. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4567. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4568. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4569. }
  4570. var thisBinding = baseCreate(Ctor.prototype),
  4571. result = Ctor.apply(thisBinding, args);
  4572. // Mimic the constructor's `return` behavior.
  4573. // See https://es5.github.io/#x13.2.2 for more details.
  4574. return isObject(result) ? result : thisBinding;
  4575. };
  4576. }
  4577. /**
  4578. * Creates a function that wraps `func` to enable currying.
  4579. *
  4580. * @private
  4581. * @param {Function} func The function to wrap.
  4582. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4583. * @param {number} arity The arity of `func`.
  4584. * @returns {Function} Returns the new wrapped function.
  4585. */
  4586. function createCurry(func, bitmask, arity) {
  4587. var Ctor = createCtor(func);
  4588. function wrapper() {
  4589. var length = arguments.length,
  4590. args = Array(length),
  4591. index = length,
  4592. placeholder = getHolder(wrapper);
  4593. while (index--) {
  4594. args[index] = arguments[index];
  4595. }
  4596. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4597. ? []
  4598. : replaceHolders(args, placeholder);
  4599. length -= holders.length;
  4600. if (length < arity) {
  4601. return createRecurry(
  4602. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4603. args, holders, undefined, undefined, arity - length);
  4604. }
  4605. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4606. return apply(fn, this, args);
  4607. }
  4608. return wrapper;
  4609. }
  4610. /**
  4611. * Creates a `_.find` or `_.findLast` function.
  4612. *
  4613. * @private
  4614. * @param {Function} findIndexFunc The function to find the collection index.
  4615. * @returns {Function} Returns the new find function.
  4616. */
  4617. function createFind(findIndexFunc) {
  4618. return function(collection, predicate, fromIndex) {
  4619. var iterable = Object(collection);
  4620. if (!isArrayLike(collection)) {
  4621. var iteratee = getIteratee(predicate, 3);
  4622. collection = keys(collection);
  4623. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4624. }
  4625. var index = findIndexFunc(collection, predicate, fromIndex);
  4626. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4627. };
  4628. }
  4629. /**
  4630. * Creates a `_.flow` or `_.flowRight` function.
  4631. *
  4632. * @private
  4633. * @param {boolean} [fromRight] Specify iterating from right to left.
  4634. * @returns {Function} Returns the new flow function.
  4635. */
  4636. function createFlow(fromRight) {
  4637. return flatRest(function(funcs) {
  4638. var length = funcs.length,
  4639. index = length,
  4640. prereq = LodashWrapper.prototype.thru;
  4641. if (fromRight) {
  4642. funcs.reverse();
  4643. }
  4644. while (index--) {
  4645. var func = funcs[index];
  4646. if (typeof func != 'function') {
  4647. throw new TypeError(FUNC_ERROR_TEXT);
  4648. }
  4649. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4650. var wrapper = new LodashWrapper([], true);
  4651. }
  4652. }
  4653. index = wrapper ? index : length;
  4654. while (++index < length) {
  4655. func = funcs[index];
  4656. var funcName = getFuncName(func),
  4657. data = funcName == 'wrapper' ? getData(func) : undefined;
  4658. if (data && isLaziable(data[0]) &&
  4659. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4660. !data[4].length && data[9] == 1
  4661. ) {
  4662. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4663. } else {
  4664. wrapper = (func.length == 1 && isLaziable(func))
  4665. ? wrapper[funcName]()
  4666. : wrapper.thru(func);
  4667. }
  4668. }
  4669. return function() {
  4670. var args = arguments,
  4671. value = args[0];
  4672. if (wrapper && args.length == 1 && isArray(value)) {
  4673. return wrapper.plant(value).value();
  4674. }
  4675. var index = 0,
  4676. result = length ? funcs[index].apply(this, args) : value;
  4677. while (++index < length) {
  4678. result = funcs[index].call(this, result);
  4679. }
  4680. return result;
  4681. };
  4682. });
  4683. }
  4684. /**
  4685. * Creates a function that wraps `func` to invoke it with optional `this`
  4686. * binding of `thisArg`, partial application, and currying.
  4687. *
  4688. * @private
  4689. * @param {Function|string} func The function or method name to wrap.
  4690. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4691. * @param {*} [thisArg] The `this` binding of `func`.
  4692. * @param {Array} [partials] The arguments to prepend to those provided to
  4693. * the new function.
  4694. * @param {Array} [holders] The `partials` placeholder indexes.
  4695. * @param {Array} [partialsRight] The arguments to append to those provided
  4696. * to the new function.
  4697. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4698. * @param {Array} [argPos] The argument positions of the new function.
  4699. * @param {number} [ary] The arity cap of `func`.
  4700. * @param {number} [arity] The arity of `func`.
  4701. * @returns {Function} Returns the new wrapped function.
  4702. */
  4703. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4704. var isAry = bitmask & WRAP_ARY_FLAG,
  4705. isBind = bitmask & WRAP_BIND_FLAG,
  4706. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4707. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4708. isFlip = bitmask & WRAP_FLIP_FLAG,
  4709. Ctor = isBindKey ? undefined : createCtor(func);
  4710. function wrapper() {
  4711. var length = arguments.length,
  4712. args = Array(length),
  4713. index = length;
  4714. while (index--) {
  4715. args[index] = arguments[index];
  4716. }
  4717. if (isCurried) {
  4718. var placeholder = getHolder(wrapper),
  4719. holdersCount = countHolders(args, placeholder);
  4720. }
  4721. if (partials) {
  4722. args = composeArgs(args, partials, holders, isCurried);
  4723. }
  4724. if (partialsRight) {
  4725. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4726. }
  4727. length -= holdersCount;
  4728. if (isCurried && length < arity) {
  4729. var newHolders = replaceHolders(args, placeholder);
  4730. return createRecurry(
  4731. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4732. args, newHolders, argPos, ary, arity - length
  4733. );
  4734. }
  4735. var thisBinding = isBind ? thisArg : this,
  4736. fn = isBindKey ? thisBinding[func] : func;
  4737. length = args.length;
  4738. if (argPos) {
  4739. args = reorder(args, argPos);
  4740. } else if (isFlip && length > 1) {
  4741. args.reverse();
  4742. }
  4743. if (isAry && ary < length) {
  4744. args.length = ary;
  4745. }
  4746. if (this && this !== root && this instanceof wrapper) {
  4747. fn = Ctor || createCtor(fn);
  4748. }
  4749. return fn.apply(thisBinding, args);
  4750. }
  4751. return wrapper;
  4752. }
  4753. /**
  4754. * Creates a function like `_.invertBy`.
  4755. *
  4756. * @private
  4757. * @param {Function} setter The function to set accumulator values.
  4758. * @param {Function} toIteratee The function to resolve iteratees.
  4759. * @returns {Function} Returns the new inverter function.
  4760. */
  4761. function createInverter(setter, toIteratee) {
  4762. return function(object, iteratee) {
  4763. return baseInverter(object, setter, toIteratee(iteratee), {});
  4764. };
  4765. }
  4766. /**
  4767. * Creates a function that performs a mathematical operation on two values.
  4768. *
  4769. * @private
  4770. * @param {Function} operator The function to perform the operation.
  4771. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4772. * @returns {Function} Returns the new mathematical operation function.
  4773. */
  4774. function createMathOperation(operator, defaultValue) {
  4775. return function(value, other) {
  4776. var result;
  4777. if (value === undefined && other === undefined) {
  4778. return defaultValue;
  4779. }
  4780. if (value !== undefined) {
  4781. result = value;
  4782. }
  4783. if (other !== undefined) {
  4784. if (result === undefined) {
  4785. return other;
  4786. }
  4787. if (typeof value == 'string' || typeof other == 'string') {
  4788. value = baseToString(value);
  4789. other = baseToString(other);
  4790. } else {
  4791. value = baseToNumber(value);
  4792. other = baseToNumber(other);
  4793. }
  4794. result = operator(value, other);
  4795. }
  4796. return result;
  4797. };
  4798. }
  4799. /**
  4800. * Creates a function like `_.over`.
  4801. *
  4802. * @private
  4803. * @param {Function} arrayFunc The function to iterate over iteratees.
  4804. * @returns {Function} Returns the new over function.
  4805. */
  4806. function createOver(arrayFunc) {
  4807. return flatRest(function(iteratees) {
  4808. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4809. return baseRest(function(args) {
  4810. var thisArg = this;
  4811. return arrayFunc(iteratees, function(iteratee) {
  4812. return apply(iteratee, thisArg, args);
  4813. });
  4814. });
  4815. });
  4816. }
  4817. /**
  4818. * Creates the padding for `string` based on `length`. The `chars` string
  4819. * is truncated if the number of characters exceeds `length`.
  4820. *
  4821. * @private
  4822. * @param {number} length The padding length.
  4823. * @param {string} [chars=' '] The string used as padding.
  4824. * @returns {string} Returns the padding for `string`.
  4825. */
  4826. function createPadding(length, chars) {
  4827. chars = chars === undefined ? ' ' : baseToString(chars);
  4828. var charsLength = chars.length;
  4829. if (charsLength < 2) {
  4830. return charsLength ? baseRepeat(chars, length) : chars;
  4831. }
  4832. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4833. return hasUnicode(chars)
  4834. ? castSlice(stringToArray(result), 0, length).join('')
  4835. : result.slice(0, length);
  4836. }
  4837. /**
  4838. * Creates a function that wraps `func` to invoke it with the `this` binding
  4839. * of `thisArg` and `partials` prepended to the arguments it receives.
  4840. *
  4841. * @private
  4842. * @param {Function} func The function to wrap.
  4843. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4844. * @param {*} thisArg The `this` binding of `func`.
  4845. * @param {Array} partials The arguments to prepend to those provided to
  4846. * the new function.
  4847. * @returns {Function} Returns the new wrapped function.
  4848. */
  4849. function createPartial(func, bitmask, thisArg, partials) {
  4850. var isBind = bitmask & WRAP_BIND_FLAG,
  4851. Ctor = createCtor(func);
  4852. function wrapper() {
  4853. var argsIndex = -1,
  4854. argsLength = arguments.length,
  4855. leftIndex = -1,
  4856. leftLength = partials.length,
  4857. args = Array(leftLength + argsLength),
  4858. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4859. while (++leftIndex < leftLength) {
  4860. args[leftIndex] = partials[leftIndex];
  4861. }
  4862. while (argsLength--) {
  4863. args[leftIndex++] = arguments[++argsIndex];
  4864. }
  4865. return apply(fn, isBind ? thisArg : this, args);
  4866. }
  4867. return wrapper;
  4868. }
  4869. /**
  4870. * Creates a `_.range` or `_.rangeRight` function.
  4871. *
  4872. * @private
  4873. * @param {boolean} [fromRight] Specify iterating from right to left.
  4874. * @returns {Function} Returns the new range function.
  4875. */
  4876. function createRange(fromRight) {
  4877. return function(start, end, step) {
  4878. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4879. end = step = undefined;
  4880. }
  4881. // Ensure the sign of `-0` is preserved.
  4882. start = toFinite(start);
  4883. if (end === undefined) {
  4884. end = start;
  4885. start = 0;
  4886. } else {
  4887. end = toFinite(end);
  4888. }
  4889. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4890. return baseRange(start, end, step, fromRight);
  4891. };
  4892. }
  4893. /**
  4894. * Creates a function that performs a relational operation on two values.
  4895. *
  4896. * @private
  4897. * @param {Function} operator The function to perform the operation.
  4898. * @returns {Function} Returns the new relational operation function.
  4899. */
  4900. function createRelationalOperation(operator) {
  4901. return function(value, other) {
  4902. if (!(typeof value == 'string' && typeof other == 'string')) {
  4903. value = toNumber(value);
  4904. other = toNumber(other);
  4905. }
  4906. return operator(value, other);
  4907. };
  4908. }
  4909. /**
  4910. * Creates a function that wraps `func` to continue currying.
  4911. *
  4912. * @private
  4913. * @param {Function} func The function to wrap.
  4914. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4915. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4916. * @param {*} placeholder The placeholder value.
  4917. * @param {*} [thisArg] The `this` binding of `func`.
  4918. * @param {Array} [partials] The arguments to prepend to those provided to
  4919. * the new function.
  4920. * @param {Array} [holders] The `partials` placeholder indexes.
  4921. * @param {Array} [argPos] The argument positions of the new function.
  4922. * @param {number} [ary] The arity cap of `func`.
  4923. * @param {number} [arity] The arity of `func`.
  4924. * @returns {Function} Returns the new wrapped function.
  4925. */
  4926. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4927. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4928. newHolders = isCurry ? holders : undefined,
  4929. newHoldersRight = isCurry ? undefined : holders,
  4930. newPartials = isCurry ? partials : undefined,
  4931. newPartialsRight = isCurry ? undefined : partials;
  4932. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4933. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4934. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4935. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4936. }
  4937. var newData = [
  4938. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4939. newHoldersRight, argPos, ary, arity
  4940. ];
  4941. var result = wrapFunc.apply(undefined, newData);
  4942. if (isLaziable(func)) {
  4943. setData(result, newData);
  4944. }
  4945. result.placeholder = placeholder;
  4946. return setWrapToString(result, func, bitmask);
  4947. }
  4948. /**
  4949. * Creates a function like `_.round`.
  4950. *
  4951. * @private
  4952. * @param {string} methodName The name of the `Math` method to use when rounding.
  4953. * @returns {Function} Returns the new round function.
  4954. */
  4955. function createRound(methodName) {
  4956. var func = Math[methodName];
  4957. return function(number, precision) {
  4958. number = toNumber(number);
  4959. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4960. if (precision) {
  4961. // Shift with exponential notation to avoid floating-point issues.
  4962. // See [MDN](https://mdn.io/round#Examples) for more details.
  4963. var pair = (toString(number) + 'e').split('e'),
  4964. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4965. pair = (toString(value) + 'e').split('e');
  4966. return +(pair[0] + 'e' + (+pair[1] - precision));
  4967. }
  4968. return func(number);
  4969. };
  4970. }
  4971. /**
  4972. * Creates a set object of `values`.
  4973. *
  4974. * @private
  4975. * @param {Array} values The values to add to the set.
  4976. * @returns {Object} Returns the new set.
  4977. */
  4978. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4979. return new Set(values);
  4980. };
  4981. /**
  4982. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4983. *
  4984. * @private
  4985. * @param {Function} keysFunc The function to get the keys of a given object.
  4986. * @returns {Function} Returns the new pairs function.
  4987. */
  4988. function createToPairs(keysFunc) {
  4989. return function(object) {
  4990. var tag = getTag(object);
  4991. if (tag == mapTag) {
  4992. return mapToArray(object);
  4993. }
  4994. if (tag == setTag) {
  4995. return setToPairs(object);
  4996. }
  4997. return baseToPairs(object, keysFunc(object));
  4998. };
  4999. }
  5000. /**
  5001. * Creates a function that either curries or invokes `func` with optional
  5002. * `this` binding and partially applied arguments.
  5003. *
  5004. * @private
  5005. * @param {Function|string} func The function or method name to wrap.
  5006. * @param {number} bitmask The bitmask flags.
  5007. * 1 - `_.bind`
  5008. * 2 - `_.bindKey`
  5009. * 4 - `_.curry` or `_.curryRight` of a bound function
  5010. * 8 - `_.curry`
  5011. * 16 - `_.curryRight`
  5012. * 32 - `_.partial`
  5013. * 64 - `_.partialRight`
  5014. * 128 - `_.rearg`
  5015. * 256 - `_.ary`
  5016. * 512 - `_.flip`
  5017. * @param {*} [thisArg] The `this` binding of `func`.
  5018. * @param {Array} [partials] The arguments to be partially applied.
  5019. * @param {Array} [holders] The `partials` placeholder indexes.
  5020. * @param {Array} [argPos] The argument positions of the new function.
  5021. * @param {number} [ary] The arity cap of `func`.
  5022. * @param {number} [arity] The arity of `func`.
  5023. * @returns {Function} Returns the new wrapped function.
  5024. */
  5025. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5026. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5027. if (!isBindKey && typeof func != 'function') {
  5028. throw new TypeError(FUNC_ERROR_TEXT);
  5029. }
  5030. var length = partials ? partials.length : 0;
  5031. if (!length) {
  5032. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5033. partials = holders = undefined;
  5034. }
  5035. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5036. arity = arity === undefined ? arity : toInteger(arity);
  5037. length -= holders ? holders.length : 0;
  5038. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5039. var partialsRight = partials,
  5040. holdersRight = holders;
  5041. partials = holders = undefined;
  5042. }
  5043. var data = isBindKey ? undefined : getData(func);
  5044. var newData = [
  5045. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5046. argPos, ary, arity
  5047. ];
  5048. if (data) {
  5049. mergeData(newData, data);
  5050. }
  5051. func = newData[0];
  5052. bitmask = newData[1];
  5053. thisArg = newData[2];
  5054. partials = newData[3];
  5055. holders = newData[4];
  5056. arity = newData[9] = newData[9] === undefined
  5057. ? (isBindKey ? 0 : func.length)
  5058. : nativeMax(newData[9] - length, 0);
  5059. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5060. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5061. }
  5062. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5063. var result = createBind(func, bitmask, thisArg);
  5064. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5065. result = createCurry(func, bitmask, arity);
  5066. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5067. result = createPartial(func, bitmask, thisArg, partials);
  5068. } else {
  5069. result = createHybrid.apply(undefined, newData);
  5070. }
  5071. var setter = data ? baseSetData : setData;
  5072. return setWrapToString(setter(result, newData), func, bitmask);
  5073. }
  5074. /**
  5075. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5076. * of source objects to the destination object for all destination properties
  5077. * that resolve to `undefined`.
  5078. *
  5079. * @private
  5080. * @param {*} objValue The destination value.
  5081. * @param {*} srcValue The source value.
  5082. * @param {string} key The key of the property to assign.
  5083. * @param {Object} object The parent object of `objValue`.
  5084. * @returns {*} Returns the value to assign.
  5085. */
  5086. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5087. if (objValue === undefined ||
  5088. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5089. return srcValue;
  5090. }
  5091. return objValue;
  5092. }
  5093. /**
  5094. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5095. * objects into destination objects that are passed thru.
  5096. *
  5097. * @private
  5098. * @param {*} objValue The destination value.
  5099. * @param {*} srcValue The source value.
  5100. * @param {string} key The key of the property to merge.
  5101. * @param {Object} object The parent object of `objValue`.
  5102. * @param {Object} source The parent object of `srcValue`.
  5103. * @param {Object} [stack] Tracks traversed source values and their merged
  5104. * counterparts.
  5105. * @returns {*} Returns the value to assign.
  5106. */
  5107. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5108. if (isObject(objValue) && isObject(srcValue)) {
  5109. // Recursively merge objects and arrays (susceptible to call stack limits).
  5110. stack.set(srcValue, objValue);
  5111. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5112. stack['delete'](srcValue);
  5113. }
  5114. return objValue;
  5115. }
  5116. /**
  5117. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5118. * objects.
  5119. *
  5120. * @private
  5121. * @param {*} value The value to inspect.
  5122. * @param {string} key The key of the property to inspect.
  5123. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5124. */
  5125. function customOmitClone(value) {
  5126. return isPlainObject(value) ? undefined : value;
  5127. }
  5128. /**
  5129. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5130. * partial deep comparisons.
  5131. *
  5132. * @private
  5133. * @param {Array} array The array to compare.
  5134. * @param {Array} other The other array to compare.
  5135. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5136. * @param {Function} customizer The function to customize comparisons.
  5137. * @param {Function} equalFunc The function to determine equivalents of values.
  5138. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5139. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5140. */
  5141. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5142. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5143. arrLength = array.length,
  5144. othLength = other.length;
  5145. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5146. return false;
  5147. }
  5148. // Assume cyclic values are equal.
  5149. var stacked = stack.get(array);
  5150. if (stacked && stack.get(other)) {
  5151. return stacked == other;
  5152. }
  5153. var index = -1,
  5154. result = true,
  5155. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5156. stack.set(array, other);
  5157. stack.set(other, array);
  5158. // Ignore non-index properties.
  5159. while (++index < arrLength) {
  5160. var arrValue = array[index],
  5161. othValue = other[index];
  5162. if (customizer) {
  5163. var compared = isPartial
  5164. ? customizer(othValue, arrValue, index, other, array, stack)
  5165. : customizer(arrValue, othValue, index, array, other, stack);
  5166. }
  5167. if (compared !== undefined) {
  5168. if (compared) {
  5169. continue;
  5170. }
  5171. result = false;
  5172. break;
  5173. }
  5174. // Recursively compare arrays (susceptible to call stack limits).
  5175. if (seen) {
  5176. if (!arraySome(other, function(othValue, othIndex) {
  5177. if (!cacheHas(seen, othIndex) &&
  5178. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5179. return seen.push(othIndex);
  5180. }
  5181. })) {
  5182. result = false;
  5183. break;
  5184. }
  5185. } else if (!(
  5186. arrValue === othValue ||
  5187. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5188. )) {
  5189. result = false;
  5190. break;
  5191. }
  5192. }
  5193. stack['delete'](array);
  5194. stack['delete'](other);
  5195. return result;
  5196. }
  5197. /**
  5198. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5199. * the same `toStringTag`.
  5200. *
  5201. * **Note:** This function only supports comparing values with tags of
  5202. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5203. *
  5204. * @private
  5205. * @param {Object} object The object to compare.
  5206. * @param {Object} other The other object to compare.
  5207. * @param {string} tag The `toStringTag` of the objects to compare.
  5208. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5209. * @param {Function} customizer The function to customize comparisons.
  5210. * @param {Function} equalFunc The function to determine equivalents of values.
  5211. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5212. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5213. */
  5214. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5215. switch (tag) {
  5216. case dataViewTag:
  5217. if ((object.byteLength != other.byteLength) ||
  5218. (object.byteOffset != other.byteOffset)) {
  5219. return false;
  5220. }
  5221. object = object.buffer;
  5222. other = other.buffer;
  5223. case arrayBufferTag:
  5224. if ((object.byteLength != other.byteLength) ||
  5225. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5226. return false;
  5227. }
  5228. return true;
  5229. case boolTag:
  5230. case dateTag:
  5231. case numberTag:
  5232. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5233. // Invalid dates are coerced to `NaN`.
  5234. return eq(+object, +other);
  5235. case errorTag:
  5236. return object.name == other.name && object.message == other.message;
  5237. case regexpTag:
  5238. case stringTag:
  5239. // Coerce regexes to strings and treat strings, primitives and objects,
  5240. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5241. // for more details.
  5242. return object == (other + '');
  5243. case mapTag:
  5244. var convert = mapToArray;
  5245. case setTag:
  5246. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5247. convert || (convert = setToArray);
  5248. if (object.size != other.size && !isPartial) {
  5249. return false;
  5250. }
  5251. // Assume cyclic values are equal.
  5252. var stacked = stack.get(object);
  5253. if (stacked) {
  5254. return stacked == other;
  5255. }
  5256. bitmask |= COMPARE_UNORDERED_FLAG;
  5257. // Recursively compare objects (susceptible to call stack limits).
  5258. stack.set(object, other);
  5259. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5260. stack['delete'](object);
  5261. return result;
  5262. case symbolTag:
  5263. if (symbolValueOf) {
  5264. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5265. }
  5266. }
  5267. return false;
  5268. }
  5269. /**
  5270. * A specialized version of `baseIsEqualDeep` for objects with support for
  5271. * partial deep comparisons.
  5272. *
  5273. * @private
  5274. * @param {Object} object The object to compare.
  5275. * @param {Object} other The other object to compare.
  5276. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5277. * @param {Function} customizer The function to customize comparisons.
  5278. * @param {Function} equalFunc The function to determine equivalents of values.
  5279. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5280. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5281. */
  5282. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5283. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5284. objProps = getAllKeys(object),
  5285. objLength = objProps.length,
  5286. othProps = getAllKeys(other),
  5287. othLength = othProps.length;
  5288. if (objLength != othLength && !isPartial) {
  5289. return false;
  5290. }
  5291. var index = objLength;
  5292. while (index--) {
  5293. var key = objProps[index];
  5294. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5295. return false;
  5296. }
  5297. }
  5298. // Assume cyclic values are equal.
  5299. var stacked = stack.get(object);
  5300. if (stacked && stack.get(other)) {
  5301. return stacked == other;
  5302. }
  5303. var result = true;
  5304. stack.set(object, other);
  5305. stack.set(other, object);
  5306. var skipCtor = isPartial;
  5307. while (++index < objLength) {
  5308. key = objProps[index];
  5309. var objValue = object[key],
  5310. othValue = other[key];
  5311. if (customizer) {
  5312. var compared = isPartial
  5313. ? customizer(othValue, objValue, key, other, object, stack)
  5314. : customizer(objValue, othValue, key, object, other, stack);
  5315. }
  5316. // Recursively compare objects (susceptible to call stack limits).
  5317. if (!(compared === undefined
  5318. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5319. : compared
  5320. )) {
  5321. result = false;
  5322. break;
  5323. }
  5324. skipCtor || (skipCtor = key == 'constructor');
  5325. }
  5326. if (result && !skipCtor) {
  5327. var objCtor = object.constructor,
  5328. othCtor = other.constructor;
  5329. // Non `Object` object instances with different constructors are not equal.
  5330. if (objCtor != othCtor &&
  5331. ('constructor' in object && 'constructor' in other) &&
  5332. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5333. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5334. result = false;
  5335. }
  5336. }
  5337. stack['delete'](object);
  5338. stack['delete'](other);
  5339. return result;
  5340. }
  5341. /**
  5342. * A specialized version of `baseRest` which flattens the rest array.
  5343. *
  5344. * @private
  5345. * @param {Function} func The function to apply a rest parameter to.
  5346. * @returns {Function} Returns the new function.
  5347. */
  5348. function flatRest(func) {
  5349. return setToString(overRest(func, undefined, flatten), func + '');
  5350. }
  5351. /**
  5352. * Creates an array of own enumerable property names and symbols of `object`.
  5353. *
  5354. * @private
  5355. * @param {Object} object The object to query.
  5356. * @returns {Array} Returns the array of property names and symbols.
  5357. */
  5358. function getAllKeys(object) {
  5359. return baseGetAllKeys(object, keys, getSymbols);
  5360. }
  5361. /**
  5362. * Creates an array of own and inherited enumerable property names and
  5363. * symbols of `object`.
  5364. *
  5365. * @private
  5366. * @param {Object} object The object to query.
  5367. * @returns {Array} Returns the array of property names and symbols.
  5368. */
  5369. function getAllKeysIn(object) {
  5370. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5371. }
  5372. /**
  5373. * Gets metadata for `func`.
  5374. *
  5375. * @private
  5376. * @param {Function} func The function to query.
  5377. * @returns {*} Returns the metadata for `func`.
  5378. */
  5379. var getData = !metaMap ? noop : function(func) {
  5380. return metaMap.get(func);
  5381. };
  5382. /**
  5383. * Gets the name of `func`.
  5384. *
  5385. * @private
  5386. * @param {Function} func The function to query.
  5387. * @returns {string} Returns the function name.
  5388. */
  5389. function getFuncName(func) {
  5390. var result = (func.name + ''),
  5391. array = realNames[result],
  5392. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5393. while (length--) {
  5394. var data = array[length],
  5395. otherFunc = data.func;
  5396. if (otherFunc == null || otherFunc == func) {
  5397. return data.name;
  5398. }
  5399. }
  5400. return result;
  5401. }
  5402. /**
  5403. * Gets the argument placeholder value for `func`.
  5404. *
  5405. * @private
  5406. * @param {Function} func The function to inspect.
  5407. * @returns {*} Returns the placeholder value.
  5408. */
  5409. function getHolder(func) {
  5410. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5411. return object.placeholder;
  5412. }
  5413. /**
  5414. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5415. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5416. * If arguments are provided, the chosen function is invoked with them and
  5417. * its result is returned.
  5418. *
  5419. * @private
  5420. * @param {*} [value] The value to convert to an iteratee.
  5421. * @param {number} [arity] The arity of the created iteratee.
  5422. * @returns {Function} Returns the chosen function or its result.
  5423. */
  5424. function getIteratee() {
  5425. var result = lodash.iteratee || iteratee;
  5426. result = result === iteratee ? baseIteratee : result;
  5427. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5428. }
  5429. /**
  5430. * Gets the data for `map`.
  5431. *
  5432. * @private
  5433. * @param {Object} map The map to query.
  5434. * @param {string} key The reference key.
  5435. * @returns {*} Returns the map data.
  5436. */
  5437. function getMapData(map, key) {
  5438. var data = map.__data__;
  5439. return isKeyable(key)
  5440. ? data[typeof key == 'string' ? 'string' : 'hash']
  5441. : data.map;
  5442. }
  5443. /**
  5444. * Gets the property names, values, and compare flags of `object`.
  5445. *
  5446. * @private
  5447. * @param {Object} object The object to query.
  5448. * @returns {Array} Returns the match data of `object`.
  5449. */
  5450. function getMatchData(object) {
  5451. var result = keys(object),
  5452. length = result.length;
  5453. while (length--) {
  5454. var key = result[length],
  5455. value = object[key];
  5456. result[length] = [key, value, isStrictComparable(value)];
  5457. }
  5458. return result;
  5459. }
  5460. /**
  5461. * Gets the native function at `key` of `object`.
  5462. *
  5463. * @private
  5464. * @param {Object} object The object to query.
  5465. * @param {string} key The key of the method to get.
  5466. * @returns {*} Returns the function if it's native, else `undefined`.
  5467. */
  5468. function getNative(object, key) {
  5469. var value = getValue(object, key);
  5470. return baseIsNative(value) ? value : undefined;
  5471. }
  5472. /**
  5473. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5474. *
  5475. * @private
  5476. * @param {*} value The value to query.
  5477. * @returns {string} Returns the raw `toStringTag`.
  5478. */
  5479. function getRawTag(value) {
  5480. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5481. tag = value[symToStringTag];
  5482. try {
  5483. value[symToStringTag] = undefined;
  5484. var unmasked = true;
  5485. } catch (e) {}
  5486. var result = nativeObjectToString.call(value);
  5487. if (unmasked) {
  5488. if (isOwn) {
  5489. value[symToStringTag] = tag;
  5490. } else {
  5491. delete value[symToStringTag];
  5492. }
  5493. }
  5494. return result;
  5495. }
  5496. /**
  5497. * Creates an array of the own enumerable symbols of `object`.
  5498. *
  5499. * @private
  5500. * @param {Object} object The object to query.
  5501. * @returns {Array} Returns the array of symbols.
  5502. */
  5503. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5504. if (object == null) {
  5505. return [];
  5506. }
  5507. object = Object(object);
  5508. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5509. return propertyIsEnumerable.call(object, symbol);
  5510. });
  5511. };
  5512. /**
  5513. * Creates an array of the own and inherited enumerable symbols of `object`.
  5514. *
  5515. * @private
  5516. * @param {Object} object The object to query.
  5517. * @returns {Array} Returns the array of symbols.
  5518. */
  5519. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5520. var result = [];
  5521. while (object) {
  5522. arrayPush(result, getSymbols(object));
  5523. object = getPrototype(object);
  5524. }
  5525. return result;
  5526. };
  5527. /**
  5528. * Gets the `toStringTag` of `value`.
  5529. *
  5530. * @private
  5531. * @param {*} value The value to query.
  5532. * @returns {string} Returns the `toStringTag`.
  5533. */
  5534. var getTag = baseGetTag;
  5535. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5536. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5537. (Map && getTag(new Map) != mapTag) ||
  5538. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5539. (Set && getTag(new Set) != setTag) ||
  5540. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5541. getTag = function(value) {
  5542. var result = baseGetTag(value),
  5543. Ctor = result == objectTag ? value.constructor : undefined,
  5544. ctorString = Ctor ? toSource(Ctor) : '';
  5545. if (ctorString) {
  5546. switch (ctorString) {
  5547. case dataViewCtorString: return dataViewTag;
  5548. case mapCtorString: return mapTag;
  5549. case promiseCtorString: return promiseTag;
  5550. case setCtorString: return setTag;
  5551. case weakMapCtorString: return weakMapTag;
  5552. }
  5553. }
  5554. return result;
  5555. };
  5556. }
  5557. /**
  5558. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5559. *
  5560. * @private
  5561. * @param {number} start The start of the view.
  5562. * @param {number} end The end of the view.
  5563. * @param {Array} transforms The transformations to apply to the view.
  5564. * @returns {Object} Returns an object containing the `start` and `end`
  5565. * positions of the view.
  5566. */
  5567. function getView(start, end, transforms) {
  5568. var index = -1,
  5569. length = transforms.length;
  5570. while (++index < length) {
  5571. var data = transforms[index],
  5572. size = data.size;
  5573. switch (data.type) {
  5574. case 'drop': start += size; break;
  5575. case 'dropRight': end -= size; break;
  5576. case 'take': end = nativeMin(end, start + size); break;
  5577. case 'takeRight': start = nativeMax(start, end - size); break;
  5578. }
  5579. }
  5580. return { 'start': start, 'end': end };
  5581. }
  5582. /**
  5583. * Extracts wrapper details from the `source` body comment.
  5584. *
  5585. * @private
  5586. * @param {string} source The source to inspect.
  5587. * @returns {Array} Returns the wrapper details.
  5588. */
  5589. function getWrapDetails(source) {
  5590. var match = source.match(reWrapDetails);
  5591. return match ? match[1].split(reSplitDetails) : [];
  5592. }
  5593. /**
  5594. * Checks if `path` exists on `object`.
  5595. *
  5596. * @private
  5597. * @param {Object} object The object to query.
  5598. * @param {Array|string} path The path to check.
  5599. * @param {Function} hasFunc The function to check properties.
  5600. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5601. */
  5602. function hasPath(object, path, hasFunc) {
  5603. path = castPath(path, object);
  5604. var index = -1,
  5605. length = path.length,
  5606. result = false;
  5607. while (++index < length) {
  5608. var key = toKey(path[index]);
  5609. if (!(result = object != null && hasFunc(object, key))) {
  5610. break;
  5611. }
  5612. object = object[key];
  5613. }
  5614. if (result || ++index != length) {
  5615. return result;
  5616. }
  5617. length = object == null ? 0 : object.length;
  5618. return !!length && isLength(length) && isIndex(key, length) &&
  5619. (isArray(object) || isArguments(object));
  5620. }
  5621. /**
  5622. * Initializes an array clone.
  5623. *
  5624. * @private
  5625. * @param {Array} array The array to clone.
  5626. * @returns {Array} Returns the initialized clone.
  5627. */
  5628. function initCloneArray(array) {
  5629. var length = array.length,
  5630. result = new array.constructor(length);
  5631. // Add properties assigned by `RegExp#exec`.
  5632. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5633. result.index = array.index;
  5634. result.input = array.input;
  5635. }
  5636. return result;
  5637. }
  5638. /**
  5639. * Initializes an object clone.
  5640. *
  5641. * @private
  5642. * @param {Object} object The object to clone.
  5643. * @returns {Object} Returns the initialized clone.
  5644. */
  5645. function initCloneObject(object) {
  5646. return (typeof object.constructor == 'function' && !isPrototype(object))
  5647. ? baseCreate(getPrototype(object))
  5648. : {};
  5649. }
  5650. /**
  5651. * Initializes an object clone based on its `toStringTag`.
  5652. *
  5653. * **Note:** This function only supports cloning values with tags of
  5654. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5655. *
  5656. * @private
  5657. * @param {Object} object The object to clone.
  5658. * @param {string} tag The `toStringTag` of the object to clone.
  5659. * @param {boolean} [isDeep] Specify a deep clone.
  5660. * @returns {Object} Returns the initialized clone.
  5661. */
  5662. function initCloneByTag(object, tag, isDeep) {
  5663. var Ctor = object.constructor;
  5664. switch (tag) {
  5665. case arrayBufferTag:
  5666. return cloneArrayBuffer(object);
  5667. case boolTag:
  5668. case dateTag:
  5669. return new Ctor(+object);
  5670. case dataViewTag:
  5671. return cloneDataView(object, isDeep);
  5672. case float32Tag: case float64Tag:
  5673. case int8Tag: case int16Tag: case int32Tag:
  5674. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5675. return cloneTypedArray(object, isDeep);
  5676. case mapTag:
  5677. return new Ctor;
  5678. case numberTag:
  5679. case stringTag:
  5680. return new Ctor(object);
  5681. case regexpTag:
  5682. return cloneRegExp(object);
  5683. case setTag:
  5684. return new Ctor;
  5685. case symbolTag:
  5686. return cloneSymbol(object);
  5687. }
  5688. }
  5689. /**
  5690. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5691. *
  5692. * @private
  5693. * @param {string} source The source to modify.
  5694. * @returns {Array} details The details to insert.
  5695. * @returns {string} Returns the modified source.
  5696. */
  5697. function insertWrapDetails(source, details) {
  5698. var length = details.length;
  5699. if (!length) {
  5700. return source;
  5701. }
  5702. var lastIndex = length - 1;
  5703. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5704. details = details.join(length > 2 ? ', ' : ' ');
  5705. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5706. }
  5707. /**
  5708. * Checks if `value` is a flattenable `arguments` object or array.
  5709. *
  5710. * @private
  5711. * @param {*} value The value to check.
  5712. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5713. */
  5714. function isFlattenable(value) {
  5715. return isArray(value) || isArguments(value) ||
  5716. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5717. }
  5718. /**
  5719. * Checks if `value` is a valid array-like index.
  5720. *
  5721. * @private
  5722. * @param {*} value The value to check.
  5723. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5724. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5725. */
  5726. function isIndex(value, length) {
  5727. var type = typeof value;
  5728. length = length == null ? MAX_SAFE_INTEGER : length;
  5729. return !!length &&
  5730. (type == 'number' ||
  5731. (type != 'symbol' && reIsUint.test(value))) &&
  5732. (value > -1 && value % 1 == 0 && value < length);
  5733. }
  5734. /**
  5735. * Checks if the given arguments are from an iteratee call.
  5736. *
  5737. * @private
  5738. * @param {*} value The potential iteratee value argument.
  5739. * @param {*} index The potential iteratee index or key argument.
  5740. * @param {*} object The potential iteratee object argument.
  5741. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5742. * else `false`.
  5743. */
  5744. function isIterateeCall(value, index, object) {
  5745. if (!isObject(object)) {
  5746. return false;
  5747. }
  5748. var type = typeof index;
  5749. if (type == 'number'
  5750. ? (isArrayLike(object) && isIndex(index, object.length))
  5751. : (type == 'string' && index in object)
  5752. ) {
  5753. return eq(object[index], value);
  5754. }
  5755. return false;
  5756. }
  5757. /**
  5758. * Checks if `value` is a property name and not a property path.
  5759. *
  5760. * @private
  5761. * @param {*} value The value to check.
  5762. * @param {Object} [object] The object to query keys on.
  5763. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5764. */
  5765. function isKey(value, object) {
  5766. if (isArray(value)) {
  5767. return false;
  5768. }
  5769. var type = typeof value;
  5770. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5771. value == null || isSymbol(value)) {
  5772. return true;
  5773. }
  5774. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5775. (object != null && value in Object(object));
  5776. }
  5777. /**
  5778. * Checks if `value` is suitable for use as unique object key.
  5779. *
  5780. * @private
  5781. * @param {*} value The value to check.
  5782. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5783. */
  5784. function isKeyable(value) {
  5785. var type = typeof value;
  5786. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5787. ? (value !== '__proto__')
  5788. : (value === null);
  5789. }
  5790. /**
  5791. * Checks if `func` has a lazy counterpart.
  5792. *
  5793. * @private
  5794. * @param {Function} func The function to check.
  5795. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5796. * else `false`.
  5797. */
  5798. function isLaziable(func) {
  5799. var funcName = getFuncName(func),
  5800. other = lodash[funcName];
  5801. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5802. return false;
  5803. }
  5804. if (func === other) {
  5805. return true;
  5806. }
  5807. var data = getData(other);
  5808. return !!data && func === data[0];
  5809. }
  5810. /**
  5811. * Checks if `func` has its source masked.
  5812. *
  5813. * @private
  5814. * @param {Function} func The function to check.
  5815. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5816. */
  5817. function isMasked(func) {
  5818. return !!maskSrcKey && (maskSrcKey in func);
  5819. }
  5820. /**
  5821. * Checks if `func` is capable of being masked.
  5822. *
  5823. * @private
  5824. * @param {*} value The value to check.
  5825. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5826. */
  5827. var isMaskable = coreJsData ? isFunction : stubFalse;
  5828. /**
  5829. * Checks if `value` is likely a prototype object.
  5830. *
  5831. * @private
  5832. * @param {*} value The value to check.
  5833. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5834. */
  5835. function isPrototype(value) {
  5836. var Ctor = value && value.constructor,
  5837. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5838. return value === proto;
  5839. }
  5840. /**
  5841. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5842. *
  5843. * @private
  5844. * @param {*} value The value to check.
  5845. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5846. * equality comparisons, else `false`.
  5847. */
  5848. function isStrictComparable(value) {
  5849. return value === value && !isObject(value);
  5850. }
  5851. /**
  5852. * A specialized version of `matchesProperty` for source values suitable
  5853. * for strict equality comparisons, i.e. `===`.
  5854. *
  5855. * @private
  5856. * @param {string} key The key of the property to get.
  5857. * @param {*} srcValue The value to match.
  5858. * @returns {Function} Returns the new spec function.
  5859. */
  5860. function matchesStrictComparable(key, srcValue) {
  5861. return function(object) {
  5862. if (object == null) {
  5863. return false;
  5864. }
  5865. return object[key] === srcValue &&
  5866. (srcValue !== undefined || (key in Object(object)));
  5867. };
  5868. }
  5869. /**
  5870. * A specialized version of `_.memoize` which clears the memoized function's
  5871. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5872. *
  5873. * @private
  5874. * @param {Function} func The function to have its output memoized.
  5875. * @returns {Function} Returns the new memoized function.
  5876. */
  5877. function memoizeCapped(func) {
  5878. var result = memoize(func, function(key) {
  5879. if (cache.size === MAX_MEMOIZE_SIZE) {
  5880. cache.clear();
  5881. }
  5882. return key;
  5883. });
  5884. var cache = result.cache;
  5885. return result;
  5886. }
  5887. /**
  5888. * Merges the function metadata of `source` into `data`.
  5889. *
  5890. * Merging metadata reduces the number of wrappers used to invoke a function.
  5891. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5892. * may be applied regardless of execution order. Methods like `_.ary` and
  5893. * `_.rearg` modify function arguments, making the order in which they are
  5894. * executed important, preventing the merging of metadata. However, we make
  5895. * an exception for a safe combined case where curried functions have `_.ary`
  5896. * and or `_.rearg` applied.
  5897. *
  5898. * @private
  5899. * @param {Array} data The destination metadata.
  5900. * @param {Array} source The source metadata.
  5901. * @returns {Array} Returns `data`.
  5902. */
  5903. function mergeData(data, source) {
  5904. var bitmask = data[1],
  5905. srcBitmask = source[1],
  5906. newBitmask = bitmask | srcBitmask,
  5907. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5908. var isCombo =
  5909. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5910. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5911. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5912. // Exit early if metadata can't be merged.
  5913. if (!(isCommon || isCombo)) {
  5914. return data;
  5915. }
  5916. // Use source `thisArg` if available.
  5917. if (srcBitmask & WRAP_BIND_FLAG) {
  5918. data[2] = source[2];
  5919. // Set when currying a bound function.
  5920. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5921. }
  5922. // Compose partial arguments.
  5923. var value = source[3];
  5924. if (value) {
  5925. var partials = data[3];
  5926. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5927. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5928. }
  5929. // Compose partial right arguments.
  5930. value = source[5];
  5931. if (value) {
  5932. partials = data[5];
  5933. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5934. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5935. }
  5936. // Use source `argPos` if available.
  5937. value = source[7];
  5938. if (value) {
  5939. data[7] = value;
  5940. }
  5941. // Use source `ary` if it's smaller.
  5942. if (srcBitmask & WRAP_ARY_FLAG) {
  5943. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5944. }
  5945. // Use source `arity` if one is not provided.
  5946. if (data[9] == null) {
  5947. data[9] = source[9];
  5948. }
  5949. // Use source `func` and merge bitmasks.
  5950. data[0] = source[0];
  5951. data[1] = newBitmask;
  5952. return data;
  5953. }
  5954. /**
  5955. * This function is like
  5956. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5957. * except that it includes inherited enumerable properties.
  5958. *
  5959. * @private
  5960. * @param {Object} object The object to query.
  5961. * @returns {Array} Returns the array of property names.
  5962. */
  5963. function nativeKeysIn(object) {
  5964. var result = [];
  5965. if (object != null) {
  5966. for (var key in Object(object)) {
  5967. result.push(key);
  5968. }
  5969. }
  5970. return result;
  5971. }
  5972. /**
  5973. * Converts `value` to a string using `Object.prototype.toString`.
  5974. *
  5975. * @private
  5976. * @param {*} value The value to convert.
  5977. * @returns {string} Returns the converted string.
  5978. */
  5979. function objectToString(value) {
  5980. return nativeObjectToString.call(value);
  5981. }
  5982. /**
  5983. * A specialized version of `baseRest` which transforms the rest array.
  5984. *
  5985. * @private
  5986. * @param {Function} func The function to apply a rest parameter to.
  5987. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5988. * @param {Function} transform The rest array transform.
  5989. * @returns {Function} Returns the new function.
  5990. */
  5991. function overRest(func, start, transform) {
  5992. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5993. return function() {
  5994. var args = arguments,
  5995. index = -1,
  5996. length = nativeMax(args.length - start, 0),
  5997. array = Array(length);
  5998. while (++index < length) {
  5999. array[index] = args[start + index];
  6000. }
  6001. index = -1;
  6002. var otherArgs = Array(start + 1);
  6003. while (++index < start) {
  6004. otherArgs[index] = args[index];
  6005. }
  6006. otherArgs[start] = transform(array);
  6007. return apply(func, this, otherArgs);
  6008. };
  6009. }
  6010. /**
  6011. * Gets the parent value at `path` of `object`.
  6012. *
  6013. * @private
  6014. * @param {Object} object The object to query.
  6015. * @param {Array} path The path to get the parent value of.
  6016. * @returns {*} Returns the parent value.
  6017. */
  6018. function parent(object, path) {
  6019. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6020. }
  6021. /**
  6022. * Reorder `array` according to the specified indexes where the element at
  6023. * the first index is assigned as the first element, the element at
  6024. * the second index is assigned as the second element, and so on.
  6025. *
  6026. * @private
  6027. * @param {Array} array The array to reorder.
  6028. * @param {Array} indexes The arranged array indexes.
  6029. * @returns {Array} Returns `array`.
  6030. */
  6031. function reorder(array, indexes) {
  6032. var arrLength = array.length,
  6033. length = nativeMin(indexes.length, arrLength),
  6034. oldArray = copyArray(array);
  6035. while (length--) {
  6036. var index = indexes[length];
  6037. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6038. }
  6039. return array;
  6040. }
  6041. /**
  6042. * Sets metadata for `func`.
  6043. *
  6044. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6045. * period of time, it will trip its breaker and transition to an identity
  6046. * function to avoid garbage collection pauses in V8. See
  6047. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6048. * for more details.
  6049. *
  6050. * @private
  6051. * @param {Function} func The function to associate metadata with.
  6052. * @param {*} data The metadata.
  6053. * @returns {Function} Returns `func`.
  6054. */
  6055. var setData = shortOut(baseSetData);
  6056. /**
  6057. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6058. *
  6059. * @private
  6060. * @param {Function} func The function to delay.
  6061. * @param {number} wait The number of milliseconds to delay invocation.
  6062. * @returns {number|Object} Returns the timer id or timeout object.
  6063. */
  6064. var setTimeout = ctxSetTimeout || function(func, wait) {
  6065. return root.setTimeout(func, wait);
  6066. };
  6067. /**
  6068. * Sets the `toString` method of `func` to return `string`.
  6069. *
  6070. * @private
  6071. * @param {Function} func The function to modify.
  6072. * @param {Function} string The `toString` result.
  6073. * @returns {Function} Returns `func`.
  6074. */
  6075. var setToString = shortOut(baseSetToString);
  6076. /**
  6077. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6078. * with wrapper details in a comment at the top of the source body.
  6079. *
  6080. * @private
  6081. * @param {Function} wrapper The function to modify.
  6082. * @param {Function} reference The reference function.
  6083. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6084. * @returns {Function} Returns `wrapper`.
  6085. */
  6086. function setWrapToString(wrapper, reference, bitmask) {
  6087. var source = (reference + '');
  6088. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6089. }
  6090. /**
  6091. * Creates a function that'll short out and invoke `identity` instead
  6092. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6093. * milliseconds.
  6094. *
  6095. * @private
  6096. * @param {Function} func The function to restrict.
  6097. * @returns {Function} Returns the new shortable function.
  6098. */
  6099. function shortOut(func) {
  6100. var count = 0,
  6101. lastCalled = 0;
  6102. return function() {
  6103. var stamp = nativeNow(),
  6104. remaining = HOT_SPAN - (stamp - lastCalled);
  6105. lastCalled = stamp;
  6106. if (remaining > 0) {
  6107. if (++count >= HOT_COUNT) {
  6108. return arguments[0];
  6109. }
  6110. } else {
  6111. count = 0;
  6112. }
  6113. return func.apply(undefined, arguments);
  6114. };
  6115. }
  6116. /**
  6117. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6118. *
  6119. * @private
  6120. * @param {Array} array The array to shuffle.
  6121. * @param {number} [size=array.length] The size of `array`.
  6122. * @returns {Array} Returns `array`.
  6123. */
  6124. function shuffleSelf(array, size) {
  6125. var index = -1,
  6126. length = array.length,
  6127. lastIndex = length - 1;
  6128. size = size === undefined ? length : size;
  6129. while (++index < size) {
  6130. var rand = baseRandom(index, lastIndex),
  6131. value = array[rand];
  6132. array[rand] = array[index];
  6133. array[index] = value;
  6134. }
  6135. array.length = size;
  6136. return array;
  6137. }
  6138. /**
  6139. * Converts `string` to a property path array.
  6140. *
  6141. * @private
  6142. * @param {string} string The string to convert.
  6143. * @returns {Array} Returns the property path array.
  6144. */
  6145. var stringToPath = memoizeCapped(function(string) {
  6146. var result = [];
  6147. if (string.charCodeAt(0) === 46 /* . */) {
  6148. result.push('');
  6149. }
  6150. string.replace(rePropName, function(match, number, quote, subString) {
  6151. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6152. });
  6153. return result;
  6154. });
  6155. /**
  6156. * Converts `value` to a string key if it's not a string or symbol.
  6157. *
  6158. * @private
  6159. * @param {*} value The value to inspect.
  6160. * @returns {string|symbol} Returns the key.
  6161. */
  6162. function toKey(value) {
  6163. if (typeof value == 'string' || isSymbol(value)) {
  6164. return value;
  6165. }
  6166. var result = (value + '');
  6167. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6168. }
  6169. /**
  6170. * Converts `func` to its source code.
  6171. *
  6172. * @private
  6173. * @param {Function} func The function to convert.
  6174. * @returns {string} Returns the source code.
  6175. */
  6176. function toSource(func) {
  6177. if (func != null) {
  6178. try {
  6179. return funcToString.call(func);
  6180. } catch (e) {}
  6181. try {
  6182. return (func + '');
  6183. } catch (e) {}
  6184. }
  6185. return '';
  6186. }
  6187. /**
  6188. * Updates wrapper `details` based on `bitmask` flags.
  6189. *
  6190. * @private
  6191. * @returns {Array} details The details to modify.
  6192. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6193. * @returns {Array} Returns `details`.
  6194. */
  6195. function updateWrapDetails(details, bitmask) {
  6196. arrayEach(wrapFlags, function(pair) {
  6197. var value = '_.' + pair[0];
  6198. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6199. details.push(value);
  6200. }
  6201. });
  6202. return details.sort();
  6203. }
  6204. /**
  6205. * Creates a clone of `wrapper`.
  6206. *
  6207. * @private
  6208. * @param {Object} wrapper The wrapper to clone.
  6209. * @returns {Object} Returns the cloned wrapper.
  6210. */
  6211. function wrapperClone(wrapper) {
  6212. if (wrapper instanceof LazyWrapper) {
  6213. return wrapper.clone();
  6214. }
  6215. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6216. result.__actions__ = copyArray(wrapper.__actions__);
  6217. result.__index__ = wrapper.__index__;
  6218. result.__values__ = wrapper.__values__;
  6219. return result;
  6220. }
  6221. /*------------------------------------------------------------------------*/
  6222. /**
  6223. * Creates an array of elements split into groups the length of `size`.
  6224. * If `array` can't be split evenly, the final chunk will be the remaining
  6225. * elements.
  6226. *
  6227. * @static
  6228. * @memberOf _
  6229. * @since 3.0.0
  6230. * @category Array
  6231. * @param {Array} array The array to process.
  6232. * @param {number} [size=1] The length of each chunk
  6233. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6234. * @returns {Array} Returns the new array of chunks.
  6235. * @example
  6236. *
  6237. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6238. * // => [['a', 'b'], ['c', 'd']]
  6239. *
  6240. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6241. * // => [['a', 'b', 'c'], ['d']]
  6242. */
  6243. function chunk(array, size, guard) {
  6244. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6245. size = 1;
  6246. } else {
  6247. size = nativeMax(toInteger(size), 0);
  6248. }
  6249. var length = array == null ? 0 : array.length;
  6250. if (!length || size < 1) {
  6251. return [];
  6252. }
  6253. var index = 0,
  6254. resIndex = 0,
  6255. result = Array(nativeCeil(length / size));
  6256. while (index < length) {
  6257. result[resIndex++] = baseSlice(array, index, (index += size));
  6258. }
  6259. return result;
  6260. }
  6261. /**
  6262. * Creates an array with all falsey values removed. The values `false`, `null`,
  6263. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6264. *
  6265. * @static
  6266. * @memberOf _
  6267. * @since 0.1.0
  6268. * @category Array
  6269. * @param {Array} array The array to compact.
  6270. * @returns {Array} Returns the new array of filtered values.
  6271. * @example
  6272. *
  6273. * _.compact([0, 1, false, 2, '', 3]);
  6274. * // => [1, 2, 3]
  6275. */
  6276. function compact(array) {
  6277. var index = -1,
  6278. length = array == null ? 0 : array.length,
  6279. resIndex = 0,
  6280. result = [];
  6281. while (++index < length) {
  6282. var value = array[index];
  6283. if (value) {
  6284. result[resIndex++] = value;
  6285. }
  6286. }
  6287. return result;
  6288. }
  6289. /**
  6290. * Creates a new array concatenating `array` with any additional arrays
  6291. * and/or values.
  6292. *
  6293. * @static
  6294. * @memberOf _
  6295. * @since 4.0.0
  6296. * @category Array
  6297. * @param {Array} array The array to concatenate.
  6298. * @param {...*} [values] The values to concatenate.
  6299. * @returns {Array} Returns the new concatenated array.
  6300. * @example
  6301. *
  6302. * var array = [1];
  6303. * var other = _.concat(array, 2, [3], [[4]]);
  6304. *
  6305. * console.log(other);
  6306. * // => [1, 2, 3, [4]]
  6307. *
  6308. * console.log(array);
  6309. * // => [1]
  6310. */
  6311. function concat() {
  6312. var length = arguments.length;
  6313. if (!length) {
  6314. return [];
  6315. }
  6316. var args = Array(length - 1),
  6317. array = arguments[0],
  6318. index = length;
  6319. while (index--) {
  6320. args[index - 1] = arguments[index];
  6321. }
  6322. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6323. }
  6324. /**
  6325. * Creates an array of `array` values not included in the other given arrays
  6326. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6327. * for equality comparisons. The order and references of result values are
  6328. * determined by the first array.
  6329. *
  6330. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6331. *
  6332. * @static
  6333. * @memberOf _
  6334. * @since 0.1.0
  6335. * @category Array
  6336. * @param {Array} array The array to inspect.
  6337. * @param {...Array} [values] The values to exclude.
  6338. * @returns {Array} Returns the new array of filtered values.
  6339. * @see _.without, _.xor
  6340. * @example
  6341. *
  6342. * _.difference([2, 1], [2, 3]);
  6343. * // => [1]
  6344. */
  6345. var difference = baseRest(function(array, values) {
  6346. return isArrayLikeObject(array)
  6347. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6348. : [];
  6349. });
  6350. /**
  6351. * This method is like `_.difference` except that it accepts `iteratee` which
  6352. * is invoked for each element of `array` and `values` to generate the criterion
  6353. * by which they're compared. The order and references of result values are
  6354. * determined by the first array. The iteratee is invoked with one argument:
  6355. * (value).
  6356. *
  6357. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6358. *
  6359. * @static
  6360. * @memberOf _
  6361. * @since 4.0.0
  6362. * @category Array
  6363. * @param {Array} array The array to inspect.
  6364. * @param {...Array} [values] The values to exclude.
  6365. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6366. * @returns {Array} Returns the new array of filtered values.
  6367. * @example
  6368. *
  6369. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6370. * // => [1.2]
  6371. *
  6372. * // The `_.property` iteratee shorthand.
  6373. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6374. * // => [{ 'x': 2 }]
  6375. */
  6376. var differenceBy = baseRest(function(array, values) {
  6377. var iteratee = last(values);
  6378. if (isArrayLikeObject(iteratee)) {
  6379. iteratee = undefined;
  6380. }
  6381. return isArrayLikeObject(array)
  6382. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6383. : [];
  6384. });
  6385. /**
  6386. * This method is like `_.difference` except that it accepts `comparator`
  6387. * which is invoked to compare elements of `array` to `values`. The order and
  6388. * references of result values are determined by the first array. The comparator
  6389. * is invoked with two arguments: (arrVal, othVal).
  6390. *
  6391. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6392. *
  6393. * @static
  6394. * @memberOf _
  6395. * @since 4.0.0
  6396. * @category Array
  6397. * @param {Array} array The array to inspect.
  6398. * @param {...Array} [values] The values to exclude.
  6399. * @param {Function} [comparator] The comparator invoked per element.
  6400. * @returns {Array} Returns the new array of filtered values.
  6401. * @example
  6402. *
  6403. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6404. *
  6405. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6406. * // => [{ 'x': 2, 'y': 1 }]
  6407. */
  6408. var differenceWith = baseRest(function(array, values) {
  6409. var comparator = last(values);
  6410. if (isArrayLikeObject(comparator)) {
  6411. comparator = undefined;
  6412. }
  6413. return isArrayLikeObject(array)
  6414. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6415. : [];
  6416. });
  6417. /**
  6418. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6419. *
  6420. * @static
  6421. * @memberOf _
  6422. * @since 0.5.0
  6423. * @category Array
  6424. * @param {Array} array The array to query.
  6425. * @param {number} [n=1] The number of elements to drop.
  6426. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6427. * @returns {Array} Returns the slice of `array`.
  6428. * @example
  6429. *
  6430. * _.drop([1, 2, 3]);
  6431. * // => [2, 3]
  6432. *
  6433. * _.drop([1, 2, 3], 2);
  6434. * // => [3]
  6435. *
  6436. * _.drop([1, 2, 3], 5);
  6437. * // => []
  6438. *
  6439. * _.drop([1, 2, 3], 0);
  6440. * // => [1, 2, 3]
  6441. */
  6442. function drop(array, n, guard) {
  6443. var length = array == null ? 0 : array.length;
  6444. if (!length) {
  6445. return [];
  6446. }
  6447. n = (guard || n === undefined) ? 1 : toInteger(n);
  6448. return baseSlice(array, n < 0 ? 0 : n, length);
  6449. }
  6450. /**
  6451. * Creates a slice of `array` with `n` elements dropped from the end.
  6452. *
  6453. * @static
  6454. * @memberOf _
  6455. * @since 3.0.0
  6456. * @category Array
  6457. * @param {Array} array The array to query.
  6458. * @param {number} [n=1] The number of elements to drop.
  6459. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6460. * @returns {Array} Returns the slice of `array`.
  6461. * @example
  6462. *
  6463. * _.dropRight([1, 2, 3]);
  6464. * // => [1, 2]
  6465. *
  6466. * _.dropRight([1, 2, 3], 2);
  6467. * // => [1]
  6468. *
  6469. * _.dropRight([1, 2, 3], 5);
  6470. * // => []
  6471. *
  6472. * _.dropRight([1, 2, 3], 0);
  6473. * // => [1, 2, 3]
  6474. */
  6475. function dropRight(array, n, guard) {
  6476. var length = array == null ? 0 : array.length;
  6477. if (!length) {
  6478. return [];
  6479. }
  6480. n = (guard || n === undefined) ? 1 : toInteger(n);
  6481. n = length - n;
  6482. return baseSlice(array, 0, n < 0 ? 0 : n);
  6483. }
  6484. /**
  6485. * Creates a slice of `array` excluding elements dropped from the end.
  6486. * Elements are dropped until `predicate` returns falsey. The predicate is
  6487. * invoked with three arguments: (value, index, array).
  6488. *
  6489. * @static
  6490. * @memberOf _
  6491. * @since 3.0.0
  6492. * @category Array
  6493. * @param {Array} array The array to query.
  6494. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6495. * @returns {Array} Returns the slice of `array`.
  6496. * @example
  6497. *
  6498. * var users = [
  6499. * { 'user': 'barney', 'active': true },
  6500. * { 'user': 'fred', 'active': false },
  6501. * { 'user': 'pebbles', 'active': false }
  6502. * ];
  6503. *
  6504. * _.dropRightWhile(users, function(o) { return !o.active; });
  6505. * // => objects for ['barney']
  6506. *
  6507. * // The `_.matches` iteratee shorthand.
  6508. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6509. * // => objects for ['barney', 'fred']
  6510. *
  6511. * // The `_.matchesProperty` iteratee shorthand.
  6512. * _.dropRightWhile(users, ['active', false]);
  6513. * // => objects for ['barney']
  6514. *
  6515. * // The `_.property` iteratee shorthand.
  6516. * _.dropRightWhile(users, 'active');
  6517. * // => objects for ['barney', 'fred', 'pebbles']
  6518. */
  6519. function dropRightWhile(array, predicate) {
  6520. return (array && array.length)
  6521. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6522. : [];
  6523. }
  6524. /**
  6525. * Creates a slice of `array` excluding elements dropped from the beginning.
  6526. * Elements are dropped until `predicate` returns falsey. The predicate is
  6527. * invoked with three arguments: (value, index, array).
  6528. *
  6529. * @static
  6530. * @memberOf _
  6531. * @since 3.0.0
  6532. * @category Array
  6533. * @param {Array} array The array to query.
  6534. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6535. * @returns {Array} Returns the slice of `array`.
  6536. * @example
  6537. *
  6538. * var users = [
  6539. * { 'user': 'barney', 'active': false },
  6540. * { 'user': 'fred', 'active': false },
  6541. * { 'user': 'pebbles', 'active': true }
  6542. * ];
  6543. *
  6544. * _.dropWhile(users, function(o) { return !o.active; });
  6545. * // => objects for ['pebbles']
  6546. *
  6547. * // The `_.matches` iteratee shorthand.
  6548. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6549. * // => objects for ['fred', 'pebbles']
  6550. *
  6551. * // The `_.matchesProperty` iteratee shorthand.
  6552. * _.dropWhile(users, ['active', false]);
  6553. * // => objects for ['pebbles']
  6554. *
  6555. * // The `_.property` iteratee shorthand.
  6556. * _.dropWhile(users, 'active');
  6557. * // => objects for ['barney', 'fred', 'pebbles']
  6558. */
  6559. function dropWhile(array, predicate) {
  6560. return (array && array.length)
  6561. ? baseWhile(array, getIteratee(predicate, 3), true)
  6562. : [];
  6563. }
  6564. /**
  6565. * Fills elements of `array` with `value` from `start` up to, but not
  6566. * including, `end`.
  6567. *
  6568. * **Note:** This method mutates `array`.
  6569. *
  6570. * @static
  6571. * @memberOf _
  6572. * @since 3.2.0
  6573. * @category Array
  6574. * @param {Array} array The array to fill.
  6575. * @param {*} value The value to fill `array` with.
  6576. * @param {number} [start=0] The start position.
  6577. * @param {number} [end=array.length] The end position.
  6578. * @returns {Array} Returns `array`.
  6579. * @example
  6580. *
  6581. * var array = [1, 2, 3];
  6582. *
  6583. * _.fill(array, 'a');
  6584. * console.log(array);
  6585. * // => ['a', 'a', 'a']
  6586. *
  6587. * _.fill(Array(3), 2);
  6588. * // => [2, 2, 2]
  6589. *
  6590. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6591. * // => [4, '*', '*', 10]
  6592. */
  6593. function fill(array, value, start, end) {
  6594. var length = array == null ? 0 : array.length;
  6595. if (!length) {
  6596. return [];
  6597. }
  6598. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6599. start = 0;
  6600. end = length;
  6601. }
  6602. return baseFill(array, value, start, end);
  6603. }
  6604. /**
  6605. * This method is like `_.find` except that it returns the index of the first
  6606. * element `predicate` returns truthy for instead of the element itself.
  6607. *
  6608. * @static
  6609. * @memberOf _
  6610. * @since 1.1.0
  6611. * @category Array
  6612. * @param {Array} array The array to inspect.
  6613. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6614. * @param {number} [fromIndex=0] The index to search from.
  6615. * @returns {number} Returns the index of the found element, else `-1`.
  6616. * @example
  6617. *
  6618. * var users = [
  6619. * { 'user': 'barney', 'active': false },
  6620. * { 'user': 'fred', 'active': false },
  6621. * { 'user': 'pebbles', 'active': true }
  6622. * ];
  6623. *
  6624. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6625. * // => 0
  6626. *
  6627. * // The `_.matches` iteratee shorthand.
  6628. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6629. * // => 1
  6630. *
  6631. * // The `_.matchesProperty` iteratee shorthand.
  6632. * _.findIndex(users, ['active', false]);
  6633. * // => 0
  6634. *
  6635. * // The `_.property` iteratee shorthand.
  6636. * _.findIndex(users, 'active');
  6637. * // => 2
  6638. */
  6639. function findIndex(array, predicate, fromIndex) {
  6640. var length = array == null ? 0 : array.length;
  6641. if (!length) {
  6642. return -1;
  6643. }
  6644. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6645. if (index < 0) {
  6646. index = nativeMax(length + index, 0);
  6647. }
  6648. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6649. }
  6650. /**
  6651. * This method is like `_.findIndex` except that it iterates over elements
  6652. * of `collection` from right to left.
  6653. *
  6654. * @static
  6655. * @memberOf _
  6656. * @since 2.0.0
  6657. * @category Array
  6658. * @param {Array} array The array to inspect.
  6659. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6660. * @param {number} [fromIndex=array.length-1] The index to search from.
  6661. * @returns {number} Returns the index of the found element, else `-1`.
  6662. * @example
  6663. *
  6664. * var users = [
  6665. * { 'user': 'barney', 'active': true },
  6666. * { 'user': 'fred', 'active': false },
  6667. * { 'user': 'pebbles', 'active': false }
  6668. * ];
  6669. *
  6670. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6671. * // => 2
  6672. *
  6673. * // The `_.matches` iteratee shorthand.
  6674. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6675. * // => 0
  6676. *
  6677. * // The `_.matchesProperty` iteratee shorthand.
  6678. * _.findLastIndex(users, ['active', false]);
  6679. * // => 2
  6680. *
  6681. * // The `_.property` iteratee shorthand.
  6682. * _.findLastIndex(users, 'active');
  6683. * // => 0
  6684. */
  6685. function findLastIndex(array, predicate, fromIndex) {
  6686. var length = array == null ? 0 : array.length;
  6687. if (!length) {
  6688. return -1;
  6689. }
  6690. var index = length - 1;
  6691. if (fromIndex !== undefined) {
  6692. index = toInteger(fromIndex);
  6693. index = fromIndex < 0
  6694. ? nativeMax(length + index, 0)
  6695. : nativeMin(index, length - 1);
  6696. }
  6697. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6698. }
  6699. /**
  6700. * Flattens `array` a single level deep.
  6701. *
  6702. * @static
  6703. * @memberOf _
  6704. * @since 0.1.0
  6705. * @category Array
  6706. * @param {Array} array The array to flatten.
  6707. * @returns {Array} Returns the new flattened array.
  6708. * @example
  6709. *
  6710. * _.flatten([1, [2, [3, [4]], 5]]);
  6711. * // => [1, 2, [3, [4]], 5]
  6712. */
  6713. function flatten(array) {
  6714. var length = array == null ? 0 : array.length;
  6715. return length ? baseFlatten(array, 1) : [];
  6716. }
  6717. /**
  6718. * Recursively flattens `array`.
  6719. *
  6720. * @static
  6721. * @memberOf _
  6722. * @since 3.0.0
  6723. * @category Array
  6724. * @param {Array} array The array to flatten.
  6725. * @returns {Array} Returns the new flattened array.
  6726. * @example
  6727. *
  6728. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6729. * // => [1, 2, 3, 4, 5]
  6730. */
  6731. function flattenDeep(array) {
  6732. var length = array == null ? 0 : array.length;
  6733. return length ? baseFlatten(array, INFINITY) : [];
  6734. }
  6735. /**
  6736. * Recursively flatten `array` up to `depth` times.
  6737. *
  6738. * @static
  6739. * @memberOf _
  6740. * @since 4.4.0
  6741. * @category Array
  6742. * @param {Array} array The array to flatten.
  6743. * @param {number} [depth=1] The maximum recursion depth.
  6744. * @returns {Array} Returns the new flattened array.
  6745. * @example
  6746. *
  6747. * var array = [1, [2, [3, [4]], 5]];
  6748. *
  6749. * _.flattenDepth(array, 1);
  6750. * // => [1, 2, [3, [4]], 5]
  6751. *
  6752. * _.flattenDepth(array, 2);
  6753. * // => [1, 2, 3, [4], 5]
  6754. */
  6755. function flattenDepth(array, depth) {
  6756. var length = array == null ? 0 : array.length;
  6757. if (!length) {
  6758. return [];
  6759. }
  6760. depth = depth === undefined ? 1 : toInteger(depth);
  6761. return baseFlatten(array, depth);
  6762. }
  6763. /**
  6764. * The inverse of `_.toPairs`; this method returns an object composed
  6765. * from key-value `pairs`.
  6766. *
  6767. * @static
  6768. * @memberOf _
  6769. * @since 4.0.0
  6770. * @category Array
  6771. * @param {Array} pairs The key-value pairs.
  6772. * @returns {Object} Returns the new object.
  6773. * @example
  6774. *
  6775. * _.fromPairs([['a', 1], ['b', 2]]);
  6776. * // => { 'a': 1, 'b': 2 }
  6777. */
  6778. function fromPairs(pairs) {
  6779. var index = -1,
  6780. length = pairs == null ? 0 : pairs.length,
  6781. result = {};
  6782. while (++index < length) {
  6783. var pair = pairs[index];
  6784. result[pair[0]] = pair[1];
  6785. }
  6786. return result;
  6787. }
  6788. /**
  6789. * Gets the first element of `array`.
  6790. *
  6791. * @static
  6792. * @memberOf _
  6793. * @since 0.1.0
  6794. * @alias first
  6795. * @category Array
  6796. * @param {Array} array The array to query.
  6797. * @returns {*} Returns the first element of `array`.
  6798. * @example
  6799. *
  6800. * _.head([1, 2, 3]);
  6801. * // => 1
  6802. *
  6803. * _.head([]);
  6804. * // => undefined
  6805. */
  6806. function head(array) {
  6807. return (array && array.length) ? array[0] : undefined;
  6808. }
  6809. /**
  6810. * Gets the index at which the first occurrence of `value` is found in `array`
  6811. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6812. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6813. * offset from the end of `array`.
  6814. *
  6815. * @static
  6816. * @memberOf _
  6817. * @since 0.1.0
  6818. * @category Array
  6819. * @param {Array} array The array to inspect.
  6820. * @param {*} value The value to search for.
  6821. * @param {number} [fromIndex=0] The index to search from.
  6822. * @returns {number} Returns the index of the matched value, else `-1`.
  6823. * @example
  6824. *
  6825. * _.indexOf([1, 2, 1, 2], 2);
  6826. * // => 1
  6827. *
  6828. * // Search from the `fromIndex`.
  6829. * _.indexOf([1, 2, 1, 2], 2, 2);
  6830. * // => 3
  6831. */
  6832. function indexOf(array, value, fromIndex) {
  6833. var length = array == null ? 0 : array.length;
  6834. if (!length) {
  6835. return -1;
  6836. }
  6837. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6838. if (index < 0) {
  6839. index = nativeMax(length + index, 0);
  6840. }
  6841. return baseIndexOf(array, value, index);
  6842. }
  6843. /**
  6844. * Gets all but the last element of `array`.
  6845. *
  6846. * @static
  6847. * @memberOf _
  6848. * @since 0.1.0
  6849. * @category Array
  6850. * @param {Array} array The array to query.
  6851. * @returns {Array} Returns the slice of `array`.
  6852. * @example
  6853. *
  6854. * _.initial([1, 2, 3]);
  6855. * // => [1, 2]
  6856. */
  6857. function initial(array) {
  6858. var length = array == null ? 0 : array.length;
  6859. return length ? baseSlice(array, 0, -1) : [];
  6860. }
  6861. /**
  6862. * Creates an array of unique values that are included in all given arrays
  6863. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6864. * for equality comparisons. The order and references of result values are
  6865. * determined by the first array.
  6866. *
  6867. * @static
  6868. * @memberOf _
  6869. * @since 0.1.0
  6870. * @category Array
  6871. * @param {...Array} [arrays] The arrays to inspect.
  6872. * @returns {Array} Returns the new array of intersecting values.
  6873. * @example
  6874. *
  6875. * _.intersection([2, 1], [2, 3]);
  6876. * // => [2]
  6877. */
  6878. var intersection = baseRest(function(arrays) {
  6879. var mapped = arrayMap(arrays, castArrayLikeObject);
  6880. return (mapped.length && mapped[0] === arrays[0])
  6881. ? baseIntersection(mapped)
  6882. : [];
  6883. });
  6884. /**
  6885. * This method is like `_.intersection` except that it accepts `iteratee`
  6886. * which is invoked for each element of each `arrays` to generate the criterion
  6887. * by which they're compared. The order and references of result values are
  6888. * determined by the first array. The iteratee is invoked with one argument:
  6889. * (value).
  6890. *
  6891. * @static
  6892. * @memberOf _
  6893. * @since 4.0.0
  6894. * @category Array
  6895. * @param {...Array} [arrays] The arrays to inspect.
  6896. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6897. * @returns {Array} Returns the new array of intersecting values.
  6898. * @example
  6899. *
  6900. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6901. * // => [2.1]
  6902. *
  6903. * // The `_.property` iteratee shorthand.
  6904. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6905. * // => [{ 'x': 1 }]
  6906. */
  6907. var intersectionBy = baseRest(function(arrays) {
  6908. var iteratee = last(arrays),
  6909. mapped = arrayMap(arrays, castArrayLikeObject);
  6910. if (iteratee === last(mapped)) {
  6911. iteratee = undefined;
  6912. } else {
  6913. mapped.pop();
  6914. }
  6915. return (mapped.length && mapped[0] === arrays[0])
  6916. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6917. : [];
  6918. });
  6919. /**
  6920. * This method is like `_.intersection` except that it accepts `comparator`
  6921. * which is invoked to compare elements of `arrays`. The order and references
  6922. * of result values are determined by the first array. The comparator is
  6923. * invoked with two arguments: (arrVal, othVal).
  6924. *
  6925. * @static
  6926. * @memberOf _
  6927. * @since 4.0.0
  6928. * @category Array
  6929. * @param {...Array} [arrays] The arrays to inspect.
  6930. * @param {Function} [comparator] The comparator invoked per element.
  6931. * @returns {Array} Returns the new array of intersecting values.
  6932. * @example
  6933. *
  6934. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6935. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6936. *
  6937. * _.intersectionWith(objects, others, _.isEqual);
  6938. * // => [{ 'x': 1, 'y': 2 }]
  6939. */
  6940. var intersectionWith = baseRest(function(arrays) {
  6941. var comparator = last(arrays),
  6942. mapped = arrayMap(arrays, castArrayLikeObject);
  6943. comparator = typeof comparator == 'function' ? comparator : undefined;
  6944. if (comparator) {
  6945. mapped.pop();
  6946. }
  6947. return (mapped.length && mapped[0] === arrays[0])
  6948. ? baseIntersection(mapped, undefined, comparator)
  6949. : [];
  6950. });
  6951. /**
  6952. * Converts all elements in `array` into a string separated by `separator`.
  6953. *
  6954. * @static
  6955. * @memberOf _
  6956. * @since 4.0.0
  6957. * @category Array
  6958. * @param {Array} array The array to convert.
  6959. * @param {string} [separator=','] The element separator.
  6960. * @returns {string} Returns the joined string.
  6961. * @example
  6962. *
  6963. * _.join(['a', 'b', 'c'], '~');
  6964. * // => 'a~b~c'
  6965. */
  6966. function join(array, separator) {
  6967. return array == null ? '' : nativeJoin.call(array, separator);
  6968. }
  6969. /**
  6970. * Gets the last element of `array`.
  6971. *
  6972. * @static
  6973. * @memberOf _
  6974. * @since 0.1.0
  6975. * @category Array
  6976. * @param {Array} array The array to query.
  6977. * @returns {*} Returns the last element of `array`.
  6978. * @example
  6979. *
  6980. * _.last([1, 2, 3]);
  6981. * // => 3
  6982. */
  6983. function last(array) {
  6984. var length = array == null ? 0 : array.length;
  6985. return length ? array[length - 1] : undefined;
  6986. }
  6987. /**
  6988. * This method is like `_.indexOf` except that it iterates over elements of
  6989. * `array` from right to left.
  6990. *
  6991. * @static
  6992. * @memberOf _
  6993. * @since 0.1.0
  6994. * @category Array
  6995. * @param {Array} array The array to inspect.
  6996. * @param {*} value The value to search for.
  6997. * @param {number} [fromIndex=array.length-1] The index to search from.
  6998. * @returns {number} Returns the index of the matched value, else `-1`.
  6999. * @example
  7000. *
  7001. * _.lastIndexOf([1, 2, 1, 2], 2);
  7002. * // => 3
  7003. *
  7004. * // Search from the `fromIndex`.
  7005. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7006. * // => 1
  7007. */
  7008. function lastIndexOf(array, value, fromIndex) {
  7009. var length = array == null ? 0 : array.length;
  7010. if (!length) {
  7011. return -1;
  7012. }
  7013. var index = length;
  7014. if (fromIndex !== undefined) {
  7015. index = toInteger(fromIndex);
  7016. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7017. }
  7018. return value === value
  7019. ? strictLastIndexOf(array, value, index)
  7020. : baseFindIndex(array, baseIsNaN, index, true);
  7021. }
  7022. /**
  7023. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7024. * element from the end is returned.
  7025. *
  7026. * @static
  7027. * @memberOf _
  7028. * @since 4.11.0
  7029. * @category Array
  7030. * @param {Array} array The array to query.
  7031. * @param {number} [n=0] The index of the element to return.
  7032. * @returns {*} Returns the nth element of `array`.
  7033. * @example
  7034. *
  7035. * var array = ['a', 'b', 'c', 'd'];
  7036. *
  7037. * _.nth(array, 1);
  7038. * // => 'b'
  7039. *
  7040. * _.nth(array, -2);
  7041. * // => 'c';
  7042. */
  7043. function nth(array, n) {
  7044. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7045. }
  7046. /**
  7047. * Removes all given values from `array` using
  7048. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7049. * for equality comparisons.
  7050. *
  7051. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7052. * to remove elements from an array by predicate.
  7053. *
  7054. * @static
  7055. * @memberOf _
  7056. * @since 2.0.0
  7057. * @category Array
  7058. * @param {Array} array The array to modify.
  7059. * @param {...*} [values] The values to remove.
  7060. * @returns {Array} Returns `array`.
  7061. * @example
  7062. *
  7063. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7064. *
  7065. * _.pull(array, 'a', 'c');
  7066. * console.log(array);
  7067. * // => ['b', 'b']
  7068. */
  7069. var pull = baseRest(pullAll);
  7070. /**
  7071. * This method is like `_.pull` except that it accepts an array of values to remove.
  7072. *
  7073. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7074. *
  7075. * @static
  7076. * @memberOf _
  7077. * @since 4.0.0
  7078. * @category Array
  7079. * @param {Array} array The array to modify.
  7080. * @param {Array} values The values to remove.
  7081. * @returns {Array} Returns `array`.
  7082. * @example
  7083. *
  7084. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7085. *
  7086. * _.pullAll(array, ['a', 'c']);
  7087. * console.log(array);
  7088. * // => ['b', 'b']
  7089. */
  7090. function pullAll(array, values) {
  7091. return (array && array.length && values && values.length)
  7092. ? basePullAll(array, values)
  7093. : array;
  7094. }
  7095. /**
  7096. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7097. * invoked for each element of `array` and `values` to generate the criterion
  7098. * by which they're compared. The iteratee is invoked with one argument: (value).
  7099. *
  7100. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7101. *
  7102. * @static
  7103. * @memberOf _
  7104. * @since 4.0.0
  7105. * @category Array
  7106. * @param {Array} array The array to modify.
  7107. * @param {Array} values The values to remove.
  7108. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7109. * @returns {Array} Returns `array`.
  7110. * @example
  7111. *
  7112. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7113. *
  7114. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7115. * console.log(array);
  7116. * // => [{ 'x': 2 }]
  7117. */
  7118. function pullAllBy(array, values, iteratee) {
  7119. return (array && array.length && values && values.length)
  7120. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7121. : array;
  7122. }
  7123. /**
  7124. * This method is like `_.pullAll` except that it accepts `comparator` which
  7125. * is invoked to compare elements of `array` to `values`. The comparator is
  7126. * invoked with two arguments: (arrVal, othVal).
  7127. *
  7128. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7129. *
  7130. * @static
  7131. * @memberOf _
  7132. * @since 4.6.0
  7133. * @category Array
  7134. * @param {Array} array The array to modify.
  7135. * @param {Array} values The values to remove.
  7136. * @param {Function} [comparator] The comparator invoked per element.
  7137. * @returns {Array} Returns `array`.
  7138. * @example
  7139. *
  7140. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7141. *
  7142. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7143. * console.log(array);
  7144. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7145. */
  7146. function pullAllWith(array, values, comparator) {
  7147. return (array && array.length && values && values.length)
  7148. ? basePullAll(array, values, undefined, comparator)
  7149. : array;
  7150. }
  7151. /**
  7152. * Removes elements from `array` corresponding to `indexes` and returns an
  7153. * array of removed elements.
  7154. *
  7155. * **Note:** Unlike `_.at`, this method mutates `array`.
  7156. *
  7157. * @static
  7158. * @memberOf _
  7159. * @since 3.0.0
  7160. * @category Array
  7161. * @param {Array} array The array to modify.
  7162. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7163. * @returns {Array} Returns the new array of removed elements.
  7164. * @example
  7165. *
  7166. * var array = ['a', 'b', 'c', 'd'];
  7167. * var pulled = _.pullAt(array, [1, 3]);
  7168. *
  7169. * console.log(array);
  7170. * // => ['a', 'c']
  7171. *
  7172. * console.log(pulled);
  7173. * // => ['b', 'd']
  7174. */
  7175. var pullAt = flatRest(function(array, indexes) {
  7176. var length = array == null ? 0 : array.length,
  7177. result = baseAt(array, indexes);
  7178. basePullAt(array, arrayMap(indexes, function(index) {
  7179. return isIndex(index, length) ? +index : index;
  7180. }).sort(compareAscending));
  7181. return result;
  7182. });
  7183. /**
  7184. * Removes all elements from `array` that `predicate` returns truthy for
  7185. * and returns an array of the removed elements. The predicate is invoked
  7186. * with three arguments: (value, index, array).
  7187. *
  7188. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7189. * to pull elements from an array by value.
  7190. *
  7191. * @static
  7192. * @memberOf _
  7193. * @since 2.0.0
  7194. * @category Array
  7195. * @param {Array} array The array to modify.
  7196. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7197. * @returns {Array} Returns the new array of removed elements.
  7198. * @example
  7199. *
  7200. * var array = [1, 2, 3, 4];
  7201. * var evens = _.remove(array, function(n) {
  7202. * return n % 2 == 0;
  7203. * });
  7204. *
  7205. * console.log(array);
  7206. * // => [1, 3]
  7207. *
  7208. * console.log(evens);
  7209. * // => [2, 4]
  7210. */
  7211. function remove(array, predicate) {
  7212. var result = [];
  7213. if (!(array && array.length)) {
  7214. return result;
  7215. }
  7216. var index = -1,
  7217. indexes = [],
  7218. length = array.length;
  7219. predicate = getIteratee(predicate, 3);
  7220. while (++index < length) {
  7221. var value = array[index];
  7222. if (predicate(value, index, array)) {
  7223. result.push(value);
  7224. indexes.push(index);
  7225. }
  7226. }
  7227. basePullAt(array, indexes);
  7228. return result;
  7229. }
  7230. /**
  7231. * Reverses `array` so that the first element becomes the last, the second
  7232. * element becomes the second to last, and so on.
  7233. *
  7234. * **Note:** This method mutates `array` and is based on
  7235. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7236. *
  7237. * @static
  7238. * @memberOf _
  7239. * @since 4.0.0
  7240. * @category Array
  7241. * @param {Array} array The array to modify.
  7242. * @returns {Array} Returns `array`.
  7243. * @example
  7244. *
  7245. * var array = [1, 2, 3];
  7246. *
  7247. * _.reverse(array);
  7248. * // => [3, 2, 1]
  7249. *
  7250. * console.log(array);
  7251. * // => [3, 2, 1]
  7252. */
  7253. function reverse(array) {
  7254. return array == null ? array : nativeReverse.call(array);
  7255. }
  7256. /**
  7257. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7258. *
  7259. * **Note:** This method is used instead of
  7260. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7261. * returned.
  7262. *
  7263. * @static
  7264. * @memberOf _
  7265. * @since 3.0.0
  7266. * @category Array
  7267. * @param {Array} array The array to slice.
  7268. * @param {number} [start=0] The start position.
  7269. * @param {number} [end=array.length] The end position.
  7270. * @returns {Array} Returns the slice of `array`.
  7271. */
  7272. function slice(array, start, end) {
  7273. var length = array == null ? 0 : array.length;
  7274. if (!length) {
  7275. return [];
  7276. }
  7277. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7278. start = 0;
  7279. end = length;
  7280. }
  7281. else {
  7282. start = start == null ? 0 : toInteger(start);
  7283. end = end === undefined ? length : toInteger(end);
  7284. }
  7285. return baseSlice(array, start, end);
  7286. }
  7287. /**
  7288. * Uses a binary search to determine the lowest index at which `value`
  7289. * should be inserted into `array` in order to maintain its sort order.
  7290. *
  7291. * @static
  7292. * @memberOf _
  7293. * @since 0.1.0
  7294. * @category Array
  7295. * @param {Array} array The sorted array to inspect.
  7296. * @param {*} value The value to evaluate.
  7297. * @returns {number} Returns the index at which `value` should be inserted
  7298. * into `array`.
  7299. * @example
  7300. *
  7301. * _.sortedIndex([30, 50], 40);
  7302. * // => 1
  7303. */
  7304. function sortedIndex(array, value) {
  7305. return baseSortedIndex(array, value);
  7306. }
  7307. /**
  7308. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7309. * which is invoked for `value` and each element of `array` to compute their
  7310. * sort ranking. The iteratee is invoked with one argument: (value).
  7311. *
  7312. * @static
  7313. * @memberOf _
  7314. * @since 4.0.0
  7315. * @category Array
  7316. * @param {Array} array The sorted array to inspect.
  7317. * @param {*} value The value to evaluate.
  7318. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7319. * @returns {number} Returns the index at which `value` should be inserted
  7320. * into `array`.
  7321. * @example
  7322. *
  7323. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7324. *
  7325. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7326. * // => 0
  7327. *
  7328. * // The `_.property` iteratee shorthand.
  7329. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7330. * // => 0
  7331. */
  7332. function sortedIndexBy(array, value, iteratee) {
  7333. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7334. }
  7335. /**
  7336. * This method is like `_.indexOf` except that it performs a binary
  7337. * search on a sorted `array`.
  7338. *
  7339. * @static
  7340. * @memberOf _
  7341. * @since 4.0.0
  7342. * @category Array
  7343. * @param {Array} array The array to inspect.
  7344. * @param {*} value The value to search for.
  7345. * @returns {number} Returns the index of the matched value, else `-1`.
  7346. * @example
  7347. *
  7348. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7349. * // => 1
  7350. */
  7351. function sortedIndexOf(array, value) {
  7352. var length = array == null ? 0 : array.length;
  7353. if (length) {
  7354. var index = baseSortedIndex(array, value);
  7355. if (index < length && eq(array[index], value)) {
  7356. return index;
  7357. }
  7358. }
  7359. return -1;
  7360. }
  7361. /**
  7362. * This method is like `_.sortedIndex` except that it returns the highest
  7363. * index at which `value` should be inserted into `array` in order to
  7364. * maintain its sort order.
  7365. *
  7366. * @static
  7367. * @memberOf _
  7368. * @since 3.0.0
  7369. * @category Array
  7370. * @param {Array} array The sorted array to inspect.
  7371. * @param {*} value The value to evaluate.
  7372. * @returns {number} Returns the index at which `value` should be inserted
  7373. * into `array`.
  7374. * @example
  7375. *
  7376. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7377. * // => 4
  7378. */
  7379. function sortedLastIndex(array, value) {
  7380. return baseSortedIndex(array, value, true);
  7381. }
  7382. /**
  7383. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7384. * which is invoked for `value` and each element of `array` to compute their
  7385. * sort ranking. The iteratee is invoked with one argument: (value).
  7386. *
  7387. * @static
  7388. * @memberOf _
  7389. * @since 4.0.0
  7390. * @category Array
  7391. * @param {Array} array The sorted array to inspect.
  7392. * @param {*} value The value to evaluate.
  7393. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7394. * @returns {number} Returns the index at which `value` should be inserted
  7395. * into `array`.
  7396. * @example
  7397. *
  7398. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7399. *
  7400. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7401. * // => 1
  7402. *
  7403. * // The `_.property` iteratee shorthand.
  7404. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7405. * // => 1
  7406. */
  7407. function sortedLastIndexBy(array, value, iteratee) {
  7408. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7409. }
  7410. /**
  7411. * This method is like `_.lastIndexOf` except that it performs a binary
  7412. * search on a sorted `array`.
  7413. *
  7414. * @static
  7415. * @memberOf _
  7416. * @since 4.0.0
  7417. * @category Array
  7418. * @param {Array} array The array to inspect.
  7419. * @param {*} value The value to search for.
  7420. * @returns {number} Returns the index of the matched value, else `-1`.
  7421. * @example
  7422. *
  7423. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7424. * // => 3
  7425. */
  7426. function sortedLastIndexOf(array, value) {
  7427. var length = array == null ? 0 : array.length;
  7428. if (length) {
  7429. var index = baseSortedIndex(array, value, true) - 1;
  7430. if (eq(array[index], value)) {
  7431. return index;
  7432. }
  7433. }
  7434. return -1;
  7435. }
  7436. /**
  7437. * This method is like `_.uniq` except that it's designed and optimized
  7438. * for sorted arrays.
  7439. *
  7440. * @static
  7441. * @memberOf _
  7442. * @since 4.0.0
  7443. * @category Array
  7444. * @param {Array} array The array to inspect.
  7445. * @returns {Array} Returns the new duplicate free array.
  7446. * @example
  7447. *
  7448. * _.sortedUniq([1, 1, 2]);
  7449. * // => [1, 2]
  7450. */
  7451. function sortedUniq(array) {
  7452. return (array && array.length)
  7453. ? baseSortedUniq(array)
  7454. : [];
  7455. }
  7456. /**
  7457. * This method is like `_.uniqBy` except that it's designed and optimized
  7458. * for sorted arrays.
  7459. *
  7460. * @static
  7461. * @memberOf _
  7462. * @since 4.0.0
  7463. * @category Array
  7464. * @param {Array} array The array to inspect.
  7465. * @param {Function} [iteratee] The iteratee invoked per element.
  7466. * @returns {Array} Returns the new duplicate free array.
  7467. * @example
  7468. *
  7469. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7470. * // => [1.1, 2.3]
  7471. */
  7472. function sortedUniqBy(array, iteratee) {
  7473. return (array && array.length)
  7474. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7475. : [];
  7476. }
  7477. /**
  7478. * Gets all but the first element of `array`.
  7479. *
  7480. * @static
  7481. * @memberOf _
  7482. * @since 4.0.0
  7483. * @category Array
  7484. * @param {Array} array The array to query.
  7485. * @returns {Array} Returns the slice of `array`.
  7486. * @example
  7487. *
  7488. * _.tail([1, 2, 3]);
  7489. * // => [2, 3]
  7490. */
  7491. function tail(array) {
  7492. var length = array == null ? 0 : array.length;
  7493. return length ? baseSlice(array, 1, length) : [];
  7494. }
  7495. /**
  7496. * Creates a slice of `array` with `n` elements taken from the beginning.
  7497. *
  7498. * @static
  7499. * @memberOf _
  7500. * @since 0.1.0
  7501. * @category Array
  7502. * @param {Array} array The array to query.
  7503. * @param {number} [n=1] The number of elements to take.
  7504. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7505. * @returns {Array} Returns the slice of `array`.
  7506. * @example
  7507. *
  7508. * _.take([1, 2, 3]);
  7509. * // => [1]
  7510. *
  7511. * _.take([1, 2, 3], 2);
  7512. * // => [1, 2]
  7513. *
  7514. * _.take([1, 2, 3], 5);
  7515. * // => [1, 2, 3]
  7516. *
  7517. * _.take([1, 2, 3], 0);
  7518. * // => []
  7519. */
  7520. function take(array, n, guard) {
  7521. if (!(array && array.length)) {
  7522. return [];
  7523. }
  7524. n = (guard || n === undefined) ? 1 : toInteger(n);
  7525. return baseSlice(array, 0, n < 0 ? 0 : n);
  7526. }
  7527. /**
  7528. * Creates a slice of `array` with `n` elements taken from the end.
  7529. *
  7530. * @static
  7531. * @memberOf _
  7532. * @since 3.0.0
  7533. * @category Array
  7534. * @param {Array} array The array to query.
  7535. * @param {number} [n=1] The number of elements to take.
  7536. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7537. * @returns {Array} Returns the slice of `array`.
  7538. * @example
  7539. *
  7540. * _.takeRight([1, 2, 3]);
  7541. * // => [3]
  7542. *
  7543. * _.takeRight([1, 2, 3], 2);
  7544. * // => [2, 3]
  7545. *
  7546. * _.takeRight([1, 2, 3], 5);
  7547. * // => [1, 2, 3]
  7548. *
  7549. * _.takeRight([1, 2, 3], 0);
  7550. * // => []
  7551. */
  7552. function takeRight(array, n, guard) {
  7553. var length = array == null ? 0 : array.length;
  7554. if (!length) {
  7555. return [];
  7556. }
  7557. n = (guard || n === undefined) ? 1 : toInteger(n);
  7558. n = length - n;
  7559. return baseSlice(array, n < 0 ? 0 : n, length);
  7560. }
  7561. /**
  7562. * Creates a slice of `array` with elements taken from the end. Elements are
  7563. * taken until `predicate` returns falsey. The predicate is invoked with
  7564. * three arguments: (value, index, array).
  7565. *
  7566. * @static
  7567. * @memberOf _
  7568. * @since 3.0.0
  7569. * @category Array
  7570. * @param {Array} array The array to query.
  7571. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7572. * @returns {Array} Returns the slice of `array`.
  7573. * @example
  7574. *
  7575. * var users = [
  7576. * { 'user': 'barney', 'active': true },
  7577. * { 'user': 'fred', 'active': false },
  7578. * { 'user': 'pebbles', 'active': false }
  7579. * ];
  7580. *
  7581. * _.takeRightWhile(users, function(o) { return !o.active; });
  7582. * // => objects for ['fred', 'pebbles']
  7583. *
  7584. * // The `_.matches` iteratee shorthand.
  7585. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7586. * // => objects for ['pebbles']
  7587. *
  7588. * // The `_.matchesProperty` iteratee shorthand.
  7589. * _.takeRightWhile(users, ['active', false]);
  7590. * // => objects for ['fred', 'pebbles']
  7591. *
  7592. * // The `_.property` iteratee shorthand.
  7593. * _.takeRightWhile(users, 'active');
  7594. * // => []
  7595. */
  7596. function takeRightWhile(array, predicate) {
  7597. return (array && array.length)
  7598. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7599. : [];
  7600. }
  7601. /**
  7602. * Creates a slice of `array` with elements taken from the beginning. Elements
  7603. * are taken until `predicate` returns falsey. The predicate is invoked with
  7604. * three arguments: (value, index, array).
  7605. *
  7606. * @static
  7607. * @memberOf _
  7608. * @since 3.0.0
  7609. * @category Array
  7610. * @param {Array} array The array to query.
  7611. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7612. * @returns {Array} Returns the slice of `array`.
  7613. * @example
  7614. *
  7615. * var users = [
  7616. * { 'user': 'barney', 'active': false },
  7617. * { 'user': 'fred', 'active': false },
  7618. * { 'user': 'pebbles', 'active': true }
  7619. * ];
  7620. *
  7621. * _.takeWhile(users, function(o) { return !o.active; });
  7622. * // => objects for ['barney', 'fred']
  7623. *
  7624. * // The `_.matches` iteratee shorthand.
  7625. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7626. * // => objects for ['barney']
  7627. *
  7628. * // The `_.matchesProperty` iteratee shorthand.
  7629. * _.takeWhile(users, ['active', false]);
  7630. * // => objects for ['barney', 'fred']
  7631. *
  7632. * // The `_.property` iteratee shorthand.
  7633. * _.takeWhile(users, 'active');
  7634. * // => []
  7635. */
  7636. function takeWhile(array, predicate) {
  7637. return (array && array.length)
  7638. ? baseWhile(array, getIteratee(predicate, 3))
  7639. : [];
  7640. }
  7641. /**
  7642. * Creates an array of unique values, in order, from all given arrays using
  7643. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7644. * for equality comparisons.
  7645. *
  7646. * @static
  7647. * @memberOf _
  7648. * @since 0.1.0
  7649. * @category Array
  7650. * @param {...Array} [arrays] The arrays to inspect.
  7651. * @returns {Array} Returns the new array of combined values.
  7652. * @example
  7653. *
  7654. * _.union([2], [1, 2]);
  7655. * // => [2, 1]
  7656. */
  7657. var union = baseRest(function(arrays) {
  7658. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7659. });
  7660. /**
  7661. * This method is like `_.union` except that it accepts `iteratee` which is
  7662. * invoked for each element of each `arrays` to generate the criterion by
  7663. * which uniqueness is computed. Result values are chosen from the first
  7664. * array in which the value occurs. The iteratee is invoked with one argument:
  7665. * (value).
  7666. *
  7667. * @static
  7668. * @memberOf _
  7669. * @since 4.0.0
  7670. * @category Array
  7671. * @param {...Array} [arrays] The arrays to inspect.
  7672. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7673. * @returns {Array} Returns the new array of combined values.
  7674. * @example
  7675. *
  7676. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7677. * // => [2.1, 1.2]
  7678. *
  7679. * // The `_.property` iteratee shorthand.
  7680. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7681. * // => [{ 'x': 1 }, { 'x': 2 }]
  7682. */
  7683. var unionBy = baseRest(function(arrays) {
  7684. var iteratee = last(arrays);
  7685. if (isArrayLikeObject(iteratee)) {
  7686. iteratee = undefined;
  7687. }
  7688. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7689. });
  7690. /**
  7691. * This method is like `_.union` except that it accepts `comparator` which
  7692. * is invoked to compare elements of `arrays`. Result values are chosen from
  7693. * the first array in which the value occurs. The comparator is invoked
  7694. * with two arguments: (arrVal, othVal).
  7695. *
  7696. * @static
  7697. * @memberOf _
  7698. * @since 4.0.0
  7699. * @category Array
  7700. * @param {...Array} [arrays] The arrays to inspect.
  7701. * @param {Function} [comparator] The comparator invoked per element.
  7702. * @returns {Array} Returns the new array of combined values.
  7703. * @example
  7704. *
  7705. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7706. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7707. *
  7708. * _.unionWith(objects, others, _.isEqual);
  7709. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7710. */
  7711. var unionWith = baseRest(function(arrays) {
  7712. var comparator = last(arrays);
  7713. comparator = typeof comparator == 'function' ? comparator : undefined;
  7714. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7715. });
  7716. /**
  7717. * Creates a duplicate-free version of an array, using
  7718. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7719. * for equality comparisons, in which only the first occurrence of each element
  7720. * is kept. The order of result values is determined by the order they occur
  7721. * in the array.
  7722. *
  7723. * @static
  7724. * @memberOf _
  7725. * @since 0.1.0
  7726. * @category Array
  7727. * @param {Array} array The array to inspect.
  7728. * @returns {Array} Returns the new duplicate free array.
  7729. * @example
  7730. *
  7731. * _.uniq([2, 1, 2]);
  7732. * // => [2, 1]
  7733. */
  7734. function uniq(array) {
  7735. return (array && array.length) ? baseUniq(array) : [];
  7736. }
  7737. /**
  7738. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7739. * invoked for each element in `array` to generate the criterion by which
  7740. * uniqueness is computed. The order of result values is determined by the
  7741. * order they occur in the array. The iteratee is invoked with one argument:
  7742. * (value).
  7743. *
  7744. * @static
  7745. * @memberOf _
  7746. * @since 4.0.0
  7747. * @category Array
  7748. * @param {Array} array The array to inspect.
  7749. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7750. * @returns {Array} Returns the new duplicate free array.
  7751. * @example
  7752. *
  7753. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7754. * // => [2.1, 1.2]
  7755. *
  7756. * // The `_.property` iteratee shorthand.
  7757. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7758. * // => [{ 'x': 1 }, { 'x': 2 }]
  7759. */
  7760. function uniqBy(array, iteratee) {
  7761. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7762. }
  7763. /**
  7764. * This method is like `_.uniq` except that it accepts `comparator` which
  7765. * is invoked to compare elements of `array`. The order of result values is
  7766. * determined by the order they occur in the array.The comparator is invoked
  7767. * with two arguments: (arrVal, othVal).
  7768. *
  7769. * @static
  7770. * @memberOf _
  7771. * @since 4.0.0
  7772. * @category Array
  7773. * @param {Array} array The array to inspect.
  7774. * @param {Function} [comparator] The comparator invoked per element.
  7775. * @returns {Array} Returns the new duplicate free array.
  7776. * @example
  7777. *
  7778. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7779. *
  7780. * _.uniqWith(objects, _.isEqual);
  7781. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7782. */
  7783. function uniqWith(array, comparator) {
  7784. comparator = typeof comparator == 'function' ? comparator : undefined;
  7785. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7786. }
  7787. /**
  7788. * This method is like `_.zip` except that it accepts an array of grouped
  7789. * elements and creates an array regrouping the elements to their pre-zip
  7790. * configuration.
  7791. *
  7792. * @static
  7793. * @memberOf _
  7794. * @since 1.2.0
  7795. * @category Array
  7796. * @param {Array} array The array of grouped elements to process.
  7797. * @returns {Array} Returns the new array of regrouped elements.
  7798. * @example
  7799. *
  7800. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7801. * // => [['a', 1, true], ['b', 2, false]]
  7802. *
  7803. * _.unzip(zipped);
  7804. * // => [['a', 'b'], [1, 2], [true, false]]
  7805. */
  7806. function unzip(array) {
  7807. if (!(array && array.length)) {
  7808. return [];
  7809. }
  7810. var length = 0;
  7811. array = arrayFilter(array, function(group) {
  7812. if (isArrayLikeObject(group)) {
  7813. length = nativeMax(group.length, length);
  7814. return true;
  7815. }
  7816. });
  7817. return baseTimes(length, function(index) {
  7818. return arrayMap(array, baseProperty(index));
  7819. });
  7820. }
  7821. /**
  7822. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7823. * how regrouped values should be combined. The iteratee is invoked with the
  7824. * elements of each group: (...group).
  7825. *
  7826. * @static
  7827. * @memberOf _
  7828. * @since 3.8.0
  7829. * @category Array
  7830. * @param {Array} array The array of grouped elements to process.
  7831. * @param {Function} [iteratee=_.identity] The function to combine
  7832. * regrouped values.
  7833. * @returns {Array} Returns the new array of regrouped elements.
  7834. * @example
  7835. *
  7836. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7837. * // => [[1, 10, 100], [2, 20, 200]]
  7838. *
  7839. * _.unzipWith(zipped, _.add);
  7840. * // => [3, 30, 300]
  7841. */
  7842. function unzipWith(array, iteratee) {
  7843. if (!(array && array.length)) {
  7844. return [];
  7845. }
  7846. var result = unzip(array);
  7847. if (iteratee == null) {
  7848. return result;
  7849. }
  7850. return arrayMap(result, function(group) {
  7851. return apply(iteratee, undefined, group);
  7852. });
  7853. }
  7854. /**
  7855. * Creates an array excluding all given values using
  7856. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7857. * for equality comparisons.
  7858. *
  7859. * **Note:** Unlike `_.pull`, this method returns a new array.
  7860. *
  7861. * @static
  7862. * @memberOf _
  7863. * @since 0.1.0
  7864. * @category Array
  7865. * @param {Array} array The array to inspect.
  7866. * @param {...*} [values] The values to exclude.
  7867. * @returns {Array} Returns the new array of filtered values.
  7868. * @see _.difference, _.xor
  7869. * @example
  7870. *
  7871. * _.without([2, 1, 2, 3], 1, 2);
  7872. * // => [3]
  7873. */
  7874. var without = baseRest(function(array, values) {
  7875. return isArrayLikeObject(array)
  7876. ? baseDifference(array, values)
  7877. : [];
  7878. });
  7879. /**
  7880. * Creates an array of unique values that is the
  7881. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7882. * of the given arrays. The order of result values is determined by the order
  7883. * they occur in the arrays.
  7884. *
  7885. * @static
  7886. * @memberOf _
  7887. * @since 2.4.0
  7888. * @category Array
  7889. * @param {...Array} [arrays] The arrays to inspect.
  7890. * @returns {Array} Returns the new array of filtered values.
  7891. * @see _.difference, _.without
  7892. * @example
  7893. *
  7894. * _.xor([2, 1], [2, 3]);
  7895. * // => [1, 3]
  7896. */
  7897. var xor = baseRest(function(arrays) {
  7898. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7899. });
  7900. /**
  7901. * This method is like `_.xor` except that it accepts `iteratee` which is
  7902. * invoked for each element of each `arrays` to generate the criterion by
  7903. * which by which they're compared. The order of result values is determined
  7904. * by the order they occur in the arrays. The iteratee is invoked with one
  7905. * argument: (value).
  7906. *
  7907. * @static
  7908. * @memberOf _
  7909. * @since 4.0.0
  7910. * @category Array
  7911. * @param {...Array} [arrays] The arrays to inspect.
  7912. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7913. * @returns {Array} Returns the new array of filtered values.
  7914. * @example
  7915. *
  7916. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7917. * // => [1.2, 3.4]
  7918. *
  7919. * // The `_.property` iteratee shorthand.
  7920. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7921. * // => [{ 'x': 2 }]
  7922. */
  7923. var xorBy = baseRest(function(arrays) {
  7924. var iteratee = last(arrays);
  7925. if (isArrayLikeObject(iteratee)) {
  7926. iteratee = undefined;
  7927. }
  7928. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7929. });
  7930. /**
  7931. * This method is like `_.xor` except that it accepts `comparator` which is
  7932. * invoked to compare elements of `arrays`. The order of result values is
  7933. * determined by the order they occur in the arrays. The comparator is invoked
  7934. * with two arguments: (arrVal, othVal).
  7935. *
  7936. * @static
  7937. * @memberOf _
  7938. * @since 4.0.0
  7939. * @category Array
  7940. * @param {...Array} [arrays] The arrays to inspect.
  7941. * @param {Function} [comparator] The comparator invoked per element.
  7942. * @returns {Array} Returns the new array of filtered values.
  7943. * @example
  7944. *
  7945. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7946. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7947. *
  7948. * _.xorWith(objects, others, _.isEqual);
  7949. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7950. */
  7951. var xorWith = baseRest(function(arrays) {
  7952. var comparator = last(arrays);
  7953. comparator = typeof comparator == 'function' ? comparator : undefined;
  7954. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7955. });
  7956. /**
  7957. * Creates an array of grouped elements, the first of which contains the
  7958. * first elements of the given arrays, the second of which contains the
  7959. * second elements of the given arrays, and so on.
  7960. *
  7961. * @static
  7962. * @memberOf _
  7963. * @since 0.1.0
  7964. * @category Array
  7965. * @param {...Array} [arrays] The arrays to process.
  7966. * @returns {Array} Returns the new array of grouped elements.
  7967. * @example
  7968. *
  7969. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7970. * // => [['a', 1, true], ['b', 2, false]]
  7971. */
  7972. var zip = baseRest(unzip);
  7973. /**
  7974. * This method is like `_.fromPairs` except that it accepts two arrays,
  7975. * one of property identifiers and one of corresponding values.
  7976. *
  7977. * @static
  7978. * @memberOf _
  7979. * @since 0.4.0
  7980. * @category Array
  7981. * @param {Array} [props=[]] The property identifiers.
  7982. * @param {Array} [values=[]] The property values.
  7983. * @returns {Object} Returns the new object.
  7984. * @example
  7985. *
  7986. * _.zipObject(['a', 'b'], [1, 2]);
  7987. * // => { 'a': 1, 'b': 2 }
  7988. */
  7989. function zipObject(props, values) {
  7990. return baseZipObject(props || [], values || [], assignValue);
  7991. }
  7992. /**
  7993. * This method is like `_.zipObject` except that it supports property paths.
  7994. *
  7995. * @static
  7996. * @memberOf _
  7997. * @since 4.1.0
  7998. * @category Array
  7999. * @param {Array} [props=[]] The property identifiers.
  8000. * @param {Array} [values=[]] The property values.
  8001. * @returns {Object} Returns the new object.
  8002. * @example
  8003. *
  8004. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8005. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8006. */
  8007. function zipObjectDeep(props, values) {
  8008. return baseZipObject(props || [], values || [], baseSet);
  8009. }
  8010. /**
  8011. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8012. * how grouped values should be combined. The iteratee is invoked with the
  8013. * elements of each group: (...group).
  8014. *
  8015. * @static
  8016. * @memberOf _
  8017. * @since 3.8.0
  8018. * @category Array
  8019. * @param {...Array} [arrays] The arrays to process.
  8020. * @param {Function} [iteratee=_.identity] The function to combine
  8021. * grouped values.
  8022. * @returns {Array} Returns the new array of grouped elements.
  8023. * @example
  8024. *
  8025. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8026. * return a + b + c;
  8027. * });
  8028. * // => [111, 222]
  8029. */
  8030. var zipWith = baseRest(function(arrays) {
  8031. var length = arrays.length,
  8032. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8033. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8034. return unzipWith(arrays, iteratee);
  8035. });
  8036. /*------------------------------------------------------------------------*/
  8037. /**
  8038. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8039. * chain sequences enabled. The result of such sequences must be unwrapped
  8040. * with `_#value`.
  8041. *
  8042. * @static
  8043. * @memberOf _
  8044. * @since 1.3.0
  8045. * @category Seq
  8046. * @param {*} value The value to wrap.
  8047. * @returns {Object} Returns the new `lodash` wrapper instance.
  8048. * @example
  8049. *
  8050. * var users = [
  8051. * { 'user': 'barney', 'age': 36 },
  8052. * { 'user': 'fred', 'age': 40 },
  8053. * { 'user': 'pebbles', 'age': 1 }
  8054. * ];
  8055. *
  8056. * var youngest = _
  8057. * .chain(users)
  8058. * .sortBy('age')
  8059. * .map(function(o) {
  8060. * return o.user + ' is ' + o.age;
  8061. * })
  8062. * .head()
  8063. * .value();
  8064. * // => 'pebbles is 1'
  8065. */
  8066. function chain(value) {
  8067. var result = lodash(value);
  8068. result.__chain__ = true;
  8069. return result;
  8070. }
  8071. /**
  8072. * This method invokes `interceptor` and returns `value`. The interceptor
  8073. * is invoked with one argument; (value). The purpose of this method is to
  8074. * "tap into" a method chain sequence in order to modify intermediate results.
  8075. *
  8076. * @static
  8077. * @memberOf _
  8078. * @since 0.1.0
  8079. * @category Seq
  8080. * @param {*} value The value to provide to `interceptor`.
  8081. * @param {Function} interceptor The function to invoke.
  8082. * @returns {*} Returns `value`.
  8083. * @example
  8084. *
  8085. * _([1, 2, 3])
  8086. * .tap(function(array) {
  8087. * // Mutate input array.
  8088. * array.pop();
  8089. * })
  8090. * .reverse()
  8091. * .value();
  8092. * // => [2, 1]
  8093. */
  8094. function tap(value, interceptor) {
  8095. interceptor(value);
  8096. return value;
  8097. }
  8098. /**
  8099. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8100. * The purpose of this method is to "pass thru" values replacing intermediate
  8101. * results in a method chain sequence.
  8102. *
  8103. * @static
  8104. * @memberOf _
  8105. * @since 3.0.0
  8106. * @category Seq
  8107. * @param {*} value The value to provide to `interceptor`.
  8108. * @param {Function} interceptor The function to invoke.
  8109. * @returns {*} Returns the result of `interceptor`.
  8110. * @example
  8111. *
  8112. * _(' abc ')
  8113. * .chain()
  8114. * .trim()
  8115. * .thru(function(value) {
  8116. * return [value];
  8117. * })
  8118. * .value();
  8119. * // => ['abc']
  8120. */
  8121. function thru(value, interceptor) {
  8122. return interceptor(value);
  8123. }
  8124. /**
  8125. * This method is the wrapper version of `_.at`.
  8126. *
  8127. * @name at
  8128. * @memberOf _
  8129. * @since 1.0.0
  8130. * @category Seq
  8131. * @param {...(string|string[])} [paths] The property paths to pick.
  8132. * @returns {Object} Returns the new `lodash` wrapper instance.
  8133. * @example
  8134. *
  8135. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8136. *
  8137. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8138. * // => [3, 4]
  8139. */
  8140. var wrapperAt = flatRest(function(paths) {
  8141. var length = paths.length,
  8142. start = length ? paths[0] : 0,
  8143. value = this.__wrapped__,
  8144. interceptor = function(object) { return baseAt(object, paths); };
  8145. if (length > 1 || this.__actions__.length ||
  8146. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8147. return this.thru(interceptor);
  8148. }
  8149. value = value.slice(start, +start + (length ? 1 : 0));
  8150. value.__actions__.push({
  8151. 'func': thru,
  8152. 'args': [interceptor],
  8153. 'thisArg': undefined
  8154. });
  8155. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8156. if (length && !array.length) {
  8157. array.push(undefined);
  8158. }
  8159. return array;
  8160. });
  8161. });
  8162. /**
  8163. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8164. *
  8165. * @name chain
  8166. * @memberOf _
  8167. * @since 0.1.0
  8168. * @category Seq
  8169. * @returns {Object} Returns the new `lodash` wrapper instance.
  8170. * @example
  8171. *
  8172. * var users = [
  8173. * { 'user': 'barney', 'age': 36 },
  8174. * { 'user': 'fred', 'age': 40 }
  8175. * ];
  8176. *
  8177. * // A sequence without explicit chaining.
  8178. * _(users).head();
  8179. * // => { 'user': 'barney', 'age': 36 }
  8180. *
  8181. * // A sequence with explicit chaining.
  8182. * _(users)
  8183. * .chain()
  8184. * .head()
  8185. * .pick('user')
  8186. * .value();
  8187. * // => { 'user': 'barney' }
  8188. */
  8189. function wrapperChain() {
  8190. return chain(this);
  8191. }
  8192. /**
  8193. * Executes the chain sequence and returns the wrapped result.
  8194. *
  8195. * @name commit
  8196. * @memberOf _
  8197. * @since 3.2.0
  8198. * @category Seq
  8199. * @returns {Object} Returns the new `lodash` wrapper instance.
  8200. * @example
  8201. *
  8202. * var array = [1, 2];
  8203. * var wrapped = _(array).push(3);
  8204. *
  8205. * console.log(array);
  8206. * // => [1, 2]
  8207. *
  8208. * wrapped = wrapped.commit();
  8209. * console.log(array);
  8210. * // => [1, 2, 3]
  8211. *
  8212. * wrapped.last();
  8213. * // => 3
  8214. *
  8215. * console.log(array);
  8216. * // => [1, 2, 3]
  8217. */
  8218. function wrapperCommit() {
  8219. return new LodashWrapper(this.value(), this.__chain__);
  8220. }
  8221. /**
  8222. * Gets the next value on a wrapped object following the
  8223. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8224. *
  8225. * @name next
  8226. * @memberOf _
  8227. * @since 4.0.0
  8228. * @category Seq
  8229. * @returns {Object} Returns the next iterator value.
  8230. * @example
  8231. *
  8232. * var wrapped = _([1, 2]);
  8233. *
  8234. * wrapped.next();
  8235. * // => { 'done': false, 'value': 1 }
  8236. *
  8237. * wrapped.next();
  8238. * // => { 'done': false, 'value': 2 }
  8239. *
  8240. * wrapped.next();
  8241. * // => { 'done': true, 'value': undefined }
  8242. */
  8243. function wrapperNext() {
  8244. if (this.__values__ === undefined) {
  8245. this.__values__ = toArray(this.value());
  8246. }
  8247. var done = this.__index__ >= this.__values__.length,
  8248. value = done ? undefined : this.__values__[this.__index__++];
  8249. return { 'done': done, 'value': value };
  8250. }
  8251. /**
  8252. * Enables the wrapper to be iterable.
  8253. *
  8254. * @name Symbol.iterator
  8255. * @memberOf _
  8256. * @since 4.0.0
  8257. * @category Seq
  8258. * @returns {Object} Returns the wrapper object.
  8259. * @example
  8260. *
  8261. * var wrapped = _([1, 2]);
  8262. *
  8263. * wrapped[Symbol.iterator]() === wrapped;
  8264. * // => true
  8265. *
  8266. * Array.from(wrapped);
  8267. * // => [1, 2]
  8268. */
  8269. function wrapperToIterator() {
  8270. return this;
  8271. }
  8272. /**
  8273. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8274. *
  8275. * @name plant
  8276. * @memberOf _
  8277. * @since 3.2.0
  8278. * @category Seq
  8279. * @param {*} value The value to plant.
  8280. * @returns {Object} Returns the new `lodash` wrapper instance.
  8281. * @example
  8282. *
  8283. * function square(n) {
  8284. * return n * n;
  8285. * }
  8286. *
  8287. * var wrapped = _([1, 2]).map(square);
  8288. * var other = wrapped.plant([3, 4]);
  8289. *
  8290. * other.value();
  8291. * // => [9, 16]
  8292. *
  8293. * wrapped.value();
  8294. * // => [1, 4]
  8295. */
  8296. function wrapperPlant(value) {
  8297. var result,
  8298. parent = this;
  8299. while (parent instanceof baseLodash) {
  8300. var clone = wrapperClone(parent);
  8301. clone.__index__ = 0;
  8302. clone.__values__ = undefined;
  8303. if (result) {
  8304. previous.__wrapped__ = clone;
  8305. } else {
  8306. result = clone;
  8307. }
  8308. var previous = clone;
  8309. parent = parent.__wrapped__;
  8310. }
  8311. previous.__wrapped__ = value;
  8312. return result;
  8313. }
  8314. /**
  8315. * This method is the wrapper version of `_.reverse`.
  8316. *
  8317. * **Note:** This method mutates the wrapped array.
  8318. *
  8319. * @name reverse
  8320. * @memberOf _
  8321. * @since 0.1.0
  8322. * @category Seq
  8323. * @returns {Object} Returns the new `lodash` wrapper instance.
  8324. * @example
  8325. *
  8326. * var array = [1, 2, 3];
  8327. *
  8328. * _(array).reverse().value()
  8329. * // => [3, 2, 1]
  8330. *
  8331. * console.log(array);
  8332. * // => [3, 2, 1]
  8333. */
  8334. function wrapperReverse() {
  8335. var value = this.__wrapped__;
  8336. if (value instanceof LazyWrapper) {
  8337. var wrapped = value;
  8338. if (this.__actions__.length) {
  8339. wrapped = new LazyWrapper(this);
  8340. }
  8341. wrapped = wrapped.reverse();
  8342. wrapped.__actions__.push({
  8343. 'func': thru,
  8344. 'args': [reverse],
  8345. 'thisArg': undefined
  8346. });
  8347. return new LodashWrapper(wrapped, this.__chain__);
  8348. }
  8349. return this.thru(reverse);
  8350. }
  8351. /**
  8352. * Executes the chain sequence to resolve the unwrapped value.
  8353. *
  8354. * @name value
  8355. * @memberOf _
  8356. * @since 0.1.0
  8357. * @alias toJSON, valueOf
  8358. * @category Seq
  8359. * @returns {*} Returns the resolved unwrapped value.
  8360. * @example
  8361. *
  8362. * _([1, 2, 3]).value();
  8363. * // => [1, 2, 3]
  8364. */
  8365. function wrapperValue() {
  8366. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8367. }
  8368. /*------------------------------------------------------------------------*/
  8369. /**
  8370. * Creates an object composed of keys generated from the results of running
  8371. * each element of `collection` thru `iteratee`. The corresponding value of
  8372. * each key is the number of times the key was returned by `iteratee`. The
  8373. * iteratee is invoked with one argument: (value).
  8374. *
  8375. * @static
  8376. * @memberOf _
  8377. * @since 0.5.0
  8378. * @category Collection
  8379. * @param {Array|Object} collection The collection to iterate over.
  8380. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8381. * @returns {Object} Returns the composed aggregate object.
  8382. * @example
  8383. *
  8384. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8385. * // => { '4': 1, '6': 2 }
  8386. *
  8387. * // The `_.property` iteratee shorthand.
  8388. * _.countBy(['one', 'two', 'three'], 'length');
  8389. * // => { '3': 2, '5': 1 }
  8390. */
  8391. var countBy = createAggregator(function(result, value, key) {
  8392. if (hasOwnProperty.call(result, key)) {
  8393. ++result[key];
  8394. } else {
  8395. baseAssignValue(result, key, 1);
  8396. }
  8397. });
  8398. /**
  8399. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8400. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8401. * invoked with three arguments: (value, index|key, collection).
  8402. *
  8403. * **Note:** This method returns `true` for
  8404. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8405. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8406. * elements of empty collections.
  8407. *
  8408. * @static
  8409. * @memberOf _
  8410. * @since 0.1.0
  8411. * @category Collection
  8412. * @param {Array|Object} collection The collection to iterate over.
  8413. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8414. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8415. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8416. * else `false`.
  8417. * @example
  8418. *
  8419. * _.every([true, 1, null, 'yes'], Boolean);
  8420. * // => false
  8421. *
  8422. * var users = [
  8423. * { 'user': 'barney', 'age': 36, 'active': false },
  8424. * { 'user': 'fred', 'age': 40, 'active': false }
  8425. * ];
  8426. *
  8427. * // The `_.matches` iteratee shorthand.
  8428. * _.every(users, { 'user': 'barney', 'active': false });
  8429. * // => false
  8430. *
  8431. * // The `_.matchesProperty` iteratee shorthand.
  8432. * _.every(users, ['active', false]);
  8433. * // => true
  8434. *
  8435. * // The `_.property` iteratee shorthand.
  8436. * _.every(users, 'active');
  8437. * // => false
  8438. */
  8439. function every(collection, predicate, guard) {
  8440. var func = isArray(collection) ? arrayEvery : baseEvery;
  8441. if (guard && isIterateeCall(collection, predicate, guard)) {
  8442. predicate = undefined;
  8443. }
  8444. return func(collection, getIteratee(predicate, 3));
  8445. }
  8446. /**
  8447. * Iterates over elements of `collection`, returning an array of all elements
  8448. * `predicate` returns truthy for. The predicate is invoked with three
  8449. * arguments: (value, index|key, collection).
  8450. *
  8451. * **Note:** Unlike `_.remove`, this method returns a new array.
  8452. *
  8453. * @static
  8454. * @memberOf _
  8455. * @since 0.1.0
  8456. * @category Collection
  8457. * @param {Array|Object} collection The collection to iterate over.
  8458. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8459. * @returns {Array} Returns the new filtered array.
  8460. * @see _.reject
  8461. * @example
  8462. *
  8463. * var users = [
  8464. * { 'user': 'barney', 'age': 36, 'active': true },
  8465. * { 'user': 'fred', 'age': 40, 'active': false }
  8466. * ];
  8467. *
  8468. * _.filter(users, function(o) { return !o.active; });
  8469. * // => objects for ['fred']
  8470. *
  8471. * // The `_.matches` iteratee shorthand.
  8472. * _.filter(users, { 'age': 36, 'active': true });
  8473. * // => objects for ['barney']
  8474. *
  8475. * // The `_.matchesProperty` iteratee shorthand.
  8476. * _.filter(users, ['active', false]);
  8477. * // => objects for ['fred']
  8478. *
  8479. * // The `_.property` iteratee shorthand.
  8480. * _.filter(users, 'active');
  8481. * // => objects for ['barney']
  8482. */
  8483. function filter(collection, predicate) {
  8484. var func = isArray(collection) ? arrayFilter : baseFilter;
  8485. return func(collection, getIteratee(predicate, 3));
  8486. }
  8487. /**
  8488. * Iterates over elements of `collection`, returning the first element
  8489. * `predicate` returns truthy for. The predicate is invoked with three
  8490. * arguments: (value, index|key, collection).
  8491. *
  8492. * @static
  8493. * @memberOf _
  8494. * @since 0.1.0
  8495. * @category Collection
  8496. * @param {Array|Object} collection The collection to inspect.
  8497. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8498. * @param {number} [fromIndex=0] The index to search from.
  8499. * @returns {*} Returns the matched element, else `undefined`.
  8500. * @example
  8501. *
  8502. * var users = [
  8503. * { 'user': 'barney', 'age': 36, 'active': true },
  8504. * { 'user': 'fred', 'age': 40, 'active': false },
  8505. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8506. * ];
  8507. *
  8508. * _.find(users, function(o) { return o.age < 40; });
  8509. * // => object for 'barney'
  8510. *
  8511. * // The `_.matches` iteratee shorthand.
  8512. * _.find(users, { 'age': 1, 'active': true });
  8513. * // => object for 'pebbles'
  8514. *
  8515. * // The `_.matchesProperty` iteratee shorthand.
  8516. * _.find(users, ['active', false]);
  8517. * // => object for 'fred'
  8518. *
  8519. * // The `_.property` iteratee shorthand.
  8520. * _.find(users, 'active');
  8521. * // => object for 'barney'
  8522. */
  8523. var find = createFind(findIndex);
  8524. /**
  8525. * This method is like `_.find` except that it iterates over elements of
  8526. * `collection` from right to left.
  8527. *
  8528. * @static
  8529. * @memberOf _
  8530. * @since 2.0.0
  8531. * @category Collection
  8532. * @param {Array|Object} collection The collection to inspect.
  8533. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8534. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8535. * @returns {*} Returns the matched element, else `undefined`.
  8536. * @example
  8537. *
  8538. * _.findLast([1, 2, 3, 4], function(n) {
  8539. * return n % 2 == 1;
  8540. * });
  8541. * // => 3
  8542. */
  8543. var findLast = createFind(findLastIndex);
  8544. /**
  8545. * Creates a flattened array of values by running each element in `collection`
  8546. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8547. * with three arguments: (value, index|key, collection).
  8548. *
  8549. * @static
  8550. * @memberOf _
  8551. * @since 4.0.0
  8552. * @category Collection
  8553. * @param {Array|Object} collection The collection to iterate over.
  8554. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8555. * @returns {Array} Returns the new flattened array.
  8556. * @example
  8557. *
  8558. * function duplicate(n) {
  8559. * return [n, n];
  8560. * }
  8561. *
  8562. * _.flatMap([1, 2], duplicate);
  8563. * // => [1, 1, 2, 2]
  8564. */
  8565. function flatMap(collection, iteratee) {
  8566. return baseFlatten(map(collection, iteratee), 1);
  8567. }
  8568. /**
  8569. * This method is like `_.flatMap` except that it recursively flattens the
  8570. * mapped results.
  8571. *
  8572. * @static
  8573. * @memberOf _
  8574. * @since 4.7.0
  8575. * @category Collection
  8576. * @param {Array|Object} collection The collection to iterate over.
  8577. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8578. * @returns {Array} Returns the new flattened array.
  8579. * @example
  8580. *
  8581. * function duplicate(n) {
  8582. * return [[[n, n]]];
  8583. * }
  8584. *
  8585. * _.flatMapDeep([1, 2], duplicate);
  8586. * // => [1, 1, 2, 2]
  8587. */
  8588. function flatMapDeep(collection, iteratee) {
  8589. return baseFlatten(map(collection, iteratee), INFINITY);
  8590. }
  8591. /**
  8592. * This method is like `_.flatMap` except that it recursively flattens the
  8593. * mapped results up to `depth` times.
  8594. *
  8595. * @static
  8596. * @memberOf _
  8597. * @since 4.7.0
  8598. * @category Collection
  8599. * @param {Array|Object} collection The collection to iterate over.
  8600. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8601. * @param {number} [depth=1] The maximum recursion depth.
  8602. * @returns {Array} Returns the new flattened array.
  8603. * @example
  8604. *
  8605. * function duplicate(n) {
  8606. * return [[[n, n]]];
  8607. * }
  8608. *
  8609. * _.flatMapDepth([1, 2], duplicate, 2);
  8610. * // => [[1, 1], [2, 2]]
  8611. */
  8612. function flatMapDepth(collection, iteratee, depth) {
  8613. depth = depth === undefined ? 1 : toInteger(depth);
  8614. return baseFlatten(map(collection, iteratee), depth);
  8615. }
  8616. /**
  8617. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8618. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8619. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8620. *
  8621. * **Note:** As with other "Collections" methods, objects with a "length"
  8622. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8623. * or `_.forOwn` for object iteration.
  8624. *
  8625. * @static
  8626. * @memberOf _
  8627. * @since 0.1.0
  8628. * @alias each
  8629. * @category Collection
  8630. * @param {Array|Object} collection The collection to iterate over.
  8631. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8632. * @returns {Array|Object} Returns `collection`.
  8633. * @see _.forEachRight
  8634. * @example
  8635. *
  8636. * _.forEach([1, 2], function(value) {
  8637. * console.log(value);
  8638. * });
  8639. * // => Logs `1` then `2`.
  8640. *
  8641. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8642. * console.log(key);
  8643. * });
  8644. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8645. */
  8646. function forEach(collection, iteratee) {
  8647. var func = isArray(collection) ? arrayEach : baseEach;
  8648. return func(collection, getIteratee(iteratee, 3));
  8649. }
  8650. /**
  8651. * This method is like `_.forEach` except that it iterates over elements of
  8652. * `collection` from right to left.
  8653. *
  8654. * @static
  8655. * @memberOf _
  8656. * @since 2.0.0
  8657. * @alias eachRight
  8658. * @category Collection
  8659. * @param {Array|Object} collection The collection to iterate over.
  8660. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8661. * @returns {Array|Object} Returns `collection`.
  8662. * @see _.forEach
  8663. * @example
  8664. *
  8665. * _.forEachRight([1, 2], function(value) {
  8666. * console.log(value);
  8667. * });
  8668. * // => Logs `2` then `1`.
  8669. */
  8670. function forEachRight(collection, iteratee) {
  8671. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8672. return func(collection, getIteratee(iteratee, 3));
  8673. }
  8674. /**
  8675. * Creates an object composed of keys generated from the results of running
  8676. * each element of `collection` thru `iteratee`. The order of grouped values
  8677. * is determined by the order they occur in `collection`. The corresponding
  8678. * value of each key is an array of elements responsible for generating the
  8679. * key. The iteratee is invoked with one argument: (value).
  8680. *
  8681. * @static
  8682. * @memberOf _
  8683. * @since 0.1.0
  8684. * @category Collection
  8685. * @param {Array|Object} collection The collection to iterate over.
  8686. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8687. * @returns {Object} Returns the composed aggregate object.
  8688. * @example
  8689. *
  8690. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8691. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8692. *
  8693. * // The `_.property` iteratee shorthand.
  8694. * _.groupBy(['one', 'two', 'three'], 'length');
  8695. * // => { '3': ['one', 'two'], '5': ['three'] }
  8696. */
  8697. var groupBy = createAggregator(function(result, value, key) {
  8698. if (hasOwnProperty.call(result, key)) {
  8699. result[key].push(value);
  8700. } else {
  8701. baseAssignValue(result, key, [value]);
  8702. }
  8703. });
  8704. /**
  8705. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8706. * checked for a substring of `value`, otherwise
  8707. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8708. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8709. * the offset from the end of `collection`.
  8710. *
  8711. * @static
  8712. * @memberOf _
  8713. * @since 0.1.0
  8714. * @category Collection
  8715. * @param {Array|Object|string} collection The collection to inspect.
  8716. * @param {*} value The value to search for.
  8717. * @param {number} [fromIndex=0] The index to search from.
  8718. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8719. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8720. * @example
  8721. *
  8722. * _.includes([1, 2, 3], 1);
  8723. * // => true
  8724. *
  8725. * _.includes([1, 2, 3], 1, 2);
  8726. * // => false
  8727. *
  8728. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8729. * // => true
  8730. *
  8731. * _.includes('abcd', 'bc');
  8732. * // => true
  8733. */
  8734. function includes(collection, value, fromIndex, guard) {
  8735. collection = isArrayLike(collection) ? collection : values(collection);
  8736. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8737. var length = collection.length;
  8738. if (fromIndex < 0) {
  8739. fromIndex = nativeMax(length + fromIndex, 0);
  8740. }
  8741. return isString(collection)
  8742. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8743. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8744. }
  8745. /**
  8746. * Invokes the method at `path` of each element in `collection`, returning
  8747. * an array of the results of each invoked method. Any additional arguments
  8748. * are provided to each invoked method. If `path` is a function, it's invoked
  8749. * for, and `this` bound to, each element in `collection`.
  8750. *
  8751. * @static
  8752. * @memberOf _
  8753. * @since 4.0.0
  8754. * @category Collection
  8755. * @param {Array|Object} collection The collection to iterate over.
  8756. * @param {Array|Function|string} path The path of the method to invoke or
  8757. * the function invoked per iteration.
  8758. * @param {...*} [args] The arguments to invoke each method with.
  8759. * @returns {Array} Returns the array of results.
  8760. * @example
  8761. *
  8762. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8763. * // => [[1, 5, 7], [1, 2, 3]]
  8764. *
  8765. * _.invokeMap([123, 456], String.prototype.split, '');
  8766. * // => [['1', '2', '3'], ['4', '5', '6']]
  8767. */
  8768. var invokeMap = baseRest(function(collection, path, args) {
  8769. var index = -1,
  8770. isFunc = typeof path == 'function',
  8771. result = isArrayLike(collection) ? Array(collection.length) : [];
  8772. baseEach(collection, function(value) {
  8773. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8774. });
  8775. return result;
  8776. });
  8777. /**
  8778. * Creates an object composed of keys generated from the results of running
  8779. * each element of `collection` thru `iteratee`. The corresponding value of
  8780. * each key is the last element responsible for generating the key. The
  8781. * iteratee is invoked with one argument: (value).
  8782. *
  8783. * @static
  8784. * @memberOf _
  8785. * @since 4.0.0
  8786. * @category Collection
  8787. * @param {Array|Object} collection The collection to iterate over.
  8788. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8789. * @returns {Object} Returns the composed aggregate object.
  8790. * @example
  8791. *
  8792. * var array = [
  8793. * { 'dir': 'left', 'code': 97 },
  8794. * { 'dir': 'right', 'code': 100 }
  8795. * ];
  8796. *
  8797. * _.keyBy(array, function(o) {
  8798. * return String.fromCharCode(o.code);
  8799. * });
  8800. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8801. *
  8802. * _.keyBy(array, 'dir');
  8803. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8804. */
  8805. var keyBy = createAggregator(function(result, value, key) {
  8806. baseAssignValue(result, key, value);
  8807. });
  8808. /**
  8809. * Creates an array of values by running each element in `collection` thru
  8810. * `iteratee`. The iteratee is invoked with three arguments:
  8811. * (value, index|key, collection).
  8812. *
  8813. * Many lodash methods are guarded to work as iteratees for methods like
  8814. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8815. *
  8816. * The guarded methods are:
  8817. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8818. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8819. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8820. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8821. *
  8822. * @static
  8823. * @memberOf _
  8824. * @since 0.1.0
  8825. * @category Collection
  8826. * @param {Array|Object} collection The collection to iterate over.
  8827. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8828. * @returns {Array} Returns the new mapped array.
  8829. * @example
  8830. *
  8831. * function square(n) {
  8832. * return n * n;
  8833. * }
  8834. *
  8835. * _.map([4, 8], square);
  8836. * // => [16, 64]
  8837. *
  8838. * _.map({ 'a': 4, 'b': 8 }, square);
  8839. * // => [16, 64] (iteration order is not guaranteed)
  8840. *
  8841. * var users = [
  8842. * { 'user': 'barney' },
  8843. * { 'user': 'fred' }
  8844. * ];
  8845. *
  8846. * // The `_.property` iteratee shorthand.
  8847. * _.map(users, 'user');
  8848. * // => ['barney', 'fred']
  8849. */
  8850. function map(collection, iteratee) {
  8851. var func = isArray(collection) ? arrayMap : baseMap;
  8852. return func(collection, getIteratee(iteratee, 3));
  8853. }
  8854. /**
  8855. * This method is like `_.sortBy` except that it allows specifying the sort
  8856. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8857. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8858. * descending or "asc" for ascending sort order of corresponding values.
  8859. *
  8860. * @static
  8861. * @memberOf _
  8862. * @since 4.0.0
  8863. * @category Collection
  8864. * @param {Array|Object} collection The collection to iterate over.
  8865. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8866. * The iteratees to sort by.
  8867. * @param {string[]} [orders] The sort orders of `iteratees`.
  8868. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8869. * @returns {Array} Returns the new sorted array.
  8870. * @example
  8871. *
  8872. * var users = [
  8873. * { 'user': 'fred', 'age': 48 },
  8874. * { 'user': 'barney', 'age': 34 },
  8875. * { 'user': 'fred', 'age': 40 },
  8876. * { 'user': 'barney', 'age': 36 }
  8877. * ];
  8878. *
  8879. * // Sort by `user` in ascending order and by `age` in descending order.
  8880. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8881. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8882. */
  8883. function orderBy(collection, iteratees, orders, guard) {
  8884. if (collection == null) {
  8885. return [];
  8886. }
  8887. if (!isArray(iteratees)) {
  8888. iteratees = iteratees == null ? [] : [iteratees];
  8889. }
  8890. orders = guard ? undefined : orders;
  8891. if (!isArray(orders)) {
  8892. orders = orders == null ? [] : [orders];
  8893. }
  8894. return baseOrderBy(collection, iteratees, orders);
  8895. }
  8896. /**
  8897. * Creates an array of elements split into two groups, the first of which
  8898. * contains elements `predicate` returns truthy for, the second of which
  8899. * contains elements `predicate` returns falsey for. The predicate is
  8900. * invoked with one argument: (value).
  8901. *
  8902. * @static
  8903. * @memberOf _
  8904. * @since 3.0.0
  8905. * @category Collection
  8906. * @param {Array|Object} collection The collection to iterate over.
  8907. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8908. * @returns {Array} Returns the array of grouped elements.
  8909. * @example
  8910. *
  8911. * var users = [
  8912. * { 'user': 'barney', 'age': 36, 'active': false },
  8913. * { 'user': 'fred', 'age': 40, 'active': true },
  8914. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8915. * ];
  8916. *
  8917. * _.partition(users, function(o) { return o.active; });
  8918. * // => objects for [['fred'], ['barney', 'pebbles']]
  8919. *
  8920. * // The `_.matches` iteratee shorthand.
  8921. * _.partition(users, { 'age': 1, 'active': false });
  8922. * // => objects for [['pebbles'], ['barney', 'fred']]
  8923. *
  8924. * // The `_.matchesProperty` iteratee shorthand.
  8925. * _.partition(users, ['active', false]);
  8926. * // => objects for [['barney', 'pebbles'], ['fred']]
  8927. *
  8928. * // The `_.property` iteratee shorthand.
  8929. * _.partition(users, 'active');
  8930. * // => objects for [['fred'], ['barney', 'pebbles']]
  8931. */
  8932. var partition = createAggregator(function(result, value, key) {
  8933. result[key ? 0 : 1].push(value);
  8934. }, function() { return [[], []]; });
  8935. /**
  8936. * Reduces `collection` to a value which is the accumulated result of running
  8937. * each element in `collection` thru `iteratee`, where each successive
  8938. * invocation is supplied the return value of the previous. If `accumulator`
  8939. * is not given, the first element of `collection` is used as the initial
  8940. * value. The iteratee is invoked with four arguments:
  8941. * (accumulator, value, index|key, collection).
  8942. *
  8943. * Many lodash methods are guarded to work as iteratees for methods like
  8944. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8945. *
  8946. * The guarded methods are:
  8947. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8948. * and `sortBy`
  8949. *
  8950. * @static
  8951. * @memberOf _
  8952. * @since 0.1.0
  8953. * @category Collection
  8954. * @param {Array|Object} collection The collection to iterate over.
  8955. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8956. * @param {*} [accumulator] The initial value.
  8957. * @returns {*} Returns the accumulated value.
  8958. * @see _.reduceRight
  8959. * @example
  8960. *
  8961. * _.reduce([1, 2], function(sum, n) {
  8962. * return sum + n;
  8963. * }, 0);
  8964. * // => 3
  8965. *
  8966. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8967. * (result[value] || (result[value] = [])).push(key);
  8968. * return result;
  8969. * }, {});
  8970. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8971. */
  8972. function reduce(collection, iteratee, accumulator) {
  8973. var func = isArray(collection) ? arrayReduce : baseReduce,
  8974. initAccum = arguments.length < 3;
  8975. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8976. }
  8977. /**
  8978. * This method is like `_.reduce` except that it iterates over elements of
  8979. * `collection` from right to left.
  8980. *
  8981. * @static
  8982. * @memberOf _
  8983. * @since 0.1.0
  8984. * @category Collection
  8985. * @param {Array|Object} collection The collection to iterate over.
  8986. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8987. * @param {*} [accumulator] The initial value.
  8988. * @returns {*} Returns the accumulated value.
  8989. * @see _.reduce
  8990. * @example
  8991. *
  8992. * var array = [[0, 1], [2, 3], [4, 5]];
  8993. *
  8994. * _.reduceRight(array, function(flattened, other) {
  8995. * return flattened.concat(other);
  8996. * }, []);
  8997. * // => [4, 5, 2, 3, 0, 1]
  8998. */
  8999. function reduceRight(collection, iteratee, accumulator) {
  9000. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9001. initAccum = arguments.length < 3;
  9002. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9003. }
  9004. /**
  9005. * The opposite of `_.filter`; this method returns the elements of `collection`
  9006. * that `predicate` does **not** return truthy for.
  9007. *
  9008. * @static
  9009. * @memberOf _
  9010. * @since 0.1.0
  9011. * @category Collection
  9012. * @param {Array|Object} collection The collection to iterate over.
  9013. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9014. * @returns {Array} Returns the new filtered array.
  9015. * @see _.filter
  9016. * @example
  9017. *
  9018. * var users = [
  9019. * { 'user': 'barney', 'age': 36, 'active': false },
  9020. * { 'user': 'fred', 'age': 40, 'active': true }
  9021. * ];
  9022. *
  9023. * _.reject(users, function(o) { return !o.active; });
  9024. * // => objects for ['fred']
  9025. *
  9026. * // The `_.matches` iteratee shorthand.
  9027. * _.reject(users, { 'age': 40, 'active': true });
  9028. * // => objects for ['barney']
  9029. *
  9030. * // The `_.matchesProperty` iteratee shorthand.
  9031. * _.reject(users, ['active', false]);
  9032. * // => objects for ['fred']
  9033. *
  9034. * // The `_.property` iteratee shorthand.
  9035. * _.reject(users, 'active');
  9036. * // => objects for ['barney']
  9037. */
  9038. function reject(collection, predicate) {
  9039. var func = isArray(collection) ? arrayFilter : baseFilter;
  9040. return func(collection, negate(getIteratee(predicate, 3)));
  9041. }
  9042. /**
  9043. * Gets a random element from `collection`.
  9044. *
  9045. * @static
  9046. * @memberOf _
  9047. * @since 2.0.0
  9048. * @category Collection
  9049. * @param {Array|Object} collection The collection to sample.
  9050. * @returns {*} Returns the random element.
  9051. * @example
  9052. *
  9053. * _.sample([1, 2, 3, 4]);
  9054. * // => 2
  9055. */
  9056. function sample(collection) {
  9057. var func = isArray(collection) ? arraySample : baseSample;
  9058. return func(collection);
  9059. }
  9060. /**
  9061. * Gets `n` random elements at unique keys from `collection` up to the
  9062. * size of `collection`.
  9063. *
  9064. * @static
  9065. * @memberOf _
  9066. * @since 4.0.0
  9067. * @category Collection
  9068. * @param {Array|Object} collection The collection to sample.
  9069. * @param {number} [n=1] The number of elements to sample.
  9070. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9071. * @returns {Array} Returns the random elements.
  9072. * @example
  9073. *
  9074. * _.sampleSize([1, 2, 3], 2);
  9075. * // => [3, 1]
  9076. *
  9077. * _.sampleSize([1, 2, 3], 4);
  9078. * // => [2, 3, 1]
  9079. */
  9080. function sampleSize(collection, n, guard) {
  9081. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9082. n = 1;
  9083. } else {
  9084. n = toInteger(n);
  9085. }
  9086. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9087. return func(collection, n);
  9088. }
  9089. /**
  9090. * Creates an array of shuffled values, using a version of the
  9091. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9092. *
  9093. * @static
  9094. * @memberOf _
  9095. * @since 0.1.0
  9096. * @category Collection
  9097. * @param {Array|Object} collection The collection to shuffle.
  9098. * @returns {Array} Returns the new shuffled array.
  9099. * @example
  9100. *
  9101. * _.shuffle([1, 2, 3, 4]);
  9102. * // => [4, 1, 3, 2]
  9103. */
  9104. function shuffle(collection) {
  9105. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9106. return func(collection);
  9107. }
  9108. /**
  9109. * Gets the size of `collection` by returning its length for array-like
  9110. * values or the number of own enumerable string keyed properties for objects.
  9111. *
  9112. * @static
  9113. * @memberOf _
  9114. * @since 0.1.0
  9115. * @category Collection
  9116. * @param {Array|Object|string} collection The collection to inspect.
  9117. * @returns {number} Returns the collection size.
  9118. * @example
  9119. *
  9120. * _.size([1, 2, 3]);
  9121. * // => 3
  9122. *
  9123. * _.size({ 'a': 1, 'b': 2 });
  9124. * // => 2
  9125. *
  9126. * _.size('pebbles');
  9127. * // => 7
  9128. */
  9129. function size(collection) {
  9130. if (collection == null) {
  9131. return 0;
  9132. }
  9133. if (isArrayLike(collection)) {
  9134. return isString(collection) ? stringSize(collection) : collection.length;
  9135. }
  9136. var tag = getTag(collection);
  9137. if (tag == mapTag || tag == setTag) {
  9138. return collection.size;
  9139. }
  9140. return baseKeys(collection).length;
  9141. }
  9142. /**
  9143. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9144. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9145. * invoked with three arguments: (value, index|key, collection).
  9146. *
  9147. * @static
  9148. * @memberOf _
  9149. * @since 0.1.0
  9150. * @category Collection
  9151. * @param {Array|Object} collection The collection to iterate over.
  9152. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9153. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9154. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9155. * else `false`.
  9156. * @example
  9157. *
  9158. * _.some([null, 0, 'yes', false], Boolean);
  9159. * // => true
  9160. *
  9161. * var users = [
  9162. * { 'user': 'barney', 'active': true },
  9163. * { 'user': 'fred', 'active': false }
  9164. * ];
  9165. *
  9166. * // The `_.matches` iteratee shorthand.
  9167. * _.some(users, { 'user': 'barney', 'active': false });
  9168. * // => false
  9169. *
  9170. * // The `_.matchesProperty` iteratee shorthand.
  9171. * _.some(users, ['active', false]);
  9172. * // => true
  9173. *
  9174. * // The `_.property` iteratee shorthand.
  9175. * _.some(users, 'active');
  9176. * // => true
  9177. */
  9178. function some(collection, predicate, guard) {
  9179. var func = isArray(collection) ? arraySome : baseSome;
  9180. if (guard && isIterateeCall(collection, predicate, guard)) {
  9181. predicate = undefined;
  9182. }
  9183. return func(collection, getIteratee(predicate, 3));
  9184. }
  9185. /**
  9186. * Creates an array of elements, sorted in ascending order by the results of
  9187. * running each element in a collection thru each iteratee. This method
  9188. * performs a stable sort, that is, it preserves the original sort order of
  9189. * equal elements. The iteratees are invoked with one argument: (value).
  9190. *
  9191. * @static
  9192. * @memberOf _
  9193. * @since 0.1.0
  9194. * @category Collection
  9195. * @param {Array|Object} collection The collection to iterate over.
  9196. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9197. * The iteratees to sort by.
  9198. * @returns {Array} Returns the new sorted array.
  9199. * @example
  9200. *
  9201. * var users = [
  9202. * { 'user': 'fred', 'age': 48 },
  9203. * { 'user': 'barney', 'age': 36 },
  9204. * { 'user': 'fred', 'age': 40 },
  9205. * { 'user': 'barney', 'age': 34 }
  9206. * ];
  9207. *
  9208. * _.sortBy(users, [function(o) { return o.user; }]);
  9209. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9210. *
  9211. * _.sortBy(users, ['user', 'age']);
  9212. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9213. */
  9214. var sortBy = baseRest(function(collection, iteratees) {
  9215. if (collection == null) {
  9216. return [];
  9217. }
  9218. var length = iteratees.length;
  9219. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9220. iteratees = [];
  9221. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9222. iteratees = [iteratees[0]];
  9223. }
  9224. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9225. });
  9226. /*------------------------------------------------------------------------*/
  9227. /**
  9228. * Gets the timestamp of the number of milliseconds that have elapsed since
  9229. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9230. *
  9231. * @static
  9232. * @memberOf _
  9233. * @since 2.4.0
  9234. * @category Date
  9235. * @returns {number} Returns the timestamp.
  9236. * @example
  9237. *
  9238. * _.defer(function(stamp) {
  9239. * console.log(_.now() - stamp);
  9240. * }, _.now());
  9241. * // => Logs the number of milliseconds it took for the deferred invocation.
  9242. */
  9243. var now = ctxNow || function() {
  9244. return root.Date.now();
  9245. };
  9246. /*------------------------------------------------------------------------*/
  9247. /**
  9248. * The opposite of `_.before`; this method creates a function that invokes
  9249. * `func` once it's called `n` or more times.
  9250. *
  9251. * @static
  9252. * @memberOf _
  9253. * @since 0.1.0
  9254. * @category Function
  9255. * @param {number} n The number of calls before `func` is invoked.
  9256. * @param {Function} func The function to restrict.
  9257. * @returns {Function} Returns the new restricted function.
  9258. * @example
  9259. *
  9260. * var saves = ['profile', 'settings'];
  9261. *
  9262. * var done = _.after(saves.length, function() {
  9263. * console.log('done saving!');
  9264. * });
  9265. *
  9266. * _.forEach(saves, function(type) {
  9267. * asyncSave({ 'type': type, 'complete': done });
  9268. * });
  9269. * // => Logs 'done saving!' after the two async saves have completed.
  9270. */
  9271. function after(n, func) {
  9272. if (typeof func != 'function') {
  9273. throw new TypeError(FUNC_ERROR_TEXT);
  9274. }
  9275. n = toInteger(n);
  9276. return function() {
  9277. if (--n < 1) {
  9278. return func.apply(this, arguments);
  9279. }
  9280. };
  9281. }
  9282. /**
  9283. * Creates a function that invokes `func`, with up to `n` arguments,
  9284. * ignoring any additional arguments.
  9285. *
  9286. * @static
  9287. * @memberOf _
  9288. * @since 3.0.0
  9289. * @category Function
  9290. * @param {Function} func The function to cap arguments for.
  9291. * @param {number} [n=func.length] The arity cap.
  9292. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9293. * @returns {Function} Returns the new capped function.
  9294. * @example
  9295. *
  9296. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9297. * // => [6, 8, 10]
  9298. */
  9299. function ary(func, n, guard) {
  9300. n = guard ? undefined : n;
  9301. n = (func && n == null) ? func.length : n;
  9302. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9303. }
  9304. /**
  9305. * Creates a function that invokes `func`, with the `this` binding and arguments
  9306. * of the created function, while it's called less than `n` times. Subsequent
  9307. * calls to the created function return the result of the last `func` invocation.
  9308. *
  9309. * @static
  9310. * @memberOf _
  9311. * @since 3.0.0
  9312. * @category Function
  9313. * @param {number} n The number of calls at which `func` is no longer invoked.
  9314. * @param {Function} func The function to restrict.
  9315. * @returns {Function} Returns the new restricted function.
  9316. * @example
  9317. *
  9318. * jQuery(element).on('click', _.before(5, addContactToList));
  9319. * // => Allows adding up to 4 contacts to the list.
  9320. */
  9321. function before(n, func) {
  9322. var result;
  9323. if (typeof func != 'function') {
  9324. throw new TypeError(FUNC_ERROR_TEXT);
  9325. }
  9326. n = toInteger(n);
  9327. return function() {
  9328. if (--n > 0) {
  9329. result = func.apply(this, arguments);
  9330. }
  9331. if (n <= 1) {
  9332. func = undefined;
  9333. }
  9334. return result;
  9335. };
  9336. }
  9337. /**
  9338. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9339. * and `partials` prepended to the arguments it receives.
  9340. *
  9341. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9342. * may be used as a placeholder for partially applied arguments.
  9343. *
  9344. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9345. * property of bound functions.
  9346. *
  9347. * @static
  9348. * @memberOf _
  9349. * @since 0.1.0
  9350. * @category Function
  9351. * @param {Function} func The function to bind.
  9352. * @param {*} thisArg The `this` binding of `func`.
  9353. * @param {...*} [partials] The arguments to be partially applied.
  9354. * @returns {Function} Returns the new bound function.
  9355. * @example
  9356. *
  9357. * function greet(greeting, punctuation) {
  9358. * return greeting + ' ' + this.user + punctuation;
  9359. * }
  9360. *
  9361. * var object = { 'user': 'fred' };
  9362. *
  9363. * var bound = _.bind(greet, object, 'hi');
  9364. * bound('!');
  9365. * // => 'hi fred!'
  9366. *
  9367. * // Bound with placeholders.
  9368. * var bound = _.bind(greet, object, _, '!');
  9369. * bound('hi');
  9370. * // => 'hi fred!'
  9371. */
  9372. var bind = baseRest(function(func, thisArg, partials) {
  9373. var bitmask = WRAP_BIND_FLAG;
  9374. if (partials.length) {
  9375. var holders = replaceHolders(partials, getHolder(bind));
  9376. bitmask |= WRAP_PARTIAL_FLAG;
  9377. }
  9378. return createWrap(func, bitmask, thisArg, partials, holders);
  9379. });
  9380. /**
  9381. * Creates a function that invokes the method at `object[key]` with `partials`
  9382. * prepended to the arguments it receives.
  9383. *
  9384. * This method differs from `_.bind` by allowing bound functions to reference
  9385. * methods that may be redefined or don't yet exist. See
  9386. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9387. * for more details.
  9388. *
  9389. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9390. * builds, may be used as a placeholder for partially applied arguments.
  9391. *
  9392. * @static
  9393. * @memberOf _
  9394. * @since 0.10.0
  9395. * @category Function
  9396. * @param {Object} object The object to invoke the method on.
  9397. * @param {string} key The key of the method.
  9398. * @param {...*} [partials] The arguments to be partially applied.
  9399. * @returns {Function} Returns the new bound function.
  9400. * @example
  9401. *
  9402. * var object = {
  9403. * 'user': 'fred',
  9404. * 'greet': function(greeting, punctuation) {
  9405. * return greeting + ' ' + this.user + punctuation;
  9406. * }
  9407. * };
  9408. *
  9409. * var bound = _.bindKey(object, 'greet', 'hi');
  9410. * bound('!');
  9411. * // => 'hi fred!'
  9412. *
  9413. * object.greet = function(greeting, punctuation) {
  9414. * return greeting + 'ya ' + this.user + punctuation;
  9415. * };
  9416. *
  9417. * bound('!');
  9418. * // => 'hiya fred!'
  9419. *
  9420. * // Bound with placeholders.
  9421. * var bound = _.bindKey(object, 'greet', _, '!');
  9422. * bound('hi');
  9423. * // => 'hiya fred!'
  9424. */
  9425. var bindKey = baseRest(function(object, key, partials) {
  9426. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9427. if (partials.length) {
  9428. var holders = replaceHolders(partials, getHolder(bindKey));
  9429. bitmask |= WRAP_PARTIAL_FLAG;
  9430. }
  9431. return createWrap(key, bitmask, object, partials, holders);
  9432. });
  9433. /**
  9434. * Creates a function that accepts arguments of `func` and either invokes
  9435. * `func` returning its result, if at least `arity` number of arguments have
  9436. * been provided, or returns a function that accepts the remaining `func`
  9437. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9438. * is not sufficient.
  9439. *
  9440. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9441. * may be used as a placeholder for provided arguments.
  9442. *
  9443. * **Note:** This method doesn't set the "length" property of curried functions.
  9444. *
  9445. * @static
  9446. * @memberOf _
  9447. * @since 2.0.0
  9448. * @category Function
  9449. * @param {Function} func The function to curry.
  9450. * @param {number} [arity=func.length] The arity of `func`.
  9451. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9452. * @returns {Function} Returns the new curried function.
  9453. * @example
  9454. *
  9455. * var abc = function(a, b, c) {
  9456. * return [a, b, c];
  9457. * };
  9458. *
  9459. * var curried = _.curry(abc);
  9460. *
  9461. * curried(1)(2)(3);
  9462. * // => [1, 2, 3]
  9463. *
  9464. * curried(1, 2)(3);
  9465. * // => [1, 2, 3]
  9466. *
  9467. * curried(1, 2, 3);
  9468. * // => [1, 2, 3]
  9469. *
  9470. * // Curried with placeholders.
  9471. * curried(1)(_, 3)(2);
  9472. * // => [1, 2, 3]
  9473. */
  9474. function curry(func, arity, guard) {
  9475. arity = guard ? undefined : arity;
  9476. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9477. result.placeholder = curry.placeholder;
  9478. return result;
  9479. }
  9480. /**
  9481. * This method is like `_.curry` except that arguments are applied to `func`
  9482. * in the manner of `_.partialRight` instead of `_.partial`.
  9483. *
  9484. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9485. * builds, may be used as a placeholder for provided arguments.
  9486. *
  9487. * **Note:** This method doesn't set the "length" property of curried functions.
  9488. *
  9489. * @static
  9490. * @memberOf _
  9491. * @since 3.0.0
  9492. * @category Function
  9493. * @param {Function} func The function to curry.
  9494. * @param {number} [arity=func.length] The arity of `func`.
  9495. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9496. * @returns {Function} Returns the new curried function.
  9497. * @example
  9498. *
  9499. * var abc = function(a, b, c) {
  9500. * return [a, b, c];
  9501. * };
  9502. *
  9503. * var curried = _.curryRight(abc);
  9504. *
  9505. * curried(3)(2)(1);
  9506. * // => [1, 2, 3]
  9507. *
  9508. * curried(2, 3)(1);
  9509. * // => [1, 2, 3]
  9510. *
  9511. * curried(1, 2, 3);
  9512. * // => [1, 2, 3]
  9513. *
  9514. * // Curried with placeholders.
  9515. * curried(3)(1, _)(2);
  9516. * // => [1, 2, 3]
  9517. */
  9518. function curryRight(func, arity, guard) {
  9519. arity = guard ? undefined : arity;
  9520. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9521. result.placeholder = curryRight.placeholder;
  9522. return result;
  9523. }
  9524. /**
  9525. * Creates a debounced function that delays invoking `func` until after `wait`
  9526. * milliseconds have elapsed since the last time the debounced function was
  9527. * invoked. The debounced function comes with a `cancel` method to cancel
  9528. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9529. * Provide `options` to indicate whether `func` should be invoked on the
  9530. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9531. * with the last arguments provided to the debounced function. Subsequent
  9532. * calls to the debounced function return the result of the last `func`
  9533. * invocation.
  9534. *
  9535. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9536. * invoked on the trailing edge of the timeout only if the debounced function
  9537. * is invoked more than once during the `wait` timeout.
  9538. *
  9539. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9540. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9541. *
  9542. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9543. * for details over the differences between `_.debounce` and `_.throttle`.
  9544. *
  9545. * @static
  9546. * @memberOf _
  9547. * @since 0.1.0
  9548. * @category Function
  9549. * @param {Function} func The function to debounce.
  9550. * @param {number} [wait=0] The number of milliseconds to delay.
  9551. * @param {Object} [options={}] The options object.
  9552. * @param {boolean} [options.leading=false]
  9553. * Specify invoking on the leading edge of the timeout.
  9554. * @param {number} [options.maxWait]
  9555. * The maximum time `func` is allowed to be delayed before it's invoked.
  9556. * @param {boolean} [options.trailing=true]
  9557. * Specify invoking on the trailing edge of the timeout.
  9558. * @returns {Function} Returns the new debounced function.
  9559. * @example
  9560. *
  9561. * // Avoid costly calculations while the window size is in flux.
  9562. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9563. *
  9564. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9565. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9566. * 'leading': true,
  9567. * 'trailing': false
  9568. * }));
  9569. *
  9570. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9571. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9572. * var source = new EventSource('/stream');
  9573. * jQuery(source).on('message', debounced);
  9574. *
  9575. * // Cancel the trailing debounced invocation.
  9576. * jQuery(window).on('popstate', debounced.cancel);
  9577. */
  9578. function debounce(func, wait, options) {
  9579. var lastArgs,
  9580. lastThis,
  9581. maxWait,
  9582. result,
  9583. timerId,
  9584. lastCallTime,
  9585. lastInvokeTime = 0,
  9586. leading = false,
  9587. maxing = false,
  9588. trailing = true;
  9589. if (typeof func != 'function') {
  9590. throw new TypeError(FUNC_ERROR_TEXT);
  9591. }
  9592. wait = toNumber(wait) || 0;
  9593. if (isObject(options)) {
  9594. leading = !!options.leading;
  9595. maxing = 'maxWait' in options;
  9596. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9597. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9598. }
  9599. function invokeFunc(time) {
  9600. var args = lastArgs,
  9601. thisArg = lastThis;
  9602. lastArgs = lastThis = undefined;
  9603. lastInvokeTime = time;
  9604. result = func.apply(thisArg, args);
  9605. return result;
  9606. }
  9607. function leadingEdge(time) {
  9608. // Reset any `maxWait` timer.
  9609. lastInvokeTime = time;
  9610. // Start the timer for the trailing edge.
  9611. timerId = setTimeout(timerExpired, wait);
  9612. // Invoke the leading edge.
  9613. return leading ? invokeFunc(time) : result;
  9614. }
  9615. function remainingWait(time) {
  9616. var timeSinceLastCall = time - lastCallTime,
  9617. timeSinceLastInvoke = time - lastInvokeTime,
  9618. timeWaiting = wait - timeSinceLastCall;
  9619. return maxing
  9620. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9621. : timeWaiting;
  9622. }
  9623. function shouldInvoke(time) {
  9624. var timeSinceLastCall = time - lastCallTime,
  9625. timeSinceLastInvoke = time - lastInvokeTime;
  9626. // Either this is the first call, activity has stopped and we're at the
  9627. // trailing edge, the system time has gone backwards and we're treating
  9628. // it as the trailing edge, or we've hit the `maxWait` limit.
  9629. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9630. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9631. }
  9632. function timerExpired() {
  9633. var time = now();
  9634. if (shouldInvoke(time)) {
  9635. return trailingEdge(time);
  9636. }
  9637. // Restart the timer.
  9638. timerId = setTimeout(timerExpired, remainingWait(time));
  9639. }
  9640. function trailingEdge(time) {
  9641. timerId = undefined;
  9642. // Only invoke if we have `lastArgs` which means `func` has been
  9643. // debounced at least once.
  9644. if (trailing && lastArgs) {
  9645. return invokeFunc(time);
  9646. }
  9647. lastArgs = lastThis = undefined;
  9648. return result;
  9649. }
  9650. function cancel() {
  9651. if (timerId !== undefined) {
  9652. clearTimeout(timerId);
  9653. }
  9654. lastInvokeTime = 0;
  9655. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9656. }
  9657. function flush() {
  9658. return timerId === undefined ? result : trailingEdge(now());
  9659. }
  9660. function debounced() {
  9661. var time = now(),
  9662. isInvoking = shouldInvoke(time);
  9663. lastArgs = arguments;
  9664. lastThis = this;
  9665. lastCallTime = time;
  9666. if (isInvoking) {
  9667. if (timerId === undefined) {
  9668. return leadingEdge(lastCallTime);
  9669. }
  9670. if (maxing) {
  9671. // Handle invocations in a tight loop.
  9672. timerId = setTimeout(timerExpired, wait);
  9673. return invokeFunc(lastCallTime);
  9674. }
  9675. }
  9676. if (timerId === undefined) {
  9677. timerId = setTimeout(timerExpired, wait);
  9678. }
  9679. return result;
  9680. }
  9681. debounced.cancel = cancel;
  9682. debounced.flush = flush;
  9683. return debounced;
  9684. }
  9685. /**
  9686. * Defers invoking the `func` until the current call stack has cleared. Any
  9687. * additional arguments are provided to `func` when it's invoked.
  9688. *
  9689. * @static
  9690. * @memberOf _
  9691. * @since 0.1.0
  9692. * @category Function
  9693. * @param {Function} func The function to defer.
  9694. * @param {...*} [args] The arguments to invoke `func` with.
  9695. * @returns {number} Returns the timer id.
  9696. * @example
  9697. *
  9698. * _.defer(function(text) {
  9699. * console.log(text);
  9700. * }, 'deferred');
  9701. * // => Logs 'deferred' after one millisecond.
  9702. */
  9703. var defer = baseRest(function(func, args) {
  9704. return baseDelay(func, 1, args);
  9705. });
  9706. /**
  9707. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9708. * provided to `func` when it's invoked.
  9709. *
  9710. * @static
  9711. * @memberOf _
  9712. * @since 0.1.0
  9713. * @category Function
  9714. * @param {Function} func The function to delay.
  9715. * @param {number} wait The number of milliseconds to delay invocation.
  9716. * @param {...*} [args] The arguments to invoke `func` with.
  9717. * @returns {number} Returns the timer id.
  9718. * @example
  9719. *
  9720. * _.delay(function(text) {
  9721. * console.log(text);
  9722. * }, 1000, 'later');
  9723. * // => Logs 'later' after one second.
  9724. */
  9725. var delay = baseRest(function(func, wait, args) {
  9726. return baseDelay(func, toNumber(wait) || 0, args);
  9727. });
  9728. /**
  9729. * Creates a function that invokes `func` with arguments reversed.
  9730. *
  9731. * @static
  9732. * @memberOf _
  9733. * @since 4.0.0
  9734. * @category Function
  9735. * @param {Function} func The function to flip arguments for.
  9736. * @returns {Function} Returns the new flipped function.
  9737. * @example
  9738. *
  9739. * var flipped = _.flip(function() {
  9740. * return _.toArray(arguments);
  9741. * });
  9742. *
  9743. * flipped('a', 'b', 'c', 'd');
  9744. * // => ['d', 'c', 'b', 'a']
  9745. */
  9746. function flip(func) {
  9747. return createWrap(func, WRAP_FLIP_FLAG);
  9748. }
  9749. /**
  9750. * Creates a function that memoizes the result of `func`. If `resolver` is
  9751. * provided, it determines the cache key for storing the result based on the
  9752. * arguments provided to the memoized function. By default, the first argument
  9753. * provided to the memoized function is used as the map cache key. The `func`
  9754. * is invoked with the `this` binding of the memoized function.
  9755. *
  9756. * **Note:** The cache is exposed as the `cache` property on the memoized
  9757. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9758. * constructor with one whose instances implement the
  9759. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9760. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9761. *
  9762. * @static
  9763. * @memberOf _
  9764. * @since 0.1.0
  9765. * @category Function
  9766. * @param {Function} func The function to have its output memoized.
  9767. * @param {Function} [resolver] The function to resolve the cache key.
  9768. * @returns {Function} Returns the new memoized function.
  9769. * @example
  9770. *
  9771. * var object = { 'a': 1, 'b': 2 };
  9772. * var other = { 'c': 3, 'd': 4 };
  9773. *
  9774. * var values = _.memoize(_.values);
  9775. * values(object);
  9776. * // => [1, 2]
  9777. *
  9778. * values(other);
  9779. * // => [3, 4]
  9780. *
  9781. * object.a = 2;
  9782. * values(object);
  9783. * // => [1, 2]
  9784. *
  9785. * // Modify the result cache.
  9786. * values.cache.set(object, ['a', 'b']);
  9787. * values(object);
  9788. * // => ['a', 'b']
  9789. *
  9790. * // Replace `_.memoize.Cache`.
  9791. * _.memoize.Cache = WeakMap;
  9792. */
  9793. function memoize(func, resolver) {
  9794. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9795. throw new TypeError(FUNC_ERROR_TEXT);
  9796. }
  9797. var memoized = function() {
  9798. var args = arguments,
  9799. key = resolver ? resolver.apply(this, args) : args[0],
  9800. cache = memoized.cache;
  9801. if (cache.has(key)) {
  9802. return cache.get(key);
  9803. }
  9804. var result = func.apply(this, args);
  9805. memoized.cache = cache.set(key, result) || cache;
  9806. return result;
  9807. };
  9808. memoized.cache = new (memoize.Cache || MapCache);
  9809. return memoized;
  9810. }
  9811. // Expose `MapCache`.
  9812. memoize.Cache = MapCache;
  9813. /**
  9814. * Creates a function that negates the result of the predicate `func`. The
  9815. * `func` predicate is invoked with the `this` binding and arguments of the
  9816. * created function.
  9817. *
  9818. * @static
  9819. * @memberOf _
  9820. * @since 3.0.0
  9821. * @category Function
  9822. * @param {Function} predicate The predicate to negate.
  9823. * @returns {Function} Returns the new negated function.
  9824. * @example
  9825. *
  9826. * function isEven(n) {
  9827. * return n % 2 == 0;
  9828. * }
  9829. *
  9830. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9831. * // => [1, 3, 5]
  9832. */
  9833. function negate(predicate) {
  9834. if (typeof predicate != 'function') {
  9835. throw new TypeError(FUNC_ERROR_TEXT);
  9836. }
  9837. return function() {
  9838. var args = arguments;
  9839. switch (args.length) {
  9840. case 0: return !predicate.call(this);
  9841. case 1: return !predicate.call(this, args[0]);
  9842. case 2: return !predicate.call(this, args[0], args[1]);
  9843. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9844. }
  9845. return !predicate.apply(this, args);
  9846. };
  9847. }
  9848. /**
  9849. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9850. * to the function return the value of the first invocation. The `func` is
  9851. * invoked with the `this` binding and arguments of the created function.
  9852. *
  9853. * @static
  9854. * @memberOf _
  9855. * @since 0.1.0
  9856. * @category Function
  9857. * @param {Function} func The function to restrict.
  9858. * @returns {Function} Returns the new restricted function.
  9859. * @example
  9860. *
  9861. * var initialize = _.once(createApplication);
  9862. * initialize();
  9863. * initialize();
  9864. * // => `createApplication` is invoked once
  9865. */
  9866. function once(func) {
  9867. return before(2, func);
  9868. }
  9869. /**
  9870. * Creates a function that invokes `func` with its arguments transformed.
  9871. *
  9872. * @static
  9873. * @since 4.0.0
  9874. * @memberOf _
  9875. * @category Function
  9876. * @param {Function} func The function to wrap.
  9877. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9878. * The argument transforms.
  9879. * @returns {Function} Returns the new function.
  9880. * @example
  9881. *
  9882. * function doubled(n) {
  9883. * return n * 2;
  9884. * }
  9885. *
  9886. * function square(n) {
  9887. * return n * n;
  9888. * }
  9889. *
  9890. * var func = _.overArgs(function(x, y) {
  9891. * return [x, y];
  9892. * }, [square, doubled]);
  9893. *
  9894. * func(9, 3);
  9895. * // => [81, 6]
  9896. *
  9897. * func(10, 5);
  9898. * // => [100, 10]
  9899. */
  9900. var overArgs = castRest(function(func, transforms) {
  9901. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9902. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9903. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9904. var funcsLength = transforms.length;
  9905. return baseRest(function(args) {
  9906. var index = -1,
  9907. length = nativeMin(args.length, funcsLength);
  9908. while (++index < length) {
  9909. args[index] = transforms[index].call(this, args[index]);
  9910. }
  9911. return apply(func, this, args);
  9912. });
  9913. });
  9914. /**
  9915. * Creates a function that invokes `func` with `partials` prepended to the
  9916. * arguments it receives. This method is like `_.bind` except it does **not**
  9917. * alter the `this` binding.
  9918. *
  9919. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9920. * builds, may be used as a placeholder for partially applied arguments.
  9921. *
  9922. * **Note:** This method doesn't set the "length" property of partially
  9923. * applied functions.
  9924. *
  9925. * @static
  9926. * @memberOf _
  9927. * @since 0.2.0
  9928. * @category Function
  9929. * @param {Function} func The function to partially apply arguments to.
  9930. * @param {...*} [partials] The arguments to be partially applied.
  9931. * @returns {Function} Returns the new partially applied function.
  9932. * @example
  9933. *
  9934. * function greet(greeting, name) {
  9935. * return greeting + ' ' + name;
  9936. * }
  9937. *
  9938. * var sayHelloTo = _.partial(greet, 'hello');
  9939. * sayHelloTo('fred');
  9940. * // => 'hello fred'
  9941. *
  9942. * // Partially applied with placeholders.
  9943. * var greetFred = _.partial(greet, _, 'fred');
  9944. * greetFred('hi');
  9945. * // => 'hi fred'
  9946. */
  9947. var partial = baseRest(function(func, partials) {
  9948. var holders = replaceHolders(partials, getHolder(partial));
  9949. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9950. });
  9951. /**
  9952. * This method is like `_.partial` except that partially applied arguments
  9953. * are appended to the arguments it receives.
  9954. *
  9955. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9956. * builds, may be used as a placeholder for partially applied arguments.
  9957. *
  9958. * **Note:** This method doesn't set the "length" property of partially
  9959. * applied functions.
  9960. *
  9961. * @static
  9962. * @memberOf _
  9963. * @since 1.0.0
  9964. * @category Function
  9965. * @param {Function} func The function to partially apply arguments to.
  9966. * @param {...*} [partials] The arguments to be partially applied.
  9967. * @returns {Function} Returns the new partially applied function.
  9968. * @example
  9969. *
  9970. * function greet(greeting, name) {
  9971. * return greeting + ' ' + name;
  9972. * }
  9973. *
  9974. * var greetFred = _.partialRight(greet, 'fred');
  9975. * greetFred('hi');
  9976. * // => 'hi fred'
  9977. *
  9978. * // Partially applied with placeholders.
  9979. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9980. * sayHelloTo('fred');
  9981. * // => 'hello fred'
  9982. */
  9983. var partialRight = baseRest(function(func, partials) {
  9984. var holders = replaceHolders(partials, getHolder(partialRight));
  9985. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9986. });
  9987. /**
  9988. * Creates a function that invokes `func` with arguments arranged according
  9989. * to the specified `indexes` where the argument value at the first index is
  9990. * provided as the first argument, the argument value at the second index is
  9991. * provided as the second argument, and so on.
  9992. *
  9993. * @static
  9994. * @memberOf _
  9995. * @since 3.0.0
  9996. * @category Function
  9997. * @param {Function} func The function to rearrange arguments for.
  9998. * @param {...(number|number[])} indexes The arranged argument indexes.
  9999. * @returns {Function} Returns the new function.
  10000. * @example
  10001. *
  10002. * var rearged = _.rearg(function(a, b, c) {
  10003. * return [a, b, c];
  10004. * }, [2, 0, 1]);
  10005. *
  10006. * rearged('b', 'c', 'a')
  10007. * // => ['a', 'b', 'c']
  10008. */
  10009. var rearg = flatRest(function(func, indexes) {
  10010. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10011. });
  10012. /**
  10013. * Creates a function that invokes `func` with the `this` binding of the
  10014. * created function and arguments from `start` and beyond provided as
  10015. * an array.
  10016. *
  10017. * **Note:** This method is based on the
  10018. * [rest parameter](https://mdn.io/rest_parameters).
  10019. *
  10020. * @static
  10021. * @memberOf _
  10022. * @since 4.0.0
  10023. * @category Function
  10024. * @param {Function} func The function to apply a rest parameter to.
  10025. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10026. * @returns {Function} Returns the new function.
  10027. * @example
  10028. *
  10029. * var say = _.rest(function(what, names) {
  10030. * return what + ' ' + _.initial(names).join(', ') +
  10031. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10032. * });
  10033. *
  10034. * say('hello', 'fred', 'barney', 'pebbles');
  10035. * // => 'hello fred, barney, & pebbles'
  10036. */
  10037. function rest(func, start) {
  10038. if (typeof func != 'function') {
  10039. throw new TypeError(FUNC_ERROR_TEXT);
  10040. }
  10041. start = start === undefined ? start : toInteger(start);
  10042. return baseRest(func, start);
  10043. }
  10044. /**
  10045. * Creates a function that invokes `func` with the `this` binding of the
  10046. * create function and an array of arguments much like
  10047. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10048. *
  10049. * **Note:** This method is based on the
  10050. * [spread operator](https://mdn.io/spread_operator).
  10051. *
  10052. * @static
  10053. * @memberOf _
  10054. * @since 3.2.0
  10055. * @category Function
  10056. * @param {Function} func The function to spread arguments over.
  10057. * @param {number} [start=0] The start position of the spread.
  10058. * @returns {Function} Returns the new function.
  10059. * @example
  10060. *
  10061. * var say = _.spread(function(who, what) {
  10062. * return who + ' says ' + what;
  10063. * });
  10064. *
  10065. * say(['fred', 'hello']);
  10066. * // => 'fred says hello'
  10067. *
  10068. * var numbers = Promise.all([
  10069. * Promise.resolve(40),
  10070. * Promise.resolve(36)
  10071. * ]);
  10072. *
  10073. * numbers.then(_.spread(function(x, y) {
  10074. * return x + y;
  10075. * }));
  10076. * // => a Promise of 76
  10077. */
  10078. function spread(func, start) {
  10079. if (typeof func != 'function') {
  10080. throw new TypeError(FUNC_ERROR_TEXT);
  10081. }
  10082. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10083. return baseRest(function(args) {
  10084. var array = args[start],
  10085. otherArgs = castSlice(args, 0, start);
  10086. if (array) {
  10087. arrayPush(otherArgs, array);
  10088. }
  10089. return apply(func, this, otherArgs);
  10090. });
  10091. }
  10092. /**
  10093. * Creates a throttled function that only invokes `func` at most once per
  10094. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10095. * method to cancel delayed `func` invocations and a `flush` method to
  10096. * immediately invoke them. Provide `options` to indicate whether `func`
  10097. * should be invoked on the leading and/or trailing edge of the `wait`
  10098. * timeout. The `func` is invoked with the last arguments provided to the
  10099. * throttled function. Subsequent calls to the throttled function return the
  10100. * result of the last `func` invocation.
  10101. *
  10102. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10103. * invoked on the trailing edge of the timeout only if the throttled function
  10104. * is invoked more than once during the `wait` timeout.
  10105. *
  10106. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10107. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10108. *
  10109. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10110. * for details over the differences between `_.throttle` and `_.debounce`.
  10111. *
  10112. * @static
  10113. * @memberOf _
  10114. * @since 0.1.0
  10115. * @category Function
  10116. * @param {Function} func The function to throttle.
  10117. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10118. * @param {Object} [options={}] The options object.
  10119. * @param {boolean} [options.leading=true]
  10120. * Specify invoking on the leading edge of the timeout.
  10121. * @param {boolean} [options.trailing=true]
  10122. * Specify invoking on the trailing edge of the timeout.
  10123. * @returns {Function} Returns the new throttled function.
  10124. * @example
  10125. *
  10126. * // Avoid excessively updating the position while scrolling.
  10127. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10128. *
  10129. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10130. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10131. * jQuery(element).on('click', throttled);
  10132. *
  10133. * // Cancel the trailing throttled invocation.
  10134. * jQuery(window).on('popstate', throttled.cancel);
  10135. */
  10136. function throttle(func, wait, options) {
  10137. var leading = true,
  10138. trailing = true;
  10139. if (typeof func != 'function') {
  10140. throw new TypeError(FUNC_ERROR_TEXT);
  10141. }
  10142. if (isObject(options)) {
  10143. leading = 'leading' in options ? !!options.leading : leading;
  10144. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10145. }
  10146. return debounce(func, wait, {
  10147. 'leading': leading,
  10148. 'maxWait': wait,
  10149. 'trailing': trailing
  10150. });
  10151. }
  10152. /**
  10153. * Creates a function that accepts up to one argument, ignoring any
  10154. * additional arguments.
  10155. *
  10156. * @static
  10157. * @memberOf _
  10158. * @since 4.0.0
  10159. * @category Function
  10160. * @param {Function} func The function to cap arguments for.
  10161. * @returns {Function} Returns the new capped function.
  10162. * @example
  10163. *
  10164. * _.map(['6', '8', '10'], _.unary(parseInt));
  10165. * // => [6, 8, 10]
  10166. */
  10167. function unary(func) {
  10168. return ary(func, 1);
  10169. }
  10170. /**
  10171. * Creates a function that provides `value` to `wrapper` as its first
  10172. * argument. Any additional arguments provided to the function are appended
  10173. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10174. * binding of the created function.
  10175. *
  10176. * @static
  10177. * @memberOf _
  10178. * @since 0.1.0
  10179. * @category Function
  10180. * @param {*} value The value to wrap.
  10181. * @param {Function} [wrapper=identity] The wrapper function.
  10182. * @returns {Function} Returns the new function.
  10183. * @example
  10184. *
  10185. * var p = _.wrap(_.escape, function(func, text) {
  10186. * return '<p>' + func(text) + '</p>';
  10187. * });
  10188. *
  10189. * p('fred, barney, & pebbles');
  10190. * // => '<p>fred, barney, &amp; pebbles</p>'
  10191. */
  10192. function wrap(value, wrapper) {
  10193. return partial(castFunction(wrapper), value);
  10194. }
  10195. /*------------------------------------------------------------------------*/
  10196. /**
  10197. * Casts `value` as an array if it's not one.
  10198. *
  10199. * @static
  10200. * @memberOf _
  10201. * @since 4.4.0
  10202. * @category Lang
  10203. * @param {*} value The value to inspect.
  10204. * @returns {Array} Returns the cast array.
  10205. * @example
  10206. *
  10207. * _.castArray(1);
  10208. * // => [1]
  10209. *
  10210. * _.castArray({ 'a': 1 });
  10211. * // => [{ 'a': 1 }]
  10212. *
  10213. * _.castArray('abc');
  10214. * // => ['abc']
  10215. *
  10216. * _.castArray(null);
  10217. * // => [null]
  10218. *
  10219. * _.castArray(undefined);
  10220. * // => [undefined]
  10221. *
  10222. * _.castArray();
  10223. * // => []
  10224. *
  10225. * var array = [1, 2, 3];
  10226. * console.log(_.castArray(array) === array);
  10227. * // => true
  10228. */
  10229. function castArray() {
  10230. if (!arguments.length) {
  10231. return [];
  10232. }
  10233. var value = arguments[0];
  10234. return isArray(value) ? value : [value];
  10235. }
  10236. /**
  10237. * Creates a shallow clone of `value`.
  10238. *
  10239. * **Note:** This method is loosely based on the
  10240. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10241. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10242. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10243. * arrays. The own enumerable properties of `arguments` objects are cloned
  10244. * as plain objects. An empty object is returned for uncloneable values such
  10245. * as error objects, functions, DOM nodes, and WeakMaps.
  10246. *
  10247. * @static
  10248. * @memberOf _
  10249. * @since 0.1.0
  10250. * @category Lang
  10251. * @param {*} value The value to clone.
  10252. * @returns {*} Returns the cloned value.
  10253. * @see _.cloneDeep
  10254. * @example
  10255. *
  10256. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10257. *
  10258. * var shallow = _.clone(objects);
  10259. * console.log(shallow[0] === objects[0]);
  10260. * // => true
  10261. */
  10262. function clone(value) {
  10263. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10264. }
  10265. /**
  10266. * This method is like `_.clone` except that it accepts `customizer` which
  10267. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10268. * cloning is handled by the method instead. The `customizer` is invoked with
  10269. * up to four arguments; (value [, index|key, object, stack]).
  10270. *
  10271. * @static
  10272. * @memberOf _
  10273. * @since 4.0.0
  10274. * @category Lang
  10275. * @param {*} value The value to clone.
  10276. * @param {Function} [customizer] The function to customize cloning.
  10277. * @returns {*} Returns the cloned value.
  10278. * @see _.cloneDeepWith
  10279. * @example
  10280. *
  10281. * function customizer(value) {
  10282. * if (_.isElement(value)) {
  10283. * return value.cloneNode(false);
  10284. * }
  10285. * }
  10286. *
  10287. * var el = _.cloneWith(document.body, customizer);
  10288. *
  10289. * console.log(el === document.body);
  10290. * // => false
  10291. * console.log(el.nodeName);
  10292. * // => 'BODY'
  10293. * console.log(el.childNodes.length);
  10294. * // => 0
  10295. */
  10296. function cloneWith(value, customizer) {
  10297. customizer = typeof customizer == 'function' ? customizer : undefined;
  10298. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10299. }
  10300. /**
  10301. * This method is like `_.clone` except that it recursively clones `value`.
  10302. *
  10303. * @static
  10304. * @memberOf _
  10305. * @since 1.0.0
  10306. * @category Lang
  10307. * @param {*} value The value to recursively clone.
  10308. * @returns {*} Returns the deep cloned value.
  10309. * @see _.clone
  10310. * @example
  10311. *
  10312. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10313. *
  10314. * var deep = _.cloneDeep(objects);
  10315. * console.log(deep[0] === objects[0]);
  10316. * // => false
  10317. */
  10318. function cloneDeep(value) {
  10319. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10320. }
  10321. /**
  10322. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10323. *
  10324. * @static
  10325. * @memberOf _
  10326. * @since 4.0.0
  10327. * @category Lang
  10328. * @param {*} value The value to recursively clone.
  10329. * @param {Function} [customizer] The function to customize cloning.
  10330. * @returns {*} Returns the deep cloned value.
  10331. * @see _.cloneWith
  10332. * @example
  10333. *
  10334. * function customizer(value) {
  10335. * if (_.isElement(value)) {
  10336. * return value.cloneNode(true);
  10337. * }
  10338. * }
  10339. *
  10340. * var el = _.cloneDeepWith(document.body, customizer);
  10341. *
  10342. * console.log(el === document.body);
  10343. * // => false
  10344. * console.log(el.nodeName);
  10345. * // => 'BODY'
  10346. * console.log(el.childNodes.length);
  10347. * // => 20
  10348. */
  10349. function cloneDeepWith(value, customizer) {
  10350. customizer = typeof customizer == 'function' ? customizer : undefined;
  10351. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10352. }
  10353. /**
  10354. * Checks if `object` conforms to `source` by invoking the predicate
  10355. * properties of `source` with the corresponding property values of `object`.
  10356. *
  10357. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10358. * partially applied.
  10359. *
  10360. * @static
  10361. * @memberOf _
  10362. * @since 4.14.0
  10363. * @category Lang
  10364. * @param {Object} object The object to inspect.
  10365. * @param {Object} source The object of property predicates to conform to.
  10366. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10367. * @example
  10368. *
  10369. * var object = { 'a': 1, 'b': 2 };
  10370. *
  10371. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10372. * // => true
  10373. *
  10374. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10375. * // => false
  10376. */
  10377. function conformsTo(object, source) {
  10378. return source == null || baseConformsTo(object, source, keys(source));
  10379. }
  10380. /**
  10381. * Performs a
  10382. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10383. * comparison between two values to determine if they are equivalent.
  10384. *
  10385. * @static
  10386. * @memberOf _
  10387. * @since 4.0.0
  10388. * @category Lang
  10389. * @param {*} value The value to compare.
  10390. * @param {*} other The other value to compare.
  10391. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10392. * @example
  10393. *
  10394. * var object = { 'a': 1 };
  10395. * var other = { 'a': 1 };
  10396. *
  10397. * _.eq(object, object);
  10398. * // => true
  10399. *
  10400. * _.eq(object, other);
  10401. * // => false
  10402. *
  10403. * _.eq('a', 'a');
  10404. * // => true
  10405. *
  10406. * _.eq('a', Object('a'));
  10407. * // => false
  10408. *
  10409. * _.eq(NaN, NaN);
  10410. * // => true
  10411. */
  10412. function eq(value, other) {
  10413. return value === other || (value !== value && other !== other);
  10414. }
  10415. /**
  10416. * Checks if `value` is greater than `other`.
  10417. *
  10418. * @static
  10419. * @memberOf _
  10420. * @since 3.9.0
  10421. * @category Lang
  10422. * @param {*} value The value to compare.
  10423. * @param {*} other The other value to compare.
  10424. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10425. * else `false`.
  10426. * @see _.lt
  10427. * @example
  10428. *
  10429. * _.gt(3, 1);
  10430. * // => true
  10431. *
  10432. * _.gt(3, 3);
  10433. * // => false
  10434. *
  10435. * _.gt(1, 3);
  10436. * // => false
  10437. */
  10438. var gt = createRelationalOperation(baseGt);
  10439. /**
  10440. * Checks if `value` is greater than or equal to `other`.
  10441. *
  10442. * @static
  10443. * @memberOf _
  10444. * @since 3.9.0
  10445. * @category Lang
  10446. * @param {*} value The value to compare.
  10447. * @param {*} other The other value to compare.
  10448. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10449. * `other`, else `false`.
  10450. * @see _.lte
  10451. * @example
  10452. *
  10453. * _.gte(3, 1);
  10454. * // => true
  10455. *
  10456. * _.gte(3, 3);
  10457. * // => true
  10458. *
  10459. * _.gte(1, 3);
  10460. * // => false
  10461. */
  10462. var gte = createRelationalOperation(function(value, other) {
  10463. return value >= other;
  10464. });
  10465. /**
  10466. * Checks if `value` is likely an `arguments` object.
  10467. *
  10468. * @static
  10469. * @memberOf _
  10470. * @since 0.1.0
  10471. * @category Lang
  10472. * @param {*} value The value to check.
  10473. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10474. * else `false`.
  10475. * @example
  10476. *
  10477. * _.isArguments(function() { return arguments; }());
  10478. * // => true
  10479. *
  10480. * _.isArguments([1, 2, 3]);
  10481. * // => false
  10482. */
  10483. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10484. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10485. !propertyIsEnumerable.call(value, 'callee');
  10486. };
  10487. /**
  10488. * Checks if `value` is classified as an `Array` object.
  10489. *
  10490. * @static
  10491. * @memberOf _
  10492. * @since 0.1.0
  10493. * @category Lang
  10494. * @param {*} value The value to check.
  10495. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10496. * @example
  10497. *
  10498. * _.isArray([1, 2, 3]);
  10499. * // => true
  10500. *
  10501. * _.isArray(document.body.children);
  10502. * // => false
  10503. *
  10504. * _.isArray('abc');
  10505. * // => false
  10506. *
  10507. * _.isArray(_.noop);
  10508. * // => false
  10509. */
  10510. var isArray = Array.isArray;
  10511. /**
  10512. * Checks if `value` is classified as an `ArrayBuffer` object.
  10513. *
  10514. * @static
  10515. * @memberOf _
  10516. * @since 4.3.0
  10517. * @category Lang
  10518. * @param {*} value The value to check.
  10519. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10520. * @example
  10521. *
  10522. * _.isArrayBuffer(new ArrayBuffer(2));
  10523. * // => true
  10524. *
  10525. * _.isArrayBuffer(new Array(2));
  10526. * // => false
  10527. */
  10528. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10529. /**
  10530. * Checks if `value` is array-like. A value is considered array-like if it's
  10531. * not a function and has a `value.length` that's an integer greater than or
  10532. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10533. *
  10534. * @static
  10535. * @memberOf _
  10536. * @since 4.0.0
  10537. * @category Lang
  10538. * @param {*} value The value to check.
  10539. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10540. * @example
  10541. *
  10542. * _.isArrayLike([1, 2, 3]);
  10543. * // => true
  10544. *
  10545. * _.isArrayLike(document.body.children);
  10546. * // => true
  10547. *
  10548. * _.isArrayLike('abc');
  10549. * // => true
  10550. *
  10551. * _.isArrayLike(_.noop);
  10552. * // => false
  10553. */
  10554. function isArrayLike(value) {
  10555. return value != null && isLength(value.length) && !isFunction(value);
  10556. }
  10557. /**
  10558. * This method is like `_.isArrayLike` except that it also checks if `value`
  10559. * is an object.
  10560. *
  10561. * @static
  10562. * @memberOf _
  10563. * @since 4.0.0
  10564. * @category Lang
  10565. * @param {*} value The value to check.
  10566. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10567. * else `false`.
  10568. * @example
  10569. *
  10570. * _.isArrayLikeObject([1, 2, 3]);
  10571. * // => true
  10572. *
  10573. * _.isArrayLikeObject(document.body.children);
  10574. * // => true
  10575. *
  10576. * _.isArrayLikeObject('abc');
  10577. * // => false
  10578. *
  10579. * _.isArrayLikeObject(_.noop);
  10580. * // => false
  10581. */
  10582. function isArrayLikeObject(value) {
  10583. return isObjectLike(value) && isArrayLike(value);
  10584. }
  10585. /**
  10586. * Checks if `value` is classified as a boolean primitive or object.
  10587. *
  10588. * @static
  10589. * @memberOf _
  10590. * @since 0.1.0
  10591. * @category Lang
  10592. * @param {*} value The value to check.
  10593. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10594. * @example
  10595. *
  10596. * _.isBoolean(false);
  10597. * // => true
  10598. *
  10599. * _.isBoolean(null);
  10600. * // => false
  10601. */
  10602. function isBoolean(value) {
  10603. return value === true || value === false ||
  10604. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10605. }
  10606. /**
  10607. * Checks if `value` is a buffer.
  10608. *
  10609. * @static
  10610. * @memberOf _
  10611. * @since 4.3.0
  10612. * @category Lang
  10613. * @param {*} value The value to check.
  10614. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10615. * @example
  10616. *
  10617. * _.isBuffer(new Buffer(2));
  10618. * // => true
  10619. *
  10620. * _.isBuffer(new Uint8Array(2));
  10621. * // => false
  10622. */
  10623. var isBuffer = nativeIsBuffer || stubFalse;
  10624. /**
  10625. * Checks if `value` is classified as a `Date` object.
  10626. *
  10627. * @static
  10628. * @memberOf _
  10629. * @since 0.1.0
  10630. * @category Lang
  10631. * @param {*} value The value to check.
  10632. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10633. * @example
  10634. *
  10635. * _.isDate(new Date);
  10636. * // => true
  10637. *
  10638. * _.isDate('Mon April 23 2012');
  10639. * // => false
  10640. */
  10641. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10642. /**
  10643. * Checks if `value` is likely a DOM element.
  10644. *
  10645. * @static
  10646. * @memberOf _
  10647. * @since 0.1.0
  10648. * @category Lang
  10649. * @param {*} value The value to check.
  10650. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10651. * @example
  10652. *
  10653. * _.isElement(document.body);
  10654. * // => true
  10655. *
  10656. * _.isElement('<body>');
  10657. * // => false
  10658. */
  10659. function isElement(value) {
  10660. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10661. }
  10662. /**
  10663. * Checks if `value` is an empty object, collection, map, or set.
  10664. *
  10665. * Objects are considered empty if they have no own enumerable string keyed
  10666. * properties.
  10667. *
  10668. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10669. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10670. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10671. *
  10672. * @static
  10673. * @memberOf _
  10674. * @since 0.1.0
  10675. * @category Lang
  10676. * @param {*} value The value to check.
  10677. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10678. * @example
  10679. *
  10680. * _.isEmpty(null);
  10681. * // => true
  10682. *
  10683. * _.isEmpty(true);
  10684. * // => true
  10685. *
  10686. * _.isEmpty(1);
  10687. * // => true
  10688. *
  10689. * _.isEmpty([1, 2, 3]);
  10690. * // => false
  10691. *
  10692. * _.isEmpty({ 'a': 1 });
  10693. * // => false
  10694. */
  10695. function isEmpty(value) {
  10696. if (value == null) {
  10697. return true;
  10698. }
  10699. if (isArrayLike(value) &&
  10700. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10701. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10702. return !value.length;
  10703. }
  10704. var tag = getTag(value);
  10705. if (tag == mapTag || tag == setTag) {
  10706. return !value.size;
  10707. }
  10708. if (isPrototype(value)) {
  10709. return !baseKeys(value).length;
  10710. }
  10711. for (var key in value) {
  10712. if (hasOwnProperty.call(value, key)) {
  10713. return false;
  10714. }
  10715. }
  10716. return true;
  10717. }
  10718. /**
  10719. * Performs a deep comparison between two values to determine if they are
  10720. * equivalent.
  10721. *
  10722. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10723. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10724. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10725. * by their own, not inherited, enumerable properties. Functions and DOM
  10726. * nodes are compared by strict equality, i.e. `===`.
  10727. *
  10728. * @static
  10729. * @memberOf _
  10730. * @since 0.1.0
  10731. * @category Lang
  10732. * @param {*} value The value to compare.
  10733. * @param {*} other The other value to compare.
  10734. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10735. * @example
  10736. *
  10737. * var object = { 'a': 1 };
  10738. * var other = { 'a': 1 };
  10739. *
  10740. * _.isEqual(object, other);
  10741. * // => true
  10742. *
  10743. * object === other;
  10744. * // => false
  10745. */
  10746. function isEqual(value, other) {
  10747. return baseIsEqual(value, other);
  10748. }
  10749. /**
  10750. * This method is like `_.isEqual` except that it accepts `customizer` which
  10751. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10752. * are handled by the method instead. The `customizer` is invoked with up to
  10753. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10754. *
  10755. * @static
  10756. * @memberOf _
  10757. * @since 4.0.0
  10758. * @category Lang
  10759. * @param {*} value The value to compare.
  10760. * @param {*} other The other value to compare.
  10761. * @param {Function} [customizer] The function to customize comparisons.
  10762. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10763. * @example
  10764. *
  10765. * function isGreeting(value) {
  10766. * return /^h(?:i|ello)$/.test(value);
  10767. * }
  10768. *
  10769. * function customizer(objValue, othValue) {
  10770. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10771. * return true;
  10772. * }
  10773. * }
  10774. *
  10775. * var array = ['hello', 'goodbye'];
  10776. * var other = ['hi', 'goodbye'];
  10777. *
  10778. * _.isEqualWith(array, other, customizer);
  10779. * // => true
  10780. */
  10781. function isEqualWith(value, other, customizer) {
  10782. customizer = typeof customizer == 'function' ? customizer : undefined;
  10783. var result = customizer ? customizer(value, other) : undefined;
  10784. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10785. }
  10786. /**
  10787. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10788. * `SyntaxError`, `TypeError`, or `URIError` object.
  10789. *
  10790. * @static
  10791. * @memberOf _
  10792. * @since 3.0.0
  10793. * @category Lang
  10794. * @param {*} value The value to check.
  10795. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10796. * @example
  10797. *
  10798. * _.isError(new Error);
  10799. * // => true
  10800. *
  10801. * _.isError(Error);
  10802. * // => false
  10803. */
  10804. function isError(value) {
  10805. if (!isObjectLike(value)) {
  10806. return false;
  10807. }
  10808. var tag = baseGetTag(value);
  10809. return tag == errorTag || tag == domExcTag ||
  10810. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10811. }
  10812. /**
  10813. * Checks if `value` is a finite primitive number.
  10814. *
  10815. * **Note:** This method is based on
  10816. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10817. *
  10818. * @static
  10819. * @memberOf _
  10820. * @since 0.1.0
  10821. * @category Lang
  10822. * @param {*} value The value to check.
  10823. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10824. * @example
  10825. *
  10826. * _.isFinite(3);
  10827. * // => true
  10828. *
  10829. * _.isFinite(Number.MIN_VALUE);
  10830. * // => true
  10831. *
  10832. * _.isFinite(Infinity);
  10833. * // => false
  10834. *
  10835. * _.isFinite('3');
  10836. * // => false
  10837. */
  10838. function isFinite(value) {
  10839. return typeof value == 'number' && nativeIsFinite(value);
  10840. }
  10841. /**
  10842. * Checks if `value` is classified as a `Function` object.
  10843. *
  10844. * @static
  10845. * @memberOf _
  10846. * @since 0.1.0
  10847. * @category Lang
  10848. * @param {*} value The value to check.
  10849. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10850. * @example
  10851. *
  10852. * _.isFunction(_);
  10853. * // => true
  10854. *
  10855. * _.isFunction(/abc/);
  10856. * // => false
  10857. */
  10858. function isFunction(value) {
  10859. if (!isObject(value)) {
  10860. return false;
  10861. }
  10862. // The use of `Object#toString` avoids issues with the `typeof` operator
  10863. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10864. var tag = baseGetTag(value);
  10865. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10866. }
  10867. /**
  10868. * Checks if `value` is an integer.
  10869. *
  10870. * **Note:** This method is based on
  10871. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10872. *
  10873. * @static
  10874. * @memberOf _
  10875. * @since 4.0.0
  10876. * @category Lang
  10877. * @param {*} value The value to check.
  10878. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10879. * @example
  10880. *
  10881. * _.isInteger(3);
  10882. * // => true
  10883. *
  10884. * _.isInteger(Number.MIN_VALUE);
  10885. * // => false
  10886. *
  10887. * _.isInteger(Infinity);
  10888. * // => false
  10889. *
  10890. * _.isInteger('3');
  10891. * // => false
  10892. */
  10893. function isInteger(value) {
  10894. return typeof value == 'number' && value == toInteger(value);
  10895. }
  10896. /**
  10897. * Checks if `value` is a valid array-like length.
  10898. *
  10899. * **Note:** This method is loosely based on
  10900. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10901. *
  10902. * @static
  10903. * @memberOf _
  10904. * @since 4.0.0
  10905. * @category Lang
  10906. * @param {*} value The value to check.
  10907. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10908. * @example
  10909. *
  10910. * _.isLength(3);
  10911. * // => true
  10912. *
  10913. * _.isLength(Number.MIN_VALUE);
  10914. * // => false
  10915. *
  10916. * _.isLength(Infinity);
  10917. * // => false
  10918. *
  10919. * _.isLength('3');
  10920. * // => false
  10921. */
  10922. function isLength(value) {
  10923. return typeof value == 'number' &&
  10924. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10925. }
  10926. /**
  10927. * Checks if `value` is the
  10928. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10929. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10930. *
  10931. * @static
  10932. * @memberOf _
  10933. * @since 0.1.0
  10934. * @category Lang
  10935. * @param {*} value The value to check.
  10936. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10937. * @example
  10938. *
  10939. * _.isObject({});
  10940. * // => true
  10941. *
  10942. * _.isObject([1, 2, 3]);
  10943. * // => true
  10944. *
  10945. * _.isObject(_.noop);
  10946. * // => true
  10947. *
  10948. * _.isObject(null);
  10949. * // => false
  10950. */
  10951. function isObject(value) {
  10952. var type = typeof value;
  10953. return value != null && (type == 'object' || type == 'function');
  10954. }
  10955. /**
  10956. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10957. * and has a `typeof` result of "object".
  10958. *
  10959. * @static
  10960. * @memberOf _
  10961. * @since 4.0.0
  10962. * @category Lang
  10963. * @param {*} value The value to check.
  10964. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10965. * @example
  10966. *
  10967. * _.isObjectLike({});
  10968. * // => true
  10969. *
  10970. * _.isObjectLike([1, 2, 3]);
  10971. * // => true
  10972. *
  10973. * _.isObjectLike(_.noop);
  10974. * // => false
  10975. *
  10976. * _.isObjectLike(null);
  10977. * // => false
  10978. */
  10979. function isObjectLike(value) {
  10980. return value != null && typeof value == 'object';
  10981. }
  10982. /**
  10983. * Checks if `value` is classified as a `Map` object.
  10984. *
  10985. * @static
  10986. * @memberOf _
  10987. * @since 4.3.0
  10988. * @category Lang
  10989. * @param {*} value The value to check.
  10990. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10991. * @example
  10992. *
  10993. * _.isMap(new Map);
  10994. * // => true
  10995. *
  10996. * _.isMap(new WeakMap);
  10997. * // => false
  10998. */
  10999. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11000. /**
  11001. * Performs a partial deep comparison between `object` and `source` to
  11002. * determine if `object` contains equivalent property values.
  11003. *
  11004. * **Note:** This method is equivalent to `_.matches` when `source` is
  11005. * partially applied.
  11006. *
  11007. * Partial comparisons will match empty array and empty object `source`
  11008. * values against any array or object value, respectively. See `_.isEqual`
  11009. * for a list of supported value comparisons.
  11010. *
  11011. * @static
  11012. * @memberOf _
  11013. * @since 3.0.0
  11014. * @category Lang
  11015. * @param {Object} object The object to inspect.
  11016. * @param {Object} source The object of property values to match.
  11017. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11018. * @example
  11019. *
  11020. * var object = { 'a': 1, 'b': 2 };
  11021. *
  11022. * _.isMatch(object, { 'b': 2 });
  11023. * // => true
  11024. *
  11025. * _.isMatch(object, { 'b': 1 });
  11026. * // => false
  11027. */
  11028. function isMatch(object, source) {
  11029. return object === source || baseIsMatch(object, source, getMatchData(source));
  11030. }
  11031. /**
  11032. * This method is like `_.isMatch` except that it accepts `customizer` which
  11033. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11034. * are handled by the method instead. The `customizer` is invoked with five
  11035. * arguments: (objValue, srcValue, index|key, object, source).
  11036. *
  11037. * @static
  11038. * @memberOf _
  11039. * @since 4.0.0
  11040. * @category Lang
  11041. * @param {Object} object The object to inspect.
  11042. * @param {Object} source The object of property values to match.
  11043. * @param {Function} [customizer] The function to customize comparisons.
  11044. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11045. * @example
  11046. *
  11047. * function isGreeting(value) {
  11048. * return /^h(?:i|ello)$/.test(value);
  11049. * }
  11050. *
  11051. * function customizer(objValue, srcValue) {
  11052. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11053. * return true;
  11054. * }
  11055. * }
  11056. *
  11057. * var object = { 'greeting': 'hello' };
  11058. * var source = { 'greeting': 'hi' };
  11059. *
  11060. * _.isMatchWith(object, source, customizer);
  11061. * // => true
  11062. */
  11063. function isMatchWith(object, source, customizer) {
  11064. customizer = typeof customizer == 'function' ? customizer : undefined;
  11065. return baseIsMatch(object, source, getMatchData(source), customizer);
  11066. }
  11067. /**
  11068. * Checks if `value` is `NaN`.
  11069. *
  11070. * **Note:** This method is based on
  11071. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11072. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11073. * `undefined` and other non-number values.
  11074. *
  11075. * @static
  11076. * @memberOf _
  11077. * @since 0.1.0
  11078. * @category Lang
  11079. * @param {*} value The value to check.
  11080. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11081. * @example
  11082. *
  11083. * _.isNaN(NaN);
  11084. * // => true
  11085. *
  11086. * _.isNaN(new Number(NaN));
  11087. * // => true
  11088. *
  11089. * isNaN(undefined);
  11090. * // => true
  11091. *
  11092. * _.isNaN(undefined);
  11093. * // => false
  11094. */
  11095. function isNaN(value) {
  11096. // An `NaN` primitive is the only value that is not equal to itself.
  11097. // Perform the `toStringTag` check first to avoid errors with some
  11098. // ActiveX objects in IE.
  11099. return isNumber(value) && value != +value;
  11100. }
  11101. /**
  11102. * Checks if `value` is a pristine native function.
  11103. *
  11104. * **Note:** This method can't reliably detect native functions in the presence
  11105. * of the core-js package because core-js circumvents this kind of detection.
  11106. * Despite multiple requests, the core-js maintainer has made it clear: any
  11107. * attempt to fix the detection will be obstructed. As a result, we're left
  11108. * with little choice but to throw an error. Unfortunately, this also affects
  11109. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11110. * which rely on core-js.
  11111. *
  11112. * @static
  11113. * @memberOf _
  11114. * @since 3.0.0
  11115. * @category Lang
  11116. * @param {*} value The value to check.
  11117. * @returns {boolean} Returns `true` if `value` is a native function,
  11118. * else `false`.
  11119. * @example
  11120. *
  11121. * _.isNative(Array.prototype.push);
  11122. * // => true
  11123. *
  11124. * _.isNative(_);
  11125. * // => false
  11126. */
  11127. function isNative(value) {
  11128. if (isMaskable(value)) {
  11129. throw new Error(CORE_ERROR_TEXT);
  11130. }
  11131. return baseIsNative(value);
  11132. }
  11133. /**
  11134. * Checks if `value` is `null`.
  11135. *
  11136. * @static
  11137. * @memberOf _
  11138. * @since 0.1.0
  11139. * @category Lang
  11140. * @param {*} value The value to check.
  11141. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11142. * @example
  11143. *
  11144. * _.isNull(null);
  11145. * // => true
  11146. *
  11147. * _.isNull(void 0);
  11148. * // => false
  11149. */
  11150. function isNull(value) {
  11151. return value === null;
  11152. }
  11153. /**
  11154. * Checks if `value` is `null` or `undefined`.
  11155. *
  11156. * @static
  11157. * @memberOf _
  11158. * @since 4.0.0
  11159. * @category Lang
  11160. * @param {*} value The value to check.
  11161. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11162. * @example
  11163. *
  11164. * _.isNil(null);
  11165. * // => true
  11166. *
  11167. * _.isNil(void 0);
  11168. * // => true
  11169. *
  11170. * _.isNil(NaN);
  11171. * // => false
  11172. */
  11173. function isNil(value) {
  11174. return value == null;
  11175. }
  11176. /**
  11177. * Checks if `value` is classified as a `Number` primitive or object.
  11178. *
  11179. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11180. * classified as numbers, use the `_.isFinite` method.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @since 0.1.0
  11185. * @category Lang
  11186. * @param {*} value The value to check.
  11187. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11188. * @example
  11189. *
  11190. * _.isNumber(3);
  11191. * // => true
  11192. *
  11193. * _.isNumber(Number.MIN_VALUE);
  11194. * // => true
  11195. *
  11196. * _.isNumber(Infinity);
  11197. * // => true
  11198. *
  11199. * _.isNumber('3');
  11200. * // => false
  11201. */
  11202. function isNumber(value) {
  11203. return typeof value == 'number' ||
  11204. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11205. }
  11206. /**
  11207. * Checks if `value` is a plain object, that is, an object created by the
  11208. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11209. *
  11210. * @static
  11211. * @memberOf _
  11212. * @since 0.8.0
  11213. * @category Lang
  11214. * @param {*} value The value to check.
  11215. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11216. * @example
  11217. *
  11218. * function Foo() {
  11219. * this.a = 1;
  11220. * }
  11221. *
  11222. * _.isPlainObject(new Foo);
  11223. * // => false
  11224. *
  11225. * _.isPlainObject([1, 2, 3]);
  11226. * // => false
  11227. *
  11228. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11229. * // => true
  11230. *
  11231. * _.isPlainObject(Object.create(null));
  11232. * // => true
  11233. */
  11234. function isPlainObject(value) {
  11235. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11236. return false;
  11237. }
  11238. var proto = getPrototype(value);
  11239. if (proto === null) {
  11240. return true;
  11241. }
  11242. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11243. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11244. funcToString.call(Ctor) == objectCtorString;
  11245. }
  11246. /**
  11247. * Checks if `value` is classified as a `RegExp` object.
  11248. *
  11249. * @static
  11250. * @memberOf _
  11251. * @since 0.1.0
  11252. * @category Lang
  11253. * @param {*} value The value to check.
  11254. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11255. * @example
  11256. *
  11257. * _.isRegExp(/abc/);
  11258. * // => true
  11259. *
  11260. * _.isRegExp('/abc/');
  11261. * // => false
  11262. */
  11263. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11264. /**
  11265. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11266. * double precision number which isn't the result of a rounded unsafe integer.
  11267. *
  11268. * **Note:** This method is based on
  11269. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11270. *
  11271. * @static
  11272. * @memberOf _
  11273. * @since 4.0.0
  11274. * @category Lang
  11275. * @param {*} value The value to check.
  11276. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11277. * @example
  11278. *
  11279. * _.isSafeInteger(3);
  11280. * // => true
  11281. *
  11282. * _.isSafeInteger(Number.MIN_VALUE);
  11283. * // => false
  11284. *
  11285. * _.isSafeInteger(Infinity);
  11286. * // => false
  11287. *
  11288. * _.isSafeInteger('3');
  11289. * // => false
  11290. */
  11291. function isSafeInteger(value) {
  11292. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11293. }
  11294. /**
  11295. * Checks if `value` is classified as a `Set` object.
  11296. *
  11297. * @static
  11298. * @memberOf _
  11299. * @since 4.3.0
  11300. * @category Lang
  11301. * @param {*} value The value to check.
  11302. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11303. * @example
  11304. *
  11305. * _.isSet(new Set);
  11306. * // => true
  11307. *
  11308. * _.isSet(new WeakSet);
  11309. * // => false
  11310. */
  11311. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11312. /**
  11313. * Checks if `value` is classified as a `String` primitive or object.
  11314. *
  11315. * @static
  11316. * @since 0.1.0
  11317. * @memberOf _
  11318. * @category Lang
  11319. * @param {*} value The value to check.
  11320. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11321. * @example
  11322. *
  11323. * _.isString('abc');
  11324. * // => true
  11325. *
  11326. * _.isString(1);
  11327. * // => false
  11328. */
  11329. function isString(value) {
  11330. return typeof value == 'string' ||
  11331. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11332. }
  11333. /**
  11334. * Checks if `value` is classified as a `Symbol` primitive or object.
  11335. *
  11336. * @static
  11337. * @memberOf _
  11338. * @since 4.0.0
  11339. * @category Lang
  11340. * @param {*} value The value to check.
  11341. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11342. * @example
  11343. *
  11344. * _.isSymbol(Symbol.iterator);
  11345. * // => true
  11346. *
  11347. * _.isSymbol('abc');
  11348. * // => false
  11349. */
  11350. function isSymbol(value) {
  11351. return typeof value == 'symbol' ||
  11352. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11353. }
  11354. /**
  11355. * Checks if `value` is classified as a typed array.
  11356. *
  11357. * @static
  11358. * @memberOf _
  11359. * @since 3.0.0
  11360. * @category Lang
  11361. * @param {*} value The value to check.
  11362. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11363. * @example
  11364. *
  11365. * _.isTypedArray(new Uint8Array);
  11366. * // => true
  11367. *
  11368. * _.isTypedArray([]);
  11369. * // => false
  11370. */
  11371. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11372. /**
  11373. * Checks if `value` is `undefined`.
  11374. *
  11375. * @static
  11376. * @since 0.1.0
  11377. * @memberOf _
  11378. * @category Lang
  11379. * @param {*} value The value to check.
  11380. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11381. * @example
  11382. *
  11383. * _.isUndefined(void 0);
  11384. * // => true
  11385. *
  11386. * _.isUndefined(null);
  11387. * // => false
  11388. */
  11389. function isUndefined(value) {
  11390. return value === undefined;
  11391. }
  11392. /**
  11393. * Checks if `value` is classified as a `WeakMap` object.
  11394. *
  11395. * @static
  11396. * @memberOf _
  11397. * @since 4.3.0
  11398. * @category Lang
  11399. * @param {*} value The value to check.
  11400. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11401. * @example
  11402. *
  11403. * _.isWeakMap(new WeakMap);
  11404. * // => true
  11405. *
  11406. * _.isWeakMap(new Map);
  11407. * // => false
  11408. */
  11409. function isWeakMap(value) {
  11410. return isObjectLike(value) && getTag(value) == weakMapTag;
  11411. }
  11412. /**
  11413. * Checks if `value` is classified as a `WeakSet` object.
  11414. *
  11415. * @static
  11416. * @memberOf _
  11417. * @since 4.3.0
  11418. * @category Lang
  11419. * @param {*} value The value to check.
  11420. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11421. * @example
  11422. *
  11423. * _.isWeakSet(new WeakSet);
  11424. * // => true
  11425. *
  11426. * _.isWeakSet(new Set);
  11427. * // => false
  11428. */
  11429. function isWeakSet(value) {
  11430. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11431. }
  11432. /**
  11433. * Checks if `value` is less than `other`.
  11434. *
  11435. * @static
  11436. * @memberOf _
  11437. * @since 3.9.0
  11438. * @category Lang
  11439. * @param {*} value The value to compare.
  11440. * @param {*} other The other value to compare.
  11441. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11442. * else `false`.
  11443. * @see _.gt
  11444. * @example
  11445. *
  11446. * _.lt(1, 3);
  11447. * // => true
  11448. *
  11449. * _.lt(3, 3);
  11450. * // => false
  11451. *
  11452. * _.lt(3, 1);
  11453. * // => false
  11454. */
  11455. var lt = createRelationalOperation(baseLt);
  11456. /**
  11457. * Checks if `value` is less than or equal to `other`.
  11458. *
  11459. * @static
  11460. * @memberOf _
  11461. * @since 3.9.0
  11462. * @category Lang
  11463. * @param {*} value The value to compare.
  11464. * @param {*} other The other value to compare.
  11465. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11466. * `other`, else `false`.
  11467. * @see _.gte
  11468. * @example
  11469. *
  11470. * _.lte(1, 3);
  11471. * // => true
  11472. *
  11473. * _.lte(3, 3);
  11474. * // => true
  11475. *
  11476. * _.lte(3, 1);
  11477. * // => false
  11478. */
  11479. var lte = createRelationalOperation(function(value, other) {
  11480. return value <= other;
  11481. });
  11482. /**
  11483. * Converts `value` to an array.
  11484. *
  11485. * @static
  11486. * @since 0.1.0
  11487. * @memberOf _
  11488. * @category Lang
  11489. * @param {*} value The value to convert.
  11490. * @returns {Array} Returns the converted array.
  11491. * @example
  11492. *
  11493. * _.toArray({ 'a': 1, 'b': 2 });
  11494. * // => [1, 2]
  11495. *
  11496. * _.toArray('abc');
  11497. * // => ['a', 'b', 'c']
  11498. *
  11499. * _.toArray(1);
  11500. * // => []
  11501. *
  11502. * _.toArray(null);
  11503. * // => []
  11504. */
  11505. function toArray(value) {
  11506. if (!value) {
  11507. return [];
  11508. }
  11509. if (isArrayLike(value)) {
  11510. return isString(value) ? stringToArray(value) : copyArray(value);
  11511. }
  11512. if (symIterator && value[symIterator]) {
  11513. return iteratorToArray(value[symIterator]());
  11514. }
  11515. var tag = getTag(value),
  11516. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11517. return func(value);
  11518. }
  11519. /**
  11520. * Converts `value` to a finite number.
  11521. *
  11522. * @static
  11523. * @memberOf _
  11524. * @since 4.12.0
  11525. * @category Lang
  11526. * @param {*} value The value to convert.
  11527. * @returns {number} Returns the converted number.
  11528. * @example
  11529. *
  11530. * _.toFinite(3.2);
  11531. * // => 3.2
  11532. *
  11533. * _.toFinite(Number.MIN_VALUE);
  11534. * // => 5e-324
  11535. *
  11536. * _.toFinite(Infinity);
  11537. * // => 1.7976931348623157e+308
  11538. *
  11539. * _.toFinite('3.2');
  11540. * // => 3.2
  11541. */
  11542. function toFinite(value) {
  11543. if (!value) {
  11544. return value === 0 ? value : 0;
  11545. }
  11546. value = toNumber(value);
  11547. if (value === INFINITY || value === -INFINITY) {
  11548. var sign = (value < 0 ? -1 : 1);
  11549. return sign * MAX_INTEGER;
  11550. }
  11551. return value === value ? value : 0;
  11552. }
  11553. /**
  11554. * Converts `value` to an integer.
  11555. *
  11556. * **Note:** This method is loosely based on
  11557. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11558. *
  11559. * @static
  11560. * @memberOf _
  11561. * @since 4.0.0
  11562. * @category Lang
  11563. * @param {*} value The value to convert.
  11564. * @returns {number} Returns the converted integer.
  11565. * @example
  11566. *
  11567. * _.toInteger(3.2);
  11568. * // => 3
  11569. *
  11570. * _.toInteger(Number.MIN_VALUE);
  11571. * // => 0
  11572. *
  11573. * _.toInteger(Infinity);
  11574. * // => 1.7976931348623157e+308
  11575. *
  11576. * _.toInteger('3.2');
  11577. * // => 3
  11578. */
  11579. function toInteger(value) {
  11580. var result = toFinite(value),
  11581. remainder = result % 1;
  11582. return result === result ? (remainder ? result - remainder : result) : 0;
  11583. }
  11584. /**
  11585. * Converts `value` to an integer suitable for use as the length of an
  11586. * array-like object.
  11587. *
  11588. * **Note:** This method is based on
  11589. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11590. *
  11591. * @static
  11592. * @memberOf _
  11593. * @since 4.0.0
  11594. * @category Lang
  11595. * @param {*} value The value to convert.
  11596. * @returns {number} Returns the converted integer.
  11597. * @example
  11598. *
  11599. * _.toLength(3.2);
  11600. * // => 3
  11601. *
  11602. * _.toLength(Number.MIN_VALUE);
  11603. * // => 0
  11604. *
  11605. * _.toLength(Infinity);
  11606. * // => 4294967295
  11607. *
  11608. * _.toLength('3.2');
  11609. * // => 3
  11610. */
  11611. function toLength(value) {
  11612. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11613. }
  11614. /**
  11615. * Converts `value` to a number.
  11616. *
  11617. * @static
  11618. * @memberOf _
  11619. * @since 4.0.0
  11620. * @category Lang
  11621. * @param {*} value The value to process.
  11622. * @returns {number} Returns the number.
  11623. * @example
  11624. *
  11625. * _.toNumber(3.2);
  11626. * // => 3.2
  11627. *
  11628. * _.toNumber(Number.MIN_VALUE);
  11629. * // => 5e-324
  11630. *
  11631. * _.toNumber(Infinity);
  11632. * // => Infinity
  11633. *
  11634. * _.toNumber('3.2');
  11635. * // => 3.2
  11636. */
  11637. function toNumber(value) {
  11638. if (typeof value == 'number') {
  11639. return value;
  11640. }
  11641. if (isSymbol(value)) {
  11642. return NAN;
  11643. }
  11644. if (isObject(value)) {
  11645. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11646. value = isObject(other) ? (other + '') : other;
  11647. }
  11648. if (typeof value != 'string') {
  11649. return value === 0 ? value : +value;
  11650. }
  11651. value = value.replace(reTrim, '');
  11652. var isBinary = reIsBinary.test(value);
  11653. return (isBinary || reIsOctal.test(value))
  11654. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11655. : (reIsBadHex.test(value) ? NAN : +value);
  11656. }
  11657. /**
  11658. * Converts `value` to a plain object flattening inherited enumerable string
  11659. * keyed properties of `value` to own properties of the plain object.
  11660. *
  11661. * @static
  11662. * @memberOf _
  11663. * @since 3.0.0
  11664. * @category Lang
  11665. * @param {*} value The value to convert.
  11666. * @returns {Object} Returns the converted plain object.
  11667. * @example
  11668. *
  11669. * function Foo() {
  11670. * this.b = 2;
  11671. * }
  11672. *
  11673. * Foo.prototype.c = 3;
  11674. *
  11675. * _.assign({ 'a': 1 }, new Foo);
  11676. * // => { 'a': 1, 'b': 2 }
  11677. *
  11678. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11679. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11680. */
  11681. function toPlainObject(value) {
  11682. return copyObject(value, keysIn(value));
  11683. }
  11684. /**
  11685. * Converts `value` to a safe integer. A safe integer can be compared and
  11686. * represented correctly.
  11687. *
  11688. * @static
  11689. * @memberOf _
  11690. * @since 4.0.0
  11691. * @category Lang
  11692. * @param {*} value The value to convert.
  11693. * @returns {number} Returns the converted integer.
  11694. * @example
  11695. *
  11696. * _.toSafeInteger(3.2);
  11697. * // => 3
  11698. *
  11699. * _.toSafeInteger(Number.MIN_VALUE);
  11700. * // => 0
  11701. *
  11702. * _.toSafeInteger(Infinity);
  11703. * // => 9007199254740991
  11704. *
  11705. * _.toSafeInteger('3.2');
  11706. * // => 3
  11707. */
  11708. function toSafeInteger(value) {
  11709. return value
  11710. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11711. : (value === 0 ? value : 0);
  11712. }
  11713. /**
  11714. * Converts `value` to a string. An empty string is returned for `null`
  11715. * and `undefined` values. The sign of `-0` is preserved.
  11716. *
  11717. * @static
  11718. * @memberOf _
  11719. * @since 4.0.0
  11720. * @category Lang
  11721. * @param {*} value The value to convert.
  11722. * @returns {string} Returns the converted string.
  11723. * @example
  11724. *
  11725. * _.toString(null);
  11726. * // => ''
  11727. *
  11728. * _.toString(-0);
  11729. * // => '-0'
  11730. *
  11731. * _.toString([1, 2, 3]);
  11732. * // => '1,2,3'
  11733. */
  11734. function toString(value) {
  11735. return value == null ? '' : baseToString(value);
  11736. }
  11737. /*------------------------------------------------------------------------*/
  11738. /**
  11739. * Assigns own enumerable string keyed properties of source objects to the
  11740. * destination object. Source objects are applied from left to right.
  11741. * Subsequent sources overwrite property assignments of previous sources.
  11742. *
  11743. * **Note:** This method mutates `object` and is loosely based on
  11744. * [`Object.assign`](https://mdn.io/Object/assign).
  11745. *
  11746. * @static
  11747. * @memberOf _
  11748. * @since 0.10.0
  11749. * @category Object
  11750. * @param {Object} object The destination object.
  11751. * @param {...Object} [sources] The source objects.
  11752. * @returns {Object} Returns `object`.
  11753. * @see _.assignIn
  11754. * @example
  11755. *
  11756. * function Foo() {
  11757. * this.a = 1;
  11758. * }
  11759. *
  11760. * function Bar() {
  11761. * this.c = 3;
  11762. * }
  11763. *
  11764. * Foo.prototype.b = 2;
  11765. * Bar.prototype.d = 4;
  11766. *
  11767. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11768. * // => { 'a': 1, 'c': 3 }
  11769. */
  11770. var assign = createAssigner(function(object, source) {
  11771. if (isPrototype(source) || isArrayLike(source)) {
  11772. copyObject(source, keys(source), object);
  11773. return;
  11774. }
  11775. for (var key in source) {
  11776. if (hasOwnProperty.call(source, key)) {
  11777. assignValue(object, key, source[key]);
  11778. }
  11779. }
  11780. });
  11781. /**
  11782. * This method is like `_.assign` except that it iterates over own and
  11783. * inherited source properties.
  11784. *
  11785. * **Note:** This method mutates `object`.
  11786. *
  11787. * @static
  11788. * @memberOf _
  11789. * @since 4.0.0
  11790. * @alias extend
  11791. * @category Object
  11792. * @param {Object} object The destination object.
  11793. * @param {...Object} [sources] The source objects.
  11794. * @returns {Object} Returns `object`.
  11795. * @see _.assign
  11796. * @example
  11797. *
  11798. * function Foo() {
  11799. * this.a = 1;
  11800. * }
  11801. *
  11802. * function Bar() {
  11803. * this.c = 3;
  11804. * }
  11805. *
  11806. * Foo.prototype.b = 2;
  11807. * Bar.prototype.d = 4;
  11808. *
  11809. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11810. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11811. */
  11812. var assignIn = createAssigner(function(object, source) {
  11813. copyObject(source, keysIn(source), object);
  11814. });
  11815. /**
  11816. * This method is like `_.assignIn` except that it accepts `customizer`
  11817. * which is invoked to produce the assigned values. If `customizer` returns
  11818. * `undefined`, assignment is handled by the method instead. The `customizer`
  11819. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11820. *
  11821. * **Note:** This method mutates `object`.
  11822. *
  11823. * @static
  11824. * @memberOf _
  11825. * @since 4.0.0
  11826. * @alias extendWith
  11827. * @category Object
  11828. * @param {Object} object The destination object.
  11829. * @param {...Object} sources The source objects.
  11830. * @param {Function} [customizer] The function to customize assigned values.
  11831. * @returns {Object} Returns `object`.
  11832. * @see _.assignWith
  11833. * @example
  11834. *
  11835. * function customizer(objValue, srcValue) {
  11836. * return _.isUndefined(objValue) ? srcValue : objValue;
  11837. * }
  11838. *
  11839. * var defaults = _.partialRight(_.assignInWith, customizer);
  11840. *
  11841. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11842. * // => { 'a': 1, 'b': 2 }
  11843. */
  11844. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11845. copyObject(source, keysIn(source), object, customizer);
  11846. });
  11847. /**
  11848. * This method is like `_.assign` except that it accepts `customizer`
  11849. * which is invoked to produce the assigned values. If `customizer` returns
  11850. * `undefined`, assignment is handled by the method instead. The `customizer`
  11851. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11852. *
  11853. * **Note:** This method mutates `object`.
  11854. *
  11855. * @static
  11856. * @memberOf _
  11857. * @since 4.0.0
  11858. * @category Object
  11859. * @param {Object} object The destination object.
  11860. * @param {...Object} sources The source objects.
  11861. * @param {Function} [customizer] The function to customize assigned values.
  11862. * @returns {Object} Returns `object`.
  11863. * @see _.assignInWith
  11864. * @example
  11865. *
  11866. * function customizer(objValue, srcValue) {
  11867. * return _.isUndefined(objValue) ? srcValue : objValue;
  11868. * }
  11869. *
  11870. * var defaults = _.partialRight(_.assignWith, customizer);
  11871. *
  11872. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11873. * // => { 'a': 1, 'b': 2 }
  11874. */
  11875. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11876. copyObject(source, keys(source), object, customizer);
  11877. });
  11878. /**
  11879. * Creates an array of values corresponding to `paths` of `object`.
  11880. *
  11881. * @static
  11882. * @memberOf _
  11883. * @since 1.0.0
  11884. * @category Object
  11885. * @param {Object} object The object to iterate over.
  11886. * @param {...(string|string[])} [paths] The property paths to pick.
  11887. * @returns {Array} Returns the picked values.
  11888. * @example
  11889. *
  11890. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11891. *
  11892. * _.at(object, ['a[0].b.c', 'a[1]']);
  11893. * // => [3, 4]
  11894. */
  11895. var at = flatRest(baseAt);
  11896. /**
  11897. * Creates an object that inherits from the `prototype` object. If a
  11898. * `properties` object is given, its own enumerable string keyed properties
  11899. * are assigned to the created object.
  11900. *
  11901. * @static
  11902. * @memberOf _
  11903. * @since 2.3.0
  11904. * @category Object
  11905. * @param {Object} prototype The object to inherit from.
  11906. * @param {Object} [properties] The properties to assign to the object.
  11907. * @returns {Object} Returns the new object.
  11908. * @example
  11909. *
  11910. * function Shape() {
  11911. * this.x = 0;
  11912. * this.y = 0;
  11913. * }
  11914. *
  11915. * function Circle() {
  11916. * Shape.call(this);
  11917. * }
  11918. *
  11919. * Circle.prototype = _.create(Shape.prototype, {
  11920. * 'constructor': Circle
  11921. * });
  11922. *
  11923. * var circle = new Circle;
  11924. * circle instanceof Circle;
  11925. * // => true
  11926. *
  11927. * circle instanceof Shape;
  11928. * // => true
  11929. */
  11930. function create(prototype, properties) {
  11931. var result = baseCreate(prototype);
  11932. return properties == null ? result : baseAssign(result, properties);
  11933. }
  11934. /**
  11935. * Assigns own and inherited enumerable string keyed properties of source
  11936. * objects to the destination object for all destination properties that
  11937. * resolve to `undefined`. Source objects are applied from left to right.
  11938. * Once a property is set, additional values of the same property are ignored.
  11939. *
  11940. * **Note:** This method mutates `object`.
  11941. *
  11942. * @static
  11943. * @since 0.1.0
  11944. * @memberOf _
  11945. * @category Object
  11946. * @param {Object} object The destination object.
  11947. * @param {...Object} [sources] The source objects.
  11948. * @returns {Object} Returns `object`.
  11949. * @see _.defaultsDeep
  11950. * @example
  11951. *
  11952. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11953. * // => { 'a': 1, 'b': 2 }
  11954. */
  11955. var defaults = baseRest(function(object, sources) {
  11956. object = Object(object);
  11957. var index = -1;
  11958. var length = sources.length;
  11959. var guard = length > 2 ? sources[2] : undefined;
  11960. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11961. length = 1;
  11962. }
  11963. while (++index < length) {
  11964. var source = sources[index];
  11965. var props = keysIn(source);
  11966. var propsIndex = -1;
  11967. var propsLength = props.length;
  11968. while (++propsIndex < propsLength) {
  11969. var key = props[propsIndex];
  11970. var value = object[key];
  11971. if (value === undefined ||
  11972. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11973. object[key] = source[key];
  11974. }
  11975. }
  11976. }
  11977. return object;
  11978. });
  11979. /**
  11980. * This method is like `_.defaults` except that it recursively assigns
  11981. * default properties.
  11982. *
  11983. * **Note:** This method mutates `object`.
  11984. *
  11985. * @static
  11986. * @memberOf _
  11987. * @since 3.10.0
  11988. * @category Object
  11989. * @param {Object} object The destination object.
  11990. * @param {...Object} [sources] The source objects.
  11991. * @returns {Object} Returns `object`.
  11992. * @see _.defaults
  11993. * @example
  11994. *
  11995. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11996. * // => { 'a': { 'b': 2, 'c': 3 } }
  11997. */
  11998. var defaultsDeep = baseRest(function(args) {
  11999. args.push(undefined, customDefaultsMerge);
  12000. return apply(mergeWith, undefined, args);
  12001. });
  12002. /**
  12003. * This method is like `_.find` except that it returns the key of the first
  12004. * element `predicate` returns truthy for instead of the element itself.
  12005. *
  12006. * @static
  12007. * @memberOf _
  12008. * @since 1.1.0
  12009. * @category Object
  12010. * @param {Object} object The object to inspect.
  12011. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12012. * @returns {string|undefined} Returns the key of the matched element,
  12013. * else `undefined`.
  12014. * @example
  12015. *
  12016. * var users = {
  12017. * 'barney': { 'age': 36, 'active': true },
  12018. * 'fred': { 'age': 40, 'active': false },
  12019. * 'pebbles': { 'age': 1, 'active': true }
  12020. * };
  12021. *
  12022. * _.findKey(users, function(o) { return o.age < 40; });
  12023. * // => 'barney' (iteration order is not guaranteed)
  12024. *
  12025. * // The `_.matches` iteratee shorthand.
  12026. * _.findKey(users, { 'age': 1, 'active': true });
  12027. * // => 'pebbles'
  12028. *
  12029. * // The `_.matchesProperty` iteratee shorthand.
  12030. * _.findKey(users, ['active', false]);
  12031. * // => 'fred'
  12032. *
  12033. * // The `_.property` iteratee shorthand.
  12034. * _.findKey(users, 'active');
  12035. * // => 'barney'
  12036. */
  12037. function findKey(object, predicate) {
  12038. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12039. }
  12040. /**
  12041. * This method is like `_.findKey` except that it iterates over elements of
  12042. * a collection in the opposite order.
  12043. *
  12044. * @static
  12045. * @memberOf _
  12046. * @since 2.0.0
  12047. * @category Object
  12048. * @param {Object} object The object to inspect.
  12049. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12050. * @returns {string|undefined} Returns the key of the matched element,
  12051. * else `undefined`.
  12052. * @example
  12053. *
  12054. * var users = {
  12055. * 'barney': { 'age': 36, 'active': true },
  12056. * 'fred': { 'age': 40, 'active': false },
  12057. * 'pebbles': { 'age': 1, 'active': true }
  12058. * };
  12059. *
  12060. * _.findLastKey(users, function(o) { return o.age < 40; });
  12061. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12062. *
  12063. * // The `_.matches` iteratee shorthand.
  12064. * _.findLastKey(users, { 'age': 36, 'active': true });
  12065. * // => 'barney'
  12066. *
  12067. * // The `_.matchesProperty` iteratee shorthand.
  12068. * _.findLastKey(users, ['active', false]);
  12069. * // => 'fred'
  12070. *
  12071. * // The `_.property` iteratee shorthand.
  12072. * _.findLastKey(users, 'active');
  12073. * // => 'pebbles'
  12074. */
  12075. function findLastKey(object, predicate) {
  12076. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12077. }
  12078. /**
  12079. * Iterates over own and inherited enumerable string keyed properties of an
  12080. * object and invokes `iteratee` for each property. The iteratee is invoked
  12081. * with three arguments: (value, key, object). Iteratee functions may exit
  12082. * iteration early by explicitly returning `false`.
  12083. *
  12084. * @static
  12085. * @memberOf _
  12086. * @since 0.3.0
  12087. * @category Object
  12088. * @param {Object} object The object to iterate over.
  12089. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12090. * @returns {Object} Returns `object`.
  12091. * @see _.forInRight
  12092. * @example
  12093. *
  12094. * function Foo() {
  12095. * this.a = 1;
  12096. * this.b = 2;
  12097. * }
  12098. *
  12099. * Foo.prototype.c = 3;
  12100. *
  12101. * _.forIn(new Foo, function(value, key) {
  12102. * console.log(key);
  12103. * });
  12104. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12105. */
  12106. function forIn(object, iteratee) {
  12107. return object == null
  12108. ? object
  12109. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12110. }
  12111. /**
  12112. * This method is like `_.forIn` except that it iterates over properties of
  12113. * `object` in the opposite order.
  12114. *
  12115. * @static
  12116. * @memberOf _
  12117. * @since 2.0.0
  12118. * @category Object
  12119. * @param {Object} object The object to iterate over.
  12120. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12121. * @returns {Object} Returns `object`.
  12122. * @see _.forIn
  12123. * @example
  12124. *
  12125. * function Foo() {
  12126. * this.a = 1;
  12127. * this.b = 2;
  12128. * }
  12129. *
  12130. * Foo.prototype.c = 3;
  12131. *
  12132. * _.forInRight(new Foo, function(value, key) {
  12133. * console.log(key);
  12134. * });
  12135. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12136. */
  12137. function forInRight(object, iteratee) {
  12138. return object == null
  12139. ? object
  12140. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12141. }
  12142. /**
  12143. * Iterates over own enumerable string keyed properties of an object and
  12144. * invokes `iteratee` for each property. The iteratee is invoked with three
  12145. * arguments: (value, key, object). Iteratee functions may exit iteration
  12146. * early by explicitly returning `false`.
  12147. *
  12148. * @static
  12149. * @memberOf _
  12150. * @since 0.3.0
  12151. * @category Object
  12152. * @param {Object} object The object to iterate over.
  12153. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12154. * @returns {Object} Returns `object`.
  12155. * @see _.forOwnRight
  12156. * @example
  12157. *
  12158. * function Foo() {
  12159. * this.a = 1;
  12160. * this.b = 2;
  12161. * }
  12162. *
  12163. * Foo.prototype.c = 3;
  12164. *
  12165. * _.forOwn(new Foo, function(value, key) {
  12166. * console.log(key);
  12167. * });
  12168. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12169. */
  12170. function forOwn(object, iteratee) {
  12171. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12172. }
  12173. /**
  12174. * This method is like `_.forOwn` except that it iterates over properties of
  12175. * `object` in the opposite order.
  12176. *
  12177. * @static
  12178. * @memberOf _
  12179. * @since 2.0.0
  12180. * @category Object
  12181. * @param {Object} object The object to iterate over.
  12182. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12183. * @returns {Object} Returns `object`.
  12184. * @see _.forOwn
  12185. * @example
  12186. *
  12187. * function Foo() {
  12188. * this.a = 1;
  12189. * this.b = 2;
  12190. * }
  12191. *
  12192. * Foo.prototype.c = 3;
  12193. *
  12194. * _.forOwnRight(new Foo, function(value, key) {
  12195. * console.log(key);
  12196. * });
  12197. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12198. */
  12199. function forOwnRight(object, iteratee) {
  12200. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12201. }
  12202. /**
  12203. * Creates an array of function property names from own enumerable properties
  12204. * of `object`.
  12205. *
  12206. * @static
  12207. * @since 0.1.0
  12208. * @memberOf _
  12209. * @category Object
  12210. * @param {Object} object The object to inspect.
  12211. * @returns {Array} Returns the function names.
  12212. * @see _.functionsIn
  12213. * @example
  12214. *
  12215. * function Foo() {
  12216. * this.a = _.constant('a');
  12217. * this.b = _.constant('b');
  12218. * }
  12219. *
  12220. * Foo.prototype.c = _.constant('c');
  12221. *
  12222. * _.functions(new Foo);
  12223. * // => ['a', 'b']
  12224. */
  12225. function functions(object) {
  12226. return object == null ? [] : baseFunctions(object, keys(object));
  12227. }
  12228. /**
  12229. * Creates an array of function property names from own and inherited
  12230. * enumerable properties of `object`.
  12231. *
  12232. * @static
  12233. * @memberOf _
  12234. * @since 4.0.0
  12235. * @category Object
  12236. * @param {Object} object The object to inspect.
  12237. * @returns {Array} Returns the function names.
  12238. * @see _.functions
  12239. * @example
  12240. *
  12241. * function Foo() {
  12242. * this.a = _.constant('a');
  12243. * this.b = _.constant('b');
  12244. * }
  12245. *
  12246. * Foo.prototype.c = _.constant('c');
  12247. *
  12248. * _.functionsIn(new Foo);
  12249. * // => ['a', 'b', 'c']
  12250. */
  12251. function functionsIn(object) {
  12252. return object == null ? [] : baseFunctions(object, keysIn(object));
  12253. }
  12254. /**
  12255. * Gets the value at `path` of `object`. If the resolved value is
  12256. * `undefined`, the `defaultValue` is returned in its place.
  12257. *
  12258. * @static
  12259. * @memberOf _
  12260. * @since 3.7.0
  12261. * @category Object
  12262. * @param {Object} object The object to query.
  12263. * @param {Array|string} path The path of the property to get.
  12264. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12265. * @returns {*} Returns the resolved value.
  12266. * @example
  12267. *
  12268. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12269. *
  12270. * _.get(object, 'a[0].b.c');
  12271. * // => 3
  12272. *
  12273. * _.get(object, ['a', '0', 'b', 'c']);
  12274. * // => 3
  12275. *
  12276. * _.get(object, 'a.b.c', 'default');
  12277. * // => 'default'
  12278. */
  12279. function get(object, path, defaultValue) {
  12280. var result = object == null ? undefined : baseGet(object, path);
  12281. return result === undefined ? defaultValue : result;
  12282. }
  12283. /**
  12284. * Checks if `path` is a direct property of `object`.
  12285. *
  12286. * @static
  12287. * @since 0.1.0
  12288. * @memberOf _
  12289. * @category Object
  12290. * @param {Object} object The object to query.
  12291. * @param {Array|string} path The path to check.
  12292. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12293. * @example
  12294. *
  12295. * var object = { 'a': { 'b': 2 } };
  12296. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12297. *
  12298. * _.has(object, 'a');
  12299. * // => true
  12300. *
  12301. * _.has(object, 'a.b');
  12302. * // => true
  12303. *
  12304. * _.has(object, ['a', 'b']);
  12305. * // => true
  12306. *
  12307. * _.has(other, 'a');
  12308. * // => false
  12309. */
  12310. function has(object, path) {
  12311. return object != null && hasPath(object, path, baseHas);
  12312. }
  12313. /**
  12314. * Checks if `path` is a direct or inherited property of `object`.
  12315. *
  12316. * @static
  12317. * @memberOf _
  12318. * @since 4.0.0
  12319. * @category Object
  12320. * @param {Object} object The object to query.
  12321. * @param {Array|string} path The path to check.
  12322. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12323. * @example
  12324. *
  12325. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12326. *
  12327. * _.hasIn(object, 'a');
  12328. * // => true
  12329. *
  12330. * _.hasIn(object, 'a.b');
  12331. * // => true
  12332. *
  12333. * _.hasIn(object, ['a', 'b']);
  12334. * // => true
  12335. *
  12336. * _.hasIn(object, 'b');
  12337. * // => false
  12338. */
  12339. function hasIn(object, path) {
  12340. return object != null && hasPath(object, path, baseHasIn);
  12341. }
  12342. /**
  12343. * Creates an object composed of the inverted keys and values of `object`.
  12344. * If `object` contains duplicate values, subsequent values overwrite
  12345. * property assignments of previous values.
  12346. *
  12347. * @static
  12348. * @memberOf _
  12349. * @since 0.7.0
  12350. * @category Object
  12351. * @param {Object} object The object to invert.
  12352. * @returns {Object} Returns the new inverted object.
  12353. * @example
  12354. *
  12355. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12356. *
  12357. * _.invert(object);
  12358. * // => { '1': 'c', '2': 'b' }
  12359. */
  12360. var invert = createInverter(function(result, value, key) {
  12361. if (value != null &&
  12362. typeof value.toString != 'function') {
  12363. value = nativeObjectToString.call(value);
  12364. }
  12365. result[value] = key;
  12366. }, constant(identity));
  12367. /**
  12368. * This method is like `_.invert` except that the inverted object is generated
  12369. * from the results of running each element of `object` thru `iteratee`. The
  12370. * corresponding inverted value of each inverted key is an array of keys
  12371. * responsible for generating the inverted value. The iteratee is invoked
  12372. * with one argument: (value).
  12373. *
  12374. * @static
  12375. * @memberOf _
  12376. * @since 4.1.0
  12377. * @category Object
  12378. * @param {Object} object The object to invert.
  12379. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12380. * @returns {Object} Returns the new inverted object.
  12381. * @example
  12382. *
  12383. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12384. *
  12385. * _.invertBy(object);
  12386. * // => { '1': ['a', 'c'], '2': ['b'] }
  12387. *
  12388. * _.invertBy(object, function(value) {
  12389. * return 'group' + value;
  12390. * });
  12391. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12392. */
  12393. var invertBy = createInverter(function(result, value, key) {
  12394. if (value != null &&
  12395. typeof value.toString != 'function') {
  12396. value = nativeObjectToString.call(value);
  12397. }
  12398. if (hasOwnProperty.call(result, value)) {
  12399. result[value].push(key);
  12400. } else {
  12401. result[value] = [key];
  12402. }
  12403. }, getIteratee);
  12404. /**
  12405. * Invokes the method at `path` of `object`.
  12406. *
  12407. * @static
  12408. * @memberOf _
  12409. * @since 4.0.0
  12410. * @category Object
  12411. * @param {Object} object The object to query.
  12412. * @param {Array|string} path The path of the method to invoke.
  12413. * @param {...*} [args] The arguments to invoke the method with.
  12414. * @returns {*} Returns the result of the invoked method.
  12415. * @example
  12416. *
  12417. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12418. *
  12419. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12420. * // => [2, 3]
  12421. */
  12422. var invoke = baseRest(baseInvoke);
  12423. /**
  12424. * Creates an array of the own enumerable property names of `object`.
  12425. *
  12426. * **Note:** Non-object values are coerced to objects. See the
  12427. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12428. * for more details.
  12429. *
  12430. * @static
  12431. * @since 0.1.0
  12432. * @memberOf _
  12433. * @category Object
  12434. * @param {Object} object The object to query.
  12435. * @returns {Array} Returns the array of property names.
  12436. * @example
  12437. *
  12438. * function Foo() {
  12439. * this.a = 1;
  12440. * this.b = 2;
  12441. * }
  12442. *
  12443. * Foo.prototype.c = 3;
  12444. *
  12445. * _.keys(new Foo);
  12446. * // => ['a', 'b'] (iteration order is not guaranteed)
  12447. *
  12448. * _.keys('hi');
  12449. * // => ['0', '1']
  12450. */
  12451. function keys(object) {
  12452. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12453. }
  12454. /**
  12455. * Creates an array of the own and inherited enumerable property names of `object`.
  12456. *
  12457. * **Note:** Non-object values are coerced to objects.
  12458. *
  12459. * @static
  12460. * @memberOf _
  12461. * @since 3.0.0
  12462. * @category Object
  12463. * @param {Object} object The object to query.
  12464. * @returns {Array} Returns the array of property names.
  12465. * @example
  12466. *
  12467. * function Foo() {
  12468. * this.a = 1;
  12469. * this.b = 2;
  12470. * }
  12471. *
  12472. * Foo.prototype.c = 3;
  12473. *
  12474. * _.keysIn(new Foo);
  12475. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12476. */
  12477. function keysIn(object) {
  12478. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12479. }
  12480. /**
  12481. * The opposite of `_.mapValues`; this method creates an object with the
  12482. * same values as `object` and keys generated by running each own enumerable
  12483. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12484. * with three arguments: (value, key, object).
  12485. *
  12486. * @static
  12487. * @memberOf _
  12488. * @since 3.8.0
  12489. * @category Object
  12490. * @param {Object} object The object to iterate over.
  12491. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12492. * @returns {Object} Returns the new mapped object.
  12493. * @see _.mapValues
  12494. * @example
  12495. *
  12496. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12497. * return key + value;
  12498. * });
  12499. * // => { 'a1': 1, 'b2': 2 }
  12500. */
  12501. function mapKeys(object, iteratee) {
  12502. var result = {};
  12503. iteratee = getIteratee(iteratee, 3);
  12504. baseForOwn(object, function(value, key, object) {
  12505. baseAssignValue(result, iteratee(value, key, object), value);
  12506. });
  12507. return result;
  12508. }
  12509. /**
  12510. * Creates an object with the same keys as `object` and values generated
  12511. * by running each own enumerable string keyed property of `object` thru
  12512. * `iteratee`. The iteratee is invoked with three arguments:
  12513. * (value, key, object).
  12514. *
  12515. * @static
  12516. * @memberOf _
  12517. * @since 2.4.0
  12518. * @category Object
  12519. * @param {Object} object The object to iterate over.
  12520. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12521. * @returns {Object} Returns the new mapped object.
  12522. * @see _.mapKeys
  12523. * @example
  12524. *
  12525. * var users = {
  12526. * 'fred': { 'user': 'fred', 'age': 40 },
  12527. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12528. * };
  12529. *
  12530. * _.mapValues(users, function(o) { return o.age; });
  12531. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12532. *
  12533. * // The `_.property` iteratee shorthand.
  12534. * _.mapValues(users, 'age');
  12535. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12536. */
  12537. function mapValues(object, iteratee) {
  12538. var result = {};
  12539. iteratee = getIteratee(iteratee, 3);
  12540. baseForOwn(object, function(value, key, object) {
  12541. baseAssignValue(result, key, iteratee(value, key, object));
  12542. });
  12543. return result;
  12544. }
  12545. /**
  12546. * This method is like `_.assign` except that it recursively merges own and
  12547. * inherited enumerable string keyed properties of source objects into the
  12548. * destination object. Source properties that resolve to `undefined` are
  12549. * skipped if a destination value exists. Array and plain object properties
  12550. * are merged recursively. Other objects and value types are overridden by
  12551. * assignment. Source objects are applied from left to right. Subsequent
  12552. * sources overwrite property assignments of previous sources.
  12553. *
  12554. * **Note:** This method mutates `object`.
  12555. *
  12556. * @static
  12557. * @memberOf _
  12558. * @since 0.5.0
  12559. * @category Object
  12560. * @param {Object} object The destination object.
  12561. * @param {...Object} [sources] The source objects.
  12562. * @returns {Object} Returns `object`.
  12563. * @example
  12564. *
  12565. * var object = {
  12566. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12567. * };
  12568. *
  12569. * var other = {
  12570. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12571. * };
  12572. *
  12573. * _.merge(object, other);
  12574. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12575. */
  12576. var merge = createAssigner(function(object, source, srcIndex) {
  12577. baseMerge(object, source, srcIndex);
  12578. });
  12579. /**
  12580. * This method is like `_.merge` except that it accepts `customizer` which
  12581. * is invoked to produce the merged values of the destination and source
  12582. * properties. If `customizer` returns `undefined`, merging is handled by the
  12583. * method instead. The `customizer` is invoked with six arguments:
  12584. * (objValue, srcValue, key, object, source, stack).
  12585. *
  12586. * **Note:** This method mutates `object`.
  12587. *
  12588. * @static
  12589. * @memberOf _
  12590. * @since 4.0.0
  12591. * @category Object
  12592. * @param {Object} object The destination object.
  12593. * @param {...Object} sources The source objects.
  12594. * @param {Function} customizer The function to customize assigned values.
  12595. * @returns {Object} Returns `object`.
  12596. * @example
  12597. *
  12598. * function customizer(objValue, srcValue) {
  12599. * if (_.isArray(objValue)) {
  12600. * return objValue.concat(srcValue);
  12601. * }
  12602. * }
  12603. *
  12604. * var object = { 'a': [1], 'b': [2] };
  12605. * var other = { 'a': [3], 'b': [4] };
  12606. *
  12607. * _.mergeWith(object, other, customizer);
  12608. * // => { 'a': [1, 3], 'b': [2, 4] }
  12609. */
  12610. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12611. baseMerge(object, source, srcIndex, customizer);
  12612. });
  12613. /**
  12614. * The opposite of `_.pick`; this method creates an object composed of the
  12615. * own and inherited enumerable property paths of `object` that are not omitted.
  12616. *
  12617. * **Note:** This method is considerably slower than `_.pick`.
  12618. *
  12619. * @static
  12620. * @since 0.1.0
  12621. * @memberOf _
  12622. * @category Object
  12623. * @param {Object} object The source object.
  12624. * @param {...(string|string[])} [paths] The property paths to omit.
  12625. * @returns {Object} Returns the new object.
  12626. * @example
  12627. *
  12628. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12629. *
  12630. * _.omit(object, ['a', 'c']);
  12631. * // => { 'b': '2' }
  12632. */
  12633. var omit = flatRest(function(object, paths) {
  12634. var result = {};
  12635. if (object == null) {
  12636. return result;
  12637. }
  12638. var isDeep = false;
  12639. paths = arrayMap(paths, function(path) {
  12640. path = castPath(path, object);
  12641. isDeep || (isDeep = path.length > 1);
  12642. return path;
  12643. });
  12644. copyObject(object, getAllKeysIn(object), result);
  12645. if (isDeep) {
  12646. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12647. }
  12648. var length = paths.length;
  12649. while (length--) {
  12650. baseUnset(result, paths[length]);
  12651. }
  12652. return result;
  12653. });
  12654. /**
  12655. * The opposite of `_.pickBy`; this method creates an object composed of
  12656. * the own and inherited enumerable string keyed properties of `object` that
  12657. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12658. * arguments: (value, key).
  12659. *
  12660. * @static
  12661. * @memberOf _
  12662. * @since 4.0.0
  12663. * @category Object
  12664. * @param {Object} object The source object.
  12665. * @param {Function} [predicate=_.identity] The function invoked per property.
  12666. * @returns {Object} Returns the new object.
  12667. * @example
  12668. *
  12669. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12670. *
  12671. * _.omitBy(object, _.isNumber);
  12672. * // => { 'b': '2' }
  12673. */
  12674. function omitBy(object, predicate) {
  12675. return pickBy(object, negate(getIteratee(predicate)));
  12676. }
  12677. /**
  12678. * Creates an object composed of the picked `object` properties.
  12679. *
  12680. * @static
  12681. * @since 0.1.0
  12682. * @memberOf _
  12683. * @category Object
  12684. * @param {Object} object The source object.
  12685. * @param {...(string|string[])} [paths] The property paths to pick.
  12686. * @returns {Object} Returns the new object.
  12687. * @example
  12688. *
  12689. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12690. *
  12691. * _.pick(object, ['a', 'c']);
  12692. * // => { 'a': 1, 'c': 3 }
  12693. */
  12694. var pick = flatRest(function(object, paths) {
  12695. return object == null ? {} : basePick(object, paths);
  12696. });
  12697. /**
  12698. * Creates an object composed of the `object` properties `predicate` returns
  12699. * truthy for. The predicate is invoked with two arguments: (value, key).
  12700. *
  12701. * @static
  12702. * @memberOf _
  12703. * @since 4.0.0
  12704. * @category Object
  12705. * @param {Object} object The source object.
  12706. * @param {Function} [predicate=_.identity] The function invoked per property.
  12707. * @returns {Object} Returns the new object.
  12708. * @example
  12709. *
  12710. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12711. *
  12712. * _.pickBy(object, _.isNumber);
  12713. * // => { 'a': 1, 'c': 3 }
  12714. */
  12715. function pickBy(object, predicate) {
  12716. if (object == null) {
  12717. return {};
  12718. }
  12719. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12720. return [prop];
  12721. });
  12722. predicate = getIteratee(predicate);
  12723. return basePickBy(object, props, function(value, path) {
  12724. return predicate(value, path[0]);
  12725. });
  12726. }
  12727. /**
  12728. * This method is like `_.get` except that if the resolved value is a
  12729. * function it's invoked with the `this` binding of its parent object and
  12730. * its result is returned.
  12731. *
  12732. * @static
  12733. * @since 0.1.0
  12734. * @memberOf _
  12735. * @category Object
  12736. * @param {Object} object The object to query.
  12737. * @param {Array|string} path The path of the property to resolve.
  12738. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12739. * @returns {*} Returns the resolved value.
  12740. * @example
  12741. *
  12742. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12743. *
  12744. * _.result(object, 'a[0].b.c1');
  12745. * // => 3
  12746. *
  12747. * _.result(object, 'a[0].b.c2');
  12748. * // => 4
  12749. *
  12750. * _.result(object, 'a[0].b.c3', 'default');
  12751. * // => 'default'
  12752. *
  12753. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12754. * // => 'default'
  12755. */
  12756. function result(object, path, defaultValue) {
  12757. path = castPath(path, object);
  12758. var index = -1,
  12759. length = path.length;
  12760. // Ensure the loop is entered when path is empty.
  12761. if (!length) {
  12762. length = 1;
  12763. object = undefined;
  12764. }
  12765. while (++index < length) {
  12766. var value = object == null ? undefined : object[toKey(path[index])];
  12767. if (value === undefined) {
  12768. index = length;
  12769. value = defaultValue;
  12770. }
  12771. object = isFunction(value) ? value.call(object) : value;
  12772. }
  12773. return object;
  12774. }
  12775. /**
  12776. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12777. * it's created. Arrays are created for missing index properties while objects
  12778. * are created for all other missing properties. Use `_.setWith` to customize
  12779. * `path` creation.
  12780. *
  12781. * **Note:** This method mutates `object`.
  12782. *
  12783. * @static
  12784. * @memberOf _
  12785. * @since 3.7.0
  12786. * @category Object
  12787. * @param {Object} object The object to modify.
  12788. * @param {Array|string} path The path of the property to set.
  12789. * @param {*} value The value to set.
  12790. * @returns {Object} Returns `object`.
  12791. * @example
  12792. *
  12793. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12794. *
  12795. * _.set(object, 'a[0].b.c', 4);
  12796. * console.log(object.a[0].b.c);
  12797. * // => 4
  12798. *
  12799. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12800. * console.log(object.x[0].y.z);
  12801. * // => 5
  12802. */
  12803. function set(object, path, value) {
  12804. return object == null ? object : baseSet(object, path, value);
  12805. }
  12806. /**
  12807. * This method is like `_.set` except that it accepts `customizer` which is
  12808. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12809. * path creation is handled by the method instead. The `customizer` is invoked
  12810. * with three arguments: (nsValue, key, nsObject).
  12811. *
  12812. * **Note:** This method mutates `object`.
  12813. *
  12814. * @static
  12815. * @memberOf _
  12816. * @since 4.0.0
  12817. * @category Object
  12818. * @param {Object} object The object to modify.
  12819. * @param {Array|string} path The path of the property to set.
  12820. * @param {*} value The value to set.
  12821. * @param {Function} [customizer] The function to customize assigned values.
  12822. * @returns {Object} Returns `object`.
  12823. * @example
  12824. *
  12825. * var object = {};
  12826. *
  12827. * _.setWith(object, '[0][1]', 'a', Object);
  12828. * // => { '0': { '1': 'a' } }
  12829. */
  12830. function setWith(object, path, value, customizer) {
  12831. customizer = typeof customizer == 'function' ? customizer : undefined;
  12832. return object == null ? object : baseSet(object, path, value, customizer);
  12833. }
  12834. /**
  12835. * Creates an array of own enumerable string keyed-value pairs for `object`
  12836. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12837. * entries are returned.
  12838. *
  12839. * @static
  12840. * @memberOf _
  12841. * @since 4.0.0
  12842. * @alias entries
  12843. * @category Object
  12844. * @param {Object} object The object to query.
  12845. * @returns {Array} Returns the key-value pairs.
  12846. * @example
  12847. *
  12848. * function Foo() {
  12849. * this.a = 1;
  12850. * this.b = 2;
  12851. * }
  12852. *
  12853. * Foo.prototype.c = 3;
  12854. *
  12855. * _.toPairs(new Foo);
  12856. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12857. */
  12858. var toPairs = createToPairs(keys);
  12859. /**
  12860. * Creates an array of own and inherited enumerable string keyed-value pairs
  12861. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12862. * or set, its entries are returned.
  12863. *
  12864. * @static
  12865. * @memberOf _
  12866. * @since 4.0.0
  12867. * @alias entriesIn
  12868. * @category Object
  12869. * @param {Object} object The object to query.
  12870. * @returns {Array} Returns the key-value pairs.
  12871. * @example
  12872. *
  12873. * function Foo() {
  12874. * this.a = 1;
  12875. * this.b = 2;
  12876. * }
  12877. *
  12878. * Foo.prototype.c = 3;
  12879. *
  12880. * _.toPairsIn(new Foo);
  12881. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12882. */
  12883. var toPairsIn = createToPairs(keysIn);
  12884. /**
  12885. * An alternative to `_.reduce`; this method transforms `object` to a new
  12886. * `accumulator` object which is the result of running each of its own
  12887. * enumerable string keyed properties thru `iteratee`, with each invocation
  12888. * potentially mutating the `accumulator` object. If `accumulator` is not
  12889. * provided, a new object with the same `[[Prototype]]` will be used. The
  12890. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12891. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12892. *
  12893. * @static
  12894. * @memberOf _
  12895. * @since 1.3.0
  12896. * @category Object
  12897. * @param {Object} object The object to iterate over.
  12898. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12899. * @param {*} [accumulator] The custom accumulator value.
  12900. * @returns {*} Returns the accumulated value.
  12901. * @example
  12902. *
  12903. * _.transform([2, 3, 4], function(result, n) {
  12904. * result.push(n *= n);
  12905. * return n % 2 == 0;
  12906. * }, []);
  12907. * // => [4, 9]
  12908. *
  12909. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12910. * (result[value] || (result[value] = [])).push(key);
  12911. * }, {});
  12912. * // => { '1': ['a', 'c'], '2': ['b'] }
  12913. */
  12914. function transform(object, iteratee, accumulator) {
  12915. var isArr = isArray(object),
  12916. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12917. iteratee = getIteratee(iteratee, 4);
  12918. if (accumulator == null) {
  12919. var Ctor = object && object.constructor;
  12920. if (isArrLike) {
  12921. accumulator = isArr ? new Ctor : [];
  12922. }
  12923. else if (isObject(object)) {
  12924. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12925. }
  12926. else {
  12927. accumulator = {};
  12928. }
  12929. }
  12930. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12931. return iteratee(accumulator, value, index, object);
  12932. });
  12933. return accumulator;
  12934. }
  12935. /**
  12936. * Removes the property at `path` of `object`.
  12937. *
  12938. * **Note:** This method mutates `object`.
  12939. *
  12940. * @static
  12941. * @memberOf _
  12942. * @since 4.0.0
  12943. * @category Object
  12944. * @param {Object} object The object to modify.
  12945. * @param {Array|string} path The path of the property to unset.
  12946. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12947. * @example
  12948. *
  12949. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12950. * _.unset(object, 'a[0].b.c');
  12951. * // => true
  12952. *
  12953. * console.log(object);
  12954. * // => { 'a': [{ 'b': {} }] };
  12955. *
  12956. * _.unset(object, ['a', '0', 'b', 'c']);
  12957. * // => true
  12958. *
  12959. * console.log(object);
  12960. * // => { 'a': [{ 'b': {} }] };
  12961. */
  12962. function unset(object, path) {
  12963. return object == null ? true : baseUnset(object, path);
  12964. }
  12965. /**
  12966. * This method is like `_.set` except that accepts `updater` to produce the
  12967. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12968. * is invoked with one argument: (value).
  12969. *
  12970. * **Note:** This method mutates `object`.
  12971. *
  12972. * @static
  12973. * @memberOf _
  12974. * @since 4.6.0
  12975. * @category Object
  12976. * @param {Object} object The object to modify.
  12977. * @param {Array|string} path The path of the property to set.
  12978. * @param {Function} updater The function to produce the updated value.
  12979. * @returns {Object} Returns `object`.
  12980. * @example
  12981. *
  12982. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12983. *
  12984. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12985. * console.log(object.a[0].b.c);
  12986. * // => 9
  12987. *
  12988. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12989. * console.log(object.x[0].y.z);
  12990. * // => 0
  12991. */
  12992. function update(object, path, updater) {
  12993. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12994. }
  12995. /**
  12996. * This method is like `_.update` except that it accepts `customizer` which is
  12997. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12998. * path creation is handled by the method instead. The `customizer` is invoked
  12999. * with three arguments: (nsValue, key, nsObject).
  13000. *
  13001. * **Note:** This method mutates `object`.
  13002. *
  13003. * @static
  13004. * @memberOf _
  13005. * @since 4.6.0
  13006. * @category Object
  13007. * @param {Object} object The object to modify.
  13008. * @param {Array|string} path The path of the property to set.
  13009. * @param {Function} updater The function to produce the updated value.
  13010. * @param {Function} [customizer] The function to customize assigned values.
  13011. * @returns {Object} Returns `object`.
  13012. * @example
  13013. *
  13014. * var object = {};
  13015. *
  13016. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13017. * // => { '0': { '1': 'a' } }
  13018. */
  13019. function updateWith(object, path, updater, customizer) {
  13020. customizer = typeof customizer == 'function' ? customizer : undefined;
  13021. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13022. }
  13023. /**
  13024. * Creates an array of the own enumerable string keyed property values of `object`.
  13025. *
  13026. * **Note:** Non-object values are coerced to objects.
  13027. *
  13028. * @static
  13029. * @since 0.1.0
  13030. * @memberOf _
  13031. * @category Object
  13032. * @param {Object} object The object to query.
  13033. * @returns {Array} Returns the array of property values.
  13034. * @example
  13035. *
  13036. * function Foo() {
  13037. * this.a = 1;
  13038. * this.b = 2;
  13039. * }
  13040. *
  13041. * Foo.prototype.c = 3;
  13042. *
  13043. * _.values(new Foo);
  13044. * // => [1, 2] (iteration order is not guaranteed)
  13045. *
  13046. * _.values('hi');
  13047. * // => ['h', 'i']
  13048. */
  13049. function values(object) {
  13050. return object == null ? [] : baseValues(object, keys(object));
  13051. }
  13052. /**
  13053. * Creates an array of the own and inherited enumerable string keyed property
  13054. * values of `object`.
  13055. *
  13056. * **Note:** Non-object values are coerced to objects.
  13057. *
  13058. * @static
  13059. * @memberOf _
  13060. * @since 3.0.0
  13061. * @category Object
  13062. * @param {Object} object The object to query.
  13063. * @returns {Array} Returns the array of property values.
  13064. * @example
  13065. *
  13066. * function Foo() {
  13067. * this.a = 1;
  13068. * this.b = 2;
  13069. * }
  13070. *
  13071. * Foo.prototype.c = 3;
  13072. *
  13073. * _.valuesIn(new Foo);
  13074. * // => [1, 2, 3] (iteration order is not guaranteed)
  13075. */
  13076. function valuesIn(object) {
  13077. return object == null ? [] : baseValues(object, keysIn(object));
  13078. }
  13079. /*------------------------------------------------------------------------*/
  13080. /**
  13081. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13082. *
  13083. * @static
  13084. * @memberOf _
  13085. * @since 4.0.0
  13086. * @category Number
  13087. * @param {number} number The number to clamp.
  13088. * @param {number} [lower] The lower bound.
  13089. * @param {number} upper The upper bound.
  13090. * @returns {number} Returns the clamped number.
  13091. * @example
  13092. *
  13093. * _.clamp(-10, -5, 5);
  13094. * // => -5
  13095. *
  13096. * _.clamp(10, -5, 5);
  13097. * // => 5
  13098. */
  13099. function clamp(number, lower, upper) {
  13100. if (upper === undefined) {
  13101. upper = lower;
  13102. lower = undefined;
  13103. }
  13104. if (upper !== undefined) {
  13105. upper = toNumber(upper);
  13106. upper = upper === upper ? upper : 0;
  13107. }
  13108. if (lower !== undefined) {
  13109. lower = toNumber(lower);
  13110. lower = lower === lower ? lower : 0;
  13111. }
  13112. return baseClamp(toNumber(number), lower, upper);
  13113. }
  13114. /**
  13115. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13116. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13117. * If `start` is greater than `end` the params are swapped to support
  13118. * negative ranges.
  13119. *
  13120. * @static
  13121. * @memberOf _
  13122. * @since 3.3.0
  13123. * @category Number
  13124. * @param {number} number The number to check.
  13125. * @param {number} [start=0] The start of the range.
  13126. * @param {number} end The end of the range.
  13127. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13128. * @see _.range, _.rangeRight
  13129. * @example
  13130. *
  13131. * _.inRange(3, 2, 4);
  13132. * // => true
  13133. *
  13134. * _.inRange(4, 8);
  13135. * // => true
  13136. *
  13137. * _.inRange(4, 2);
  13138. * // => false
  13139. *
  13140. * _.inRange(2, 2);
  13141. * // => false
  13142. *
  13143. * _.inRange(1.2, 2);
  13144. * // => true
  13145. *
  13146. * _.inRange(5.2, 4);
  13147. * // => false
  13148. *
  13149. * _.inRange(-3, -2, -6);
  13150. * // => true
  13151. */
  13152. function inRange(number, start, end) {
  13153. start = toFinite(start);
  13154. if (end === undefined) {
  13155. end = start;
  13156. start = 0;
  13157. } else {
  13158. end = toFinite(end);
  13159. }
  13160. number = toNumber(number);
  13161. return baseInRange(number, start, end);
  13162. }
  13163. /**
  13164. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13165. * If only one argument is provided a number between `0` and the given number
  13166. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13167. * floats, a floating-point number is returned instead of an integer.
  13168. *
  13169. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13170. * floating-point values which can produce unexpected results.
  13171. *
  13172. * @static
  13173. * @memberOf _
  13174. * @since 0.7.0
  13175. * @category Number
  13176. * @param {number} [lower=0] The lower bound.
  13177. * @param {number} [upper=1] The upper bound.
  13178. * @param {boolean} [floating] Specify returning a floating-point number.
  13179. * @returns {number} Returns the random number.
  13180. * @example
  13181. *
  13182. * _.random(0, 5);
  13183. * // => an integer between 0 and 5
  13184. *
  13185. * _.random(5);
  13186. * // => also an integer between 0 and 5
  13187. *
  13188. * _.random(5, true);
  13189. * // => a floating-point number between 0 and 5
  13190. *
  13191. * _.random(1.2, 5.2);
  13192. * // => a floating-point number between 1.2 and 5.2
  13193. */
  13194. function random(lower, upper, floating) {
  13195. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13196. upper = floating = undefined;
  13197. }
  13198. if (floating === undefined) {
  13199. if (typeof upper == 'boolean') {
  13200. floating = upper;
  13201. upper = undefined;
  13202. }
  13203. else if (typeof lower == 'boolean') {
  13204. floating = lower;
  13205. lower = undefined;
  13206. }
  13207. }
  13208. if (lower === undefined && upper === undefined) {
  13209. lower = 0;
  13210. upper = 1;
  13211. }
  13212. else {
  13213. lower = toFinite(lower);
  13214. if (upper === undefined) {
  13215. upper = lower;
  13216. lower = 0;
  13217. } else {
  13218. upper = toFinite(upper);
  13219. }
  13220. }
  13221. if (lower > upper) {
  13222. var temp = lower;
  13223. lower = upper;
  13224. upper = temp;
  13225. }
  13226. if (floating || lower % 1 || upper % 1) {
  13227. var rand = nativeRandom();
  13228. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13229. }
  13230. return baseRandom(lower, upper);
  13231. }
  13232. /*------------------------------------------------------------------------*/
  13233. /**
  13234. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13235. *
  13236. * @static
  13237. * @memberOf _
  13238. * @since 3.0.0
  13239. * @category String
  13240. * @param {string} [string=''] The string to convert.
  13241. * @returns {string} Returns the camel cased string.
  13242. * @example
  13243. *
  13244. * _.camelCase('Foo Bar');
  13245. * // => 'fooBar'
  13246. *
  13247. * _.camelCase('--foo-bar--');
  13248. * // => 'fooBar'
  13249. *
  13250. * _.camelCase('__FOO_BAR__');
  13251. * // => 'fooBar'
  13252. */
  13253. var camelCase = createCompounder(function(result, word, index) {
  13254. word = word.toLowerCase();
  13255. return result + (index ? capitalize(word) : word);
  13256. });
  13257. /**
  13258. * Converts the first character of `string` to upper case and the remaining
  13259. * to lower case.
  13260. *
  13261. * @static
  13262. * @memberOf _
  13263. * @since 3.0.0
  13264. * @category String
  13265. * @param {string} [string=''] The string to capitalize.
  13266. * @returns {string} Returns the capitalized string.
  13267. * @example
  13268. *
  13269. * _.capitalize('FRED');
  13270. * // => 'Fred'
  13271. */
  13272. function capitalize(string) {
  13273. return upperFirst(toString(string).toLowerCase());
  13274. }
  13275. /**
  13276. * Deburrs `string` by converting
  13277. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13278. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13279. * letters to basic Latin letters and removing
  13280. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13281. *
  13282. * @static
  13283. * @memberOf _
  13284. * @since 3.0.0
  13285. * @category String
  13286. * @param {string} [string=''] The string to deburr.
  13287. * @returns {string} Returns the deburred string.
  13288. * @example
  13289. *
  13290. * _.deburr('déjà vu');
  13291. * // => 'deja vu'
  13292. */
  13293. function deburr(string) {
  13294. string = toString(string);
  13295. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13296. }
  13297. /**
  13298. * Checks if `string` ends with the given target string.
  13299. *
  13300. * @static
  13301. * @memberOf _
  13302. * @since 3.0.0
  13303. * @category String
  13304. * @param {string} [string=''] The string to inspect.
  13305. * @param {string} [target] The string to search for.
  13306. * @param {number} [position=string.length] The position to search up to.
  13307. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13308. * else `false`.
  13309. * @example
  13310. *
  13311. * _.endsWith('abc', 'c');
  13312. * // => true
  13313. *
  13314. * _.endsWith('abc', 'b');
  13315. * // => false
  13316. *
  13317. * _.endsWith('abc', 'b', 2);
  13318. * // => true
  13319. */
  13320. function endsWith(string, target, position) {
  13321. string = toString(string);
  13322. target = baseToString(target);
  13323. var length = string.length;
  13324. position = position === undefined
  13325. ? length
  13326. : baseClamp(toInteger(position), 0, length);
  13327. var end = position;
  13328. position -= target.length;
  13329. return position >= 0 && string.slice(position, end) == target;
  13330. }
  13331. /**
  13332. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13333. * corresponding HTML entities.
  13334. *
  13335. * **Note:** No other characters are escaped. To escape additional
  13336. * characters use a third-party library like [_he_](https://mths.be/he).
  13337. *
  13338. * Though the ">" character is escaped for symmetry, characters like
  13339. * ">" and "/" don't need escaping in HTML and have no special meaning
  13340. * unless they're part of a tag or unquoted attribute value. See
  13341. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13342. * (under "semi-related fun fact") for more details.
  13343. *
  13344. * When working with HTML you should always
  13345. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13346. * XSS vectors.
  13347. *
  13348. * @static
  13349. * @since 0.1.0
  13350. * @memberOf _
  13351. * @category String
  13352. * @param {string} [string=''] The string to escape.
  13353. * @returns {string} Returns the escaped string.
  13354. * @example
  13355. *
  13356. * _.escape('fred, barney, & pebbles');
  13357. * // => 'fred, barney, &amp; pebbles'
  13358. */
  13359. function escape(string) {
  13360. string = toString(string);
  13361. return (string && reHasUnescapedHtml.test(string))
  13362. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13363. : string;
  13364. }
  13365. /**
  13366. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13367. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13368. *
  13369. * @static
  13370. * @memberOf _
  13371. * @since 3.0.0
  13372. * @category String
  13373. * @param {string} [string=''] The string to escape.
  13374. * @returns {string} Returns the escaped string.
  13375. * @example
  13376. *
  13377. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13378. * // => '\[lodash\]\(https://lodash\.com/\)'
  13379. */
  13380. function escapeRegExp(string) {
  13381. string = toString(string);
  13382. return (string && reHasRegExpChar.test(string))
  13383. ? string.replace(reRegExpChar, '\\$&')
  13384. : string;
  13385. }
  13386. /**
  13387. * Converts `string` to
  13388. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13389. *
  13390. * @static
  13391. * @memberOf _
  13392. * @since 3.0.0
  13393. * @category String
  13394. * @param {string} [string=''] The string to convert.
  13395. * @returns {string} Returns the kebab cased string.
  13396. * @example
  13397. *
  13398. * _.kebabCase('Foo Bar');
  13399. * // => 'foo-bar'
  13400. *
  13401. * _.kebabCase('fooBar');
  13402. * // => 'foo-bar'
  13403. *
  13404. * _.kebabCase('__FOO_BAR__');
  13405. * // => 'foo-bar'
  13406. */
  13407. var kebabCase = createCompounder(function(result, word, index) {
  13408. return result + (index ? '-' : '') + word.toLowerCase();
  13409. });
  13410. /**
  13411. * Converts `string`, as space separated words, to lower case.
  13412. *
  13413. * @static
  13414. * @memberOf _
  13415. * @since 4.0.0
  13416. * @category String
  13417. * @param {string} [string=''] The string to convert.
  13418. * @returns {string} Returns the lower cased string.
  13419. * @example
  13420. *
  13421. * _.lowerCase('--Foo-Bar--');
  13422. * // => 'foo bar'
  13423. *
  13424. * _.lowerCase('fooBar');
  13425. * // => 'foo bar'
  13426. *
  13427. * _.lowerCase('__FOO_BAR__');
  13428. * // => 'foo bar'
  13429. */
  13430. var lowerCase = createCompounder(function(result, word, index) {
  13431. return result + (index ? ' ' : '') + word.toLowerCase();
  13432. });
  13433. /**
  13434. * Converts the first character of `string` to lower case.
  13435. *
  13436. * @static
  13437. * @memberOf _
  13438. * @since 4.0.0
  13439. * @category String
  13440. * @param {string} [string=''] The string to convert.
  13441. * @returns {string} Returns the converted string.
  13442. * @example
  13443. *
  13444. * _.lowerFirst('Fred');
  13445. * // => 'fred'
  13446. *
  13447. * _.lowerFirst('FRED');
  13448. * // => 'fRED'
  13449. */
  13450. var lowerFirst = createCaseFirst('toLowerCase');
  13451. /**
  13452. * Pads `string` on the left and right sides if it's shorter than `length`.
  13453. * Padding characters are truncated if they can't be evenly divided by `length`.
  13454. *
  13455. * @static
  13456. * @memberOf _
  13457. * @since 3.0.0
  13458. * @category String
  13459. * @param {string} [string=''] The string to pad.
  13460. * @param {number} [length=0] The padding length.
  13461. * @param {string} [chars=' '] The string used as padding.
  13462. * @returns {string} Returns the padded string.
  13463. * @example
  13464. *
  13465. * _.pad('abc', 8);
  13466. * // => ' abc '
  13467. *
  13468. * _.pad('abc', 8, '_-');
  13469. * // => '_-abc_-_'
  13470. *
  13471. * _.pad('abc', 3);
  13472. * // => 'abc'
  13473. */
  13474. function pad(string, length, chars) {
  13475. string = toString(string);
  13476. length = toInteger(length);
  13477. var strLength = length ? stringSize(string) : 0;
  13478. if (!length || strLength >= length) {
  13479. return string;
  13480. }
  13481. var mid = (length - strLength) / 2;
  13482. return (
  13483. createPadding(nativeFloor(mid), chars) +
  13484. string +
  13485. createPadding(nativeCeil(mid), chars)
  13486. );
  13487. }
  13488. /**
  13489. * Pads `string` on the right side if it's shorter than `length`. Padding
  13490. * characters are truncated if they exceed `length`.
  13491. *
  13492. * @static
  13493. * @memberOf _
  13494. * @since 4.0.0
  13495. * @category String
  13496. * @param {string} [string=''] The string to pad.
  13497. * @param {number} [length=0] The padding length.
  13498. * @param {string} [chars=' '] The string used as padding.
  13499. * @returns {string} Returns the padded string.
  13500. * @example
  13501. *
  13502. * _.padEnd('abc', 6);
  13503. * // => 'abc '
  13504. *
  13505. * _.padEnd('abc', 6, '_-');
  13506. * // => 'abc_-_'
  13507. *
  13508. * _.padEnd('abc', 3);
  13509. * // => 'abc'
  13510. */
  13511. function padEnd(string, length, chars) {
  13512. string = toString(string);
  13513. length = toInteger(length);
  13514. var strLength = length ? stringSize(string) : 0;
  13515. return (length && strLength < length)
  13516. ? (string + createPadding(length - strLength, chars))
  13517. : string;
  13518. }
  13519. /**
  13520. * Pads `string` on the left side if it's shorter than `length`. Padding
  13521. * characters are truncated if they exceed `length`.
  13522. *
  13523. * @static
  13524. * @memberOf _
  13525. * @since 4.0.0
  13526. * @category String
  13527. * @param {string} [string=''] The string to pad.
  13528. * @param {number} [length=0] The padding length.
  13529. * @param {string} [chars=' '] The string used as padding.
  13530. * @returns {string} Returns the padded string.
  13531. * @example
  13532. *
  13533. * _.padStart('abc', 6);
  13534. * // => ' abc'
  13535. *
  13536. * _.padStart('abc', 6, '_-');
  13537. * // => '_-_abc'
  13538. *
  13539. * _.padStart('abc', 3);
  13540. * // => 'abc'
  13541. */
  13542. function padStart(string, length, chars) {
  13543. string = toString(string);
  13544. length = toInteger(length);
  13545. var strLength = length ? stringSize(string) : 0;
  13546. return (length && strLength < length)
  13547. ? (createPadding(length - strLength, chars) + string)
  13548. : string;
  13549. }
  13550. /**
  13551. * Converts `string` to an integer of the specified radix. If `radix` is
  13552. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13553. * hexadecimal, in which case a `radix` of `16` is used.
  13554. *
  13555. * **Note:** This method aligns with the
  13556. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13557. *
  13558. * @static
  13559. * @memberOf _
  13560. * @since 1.1.0
  13561. * @category String
  13562. * @param {string} string The string to convert.
  13563. * @param {number} [radix=10] The radix to interpret `value` by.
  13564. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13565. * @returns {number} Returns the converted integer.
  13566. * @example
  13567. *
  13568. * _.parseInt('08');
  13569. * // => 8
  13570. *
  13571. * _.map(['6', '08', '10'], _.parseInt);
  13572. * // => [6, 8, 10]
  13573. */
  13574. function parseInt(string, radix, guard) {
  13575. if (guard || radix == null) {
  13576. radix = 0;
  13577. } else if (radix) {
  13578. radix = +radix;
  13579. }
  13580. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13581. }
  13582. /**
  13583. * Repeats the given string `n` times.
  13584. *
  13585. * @static
  13586. * @memberOf _
  13587. * @since 3.0.0
  13588. * @category String
  13589. * @param {string} [string=''] The string to repeat.
  13590. * @param {number} [n=1] The number of times to repeat the string.
  13591. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13592. * @returns {string} Returns the repeated string.
  13593. * @example
  13594. *
  13595. * _.repeat('*', 3);
  13596. * // => '***'
  13597. *
  13598. * _.repeat('abc', 2);
  13599. * // => 'abcabc'
  13600. *
  13601. * _.repeat('abc', 0);
  13602. * // => ''
  13603. */
  13604. function repeat(string, n, guard) {
  13605. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13606. n = 1;
  13607. } else {
  13608. n = toInteger(n);
  13609. }
  13610. return baseRepeat(toString(string), n);
  13611. }
  13612. /**
  13613. * Replaces matches for `pattern` in `string` with `replacement`.
  13614. *
  13615. * **Note:** This method is based on
  13616. * [`String#replace`](https://mdn.io/String/replace).
  13617. *
  13618. * @static
  13619. * @memberOf _
  13620. * @since 4.0.0
  13621. * @category String
  13622. * @param {string} [string=''] The string to modify.
  13623. * @param {RegExp|string} pattern The pattern to replace.
  13624. * @param {Function|string} replacement The match replacement.
  13625. * @returns {string} Returns the modified string.
  13626. * @example
  13627. *
  13628. * _.replace('Hi Fred', 'Fred', 'Barney');
  13629. * // => 'Hi Barney'
  13630. */
  13631. function replace() {
  13632. var args = arguments,
  13633. string = toString(args[0]);
  13634. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13635. }
  13636. /**
  13637. * Converts `string` to
  13638. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13639. *
  13640. * @static
  13641. * @memberOf _
  13642. * @since 3.0.0
  13643. * @category String
  13644. * @param {string} [string=''] The string to convert.
  13645. * @returns {string} Returns the snake cased string.
  13646. * @example
  13647. *
  13648. * _.snakeCase('Foo Bar');
  13649. * // => 'foo_bar'
  13650. *
  13651. * _.snakeCase('fooBar');
  13652. * // => 'foo_bar'
  13653. *
  13654. * _.snakeCase('--FOO-BAR--');
  13655. * // => 'foo_bar'
  13656. */
  13657. var snakeCase = createCompounder(function(result, word, index) {
  13658. return result + (index ? '_' : '') + word.toLowerCase();
  13659. });
  13660. /**
  13661. * Splits `string` by `separator`.
  13662. *
  13663. * **Note:** This method is based on
  13664. * [`String#split`](https://mdn.io/String/split).
  13665. *
  13666. * @static
  13667. * @memberOf _
  13668. * @since 4.0.0
  13669. * @category String
  13670. * @param {string} [string=''] The string to split.
  13671. * @param {RegExp|string} separator The separator pattern to split by.
  13672. * @param {number} [limit] The length to truncate results to.
  13673. * @returns {Array} Returns the string segments.
  13674. * @example
  13675. *
  13676. * _.split('a-b-c', '-', 2);
  13677. * // => ['a', 'b']
  13678. */
  13679. function split(string, separator, limit) {
  13680. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13681. separator = limit = undefined;
  13682. }
  13683. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13684. if (!limit) {
  13685. return [];
  13686. }
  13687. string = toString(string);
  13688. if (string && (
  13689. typeof separator == 'string' ||
  13690. (separator != null && !isRegExp(separator))
  13691. )) {
  13692. separator = baseToString(separator);
  13693. if (!separator && hasUnicode(string)) {
  13694. return castSlice(stringToArray(string), 0, limit);
  13695. }
  13696. }
  13697. return string.split(separator, limit);
  13698. }
  13699. /**
  13700. * Converts `string` to
  13701. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13702. *
  13703. * @static
  13704. * @memberOf _
  13705. * @since 3.1.0
  13706. * @category String
  13707. * @param {string} [string=''] The string to convert.
  13708. * @returns {string} Returns the start cased string.
  13709. * @example
  13710. *
  13711. * _.startCase('--foo-bar--');
  13712. * // => 'Foo Bar'
  13713. *
  13714. * _.startCase('fooBar');
  13715. * // => 'Foo Bar'
  13716. *
  13717. * _.startCase('__FOO_BAR__');
  13718. * // => 'FOO BAR'
  13719. */
  13720. var startCase = createCompounder(function(result, word, index) {
  13721. return result + (index ? ' ' : '') + upperFirst(word);
  13722. });
  13723. /**
  13724. * Checks if `string` starts with the given target string.
  13725. *
  13726. * @static
  13727. * @memberOf _
  13728. * @since 3.0.0
  13729. * @category String
  13730. * @param {string} [string=''] The string to inspect.
  13731. * @param {string} [target] The string to search for.
  13732. * @param {number} [position=0] The position to search from.
  13733. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13734. * else `false`.
  13735. * @example
  13736. *
  13737. * _.startsWith('abc', 'a');
  13738. * // => true
  13739. *
  13740. * _.startsWith('abc', 'b');
  13741. * // => false
  13742. *
  13743. * _.startsWith('abc', 'b', 1);
  13744. * // => true
  13745. */
  13746. function startsWith(string, target, position) {
  13747. string = toString(string);
  13748. position = position == null
  13749. ? 0
  13750. : baseClamp(toInteger(position), 0, string.length);
  13751. target = baseToString(target);
  13752. return string.slice(position, position + target.length) == target;
  13753. }
  13754. /**
  13755. * Creates a compiled template function that can interpolate data properties
  13756. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13757. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13758. * properties may be accessed as free variables in the template. If a setting
  13759. * object is given, it takes precedence over `_.templateSettings` values.
  13760. *
  13761. * **Note:** In the development build `_.template` utilizes
  13762. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13763. * for easier debugging.
  13764. *
  13765. * For more information on precompiling templates see
  13766. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13767. *
  13768. * For more information on Chrome extension sandboxes see
  13769. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13770. *
  13771. * @static
  13772. * @since 0.1.0
  13773. * @memberOf _
  13774. * @category String
  13775. * @param {string} [string=''] The template string.
  13776. * @param {Object} [options={}] The options object.
  13777. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13778. * The HTML "escape" delimiter.
  13779. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13780. * The "evaluate" delimiter.
  13781. * @param {Object} [options.imports=_.templateSettings.imports]
  13782. * An object to import into the template as free variables.
  13783. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13784. * The "interpolate" delimiter.
  13785. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13786. * The sourceURL of the compiled template.
  13787. * @param {string} [options.variable='obj']
  13788. * The data object variable name.
  13789. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13790. * @returns {Function} Returns the compiled template function.
  13791. * @example
  13792. *
  13793. * // Use the "interpolate" delimiter to create a compiled template.
  13794. * var compiled = _.template('hello <%= user %>!');
  13795. * compiled({ 'user': 'fred' });
  13796. * // => 'hello fred!'
  13797. *
  13798. * // Use the HTML "escape" delimiter to escape data property values.
  13799. * var compiled = _.template('<b><%- value %></b>');
  13800. * compiled({ 'value': '<script>' });
  13801. * // => '<b>&lt;script&gt;</b>'
  13802. *
  13803. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13804. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13805. * compiled({ 'users': ['fred', 'barney'] });
  13806. * // => '<li>fred</li><li>barney</li>'
  13807. *
  13808. * // Use the internal `print` function in "evaluate" delimiters.
  13809. * var compiled = _.template('<% print("hello " + user); %>!');
  13810. * compiled({ 'user': 'barney' });
  13811. * // => 'hello barney!'
  13812. *
  13813. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13814. * // Disable support by replacing the "interpolate" delimiter.
  13815. * var compiled = _.template('hello ${ user }!');
  13816. * compiled({ 'user': 'pebbles' });
  13817. * // => 'hello pebbles!'
  13818. *
  13819. * // Use backslashes to treat delimiters as plain text.
  13820. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13821. * compiled({ 'value': 'ignored' });
  13822. * // => '<%- value %>'
  13823. *
  13824. * // Use the `imports` option to import `jQuery` as `jq`.
  13825. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13826. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13827. * compiled({ 'users': ['fred', 'barney'] });
  13828. * // => '<li>fred</li><li>barney</li>'
  13829. *
  13830. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13831. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13832. * compiled(data);
  13833. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13834. *
  13835. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13836. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13837. * compiled.source;
  13838. * // => function(data) {
  13839. * // var __t, __p = '';
  13840. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13841. * // return __p;
  13842. * // }
  13843. *
  13844. * // Use custom template delimiters.
  13845. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13846. * var compiled = _.template('hello {{ user }}!');
  13847. * compiled({ 'user': 'mustache' });
  13848. * // => 'hello mustache!'
  13849. *
  13850. * // Use the `source` property to inline compiled templates for meaningful
  13851. * // line numbers in error messages and stack traces.
  13852. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13853. * var JST = {\
  13854. * "main": ' + _.template(mainText).source + '\
  13855. * };\
  13856. * ');
  13857. */
  13858. function template(string, options, guard) {
  13859. // Based on John Resig's `tmpl` implementation
  13860. // (http://ejohn.org/blog/javascript-micro-templating/)
  13861. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13862. var settings = lodash.templateSettings;
  13863. if (guard && isIterateeCall(string, options, guard)) {
  13864. options = undefined;
  13865. }
  13866. string = toString(string);
  13867. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13868. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13869. importsKeys = keys(imports),
  13870. importsValues = baseValues(imports, importsKeys);
  13871. var isEscaping,
  13872. isEvaluating,
  13873. index = 0,
  13874. interpolate = options.interpolate || reNoMatch,
  13875. source = "__p += '";
  13876. // Compile the regexp to match each delimiter.
  13877. var reDelimiters = RegExp(
  13878. (options.escape || reNoMatch).source + '|' +
  13879. interpolate.source + '|' +
  13880. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13881. (options.evaluate || reNoMatch).source + '|$'
  13882. , 'g');
  13883. // Use a sourceURL for easier debugging.
  13884. var sourceURL = '//# sourceURL=' +
  13885. ('sourceURL' in options
  13886. ? options.sourceURL
  13887. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13888. ) + '\n';
  13889. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13890. interpolateValue || (interpolateValue = esTemplateValue);
  13891. // Escape characters that can't be included in string literals.
  13892. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13893. // Replace delimiters with snippets.
  13894. if (escapeValue) {
  13895. isEscaping = true;
  13896. source += "' +\n__e(" + escapeValue + ") +\n'";
  13897. }
  13898. if (evaluateValue) {
  13899. isEvaluating = true;
  13900. source += "';\n" + evaluateValue + ";\n__p += '";
  13901. }
  13902. if (interpolateValue) {
  13903. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13904. }
  13905. index = offset + match.length;
  13906. // The JS engine embedded in Adobe products needs `match` returned in
  13907. // order to produce the correct `offset` value.
  13908. return match;
  13909. });
  13910. source += "';\n";
  13911. // If `variable` is not specified wrap a with-statement around the generated
  13912. // code to add the data object to the top of the scope chain.
  13913. var variable = options.variable;
  13914. if (!variable) {
  13915. source = 'with (obj) {\n' + source + '\n}\n';
  13916. }
  13917. // Cleanup code by stripping empty strings.
  13918. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13919. .replace(reEmptyStringMiddle, '$1')
  13920. .replace(reEmptyStringTrailing, '$1;');
  13921. // Frame code as the function body.
  13922. source = 'function(' + (variable || 'obj') + ') {\n' +
  13923. (variable
  13924. ? ''
  13925. : 'obj || (obj = {});\n'
  13926. ) +
  13927. "var __t, __p = ''" +
  13928. (isEscaping
  13929. ? ', __e = _.escape'
  13930. : ''
  13931. ) +
  13932. (isEvaluating
  13933. ? ', __j = Array.prototype.join;\n' +
  13934. "function print() { __p += __j.call(arguments, '') }\n"
  13935. : ';\n'
  13936. ) +
  13937. source +
  13938. 'return __p\n}';
  13939. var result = attempt(function() {
  13940. return Function(importsKeys, sourceURL + 'return ' + source)
  13941. .apply(undefined, importsValues);
  13942. });
  13943. // Provide the compiled function's source by its `toString` method or
  13944. // the `source` property as a convenience for inlining compiled templates.
  13945. result.source = source;
  13946. if (isError(result)) {
  13947. throw result;
  13948. }
  13949. return result;
  13950. }
  13951. /**
  13952. * Converts `string`, as a whole, to lower case just like
  13953. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13954. *
  13955. * @static
  13956. * @memberOf _
  13957. * @since 4.0.0
  13958. * @category String
  13959. * @param {string} [string=''] The string to convert.
  13960. * @returns {string} Returns the lower cased string.
  13961. * @example
  13962. *
  13963. * _.toLower('--Foo-Bar--');
  13964. * // => '--foo-bar--'
  13965. *
  13966. * _.toLower('fooBar');
  13967. * // => 'foobar'
  13968. *
  13969. * _.toLower('__FOO_BAR__');
  13970. * // => '__foo_bar__'
  13971. */
  13972. function toLower(value) {
  13973. return toString(value).toLowerCase();
  13974. }
  13975. /**
  13976. * Converts `string`, as a whole, to upper case just like
  13977. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13978. *
  13979. * @static
  13980. * @memberOf _
  13981. * @since 4.0.0
  13982. * @category String
  13983. * @param {string} [string=''] The string to convert.
  13984. * @returns {string} Returns the upper cased string.
  13985. * @example
  13986. *
  13987. * _.toUpper('--foo-bar--');
  13988. * // => '--FOO-BAR--'
  13989. *
  13990. * _.toUpper('fooBar');
  13991. * // => 'FOOBAR'
  13992. *
  13993. * _.toUpper('__foo_bar__');
  13994. * // => '__FOO_BAR__'
  13995. */
  13996. function toUpper(value) {
  13997. return toString(value).toUpperCase();
  13998. }
  13999. /**
  14000. * Removes leading and trailing whitespace or specified characters from `string`.
  14001. *
  14002. * @static
  14003. * @memberOf _
  14004. * @since 3.0.0
  14005. * @category String
  14006. * @param {string} [string=''] The string to trim.
  14007. * @param {string} [chars=whitespace] The characters to trim.
  14008. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14009. * @returns {string} Returns the trimmed string.
  14010. * @example
  14011. *
  14012. * _.trim(' abc ');
  14013. * // => 'abc'
  14014. *
  14015. * _.trim('-_-abc-_-', '_-');
  14016. * // => 'abc'
  14017. *
  14018. * _.map([' foo ', ' bar '], _.trim);
  14019. * // => ['foo', 'bar']
  14020. */
  14021. function trim(string, chars, guard) {
  14022. string = toString(string);
  14023. if (string && (guard || chars === undefined)) {
  14024. return string.replace(reTrim, '');
  14025. }
  14026. if (!string || !(chars = baseToString(chars))) {
  14027. return string;
  14028. }
  14029. var strSymbols = stringToArray(string),
  14030. chrSymbols = stringToArray(chars),
  14031. start = charsStartIndex(strSymbols, chrSymbols),
  14032. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14033. return castSlice(strSymbols, start, end).join('');
  14034. }
  14035. /**
  14036. * Removes trailing whitespace or specified characters from `string`.
  14037. *
  14038. * @static
  14039. * @memberOf _
  14040. * @since 4.0.0
  14041. * @category String
  14042. * @param {string} [string=''] The string to trim.
  14043. * @param {string} [chars=whitespace] The characters to trim.
  14044. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14045. * @returns {string} Returns the trimmed string.
  14046. * @example
  14047. *
  14048. * _.trimEnd(' abc ');
  14049. * // => ' abc'
  14050. *
  14051. * _.trimEnd('-_-abc-_-', '_-');
  14052. * // => '-_-abc'
  14053. */
  14054. function trimEnd(string, chars, guard) {
  14055. string = toString(string);
  14056. if (string && (guard || chars === undefined)) {
  14057. return string.replace(reTrimEnd, '');
  14058. }
  14059. if (!string || !(chars = baseToString(chars))) {
  14060. return string;
  14061. }
  14062. var strSymbols = stringToArray(string),
  14063. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14064. return castSlice(strSymbols, 0, end).join('');
  14065. }
  14066. /**
  14067. * Removes leading whitespace or specified characters from `string`.
  14068. *
  14069. * @static
  14070. * @memberOf _
  14071. * @since 4.0.0
  14072. * @category String
  14073. * @param {string} [string=''] The string to trim.
  14074. * @param {string} [chars=whitespace] The characters to trim.
  14075. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14076. * @returns {string} Returns the trimmed string.
  14077. * @example
  14078. *
  14079. * _.trimStart(' abc ');
  14080. * // => 'abc '
  14081. *
  14082. * _.trimStart('-_-abc-_-', '_-');
  14083. * // => 'abc-_-'
  14084. */
  14085. function trimStart(string, chars, guard) {
  14086. string = toString(string);
  14087. if (string && (guard || chars === undefined)) {
  14088. return string.replace(reTrimStart, '');
  14089. }
  14090. if (!string || !(chars = baseToString(chars))) {
  14091. return string;
  14092. }
  14093. var strSymbols = stringToArray(string),
  14094. start = charsStartIndex(strSymbols, stringToArray(chars));
  14095. return castSlice(strSymbols, start).join('');
  14096. }
  14097. /**
  14098. * Truncates `string` if it's longer than the given maximum string length.
  14099. * The last characters of the truncated string are replaced with the omission
  14100. * string which defaults to "...".
  14101. *
  14102. * @static
  14103. * @memberOf _
  14104. * @since 4.0.0
  14105. * @category String
  14106. * @param {string} [string=''] The string to truncate.
  14107. * @param {Object} [options={}] The options object.
  14108. * @param {number} [options.length=30] The maximum string length.
  14109. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14110. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14111. * @returns {string} Returns the truncated string.
  14112. * @example
  14113. *
  14114. * _.truncate('hi-diddly-ho there, neighborino');
  14115. * // => 'hi-diddly-ho there, neighbo...'
  14116. *
  14117. * _.truncate('hi-diddly-ho there, neighborino', {
  14118. * 'length': 24,
  14119. * 'separator': ' '
  14120. * });
  14121. * // => 'hi-diddly-ho there,...'
  14122. *
  14123. * _.truncate('hi-diddly-ho there, neighborino', {
  14124. * 'length': 24,
  14125. * 'separator': /,? +/
  14126. * });
  14127. * // => 'hi-diddly-ho there...'
  14128. *
  14129. * _.truncate('hi-diddly-ho there, neighborino', {
  14130. * 'omission': ' [...]'
  14131. * });
  14132. * // => 'hi-diddly-ho there, neig [...]'
  14133. */
  14134. function truncate(string, options) {
  14135. var length = DEFAULT_TRUNC_LENGTH,
  14136. omission = DEFAULT_TRUNC_OMISSION;
  14137. if (isObject(options)) {
  14138. var separator = 'separator' in options ? options.separator : separator;
  14139. length = 'length' in options ? toInteger(options.length) : length;
  14140. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14141. }
  14142. string = toString(string);
  14143. var strLength = string.length;
  14144. if (hasUnicode(string)) {
  14145. var strSymbols = stringToArray(string);
  14146. strLength = strSymbols.length;
  14147. }
  14148. if (length >= strLength) {
  14149. return string;
  14150. }
  14151. var end = length - stringSize(omission);
  14152. if (end < 1) {
  14153. return omission;
  14154. }
  14155. var result = strSymbols
  14156. ? castSlice(strSymbols, 0, end).join('')
  14157. : string.slice(0, end);
  14158. if (separator === undefined) {
  14159. return result + omission;
  14160. }
  14161. if (strSymbols) {
  14162. end += (result.length - end);
  14163. }
  14164. if (isRegExp(separator)) {
  14165. if (string.slice(end).search(separator)) {
  14166. var match,
  14167. substring = result;
  14168. if (!separator.global) {
  14169. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14170. }
  14171. separator.lastIndex = 0;
  14172. while ((match = separator.exec(substring))) {
  14173. var newEnd = match.index;
  14174. }
  14175. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14176. }
  14177. } else if (string.indexOf(baseToString(separator), end) != end) {
  14178. var index = result.lastIndexOf(separator);
  14179. if (index > -1) {
  14180. result = result.slice(0, index);
  14181. }
  14182. }
  14183. return result + omission;
  14184. }
  14185. /**
  14186. * The inverse of `_.escape`; this method converts the HTML entities
  14187. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14188. * their corresponding characters.
  14189. *
  14190. * **Note:** No other HTML entities are unescaped. To unescape additional
  14191. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14192. *
  14193. * @static
  14194. * @memberOf _
  14195. * @since 0.6.0
  14196. * @category String
  14197. * @param {string} [string=''] The string to unescape.
  14198. * @returns {string} Returns the unescaped string.
  14199. * @example
  14200. *
  14201. * _.unescape('fred, barney, &amp; pebbles');
  14202. * // => 'fred, barney, & pebbles'
  14203. */
  14204. function unescape(string) {
  14205. string = toString(string);
  14206. return (string && reHasEscapedHtml.test(string))
  14207. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14208. : string;
  14209. }
  14210. /**
  14211. * Converts `string`, as space separated words, to upper case.
  14212. *
  14213. * @static
  14214. * @memberOf _
  14215. * @since 4.0.0
  14216. * @category String
  14217. * @param {string} [string=''] The string to convert.
  14218. * @returns {string} Returns the upper cased string.
  14219. * @example
  14220. *
  14221. * _.upperCase('--foo-bar');
  14222. * // => 'FOO BAR'
  14223. *
  14224. * _.upperCase('fooBar');
  14225. * // => 'FOO BAR'
  14226. *
  14227. * _.upperCase('__foo_bar__');
  14228. * // => 'FOO BAR'
  14229. */
  14230. var upperCase = createCompounder(function(result, word, index) {
  14231. return result + (index ? ' ' : '') + word.toUpperCase();
  14232. });
  14233. /**
  14234. * Converts the first character of `string` to upper case.
  14235. *
  14236. * @static
  14237. * @memberOf _
  14238. * @since 4.0.0
  14239. * @category String
  14240. * @param {string} [string=''] The string to convert.
  14241. * @returns {string} Returns the converted string.
  14242. * @example
  14243. *
  14244. * _.upperFirst('fred');
  14245. * // => 'Fred'
  14246. *
  14247. * _.upperFirst('FRED');
  14248. * // => 'FRED'
  14249. */
  14250. var upperFirst = createCaseFirst('toUpperCase');
  14251. /**
  14252. * Splits `string` into an array of its words.
  14253. *
  14254. * @static
  14255. * @memberOf _
  14256. * @since 3.0.0
  14257. * @category String
  14258. * @param {string} [string=''] The string to inspect.
  14259. * @param {RegExp|string} [pattern] The pattern to match words.
  14260. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14261. * @returns {Array} Returns the words of `string`.
  14262. * @example
  14263. *
  14264. * _.words('fred, barney, & pebbles');
  14265. * // => ['fred', 'barney', 'pebbles']
  14266. *
  14267. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14268. * // => ['fred', 'barney', '&', 'pebbles']
  14269. */
  14270. function words(string, pattern, guard) {
  14271. string = toString(string);
  14272. pattern = guard ? undefined : pattern;
  14273. if (pattern === undefined) {
  14274. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14275. }
  14276. return string.match(pattern) || [];
  14277. }
  14278. /*------------------------------------------------------------------------*/
  14279. /**
  14280. * Attempts to invoke `func`, returning either the result or the caught error
  14281. * object. Any additional arguments are provided to `func` when it's invoked.
  14282. *
  14283. * @static
  14284. * @memberOf _
  14285. * @since 3.0.0
  14286. * @category Util
  14287. * @param {Function} func The function to attempt.
  14288. * @param {...*} [args] The arguments to invoke `func` with.
  14289. * @returns {*} Returns the `func` result or error object.
  14290. * @example
  14291. *
  14292. * // Avoid throwing errors for invalid selectors.
  14293. * var elements = _.attempt(function(selector) {
  14294. * return document.querySelectorAll(selector);
  14295. * }, '>_>');
  14296. *
  14297. * if (_.isError(elements)) {
  14298. * elements = [];
  14299. * }
  14300. */
  14301. var attempt = baseRest(function(func, args) {
  14302. try {
  14303. return apply(func, undefined, args);
  14304. } catch (e) {
  14305. return isError(e) ? e : new Error(e);
  14306. }
  14307. });
  14308. /**
  14309. * Binds methods of an object to the object itself, overwriting the existing
  14310. * method.
  14311. *
  14312. * **Note:** This method doesn't set the "length" property of bound functions.
  14313. *
  14314. * @static
  14315. * @since 0.1.0
  14316. * @memberOf _
  14317. * @category Util
  14318. * @param {Object} object The object to bind and assign the bound methods to.
  14319. * @param {...(string|string[])} methodNames The object method names to bind.
  14320. * @returns {Object} Returns `object`.
  14321. * @example
  14322. *
  14323. * var view = {
  14324. * 'label': 'docs',
  14325. * 'click': function() {
  14326. * console.log('clicked ' + this.label);
  14327. * }
  14328. * };
  14329. *
  14330. * _.bindAll(view, ['click']);
  14331. * jQuery(element).on('click', view.click);
  14332. * // => Logs 'clicked docs' when clicked.
  14333. */
  14334. var bindAll = flatRest(function(object, methodNames) {
  14335. arrayEach(methodNames, function(key) {
  14336. key = toKey(key);
  14337. baseAssignValue(object, key, bind(object[key], object));
  14338. });
  14339. return object;
  14340. });
  14341. /**
  14342. * Creates a function that iterates over `pairs` and invokes the corresponding
  14343. * function of the first predicate to return truthy. The predicate-function
  14344. * pairs are invoked with the `this` binding and arguments of the created
  14345. * function.
  14346. *
  14347. * @static
  14348. * @memberOf _
  14349. * @since 4.0.0
  14350. * @category Util
  14351. * @param {Array} pairs The predicate-function pairs.
  14352. * @returns {Function} Returns the new composite function.
  14353. * @example
  14354. *
  14355. * var func = _.cond([
  14356. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14357. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14358. * [_.stubTrue, _.constant('no match')]
  14359. * ]);
  14360. *
  14361. * func({ 'a': 1, 'b': 2 });
  14362. * // => 'matches A'
  14363. *
  14364. * func({ 'a': 0, 'b': 1 });
  14365. * // => 'matches B'
  14366. *
  14367. * func({ 'a': '1', 'b': '2' });
  14368. * // => 'no match'
  14369. */
  14370. function cond(pairs) {
  14371. var length = pairs == null ? 0 : pairs.length,
  14372. toIteratee = getIteratee();
  14373. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14374. if (typeof pair[1] != 'function') {
  14375. throw new TypeError(FUNC_ERROR_TEXT);
  14376. }
  14377. return [toIteratee(pair[0]), pair[1]];
  14378. });
  14379. return baseRest(function(args) {
  14380. var index = -1;
  14381. while (++index < length) {
  14382. var pair = pairs[index];
  14383. if (apply(pair[0], this, args)) {
  14384. return apply(pair[1], this, args);
  14385. }
  14386. }
  14387. });
  14388. }
  14389. /**
  14390. * Creates a function that invokes the predicate properties of `source` with
  14391. * the corresponding property values of a given object, returning `true` if
  14392. * all predicates return truthy, else `false`.
  14393. *
  14394. * **Note:** The created function is equivalent to `_.conformsTo` with
  14395. * `source` partially applied.
  14396. *
  14397. * @static
  14398. * @memberOf _
  14399. * @since 4.0.0
  14400. * @category Util
  14401. * @param {Object} source The object of property predicates to conform to.
  14402. * @returns {Function} Returns the new spec function.
  14403. * @example
  14404. *
  14405. * var objects = [
  14406. * { 'a': 2, 'b': 1 },
  14407. * { 'a': 1, 'b': 2 }
  14408. * ];
  14409. *
  14410. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14411. * // => [{ 'a': 1, 'b': 2 }]
  14412. */
  14413. function conforms(source) {
  14414. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14415. }
  14416. /**
  14417. * Creates a function that returns `value`.
  14418. *
  14419. * @static
  14420. * @memberOf _
  14421. * @since 2.4.0
  14422. * @category Util
  14423. * @param {*} value The value to return from the new function.
  14424. * @returns {Function} Returns the new constant function.
  14425. * @example
  14426. *
  14427. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14428. *
  14429. * console.log(objects);
  14430. * // => [{ 'a': 1 }, { 'a': 1 }]
  14431. *
  14432. * console.log(objects[0] === objects[1]);
  14433. * // => true
  14434. */
  14435. function constant(value) {
  14436. return function() {
  14437. return value;
  14438. };
  14439. }
  14440. /**
  14441. * Checks `value` to determine whether a default value should be returned in
  14442. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14443. * or `undefined`.
  14444. *
  14445. * @static
  14446. * @memberOf _
  14447. * @since 4.14.0
  14448. * @category Util
  14449. * @param {*} value The value to check.
  14450. * @param {*} defaultValue The default value.
  14451. * @returns {*} Returns the resolved value.
  14452. * @example
  14453. *
  14454. * _.defaultTo(1, 10);
  14455. * // => 1
  14456. *
  14457. * _.defaultTo(undefined, 10);
  14458. * // => 10
  14459. */
  14460. function defaultTo(value, defaultValue) {
  14461. return (value == null || value !== value) ? defaultValue : value;
  14462. }
  14463. /**
  14464. * Creates a function that returns the result of invoking the given functions
  14465. * with the `this` binding of the created function, where each successive
  14466. * invocation is supplied the return value of the previous.
  14467. *
  14468. * @static
  14469. * @memberOf _
  14470. * @since 3.0.0
  14471. * @category Util
  14472. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14473. * @returns {Function} Returns the new composite function.
  14474. * @see _.flowRight
  14475. * @example
  14476. *
  14477. * function square(n) {
  14478. * return n * n;
  14479. * }
  14480. *
  14481. * var addSquare = _.flow([_.add, square]);
  14482. * addSquare(1, 2);
  14483. * // => 9
  14484. */
  14485. var flow = createFlow();
  14486. /**
  14487. * This method is like `_.flow` except that it creates a function that
  14488. * invokes the given functions from right to left.
  14489. *
  14490. * @static
  14491. * @since 3.0.0
  14492. * @memberOf _
  14493. * @category Util
  14494. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14495. * @returns {Function} Returns the new composite function.
  14496. * @see _.flow
  14497. * @example
  14498. *
  14499. * function square(n) {
  14500. * return n * n;
  14501. * }
  14502. *
  14503. * var addSquare = _.flowRight([square, _.add]);
  14504. * addSquare(1, 2);
  14505. * // => 9
  14506. */
  14507. var flowRight = createFlow(true);
  14508. /**
  14509. * This method returns the first argument it receives.
  14510. *
  14511. * @static
  14512. * @since 0.1.0
  14513. * @memberOf _
  14514. * @category Util
  14515. * @param {*} value Any value.
  14516. * @returns {*} Returns `value`.
  14517. * @example
  14518. *
  14519. * var object = { 'a': 1 };
  14520. *
  14521. * console.log(_.identity(object) === object);
  14522. * // => true
  14523. */
  14524. function identity(value) {
  14525. return value;
  14526. }
  14527. /**
  14528. * Creates a function that invokes `func` with the arguments of the created
  14529. * function. If `func` is a property name, the created function returns the
  14530. * property value for a given element. If `func` is an array or object, the
  14531. * created function returns `true` for elements that contain the equivalent
  14532. * source properties, otherwise it returns `false`.
  14533. *
  14534. * @static
  14535. * @since 4.0.0
  14536. * @memberOf _
  14537. * @category Util
  14538. * @param {*} [func=_.identity] The value to convert to a callback.
  14539. * @returns {Function} Returns the callback.
  14540. * @example
  14541. *
  14542. * var users = [
  14543. * { 'user': 'barney', 'age': 36, 'active': true },
  14544. * { 'user': 'fred', 'age': 40, 'active': false }
  14545. * ];
  14546. *
  14547. * // The `_.matches` iteratee shorthand.
  14548. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14549. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14550. *
  14551. * // The `_.matchesProperty` iteratee shorthand.
  14552. * _.filter(users, _.iteratee(['user', 'fred']));
  14553. * // => [{ 'user': 'fred', 'age': 40 }]
  14554. *
  14555. * // The `_.property` iteratee shorthand.
  14556. * _.map(users, _.iteratee('user'));
  14557. * // => ['barney', 'fred']
  14558. *
  14559. * // Create custom iteratee shorthands.
  14560. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14561. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14562. * return func.test(string);
  14563. * };
  14564. * });
  14565. *
  14566. * _.filter(['abc', 'def'], /ef/);
  14567. * // => ['def']
  14568. */
  14569. function iteratee(func) {
  14570. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14571. }
  14572. /**
  14573. * Creates a function that performs a partial deep comparison between a given
  14574. * object and `source`, returning `true` if the given object has equivalent
  14575. * property values, else `false`.
  14576. *
  14577. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14578. * partially applied.
  14579. *
  14580. * Partial comparisons will match empty array and empty object `source`
  14581. * values against any array or object value, respectively. See `_.isEqual`
  14582. * for a list of supported value comparisons.
  14583. *
  14584. * @static
  14585. * @memberOf _
  14586. * @since 3.0.0
  14587. * @category Util
  14588. * @param {Object} source The object of property values to match.
  14589. * @returns {Function} Returns the new spec function.
  14590. * @example
  14591. *
  14592. * var objects = [
  14593. * { 'a': 1, 'b': 2, 'c': 3 },
  14594. * { 'a': 4, 'b': 5, 'c': 6 }
  14595. * ];
  14596. *
  14597. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14598. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14599. */
  14600. function matches(source) {
  14601. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14602. }
  14603. /**
  14604. * Creates a function that performs a partial deep comparison between the
  14605. * value at `path` of a given object to `srcValue`, returning `true` if the
  14606. * object value is equivalent, else `false`.
  14607. *
  14608. * **Note:** Partial comparisons will match empty array and empty object
  14609. * `srcValue` values against any array or object value, respectively. See
  14610. * `_.isEqual` for a list of supported value comparisons.
  14611. *
  14612. * @static
  14613. * @memberOf _
  14614. * @since 3.2.0
  14615. * @category Util
  14616. * @param {Array|string} path The path of the property to get.
  14617. * @param {*} srcValue The value to match.
  14618. * @returns {Function} Returns the new spec function.
  14619. * @example
  14620. *
  14621. * var objects = [
  14622. * { 'a': 1, 'b': 2, 'c': 3 },
  14623. * { 'a': 4, 'b': 5, 'c': 6 }
  14624. * ];
  14625. *
  14626. * _.find(objects, _.matchesProperty('a', 4));
  14627. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14628. */
  14629. function matchesProperty(path, srcValue) {
  14630. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14631. }
  14632. /**
  14633. * Creates a function that invokes the method at `path` of a given object.
  14634. * Any additional arguments are provided to the invoked method.
  14635. *
  14636. * @static
  14637. * @memberOf _
  14638. * @since 3.7.0
  14639. * @category Util
  14640. * @param {Array|string} path The path of the method to invoke.
  14641. * @param {...*} [args] The arguments to invoke the method with.
  14642. * @returns {Function} Returns the new invoker function.
  14643. * @example
  14644. *
  14645. * var objects = [
  14646. * { 'a': { 'b': _.constant(2) } },
  14647. * { 'a': { 'b': _.constant(1) } }
  14648. * ];
  14649. *
  14650. * _.map(objects, _.method('a.b'));
  14651. * // => [2, 1]
  14652. *
  14653. * _.map(objects, _.method(['a', 'b']));
  14654. * // => [2, 1]
  14655. */
  14656. var method = baseRest(function(path, args) {
  14657. return function(object) {
  14658. return baseInvoke(object, path, args);
  14659. };
  14660. });
  14661. /**
  14662. * The opposite of `_.method`; this method creates a function that invokes
  14663. * the method at a given path of `object`. Any additional arguments are
  14664. * provided to the invoked method.
  14665. *
  14666. * @static
  14667. * @memberOf _
  14668. * @since 3.7.0
  14669. * @category Util
  14670. * @param {Object} object The object to query.
  14671. * @param {...*} [args] The arguments to invoke the method with.
  14672. * @returns {Function} Returns the new invoker function.
  14673. * @example
  14674. *
  14675. * var array = _.times(3, _.constant),
  14676. * object = { 'a': array, 'b': array, 'c': array };
  14677. *
  14678. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14679. * // => [2, 0]
  14680. *
  14681. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14682. * // => [2, 0]
  14683. */
  14684. var methodOf = baseRest(function(object, args) {
  14685. return function(path) {
  14686. return baseInvoke(object, path, args);
  14687. };
  14688. });
  14689. /**
  14690. * Adds all own enumerable string keyed function properties of a source
  14691. * object to the destination object. If `object` is a function, then methods
  14692. * are added to its prototype as well.
  14693. *
  14694. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14695. * avoid conflicts caused by modifying the original.
  14696. *
  14697. * @static
  14698. * @since 0.1.0
  14699. * @memberOf _
  14700. * @category Util
  14701. * @param {Function|Object} [object=lodash] The destination object.
  14702. * @param {Object} source The object of functions to add.
  14703. * @param {Object} [options={}] The options object.
  14704. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14705. * @returns {Function|Object} Returns `object`.
  14706. * @example
  14707. *
  14708. * function vowels(string) {
  14709. * return _.filter(string, function(v) {
  14710. * return /[aeiou]/i.test(v);
  14711. * });
  14712. * }
  14713. *
  14714. * _.mixin({ 'vowels': vowels });
  14715. * _.vowels('fred');
  14716. * // => ['e']
  14717. *
  14718. * _('fred').vowels().value();
  14719. * // => ['e']
  14720. *
  14721. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14722. * _('fred').vowels();
  14723. * // => ['e']
  14724. */
  14725. function mixin(object, source, options) {
  14726. var props = keys(source),
  14727. methodNames = baseFunctions(source, props);
  14728. if (options == null &&
  14729. !(isObject(source) && (methodNames.length || !props.length))) {
  14730. options = source;
  14731. source = object;
  14732. object = this;
  14733. methodNames = baseFunctions(source, keys(source));
  14734. }
  14735. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14736. isFunc = isFunction(object);
  14737. arrayEach(methodNames, function(methodName) {
  14738. var func = source[methodName];
  14739. object[methodName] = func;
  14740. if (isFunc) {
  14741. object.prototype[methodName] = function() {
  14742. var chainAll = this.__chain__;
  14743. if (chain || chainAll) {
  14744. var result = object(this.__wrapped__),
  14745. actions = result.__actions__ = copyArray(this.__actions__);
  14746. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14747. result.__chain__ = chainAll;
  14748. return result;
  14749. }
  14750. return func.apply(object, arrayPush([this.value()], arguments));
  14751. };
  14752. }
  14753. });
  14754. return object;
  14755. }
  14756. /**
  14757. * Reverts the `_` variable to its previous value and returns a reference to
  14758. * the `lodash` function.
  14759. *
  14760. * @static
  14761. * @since 0.1.0
  14762. * @memberOf _
  14763. * @category Util
  14764. * @returns {Function} Returns the `lodash` function.
  14765. * @example
  14766. *
  14767. * var lodash = _.noConflict();
  14768. */
  14769. function noConflict() {
  14770. if (root._ === this) {
  14771. root._ = oldDash;
  14772. }
  14773. return this;
  14774. }
  14775. /**
  14776. * This method returns `undefined`.
  14777. *
  14778. * @static
  14779. * @memberOf _
  14780. * @since 2.3.0
  14781. * @category Util
  14782. * @example
  14783. *
  14784. * _.times(2, _.noop);
  14785. * // => [undefined, undefined]
  14786. */
  14787. function noop() {
  14788. // No operation performed.
  14789. }
  14790. /**
  14791. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14792. * the nth argument from the end is returned.
  14793. *
  14794. * @static
  14795. * @memberOf _
  14796. * @since 4.0.0
  14797. * @category Util
  14798. * @param {number} [n=0] The index of the argument to return.
  14799. * @returns {Function} Returns the new pass-thru function.
  14800. * @example
  14801. *
  14802. * var func = _.nthArg(1);
  14803. * func('a', 'b', 'c', 'd');
  14804. * // => 'b'
  14805. *
  14806. * var func = _.nthArg(-2);
  14807. * func('a', 'b', 'c', 'd');
  14808. * // => 'c'
  14809. */
  14810. function nthArg(n) {
  14811. n = toInteger(n);
  14812. return baseRest(function(args) {
  14813. return baseNth(args, n);
  14814. });
  14815. }
  14816. /**
  14817. * Creates a function that invokes `iteratees` with the arguments it receives
  14818. * and returns their results.
  14819. *
  14820. * @static
  14821. * @memberOf _
  14822. * @since 4.0.0
  14823. * @category Util
  14824. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14825. * The iteratees to invoke.
  14826. * @returns {Function} Returns the new function.
  14827. * @example
  14828. *
  14829. * var func = _.over([Math.max, Math.min]);
  14830. *
  14831. * func(1, 2, 3, 4);
  14832. * // => [4, 1]
  14833. */
  14834. var over = createOver(arrayMap);
  14835. /**
  14836. * Creates a function that checks if **all** of the `predicates` return
  14837. * truthy when invoked with the arguments it receives.
  14838. *
  14839. * @static
  14840. * @memberOf _
  14841. * @since 4.0.0
  14842. * @category Util
  14843. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14844. * The predicates to check.
  14845. * @returns {Function} Returns the new function.
  14846. * @example
  14847. *
  14848. * var func = _.overEvery([Boolean, isFinite]);
  14849. *
  14850. * func('1');
  14851. * // => true
  14852. *
  14853. * func(null);
  14854. * // => false
  14855. *
  14856. * func(NaN);
  14857. * // => false
  14858. */
  14859. var overEvery = createOver(arrayEvery);
  14860. /**
  14861. * Creates a function that checks if **any** of the `predicates` return
  14862. * truthy when invoked with the arguments it receives.
  14863. *
  14864. * @static
  14865. * @memberOf _
  14866. * @since 4.0.0
  14867. * @category Util
  14868. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14869. * The predicates to check.
  14870. * @returns {Function} Returns the new function.
  14871. * @example
  14872. *
  14873. * var func = _.overSome([Boolean, isFinite]);
  14874. *
  14875. * func('1');
  14876. * // => true
  14877. *
  14878. * func(null);
  14879. * // => true
  14880. *
  14881. * func(NaN);
  14882. * // => false
  14883. */
  14884. var overSome = createOver(arraySome);
  14885. /**
  14886. * Creates a function that returns the value at `path` of a given object.
  14887. *
  14888. * @static
  14889. * @memberOf _
  14890. * @since 2.4.0
  14891. * @category Util
  14892. * @param {Array|string} path The path of the property to get.
  14893. * @returns {Function} Returns the new accessor function.
  14894. * @example
  14895. *
  14896. * var objects = [
  14897. * { 'a': { 'b': 2 } },
  14898. * { 'a': { 'b': 1 } }
  14899. * ];
  14900. *
  14901. * _.map(objects, _.property('a.b'));
  14902. * // => [2, 1]
  14903. *
  14904. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14905. * // => [1, 2]
  14906. */
  14907. function property(path) {
  14908. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14909. }
  14910. /**
  14911. * The opposite of `_.property`; this method creates a function that returns
  14912. * the value at a given path of `object`.
  14913. *
  14914. * @static
  14915. * @memberOf _
  14916. * @since 3.0.0
  14917. * @category Util
  14918. * @param {Object} object The object to query.
  14919. * @returns {Function} Returns the new accessor function.
  14920. * @example
  14921. *
  14922. * var array = [0, 1, 2],
  14923. * object = { 'a': array, 'b': array, 'c': array };
  14924. *
  14925. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14926. * // => [2, 0]
  14927. *
  14928. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14929. * // => [2, 0]
  14930. */
  14931. function propertyOf(object) {
  14932. return function(path) {
  14933. return object == null ? undefined : baseGet(object, path);
  14934. };
  14935. }
  14936. /**
  14937. * Creates an array of numbers (positive and/or negative) progressing from
  14938. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14939. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14940. * it's set to `start` with `start` then set to `0`.
  14941. *
  14942. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14943. * floating-point values which can produce unexpected results.
  14944. *
  14945. * @static
  14946. * @since 0.1.0
  14947. * @memberOf _
  14948. * @category Util
  14949. * @param {number} [start=0] The start of the range.
  14950. * @param {number} end The end of the range.
  14951. * @param {number} [step=1] The value to increment or decrement by.
  14952. * @returns {Array} Returns the range of numbers.
  14953. * @see _.inRange, _.rangeRight
  14954. * @example
  14955. *
  14956. * _.range(4);
  14957. * // => [0, 1, 2, 3]
  14958. *
  14959. * _.range(-4);
  14960. * // => [0, -1, -2, -3]
  14961. *
  14962. * _.range(1, 5);
  14963. * // => [1, 2, 3, 4]
  14964. *
  14965. * _.range(0, 20, 5);
  14966. * // => [0, 5, 10, 15]
  14967. *
  14968. * _.range(0, -4, -1);
  14969. * // => [0, -1, -2, -3]
  14970. *
  14971. * _.range(1, 4, 0);
  14972. * // => [1, 1, 1]
  14973. *
  14974. * _.range(0);
  14975. * // => []
  14976. */
  14977. var range = createRange();
  14978. /**
  14979. * This method is like `_.range` except that it populates values in
  14980. * descending order.
  14981. *
  14982. * @static
  14983. * @memberOf _
  14984. * @since 4.0.0
  14985. * @category Util
  14986. * @param {number} [start=0] The start of the range.
  14987. * @param {number} end The end of the range.
  14988. * @param {number} [step=1] The value to increment or decrement by.
  14989. * @returns {Array} Returns the range of numbers.
  14990. * @see _.inRange, _.range
  14991. * @example
  14992. *
  14993. * _.rangeRight(4);
  14994. * // => [3, 2, 1, 0]
  14995. *
  14996. * _.rangeRight(-4);
  14997. * // => [-3, -2, -1, 0]
  14998. *
  14999. * _.rangeRight(1, 5);
  15000. * // => [4, 3, 2, 1]
  15001. *
  15002. * _.rangeRight(0, 20, 5);
  15003. * // => [15, 10, 5, 0]
  15004. *
  15005. * _.rangeRight(0, -4, -1);
  15006. * // => [-3, -2, -1, 0]
  15007. *
  15008. * _.rangeRight(1, 4, 0);
  15009. * // => [1, 1, 1]
  15010. *
  15011. * _.rangeRight(0);
  15012. * // => []
  15013. */
  15014. var rangeRight = createRange(true);
  15015. /**
  15016. * This method returns a new empty array.
  15017. *
  15018. * @static
  15019. * @memberOf _
  15020. * @since 4.13.0
  15021. * @category Util
  15022. * @returns {Array} Returns the new empty array.
  15023. * @example
  15024. *
  15025. * var arrays = _.times(2, _.stubArray);
  15026. *
  15027. * console.log(arrays);
  15028. * // => [[], []]
  15029. *
  15030. * console.log(arrays[0] === arrays[1]);
  15031. * // => false
  15032. */
  15033. function stubArray() {
  15034. return [];
  15035. }
  15036. /**
  15037. * This method returns `false`.
  15038. *
  15039. * @static
  15040. * @memberOf _
  15041. * @since 4.13.0
  15042. * @category Util
  15043. * @returns {boolean} Returns `false`.
  15044. * @example
  15045. *
  15046. * _.times(2, _.stubFalse);
  15047. * // => [false, false]
  15048. */
  15049. function stubFalse() {
  15050. return false;
  15051. }
  15052. /**
  15053. * This method returns a new empty object.
  15054. *
  15055. * @static
  15056. * @memberOf _
  15057. * @since 4.13.0
  15058. * @category Util
  15059. * @returns {Object} Returns the new empty object.
  15060. * @example
  15061. *
  15062. * var objects = _.times(2, _.stubObject);
  15063. *
  15064. * console.log(objects);
  15065. * // => [{}, {}]
  15066. *
  15067. * console.log(objects[0] === objects[1]);
  15068. * // => false
  15069. */
  15070. function stubObject() {
  15071. return {};
  15072. }
  15073. /**
  15074. * This method returns an empty string.
  15075. *
  15076. * @static
  15077. * @memberOf _
  15078. * @since 4.13.0
  15079. * @category Util
  15080. * @returns {string} Returns the empty string.
  15081. * @example
  15082. *
  15083. * _.times(2, _.stubString);
  15084. * // => ['', '']
  15085. */
  15086. function stubString() {
  15087. return '';
  15088. }
  15089. /**
  15090. * This method returns `true`.
  15091. *
  15092. * @static
  15093. * @memberOf _
  15094. * @since 4.13.0
  15095. * @category Util
  15096. * @returns {boolean} Returns `true`.
  15097. * @example
  15098. *
  15099. * _.times(2, _.stubTrue);
  15100. * // => [true, true]
  15101. */
  15102. function stubTrue() {
  15103. return true;
  15104. }
  15105. /**
  15106. * Invokes the iteratee `n` times, returning an array of the results of
  15107. * each invocation. The iteratee is invoked with one argument; (index).
  15108. *
  15109. * @static
  15110. * @since 0.1.0
  15111. * @memberOf _
  15112. * @category Util
  15113. * @param {number} n The number of times to invoke `iteratee`.
  15114. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15115. * @returns {Array} Returns the array of results.
  15116. * @example
  15117. *
  15118. * _.times(3, String);
  15119. * // => ['0', '1', '2']
  15120. *
  15121. * _.times(4, _.constant(0));
  15122. * // => [0, 0, 0, 0]
  15123. */
  15124. function times(n, iteratee) {
  15125. n = toInteger(n);
  15126. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15127. return [];
  15128. }
  15129. var index = MAX_ARRAY_LENGTH,
  15130. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15131. iteratee = getIteratee(iteratee);
  15132. n -= MAX_ARRAY_LENGTH;
  15133. var result = baseTimes(length, iteratee);
  15134. while (++index < n) {
  15135. iteratee(index);
  15136. }
  15137. return result;
  15138. }
  15139. /**
  15140. * Converts `value` to a property path array.
  15141. *
  15142. * @static
  15143. * @memberOf _
  15144. * @since 4.0.0
  15145. * @category Util
  15146. * @param {*} value The value to convert.
  15147. * @returns {Array} Returns the new property path array.
  15148. * @example
  15149. *
  15150. * _.toPath('a.b.c');
  15151. * // => ['a', 'b', 'c']
  15152. *
  15153. * _.toPath('a[0].b.c');
  15154. * // => ['a', '0', 'b', 'c']
  15155. */
  15156. function toPath(value) {
  15157. if (isArray(value)) {
  15158. return arrayMap(value, toKey);
  15159. }
  15160. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15161. }
  15162. /**
  15163. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15164. *
  15165. * @static
  15166. * @since 0.1.0
  15167. * @memberOf _
  15168. * @category Util
  15169. * @param {string} [prefix=''] The value to prefix the ID with.
  15170. * @returns {string} Returns the unique ID.
  15171. * @example
  15172. *
  15173. * _.uniqueId('contact_');
  15174. * // => 'contact_104'
  15175. *
  15176. * _.uniqueId();
  15177. * // => '105'
  15178. */
  15179. function uniqueId(prefix) {
  15180. var id = ++idCounter;
  15181. return toString(prefix) + id;
  15182. }
  15183. /*------------------------------------------------------------------------*/
  15184. /**
  15185. * Adds two numbers.
  15186. *
  15187. * @static
  15188. * @memberOf _
  15189. * @since 3.4.0
  15190. * @category Math
  15191. * @param {number} augend The first number in an addition.
  15192. * @param {number} addend The second number in an addition.
  15193. * @returns {number} Returns the total.
  15194. * @example
  15195. *
  15196. * _.add(6, 4);
  15197. * // => 10
  15198. */
  15199. var add = createMathOperation(function(augend, addend) {
  15200. return augend + addend;
  15201. }, 0);
  15202. /**
  15203. * Computes `number` rounded up to `precision`.
  15204. *
  15205. * @static
  15206. * @memberOf _
  15207. * @since 3.10.0
  15208. * @category Math
  15209. * @param {number} number The number to round up.
  15210. * @param {number} [precision=0] The precision to round up to.
  15211. * @returns {number} Returns the rounded up number.
  15212. * @example
  15213. *
  15214. * _.ceil(4.006);
  15215. * // => 5
  15216. *
  15217. * _.ceil(6.004, 2);
  15218. * // => 6.01
  15219. *
  15220. * _.ceil(6040, -2);
  15221. * // => 6100
  15222. */
  15223. var ceil = createRound('ceil');
  15224. /**
  15225. * Divide two numbers.
  15226. *
  15227. * @static
  15228. * @memberOf _
  15229. * @since 4.7.0
  15230. * @category Math
  15231. * @param {number} dividend The first number in a division.
  15232. * @param {number} divisor The second number in a division.
  15233. * @returns {number} Returns the quotient.
  15234. * @example
  15235. *
  15236. * _.divide(6, 4);
  15237. * // => 1.5
  15238. */
  15239. var divide = createMathOperation(function(dividend, divisor) {
  15240. return dividend / divisor;
  15241. }, 1);
  15242. /**
  15243. * Computes `number` rounded down to `precision`.
  15244. *
  15245. * @static
  15246. * @memberOf _
  15247. * @since 3.10.0
  15248. * @category Math
  15249. * @param {number} number The number to round down.
  15250. * @param {number} [precision=0] The precision to round down to.
  15251. * @returns {number} Returns the rounded down number.
  15252. * @example
  15253. *
  15254. * _.floor(4.006);
  15255. * // => 4
  15256. *
  15257. * _.floor(0.046, 2);
  15258. * // => 0.04
  15259. *
  15260. * _.floor(4060, -2);
  15261. * // => 4000
  15262. */
  15263. var floor = createRound('floor');
  15264. /**
  15265. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15266. * `undefined` is returned.
  15267. *
  15268. * @static
  15269. * @since 0.1.0
  15270. * @memberOf _
  15271. * @category Math
  15272. * @param {Array} array The array to iterate over.
  15273. * @returns {*} Returns the maximum value.
  15274. * @example
  15275. *
  15276. * _.max([4, 2, 8, 6]);
  15277. * // => 8
  15278. *
  15279. * _.max([]);
  15280. * // => undefined
  15281. */
  15282. function max(array) {
  15283. return (array && array.length)
  15284. ? baseExtremum(array, identity, baseGt)
  15285. : undefined;
  15286. }
  15287. /**
  15288. * This method is like `_.max` except that it accepts `iteratee` which is
  15289. * invoked for each element in `array` to generate the criterion by which
  15290. * the value is ranked. The iteratee is invoked with one argument: (value).
  15291. *
  15292. * @static
  15293. * @memberOf _
  15294. * @since 4.0.0
  15295. * @category Math
  15296. * @param {Array} array The array to iterate over.
  15297. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15298. * @returns {*} Returns the maximum value.
  15299. * @example
  15300. *
  15301. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15302. *
  15303. * _.maxBy(objects, function(o) { return o.n; });
  15304. * // => { 'n': 2 }
  15305. *
  15306. * // The `_.property` iteratee shorthand.
  15307. * _.maxBy(objects, 'n');
  15308. * // => { 'n': 2 }
  15309. */
  15310. function maxBy(array, iteratee) {
  15311. return (array && array.length)
  15312. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15313. : undefined;
  15314. }
  15315. /**
  15316. * Computes the mean of the values in `array`.
  15317. *
  15318. * @static
  15319. * @memberOf _
  15320. * @since 4.0.0
  15321. * @category Math
  15322. * @param {Array} array The array to iterate over.
  15323. * @returns {number} Returns the mean.
  15324. * @example
  15325. *
  15326. * _.mean([4, 2, 8, 6]);
  15327. * // => 5
  15328. */
  15329. function mean(array) {
  15330. return baseMean(array, identity);
  15331. }
  15332. /**
  15333. * This method is like `_.mean` except that it accepts `iteratee` which is
  15334. * invoked for each element in `array` to generate the value to be averaged.
  15335. * The iteratee is invoked with one argument: (value).
  15336. *
  15337. * @static
  15338. * @memberOf _
  15339. * @since 4.7.0
  15340. * @category Math
  15341. * @param {Array} array The array to iterate over.
  15342. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15343. * @returns {number} Returns the mean.
  15344. * @example
  15345. *
  15346. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15347. *
  15348. * _.meanBy(objects, function(o) { return o.n; });
  15349. * // => 5
  15350. *
  15351. * // The `_.property` iteratee shorthand.
  15352. * _.meanBy(objects, 'n');
  15353. * // => 5
  15354. */
  15355. function meanBy(array, iteratee) {
  15356. return baseMean(array, getIteratee(iteratee, 2));
  15357. }
  15358. /**
  15359. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15360. * `undefined` is returned.
  15361. *
  15362. * @static
  15363. * @since 0.1.0
  15364. * @memberOf _
  15365. * @category Math
  15366. * @param {Array} array The array to iterate over.
  15367. * @returns {*} Returns the minimum value.
  15368. * @example
  15369. *
  15370. * _.min([4, 2, 8, 6]);
  15371. * // => 2
  15372. *
  15373. * _.min([]);
  15374. * // => undefined
  15375. */
  15376. function min(array) {
  15377. return (array && array.length)
  15378. ? baseExtremum(array, identity, baseLt)
  15379. : undefined;
  15380. }
  15381. /**
  15382. * This method is like `_.min` except that it accepts `iteratee` which is
  15383. * invoked for each element in `array` to generate the criterion by which
  15384. * the value is ranked. The iteratee is invoked with one argument: (value).
  15385. *
  15386. * @static
  15387. * @memberOf _
  15388. * @since 4.0.0
  15389. * @category Math
  15390. * @param {Array} array The array to iterate over.
  15391. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15392. * @returns {*} Returns the minimum value.
  15393. * @example
  15394. *
  15395. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15396. *
  15397. * _.minBy(objects, function(o) { return o.n; });
  15398. * // => { 'n': 1 }
  15399. *
  15400. * // The `_.property` iteratee shorthand.
  15401. * _.minBy(objects, 'n');
  15402. * // => { 'n': 1 }
  15403. */
  15404. function minBy(array, iteratee) {
  15405. return (array && array.length)
  15406. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15407. : undefined;
  15408. }
  15409. /**
  15410. * Multiply two numbers.
  15411. *
  15412. * @static
  15413. * @memberOf _
  15414. * @since 4.7.0
  15415. * @category Math
  15416. * @param {number} multiplier The first number in a multiplication.
  15417. * @param {number} multiplicand The second number in a multiplication.
  15418. * @returns {number} Returns the product.
  15419. * @example
  15420. *
  15421. * _.multiply(6, 4);
  15422. * // => 24
  15423. */
  15424. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15425. return multiplier * multiplicand;
  15426. }, 1);
  15427. /**
  15428. * Computes `number` rounded to `precision`.
  15429. *
  15430. * @static
  15431. * @memberOf _
  15432. * @since 3.10.0
  15433. * @category Math
  15434. * @param {number} number The number to round.
  15435. * @param {number} [precision=0] The precision to round to.
  15436. * @returns {number} Returns the rounded number.
  15437. * @example
  15438. *
  15439. * _.round(4.006);
  15440. * // => 4
  15441. *
  15442. * _.round(4.006, 2);
  15443. * // => 4.01
  15444. *
  15445. * _.round(4060, -2);
  15446. * // => 4100
  15447. */
  15448. var round = createRound('round');
  15449. /**
  15450. * Subtract two numbers.
  15451. *
  15452. * @static
  15453. * @memberOf _
  15454. * @since 4.0.0
  15455. * @category Math
  15456. * @param {number} minuend The first number in a subtraction.
  15457. * @param {number} subtrahend The second number in a subtraction.
  15458. * @returns {number} Returns the difference.
  15459. * @example
  15460. *
  15461. * _.subtract(6, 4);
  15462. * // => 2
  15463. */
  15464. var subtract = createMathOperation(function(minuend, subtrahend) {
  15465. return minuend - subtrahend;
  15466. }, 0);
  15467. /**
  15468. * Computes the sum of the values in `array`.
  15469. *
  15470. * @static
  15471. * @memberOf _
  15472. * @since 3.4.0
  15473. * @category Math
  15474. * @param {Array} array The array to iterate over.
  15475. * @returns {number} Returns the sum.
  15476. * @example
  15477. *
  15478. * _.sum([4, 2, 8, 6]);
  15479. * // => 20
  15480. */
  15481. function sum(array) {
  15482. return (array && array.length)
  15483. ? baseSum(array, identity)
  15484. : 0;
  15485. }
  15486. /**
  15487. * This method is like `_.sum` except that it accepts `iteratee` which is
  15488. * invoked for each element in `array` to generate the value to be summed.
  15489. * The iteratee is invoked with one argument: (value).
  15490. *
  15491. * @static
  15492. * @memberOf _
  15493. * @since 4.0.0
  15494. * @category Math
  15495. * @param {Array} array The array to iterate over.
  15496. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15497. * @returns {number} Returns the sum.
  15498. * @example
  15499. *
  15500. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15501. *
  15502. * _.sumBy(objects, function(o) { return o.n; });
  15503. * // => 20
  15504. *
  15505. * // The `_.property` iteratee shorthand.
  15506. * _.sumBy(objects, 'n');
  15507. * // => 20
  15508. */
  15509. function sumBy(array, iteratee) {
  15510. return (array && array.length)
  15511. ? baseSum(array, getIteratee(iteratee, 2))
  15512. : 0;
  15513. }
  15514. /*------------------------------------------------------------------------*/
  15515. // Add methods that return wrapped values in chain sequences.
  15516. lodash.after = after;
  15517. lodash.ary = ary;
  15518. lodash.assign = assign;
  15519. lodash.assignIn = assignIn;
  15520. lodash.assignInWith = assignInWith;
  15521. lodash.assignWith = assignWith;
  15522. lodash.at = at;
  15523. lodash.before = before;
  15524. lodash.bind = bind;
  15525. lodash.bindAll = bindAll;
  15526. lodash.bindKey = bindKey;
  15527. lodash.castArray = castArray;
  15528. lodash.chain = chain;
  15529. lodash.chunk = chunk;
  15530. lodash.compact = compact;
  15531. lodash.concat = concat;
  15532. lodash.cond = cond;
  15533. lodash.conforms = conforms;
  15534. lodash.constant = constant;
  15535. lodash.countBy = countBy;
  15536. lodash.create = create;
  15537. lodash.curry = curry;
  15538. lodash.curryRight = curryRight;
  15539. lodash.debounce = debounce;
  15540. lodash.defaults = defaults;
  15541. lodash.defaultsDeep = defaultsDeep;
  15542. lodash.defer = defer;
  15543. lodash.delay = delay;
  15544. lodash.difference = difference;
  15545. lodash.differenceBy = differenceBy;
  15546. lodash.differenceWith = differenceWith;
  15547. lodash.drop = drop;
  15548. lodash.dropRight = dropRight;
  15549. lodash.dropRightWhile = dropRightWhile;
  15550. lodash.dropWhile = dropWhile;
  15551. lodash.fill = fill;
  15552. lodash.filter = filter;
  15553. lodash.flatMap = flatMap;
  15554. lodash.flatMapDeep = flatMapDeep;
  15555. lodash.flatMapDepth = flatMapDepth;
  15556. lodash.flatten = flatten;
  15557. lodash.flattenDeep = flattenDeep;
  15558. lodash.flattenDepth = flattenDepth;
  15559. lodash.flip = flip;
  15560. lodash.flow = flow;
  15561. lodash.flowRight = flowRight;
  15562. lodash.fromPairs = fromPairs;
  15563. lodash.functions = functions;
  15564. lodash.functionsIn = functionsIn;
  15565. lodash.groupBy = groupBy;
  15566. lodash.initial = initial;
  15567. lodash.intersection = intersection;
  15568. lodash.intersectionBy = intersectionBy;
  15569. lodash.intersectionWith = intersectionWith;
  15570. lodash.invert = invert;
  15571. lodash.invertBy = invertBy;
  15572. lodash.invokeMap = invokeMap;
  15573. lodash.iteratee = iteratee;
  15574. lodash.keyBy = keyBy;
  15575. lodash.keys = keys;
  15576. lodash.keysIn = keysIn;
  15577. lodash.map = map;
  15578. lodash.mapKeys = mapKeys;
  15579. lodash.mapValues = mapValues;
  15580. lodash.matches = matches;
  15581. lodash.matchesProperty = matchesProperty;
  15582. lodash.memoize = memoize;
  15583. lodash.merge = merge;
  15584. lodash.mergeWith = mergeWith;
  15585. lodash.method = method;
  15586. lodash.methodOf = methodOf;
  15587. lodash.mixin = mixin;
  15588. lodash.negate = negate;
  15589. lodash.nthArg = nthArg;
  15590. lodash.omit = omit;
  15591. lodash.omitBy = omitBy;
  15592. lodash.once = once;
  15593. lodash.orderBy = orderBy;
  15594. lodash.over = over;
  15595. lodash.overArgs = overArgs;
  15596. lodash.overEvery = overEvery;
  15597. lodash.overSome = overSome;
  15598. lodash.partial = partial;
  15599. lodash.partialRight = partialRight;
  15600. lodash.partition = partition;
  15601. lodash.pick = pick;
  15602. lodash.pickBy = pickBy;
  15603. lodash.property = property;
  15604. lodash.propertyOf = propertyOf;
  15605. lodash.pull = pull;
  15606. lodash.pullAll = pullAll;
  15607. lodash.pullAllBy = pullAllBy;
  15608. lodash.pullAllWith = pullAllWith;
  15609. lodash.pullAt = pullAt;
  15610. lodash.range = range;
  15611. lodash.rangeRight = rangeRight;
  15612. lodash.rearg = rearg;
  15613. lodash.reject = reject;
  15614. lodash.remove = remove;
  15615. lodash.rest = rest;
  15616. lodash.reverse = reverse;
  15617. lodash.sampleSize = sampleSize;
  15618. lodash.set = set;
  15619. lodash.setWith = setWith;
  15620. lodash.shuffle = shuffle;
  15621. lodash.slice = slice;
  15622. lodash.sortBy = sortBy;
  15623. lodash.sortedUniq = sortedUniq;
  15624. lodash.sortedUniqBy = sortedUniqBy;
  15625. lodash.split = split;
  15626. lodash.spread = spread;
  15627. lodash.tail = tail;
  15628. lodash.take = take;
  15629. lodash.takeRight = takeRight;
  15630. lodash.takeRightWhile = takeRightWhile;
  15631. lodash.takeWhile = takeWhile;
  15632. lodash.tap = tap;
  15633. lodash.throttle = throttle;
  15634. lodash.thru = thru;
  15635. lodash.toArray = toArray;
  15636. lodash.toPairs = toPairs;
  15637. lodash.toPairsIn = toPairsIn;
  15638. lodash.toPath = toPath;
  15639. lodash.toPlainObject = toPlainObject;
  15640. lodash.transform = transform;
  15641. lodash.unary = unary;
  15642. lodash.union = union;
  15643. lodash.unionBy = unionBy;
  15644. lodash.unionWith = unionWith;
  15645. lodash.uniq = uniq;
  15646. lodash.uniqBy = uniqBy;
  15647. lodash.uniqWith = uniqWith;
  15648. lodash.unset = unset;
  15649. lodash.unzip = unzip;
  15650. lodash.unzipWith = unzipWith;
  15651. lodash.update = update;
  15652. lodash.updateWith = updateWith;
  15653. lodash.values = values;
  15654. lodash.valuesIn = valuesIn;
  15655. lodash.without = without;
  15656. lodash.words = words;
  15657. lodash.wrap = wrap;
  15658. lodash.xor = xor;
  15659. lodash.xorBy = xorBy;
  15660. lodash.xorWith = xorWith;
  15661. lodash.zip = zip;
  15662. lodash.zipObject = zipObject;
  15663. lodash.zipObjectDeep = zipObjectDeep;
  15664. lodash.zipWith = zipWith;
  15665. // Add aliases.
  15666. lodash.entries = toPairs;
  15667. lodash.entriesIn = toPairsIn;
  15668. lodash.extend = assignIn;
  15669. lodash.extendWith = assignInWith;
  15670. // Add methods to `lodash.prototype`.
  15671. mixin(lodash, lodash);
  15672. /*------------------------------------------------------------------------*/
  15673. // Add methods that return unwrapped values in chain sequences.
  15674. lodash.add = add;
  15675. lodash.attempt = attempt;
  15676. lodash.camelCase = camelCase;
  15677. lodash.capitalize = capitalize;
  15678. lodash.ceil = ceil;
  15679. lodash.clamp = clamp;
  15680. lodash.clone = clone;
  15681. lodash.cloneDeep = cloneDeep;
  15682. lodash.cloneDeepWith = cloneDeepWith;
  15683. lodash.cloneWith = cloneWith;
  15684. lodash.conformsTo = conformsTo;
  15685. lodash.deburr = deburr;
  15686. lodash.defaultTo = defaultTo;
  15687. lodash.divide = divide;
  15688. lodash.endsWith = endsWith;
  15689. lodash.eq = eq;
  15690. lodash.escape = escape;
  15691. lodash.escapeRegExp = escapeRegExp;
  15692. lodash.every = every;
  15693. lodash.find = find;
  15694. lodash.findIndex = findIndex;
  15695. lodash.findKey = findKey;
  15696. lodash.findLast = findLast;
  15697. lodash.findLastIndex = findLastIndex;
  15698. lodash.findLastKey = findLastKey;
  15699. lodash.floor = floor;
  15700. lodash.forEach = forEach;
  15701. lodash.forEachRight = forEachRight;
  15702. lodash.forIn = forIn;
  15703. lodash.forInRight = forInRight;
  15704. lodash.forOwn = forOwn;
  15705. lodash.forOwnRight = forOwnRight;
  15706. lodash.get = get;
  15707. lodash.gt = gt;
  15708. lodash.gte = gte;
  15709. lodash.has = has;
  15710. lodash.hasIn = hasIn;
  15711. lodash.head = head;
  15712. lodash.identity = identity;
  15713. lodash.includes = includes;
  15714. lodash.indexOf = indexOf;
  15715. lodash.inRange = inRange;
  15716. lodash.invoke = invoke;
  15717. lodash.isArguments = isArguments;
  15718. lodash.isArray = isArray;
  15719. lodash.isArrayBuffer = isArrayBuffer;
  15720. lodash.isArrayLike = isArrayLike;
  15721. lodash.isArrayLikeObject = isArrayLikeObject;
  15722. lodash.isBoolean = isBoolean;
  15723. lodash.isBuffer = isBuffer;
  15724. lodash.isDate = isDate;
  15725. lodash.isElement = isElement;
  15726. lodash.isEmpty = isEmpty;
  15727. lodash.isEqual = isEqual;
  15728. lodash.isEqualWith = isEqualWith;
  15729. lodash.isError = isError;
  15730. lodash.isFinite = isFinite;
  15731. lodash.isFunction = isFunction;
  15732. lodash.isInteger = isInteger;
  15733. lodash.isLength = isLength;
  15734. lodash.isMap = isMap;
  15735. lodash.isMatch = isMatch;
  15736. lodash.isMatchWith = isMatchWith;
  15737. lodash.isNaN = isNaN;
  15738. lodash.isNative = isNative;
  15739. lodash.isNil = isNil;
  15740. lodash.isNull = isNull;
  15741. lodash.isNumber = isNumber;
  15742. lodash.isObject = isObject;
  15743. lodash.isObjectLike = isObjectLike;
  15744. lodash.isPlainObject = isPlainObject;
  15745. lodash.isRegExp = isRegExp;
  15746. lodash.isSafeInteger = isSafeInteger;
  15747. lodash.isSet = isSet;
  15748. lodash.isString = isString;
  15749. lodash.isSymbol = isSymbol;
  15750. lodash.isTypedArray = isTypedArray;
  15751. lodash.isUndefined = isUndefined;
  15752. lodash.isWeakMap = isWeakMap;
  15753. lodash.isWeakSet = isWeakSet;
  15754. lodash.join = join;
  15755. lodash.kebabCase = kebabCase;
  15756. lodash.last = last;
  15757. lodash.lastIndexOf = lastIndexOf;
  15758. lodash.lowerCase = lowerCase;
  15759. lodash.lowerFirst = lowerFirst;
  15760. lodash.lt = lt;
  15761. lodash.lte = lte;
  15762. lodash.max = max;
  15763. lodash.maxBy = maxBy;
  15764. lodash.mean = mean;
  15765. lodash.meanBy = meanBy;
  15766. lodash.min = min;
  15767. lodash.minBy = minBy;
  15768. lodash.stubArray = stubArray;
  15769. lodash.stubFalse = stubFalse;
  15770. lodash.stubObject = stubObject;
  15771. lodash.stubString = stubString;
  15772. lodash.stubTrue = stubTrue;
  15773. lodash.multiply = multiply;
  15774. lodash.nth = nth;
  15775. lodash.noConflict = noConflict;
  15776. lodash.noop = noop;
  15777. lodash.now = now;
  15778. lodash.pad = pad;
  15779. lodash.padEnd = padEnd;
  15780. lodash.padStart = padStart;
  15781. lodash.parseInt = parseInt;
  15782. lodash.random = random;
  15783. lodash.reduce = reduce;
  15784. lodash.reduceRight = reduceRight;
  15785. lodash.repeat = repeat;
  15786. lodash.replace = replace;
  15787. lodash.result = result;
  15788. lodash.round = round;
  15789. lodash.runInContext = runInContext;
  15790. lodash.sample = sample;
  15791. lodash.size = size;
  15792. lodash.snakeCase = snakeCase;
  15793. lodash.some = some;
  15794. lodash.sortedIndex = sortedIndex;
  15795. lodash.sortedIndexBy = sortedIndexBy;
  15796. lodash.sortedIndexOf = sortedIndexOf;
  15797. lodash.sortedLastIndex = sortedLastIndex;
  15798. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15799. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15800. lodash.startCase = startCase;
  15801. lodash.startsWith = startsWith;
  15802. lodash.subtract = subtract;
  15803. lodash.sum = sum;
  15804. lodash.sumBy = sumBy;
  15805. lodash.template = template;
  15806. lodash.times = times;
  15807. lodash.toFinite = toFinite;
  15808. lodash.toInteger = toInteger;
  15809. lodash.toLength = toLength;
  15810. lodash.toLower = toLower;
  15811. lodash.toNumber = toNumber;
  15812. lodash.toSafeInteger = toSafeInteger;
  15813. lodash.toString = toString;
  15814. lodash.toUpper = toUpper;
  15815. lodash.trim = trim;
  15816. lodash.trimEnd = trimEnd;
  15817. lodash.trimStart = trimStart;
  15818. lodash.truncate = truncate;
  15819. lodash.unescape = unescape;
  15820. lodash.uniqueId = uniqueId;
  15821. lodash.upperCase = upperCase;
  15822. lodash.upperFirst = upperFirst;
  15823. // Add aliases.
  15824. lodash.each = forEach;
  15825. lodash.eachRight = forEachRight;
  15826. lodash.first = head;
  15827. mixin(lodash, (function() {
  15828. var source = {};
  15829. baseForOwn(lodash, function(func, methodName) {
  15830. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15831. source[methodName] = func;
  15832. }
  15833. });
  15834. return source;
  15835. }()), { 'chain': false });
  15836. /*------------------------------------------------------------------------*/
  15837. /**
  15838. * The semantic version number.
  15839. *
  15840. * @static
  15841. * @memberOf _
  15842. * @type {string}
  15843. */
  15844. lodash.VERSION = VERSION;
  15845. // Assign default placeholders.
  15846. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15847. lodash[methodName].placeholder = lodash;
  15848. });
  15849. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15850. arrayEach(['drop', 'take'], function(methodName, index) {
  15851. LazyWrapper.prototype[methodName] = function(n) {
  15852. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15853. var result = (this.__filtered__ && !index)
  15854. ? new LazyWrapper(this)
  15855. : this.clone();
  15856. if (result.__filtered__) {
  15857. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15858. } else {
  15859. result.__views__.push({
  15860. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15861. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15862. });
  15863. }
  15864. return result;
  15865. };
  15866. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15867. return this.reverse()[methodName](n).reverse();
  15868. };
  15869. });
  15870. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15871. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15872. var type = index + 1,
  15873. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15874. LazyWrapper.prototype[methodName] = function(iteratee) {
  15875. var result = this.clone();
  15876. result.__iteratees__.push({
  15877. 'iteratee': getIteratee(iteratee, 3),
  15878. 'type': type
  15879. });
  15880. result.__filtered__ = result.__filtered__ || isFilter;
  15881. return result;
  15882. };
  15883. });
  15884. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15885. arrayEach(['head', 'last'], function(methodName, index) {
  15886. var takeName = 'take' + (index ? 'Right' : '');
  15887. LazyWrapper.prototype[methodName] = function() {
  15888. return this[takeName](1).value()[0];
  15889. };
  15890. });
  15891. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15892. arrayEach(['initial', 'tail'], function(methodName, index) {
  15893. var dropName = 'drop' + (index ? '' : 'Right');
  15894. LazyWrapper.prototype[methodName] = function() {
  15895. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15896. };
  15897. });
  15898. LazyWrapper.prototype.compact = function() {
  15899. return this.filter(identity);
  15900. };
  15901. LazyWrapper.prototype.find = function(predicate) {
  15902. return this.filter(predicate).head();
  15903. };
  15904. LazyWrapper.prototype.findLast = function(predicate) {
  15905. return this.reverse().find(predicate);
  15906. };
  15907. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15908. if (typeof path == 'function') {
  15909. return new LazyWrapper(this);
  15910. }
  15911. return this.map(function(value) {
  15912. return baseInvoke(value, path, args);
  15913. });
  15914. });
  15915. LazyWrapper.prototype.reject = function(predicate) {
  15916. return this.filter(negate(getIteratee(predicate)));
  15917. };
  15918. LazyWrapper.prototype.slice = function(start, end) {
  15919. start = toInteger(start);
  15920. var result = this;
  15921. if (result.__filtered__ && (start > 0 || end < 0)) {
  15922. return new LazyWrapper(result);
  15923. }
  15924. if (start < 0) {
  15925. result = result.takeRight(-start);
  15926. } else if (start) {
  15927. result = result.drop(start);
  15928. }
  15929. if (end !== undefined) {
  15930. end = toInteger(end);
  15931. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15932. }
  15933. return result;
  15934. };
  15935. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15936. return this.reverse().takeWhile(predicate).reverse();
  15937. };
  15938. LazyWrapper.prototype.toArray = function() {
  15939. return this.take(MAX_ARRAY_LENGTH);
  15940. };
  15941. // Add `LazyWrapper` methods to `lodash.prototype`.
  15942. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15943. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15944. isTaker = /^(?:head|last)$/.test(methodName),
  15945. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15946. retUnwrapped = isTaker || /^find/.test(methodName);
  15947. if (!lodashFunc) {
  15948. return;
  15949. }
  15950. lodash.prototype[methodName] = function() {
  15951. var value = this.__wrapped__,
  15952. args = isTaker ? [1] : arguments,
  15953. isLazy = value instanceof LazyWrapper,
  15954. iteratee = args[0],
  15955. useLazy = isLazy || isArray(value);
  15956. var interceptor = function(value) {
  15957. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15958. return (isTaker && chainAll) ? result[0] : result;
  15959. };
  15960. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15961. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15962. isLazy = useLazy = false;
  15963. }
  15964. var chainAll = this.__chain__,
  15965. isHybrid = !!this.__actions__.length,
  15966. isUnwrapped = retUnwrapped && !chainAll,
  15967. onlyLazy = isLazy && !isHybrid;
  15968. if (!retUnwrapped && useLazy) {
  15969. value = onlyLazy ? value : new LazyWrapper(this);
  15970. var result = func.apply(value, args);
  15971. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15972. return new LodashWrapper(result, chainAll);
  15973. }
  15974. if (isUnwrapped && onlyLazy) {
  15975. return func.apply(this, args);
  15976. }
  15977. result = this.thru(interceptor);
  15978. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15979. };
  15980. });
  15981. // Add `Array` methods to `lodash.prototype`.
  15982. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15983. var func = arrayProto[methodName],
  15984. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15985. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15986. lodash.prototype[methodName] = function() {
  15987. var args = arguments;
  15988. if (retUnwrapped && !this.__chain__) {
  15989. var value = this.value();
  15990. return func.apply(isArray(value) ? value : [], args);
  15991. }
  15992. return this[chainName](function(value) {
  15993. return func.apply(isArray(value) ? value : [], args);
  15994. });
  15995. };
  15996. });
  15997. // Map minified method names to their real names.
  15998. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15999. var lodashFunc = lodash[methodName];
  16000. if (lodashFunc) {
  16001. var key = (lodashFunc.name + ''),
  16002. names = realNames[key] || (realNames[key] = []);
  16003. names.push({ 'name': methodName, 'func': lodashFunc });
  16004. }
  16005. });
  16006. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16007. 'name': 'wrapper',
  16008. 'func': undefined
  16009. }];
  16010. // Add methods to `LazyWrapper`.
  16011. LazyWrapper.prototype.clone = lazyClone;
  16012. LazyWrapper.prototype.reverse = lazyReverse;
  16013. LazyWrapper.prototype.value = lazyValue;
  16014. // Add chain sequence methods to the `lodash` wrapper.
  16015. lodash.prototype.at = wrapperAt;
  16016. lodash.prototype.chain = wrapperChain;
  16017. lodash.prototype.commit = wrapperCommit;
  16018. lodash.prototype.next = wrapperNext;
  16019. lodash.prototype.plant = wrapperPlant;
  16020. lodash.prototype.reverse = wrapperReverse;
  16021. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16022. // Add lazy aliases.
  16023. lodash.prototype.first = lodash.prototype.head;
  16024. if (symIterator) {
  16025. lodash.prototype[symIterator] = wrapperToIterator;
  16026. }
  16027. return lodash;
  16028. });
  16029. /*--------------------------------------------------------------------------*/
  16030. // Export lodash.
  16031. var _ = runInContext();
  16032. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16033. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16034. // Expose Lodash on the global object to prevent errors when Lodash is
  16035. // loaded by a script tag in the presence of an AMD loader.
  16036. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16037. // Use `_.noConflict` to remove Lodash from the global object.
  16038. root._ = _;
  16039. // Define as an anonymous module so, through path mapping, it can be
  16040. // referenced as the "underscore" module.
  16041. define(function() {
  16042. return _;
  16043. });
  16044. }
  16045. // Check for `exports` after `define` in case a build optimizer adds it.
  16046. else if (freeModule) {
  16047. // Export for Node.js.
  16048. (freeModule.exports = _)._ = _;
  16049. // Export for CommonJS support.
  16050. freeExports._ = _;
  16051. }
  16052. else {
  16053. // Export to the global object.
  16054. root._ = _;
  16055. }
  16056. }.call(this));