lodash.js 527 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084
  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.4';
  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. reLeadingDot = /^\./,
  125. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  126. /**
  127. * Used to match `RegExp`
  128. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  129. */
  130. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  131. reHasRegExpChar = RegExp(reRegExpChar.source);
  132. /** Used to match leading and trailing whitespace. */
  133. var reTrim = /^\s+|\s+$/g,
  134. reTrimStart = /^\s+/,
  135. reTrimEnd = /\s+$/;
  136. /** Used to match wrap detail comments. */
  137. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  138. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  139. reSplitDetails = /,? & /;
  140. /** Used to match words composed of alphanumeric characters. */
  141. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  142. /** Used to match backslashes in property paths. */
  143. var reEscapeChar = /\\(\\)?/g;
  144. /**
  145. * Used to match
  146. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  147. */
  148. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  149. /** Used to match `RegExp` flags from their coerced string values. */
  150. var reFlags = /\w*$/;
  151. /** Used to detect bad signed hexadecimal string values. */
  152. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  153. /** Used to detect binary string values. */
  154. var reIsBinary = /^0b[01]+$/i;
  155. /** Used to detect host constructors (Safari). */
  156. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  157. /** Used to detect octal string values. */
  158. var reIsOctal = /^0o[0-7]+$/i;
  159. /** Used to detect unsigned integer values. */
  160. var reIsUint = /^(?:0|[1-9]\d*)$/;
  161. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  162. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  163. /** Used to ensure capturing order of template delimiters. */
  164. var reNoMatch = /($^)/;
  165. /** Used to match unescaped characters in compiled string literals. */
  166. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  167. /** Used to compose unicode character classes. */
  168. var rsAstralRange = '\\ud800-\\udfff',
  169. rsComboMarksRange = '\\u0300-\\u036f',
  170. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  171. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  172. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  173. rsDingbatRange = '\\u2700-\\u27bf',
  174. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  175. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  176. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  177. rsPunctuationRange = '\\u2000-\\u206f',
  178. 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',
  179. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  180. rsVarRange = '\\ufe0e\\ufe0f',
  181. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  182. /** Used to compose unicode capture groups. */
  183. var rsApos = "['\u2019]",
  184. rsAstral = '[' + rsAstralRange + ']',
  185. rsBreak = '[' + rsBreakRange + ']',
  186. rsCombo = '[' + rsComboRange + ']',
  187. rsDigits = '\\d+',
  188. rsDingbat = '[' + rsDingbatRange + ']',
  189. rsLower = '[' + rsLowerRange + ']',
  190. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  191. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  192. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  193. rsNonAstral = '[^' + rsAstralRange + ']',
  194. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  195. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  196. rsUpper = '[' + rsUpperRange + ']',
  197. rsZWJ = '\\u200d';
  198. /** Used to compose unicode regexes. */
  199. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  200. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  201. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  202. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  203. reOptMod = rsModifier + '?',
  204. rsOptVar = '[' + rsVarRange + ']?',
  205. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  206. rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)',
  207. rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)',
  208. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  209. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  210. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  211. /** Used to match apostrophes. */
  212. var reApos = RegExp(rsApos, 'g');
  213. /**
  214. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  215. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  216. */
  217. var reComboMark = RegExp(rsCombo, 'g');
  218. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  219. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  220. /** Used to match complex or compound words. */
  221. var reUnicodeWord = RegExp([
  222. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  223. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  224. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  225. rsUpper + '+' + rsOptContrUpper,
  226. rsOrdUpper,
  227. rsOrdLower,
  228. rsDigits,
  229. rsEmoji
  230. ].join('|'), 'g');
  231. /** 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/). */
  232. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  233. /** Used to detect strings that need a more robust regexp to match words. */
  234. 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 ]/;
  235. /** Used to assign default `context` object properties. */
  236. var contextProps = [
  237. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  238. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  239. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  240. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  241. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  242. ];
  243. /** Used to make template sourceURLs easier to identify. */
  244. var templateCounter = -1;
  245. /** Used to identify `toStringTag` values of typed arrays. */
  246. var typedArrayTags = {};
  247. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  248. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  249. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  250. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  251. typedArrayTags[uint32Tag] = true;
  252. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  253. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  254. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  255. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  256. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  257. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  258. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  259. typedArrayTags[weakMapTag] = false;
  260. /** Used to identify `toStringTag` values supported by `_.clone`. */
  261. var cloneableTags = {};
  262. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  263. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  264. cloneableTags[boolTag] = cloneableTags[dateTag] =
  265. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  266. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  267. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  268. cloneableTags[numberTag] = cloneableTags[objectTag] =
  269. cloneableTags[regexpTag] = cloneableTags[setTag] =
  270. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  271. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  272. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  273. cloneableTags[errorTag] = cloneableTags[funcTag] =
  274. cloneableTags[weakMapTag] = false;
  275. /** Used to map Latin Unicode letters to basic Latin letters. */
  276. var deburredLetters = {
  277. // Latin-1 Supplement block.
  278. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  279. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  280. '\xc7': 'C', '\xe7': 'c',
  281. '\xd0': 'D', '\xf0': 'd',
  282. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  283. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  284. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  285. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  286. '\xd1': 'N', '\xf1': 'n',
  287. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  288. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  289. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  290. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  291. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  292. '\xc6': 'Ae', '\xe6': 'ae',
  293. '\xde': 'Th', '\xfe': 'th',
  294. '\xdf': 'ss',
  295. // Latin Extended-A block.
  296. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  297. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  298. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  299. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  300. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  301. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  302. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  303. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  304. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  305. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  306. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  307. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  308. '\u0134': 'J', '\u0135': 'j',
  309. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  310. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  311. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  312. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  313. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  314. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  315. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  316. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  317. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  318. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  319. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  320. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  321. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  322. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  323. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  324. '\u0174': 'W', '\u0175': 'w',
  325. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  326. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  327. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  328. '\u0132': 'IJ', '\u0133': 'ij',
  329. '\u0152': 'Oe', '\u0153': 'oe',
  330. '\u0149': "'n", '\u017f': 's'
  331. };
  332. /** Used to map characters to HTML entities. */
  333. var htmlEscapes = {
  334. '&': '&amp;',
  335. '<': '&lt;',
  336. '>': '&gt;',
  337. '"': '&quot;',
  338. "'": '&#39;'
  339. };
  340. /** Used to map HTML entities to characters. */
  341. var htmlUnescapes = {
  342. '&amp;': '&',
  343. '&lt;': '<',
  344. '&gt;': '>',
  345. '&quot;': '"',
  346. '&#39;': "'"
  347. };
  348. /** Used to escape characters for inclusion in compiled string literals. */
  349. var stringEscapes = {
  350. '\\': '\\',
  351. "'": "'",
  352. '\n': 'n',
  353. '\r': 'r',
  354. '\u2028': 'u2028',
  355. '\u2029': 'u2029'
  356. };
  357. /** Built-in method references without a dependency on `root`. */
  358. var freeParseFloat = parseFloat,
  359. freeParseInt = parseInt;
  360. /** Detect free variable `global` from Node.js. */
  361. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  362. /** Detect free variable `self`. */
  363. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  364. /** Used as a reference to the global object. */
  365. var root = freeGlobal || freeSelf || Function('return this')();
  366. /** Detect free variable `exports`. */
  367. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  368. /** Detect free variable `module`. */
  369. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  370. /** Detect the popular CommonJS extension `module.exports`. */
  371. var moduleExports = freeModule && freeModule.exports === freeExports;
  372. /** Detect free variable `process` from Node.js. */
  373. var freeProcess = moduleExports && freeGlobal.process;
  374. /** Used to access faster Node.js helpers. */
  375. var nodeUtil = (function() {
  376. try {
  377. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  378. } catch (e) {}
  379. }());
  380. /* Node.js helper references. */
  381. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  382. nodeIsDate = nodeUtil && nodeUtil.isDate,
  383. nodeIsMap = nodeUtil && nodeUtil.isMap,
  384. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  385. nodeIsSet = nodeUtil && nodeUtil.isSet,
  386. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  387. /*--------------------------------------------------------------------------*/
  388. /**
  389. * Adds the key-value `pair` to `map`.
  390. *
  391. * @private
  392. * @param {Object} map The map to modify.
  393. * @param {Array} pair The key-value pair to add.
  394. * @returns {Object} Returns `map`.
  395. */
  396. function addMapEntry(map, pair) {
  397. // Don't return `map.set` because it's not chainable in IE 11.
  398. map.set(pair[0], pair[1]);
  399. return map;
  400. }
  401. /**
  402. * Adds `value` to `set`.
  403. *
  404. * @private
  405. * @param {Object} set The set to modify.
  406. * @param {*} value The value to add.
  407. * @returns {Object} Returns `set`.
  408. */
  409. function addSetEntry(set, value) {
  410. // Don't return `set.add` because it's not chainable in IE 11.
  411. set.add(value);
  412. return set;
  413. }
  414. /**
  415. * A faster alternative to `Function#apply`, this function invokes `func`
  416. * with the `this` binding of `thisArg` and the arguments of `args`.
  417. *
  418. * @private
  419. * @param {Function} func The function to invoke.
  420. * @param {*} thisArg The `this` binding of `func`.
  421. * @param {Array} args The arguments to invoke `func` with.
  422. * @returns {*} Returns the result of `func`.
  423. */
  424. function apply(func, thisArg, args) {
  425. switch (args.length) {
  426. case 0: return func.call(thisArg);
  427. case 1: return func.call(thisArg, args[0]);
  428. case 2: return func.call(thisArg, args[0], args[1]);
  429. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  430. }
  431. return func.apply(thisArg, args);
  432. }
  433. /**
  434. * A specialized version of `baseAggregator` for arrays.
  435. *
  436. * @private
  437. * @param {Array} [array] The array to iterate over.
  438. * @param {Function} setter The function to set `accumulator` values.
  439. * @param {Function} iteratee The iteratee to transform keys.
  440. * @param {Object} accumulator The initial aggregated object.
  441. * @returns {Function} Returns `accumulator`.
  442. */
  443. function arrayAggregator(array, setter, iteratee, accumulator) {
  444. var index = -1,
  445. length = array == null ? 0 : array.length;
  446. while (++index < length) {
  447. var value = array[index];
  448. setter(accumulator, value, iteratee(value), array);
  449. }
  450. return accumulator;
  451. }
  452. /**
  453. * A specialized version of `_.forEach` for arrays without support for
  454. * iteratee shorthands.
  455. *
  456. * @private
  457. * @param {Array} [array] The array to iterate over.
  458. * @param {Function} iteratee The function invoked per iteration.
  459. * @returns {Array} Returns `array`.
  460. */
  461. function arrayEach(array, iteratee) {
  462. var index = -1,
  463. length = array == null ? 0 : array.length;
  464. while (++index < length) {
  465. if (iteratee(array[index], index, array) === false) {
  466. break;
  467. }
  468. }
  469. return array;
  470. }
  471. /**
  472. * A specialized version of `_.forEachRight` for arrays without support for
  473. * iteratee shorthands.
  474. *
  475. * @private
  476. * @param {Array} [array] The array to iterate over.
  477. * @param {Function} iteratee The function invoked per iteration.
  478. * @returns {Array} Returns `array`.
  479. */
  480. function arrayEachRight(array, iteratee) {
  481. var length = array == null ? 0 : array.length;
  482. while (length--) {
  483. if (iteratee(array[length], length, array) === false) {
  484. break;
  485. }
  486. }
  487. return array;
  488. }
  489. /**
  490. * A specialized version of `_.every` for arrays without support for
  491. * iteratee shorthands.
  492. *
  493. * @private
  494. * @param {Array} [array] The array to iterate over.
  495. * @param {Function} predicate The function invoked per iteration.
  496. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  497. * else `false`.
  498. */
  499. function arrayEvery(array, predicate) {
  500. var index = -1,
  501. length = array == null ? 0 : array.length;
  502. while (++index < length) {
  503. if (!predicate(array[index], index, array)) {
  504. return false;
  505. }
  506. }
  507. return true;
  508. }
  509. /**
  510. * A specialized version of `_.filter` for arrays without support for
  511. * iteratee shorthands.
  512. *
  513. * @private
  514. * @param {Array} [array] The array to iterate over.
  515. * @param {Function} predicate The function invoked per iteration.
  516. * @returns {Array} Returns the new filtered array.
  517. */
  518. function arrayFilter(array, predicate) {
  519. var index = -1,
  520. length = array == null ? 0 : array.length,
  521. resIndex = 0,
  522. result = [];
  523. while (++index < length) {
  524. var value = array[index];
  525. if (predicate(value, index, array)) {
  526. result[resIndex++] = value;
  527. }
  528. }
  529. return result;
  530. }
  531. /**
  532. * A specialized version of `_.includes` for arrays without support for
  533. * specifying an index to search from.
  534. *
  535. * @private
  536. * @param {Array} [array] The array to inspect.
  537. * @param {*} target The value to search for.
  538. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  539. */
  540. function arrayIncludes(array, value) {
  541. var length = array == null ? 0 : array.length;
  542. return !!length && baseIndexOf(array, value, 0) > -1;
  543. }
  544. /**
  545. * This function is like `arrayIncludes` except that it accepts a comparator.
  546. *
  547. * @private
  548. * @param {Array} [array] The array to inspect.
  549. * @param {*} target The value to search for.
  550. * @param {Function} comparator The comparator invoked per element.
  551. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  552. */
  553. function arrayIncludesWith(array, value, comparator) {
  554. var index = -1,
  555. length = array == null ? 0 : array.length;
  556. while (++index < length) {
  557. if (comparator(value, array[index])) {
  558. return true;
  559. }
  560. }
  561. return false;
  562. }
  563. /**
  564. * A specialized version of `_.map` for arrays without support for iteratee
  565. * shorthands.
  566. *
  567. * @private
  568. * @param {Array} [array] The array to iterate over.
  569. * @param {Function} iteratee The function invoked per iteration.
  570. * @returns {Array} Returns the new mapped array.
  571. */
  572. function arrayMap(array, iteratee) {
  573. var index = -1,
  574. length = array == null ? 0 : array.length,
  575. result = Array(length);
  576. while (++index < length) {
  577. result[index] = iteratee(array[index], index, array);
  578. }
  579. return result;
  580. }
  581. /**
  582. * Appends the elements of `values` to `array`.
  583. *
  584. * @private
  585. * @param {Array} array The array to modify.
  586. * @param {Array} values The values to append.
  587. * @returns {Array} Returns `array`.
  588. */
  589. function arrayPush(array, values) {
  590. var index = -1,
  591. length = values.length,
  592. offset = array.length;
  593. while (++index < length) {
  594. array[offset + index] = values[index];
  595. }
  596. return array;
  597. }
  598. /**
  599. * A specialized version of `_.reduce` for arrays without support for
  600. * iteratee shorthands.
  601. *
  602. * @private
  603. * @param {Array} [array] The array to iterate over.
  604. * @param {Function} iteratee The function invoked per iteration.
  605. * @param {*} [accumulator] The initial value.
  606. * @param {boolean} [initAccum] Specify using the first element of `array` as
  607. * the initial value.
  608. * @returns {*} Returns the accumulated value.
  609. */
  610. function arrayReduce(array, iteratee, accumulator, initAccum) {
  611. var index = -1,
  612. length = array == null ? 0 : array.length;
  613. if (initAccum && length) {
  614. accumulator = array[++index];
  615. }
  616. while (++index < length) {
  617. accumulator = iteratee(accumulator, array[index], index, array);
  618. }
  619. return accumulator;
  620. }
  621. /**
  622. * A specialized version of `_.reduceRight` for arrays without support for
  623. * iteratee shorthands.
  624. *
  625. * @private
  626. * @param {Array} [array] The array to iterate over.
  627. * @param {Function} iteratee The function invoked per iteration.
  628. * @param {*} [accumulator] The initial value.
  629. * @param {boolean} [initAccum] Specify using the last element of `array` as
  630. * the initial value.
  631. * @returns {*} Returns the accumulated value.
  632. */
  633. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  634. var length = array == null ? 0 : array.length;
  635. if (initAccum && length) {
  636. accumulator = array[--length];
  637. }
  638. while (length--) {
  639. accumulator = iteratee(accumulator, array[length], length, array);
  640. }
  641. return accumulator;
  642. }
  643. /**
  644. * A specialized version of `_.some` for arrays without support for iteratee
  645. * shorthands.
  646. *
  647. * @private
  648. * @param {Array} [array] The array to iterate over.
  649. * @param {Function} predicate The function invoked per iteration.
  650. * @returns {boolean} Returns `true` if any element passes the predicate check,
  651. * else `false`.
  652. */
  653. function arraySome(array, predicate) {
  654. var index = -1,
  655. length = array == null ? 0 : array.length;
  656. while (++index < length) {
  657. if (predicate(array[index], index, array)) {
  658. return true;
  659. }
  660. }
  661. return false;
  662. }
  663. /**
  664. * Gets the size of an ASCII `string`.
  665. *
  666. * @private
  667. * @param {string} string The string inspect.
  668. * @returns {number} Returns the string size.
  669. */
  670. var asciiSize = baseProperty('length');
  671. /**
  672. * Converts an ASCII `string` to an array.
  673. *
  674. * @private
  675. * @param {string} string The string to convert.
  676. * @returns {Array} Returns the converted array.
  677. */
  678. function asciiToArray(string) {
  679. return string.split('');
  680. }
  681. /**
  682. * Splits an ASCII `string` into an array of its words.
  683. *
  684. * @private
  685. * @param {string} The string to inspect.
  686. * @returns {Array} Returns the words of `string`.
  687. */
  688. function asciiWords(string) {
  689. return string.match(reAsciiWord) || [];
  690. }
  691. /**
  692. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  693. * without support for iteratee shorthands, which iterates over `collection`
  694. * using `eachFunc`.
  695. *
  696. * @private
  697. * @param {Array|Object} collection The collection to inspect.
  698. * @param {Function} predicate The function invoked per iteration.
  699. * @param {Function} eachFunc The function to iterate over `collection`.
  700. * @returns {*} Returns the found element or its key, else `undefined`.
  701. */
  702. function baseFindKey(collection, predicate, eachFunc) {
  703. var result;
  704. eachFunc(collection, function(value, key, collection) {
  705. if (predicate(value, key, collection)) {
  706. result = key;
  707. return false;
  708. }
  709. });
  710. return result;
  711. }
  712. /**
  713. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  714. * support for iteratee shorthands.
  715. *
  716. * @private
  717. * @param {Array} array The array to inspect.
  718. * @param {Function} predicate The function invoked per iteration.
  719. * @param {number} fromIndex The index to search from.
  720. * @param {boolean} [fromRight] Specify iterating from right to left.
  721. * @returns {number} Returns the index of the matched value, else `-1`.
  722. */
  723. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  724. var length = array.length,
  725. index = fromIndex + (fromRight ? 1 : -1);
  726. while ((fromRight ? index-- : ++index < length)) {
  727. if (predicate(array[index], index, array)) {
  728. return index;
  729. }
  730. }
  731. return -1;
  732. }
  733. /**
  734. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  735. *
  736. * @private
  737. * @param {Array} array The array to inspect.
  738. * @param {*} value The value to search for.
  739. * @param {number} fromIndex The index to search from.
  740. * @returns {number} Returns the index of the matched value, else `-1`.
  741. */
  742. function baseIndexOf(array, value, fromIndex) {
  743. return value === value
  744. ? strictIndexOf(array, value, fromIndex)
  745. : baseFindIndex(array, baseIsNaN, fromIndex);
  746. }
  747. /**
  748. * This function is like `baseIndexOf` except that it accepts a comparator.
  749. *
  750. * @private
  751. * @param {Array} array The array to inspect.
  752. * @param {*} value The value to search for.
  753. * @param {number} fromIndex The index to search from.
  754. * @param {Function} comparator The comparator invoked per element.
  755. * @returns {number} Returns the index of the matched value, else `-1`.
  756. */
  757. function baseIndexOfWith(array, value, fromIndex, comparator) {
  758. var index = fromIndex - 1,
  759. length = array.length;
  760. while (++index < length) {
  761. if (comparator(array[index], value)) {
  762. return index;
  763. }
  764. }
  765. return -1;
  766. }
  767. /**
  768. * The base implementation of `_.isNaN` without support for number objects.
  769. *
  770. * @private
  771. * @param {*} value The value to check.
  772. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  773. */
  774. function baseIsNaN(value) {
  775. return value !== value;
  776. }
  777. /**
  778. * The base implementation of `_.mean` and `_.meanBy` without support for
  779. * iteratee shorthands.
  780. *
  781. * @private
  782. * @param {Array} array The array to iterate over.
  783. * @param {Function} iteratee The function invoked per iteration.
  784. * @returns {number} Returns the mean.
  785. */
  786. function baseMean(array, iteratee) {
  787. var length = array == null ? 0 : array.length;
  788. return length ? (baseSum(array, iteratee) / length) : NAN;
  789. }
  790. /**
  791. * The base implementation of `_.property` without support for deep paths.
  792. *
  793. * @private
  794. * @param {string} key The key of the property to get.
  795. * @returns {Function} Returns the new accessor function.
  796. */
  797. function baseProperty(key) {
  798. return function(object) {
  799. return object == null ? undefined : object[key];
  800. };
  801. }
  802. /**
  803. * The base implementation of `_.propertyOf` without support for deep paths.
  804. *
  805. * @private
  806. * @param {Object} object The object to query.
  807. * @returns {Function} Returns the new accessor function.
  808. */
  809. function basePropertyOf(object) {
  810. return function(key) {
  811. return object == null ? undefined : object[key];
  812. };
  813. }
  814. /**
  815. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  816. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  817. *
  818. * @private
  819. * @param {Array|Object} collection The collection to iterate over.
  820. * @param {Function} iteratee The function invoked per iteration.
  821. * @param {*} accumulator The initial value.
  822. * @param {boolean} initAccum Specify using the first or last element of
  823. * `collection` as the initial value.
  824. * @param {Function} eachFunc The function to iterate over `collection`.
  825. * @returns {*} Returns the accumulated value.
  826. */
  827. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  828. eachFunc(collection, function(value, index, collection) {
  829. accumulator = initAccum
  830. ? (initAccum = false, value)
  831. : iteratee(accumulator, value, index, collection);
  832. });
  833. return accumulator;
  834. }
  835. /**
  836. * The base implementation of `_.sortBy` which uses `comparer` to define the
  837. * sort order of `array` and replaces criteria objects with their corresponding
  838. * values.
  839. *
  840. * @private
  841. * @param {Array} array The array to sort.
  842. * @param {Function} comparer The function to define sort order.
  843. * @returns {Array} Returns `array`.
  844. */
  845. function baseSortBy(array, comparer) {
  846. var length = array.length;
  847. array.sort(comparer);
  848. while (length--) {
  849. array[length] = array[length].value;
  850. }
  851. return array;
  852. }
  853. /**
  854. * The base implementation of `_.sum` and `_.sumBy` without support for
  855. * iteratee shorthands.
  856. *
  857. * @private
  858. * @param {Array} array The array to iterate over.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {number} Returns the sum.
  861. */
  862. function baseSum(array, iteratee) {
  863. var result,
  864. index = -1,
  865. length = array.length;
  866. while (++index < length) {
  867. var current = iteratee(array[index]);
  868. if (current !== undefined) {
  869. result = result === undefined ? current : (result + current);
  870. }
  871. }
  872. return result;
  873. }
  874. /**
  875. * The base implementation of `_.times` without support for iteratee shorthands
  876. * or max array length checks.
  877. *
  878. * @private
  879. * @param {number} n The number of times to invoke `iteratee`.
  880. * @param {Function} iteratee The function invoked per iteration.
  881. * @returns {Array} Returns the array of results.
  882. */
  883. function baseTimes(n, iteratee) {
  884. var index = -1,
  885. result = Array(n);
  886. while (++index < n) {
  887. result[index] = iteratee(index);
  888. }
  889. return result;
  890. }
  891. /**
  892. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  893. * of key-value pairs for `object` corresponding to the property names of `props`.
  894. *
  895. * @private
  896. * @param {Object} object The object to query.
  897. * @param {Array} props The property names to get values for.
  898. * @returns {Object} Returns the key-value pairs.
  899. */
  900. function baseToPairs(object, props) {
  901. return arrayMap(props, function(key) {
  902. return [key, object[key]];
  903. });
  904. }
  905. /**
  906. * The base implementation of `_.unary` without support for storing metadata.
  907. *
  908. * @private
  909. * @param {Function} func The function to cap arguments for.
  910. * @returns {Function} Returns the new capped function.
  911. */
  912. function baseUnary(func) {
  913. return function(value) {
  914. return func(value);
  915. };
  916. }
  917. /**
  918. * The base implementation of `_.values` and `_.valuesIn` which creates an
  919. * array of `object` property values corresponding to the property names
  920. * of `props`.
  921. *
  922. * @private
  923. * @param {Object} object The object to query.
  924. * @param {Array} props The property names to get values for.
  925. * @returns {Object} Returns the array of property values.
  926. */
  927. function baseValues(object, props) {
  928. return arrayMap(props, function(key) {
  929. return object[key];
  930. });
  931. }
  932. /**
  933. * Checks if a `cache` value for `key` exists.
  934. *
  935. * @private
  936. * @param {Object} cache The cache to query.
  937. * @param {string} key The key of the entry to check.
  938. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  939. */
  940. function cacheHas(cache, key) {
  941. return cache.has(key);
  942. }
  943. /**
  944. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  945. * that is not found in the character symbols.
  946. *
  947. * @private
  948. * @param {Array} strSymbols The string symbols to inspect.
  949. * @param {Array} chrSymbols The character symbols to find.
  950. * @returns {number} Returns the index of the first unmatched string symbol.
  951. */
  952. function charsStartIndex(strSymbols, chrSymbols) {
  953. var index = -1,
  954. length = strSymbols.length;
  955. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  956. return index;
  957. }
  958. /**
  959. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  960. * that is not found in the character symbols.
  961. *
  962. * @private
  963. * @param {Array} strSymbols The string symbols to inspect.
  964. * @param {Array} chrSymbols The character symbols to find.
  965. * @returns {number} Returns the index of the last unmatched string symbol.
  966. */
  967. function charsEndIndex(strSymbols, chrSymbols) {
  968. var index = strSymbols.length;
  969. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  970. return index;
  971. }
  972. /**
  973. * Gets the number of `placeholder` occurrences in `array`.
  974. *
  975. * @private
  976. * @param {Array} array The array to inspect.
  977. * @param {*} placeholder The placeholder to search for.
  978. * @returns {number} Returns the placeholder count.
  979. */
  980. function countHolders(array, placeholder) {
  981. var length = array.length,
  982. result = 0;
  983. while (length--) {
  984. if (array[length] === placeholder) {
  985. ++result;
  986. }
  987. }
  988. return result;
  989. }
  990. /**
  991. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  992. * letters to basic Latin letters.
  993. *
  994. * @private
  995. * @param {string} letter The matched letter to deburr.
  996. * @returns {string} Returns the deburred letter.
  997. */
  998. var deburrLetter = basePropertyOf(deburredLetters);
  999. /**
  1000. * Used by `_.escape` to convert characters to HTML entities.
  1001. *
  1002. * @private
  1003. * @param {string} chr The matched character to escape.
  1004. * @returns {string} Returns the escaped character.
  1005. */
  1006. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1007. /**
  1008. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1009. *
  1010. * @private
  1011. * @param {string} chr The matched character to escape.
  1012. * @returns {string} Returns the escaped character.
  1013. */
  1014. function escapeStringChar(chr) {
  1015. return '\\' + stringEscapes[chr];
  1016. }
  1017. /**
  1018. * Gets the value at `key` of `object`.
  1019. *
  1020. * @private
  1021. * @param {Object} [object] The object to query.
  1022. * @param {string} key The key of the property to get.
  1023. * @returns {*} Returns the property value.
  1024. */
  1025. function getValue(object, key) {
  1026. return object == null ? undefined : object[key];
  1027. }
  1028. /**
  1029. * Checks if `string` contains Unicode symbols.
  1030. *
  1031. * @private
  1032. * @param {string} string The string to inspect.
  1033. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1034. */
  1035. function hasUnicode(string) {
  1036. return reHasUnicode.test(string);
  1037. }
  1038. /**
  1039. * Checks if `string` contains a word composed of Unicode symbols.
  1040. *
  1041. * @private
  1042. * @param {string} string The string to inspect.
  1043. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1044. */
  1045. function hasUnicodeWord(string) {
  1046. return reHasUnicodeWord.test(string);
  1047. }
  1048. /**
  1049. * Converts `iterator` to an array.
  1050. *
  1051. * @private
  1052. * @param {Object} iterator The iterator to convert.
  1053. * @returns {Array} Returns the converted array.
  1054. */
  1055. function iteratorToArray(iterator) {
  1056. var data,
  1057. result = [];
  1058. while (!(data = iterator.next()).done) {
  1059. result.push(data.value);
  1060. }
  1061. return result;
  1062. }
  1063. /**
  1064. * Converts `map` to its key-value pairs.
  1065. *
  1066. * @private
  1067. * @param {Object} map The map to convert.
  1068. * @returns {Array} Returns the key-value pairs.
  1069. */
  1070. function mapToArray(map) {
  1071. var index = -1,
  1072. result = Array(map.size);
  1073. map.forEach(function(value, key) {
  1074. result[++index] = [key, value];
  1075. });
  1076. return result;
  1077. }
  1078. /**
  1079. * Creates a unary function that invokes `func` with its argument transformed.
  1080. *
  1081. * @private
  1082. * @param {Function} func The function to wrap.
  1083. * @param {Function} transform The argument transform.
  1084. * @returns {Function} Returns the new function.
  1085. */
  1086. function overArg(func, transform) {
  1087. return function(arg) {
  1088. return func(transform(arg));
  1089. };
  1090. }
  1091. /**
  1092. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1093. * and returns an array of their indexes.
  1094. *
  1095. * @private
  1096. * @param {Array} array The array to modify.
  1097. * @param {*} placeholder The placeholder to replace.
  1098. * @returns {Array} Returns the new array of placeholder indexes.
  1099. */
  1100. function replaceHolders(array, placeholder) {
  1101. var index = -1,
  1102. length = array.length,
  1103. resIndex = 0,
  1104. result = [];
  1105. while (++index < length) {
  1106. var value = array[index];
  1107. if (value === placeholder || value === PLACEHOLDER) {
  1108. array[index] = PLACEHOLDER;
  1109. result[resIndex++] = index;
  1110. }
  1111. }
  1112. return result;
  1113. }
  1114. /**
  1115. * Converts `set` to an array of its values.
  1116. *
  1117. * @private
  1118. * @param {Object} set The set to convert.
  1119. * @returns {Array} Returns the values.
  1120. */
  1121. function setToArray(set) {
  1122. var index = -1,
  1123. result = Array(set.size);
  1124. set.forEach(function(value) {
  1125. result[++index] = value;
  1126. });
  1127. return result;
  1128. }
  1129. /**
  1130. * Converts `set` to its value-value pairs.
  1131. *
  1132. * @private
  1133. * @param {Object} set The set to convert.
  1134. * @returns {Array} Returns the value-value pairs.
  1135. */
  1136. function setToPairs(set) {
  1137. var index = -1,
  1138. result = Array(set.size);
  1139. set.forEach(function(value) {
  1140. result[++index] = [value, value];
  1141. });
  1142. return result;
  1143. }
  1144. /**
  1145. * A specialized version of `_.indexOf` which performs strict equality
  1146. * comparisons of values, i.e. `===`.
  1147. *
  1148. * @private
  1149. * @param {Array} array The array to inspect.
  1150. * @param {*} value The value to search for.
  1151. * @param {number} fromIndex The index to search from.
  1152. * @returns {number} Returns the index of the matched value, else `-1`.
  1153. */
  1154. function strictIndexOf(array, value, fromIndex) {
  1155. var index = fromIndex - 1,
  1156. length = array.length;
  1157. while (++index < length) {
  1158. if (array[index] === value) {
  1159. return index;
  1160. }
  1161. }
  1162. return -1;
  1163. }
  1164. /**
  1165. * A specialized version of `_.lastIndexOf` which performs strict equality
  1166. * comparisons of values, i.e. `===`.
  1167. *
  1168. * @private
  1169. * @param {Array} array The array to inspect.
  1170. * @param {*} value The value to search for.
  1171. * @param {number} fromIndex The index to search from.
  1172. * @returns {number} Returns the index of the matched value, else `-1`.
  1173. */
  1174. function strictLastIndexOf(array, value, fromIndex) {
  1175. var index = fromIndex + 1;
  1176. while (index--) {
  1177. if (array[index] === value) {
  1178. return index;
  1179. }
  1180. }
  1181. return index;
  1182. }
  1183. /**
  1184. * Gets the number of symbols in `string`.
  1185. *
  1186. * @private
  1187. * @param {string} string The string to inspect.
  1188. * @returns {number} Returns the string size.
  1189. */
  1190. function stringSize(string) {
  1191. return hasUnicode(string)
  1192. ? unicodeSize(string)
  1193. : asciiSize(string);
  1194. }
  1195. /**
  1196. * Converts `string` to an array.
  1197. *
  1198. * @private
  1199. * @param {string} string The string to convert.
  1200. * @returns {Array} Returns the converted array.
  1201. */
  1202. function stringToArray(string) {
  1203. return hasUnicode(string)
  1204. ? unicodeToArray(string)
  1205. : asciiToArray(string);
  1206. }
  1207. /**
  1208. * Used by `_.unescape` to convert HTML entities to characters.
  1209. *
  1210. * @private
  1211. * @param {string} chr The matched character to unescape.
  1212. * @returns {string} Returns the unescaped character.
  1213. */
  1214. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1215. /**
  1216. * Gets the size of a Unicode `string`.
  1217. *
  1218. * @private
  1219. * @param {string} string The string inspect.
  1220. * @returns {number} Returns the string size.
  1221. */
  1222. function unicodeSize(string) {
  1223. var result = reUnicode.lastIndex = 0;
  1224. while (reUnicode.test(string)) {
  1225. ++result;
  1226. }
  1227. return result;
  1228. }
  1229. /**
  1230. * Converts a Unicode `string` to an array.
  1231. *
  1232. * @private
  1233. * @param {string} string The string to convert.
  1234. * @returns {Array} Returns the converted array.
  1235. */
  1236. function unicodeToArray(string) {
  1237. return string.match(reUnicode) || [];
  1238. }
  1239. /**
  1240. * Splits a Unicode `string` into an array of its words.
  1241. *
  1242. * @private
  1243. * @param {string} The string to inspect.
  1244. * @returns {Array} Returns the words of `string`.
  1245. */
  1246. function unicodeWords(string) {
  1247. return string.match(reUnicodeWord) || [];
  1248. }
  1249. /*--------------------------------------------------------------------------*/
  1250. /**
  1251. * Create a new pristine `lodash` function using the `context` object.
  1252. *
  1253. * @static
  1254. * @memberOf _
  1255. * @since 1.1.0
  1256. * @category Util
  1257. * @param {Object} [context=root] The context object.
  1258. * @returns {Function} Returns a new `lodash` function.
  1259. * @example
  1260. *
  1261. * _.mixin({ 'foo': _.constant('foo') });
  1262. *
  1263. * var lodash = _.runInContext();
  1264. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1265. *
  1266. * _.isFunction(_.foo);
  1267. * // => true
  1268. * _.isFunction(_.bar);
  1269. * // => false
  1270. *
  1271. * lodash.isFunction(lodash.foo);
  1272. * // => false
  1273. * lodash.isFunction(lodash.bar);
  1274. * // => true
  1275. *
  1276. * // Create a suped-up `defer` in Node.js.
  1277. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1278. */
  1279. var runInContext = (function runInContext(context) {
  1280. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1281. /** Built-in constructor references. */
  1282. var Array = context.Array,
  1283. Date = context.Date,
  1284. Error = context.Error,
  1285. Function = context.Function,
  1286. Math = context.Math,
  1287. Object = context.Object,
  1288. RegExp = context.RegExp,
  1289. String = context.String,
  1290. TypeError = context.TypeError;
  1291. /** Used for built-in method references. */
  1292. var arrayProto = Array.prototype,
  1293. funcProto = Function.prototype,
  1294. objectProto = Object.prototype;
  1295. /** Used to detect overreaching core-js shims. */
  1296. var coreJsData = context['__core-js_shared__'];
  1297. /** Used to resolve the decompiled source of functions. */
  1298. var funcToString = funcProto.toString;
  1299. /** Used to check objects for own properties. */
  1300. var hasOwnProperty = objectProto.hasOwnProperty;
  1301. /** Used to generate unique IDs. */
  1302. var idCounter = 0;
  1303. /** Used to detect methods masquerading as native. */
  1304. var maskSrcKey = (function() {
  1305. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1306. return uid ? ('Symbol(src)_1.' + uid) : '';
  1307. }());
  1308. /**
  1309. * Used to resolve the
  1310. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1311. * of values.
  1312. */
  1313. var nativeObjectToString = objectProto.toString;
  1314. /** Used to infer the `Object` constructor. */
  1315. var objectCtorString = funcToString.call(Object);
  1316. /** Used to restore the original `_` reference in `_.noConflict`. */
  1317. var oldDash = root._;
  1318. /** Used to detect if a method is native. */
  1319. var reIsNative = RegExp('^' +
  1320. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1321. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1322. );
  1323. /** Built-in value references. */
  1324. var Buffer = moduleExports ? context.Buffer : undefined,
  1325. Symbol = context.Symbol,
  1326. Uint8Array = context.Uint8Array,
  1327. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1328. getPrototype = overArg(Object.getPrototypeOf, Object),
  1329. objectCreate = Object.create,
  1330. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1331. splice = arrayProto.splice,
  1332. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1333. symIterator = Symbol ? Symbol.iterator : undefined,
  1334. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1335. var defineProperty = (function() {
  1336. try {
  1337. var func = getNative(Object, 'defineProperty');
  1338. func({}, '', {});
  1339. return func;
  1340. } catch (e) {}
  1341. }());
  1342. /** Mocked built-ins. */
  1343. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1344. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1345. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1346. /* Built-in method references for those with the same name as other `lodash` methods. */
  1347. var nativeCeil = Math.ceil,
  1348. nativeFloor = Math.floor,
  1349. nativeGetSymbols = Object.getOwnPropertySymbols,
  1350. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1351. nativeIsFinite = context.isFinite,
  1352. nativeJoin = arrayProto.join,
  1353. nativeKeys = overArg(Object.keys, Object),
  1354. nativeMax = Math.max,
  1355. nativeMin = Math.min,
  1356. nativeNow = Date.now,
  1357. nativeParseInt = context.parseInt,
  1358. nativeRandom = Math.random,
  1359. nativeReverse = arrayProto.reverse;
  1360. /* Built-in method references that are verified to be native. */
  1361. var DataView = getNative(context, 'DataView'),
  1362. Map = getNative(context, 'Map'),
  1363. Promise = getNative(context, 'Promise'),
  1364. Set = getNative(context, 'Set'),
  1365. WeakMap = getNative(context, 'WeakMap'),
  1366. nativeCreate = getNative(Object, 'create');
  1367. /** Used to store function metadata. */
  1368. var metaMap = WeakMap && new WeakMap;
  1369. /** Used to lookup unminified function names. */
  1370. var realNames = {};
  1371. /** Used to detect maps, sets, and weakmaps. */
  1372. var dataViewCtorString = toSource(DataView),
  1373. mapCtorString = toSource(Map),
  1374. promiseCtorString = toSource(Promise),
  1375. setCtorString = toSource(Set),
  1376. weakMapCtorString = toSource(WeakMap);
  1377. /** Used to convert symbols to primitives and strings. */
  1378. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1379. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1380. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1381. /*------------------------------------------------------------------------*/
  1382. /**
  1383. * Creates a `lodash` object which wraps `value` to enable implicit method
  1384. * chain sequences. Methods that operate on and return arrays, collections,
  1385. * and functions can be chained together. Methods that retrieve a single value
  1386. * or may return a primitive value will automatically end the chain sequence
  1387. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1388. * with `_#value`.
  1389. *
  1390. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1391. * enabled using `_.chain`.
  1392. *
  1393. * The execution of chained methods is lazy, that is, it's deferred until
  1394. * `_#value` is implicitly or explicitly called.
  1395. *
  1396. * Lazy evaluation allows several methods to support shortcut fusion.
  1397. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1398. * the creation of intermediate arrays and can greatly reduce the number of
  1399. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1400. * fusion if the section is applied to an array and iteratees accept only
  1401. * one argument. The heuristic for whether a section qualifies for shortcut
  1402. * fusion is subject to change.
  1403. *
  1404. * Chaining is supported in custom builds as long as the `_#value` method is
  1405. * directly or indirectly included in the build.
  1406. *
  1407. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1408. *
  1409. * The wrapper `Array` methods are:
  1410. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1411. *
  1412. * The wrapper `String` methods are:
  1413. * `replace` and `split`
  1414. *
  1415. * The wrapper methods that support shortcut fusion are:
  1416. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1417. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1418. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1419. *
  1420. * The chainable wrapper methods are:
  1421. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1422. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1423. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1424. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1425. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1426. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1427. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1428. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1429. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1430. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1431. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1432. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1433. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1434. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1435. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1436. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1437. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1438. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1439. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1440. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1441. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1442. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1443. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1444. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1445. *
  1446. * The wrapper methods that are **not** chainable by default are:
  1447. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1448. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1449. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1450. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1451. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1452. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1453. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1454. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1455. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1456. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1457. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1458. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1459. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1460. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1461. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1462. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1463. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1464. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1465. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1466. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1467. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1468. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1469. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1470. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1471. * `upperFirst`, `value`, and `words`
  1472. *
  1473. * @name _
  1474. * @constructor
  1475. * @category Seq
  1476. * @param {*} value The value to wrap in a `lodash` instance.
  1477. * @returns {Object} Returns the new `lodash` wrapper instance.
  1478. * @example
  1479. *
  1480. * function square(n) {
  1481. * return n * n;
  1482. * }
  1483. *
  1484. * var wrapped = _([1, 2, 3]);
  1485. *
  1486. * // Returns an unwrapped value.
  1487. * wrapped.reduce(_.add);
  1488. * // => 6
  1489. *
  1490. * // Returns a wrapped value.
  1491. * var squares = wrapped.map(square);
  1492. *
  1493. * _.isArray(squares);
  1494. * // => false
  1495. *
  1496. * _.isArray(squares.value());
  1497. * // => true
  1498. */
  1499. function lodash(value) {
  1500. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1501. if (value instanceof LodashWrapper) {
  1502. return value;
  1503. }
  1504. if (hasOwnProperty.call(value, '__wrapped__')) {
  1505. return wrapperClone(value);
  1506. }
  1507. }
  1508. return new LodashWrapper(value);
  1509. }
  1510. /**
  1511. * The base implementation of `_.create` without support for assigning
  1512. * properties to the created object.
  1513. *
  1514. * @private
  1515. * @param {Object} proto The object to inherit from.
  1516. * @returns {Object} Returns the new object.
  1517. */
  1518. var baseCreate = (function() {
  1519. function object() {}
  1520. return function(proto) {
  1521. if (!isObject(proto)) {
  1522. return {};
  1523. }
  1524. if (objectCreate) {
  1525. return objectCreate(proto);
  1526. }
  1527. object.prototype = proto;
  1528. var result = new object;
  1529. object.prototype = undefined;
  1530. return result;
  1531. };
  1532. }());
  1533. /**
  1534. * The function whose prototype chain sequence wrappers inherit from.
  1535. *
  1536. * @private
  1537. */
  1538. function baseLodash() {
  1539. // No operation performed.
  1540. }
  1541. /**
  1542. * The base constructor for creating `lodash` wrapper objects.
  1543. *
  1544. * @private
  1545. * @param {*} value The value to wrap.
  1546. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1547. */
  1548. function LodashWrapper(value, chainAll) {
  1549. this.__wrapped__ = value;
  1550. this.__actions__ = [];
  1551. this.__chain__ = !!chainAll;
  1552. this.__index__ = 0;
  1553. this.__values__ = undefined;
  1554. }
  1555. /**
  1556. * By default, the template delimiters used by lodash are like those in
  1557. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1558. * following template settings to use alternative delimiters.
  1559. *
  1560. * @static
  1561. * @memberOf _
  1562. * @type {Object}
  1563. */
  1564. lodash.templateSettings = {
  1565. /**
  1566. * Used to detect `data` property values to be HTML-escaped.
  1567. *
  1568. * @memberOf _.templateSettings
  1569. * @type {RegExp}
  1570. */
  1571. 'escape': reEscape,
  1572. /**
  1573. * Used to detect code to be evaluated.
  1574. *
  1575. * @memberOf _.templateSettings
  1576. * @type {RegExp}
  1577. */
  1578. 'evaluate': reEvaluate,
  1579. /**
  1580. * Used to detect `data` property values to inject.
  1581. *
  1582. * @memberOf _.templateSettings
  1583. * @type {RegExp}
  1584. */
  1585. 'interpolate': reInterpolate,
  1586. /**
  1587. * Used to reference the data object in the template text.
  1588. *
  1589. * @memberOf _.templateSettings
  1590. * @type {string}
  1591. */
  1592. 'variable': '',
  1593. /**
  1594. * Used to import variables into the compiled template.
  1595. *
  1596. * @memberOf _.templateSettings
  1597. * @type {Object}
  1598. */
  1599. 'imports': {
  1600. /**
  1601. * A reference to the `lodash` function.
  1602. *
  1603. * @memberOf _.templateSettings.imports
  1604. * @type {Function}
  1605. */
  1606. '_': lodash
  1607. }
  1608. };
  1609. // Ensure wrappers are instances of `baseLodash`.
  1610. lodash.prototype = baseLodash.prototype;
  1611. lodash.prototype.constructor = lodash;
  1612. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1613. LodashWrapper.prototype.constructor = LodashWrapper;
  1614. /*------------------------------------------------------------------------*/
  1615. /**
  1616. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1617. *
  1618. * @private
  1619. * @constructor
  1620. * @param {*} value The value to wrap.
  1621. */
  1622. function LazyWrapper(value) {
  1623. this.__wrapped__ = value;
  1624. this.__actions__ = [];
  1625. this.__dir__ = 1;
  1626. this.__filtered__ = false;
  1627. this.__iteratees__ = [];
  1628. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1629. this.__views__ = [];
  1630. }
  1631. /**
  1632. * Creates a clone of the lazy wrapper object.
  1633. *
  1634. * @private
  1635. * @name clone
  1636. * @memberOf LazyWrapper
  1637. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1638. */
  1639. function lazyClone() {
  1640. var result = new LazyWrapper(this.__wrapped__);
  1641. result.__actions__ = copyArray(this.__actions__);
  1642. result.__dir__ = this.__dir__;
  1643. result.__filtered__ = this.__filtered__;
  1644. result.__iteratees__ = copyArray(this.__iteratees__);
  1645. result.__takeCount__ = this.__takeCount__;
  1646. result.__views__ = copyArray(this.__views__);
  1647. return result;
  1648. }
  1649. /**
  1650. * Reverses the direction of lazy iteration.
  1651. *
  1652. * @private
  1653. * @name reverse
  1654. * @memberOf LazyWrapper
  1655. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1656. */
  1657. function lazyReverse() {
  1658. if (this.__filtered__) {
  1659. var result = new LazyWrapper(this);
  1660. result.__dir__ = -1;
  1661. result.__filtered__ = true;
  1662. } else {
  1663. result = this.clone();
  1664. result.__dir__ *= -1;
  1665. }
  1666. return result;
  1667. }
  1668. /**
  1669. * Extracts the unwrapped value from its lazy wrapper.
  1670. *
  1671. * @private
  1672. * @name value
  1673. * @memberOf LazyWrapper
  1674. * @returns {*} Returns the unwrapped value.
  1675. */
  1676. function lazyValue() {
  1677. var array = this.__wrapped__.value(),
  1678. dir = this.__dir__,
  1679. isArr = isArray(array),
  1680. isRight = dir < 0,
  1681. arrLength = isArr ? array.length : 0,
  1682. view = getView(0, arrLength, this.__views__),
  1683. start = view.start,
  1684. end = view.end,
  1685. length = end - start,
  1686. index = isRight ? end : (start - 1),
  1687. iteratees = this.__iteratees__,
  1688. iterLength = iteratees.length,
  1689. resIndex = 0,
  1690. takeCount = nativeMin(length, this.__takeCount__);
  1691. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1692. return baseWrapperValue(array, this.__actions__);
  1693. }
  1694. var result = [];
  1695. outer:
  1696. while (length-- && resIndex < takeCount) {
  1697. index += dir;
  1698. var iterIndex = -1,
  1699. value = array[index];
  1700. while (++iterIndex < iterLength) {
  1701. var data = iteratees[iterIndex],
  1702. iteratee = data.iteratee,
  1703. type = data.type,
  1704. computed = iteratee(value);
  1705. if (type == LAZY_MAP_FLAG) {
  1706. value = computed;
  1707. } else if (!computed) {
  1708. if (type == LAZY_FILTER_FLAG) {
  1709. continue outer;
  1710. } else {
  1711. break outer;
  1712. }
  1713. }
  1714. }
  1715. result[resIndex++] = value;
  1716. }
  1717. return result;
  1718. }
  1719. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1720. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1721. LazyWrapper.prototype.constructor = LazyWrapper;
  1722. /*------------------------------------------------------------------------*/
  1723. /**
  1724. * Creates a hash object.
  1725. *
  1726. * @private
  1727. * @constructor
  1728. * @param {Array} [entries] The key-value pairs to cache.
  1729. */
  1730. function Hash(entries) {
  1731. var index = -1,
  1732. length = entries == null ? 0 : entries.length;
  1733. this.clear();
  1734. while (++index < length) {
  1735. var entry = entries[index];
  1736. this.set(entry[0], entry[1]);
  1737. }
  1738. }
  1739. /**
  1740. * Removes all key-value entries from the hash.
  1741. *
  1742. * @private
  1743. * @name clear
  1744. * @memberOf Hash
  1745. */
  1746. function hashClear() {
  1747. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1748. this.size = 0;
  1749. }
  1750. /**
  1751. * Removes `key` and its value from the hash.
  1752. *
  1753. * @private
  1754. * @name delete
  1755. * @memberOf Hash
  1756. * @param {Object} hash The hash to modify.
  1757. * @param {string} key The key of the value to remove.
  1758. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1759. */
  1760. function hashDelete(key) {
  1761. var result = this.has(key) && delete this.__data__[key];
  1762. this.size -= result ? 1 : 0;
  1763. return result;
  1764. }
  1765. /**
  1766. * Gets the hash value for `key`.
  1767. *
  1768. * @private
  1769. * @name get
  1770. * @memberOf Hash
  1771. * @param {string} key The key of the value to get.
  1772. * @returns {*} Returns the entry value.
  1773. */
  1774. function hashGet(key) {
  1775. var data = this.__data__;
  1776. if (nativeCreate) {
  1777. var result = data[key];
  1778. return result === HASH_UNDEFINED ? undefined : result;
  1779. }
  1780. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1781. }
  1782. /**
  1783. * Checks if a hash value for `key` exists.
  1784. *
  1785. * @private
  1786. * @name has
  1787. * @memberOf Hash
  1788. * @param {string} key The key of the entry to check.
  1789. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1790. */
  1791. function hashHas(key) {
  1792. var data = this.__data__;
  1793. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1794. }
  1795. /**
  1796. * Sets the hash `key` to `value`.
  1797. *
  1798. * @private
  1799. * @name set
  1800. * @memberOf Hash
  1801. * @param {string} key The key of the value to set.
  1802. * @param {*} value The value to set.
  1803. * @returns {Object} Returns the hash instance.
  1804. */
  1805. function hashSet(key, value) {
  1806. var data = this.__data__;
  1807. this.size += this.has(key) ? 0 : 1;
  1808. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1809. return this;
  1810. }
  1811. // Add methods to `Hash`.
  1812. Hash.prototype.clear = hashClear;
  1813. Hash.prototype['delete'] = hashDelete;
  1814. Hash.prototype.get = hashGet;
  1815. Hash.prototype.has = hashHas;
  1816. Hash.prototype.set = hashSet;
  1817. /*------------------------------------------------------------------------*/
  1818. /**
  1819. * Creates an list cache object.
  1820. *
  1821. * @private
  1822. * @constructor
  1823. * @param {Array} [entries] The key-value pairs to cache.
  1824. */
  1825. function ListCache(entries) {
  1826. var index = -1,
  1827. length = entries == null ? 0 : entries.length;
  1828. this.clear();
  1829. while (++index < length) {
  1830. var entry = entries[index];
  1831. this.set(entry[0], entry[1]);
  1832. }
  1833. }
  1834. /**
  1835. * Removes all key-value entries from the list cache.
  1836. *
  1837. * @private
  1838. * @name clear
  1839. * @memberOf ListCache
  1840. */
  1841. function listCacheClear() {
  1842. this.__data__ = [];
  1843. this.size = 0;
  1844. }
  1845. /**
  1846. * Removes `key` and its value from the list cache.
  1847. *
  1848. * @private
  1849. * @name delete
  1850. * @memberOf ListCache
  1851. * @param {string} key The key of the value to remove.
  1852. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1853. */
  1854. function listCacheDelete(key) {
  1855. var data = this.__data__,
  1856. index = assocIndexOf(data, key);
  1857. if (index < 0) {
  1858. return false;
  1859. }
  1860. var lastIndex = data.length - 1;
  1861. if (index == lastIndex) {
  1862. data.pop();
  1863. } else {
  1864. splice.call(data, index, 1);
  1865. }
  1866. --this.size;
  1867. return true;
  1868. }
  1869. /**
  1870. * Gets the list cache value for `key`.
  1871. *
  1872. * @private
  1873. * @name get
  1874. * @memberOf ListCache
  1875. * @param {string} key The key of the value to get.
  1876. * @returns {*} Returns the entry value.
  1877. */
  1878. function listCacheGet(key) {
  1879. var data = this.__data__,
  1880. index = assocIndexOf(data, key);
  1881. return index < 0 ? undefined : data[index][1];
  1882. }
  1883. /**
  1884. * Checks if a list cache value for `key` exists.
  1885. *
  1886. * @private
  1887. * @name has
  1888. * @memberOf ListCache
  1889. * @param {string} key The key of the entry to check.
  1890. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1891. */
  1892. function listCacheHas(key) {
  1893. return assocIndexOf(this.__data__, key) > -1;
  1894. }
  1895. /**
  1896. * Sets the list cache `key` to `value`.
  1897. *
  1898. * @private
  1899. * @name set
  1900. * @memberOf ListCache
  1901. * @param {string} key The key of the value to set.
  1902. * @param {*} value The value to set.
  1903. * @returns {Object} Returns the list cache instance.
  1904. */
  1905. function listCacheSet(key, value) {
  1906. var data = this.__data__,
  1907. index = assocIndexOf(data, key);
  1908. if (index < 0) {
  1909. ++this.size;
  1910. data.push([key, value]);
  1911. } else {
  1912. data[index][1] = value;
  1913. }
  1914. return this;
  1915. }
  1916. // Add methods to `ListCache`.
  1917. ListCache.prototype.clear = listCacheClear;
  1918. ListCache.prototype['delete'] = listCacheDelete;
  1919. ListCache.prototype.get = listCacheGet;
  1920. ListCache.prototype.has = listCacheHas;
  1921. ListCache.prototype.set = listCacheSet;
  1922. /*------------------------------------------------------------------------*/
  1923. /**
  1924. * Creates a map cache object to store key-value pairs.
  1925. *
  1926. * @private
  1927. * @constructor
  1928. * @param {Array} [entries] The key-value pairs to cache.
  1929. */
  1930. function MapCache(entries) {
  1931. var index = -1,
  1932. length = entries == null ? 0 : entries.length;
  1933. this.clear();
  1934. while (++index < length) {
  1935. var entry = entries[index];
  1936. this.set(entry[0], entry[1]);
  1937. }
  1938. }
  1939. /**
  1940. * Removes all key-value entries from the map.
  1941. *
  1942. * @private
  1943. * @name clear
  1944. * @memberOf MapCache
  1945. */
  1946. function mapCacheClear() {
  1947. this.size = 0;
  1948. this.__data__ = {
  1949. 'hash': new Hash,
  1950. 'map': new (Map || ListCache),
  1951. 'string': new Hash
  1952. };
  1953. }
  1954. /**
  1955. * Removes `key` and its value from the map.
  1956. *
  1957. * @private
  1958. * @name delete
  1959. * @memberOf MapCache
  1960. * @param {string} key The key of the value to remove.
  1961. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1962. */
  1963. function mapCacheDelete(key) {
  1964. var result = getMapData(this, key)['delete'](key);
  1965. this.size -= result ? 1 : 0;
  1966. return result;
  1967. }
  1968. /**
  1969. * Gets the map value for `key`.
  1970. *
  1971. * @private
  1972. * @name get
  1973. * @memberOf MapCache
  1974. * @param {string} key The key of the value to get.
  1975. * @returns {*} Returns the entry value.
  1976. */
  1977. function mapCacheGet(key) {
  1978. return getMapData(this, key).get(key);
  1979. }
  1980. /**
  1981. * Checks if a map value for `key` exists.
  1982. *
  1983. * @private
  1984. * @name has
  1985. * @memberOf MapCache
  1986. * @param {string} key The key of the entry to check.
  1987. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1988. */
  1989. function mapCacheHas(key) {
  1990. return getMapData(this, key).has(key);
  1991. }
  1992. /**
  1993. * Sets the map `key` to `value`.
  1994. *
  1995. * @private
  1996. * @name set
  1997. * @memberOf MapCache
  1998. * @param {string} key The key of the value to set.
  1999. * @param {*} value The value to set.
  2000. * @returns {Object} Returns the map cache instance.
  2001. */
  2002. function mapCacheSet(key, value) {
  2003. var data = getMapData(this, key),
  2004. size = data.size;
  2005. data.set(key, value);
  2006. this.size += data.size == size ? 0 : 1;
  2007. return this;
  2008. }
  2009. // Add methods to `MapCache`.
  2010. MapCache.prototype.clear = mapCacheClear;
  2011. MapCache.prototype['delete'] = mapCacheDelete;
  2012. MapCache.prototype.get = mapCacheGet;
  2013. MapCache.prototype.has = mapCacheHas;
  2014. MapCache.prototype.set = mapCacheSet;
  2015. /*------------------------------------------------------------------------*/
  2016. /**
  2017. *
  2018. * Creates an array cache object to store unique values.
  2019. *
  2020. * @private
  2021. * @constructor
  2022. * @param {Array} [values] The values to cache.
  2023. */
  2024. function SetCache(values) {
  2025. var index = -1,
  2026. length = values == null ? 0 : values.length;
  2027. this.__data__ = new MapCache;
  2028. while (++index < length) {
  2029. this.add(values[index]);
  2030. }
  2031. }
  2032. /**
  2033. * Adds `value` to the array cache.
  2034. *
  2035. * @private
  2036. * @name add
  2037. * @memberOf SetCache
  2038. * @alias push
  2039. * @param {*} value The value to cache.
  2040. * @returns {Object} Returns the cache instance.
  2041. */
  2042. function setCacheAdd(value) {
  2043. this.__data__.set(value, HASH_UNDEFINED);
  2044. return this;
  2045. }
  2046. /**
  2047. * Checks if `value` is in the array cache.
  2048. *
  2049. * @private
  2050. * @name has
  2051. * @memberOf SetCache
  2052. * @param {*} value The value to search for.
  2053. * @returns {number} Returns `true` if `value` is found, else `false`.
  2054. */
  2055. function setCacheHas(value) {
  2056. return this.__data__.has(value);
  2057. }
  2058. // Add methods to `SetCache`.
  2059. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2060. SetCache.prototype.has = setCacheHas;
  2061. /*------------------------------------------------------------------------*/
  2062. /**
  2063. * Creates a stack cache object to store key-value pairs.
  2064. *
  2065. * @private
  2066. * @constructor
  2067. * @param {Array} [entries] The key-value pairs to cache.
  2068. */
  2069. function Stack(entries) {
  2070. var data = this.__data__ = new ListCache(entries);
  2071. this.size = data.size;
  2072. }
  2073. /**
  2074. * Removes all key-value entries from the stack.
  2075. *
  2076. * @private
  2077. * @name clear
  2078. * @memberOf Stack
  2079. */
  2080. function stackClear() {
  2081. this.__data__ = new ListCache;
  2082. this.size = 0;
  2083. }
  2084. /**
  2085. * Removes `key` and its value from the stack.
  2086. *
  2087. * @private
  2088. * @name delete
  2089. * @memberOf Stack
  2090. * @param {string} key The key of the value to remove.
  2091. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2092. */
  2093. function stackDelete(key) {
  2094. var data = this.__data__,
  2095. result = data['delete'](key);
  2096. this.size = data.size;
  2097. return result;
  2098. }
  2099. /**
  2100. * Gets the stack value for `key`.
  2101. *
  2102. * @private
  2103. * @name get
  2104. * @memberOf Stack
  2105. * @param {string} key The key of the value to get.
  2106. * @returns {*} Returns the entry value.
  2107. */
  2108. function stackGet(key) {
  2109. return this.__data__.get(key);
  2110. }
  2111. /**
  2112. * Checks if a stack value for `key` exists.
  2113. *
  2114. * @private
  2115. * @name has
  2116. * @memberOf Stack
  2117. * @param {string} key The key of the entry to check.
  2118. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2119. */
  2120. function stackHas(key) {
  2121. return this.__data__.has(key);
  2122. }
  2123. /**
  2124. * Sets the stack `key` to `value`.
  2125. *
  2126. * @private
  2127. * @name set
  2128. * @memberOf Stack
  2129. * @param {string} key The key of the value to set.
  2130. * @param {*} value The value to set.
  2131. * @returns {Object} Returns the stack cache instance.
  2132. */
  2133. function stackSet(key, value) {
  2134. var data = this.__data__;
  2135. if (data instanceof ListCache) {
  2136. var pairs = data.__data__;
  2137. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2138. pairs.push([key, value]);
  2139. this.size = ++data.size;
  2140. return this;
  2141. }
  2142. data = this.__data__ = new MapCache(pairs);
  2143. }
  2144. data.set(key, value);
  2145. this.size = data.size;
  2146. return this;
  2147. }
  2148. // Add methods to `Stack`.
  2149. Stack.prototype.clear = stackClear;
  2150. Stack.prototype['delete'] = stackDelete;
  2151. Stack.prototype.get = stackGet;
  2152. Stack.prototype.has = stackHas;
  2153. Stack.prototype.set = stackSet;
  2154. /*------------------------------------------------------------------------*/
  2155. /**
  2156. * Creates an array of the enumerable property names of the array-like `value`.
  2157. *
  2158. * @private
  2159. * @param {*} value The value to query.
  2160. * @param {boolean} inherited Specify returning inherited property names.
  2161. * @returns {Array} Returns the array of property names.
  2162. */
  2163. function arrayLikeKeys(value, inherited) {
  2164. var isArr = isArray(value),
  2165. isArg = !isArr && isArguments(value),
  2166. isBuff = !isArr && !isArg && isBuffer(value),
  2167. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2168. skipIndexes = isArr || isArg || isBuff || isType,
  2169. result = skipIndexes ? baseTimes(value.length, String) : [],
  2170. length = result.length;
  2171. for (var key in value) {
  2172. if ((inherited || hasOwnProperty.call(value, key)) &&
  2173. !(skipIndexes && (
  2174. // Safari 9 has enumerable `arguments.length` in strict mode.
  2175. key == 'length' ||
  2176. // Node.js 0.10 has enumerable non-index properties on buffers.
  2177. (isBuff && (key == 'offset' || key == 'parent')) ||
  2178. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2179. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2180. // Skip index properties.
  2181. isIndex(key, length)
  2182. ))) {
  2183. result.push(key);
  2184. }
  2185. }
  2186. return result;
  2187. }
  2188. /**
  2189. * A specialized version of `_.sample` for arrays.
  2190. *
  2191. * @private
  2192. * @param {Array} array The array to sample.
  2193. * @returns {*} Returns the random element.
  2194. */
  2195. function arraySample(array) {
  2196. var length = array.length;
  2197. return length ? array[baseRandom(0, length - 1)] : undefined;
  2198. }
  2199. /**
  2200. * A specialized version of `_.sampleSize` for arrays.
  2201. *
  2202. * @private
  2203. * @param {Array} array The array to sample.
  2204. * @param {number} n The number of elements to sample.
  2205. * @returns {Array} Returns the random elements.
  2206. */
  2207. function arraySampleSize(array, n) {
  2208. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2209. }
  2210. /**
  2211. * A specialized version of `_.shuffle` for arrays.
  2212. *
  2213. * @private
  2214. * @param {Array} array The array to shuffle.
  2215. * @returns {Array} Returns the new shuffled array.
  2216. */
  2217. function arrayShuffle(array) {
  2218. return shuffleSelf(copyArray(array));
  2219. }
  2220. /**
  2221. * This function is like `assignValue` except that it doesn't assign
  2222. * `undefined` values.
  2223. *
  2224. * @private
  2225. * @param {Object} object The object to modify.
  2226. * @param {string} key The key of the property to assign.
  2227. * @param {*} value The value to assign.
  2228. */
  2229. function assignMergeValue(object, key, value) {
  2230. if ((value !== undefined && !eq(object[key], value)) ||
  2231. (value === undefined && !(key in object))) {
  2232. baseAssignValue(object, key, value);
  2233. }
  2234. }
  2235. /**
  2236. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2237. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2238. * for equality comparisons.
  2239. *
  2240. * @private
  2241. * @param {Object} object The object to modify.
  2242. * @param {string} key The key of the property to assign.
  2243. * @param {*} value The value to assign.
  2244. */
  2245. function assignValue(object, key, value) {
  2246. var objValue = object[key];
  2247. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2248. (value === undefined && !(key in object))) {
  2249. baseAssignValue(object, key, value);
  2250. }
  2251. }
  2252. /**
  2253. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2254. *
  2255. * @private
  2256. * @param {Array} array The array to inspect.
  2257. * @param {*} key The key to search for.
  2258. * @returns {number} Returns the index of the matched value, else `-1`.
  2259. */
  2260. function assocIndexOf(array, key) {
  2261. var length = array.length;
  2262. while (length--) {
  2263. if (eq(array[length][0], key)) {
  2264. return length;
  2265. }
  2266. }
  2267. return -1;
  2268. }
  2269. /**
  2270. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2271. * by `iteratee` and values set by `setter`.
  2272. *
  2273. * @private
  2274. * @param {Array|Object} collection The collection to iterate over.
  2275. * @param {Function} setter The function to set `accumulator` values.
  2276. * @param {Function} iteratee The iteratee to transform keys.
  2277. * @param {Object} accumulator The initial aggregated object.
  2278. * @returns {Function} Returns `accumulator`.
  2279. */
  2280. function baseAggregator(collection, setter, iteratee, accumulator) {
  2281. baseEach(collection, function(value, key, collection) {
  2282. setter(accumulator, value, iteratee(value), collection);
  2283. });
  2284. return accumulator;
  2285. }
  2286. /**
  2287. * The base implementation of `_.assign` without support for multiple sources
  2288. * or `customizer` functions.
  2289. *
  2290. * @private
  2291. * @param {Object} object The destination object.
  2292. * @param {Object} source The source object.
  2293. * @returns {Object} Returns `object`.
  2294. */
  2295. function baseAssign(object, source) {
  2296. return object && copyObject(source, keys(source), object);
  2297. }
  2298. /**
  2299. * The base implementation of `_.assignIn` without support for multiple sources
  2300. * or `customizer` functions.
  2301. *
  2302. * @private
  2303. * @param {Object} object The destination object.
  2304. * @param {Object} source The source object.
  2305. * @returns {Object} Returns `object`.
  2306. */
  2307. function baseAssignIn(object, source) {
  2308. return object && copyObject(source, keysIn(source), object);
  2309. }
  2310. /**
  2311. * The base implementation of `assignValue` and `assignMergeValue` without
  2312. * value checks.
  2313. *
  2314. * @private
  2315. * @param {Object} object The object to modify.
  2316. * @param {string} key The key of the property to assign.
  2317. * @param {*} value The value to assign.
  2318. */
  2319. function baseAssignValue(object, key, value) {
  2320. if (key == '__proto__' && defineProperty) {
  2321. defineProperty(object, key, {
  2322. 'configurable': true,
  2323. 'enumerable': true,
  2324. 'value': value,
  2325. 'writable': true
  2326. });
  2327. } else {
  2328. object[key] = value;
  2329. }
  2330. }
  2331. /**
  2332. * The base implementation of `_.at` without support for individual paths.
  2333. *
  2334. * @private
  2335. * @param {Object} object The object to iterate over.
  2336. * @param {string[]} paths The property paths to pick.
  2337. * @returns {Array} Returns the picked elements.
  2338. */
  2339. function baseAt(object, paths) {
  2340. var index = -1,
  2341. length = paths.length,
  2342. result = Array(length),
  2343. skip = object == null;
  2344. while (++index < length) {
  2345. result[index] = skip ? undefined : get(object, paths[index]);
  2346. }
  2347. return result;
  2348. }
  2349. /**
  2350. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2351. *
  2352. * @private
  2353. * @param {number} number The number to clamp.
  2354. * @param {number} [lower] The lower bound.
  2355. * @param {number} upper The upper bound.
  2356. * @returns {number} Returns the clamped number.
  2357. */
  2358. function baseClamp(number, lower, upper) {
  2359. if (number === number) {
  2360. if (upper !== undefined) {
  2361. number = number <= upper ? number : upper;
  2362. }
  2363. if (lower !== undefined) {
  2364. number = number >= lower ? number : lower;
  2365. }
  2366. }
  2367. return number;
  2368. }
  2369. /**
  2370. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2371. * traversed objects.
  2372. *
  2373. * @private
  2374. * @param {*} value The value to clone.
  2375. * @param {boolean} bitmask The bitmask flags.
  2376. * 1 - Deep clone
  2377. * 2 - Flatten inherited properties
  2378. * 4 - Clone symbols
  2379. * @param {Function} [customizer] The function to customize cloning.
  2380. * @param {string} [key] The key of `value`.
  2381. * @param {Object} [object] The parent object of `value`.
  2382. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2383. * @returns {*} Returns the cloned value.
  2384. */
  2385. function baseClone(value, bitmask, customizer, key, object, stack) {
  2386. var result,
  2387. isDeep = bitmask & CLONE_DEEP_FLAG,
  2388. isFlat = bitmask & CLONE_FLAT_FLAG,
  2389. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2390. if (customizer) {
  2391. result = object ? customizer(value, key, object, stack) : customizer(value);
  2392. }
  2393. if (result !== undefined) {
  2394. return result;
  2395. }
  2396. if (!isObject(value)) {
  2397. return value;
  2398. }
  2399. var isArr = isArray(value);
  2400. if (isArr) {
  2401. result = initCloneArray(value);
  2402. if (!isDeep) {
  2403. return copyArray(value, result);
  2404. }
  2405. } else {
  2406. var tag = getTag(value),
  2407. isFunc = tag == funcTag || tag == genTag;
  2408. if (isBuffer(value)) {
  2409. return cloneBuffer(value, isDeep);
  2410. }
  2411. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2412. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2413. if (!isDeep) {
  2414. return isFlat
  2415. ? copySymbolsIn(value, baseAssignIn(result, value))
  2416. : copySymbols(value, baseAssign(result, value));
  2417. }
  2418. } else {
  2419. if (!cloneableTags[tag]) {
  2420. return object ? value : {};
  2421. }
  2422. result = initCloneByTag(value, tag, baseClone, isDeep);
  2423. }
  2424. }
  2425. // Check for circular references and return its corresponding clone.
  2426. stack || (stack = new Stack);
  2427. var stacked = stack.get(value);
  2428. if (stacked) {
  2429. return stacked;
  2430. }
  2431. stack.set(value, result);
  2432. var keysFunc = isFull
  2433. ? (isFlat ? getAllKeysIn : getAllKeys)
  2434. : (isFlat ? keysIn : keys);
  2435. var props = isArr ? undefined : keysFunc(value);
  2436. arrayEach(props || value, function(subValue, key) {
  2437. if (props) {
  2438. key = subValue;
  2439. subValue = value[key];
  2440. }
  2441. // Recursively populate clone (susceptible to call stack limits).
  2442. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2443. });
  2444. return result;
  2445. }
  2446. /**
  2447. * The base implementation of `_.conforms` which doesn't clone `source`.
  2448. *
  2449. * @private
  2450. * @param {Object} source The object of property predicates to conform to.
  2451. * @returns {Function} Returns the new spec function.
  2452. */
  2453. function baseConforms(source) {
  2454. var props = keys(source);
  2455. return function(object) {
  2456. return baseConformsTo(object, source, props);
  2457. };
  2458. }
  2459. /**
  2460. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2461. *
  2462. * @private
  2463. * @param {Object} object The object to inspect.
  2464. * @param {Object} source The object of property predicates to conform to.
  2465. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2466. */
  2467. function baseConformsTo(object, source, props) {
  2468. var length = props.length;
  2469. if (object == null) {
  2470. return !length;
  2471. }
  2472. object = Object(object);
  2473. while (length--) {
  2474. var key = props[length],
  2475. predicate = source[key],
  2476. value = object[key];
  2477. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2478. return false;
  2479. }
  2480. }
  2481. return true;
  2482. }
  2483. /**
  2484. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2485. * to provide to `func`.
  2486. *
  2487. * @private
  2488. * @param {Function} func The function to delay.
  2489. * @param {number} wait The number of milliseconds to delay invocation.
  2490. * @param {Array} args The arguments to provide to `func`.
  2491. * @returns {number|Object} Returns the timer id or timeout object.
  2492. */
  2493. function baseDelay(func, wait, args) {
  2494. if (typeof func != 'function') {
  2495. throw new TypeError(FUNC_ERROR_TEXT);
  2496. }
  2497. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2498. }
  2499. /**
  2500. * The base implementation of methods like `_.difference` without support
  2501. * for excluding multiple arrays or iteratee shorthands.
  2502. *
  2503. * @private
  2504. * @param {Array} array The array to inspect.
  2505. * @param {Array} values The values to exclude.
  2506. * @param {Function} [iteratee] The iteratee invoked per element.
  2507. * @param {Function} [comparator] The comparator invoked per element.
  2508. * @returns {Array} Returns the new array of filtered values.
  2509. */
  2510. function baseDifference(array, values, iteratee, comparator) {
  2511. var index = -1,
  2512. includes = arrayIncludes,
  2513. isCommon = true,
  2514. length = array.length,
  2515. result = [],
  2516. valuesLength = values.length;
  2517. if (!length) {
  2518. return result;
  2519. }
  2520. if (iteratee) {
  2521. values = arrayMap(values, baseUnary(iteratee));
  2522. }
  2523. if (comparator) {
  2524. includes = arrayIncludesWith;
  2525. isCommon = false;
  2526. }
  2527. else if (values.length >= LARGE_ARRAY_SIZE) {
  2528. includes = cacheHas;
  2529. isCommon = false;
  2530. values = new SetCache(values);
  2531. }
  2532. outer:
  2533. while (++index < length) {
  2534. var value = array[index],
  2535. computed = iteratee == null ? value : iteratee(value);
  2536. value = (comparator || value !== 0) ? value : 0;
  2537. if (isCommon && computed === computed) {
  2538. var valuesIndex = valuesLength;
  2539. while (valuesIndex--) {
  2540. if (values[valuesIndex] === computed) {
  2541. continue outer;
  2542. }
  2543. }
  2544. result.push(value);
  2545. }
  2546. else if (!includes(values, computed, comparator)) {
  2547. result.push(value);
  2548. }
  2549. }
  2550. return result;
  2551. }
  2552. /**
  2553. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2554. *
  2555. * @private
  2556. * @param {Array|Object} collection The collection to iterate over.
  2557. * @param {Function} iteratee The function invoked per iteration.
  2558. * @returns {Array|Object} Returns `collection`.
  2559. */
  2560. var baseEach = createBaseEach(baseForOwn);
  2561. /**
  2562. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2563. *
  2564. * @private
  2565. * @param {Array|Object} collection The collection to iterate over.
  2566. * @param {Function} iteratee The function invoked per iteration.
  2567. * @returns {Array|Object} Returns `collection`.
  2568. */
  2569. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2570. /**
  2571. * The base implementation of `_.every` without support for iteratee shorthands.
  2572. *
  2573. * @private
  2574. * @param {Array|Object} collection The collection to iterate over.
  2575. * @param {Function} predicate The function invoked per iteration.
  2576. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2577. * else `false`
  2578. */
  2579. function baseEvery(collection, predicate) {
  2580. var result = true;
  2581. baseEach(collection, function(value, index, collection) {
  2582. result = !!predicate(value, index, collection);
  2583. return result;
  2584. });
  2585. return result;
  2586. }
  2587. /**
  2588. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2589. * `comparator` to determine the extremum value.
  2590. *
  2591. * @private
  2592. * @param {Array} array The array to iterate over.
  2593. * @param {Function} iteratee The iteratee invoked per iteration.
  2594. * @param {Function} comparator The comparator used to compare values.
  2595. * @returns {*} Returns the extremum value.
  2596. */
  2597. function baseExtremum(array, iteratee, comparator) {
  2598. var index = -1,
  2599. length = array.length;
  2600. while (++index < length) {
  2601. var value = array[index],
  2602. current = iteratee(value);
  2603. if (current != null && (computed === undefined
  2604. ? (current === current && !isSymbol(current))
  2605. : comparator(current, computed)
  2606. )) {
  2607. var computed = current,
  2608. result = value;
  2609. }
  2610. }
  2611. return result;
  2612. }
  2613. /**
  2614. * The base implementation of `_.fill` without an iteratee call guard.
  2615. *
  2616. * @private
  2617. * @param {Array} array The array to fill.
  2618. * @param {*} value The value to fill `array` with.
  2619. * @param {number} [start=0] The start position.
  2620. * @param {number} [end=array.length] The end position.
  2621. * @returns {Array} Returns `array`.
  2622. */
  2623. function baseFill(array, value, start, end) {
  2624. var length = array.length;
  2625. start = toInteger(start);
  2626. if (start < 0) {
  2627. start = -start > length ? 0 : (length + start);
  2628. }
  2629. end = (end === undefined || end > length) ? length : toInteger(end);
  2630. if (end < 0) {
  2631. end += length;
  2632. }
  2633. end = start > end ? 0 : toLength(end);
  2634. while (start < end) {
  2635. array[start++] = value;
  2636. }
  2637. return array;
  2638. }
  2639. /**
  2640. * The base implementation of `_.filter` without support for iteratee shorthands.
  2641. *
  2642. * @private
  2643. * @param {Array|Object} collection The collection to iterate over.
  2644. * @param {Function} predicate The function invoked per iteration.
  2645. * @returns {Array} Returns the new filtered array.
  2646. */
  2647. function baseFilter(collection, predicate) {
  2648. var result = [];
  2649. baseEach(collection, function(value, index, collection) {
  2650. if (predicate(value, index, collection)) {
  2651. result.push(value);
  2652. }
  2653. });
  2654. return result;
  2655. }
  2656. /**
  2657. * The base implementation of `_.flatten` with support for restricting flattening.
  2658. *
  2659. * @private
  2660. * @param {Array} array The array to flatten.
  2661. * @param {number} depth The maximum recursion depth.
  2662. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2663. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2664. * @param {Array} [result=[]] The initial result value.
  2665. * @returns {Array} Returns the new flattened array.
  2666. */
  2667. function baseFlatten(array, depth, predicate, isStrict, result) {
  2668. var index = -1,
  2669. length = array.length;
  2670. predicate || (predicate = isFlattenable);
  2671. result || (result = []);
  2672. while (++index < length) {
  2673. var value = array[index];
  2674. if (depth > 0 && predicate(value)) {
  2675. if (depth > 1) {
  2676. // Recursively flatten arrays (susceptible to call stack limits).
  2677. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2678. } else {
  2679. arrayPush(result, value);
  2680. }
  2681. } else if (!isStrict) {
  2682. result[result.length] = value;
  2683. }
  2684. }
  2685. return result;
  2686. }
  2687. /**
  2688. * The base implementation of `baseForOwn` which iterates over `object`
  2689. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2690. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2691. *
  2692. * @private
  2693. * @param {Object} object The object to iterate over.
  2694. * @param {Function} iteratee The function invoked per iteration.
  2695. * @param {Function} keysFunc The function to get the keys of `object`.
  2696. * @returns {Object} Returns `object`.
  2697. */
  2698. var baseFor = createBaseFor();
  2699. /**
  2700. * This function is like `baseFor` except that it iterates over properties
  2701. * in the opposite order.
  2702. *
  2703. * @private
  2704. * @param {Object} object The object to iterate over.
  2705. * @param {Function} iteratee The function invoked per iteration.
  2706. * @param {Function} keysFunc The function to get the keys of `object`.
  2707. * @returns {Object} Returns `object`.
  2708. */
  2709. var baseForRight = createBaseFor(true);
  2710. /**
  2711. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2712. *
  2713. * @private
  2714. * @param {Object} object The object to iterate over.
  2715. * @param {Function} iteratee The function invoked per iteration.
  2716. * @returns {Object} Returns `object`.
  2717. */
  2718. function baseForOwn(object, iteratee) {
  2719. return object && baseFor(object, iteratee, keys);
  2720. }
  2721. /**
  2722. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2723. *
  2724. * @private
  2725. * @param {Object} object The object to iterate over.
  2726. * @param {Function} iteratee The function invoked per iteration.
  2727. * @returns {Object} Returns `object`.
  2728. */
  2729. function baseForOwnRight(object, iteratee) {
  2730. return object && baseForRight(object, iteratee, keys);
  2731. }
  2732. /**
  2733. * The base implementation of `_.functions` which creates an array of
  2734. * `object` function property names filtered from `props`.
  2735. *
  2736. * @private
  2737. * @param {Object} object The object to inspect.
  2738. * @param {Array} props The property names to filter.
  2739. * @returns {Array} Returns the function names.
  2740. */
  2741. function baseFunctions(object, props) {
  2742. return arrayFilter(props, function(key) {
  2743. return isFunction(object[key]);
  2744. });
  2745. }
  2746. /**
  2747. * The base implementation of `_.get` without support for default values.
  2748. *
  2749. * @private
  2750. * @param {Object} object The object to query.
  2751. * @param {Array|string} path The path of the property to get.
  2752. * @returns {*} Returns the resolved value.
  2753. */
  2754. function baseGet(object, path) {
  2755. path = castPath(path, object);
  2756. var index = 0,
  2757. length = path.length;
  2758. while (object != null && index < length) {
  2759. object = object[toKey(path[index++])];
  2760. }
  2761. return (index && index == length) ? object : undefined;
  2762. }
  2763. /**
  2764. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2765. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2766. * symbols of `object`.
  2767. *
  2768. * @private
  2769. * @param {Object} object The object to query.
  2770. * @param {Function} keysFunc The function to get the keys of `object`.
  2771. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2772. * @returns {Array} Returns the array of property names and symbols.
  2773. */
  2774. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2775. var result = keysFunc(object);
  2776. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2777. }
  2778. /**
  2779. * The base implementation of `getTag` without fallbacks for buggy environments.
  2780. *
  2781. * @private
  2782. * @param {*} value The value to query.
  2783. * @returns {string} Returns the `toStringTag`.
  2784. */
  2785. function baseGetTag(value) {
  2786. if (value == null) {
  2787. return value === undefined ? undefinedTag : nullTag;
  2788. }
  2789. return (symToStringTag && symToStringTag in Object(value))
  2790. ? getRawTag(value)
  2791. : objectToString(value);
  2792. }
  2793. /**
  2794. * The base implementation of `_.gt` which doesn't coerce arguments.
  2795. *
  2796. * @private
  2797. * @param {*} value The value to compare.
  2798. * @param {*} other The other value to compare.
  2799. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2800. * else `false`.
  2801. */
  2802. function baseGt(value, other) {
  2803. return value > other;
  2804. }
  2805. /**
  2806. * The base implementation of `_.has` without support for deep paths.
  2807. *
  2808. * @private
  2809. * @param {Object} [object] The object to query.
  2810. * @param {Array|string} key The key to check.
  2811. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2812. */
  2813. function baseHas(object, key) {
  2814. return object != null && hasOwnProperty.call(object, key);
  2815. }
  2816. /**
  2817. * The base implementation of `_.hasIn` without support for deep paths.
  2818. *
  2819. * @private
  2820. * @param {Object} [object] The object to query.
  2821. * @param {Array|string} key The key to check.
  2822. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2823. */
  2824. function baseHasIn(object, key) {
  2825. return object != null && key in Object(object);
  2826. }
  2827. /**
  2828. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2829. *
  2830. * @private
  2831. * @param {number} number The number to check.
  2832. * @param {number} start The start of the range.
  2833. * @param {number} end The end of the range.
  2834. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2835. */
  2836. function baseInRange(number, start, end) {
  2837. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2838. }
  2839. /**
  2840. * The base implementation of methods like `_.intersection`, without support
  2841. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2842. *
  2843. * @private
  2844. * @param {Array} arrays The arrays to inspect.
  2845. * @param {Function} [iteratee] The iteratee invoked per element.
  2846. * @param {Function} [comparator] The comparator invoked per element.
  2847. * @returns {Array} Returns the new array of shared values.
  2848. */
  2849. function baseIntersection(arrays, iteratee, comparator) {
  2850. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2851. length = arrays[0].length,
  2852. othLength = arrays.length,
  2853. othIndex = othLength,
  2854. caches = Array(othLength),
  2855. maxLength = Infinity,
  2856. result = [];
  2857. while (othIndex--) {
  2858. var array = arrays[othIndex];
  2859. if (othIndex && iteratee) {
  2860. array = arrayMap(array, baseUnary(iteratee));
  2861. }
  2862. maxLength = nativeMin(array.length, maxLength);
  2863. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2864. ? new SetCache(othIndex && array)
  2865. : undefined;
  2866. }
  2867. array = arrays[0];
  2868. var index = -1,
  2869. seen = caches[0];
  2870. outer:
  2871. while (++index < length && result.length < maxLength) {
  2872. var value = array[index],
  2873. computed = iteratee ? iteratee(value) : value;
  2874. value = (comparator || value !== 0) ? value : 0;
  2875. if (!(seen
  2876. ? cacheHas(seen, computed)
  2877. : includes(result, computed, comparator)
  2878. )) {
  2879. othIndex = othLength;
  2880. while (--othIndex) {
  2881. var cache = caches[othIndex];
  2882. if (!(cache
  2883. ? cacheHas(cache, computed)
  2884. : includes(arrays[othIndex], computed, comparator))
  2885. ) {
  2886. continue outer;
  2887. }
  2888. }
  2889. if (seen) {
  2890. seen.push(computed);
  2891. }
  2892. result.push(value);
  2893. }
  2894. }
  2895. return result;
  2896. }
  2897. /**
  2898. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2899. * `object` with values transformed by `iteratee` and set by `setter`.
  2900. *
  2901. * @private
  2902. * @param {Object} object The object to iterate over.
  2903. * @param {Function} setter The function to set `accumulator` values.
  2904. * @param {Function} iteratee The iteratee to transform values.
  2905. * @param {Object} accumulator The initial inverted object.
  2906. * @returns {Function} Returns `accumulator`.
  2907. */
  2908. function baseInverter(object, setter, iteratee, accumulator) {
  2909. baseForOwn(object, function(value, key, object) {
  2910. setter(accumulator, iteratee(value), key, object);
  2911. });
  2912. return accumulator;
  2913. }
  2914. /**
  2915. * The base implementation of `_.invoke` without support for individual
  2916. * method arguments.
  2917. *
  2918. * @private
  2919. * @param {Object} object The object to query.
  2920. * @param {Array|string} path The path of the method to invoke.
  2921. * @param {Array} args The arguments to invoke the method with.
  2922. * @returns {*} Returns the result of the invoked method.
  2923. */
  2924. function baseInvoke(object, path, args) {
  2925. path = castPath(path, object);
  2926. object = parent(object, path);
  2927. var func = object == null ? object : object[toKey(last(path))];
  2928. return func == null ? undefined : apply(func, object, args);
  2929. }
  2930. /**
  2931. * The base implementation of `_.isArguments`.
  2932. *
  2933. * @private
  2934. * @param {*} value The value to check.
  2935. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2936. */
  2937. function baseIsArguments(value) {
  2938. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2939. }
  2940. /**
  2941. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2942. *
  2943. * @private
  2944. * @param {*} value The value to check.
  2945. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2946. */
  2947. function baseIsArrayBuffer(value) {
  2948. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2949. }
  2950. /**
  2951. * The base implementation of `_.isDate` without Node.js optimizations.
  2952. *
  2953. * @private
  2954. * @param {*} value The value to check.
  2955. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2956. */
  2957. function baseIsDate(value) {
  2958. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2959. }
  2960. /**
  2961. * The base implementation of `_.isEqual` which supports partial comparisons
  2962. * and tracks traversed objects.
  2963. *
  2964. * @private
  2965. * @param {*} value The value to compare.
  2966. * @param {*} other The other value to compare.
  2967. * @param {boolean} bitmask The bitmask flags.
  2968. * 1 - Unordered comparison
  2969. * 2 - Partial comparison
  2970. * @param {Function} [customizer] The function to customize comparisons.
  2971. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2972. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2973. */
  2974. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2975. if (value === other) {
  2976. return true;
  2977. }
  2978. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2979. return value !== value && other !== other;
  2980. }
  2981. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2982. }
  2983. /**
  2984. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2985. * deep comparisons and tracks traversed objects enabling objects with circular
  2986. * references to be compared.
  2987. *
  2988. * @private
  2989. * @param {Object} object The object to compare.
  2990. * @param {Object} other The other object to compare.
  2991. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2992. * @param {Function} customizer The function to customize comparisons.
  2993. * @param {Function} equalFunc The function to determine equivalents of values.
  2994. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2995. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2996. */
  2997. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2998. var objIsArr = isArray(object),
  2999. othIsArr = isArray(other),
  3000. objTag = objIsArr ? arrayTag : getTag(object),
  3001. othTag = othIsArr ? arrayTag : getTag(other);
  3002. objTag = objTag == argsTag ? objectTag : objTag;
  3003. othTag = othTag == argsTag ? objectTag : othTag;
  3004. var objIsObj = objTag == objectTag,
  3005. othIsObj = othTag == objectTag,
  3006. isSameTag = objTag == othTag;
  3007. if (isSameTag && isBuffer(object)) {
  3008. if (!isBuffer(other)) {
  3009. return false;
  3010. }
  3011. objIsArr = true;
  3012. objIsObj = false;
  3013. }
  3014. if (isSameTag && !objIsObj) {
  3015. stack || (stack = new Stack);
  3016. return (objIsArr || isTypedArray(object))
  3017. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3018. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3019. }
  3020. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3021. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3022. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3023. if (objIsWrapped || othIsWrapped) {
  3024. var objUnwrapped = objIsWrapped ? object.value() : object,
  3025. othUnwrapped = othIsWrapped ? other.value() : other;
  3026. stack || (stack = new Stack);
  3027. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3028. }
  3029. }
  3030. if (!isSameTag) {
  3031. return false;
  3032. }
  3033. stack || (stack = new Stack);
  3034. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3035. }
  3036. /**
  3037. * The base implementation of `_.isMap` without Node.js optimizations.
  3038. *
  3039. * @private
  3040. * @param {*} value The value to check.
  3041. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3042. */
  3043. function baseIsMap(value) {
  3044. return isObjectLike(value) && getTag(value) == mapTag;
  3045. }
  3046. /**
  3047. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3048. *
  3049. * @private
  3050. * @param {Object} object The object to inspect.
  3051. * @param {Object} source The object of property values to match.
  3052. * @param {Array} matchData The property names, values, and compare flags to match.
  3053. * @param {Function} [customizer] The function to customize comparisons.
  3054. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3055. */
  3056. function baseIsMatch(object, source, matchData, customizer) {
  3057. var index = matchData.length,
  3058. length = index,
  3059. noCustomizer = !customizer;
  3060. if (object == null) {
  3061. return !length;
  3062. }
  3063. object = Object(object);
  3064. while (index--) {
  3065. var data = matchData[index];
  3066. if ((noCustomizer && data[2])
  3067. ? data[1] !== object[data[0]]
  3068. : !(data[0] in object)
  3069. ) {
  3070. return false;
  3071. }
  3072. }
  3073. while (++index < length) {
  3074. data = matchData[index];
  3075. var key = data[0],
  3076. objValue = object[key],
  3077. srcValue = data[1];
  3078. if (noCustomizer && data[2]) {
  3079. if (objValue === undefined && !(key in object)) {
  3080. return false;
  3081. }
  3082. } else {
  3083. var stack = new Stack;
  3084. if (customizer) {
  3085. var result = customizer(objValue, srcValue, key, object, source, stack);
  3086. }
  3087. if (!(result === undefined
  3088. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3089. : result
  3090. )) {
  3091. return false;
  3092. }
  3093. }
  3094. }
  3095. return true;
  3096. }
  3097. /**
  3098. * The base implementation of `_.isNative` without bad shim checks.
  3099. *
  3100. * @private
  3101. * @param {*} value The value to check.
  3102. * @returns {boolean} Returns `true` if `value` is a native function,
  3103. * else `false`.
  3104. */
  3105. function baseIsNative(value) {
  3106. if (!isObject(value) || isMasked(value)) {
  3107. return false;
  3108. }
  3109. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3110. return pattern.test(toSource(value));
  3111. }
  3112. /**
  3113. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3114. *
  3115. * @private
  3116. * @param {*} value The value to check.
  3117. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3118. */
  3119. function baseIsRegExp(value) {
  3120. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3121. }
  3122. /**
  3123. * The base implementation of `_.isSet` without Node.js optimizations.
  3124. *
  3125. * @private
  3126. * @param {*} value The value to check.
  3127. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3128. */
  3129. function baseIsSet(value) {
  3130. return isObjectLike(value) && getTag(value) == setTag;
  3131. }
  3132. /**
  3133. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3134. *
  3135. * @private
  3136. * @param {*} value The value to check.
  3137. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3138. */
  3139. function baseIsTypedArray(value) {
  3140. return isObjectLike(value) &&
  3141. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3142. }
  3143. /**
  3144. * The base implementation of `_.iteratee`.
  3145. *
  3146. * @private
  3147. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3148. * @returns {Function} Returns the iteratee.
  3149. */
  3150. function baseIteratee(value) {
  3151. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3152. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3153. if (typeof value == 'function') {
  3154. return value;
  3155. }
  3156. if (value == null) {
  3157. return identity;
  3158. }
  3159. if (typeof value == 'object') {
  3160. return isArray(value)
  3161. ? baseMatchesProperty(value[0], value[1])
  3162. : baseMatches(value);
  3163. }
  3164. return property(value);
  3165. }
  3166. /**
  3167. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3168. *
  3169. * @private
  3170. * @param {Object} object The object to query.
  3171. * @returns {Array} Returns the array of property names.
  3172. */
  3173. function baseKeys(object) {
  3174. if (!isPrototype(object)) {
  3175. return nativeKeys(object);
  3176. }
  3177. var result = [];
  3178. for (var key in Object(object)) {
  3179. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3180. result.push(key);
  3181. }
  3182. }
  3183. return result;
  3184. }
  3185. /**
  3186. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3187. *
  3188. * @private
  3189. * @param {Object} object The object to query.
  3190. * @returns {Array} Returns the array of property names.
  3191. */
  3192. function baseKeysIn(object) {
  3193. if (!isObject(object)) {
  3194. return nativeKeysIn(object);
  3195. }
  3196. var isProto = isPrototype(object),
  3197. result = [];
  3198. for (var key in object) {
  3199. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3200. result.push(key);
  3201. }
  3202. }
  3203. return result;
  3204. }
  3205. /**
  3206. * The base implementation of `_.lt` which doesn't coerce arguments.
  3207. *
  3208. * @private
  3209. * @param {*} value The value to compare.
  3210. * @param {*} other The other value to compare.
  3211. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3212. * else `false`.
  3213. */
  3214. function baseLt(value, other) {
  3215. return value < other;
  3216. }
  3217. /**
  3218. * The base implementation of `_.map` without support for iteratee shorthands.
  3219. *
  3220. * @private
  3221. * @param {Array|Object} collection The collection to iterate over.
  3222. * @param {Function} iteratee The function invoked per iteration.
  3223. * @returns {Array} Returns the new mapped array.
  3224. */
  3225. function baseMap(collection, iteratee) {
  3226. var index = -1,
  3227. result = isArrayLike(collection) ? Array(collection.length) : [];
  3228. baseEach(collection, function(value, key, collection) {
  3229. result[++index] = iteratee(value, key, collection);
  3230. });
  3231. return result;
  3232. }
  3233. /**
  3234. * The base implementation of `_.matches` which doesn't clone `source`.
  3235. *
  3236. * @private
  3237. * @param {Object} source The object of property values to match.
  3238. * @returns {Function} Returns the new spec function.
  3239. */
  3240. function baseMatches(source) {
  3241. var matchData = getMatchData(source);
  3242. if (matchData.length == 1 && matchData[0][2]) {
  3243. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3244. }
  3245. return function(object) {
  3246. return object === source || baseIsMatch(object, source, matchData);
  3247. };
  3248. }
  3249. /**
  3250. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3251. *
  3252. * @private
  3253. * @param {string} path The path of the property to get.
  3254. * @param {*} srcValue The value to match.
  3255. * @returns {Function} Returns the new spec function.
  3256. */
  3257. function baseMatchesProperty(path, srcValue) {
  3258. if (isKey(path) && isStrictComparable(srcValue)) {
  3259. return matchesStrictComparable(toKey(path), srcValue);
  3260. }
  3261. return function(object) {
  3262. var objValue = get(object, path);
  3263. return (objValue === undefined && objValue === srcValue)
  3264. ? hasIn(object, path)
  3265. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3266. };
  3267. }
  3268. /**
  3269. * The base implementation of `_.merge` without support for multiple sources.
  3270. *
  3271. * @private
  3272. * @param {Object} object The destination object.
  3273. * @param {Object} source The source object.
  3274. * @param {number} srcIndex The index of `source`.
  3275. * @param {Function} [customizer] The function to customize merged values.
  3276. * @param {Object} [stack] Tracks traversed source values and their merged
  3277. * counterparts.
  3278. */
  3279. function baseMerge(object, source, srcIndex, customizer, stack) {
  3280. if (object === source) {
  3281. return;
  3282. }
  3283. baseFor(source, function(srcValue, key) {
  3284. if (isObject(srcValue)) {
  3285. stack || (stack = new Stack);
  3286. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3287. }
  3288. else {
  3289. var newValue = customizer
  3290. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  3291. : undefined;
  3292. if (newValue === undefined) {
  3293. newValue = srcValue;
  3294. }
  3295. assignMergeValue(object, key, newValue);
  3296. }
  3297. }, keysIn);
  3298. }
  3299. /**
  3300. * A specialized version of `baseMerge` for arrays and objects which performs
  3301. * deep merges and tracks traversed objects enabling objects with circular
  3302. * references to be merged.
  3303. *
  3304. * @private
  3305. * @param {Object} object The destination object.
  3306. * @param {Object} source The source object.
  3307. * @param {string} key The key of the value to merge.
  3308. * @param {number} srcIndex The index of `source`.
  3309. * @param {Function} mergeFunc The function to merge values.
  3310. * @param {Function} [customizer] The function to customize assigned values.
  3311. * @param {Object} [stack] Tracks traversed source values and their merged
  3312. * counterparts.
  3313. */
  3314. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3315. var objValue = object[key],
  3316. srcValue = source[key],
  3317. stacked = stack.get(srcValue);
  3318. if (stacked) {
  3319. assignMergeValue(object, key, stacked);
  3320. return;
  3321. }
  3322. var newValue = customizer
  3323. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3324. : undefined;
  3325. var isCommon = newValue === undefined;
  3326. if (isCommon) {
  3327. var isArr = isArray(srcValue),
  3328. isBuff = !isArr && isBuffer(srcValue),
  3329. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3330. newValue = srcValue;
  3331. if (isArr || isBuff || isTyped) {
  3332. if (isArray(objValue)) {
  3333. newValue = objValue;
  3334. }
  3335. else if (isArrayLikeObject(objValue)) {
  3336. newValue = copyArray(objValue);
  3337. }
  3338. else if (isBuff) {
  3339. isCommon = false;
  3340. newValue = cloneBuffer(srcValue, true);
  3341. }
  3342. else if (isTyped) {
  3343. isCommon = false;
  3344. newValue = cloneTypedArray(srcValue, true);
  3345. }
  3346. else {
  3347. newValue = [];
  3348. }
  3349. }
  3350. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3351. newValue = objValue;
  3352. if (isArguments(objValue)) {
  3353. newValue = toPlainObject(objValue);
  3354. }
  3355. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3356. newValue = initCloneObject(srcValue);
  3357. }
  3358. }
  3359. else {
  3360. isCommon = false;
  3361. }
  3362. }
  3363. if (isCommon) {
  3364. // Recursively merge objects and arrays (susceptible to call stack limits).
  3365. stack.set(srcValue, newValue);
  3366. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3367. stack['delete'](srcValue);
  3368. }
  3369. assignMergeValue(object, key, newValue);
  3370. }
  3371. /**
  3372. * The base implementation of `_.nth` which doesn't coerce arguments.
  3373. *
  3374. * @private
  3375. * @param {Array} array The array to query.
  3376. * @param {number} n The index of the element to return.
  3377. * @returns {*} Returns the nth element of `array`.
  3378. */
  3379. function baseNth(array, n) {
  3380. var length = array.length;
  3381. if (!length) {
  3382. return;
  3383. }
  3384. n += n < 0 ? length : 0;
  3385. return isIndex(n, length) ? array[n] : undefined;
  3386. }
  3387. /**
  3388. * The base implementation of `_.orderBy` without param guards.
  3389. *
  3390. * @private
  3391. * @param {Array|Object} collection The collection to iterate over.
  3392. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3393. * @param {string[]} orders The sort orders of `iteratees`.
  3394. * @returns {Array} Returns the new sorted array.
  3395. */
  3396. function baseOrderBy(collection, iteratees, orders) {
  3397. var index = -1;
  3398. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3399. var result = baseMap(collection, function(value, key, collection) {
  3400. var criteria = arrayMap(iteratees, function(iteratee) {
  3401. return iteratee(value);
  3402. });
  3403. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3404. });
  3405. return baseSortBy(result, function(object, other) {
  3406. return compareMultiple(object, other, orders);
  3407. });
  3408. }
  3409. /**
  3410. * The base implementation of `_.pick` without support for individual
  3411. * property identifiers.
  3412. *
  3413. * @private
  3414. * @param {Object} object The source object.
  3415. * @param {string[]} paths The property paths to pick.
  3416. * @returns {Object} Returns the new object.
  3417. */
  3418. function basePick(object, paths) {
  3419. return basePickBy(object, paths, function(value, path) {
  3420. return hasIn(object, path);
  3421. });
  3422. }
  3423. /**
  3424. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3425. *
  3426. * @private
  3427. * @param {Object} object The source object.
  3428. * @param {string[]} paths The property paths to pick.
  3429. * @param {Function} predicate The function invoked per property.
  3430. * @returns {Object} Returns the new object.
  3431. */
  3432. function basePickBy(object, paths, predicate) {
  3433. var index = -1,
  3434. length = paths.length,
  3435. result = {};
  3436. while (++index < length) {
  3437. var path = paths[index],
  3438. value = baseGet(object, path);
  3439. if (predicate(value, path)) {
  3440. baseSet(result, castPath(path, object), value);
  3441. }
  3442. }
  3443. return result;
  3444. }
  3445. /**
  3446. * A specialized version of `baseProperty` which supports deep paths.
  3447. *
  3448. * @private
  3449. * @param {Array|string} path The path of the property to get.
  3450. * @returns {Function} Returns the new accessor function.
  3451. */
  3452. function basePropertyDeep(path) {
  3453. return function(object) {
  3454. return baseGet(object, path);
  3455. };
  3456. }
  3457. /**
  3458. * The base implementation of `_.pullAllBy` without support for iteratee
  3459. * shorthands.
  3460. *
  3461. * @private
  3462. * @param {Array} array The array to modify.
  3463. * @param {Array} values The values to remove.
  3464. * @param {Function} [iteratee] The iteratee invoked per element.
  3465. * @param {Function} [comparator] The comparator invoked per element.
  3466. * @returns {Array} Returns `array`.
  3467. */
  3468. function basePullAll(array, values, iteratee, comparator) {
  3469. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3470. index = -1,
  3471. length = values.length,
  3472. seen = array;
  3473. if (array === values) {
  3474. values = copyArray(values);
  3475. }
  3476. if (iteratee) {
  3477. seen = arrayMap(array, baseUnary(iteratee));
  3478. }
  3479. while (++index < length) {
  3480. var fromIndex = 0,
  3481. value = values[index],
  3482. computed = iteratee ? iteratee(value) : value;
  3483. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3484. if (seen !== array) {
  3485. splice.call(seen, fromIndex, 1);
  3486. }
  3487. splice.call(array, fromIndex, 1);
  3488. }
  3489. }
  3490. return array;
  3491. }
  3492. /**
  3493. * The base implementation of `_.pullAt` without support for individual
  3494. * indexes or capturing the removed elements.
  3495. *
  3496. * @private
  3497. * @param {Array} array The array to modify.
  3498. * @param {number[]} indexes The indexes of elements to remove.
  3499. * @returns {Array} Returns `array`.
  3500. */
  3501. function basePullAt(array, indexes) {
  3502. var length = array ? indexes.length : 0,
  3503. lastIndex = length - 1;
  3504. while (length--) {
  3505. var index = indexes[length];
  3506. if (length == lastIndex || index !== previous) {
  3507. var previous = index;
  3508. if (isIndex(index)) {
  3509. splice.call(array, index, 1);
  3510. } else {
  3511. baseUnset(array, index);
  3512. }
  3513. }
  3514. }
  3515. return array;
  3516. }
  3517. /**
  3518. * The base implementation of `_.random` without support for returning
  3519. * floating-point numbers.
  3520. *
  3521. * @private
  3522. * @param {number} lower The lower bound.
  3523. * @param {number} upper The upper bound.
  3524. * @returns {number} Returns the random number.
  3525. */
  3526. function baseRandom(lower, upper) {
  3527. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3528. }
  3529. /**
  3530. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3531. * coerce arguments.
  3532. *
  3533. * @private
  3534. * @param {number} start The start of the range.
  3535. * @param {number} end The end of the range.
  3536. * @param {number} step The value to increment or decrement by.
  3537. * @param {boolean} [fromRight] Specify iterating from right to left.
  3538. * @returns {Array} Returns the range of numbers.
  3539. */
  3540. function baseRange(start, end, step, fromRight) {
  3541. var index = -1,
  3542. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3543. result = Array(length);
  3544. while (length--) {
  3545. result[fromRight ? length : ++index] = start;
  3546. start += step;
  3547. }
  3548. return result;
  3549. }
  3550. /**
  3551. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3552. *
  3553. * @private
  3554. * @param {string} string The string to repeat.
  3555. * @param {number} n The number of times to repeat the string.
  3556. * @returns {string} Returns the repeated string.
  3557. */
  3558. function baseRepeat(string, n) {
  3559. var result = '';
  3560. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3561. return result;
  3562. }
  3563. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3564. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3565. do {
  3566. if (n % 2) {
  3567. result += string;
  3568. }
  3569. n = nativeFloor(n / 2);
  3570. if (n) {
  3571. string += string;
  3572. }
  3573. } while (n);
  3574. return result;
  3575. }
  3576. /**
  3577. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3578. *
  3579. * @private
  3580. * @param {Function} func The function to apply a rest parameter to.
  3581. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3582. * @returns {Function} Returns the new function.
  3583. */
  3584. function baseRest(func, start) {
  3585. return setToString(overRest(func, start, identity), func + '');
  3586. }
  3587. /**
  3588. * The base implementation of `_.sample`.
  3589. *
  3590. * @private
  3591. * @param {Array|Object} collection The collection to sample.
  3592. * @returns {*} Returns the random element.
  3593. */
  3594. function baseSample(collection) {
  3595. return arraySample(values(collection));
  3596. }
  3597. /**
  3598. * The base implementation of `_.sampleSize` without param guards.
  3599. *
  3600. * @private
  3601. * @param {Array|Object} collection The collection to sample.
  3602. * @param {number} n The number of elements to sample.
  3603. * @returns {Array} Returns the random elements.
  3604. */
  3605. function baseSampleSize(collection, n) {
  3606. var array = values(collection);
  3607. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3608. }
  3609. /**
  3610. * The base implementation of `_.set`.
  3611. *
  3612. * @private
  3613. * @param {Object} object The object to modify.
  3614. * @param {Array|string} path The path of the property to set.
  3615. * @param {*} value The value to set.
  3616. * @param {Function} [customizer] The function to customize path creation.
  3617. * @returns {Object} Returns `object`.
  3618. */
  3619. function baseSet(object, path, value, customizer) {
  3620. if (!isObject(object)) {
  3621. return object;
  3622. }
  3623. path = castPath(path, object);
  3624. var index = -1,
  3625. length = path.length,
  3626. lastIndex = length - 1,
  3627. nested = object;
  3628. while (nested != null && ++index < length) {
  3629. var key = toKey(path[index]),
  3630. newValue = value;
  3631. if (index != lastIndex) {
  3632. var objValue = nested[key];
  3633. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3634. if (newValue === undefined) {
  3635. newValue = isObject(objValue)
  3636. ? objValue
  3637. : (isIndex(path[index + 1]) ? [] : {});
  3638. }
  3639. }
  3640. assignValue(nested, key, newValue);
  3641. nested = nested[key];
  3642. }
  3643. return object;
  3644. }
  3645. /**
  3646. * The base implementation of `setData` without support for hot loop shorting.
  3647. *
  3648. * @private
  3649. * @param {Function} func The function to associate metadata with.
  3650. * @param {*} data The metadata.
  3651. * @returns {Function} Returns `func`.
  3652. */
  3653. var baseSetData = !metaMap ? identity : function(func, data) {
  3654. metaMap.set(func, data);
  3655. return func;
  3656. };
  3657. /**
  3658. * The base implementation of `setToString` without support for hot loop shorting.
  3659. *
  3660. * @private
  3661. * @param {Function} func The function to modify.
  3662. * @param {Function} string The `toString` result.
  3663. * @returns {Function} Returns `func`.
  3664. */
  3665. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3666. return defineProperty(func, 'toString', {
  3667. 'configurable': true,
  3668. 'enumerable': false,
  3669. 'value': constant(string),
  3670. 'writable': true
  3671. });
  3672. };
  3673. /**
  3674. * The base implementation of `_.shuffle`.
  3675. *
  3676. * @private
  3677. * @param {Array|Object} collection The collection to shuffle.
  3678. * @returns {Array} Returns the new shuffled array.
  3679. */
  3680. function baseShuffle(collection) {
  3681. return shuffleSelf(values(collection));
  3682. }
  3683. /**
  3684. * The base implementation of `_.slice` without an iteratee call guard.
  3685. *
  3686. * @private
  3687. * @param {Array} array The array to slice.
  3688. * @param {number} [start=0] The start position.
  3689. * @param {number} [end=array.length] The end position.
  3690. * @returns {Array} Returns the slice of `array`.
  3691. */
  3692. function baseSlice(array, start, end) {
  3693. var index = -1,
  3694. length = array.length;
  3695. if (start < 0) {
  3696. start = -start > length ? 0 : (length + start);
  3697. }
  3698. end = end > length ? length : end;
  3699. if (end < 0) {
  3700. end += length;
  3701. }
  3702. length = start > end ? 0 : ((end - start) >>> 0);
  3703. start >>>= 0;
  3704. var result = Array(length);
  3705. while (++index < length) {
  3706. result[index] = array[index + start];
  3707. }
  3708. return result;
  3709. }
  3710. /**
  3711. * The base implementation of `_.some` without support for iteratee shorthands.
  3712. *
  3713. * @private
  3714. * @param {Array|Object} collection The collection to iterate over.
  3715. * @param {Function} predicate The function invoked per iteration.
  3716. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3717. * else `false`.
  3718. */
  3719. function baseSome(collection, predicate) {
  3720. var result;
  3721. baseEach(collection, function(value, index, collection) {
  3722. result = predicate(value, index, collection);
  3723. return !result;
  3724. });
  3725. return !!result;
  3726. }
  3727. /**
  3728. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3729. * performs a binary search of `array` to determine the index at which `value`
  3730. * should be inserted into `array` in order to maintain its sort order.
  3731. *
  3732. * @private
  3733. * @param {Array} array The sorted array to inspect.
  3734. * @param {*} value The value to evaluate.
  3735. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3736. * @returns {number} Returns the index at which `value` should be inserted
  3737. * into `array`.
  3738. */
  3739. function baseSortedIndex(array, value, retHighest) {
  3740. var low = 0,
  3741. high = array == null ? low : array.length;
  3742. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3743. while (low < high) {
  3744. var mid = (low + high) >>> 1,
  3745. computed = array[mid];
  3746. if (computed !== null && !isSymbol(computed) &&
  3747. (retHighest ? (computed <= value) : (computed < value))) {
  3748. low = mid + 1;
  3749. } else {
  3750. high = mid;
  3751. }
  3752. }
  3753. return high;
  3754. }
  3755. return baseSortedIndexBy(array, value, identity, retHighest);
  3756. }
  3757. /**
  3758. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3759. * which invokes `iteratee` for `value` and each element of `array` to compute
  3760. * their sort ranking. The iteratee is invoked with one argument; (value).
  3761. *
  3762. * @private
  3763. * @param {Array} array The sorted array to inspect.
  3764. * @param {*} value The value to evaluate.
  3765. * @param {Function} iteratee The iteratee invoked per element.
  3766. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3767. * @returns {number} Returns the index at which `value` should be inserted
  3768. * into `array`.
  3769. */
  3770. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3771. value = iteratee(value);
  3772. var low = 0,
  3773. high = array == null ? 0 : array.length,
  3774. valIsNaN = value !== value,
  3775. valIsNull = value === null,
  3776. valIsSymbol = isSymbol(value),
  3777. valIsUndefined = value === undefined;
  3778. while (low < high) {
  3779. var mid = nativeFloor((low + high) / 2),
  3780. computed = iteratee(array[mid]),
  3781. othIsDefined = computed !== undefined,
  3782. othIsNull = computed === null,
  3783. othIsReflexive = computed === computed,
  3784. othIsSymbol = isSymbol(computed);
  3785. if (valIsNaN) {
  3786. var setLow = retHighest || othIsReflexive;
  3787. } else if (valIsUndefined) {
  3788. setLow = othIsReflexive && (retHighest || othIsDefined);
  3789. } else if (valIsNull) {
  3790. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3791. } else if (valIsSymbol) {
  3792. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3793. } else if (othIsNull || othIsSymbol) {
  3794. setLow = false;
  3795. } else {
  3796. setLow = retHighest ? (computed <= value) : (computed < value);
  3797. }
  3798. if (setLow) {
  3799. low = mid + 1;
  3800. } else {
  3801. high = mid;
  3802. }
  3803. }
  3804. return nativeMin(high, MAX_ARRAY_INDEX);
  3805. }
  3806. /**
  3807. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3808. * support for iteratee shorthands.
  3809. *
  3810. * @private
  3811. * @param {Array} array The array to inspect.
  3812. * @param {Function} [iteratee] The iteratee invoked per element.
  3813. * @returns {Array} Returns the new duplicate free array.
  3814. */
  3815. function baseSortedUniq(array, iteratee) {
  3816. var index = -1,
  3817. length = array.length,
  3818. resIndex = 0,
  3819. result = [];
  3820. while (++index < length) {
  3821. var value = array[index],
  3822. computed = iteratee ? iteratee(value) : value;
  3823. if (!index || !eq(computed, seen)) {
  3824. var seen = computed;
  3825. result[resIndex++] = value === 0 ? 0 : value;
  3826. }
  3827. }
  3828. return result;
  3829. }
  3830. /**
  3831. * The base implementation of `_.toNumber` which doesn't ensure correct
  3832. * conversions of binary, hexadecimal, or octal string values.
  3833. *
  3834. * @private
  3835. * @param {*} value The value to process.
  3836. * @returns {number} Returns the number.
  3837. */
  3838. function baseToNumber(value) {
  3839. if (typeof value == 'number') {
  3840. return value;
  3841. }
  3842. if (isSymbol(value)) {
  3843. return NAN;
  3844. }
  3845. return +value;
  3846. }
  3847. /**
  3848. * The base implementation of `_.toString` which doesn't convert nullish
  3849. * values to empty strings.
  3850. *
  3851. * @private
  3852. * @param {*} value The value to process.
  3853. * @returns {string} Returns the string.
  3854. */
  3855. function baseToString(value) {
  3856. // Exit early for strings to avoid a performance hit in some environments.
  3857. if (typeof value == 'string') {
  3858. return value;
  3859. }
  3860. if (isArray(value)) {
  3861. // Recursively convert values (susceptible to call stack limits).
  3862. return arrayMap(value, baseToString) + '';
  3863. }
  3864. if (isSymbol(value)) {
  3865. return symbolToString ? symbolToString.call(value) : '';
  3866. }
  3867. var result = (value + '');
  3868. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3869. }
  3870. /**
  3871. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3872. *
  3873. * @private
  3874. * @param {Array} array The array to inspect.
  3875. * @param {Function} [iteratee] The iteratee invoked per element.
  3876. * @param {Function} [comparator] The comparator invoked per element.
  3877. * @returns {Array} Returns the new duplicate free array.
  3878. */
  3879. function baseUniq(array, iteratee, comparator) {
  3880. var index = -1,
  3881. includes = arrayIncludes,
  3882. length = array.length,
  3883. isCommon = true,
  3884. result = [],
  3885. seen = result;
  3886. if (comparator) {
  3887. isCommon = false;
  3888. includes = arrayIncludesWith;
  3889. }
  3890. else if (length >= LARGE_ARRAY_SIZE) {
  3891. var set = iteratee ? null : createSet(array);
  3892. if (set) {
  3893. return setToArray(set);
  3894. }
  3895. isCommon = false;
  3896. includes = cacheHas;
  3897. seen = new SetCache;
  3898. }
  3899. else {
  3900. seen = iteratee ? [] : result;
  3901. }
  3902. outer:
  3903. while (++index < length) {
  3904. var value = array[index],
  3905. computed = iteratee ? iteratee(value) : value;
  3906. value = (comparator || value !== 0) ? value : 0;
  3907. if (isCommon && computed === computed) {
  3908. var seenIndex = seen.length;
  3909. while (seenIndex--) {
  3910. if (seen[seenIndex] === computed) {
  3911. continue outer;
  3912. }
  3913. }
  3914. if (iteratee) {
  3915. seen.push(computed);
  3916. }
  3917. result.push(value);
  3918. }
  3919. else if (!includes(seen, computed, comparator)) {
  3920. if (seen !== result) {
  3921. seen.push(computed);
  3922. }
  3923. result.push(value);
  3924. }
  3925. }
  3926. return result;
  3927. }
  3928. /**
  3929. * The base implementation of `_.unset`.
  3930. *
  3931. * @private
  3932. * @param {Object} object The object to modify.
  3933. * @param {Array|string} path The property path to unset.
  3934. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3935. */
  3936. function baseUnset(object, path) {
  3937. path = castPath(path, object);
  3938. object = parent(object, path);
  3939. return object == null || delete object[toKey(last(path))];
  3940. }
  3941. /**
  3942. * The base implementation of `_.update`.
  3943. *
  3944. * @private
  3945. * @param {Object} object The object to modify.
  3946. * @param {Array|string} path The path of the property to update.
  3947. * @param {Function} updater The function to produce the updated value.
  3948. * @param {Function} [customizer] The function to customize path creation.
  3949. * @returns {Object} Returns `object`.
  3950. */
  3951. function baseUpdate(object, path, updater, customizer) {
  3952. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3953. }
  3954. /**
  3955. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3956. * without support for iteratee shorthands.
  3957. *
  3958. * @private
  3959. * @param {Array} array The array to query.
  3960. * @param {Function} predicate The function invoked per iteration.
  3961. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3962. * @param {boolean} [fromRight] Specify iterating from right to left.
  3963. * @returns {Array} Returns the slice of `array`.
  3964. */
  3965. function baseWhile(array, predicate, isDrop, fromRight) {
  3966. var length = array.length,
  3967. index = fromRight ? length : -1;
  3968. while ((fromRight ? index-- : ++index < length) &&
  3969. predicate(array[index], index, array)) {}
  3970. return isDrop
  3971. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3972. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3973. }
  3974. /**
  3975. * The base implementation of `wrapperValue` which returns the result of
  3976. * performing a sequence of actions on the unwrapped `value`, where each
  3977. * successive action is supplied the return value of the previous.
  3978. *
  3979. * @private
  3980. * @param {*} value The unwrapped value.
  3981. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3982. * @returns {*} Returns the resolved value.
  3983. */
  3984. function baseWrapperValue(value, actions) {
  3985. var result = value;
  3986. if (result instanceof LazyWrapper) {
  3987. result = result.value();
  3988. }
  3989. return arrayReduce(actions, function(result, action) {
  3990. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3991. }, result);
  3992. }
  3993. /**
  3994. * The base implementation of methods like `_.xor`, without support for
  3995. * iteratee shorthands, that accepts an array of arrays to inspect.
  3996. *
  3997. * @private
  3998. * @param {Array} arrays The arrays to inspect.
  3999. * @param {Function} [iteratee] The iteratee invoked per element.
  4000. * @param {Function} [comparator] The comparator invoked per element.
  4001. * @returns {Array} Returns the new array of values.
  4002. */
  4003. function baseXor(arrays, iteratee, comparator) {
  4004. var length = arrays.length;
  4005. if (length < 2) {
  4006. return length ? baseUniq(arrays[0]) : [];
  4007. }
  4008. var index = -1,
  4009. result = Array(length);
  4010. while (++index < length) {
  4011. var array = arrays[index],
  4012. othIndex = -1;
  4013. while (++othIndex < length) {
  4014. if (othIndex != index) {
  4015. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4016. }
  4017. }
  4018. }
  4019. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4020. }
  4021. /**
  4022. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4023. *
  4024. * @private
  4025. * @param {Array} props The property identifiers.
  4026. * @param {Array} values The property values.
  4027. * @param {Function} assignFunc The function to assign values.
  4028. * @returns {Object} Returns the new object.
  4029. */
  4030. function baseZipObject(props, values, assignFunc) {
  4031. var index = -1,
  4032. length = props.length,
  4033. valsLength = values.length,
  4034. result = {};
  4035. while (++index < length) {
  4036. var value = index < valsLength ? values[index] : undefined;
  4037. assignFunc(result, props[index], value);
  4038. }
  4039. return result;
  4040. }
  4041. /**
  4042. * Casts `value` to an empty array if it's not an array like object.
  4043. *
  4044. * @private
  4045. * @param {*} value The value to inspect.
  4046. * @returns {Array|Object} Returns the cast array-like object.
  4047. */
  4048. function castArrayLikeObject(value) {
  4049. return isArrayLikeObject(value) ? value : [];
  4050. }
  4051. /**
  4052. * Casts `value` to `identity` if it's not a function.
  4053. *
  4054. * @private
  4055. * @param {*} value The value to inspect.
  4056. * @returns {Function} Returns cast function.
  4057. */
  4058. function castFunction(value) {
  4059. return typeof value == 'function' ? value : identity;
  4060. }
  4061. /**
  4062. * Casts `value` to a path array if it's not one.
  4063. *
  4064. * @private
  4065. * @param {*} value The value to inspect.
  4066. * @param {Object} [object] The object to query keys on.
  4067. * @returns {Array} Returns the cast property path array.
  4068. */
  4069. function castPath(value, object) {
  4070. if (isArray(value)) {
  4071. return value;
  4072. }
  4073. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4074. }
  4075. /**
  4076. * A `baseRest` alias which can be replaced with `identity` by module
  4077. * replacement plugins.
  4078. *
  4079. * @private
  4080. * @type {Function}
  4081. * @param {Function} func The function to apply a rest parameter to.
  4082. * @returns {Function} Returns the new function.
  4083. */
  4084. var castRest = baseRest;
  4085. /**
  4086. * Casts `array` to a slice if it's needed.
  4087. *
  4088. * @private
  4089. * @param {Array} array The array to inspect.
  4090. * @param {number} start The start position.
  4091. * @param {number} [end=array.length] The end position.
  4092. * @returns {Array} Returns the cast slice.
  4093. */
  4094. function castSlice(array, start, end) {
  4095. var length = array.length;
  4096. end = end === undefined ? length : end;
  4097. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4098. }
  4099. /**
  4100. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4101. *
  4102. * @private
  4103. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4104. */
  4105. var clearTimeout = ctxClearTimeout || function(id) {
  4106. return root.clearTimeout(id);
  4107. };
  4108. /**
  4109. * Creates a clone of `buffer`.
  4110. *
  4111. * @private
  4112. * @param {Buffer} buffer The buffer to clone.
  4113. * @param {boolean} [isDeep] Specify a deep clone.
  4114. * @returns {Buffer} Returns the cloned buffer.
  4115. */
  4116. function cloneBuffer(buffer, isDeep) {
  4117. if (isDeep) {
  4118. return buffer.slice();
  4119. }
  4120. var length = buffer.length,
  4121. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4122. buffer.copy(result);
  4123. return result;
  4124. }
  4125. /**
  4126. * Creates a clone of `arrayBuffer`.
  4127. *
  4128. * @private
  4129. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4130. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4131. */
  4132. function cloneArrayBuffer(arrayBuffer) {
  4133. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4134. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4135. return result;
  4136. }
  4137. /**
  4138. * Creates a clone of `dataView`.
  4139. *
  4140. * @private
  4141. * @param {Object} dataView The data view to clone.
  4142. * @param {boolean} [isDeep] Specify a deep clone.
  4143. * @returns {Object} Returns the cloned data view.
  4144. */
  4145. function cloneDataView(dataView, isDeep) {
  4146. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4147. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4148. }
  4149. /**
  4150. * Creates a clone of `map`.
  4151. *
  4152. * @private
  4153. * @param {Object} map The map to clone.
  4154. * @param {Function} cloneFunc The function to clone values.
  4155. * @param {boolean} [isDeep] Specify a deep clone.
  4156. * @returns {Object} Returns the cloned map.
  4157. */
  4158. function cloneMap(map, isDeep, cloneFunc) {
  4159. var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG) : mapToArray(map);
  4160. return arrayReduce(array, addMapEntry, new map.constructor);
  4161. }
  4162. /**
  4163. * Creates a clone of `regexp`.
  4164. *
  4165. * @private
  4166. * @param {Object} regexp The regexp to clone.
  4167. * @returns {Object} Returns the cloned regexp.
  4168. */
  4169. function cloneRegExp(regexp) {
  4170. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4171. result.lastIndex = regexp.lastIndex;
  4172. return result;
  4173. }
  4174. /**
  4175. * Creates a clone of `set`.
  4176. *
  4177. * @private
  4178. * @param {Object} set The set to clone.
  4179. * @param {Function} cloneFunc The function to clone values.
  4180. * @param {boolean} [isDeep] Specify a deep clone.
  4181. * @returns {Object} Returns the cloned set.
  4182. */
  4183. function cloneSet(set, isDeep, cloneFunc) {
  4184. var array = isDeep ? cloneFunc(setToArray(set), CLONE_DEEP_FLAG) : setToArray(set);
  4185. return arrayReduce(array, addSetEntry, new set.constructor);
  4186. }
  4187. /**
  4188. * Creates a clone of the `symbol` object.
  4189. *
  4190. * @private
  4191. * @param {Object} symbol The symbol object to clone.
  4192. * @returns {Object} Returns the cloned symbol object.
  4193. */
  4194. function cloneSymbol(symbol) {
  4195. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4196. }
  4197. /**
  4198. * Creates a clone of `typedArray`.
  4199. *
  4200. * @private
  4201. * @param {Object} typedArray The typed array to clone.
  4202. * @param {boolean} [isDeep] Specify a deep clone.
  4203. * @returns {Object} Returns the cloned typed array.
  4204. */
  4205. function cloneTypedArray(typedArray, isDeep) {
  4206. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4207. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4208. }
  4209. /**
  4210. * Compares values to sort them in ascending order.
  4211. *
  4212. * @private
  4213. * @param {*} value The value to compare.
  4214. * @param {*} other The other value to compare.
  4215. * @returns {number} Returns the sort order indicator for `value`.
  4216. */
  4217. function compareAscending(value, other) {
  4218. if (value !== other) {
  4219. var valIsDefined = value !== undefined,
  4220. valIsNull = value === null,
  4221. valIsReflexive = value === value,
  4222. valIsSymbol = isSymbol(value);
  4223. var othIsDefined = other !== undefined,
  4224. othIsNull = other === null,
  4225. othIsReflexive = other === other,
  4226. othIsSymbol = isSymbol(other);
  4227. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4228. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4229. (valIsNull && othIsDefined && othIsReflexive) ||
  4230. (!valIsDefined && othIsReflexive) ||
  4231. !valIsReflexive) {
  4232. return 1;
  4233. }
  4234. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4235. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4236. (othIsNull && valIsDefined && valIsReflexive) ||
  4237. (!othIsDefined && valIsReflexive) ||
  4238. !othIsReflexive) {
  4239. return -1;
  4240. }
  4241. }
  4242. return 0;
  4243. }
  4244. /**
  4245. * Used by `_.orderBy` to compare multiple properties of a value to another
  4246. * and stable sort them.
  4247. *
  4248. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4249. * specify an order of "desc" for descending or "asc" for ascending sort order
  4250. * of corresponding values.
  4251. *
  4252. * @private
  4253. * @param {Object} object The object to compare.
  4254. * @param {Object} other The other object to compare.
  4255. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4256. * @returns {number} Returns the sort order indicator for `object`.
  4257. */
  4258. function compareMultiple(object, other, orders) {
  4259. var index = -1,
  4260. objCriteria = object.criteria,
  4261. othCriteria = other.criteria,
  4262. length = objCriteria.length,
  4263. ordersLength = orders.length;
  4264. while (++index < length) {
  4265. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4266. if (result) {
  4267. if (index >= ordersLength) {
  4268. return result;
  4269. }
  4270. var order = orders[index];
  4271. return result * (order == 'desc' ? -1 : 1);
  4272. }
  4273. }
  4274. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4275. // that causes it, under certain circumstances, to provide the same value for
  4276. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4277. // for more details.
  4278. //
  4279. // This also ensures a stable sort in V8 and other engines.
  4280. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4281. return object.index - other.index;
  4282. }
  4283. /**
  4284. * Creates an array that is the composition of partially applied arguments,
  4285. * placeholders, and provided arguments into a single array of arguments.
  4286. *
  4287. * @private
  4288. * @param {Array} args The provided arguments.
  4289. * @param {Array} partials The arguments to prepend to those provided.
  4290. * @param {Array} holders The `partials` placeholder indexes.
  4291. * @params {boolean} [isCurried] Specify composing for a curried function.
  4292. * @returns {Array} Returns the new array of composed arguments.
  4293. */
  4294. function composeArgs(args, partials, holders, isCurried) {
  4295. var argsIndex = -1,
  4296. argsLength = args.length,
  4297. holdersLength = holders.length,
  4298. leftIndex = -1,
  4299. leftLength = partials.length,
  4300. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4301. result = Array(leftLength + rangeLength),
  4302. isUncurried = !isCurried;
  4303. while (++leftIndex < leftLength) {
  4304. result[leftIndex] = partials[leftIndex];
  4305. }
  4306. while (++argsIndex < holdersLength) {
  4307. if (isUncurried || argsIndex < argsLength) {
  4308. result[holders[argsIndex]] = args[argsIndex];
  4309. }
  4310. }
  4311. while (rangeLength--) {
  4312. result[leftIndex++] = args[argsIndex++];
  4313. }
  4314. return result;
  4315. }
  4316. /**
  4317. * This function is like `composeArgs` except that the arguments composition
  4318. * is tailored for `_.partialRight`.
  4319. *
  4320. * @private
  4321. * @param {Array} args The provided arguments.
  4322. * @param {Array} partials The arguments to append to those provided.
  4323. * @param {Array} holders The `partials` placeholder indexes.
  4324. * @params {boolean} [isCurried] Specify composing for a curried function.
  4325. * @returns {Array} Returns the new array of composed arguments.
  4326. */
  4327. function composeArgsRight(args, partials, holders, isCurried) {
  4328. var argsIndex = -1,
  4329. argsLength = args.length,
  4330. holdersIndex = -1,
  4331. holdersLength = holders.length,
  4332. rightIndex = -1,
  4333. rightLength = partials.length,
  4334. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4335. result = Array(rangeLength + rightLength),
  4336. isUncurried = !isCurried;
  4337. while (++argsIndex < rangeLength) {
  4338. result[argsIndex] = args[argsIndex];
  4339. }
  4340. var offset = argsIndex;
  4341. while (++rightIndex < rightLength) {
  4342. result[offset + rightIndex] = partials[rightIndex];
  4343. }
  4344. while (++holdersIndex < holdersLength) {
  4345. if (isUncurried || argsIndex < argsLength) {
  4346. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4347. }
  4348. }
  4349. return result;
  4350. }
  4351. /**
  4352. * Copies the values of `source` to `array`.
  4353. *
  4354. * @private
  4355. * @param {Array} source The array to copy values from.
  4356. * @param {Array} [array=[]] The array to copy values to.
  4357. * @returns {Array} Returns `array`.
  4358. */
  4359. function copyArray(source, array) {
  4360. var index = -1,
  4361. length = source.length;
  4362. array || (array = Array(length));
  4363. while (++index < length) {
  4364. array[index] = source[index];
  4365. }
  4366. return array;
  4367. }
  4368. /**
  4369. * Copies properties of `source` to `object`.
  4370. *
  4371. * @private
  4372. * @param {Object} source The object to copy properties from.
  4373. * @param {Array} props The property identifiers to copy.
  4374. * @param {Object} [object={}] The object to copy properties to.
  4375. * @param {Function} [customizer] The function to customize copied values.
  4376. * @returns {Object} Returns `object`.
  4377. */
  4378. function copyObject(source, props, object, customizer) {
  4379. var isNew = !object;
  4380. object || (object = {});
  4381. var index = -1,
  4382. length = props.length;
  4383. while (++index < length) {
  4384. var key = props[index];
  4385. var newValue = customizer
  4386. ? customizer(object[key], source[key], key, object, source)
  4387. : undefined;
  4388. if (newValue === undefined) {
  4389. newValue = source[key];
  4390. }
  4391. if (isNew) {
  4392. baseAssignValue(object, key, newValue);
  4393. } else {
  4394. assignValue(object, key, newValue);
  4395. }
  4396. }
  4397. return object;
  4398. }
  4399. /**
  4400. * Copies own symbols of `source` to `object`.
  4401. *
  4402. * @private
  4403. * @param {Object} source The object to copy symbols from.
  4404. * @param {Object} [object={}] The object to copy symbols to.
  4405. * @returns {Object} Returns `object`.
  4406. */
  4407. function copySymbols(source, object) {
  4408. return copyObject(source, getSymbols(source), object);
  4409. }
  4410. /**
  4411. * Copies own and inherited symbols of `source` to `object`.
  4412. *
  4413. * @private
  4414. * @param {Object} source The object to copy symbols from.
  4415. * @param {Object} [object={}] The object to copy symbols to.
  4416. * @returns {Object} Returns `object`.
  4417. */
  4418. function copySymbolsIn(source, object) {
  4419. return copyObject(source, getSymbolsIn(source), object);
  4420. }
  4421. /**
  4422. * Creates a function like `_.groupBy`.
  4423. *
  4424. * @private
  4425. * @param {Function} setter The function to set accumulator values.
  4426. * @param {Function} [initializer] The accumulator object initializer.
  4427. * @returns {Function} Returns the new aggregator function.
  4428. */
  4429. function createAggregator(setter, initializer) {
  4430. return function(collection, iteratee) {
  4431. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4432. accumulator = initializer ? initializer() : {};
  4433. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4434. };
  4435. }
  4436. /**
  4437. * Creates a function like `_.assign`.
  4438. *
  4439. * @private
  4440. * @param {Function} assigner The function to assign values.
  4441. * @returns {Function} Returns the new assigner function.
  4442. */
  4443. function createAssigner(assigner) {
  4444. return baseRest(function(object, sources) {
  4445. var index = -1,
  4446. length = sources.length,
  4447. customizer = length > 1 ? sources[length - 1] : undefined,
  4448. guard = length > 2 ? sources[2] : undefined;
  4449. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4450. ? (length--, customizer)
  4451. : undefined;
  4452. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4453. customizer = length < 3 ? undefined : customizer;
  4454. length = 1;
  4455. }
  4456. object = Object(object);
  4457. while (++index < length) {
  4458. var source = sources[index];
  4459. if (source) {
  4460. assigner(object, source, index, customizer);
  4461. }
  4462. }
  4463. return object;
  4464. });
  4465. }
  4466. /**
  4467. * Creates a `baseEach` or `baseEachRight` function.
  4468. *
  4469. * @private
  4470. * @param {Function} eachFunc The function to iterate over a collection.
  4471. * @param {boolean} [fromRight] Specify iterating from right to left.
  4472. * @returns {Function} Returns the new base function.
  4473. */
  4474. function createBaseEach(eachFunc, fromRight) {
  4475. return function(collection, iteratee) {
  4476. if (collection == null) {
  4477. return collection;
  4478. }
  4479. if (!isArrayLike(collection)) {
  4480. return eachFunc(collection, iteratee);
  4481. }
  4482. var length = collection.length,
  4483. index = fromRight ? length : -1,
  4484. iterable = Object(collection);
  4485. while ((fromRight ? index-- : ++index < length)) {
  4486. if (iteratee(iterable[index], index, iterable) === false) {
  4487. break;
  4488. }
  4489. }
  4490. return collection;
  4491. };
  4492. }
  4493. /**
  4494. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4495. *
  4496. * @private
  4497. * @param {boolean} [fromRight] Specify iterating from right to left.
  4498. * @returns {Function} Returns the new base function.
  4499. */
  4500. function createBaseFor(fromRight) {
  4501. return function(object, iteratee, keysFunc) {
  4502. var index = -1,
  4503. iterable = Object(object),
  4504. props = keysFunc(object),
  4505. length = props.length;
  4506. while (length--) {
  4507. var key = props[fromRight ? length : ++index];
  4508. if (iteratee(iterable[key], key, iterable) === false) {
  4509. break;
  4510. }
  4511. }
  4512. return object;
  4513. };
  4514. }
  4515. /**
  4516. * Creates a function that wraps `func` to invoke it with the optional `this`
  4517. * binding of `thisArg`.
  4518. *
  4519. * @private
  4520. * @param {Function} func The function to wrap.
  4521. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4522. * @param {*} [thisArg] The `this` binding of `func`.
  4523. * @returns {Function} Returns the new wrapped function.
  4524. */
  4525. function createBind(func, bitmask, thisArg) {
  4526. var isBind = bitmask & WRAP_BIND_FLAG,
  4527. Ctor = createCtor(func);
  4528. function wrapper() {
  4529. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4530. return fn.apply(isBind ? thisArg : this, arguments);
  4531. }
  4532. return wrapper;
  4533. }
  4534. /**
  4535. * Creates a function like `_.lowerFirst`.
  4536. *
  4537. * @private
  4538. * @param {string} methodName The name of the `String` case method to use.
  4539. * @returns {Function} Returns the new case function.
  4540. */
  4541. function createCaseFirst(methodName) {
  4542. return function(string) {
  4543. string = toString(string);
  4544. var strSymbols = hasUnicode(string)
  4545. ? stringToArray(string)
  4546. : undefined;
  4547. var chr = strSymbols
  4548. ? strSymbols[0]
  4549. : string.charAt(0);
  4550. var trailing = strSymbols
  4551. ? castSlice(strSymbols, 1).join('')
  4552. : string.slice(1);
  4553. return chr[methodName]() + trailing;
  4554. };
  4555. }
  4556. /**
  4557. * Creates a function like `_.camelCase`.
  4558. *
  4559. * @private
  4560. * @param {Function} callback The function to combine each word.
  4561. * @returns {Function} Returns the new compounder function.
  4562. */
  4563. function createCompounder(callback) {
  4564. return function(string) {
  4565. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4566. };
  4567. }
  4568. /**
  4569. * Creates a function that produces an instance of `Ctor` regardless of
  4570. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4571. *
  4572. * @private
  4573. * @param {Function} Ctor The constructor to wrap.
  4574. * @returns {Function} Returns the new wrapped function.
  4575. */
  4576. function createCtor(Ctor) {
  4577. return function() {
  4578. // Use a `switch` statement to work with class constructors. See
  4579. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4580. // for more details.
  4581. var args = arguments;
  4582. switch (args.length) {
  4583. case 0: return new Ctor;
  4584. case 1: return new Ctor(args[0]);
  4585. case 2: return new Ctor(args[0], args[1]);
  4586. case 3: return new Ctor(args[0], args[1], args[2]);
  4587. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4588. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4589. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4590. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4591. }
  4592. var thisBinding = baseCreate(Ctor.prototype),
  4593. result = Ctor.apply(thisBinding, args);
  4594. // Mimic the constructor's `return` behavior.
  4595. // See https://es5.github.io/#x13.2.2 for more details.
  4596. return isObject(result) ? result : thisBinding;
  4597. };
  4598. }
  4599. /**
  4600. * Creates a function that wraps `func` to enable currying.
  4601. *
  4602. * @private
  4603. * @param {Function} func The function to wrap.
  4604. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4605. * @param {number} arity The arity of `func`.
  4606. * @returns {Function} Returns the new wrapped function.
  4607. */
  4608. function createCurry(func, bitmask, arity) {
  4609. var Ctor = createCtor(func);
  4610. function wrapper() {
  4611. var length = arguments.length,
  4612. args = Array(length),
  4613. index = length,
  4614. placeholder = getHolder(wrapper);
  4615. while (index--) {
  4616. args[index] = arguments[index];
  4617. }
  4618. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4619. ? []
  4620. : replaceHolders(args, placeholder);
  4621. length -= holders.length;
  4622. if (length < arity) {
  4623. return createRecurry(
  4624. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4625. args, holders, undefined, undefined, arity - length);
  4626. }
  4627. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4628. return apply(fn, this, args);
  4629. }
  4630. return wrapper;
  4631. }
  4632. /**
  4633. * Creates a `_.find` or `_.findLast` function.
  4634. *
  4635. * @private
  4636. * @param {Function} findIndexFunc The function to find the collection index.
  4637. * @returns {Function} Returns the new find function.
  4638. */
  4639. function createFind(findIndexFunc) {
  4640. return function(collection, predicate, fromIndex) {
  4641. var iterable = Object(collection);
  4642. if (!isArrayLike(collection)) {
  4643. var iteratee = getIteratee(predicate, 3);
  4644. collection = keys(collection);
  4645. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4646. }
  4647. var index = findIndexFunc(collection, predicate, fromIndex);
  4648. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4649. };
  4650. }
  4651. /**
  4652. * Creates a `_.flow` or `_.flowRight` function.
  4653. *
  4654. * @private
  4655. * @param {boolean} [fromRight] Specify iterating from right to left.
  4656. * @returns {Function} Returns the new flow function.
  4657. */
  4658. function createFlow(fromRight) {
  4659. return flatRest(function(funcs) {
  4660. var length = funcs.length,
  4661. index = length,
  4662. prereq = LodashWrapper.prototype.thru;
  4663. if (fromRight) {
  4664. funcs.reverse();
  4665. }
  4666. while (index--) {
  4667. var func = funcs[index];
  4668. if (typeof func != 'function') {
  4669. throw new TypeError(FUNC_ERROR_TEXT);
  4670. }
  4671. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4672. var wrapper = new LodashWrapper([], true);
  4673. }
  4674. }
  4675. index = wrapper ? index : length;
  4676. while (++index < length) {
  4677. func = funcs[index];
  4678. var funcName = getFuncName(func),
  4679. data = funcName == 'wrapper' ? getData(func) : undefined;
  4680. if (data && isLaziable(data[0]) &&
  4681. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4682. !data[4].length && data[9] == 1
  4683. ) {
  4684. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4685. } else {
  4686. wrapper = (func.length == 1 && isLaziable(func))
  4687. ? wrapper[funcName]()
  4688. : wrapper.thru(func);
  4689. }
  4690. }
  4691. return function() {
  4692. var args = arguments,
  4693. value = args[0];
  4694. if (wrapper && args.length == 1 && isArray(value)) {
  4695. return wrapper.plant(value).value();
  4696. }
  4697. var index = 0,
  4698. result = length ? funcs[index].apply(this, args) : value;
  4699. while (++index < length) {
  4700. result = funcs[index].call(this, result);
  4701. }
  4702. return result;
  4703. };
  4704. });
  4705. }
  4706. /**
  4707. * Creates a function that wraps `func` to invoke it with optional `this`
  4708. * binding of `thisArg`, partial application, and currying.
  4709. *
  4710. * @private
  4711. * @param {Function|string} func The function or method name to wrap.
  4712. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4713. * @param {*} [thisArg] The `this` binding of `func`.
  4714. * @param {Array} [partials] The arguments to prepend to those provided to
  4715. * the new function.
  4716. * @param {Array} [holders] The `partials` placeholder indexes.
  4717. * @param {Array} [partialsRight] The arguments to append to those provided
  4718. * to the new function.
  4719. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4720. * @param {Array} [argPos] The argument positions of the new function.
  4721. * @param {number} [ary] The arity cap of `func`.
  4722. * @param {number} [arity] The arity of `func`.
  4723. * @returns {Function} Returns the new wrapped function.
  4724. */
  4725. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4726. var isAry = bitmask & WRAP_ARY_FLAG,
  4727. isBind = bitmask & WRAP_BIND_FLAG,
  4728. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4729. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4730. isFlip = bitmask & WRAP_FLIP_FLAG,
  4731. Ctor = isBindKey ? undefined : createCtor(func);
  4732. function wrapper() {
  4733. var length = arguments.length,
  4734. args = Array(length),
  4735. index = length;
  4736. while (index--) {
  4737. args[index] = arguments[index];
  4738. }
  4739. if (isCurried) {
  4740. var placeholder = getHolder(wrapper),
  4741. holdersCount = countHolders(args, placeholder);
  4742. }
  4743. if (partials) {
  4744. args = composeArgs(args, partials, holders, isCurried);
  4745. }
  4746. if (partialsRight) {
  4747. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4748. }
  4749. length -= holdersCount;
  4750. if (isCurried && length < arity) {
  4751. var newHolders = replaceHolders(args, placeholder);
  4752. return createRecurry(
  4753. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4754. args, newHolders, argPos, ary, arity - length
  4755. );
  4756. }
  4757. var thisBinding = isBind ? thisArg : this,
  4758. fn = isBindKey ? thisBinding[func] : func;
  4759. length = args.length;
  4760. if (argPos) {
  4761. args = reorder(args, argPos);
  4762. } else if (isFlip && length > 1) {
  4763. args.reverse();
  4764. }
  4765. if (isAry && ary < length) {
  4766. args.length = ary;
  4767. }
  4768. if (this && this !== root && this instanceof wrapper) {
  4769. fn = Ctor || createCtor(fn);
  4770. }
  4771. return fn.apply(thisBinding, args);
  4772. }
  4773. return wrapper;
  4774. }
  4775. /**
  4776. * Creates a function like `_.invertBy`.
  4777. *
  4778. * @private
  4779. * @param {Function} setter The function to set accumulator values.
  4780. * @param {Function} toIteratee The function to resolve iteratees.
  4781. * @returns {Function} Returns the new inverter function.
  4782. */
  4783. function createInverter(setter, toIteratee) {
  4784. return function(object, iteratee) {
  4785. return baseInverter(object, setter, toIteratee(iteratee), {});
  4786. };
  4787. }
  4788. /**
  4789. * Creates a function that performs a mathematical operation on two values.
  4790. *
  4791. * @private
  4792. * @param {Function} operator The function to perform the operation.
  4793. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4794. * @returns {Function} Returns the new mathematical operation function.
  4795. */
  4796. function createMathOperation(operator, defaultValue) {
  4797. return function(value, other) {
  4798. var result;
  4799. if (value === undefined && other === undefined) {
  4800. return defaultValue;
  4801. }
  4802. if (value !== undefined) {
  4803. result = value;
  4804. }
  4805. if (other !== undefined) {
  4806. if (result === undefined) {
  4807. return other;
  4808. }
  4809. if (typeof value == 'string' || typeof other == 'string') {
  4810. value = baseToString(value);
  4811. other = baseToString(other);
  4812. } else {
  4813. value = baseToNumber(value);
  4814. other = baseToNumber(other);
  4815. }
  4816. result = operator(value, other);
  4817. }
  4818. return result;
  4819. };
  4820. }
  4821. /**
  4822. * Creates a function like `_.over`.
  4823. *
  4824. * @private
  4825. * @param {Function} arrayFunc The function to iterate over iteratees.
  4826. * @returns {Function} Returns the new over function.
  4827. */
  4828. function createOver(arrayFunc) {
  4829. return flatRest(function(iteratees) {
  4830. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4831. return baseRest(function(args) {
  4832. var thisArg = this;
  4833. return arrayFunc(iteratees, function(iteratee) {
  4834. return apply(iteratee, thisArg, args);
  4835. });
  4836. });
  4837. });
  4838. }
  4839. /**
  4840. * Creates the padding for `string` based on `length`. The `chars` string
  4841. * is truncated if the number of characters exceeds `length`.
  4842. *
  4843. * @private
  4844. * @param {number} length The padding length.
  4845. * @param {string} [chars=' '] The string used as padding.
  4846. * @returns {string} Returns the padding for `string`.
  4847. */
  4848. function createPadding(length, chars) {
  4849. chars = chars === undefined ? ' ' : baseToString(chars);
  4850. var charsLength = chars.length;
  4851. if (charsLength < 2) {
  4852. return charsLength ? baseRepeat(chars, length) : chars;
  4853. }
  4854. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4855. return hasUnicode(chars)
  4856. ? castSlice(stringToArray(result), 0, length).join('')
  4857. : result.slice(0, length);
  4858. }
  4859. /**
  4860. * Creates a function that wraps `func` to invoke it with the `this` binding
  4861. * of `thisArg` and `partials` prepended to the arguments it receives.
  4862. *
  4863. * @private
  4864. * @param {Function} func The function to wrap.
  4865. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4866. * @param {*} thisArg The `this` binding of `func`.
  4867. * @param {Array} partials The arguments to prepend to those provided to
  4868. * the new function.
  4869. * @returns {Function} Returns the new wrapped function.
  4870. */
  4871. function createPartial(func, bitmask, thisArg, partials) {
  4872. var isBind = bitmask & WRAP_BIND_FLAG,
  4873. Ctor = createCtor(func);
  4874. function wrapper() {
  4875. var argsIndex = -1,
  4876. argsLength = arguments.length,
  4877. leftIndex = -1,
  4878. leftLength = partials.length,
  4879. args = Array(leftLength + argsLength),
  4880. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4881. while (++leftIndex < leftLength) {
  4882. args[leftIndex] = partials[leftIndex];
  4883. }
  4884. while (argsLength--) {
  4885. args[leftIndex++] = arguments[++argsIndex];
  4886. }
  4887. return apply(fn, isBind ? thisArg : this, args);
  4888. }
  4889. return wrapper;
  4890. }
  4891. /**
  4892. * Creates a `_.range` or `_.rangeRight` function.
  4893. *
  4894. * @private
  4895. * @param {boolean} [fromRight] Specify iterating from right to left.
  4896. * @returns {Function} Returns the new range function.
  4897. */
  4898. function createRange(fromRight) {
  4899. return function(start, end, step) {
  4900. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4901. end = step = undefined;
  4902. }
  4903. // Ensure the sign of `-0` is preserved.
  4904. start = toFinite(start);
  4905. if (end === undefined) {
  4906. end = start;
  4907. start = 0;
  4908. } else {
  4909. end = toFinite(end);
  4910. }
  4911. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4912. return baseRange(start, end, step, fromRight);
  4913. };
  4914. }
  4915. /**
  4916. * Creates a function that performs a relational operation on two values.
  4917. *
  4918. * @private
  4919. * @param {Function} operator The function to perform the operation.
  4920. * @returns {Function} Returns the new relational operation function.
  4921. */
  4922. function createRelationalOperation(operator) {
  4923. return function(value, other) {
  4924. if (!(typeof value == 'string' && typeof other == 'string')) {
  4925. value = toNumber(value);
  4926. other = toNumber(other);
  4927. }
  4928. return operator(value, other);
  4929. };
  4930. }
  4931. /**
  4932. * Creates a function that wraps `func` to continue currying.
  4933. *
  4934. * @private
  4935. * @param {Function} func The function to wrap.
  4936. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4937. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4938. * @param {*} placeholder The placeholder value.
  4939. * @param {*} [thisArg] The `this` binding of `func`.
  4940. * @param {Array} [partials] The arguments to prepend to those provided to
  4941. * the new function.
  4942. * @param {Array} [holders] The `partials` placeholder indexes.
  4943. * @param {Array} [argPos] The argument positions of the new function.
  4944. * @param {number} [ary] The arity cap of `func`.
  4945. * @param {number} [arity] The arity of `func`.
  4946. * @returns {Function} Returns the new wrapped function.
  4947. */
  4948. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4949. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4950. newHolders = isCurry ? holders : undefined,
  4951. newHoldersRight = isCurry ? undefined : holders,
  4952. newPartials = isCurry ? partials : undefined,
  4953. newPartialsRight = isCurry ? undefined : partials;
  4954. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4955. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4956. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4957. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4958. }
  4959. var newData = [
  4960. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4961. newHoldersRight, argPos, ary, arity
  4962. ];
  4963. var result = wrapFunc.apply(undefined, newData);
  4964. if (isLaziable(func)) {
  4965. setData(result, newData);
  4966. }
  4967. result.placeholder = placeholder;
  4968. return setWrapToString(result, func, bitmask);
  4969. }
  4970. /**
  4971. * Creates a function like `_.round`.
  4972. *
  4973. * @private
  4974. * @param {string} methodName The name of the `Math` method to use when rounding.
  4975. * @returns {Function} Returns the new round function.
  4976. */
  4977. function createRound(methodName) {
  4978. var func = Math[methodName];
  4979. return function(number, precision) {
  4980. number = toNumber(number);
  4981. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4982. if (precision) {
  4983. // Shift with exponential notation to avoid floating-point issues.
  4984. // See [MDN](https://mdn.io/round#Examples) for more details.
  4985. var pair = (toString(number) + 'e').split('e'),
  4986. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4987. pair = (toString(value) + 'e').split('e');
  4988. return +(pair[0] + 'e' + (+pair[1] - precision));
  4989. }
  4990. return func(number);
  4991. };
  4992. }
  4993. /**
  4994. * Creates a set object of `values`.
  4995. *
  4996. * @private
  4997. * @param {Array} values The values to add to the set.
  4998. * @returns {Object} Returns the new set.
  4999. */
  5000. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5001. return new Set(values);
  5002. };
  5003. /**
  5004. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5005. *
  5006. * @private
  5007. * @param {Function} keysFunc The function to get the keys of a given object.
  5008. * @returns {Function} Returns the new pairs function.
  5009. */
  5010. function createToPairs(keysFunc) {
  5011. return function(object) {
  5012. var tag = getTag(object);
  5013. if (tag == mapTag) {
  5014. return mapToArray(object);
  5015. }
  5016. if (tag == setTag) {
  5017. return setToPairs(object);
  5018. }
  5019. return baseToPairs(object, keysFunc(object));
  5020. };
  5021. }
  5022. /**
  5023. * Creates a function that either curries or invokes `func` with optional
  5024. * `this` binding and partially applied arguments.
  5025. *
  5026. * @private
  5027. * @param {Function|string} func The function or method name to wrap.
  5028. * @param {number} bitmask The bitmask flags.
  5029. * 1 - `_.bind`
  5030. * 2 - `_.bindKey`
  5031. * 4 - `_.curry` or `_.curryRight` of a bound function
  5032. * 8 - `_.curry`
  5033. * 16 - `_.curryRight`
  5034. * 32 - `_.partial`
  5035. * 64 - `_.partialRight`
  5036. * 128 - `_.rearg`
  5037. * 256 - `_.ary`
  5038. * 512 - `_.flip`
  5039. * @param {*} [thisArg] The `this` binding of `func`.
  5040. * @param {Array} [partials] The arguments to be partially applied.
  5041. * @param {Array} [holders] The `partials` placeholder indexes.
  5042. * @param {Array} [argPos] The argument positions of the new function.
  5043. * @param {number} [ary] The arity cap of `func`.
  5044. * @param {number} [arity] The arity of `func`.
  5045. * @returns {Function} Returns the new wrapped function.
  5046. */
  5047. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5048. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5049. if (!isBindKey && typeof func != 'function') {
  5050. throw new TypeError(FUNC_ERROR_TEXT);
  5051. }
  5052. var length = partials ? partials.length : 0;
  5053. if (!length) {
  5054. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5055. partials = holders = undefined;
  5056. }
  5057. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5058. arity = arity === undefined ? arity : toInteger(arity);
  5059. length -= holders ? holders.length : 0;
  5060. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5061. var partialsRight = partials,
  5062. holdersRight = holders;
  5063. partials = holders = undefined;
  5064. }
  5065. var data = isBindKey ? undefined : getData(func);
  5066. var newData = [
  5067. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5068. argPos, ary, arity
  5069. ];
  5070. if (data) {
  5071. mergeData(newData, data);
  5072. }
  5073. func = newData[0];
  5074. bitmask = newData[1];
  5075. thisArg = newData[2];
  5076. partials = newData[3];
  5077. holders = newData[4];
  5078. arity = newData[9] = newData[9] === undefined
  5079. ? (isBindKey ? 0 : func.length)
  5080. : nativeMax(newData[9] - length, 0);
  5081. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5082. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5083. }
  5084. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5085. var result = createBind(func, bitmask, thisArg);
  5086. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5087. result = createCurry(func, bitmask, arity);
  5088. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5089. result = createPartial(func, bitmask, thisArg, partials);
  5090. } else {
  5091. result = createHybrid.apply(undefined, newData);
  5092. }
  5093. var setter = data ? baseSetData : setData;
  5094. return setWrapToString(setter(result, newData), func, bitmask);
  5095. }
  5096. /**
  5097. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5098. * of source objects to the destination object for all destination properties
  5099. * that resolve to `undefined`.
  5100. *
  5101. * @private
  5102. * @param {*} objValue The destination value.
  5103. * @param {*} srcValue The source value.
  5104. * @param {string} key The key of the property to assign.
  5105. * @param {Object} object The parent object of `objValue`.
  5106. * @returns {*} Returns the value to assign.
  5107. */
  5108. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5109. if (objValue === undefined ||
  5110. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5111. return srcValue;
  5112. }
  5113. return objValue;
  5114. }
  5115. /**
  5116. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5117. * objects into destination objects that are passed thru.
  5118. *
  5119. * @private
  5120. * @param {*} objValue The destination value.
  5121. * @param {*} srcValue The source value.
  5122. * @param {string} key The key of the property to merge.
  5123. * @param {Object} object The parent object of `objValue`.
  5124. * @param {Object} source The parent object of `srcValue`.
  5125. * @param {Object} [stack] Tracks traversed source values and their merged
  5126. * counterparts.
  5127. * @returns {*} Returns the value to assign.
  5128. */
  5129. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5130. if (isObject(objValue) && isObject(srcValue)) {
  5131. // Recursively merge objects and arrays (susceptible to call stack limits).
  5132. stack.set(srcValue, objValue);
  5133. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5134. stack['delete'](srcValue);
  5135. }
  5136. return objValue;
  5137. }
  5138. /**
  5139. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5140. * objects.
  5141. *
  5142. * @private
  5143. * @param {*} value The value to inspect.
  5144. * @param {string} key The key of the property to inspect.
  5145. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5146. */
  5147. function customOmitClone(value) {
  5148. return isPlainObject(value) ? undefined : value;
  5149. }
  5150. /**
  5151. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5152. * partial deep comparisons.
  5153. *
  5154. * @private
  5155. * @param {Array} array The array to compare.
  5156. * @param {Array} other The other array to compare.
  5157. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5158. * @param {Function} customizer The function to customize comparisons.
  5159. * @param {Function} equalFunc The function to determine equivalents of values.
  5160. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5161. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5162. */
  5163. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5164. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5165. arrLength = array.length,
  5166. othLength = other.length;
  5167. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5168. return false;
  5169. }
  5170. // Assume cyclic values are equal.
  5171. var stacked = stack.get(array);
  5172. if (stacked && stack.get(other)) {
  5173. return stacked == other;
  5174. }
  5175. var index = -1,
  5176. result = true,
  5177. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5178. stack.set(array, other);
  5179. stack.set(other, array);
  5180. // Ignore non-index properties.
  5181. while (++index < arrLength) {
  5182. var arrValue = array[index],
  5183. othValue = other[index];
  5184. if (customizer) {
  5185. var compared = isPartial
  5186. ? customizer(othValue, arrValue, index, other, array, stack)
  5187. : customizer(arrValue, othValue, index, array, other, stack);
  5188. }
  5189. if (compared !== undefined) {
  5190. if (compared) {
  5191. continue;
  5192. }
  5193. result = false;
  5194. break;
  5195. }
  5196. // Recursively compare arrays (susceptible to call stack limits).
  5197. if (seen) {
  5198. if (!arraySome(other, function(othValue, othIndex) {
  5199. if (!cacheHas(seen, othIndex) &&
  5200. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5201. return seen.push(othIndex);
  5202. }
  5203. })) {
  5204. result = false;
  5205. break;
  5206. }
  5207. } else if (!(
  5208. arrValue === othValue ||
  5209. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5210. )) {
  5211. result = false;
  5212. break;
  5213. }
  5214. }
  5215. stack['delete'](array);
  5216. stack['delete'](other);
  5217. return result;
  5218. }
  5219. /**
  5220. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5221. * the same `toStringTag`.
  5222. *
  5223. * **Note:** This function only supports comparing values with tags of
  5224. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5225. *
  5226. * @private
  5227. * @param {Object} object The object to compare.
  5228. * @param {Object} other The other object to compare.
  5229. * @param {string} tag The `toStringTag` of the objects to compare.
  5230. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5231. * @param {Function} customizer The function to customize comparisons.
  5232. * @param {Function} equalFunc The function to determine equivalents of values.
  5233. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5234. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5235. */
  5236. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5237. switch (tag) {
  5238. case dataViewTag:
  5239. if ((object.byteLength != other.byteLength) ||
  5240. (object.byteOffset != other.byteOffset)) {
  5241. return false;
  5242. }
  5243. object = object.buffer;
  5244. other = other.buffer;
  5245. case arrayBufferTag:
  5246. if ((object.byteLength != other.byteLength) ||
  5247. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5248. return false;
  5249. }
  5250. return true;
  5251. case boolTag:
  5252. case dateTag:
  5253. case numberTag:
  5254. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5255. // Invalid dates are coerced to `NaN`.
  5256. return eq(+object, +other);
  5257. case errorTag:
  5258. return object.name == other.name && object.message == other.message;
  5259. case regexpTag:
  5260. case stringTag:
  5261. // Coerce regexes to strings and treat strings, primitives and objects,
  5262. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5263. // for more details.
  5264. return object == (other + '');
  5265. case mapTag:
  5266. var convert = mapToArray;
  5267. case setTag:
  5268. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5269. convert || (convert = setToArray);
  5270. if (object.size != other.size && !isPartial) {
  5271. return false;
  5272. }
  5273. // Assume cyclic values are equal.
  5274. var stacked = stack.get(object);
  5275. if (stacked) {
  5276. return stacked == other;
  5277. }
  5278. bitmask |= COMPARE_UNORDERED_FLAG;
  5279. // Recursively compare objects (susceptible to call stack limits).
  5280. stack.set(object, other);
  5281. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5282. stack['delete'](object);
  5283. return result;
  5284. case symbolTag:
  5285. if (symbolValueOf) {
  5286. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5287. }
  5288. }
  5289. return false;
  5290. }
  5291. /**
  5292. * A specialized version of `baseIsEqualDeep` for objects with support for
  5293. * partial deep comparisons.
  5294. *
  5295. * @private
  5296. * @param {Object} object The object to compare.
  5297. * @param {Object} other The other object to compare.
  5298. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5299. * @param {Function} customizer The function to customize comparisons.
  5300. * @param {Function} equalFunc The function to determine equivalents of values.
  5301. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5302. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5303. */
  5304. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5305. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5306. objProps = getAllKeys(object),
  5307. objLength = objProps.length,
  5308. othProps = getAllKeys(other),
  5309. othLength = othProps.length;
  5310. if (objLength != othLength && !isPartial) {
  5311. return false;
  5312. }
  5313. var index = objLength;
  5314. while (index--) {
  5315. var key = objProps[index];
  5316. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5317. return false;
  5318. }
  5319. }
  5320. // Assume cyclic values are equal.
  5321. var stacked = stack.get(object);
  5322. if (stacked && stack.get(other)) {
  5323. return stacked == other;
  5324. }
  5325. var result = true;
  5326. stack.set(object, other);
  5327. stack.set(other, object);
  5328. var skipCtor = isPartial;
  5329. while (++index < objLength) {
  5330. key = objProps[index];
  5331. var objValue = object[key],
  5332. othValue = other[key];
  5333. if (customizer) {
  5334. var compared = isPartial
  5335. ? customizer(othValue, objValue, key, other, object, stack)
  5336. : customizer(objValue, othValue, key, object, other, stack);
  5337. }
  5338. // Recursively compare objects (susceptible to call stack limits).
  5339. if (!(compared === undefined
  5340. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5341. : compared
  5342. )) {
  5343. result = false;
  5344. break;
  5345. }
  5346. skipCtor || (skipCtor = key == 'constructor');
  5347. }
  5348. if (result && !skipCtor) {
  5349. var objCtor = object.constructor,
  5350. othCtor = other.constructor;
  5351. // Non `Object` object instances with different constructors are not equal.
  5352. if (objCtor != othCtor &&
  5353. ('constructor' in object && 'constructor' in other) &&
  5354. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5355. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5356. result = false;
  5357. }
  5358. }
  5359. stack['delete'](object);
  5360. stack['delete'](other);
  5361. return result;
  5362. }
  5363. /**
  5364. * A specialized version of `baseRest` which flattens the rest array.
  5365. *
  5366. * @private
  5367. * @param {Function} func The function to apply a rest parameter to.
  5368. * @returns {Function} Returns the new function.
  5369. */
  5370. function flatRest(func) {
  5371. return setToString(overRest(func, undefined, flatten), func + '');
  5372. }
  5373. /**
  5374. * Creates an array of own enumerable property names and symbols of `object`.
  5375. *
  5376. * @private
  5377. * @param {Object} object The object to query.
  5378. * @returns {Array} Returns the array of property names and symbols.
  5379. */
  5380. function getAllKeys(object) {
  5381. return baseGetAllKeys(object, keys, getSymbols);
  5382. }
  5383. /**
  5384. * Creates an array of own and inherited enumerable property names and
  5385. * symbols of `object`.
  5386. *
  5387. * @private
  5388. * @param {Object} object The object to query.
  5389. * @returns {Array} Returns the array of property names and symbols.
  5390. */
  5391. function getAllKeysIn(object) {
  5392. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5393. }
  5394. /**
  5395. * Gets metadata for `func`.
  5396. *
  5397. * @private
  5398. * @param {Function} func The function to query.
  5399. * @returns {*} Returns the metadata for `func`.
  5400. */
  5401. var getData = !metaMap ? noop : function(func) {
  5402. return metaMap.get(func);
  5403. };
  5404. /**
  5405. * Gets the name of `func`.
  5406. *
  5407. * @private
  5408. * @param {Function} func The function to query.
  5409. * @returns {string} Returns the function name.
  5410. */
  5411. function getFuncName(func) {
  5412. var result = (func.name + ''),
  5413. array = realNames[result],
  5414. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5415. while (length--) {
  5416. var data = array[length],
  5417. otherFunc = data.func;
  5418. if (otherFunc == null || otherFunc == func) {
  5419. return data.name;
  5420. }
  5421. }
  5422. return result;
  5423. }
  5424. /**
  5425. * Gets the argument placeholder value for `func`.
  5426. *
  5427. * @private
  5428. * @param {Function} func The function to inspect.
  5429. * @returns {*} Returns the placeholder value.
  5430. */
  5431. function getHolder(func) {
  5432. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5433. return object.placeholder;
  5434. }
  5435. /**
  5436. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5437. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5438. * If arguments are provided, the chosen function is invoked with them and
  5439. * its result is returned.
  5440. *
  5441. * @private
  5442. * @param {*} [value] The value to convert to an iteratee.
  5443. * @param {number} [arity] The arity of the created iteratee.
  5444. * @returns {Function} Returns the chosen function or its result.
  5445. */
  5446. function getIteratee() {
  5447. var result = lodash.iteratee || iteratee;
  5448. result = result === iteratee ? baseIteratee : result;
  5449. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5450. }
  5451. /**
  5452. * Gets the data for `map`.
  5453. *
  5454. * @private
  5455. * @param {Object} map The map to query.
  5456. * @param {string} key The reference key.
  5457. * @returns {*} Returns the map data.
  5458. */
  5459. function getMapData(map, key) {
  5460. var data = map.__data__;
  5461. return isKeyable(key)
  5462. ? data[typeof key == 'string' ? 'string' : 'hash']
  5463. : data.map;
  5464. }
  5465. /**
  5466. * Gets the property names, values, and compare flags of `object`.
  5467. *
  5468. * @private
  5469. * @param {Object} object The object to query.
  5470. * @returns {Array} Returns the match data of `object`.
  5471. */
  5472. function getMatchData(object) {
  5473. var result = keys(object),
  5474. length = result.length;
  5475. while (length--) {
  5476. var key = result[length],
  5477. value = object[key];
  5478. result[length] = [key, value, isStrictComparable(value)];
  5479. }
  5480. return result;
  5481. }
  5482. /**
  5483. * Gets the native function at `key` of `object`.
  5484. *
  5485. * @private
  5486. * @param {Object} object The object to query.
  5487. * @param {string} key The key of the method to get.
  5488. * @returns {*} Returns the function if it's native, else `undefined`.
  5489. */
  5490. function getNative(object, key) {
  5491. var value = getValue(object, key);
  5492. return baseIsNative(value) ? value : undefined;
  5493. }
  5494. /**
  5495. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5496. *
  5497. * @private
  5498. * @param {*} value The value to query.
  5499. * @returns {string} Returns the raw `toStringTag`.
  5500. */
  5501. function getRawTag(value) {
  5502. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5503. tag = value[symToStringTag];
  5504. try {
  5505. value[symToStringTag] = undefined;
  5506. var unmasked = true;
  5507. } catch (e) {}
  5508. var result = nativeObjectToString.call(value);
  5509. if (unmasked) {
  5510. if (isOwn) {
  5511. value[symToStringTag] = tag;
  5512. } else {
  5513. delete value[symToStringTag];
  5514. }
  5515. }
  5516. return result;
  5517. }
  5518. /**
  5519. * Creates an array of the own enumerable symbols of `object`.
  5520. *
  5521. * @private
  5522. * @param {Object} object The object to query.
  5523. * @returns {Array} Returns the array of symbols.
  5524. */
  5525. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5526. if (object == null) {
  5527. return [];
  5528. }
  5529. object = Object(object);
  5530. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5531. return propertyIsEnumerable.call(object, symbol);
  5532. });
  5533. };
  5534. /**
  5535. * Creates an array of the own and inherited enumerable symbols of `object`.
  5536. *
  5537. * @private
  5538. * @param {Object} object The object to query.
  5539. * @returns {Array} Returns the array of symbols.
  5540. */
  5541. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5542. var result = [];
  5543. while (object) {
  5544. arrayPush(result, getSymbols(object));
  5545. object = getPrototype(object);
  5546. }
  5547. return result;
  5548. };
  5549. /**
  5550. * Gets the `toStringTag` of `value`.
  5551. *
  5552. * @private
  5553. * @param {*} value The value to query.
  5554. * @returns {string} Returns the `toStringTag`.
  5555. */
  5556. var getTag = baseGetTag;
  5557. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5558. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5559. (Map && getTag(new Map) != mapTag) ||
  5560. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5561. (Set && getTag(new Set) != setTag) ||
  5562. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5563. getTag = function(value) {
  5564. var result = baseGetTag(value),
  5565. Ctor = result == objectTag ? value.constructor : undefined,
  5566. ctorString = Ctor ? toSource(Ctor) : '';
  5567. if (ctorString) {
  5568. switch (ctorString) {
  5569. case dataViewCtorString: return dataViewTag;
  5570. case mapCtorString: return mapTag;
  5571. case promiseCtorString: return promiseTag;
  5572. case setCtorString: return setTag;
  5573. case weakMapCtorString: return weakMapTag;
  5574. }
  5575. }
  5576. return result;
  5577. };
  5578. }
  5579. /**
  5580. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5581. *
  5582. * @private
  5583. * @param {number} start The start of the view.
  5584. * @param {number} end The end of the view.
  5585. * @param {Array} transforms The transformations to apply to the view.
  5586. * @returns {Object} Returns an object containing the `start` and `end`
  5587. * positions of the view.
  5588. */
  5589. function getView(start, end, transforms) {
  5590. var index = -1,
  5591. length = transforms.length;
  5592. while (++index < length) {
  5593. var data = transforms[index],
  5594. size = data.size;
  5595. switch (data.type) {
  5596. case 'drop': start += size; break;
  5597. case 'dropRight': end -= size; break;
  5598. case 'take': end = nativeMin(end, start + size); break;
  5599. case 'takeRight': start = nativeMax(start, end - size); break;
  5600. }
  5601. }
  5602. return { 'start': start, 'end': end };
  5603. }
  5604. /**
  5605. * Extracts wrapper details from the `source` body comment.
  5606. *
  5607. * @private
  5608. * @param {string} source The source to inspect.
  5609. * @returns {Array} Returns the wrapper details.
  5610. */
  5611. function getWrapDetails(source) {
  5612. var match = source.match(reWrapDetails);
  5613. return match ? match[1].split(reSplitDetails) : [];
  5614. }
  5615. /**
  5616. * Checks if `path` exists on `object`.
  5617. *
  5618. * @private
  5619. * @param {Object} object The object to query.
  5620. * @param {Array|string} path The path to check.
  5621. * @param {Function} hasFunc The function to check properties.
  5622. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5623. */
  5624. function hasPath(object, path, hasFunc) {
  5625. path = castPath(path, object);
  5626. var index = -1,
  5627. length = path.length,
  5628. result = false;
  5629. while (++index < length) {
  5630. var key = toKey(path[index]);
  5631. if (!(result = object != null && hasFunc(object, key))) {
  5632. break;
  5633. }
  5634. object = object[key];
  5635. }
  5636. if (result || ++index != length) {
  5637. return result;
  5638. }
  5639. length = object == null ? 0 : object.length;
  5640. return !!length && isLength(length) && isIndex(key, length) &&
  5641. (isArray(object) || isArguments(object));
  5642. }
  5643. /**
  5644. * Initializes an array clone.
  5645. *
  5646. * @private
  5647. * @param {Array} array The array to clone.
  5648. * @returns {Array} Returns the initialized clone.
  5649. */
  5650. function initCloneArray(array) {
  5651. var length = array.length,
  5652. result = array.constructor(length);
  5653. // Add properties assigned by `RegExp#exec`.
  5654. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5655. result.index = array.index;
  5656. result.input = array.input;
  5657. }
  5658. return result;
  5659. }
  5660. /**
  5661. * Initializes an object clone.
  5662. *
  5663. * @private
  5664. * @param {Object} object The object to clone.
  5665. * @returns {Object} Returns the initialized clone.
  5666. */
  5667. function initCloneObject(object) {
  5668. return (typeof object.constructor == 'function' && !isPrototype(object))
  5669. ? baseCreate(getPrototype(object))
  5670. : {};
  5671. }
  5672. /**
  5673. * Initializes an object clone based on its `toStringTag`.
  5674. *
  5675. * **Note:** This function only supports cloning values with tags of
  5676. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5677. *
  5678. * @private
  5679. * @param {Object} object The object to clone.
  5680. * @param {string} tag The `toStringTag` of the object to clone.
  5681. * @param {Function} cloneFunc The function to clone values.
  5682. * @param {boolean} [isDeep] Specify a deep clone.
  5683. * @returns {Object} Returns the initialized clone.
  5684. */
  5685. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  5686. var Ctor = object.constructor;
  5687. switch (tag) {
  5688. case arrayBufferTag:
  5689. return cloneArrayBuffer(object);
  5690. case boolTag:
  5691. case dateTag:
  5692. return new Ctor(+object);
  5693. case dataViewTag:
  5694. return cloneDataView(object, isDeep);
  5695. case float32Tag: case float64Tag:
  5696. case int8Tag: case int16Tag: case int32Tag:
  5697. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5698. return cloneTypedArray(object, isDeep);
  5699. case mapTag:
  5700. return cloneMap(object, isDeep, cloneFunc);
  5701. case numberTag:
  5702. case stringTag:
  5703. return new Ctor(object);
  5704. case regexpTag:
  5705. return cloneRegExp(object);
  5706. case setTag:
  5707. return cloneSet(object, isDeep, cloneFunc);
  5708. case symbolTag:
  5709. return cloneSymbol(object);
  5710. }
  5711. }
  5712. /**
  5713. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5714. *
  5715. * @private
  5716. * @param {string} source The source to modify.
  5717. * @returns {Array} details The details to insert.
  5718. * @returns {string} Returns the modified source.
  5719. */
  5720. function insertWrapDetails(source, details) {
  5721. var length = details.length;
  5722. if (!length) {
  5723. return source;
  5724. }
  5725. var lastIndex = length - 1;
  5726. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5727. details = details.join(length > 2 ? ', ' : ' ');
  5728. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5729. }
  5730. /**
  5731. * Checks if `value` is a flattenable `arguments` object or array.
  5732. *
  5733. * @private
  5734. * @param {*} value The value to check.
  5735. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5736. */
  5737. function isFlattenable(value) {
  5738. return isArray(value) || isArguments(value) ||
  5739. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5740. }
  5741. /**
  5742. * Checks if `value` is a valid array-like index.
  5743. *
  5744. * @private
  5745. * @param {*} value The value to check.
  5746. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5747. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5748. */
  5749. function isIndex(value, length) {
  5750. length = length == null ? MAX_SAFE_INTEGER : length;
  5751. return !!length &&
  5752. (typeof value == 'number' || reIsUint.test(value)) &&
  5753. (value > -1 && value % 1 == 0 && value < length);
  5754. }
  5755. /**
  5756. * Checks if the given arguments are from an iteratee call.
  5757. *
  5758. * @private
  5759. * @param {*} value The potential iteratee value argument.
  5760. * @param {*} index The potential iteratee index or key argument.
  5761. * @param {*} object The potential iteratee object argument.
  5762. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5763. * else `false`.
  5764. */
  5765. function isIterateeCall(value, index, object) {
  5766. if (!isObject(object)) {
  5767. return false;
  5768. }
  5769. var type = typeof index;
  5770. if (type == 'number'
  5771. ? (isArrayLike(object) && isIndex(index, object.length))
  5772. : (type == 'string' && index in object)
  5773. ) {
  5774. return eq(object[index], value);
  5775. }
  5776. return false;
  5777. }
  5778. /**
  5779. * Checks if `value` is a property name and not a property path.
  5780. *
  5781. * @private
  5782. * @param {*} value The value to check.
  5783. * @param {Object} [object] The object to query keys on.
  5784. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5785. */
  5786. function isKey(value, object) {
  5787. if (isArray(value)) {
  5788. return false;
  5789. }
  5790. var type = typeof value;
  5791. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5792. value == null || isSymbol(value)) {
  5793. return true;
  5794. }
  5795. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5796. (object != null && value in Object(object));
  5797. }
  5798. /**
  5799. * Checks if `value` is suitable for use as unique object key.
  5800. *
  5801. * @private
  5802. * @param {*} value The value to check.
  5803. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5804. */
  5805. function isKeyable(value) {
  5806. var type = typeof value;
  5807. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5808. ? (value !== '__proto__')
  5809. : (value === null);
  5810. }
  5811. /**
  5812. * Checks if `func` has a lazy counterpart.
  5813. *
  5814. * @private
  5815. * @param {Function} func The function to check.
  5816. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5817. * else `false`.
  5818. */
  5819. function isLaziable(func) {
  5820. var funcName = getFuncName(func),
  5821. other = lodash[funcName];
  5822. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5823. return false;
  5824. }
  5825. if (func === other) {
  5826. return true;
  5827. }
  5828. var data = getData(other);
  5829. return !!data && func === data[0];
  5830. }
  5831. /**
  5832. * Checks if `func` has its source masked.
  5833. *
  5834. * @private
  5835. * @param {Function} func The function to check.
  5836. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5837. */
  5838. function isMasked(func) {
  5839. return !!maskSrcKey && (maskSrcKey in func);
  5840. }
  5841. /**
  5842. * Checks if `func` is capable of being masked.
  5843. *
  5844. * @private
  5845. * @param {*} value The value to check.
  5846. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5847. */
  5848. var isMaskable = coreJsData ? isFunction : stubFalse;
  5849. /**
  5850. * Checks if `value` is likely a prototype object.
  5851. *
  5852. * @private
  5853. * @param {*} value The value to check.
  5854. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5855. */
  5856. function isPrototype(value) {
  5857. var Ctor = value && value.constructor,
  5858. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5859. return value === proto;
  5860. }
  5861. /**
  5862. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5863. *
  5864. * @private
  5865. * @param {*} value The value to check.
  5866. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5867. * equality comparisons, else `false`.
  5868. */
  5869. function isStrictComparable(value) {
  5870. return value === value && !isObject(value);
  5871. }
  5872. /**
  5873. * A specialized version of `matchesProperty` for source values suitable
  5874. * for strict equality comparisons, i.e. `===`.
  5875. *
  5876. * @private
  5877. * @param {string} key The key of the property to get.
  5878. * @param {*} srcValue The value to match.
  5879. * @returns {Function} Returns the new spec function.
  5880. */
  5881. function matchesStrictComparable(key, srcValue) {
  5882. return function(object) {
  5883. if (object == null) {
  5884. return false;
  5885. }
  5886. return object[key] === srcValue &&
  5887. (srcValue !== undefined || (key in Object(object)));
  5888. };
  5889. }
  5890. /**
  5891. * A specialized version of `_.memoize` which clears the memoized function's
  5892. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5893. *
  5894. * @private
  5895. * @param {Function} func The function to have its output memoized.
  5896. * @returns {Function} Returns the new memoized function.
  5897. */
  5898. function memoizeCapped(func) {
  5899. var result = memoize(func, function(key) {
  5900. if (cache.size === MAX_MEMOIZE_SIZE) {
  5901. cache.clear();
  5902. }
  5903. return key;
  5904. });
  5905. var cache = result.cache;
  5906. return result;
  5907. }
  5908. /**
  5909. * Merges the function metadata of `source` into `data`.
  5910. *
  5911. * Merging metadata reduces the number of wrappers used to invoke a function.
  5912. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5913. * may be applied regardless of execution order. Methods like `_.ary` and
  5914. * `_.rearg` modify function arguments, making the order in which they are
  5915. * executed important, preventing the merging of metadata. However, we make
  5916. * an exception for a safe combined case where curried functions have `_.ary`
  5917. * and or `_.rearg` applied.
  5918. *
  5919. * @private
  5920. * @param {Array} data The destination metadata.
  5921. * @param {Array} source The source metadata.
  5922. * @returns {Array} Returns `data`.
  5923. */
  5924. function mergeData(data, source) {
  5925. var bitmask = data[1],
  5926. srcBitmask = source[1],
  5927. newBitmask = bitmask | srcBitmask,
  5928. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5929. var isCombo =
  5930. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5931. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5932. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5933. // Exit early if metadata can't be merged.
  5934. if (!(isCommon || isCombo)) {
  5935. return data;
  5936. }
  5937. // Use source `thisArg` if available.
  5938. if (srcBitmask & WRAP_BIND_FLAG) {
  5939. data[2] = source[2];
  5940. // Set when currying a bound function.
  5941. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5942. }
  5943. // Compose partial arguments.
  5944. var value = source[3];
  5945. if (value) {
  5946. var partials = data[3];
  5947. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5948. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5949. }
  5950. // Compose partial right arguments.
  5951. value = source[5];
  5952. if (value) {
  5953. partials = data[5];
  5954. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5955. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5956. }
  5957. // Use source `argPos` if available.
  5958. value = source[7];
  5959. if (value) {
  5960. data[7] = value;
  5961. }
  5962. // Use source `ary` if it's smaller.
  5963. if (srcBitmask & WRAP_ARY_FLAG) {
  5964. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5965. }
  5966. // Use source `arity` if one is not provided.
  5967. if (data[9] == null) {
  5968. data[9] = source[9];
  5969. }
  5970. // Use source `func` and merge bitmasks.
  5971. data[0] = source[0];
  5972. data[1] = newBitmask;
  5973. return data;
  5974. }
  5975. /**
  5976. * This function is like
  5977. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5978. * except that it includes inherited enumerable properties.
  5979. *
  5980. * @private
  5981. * @param {Object} object The object to query.
  5982. * @returns {Array} Returns the array of property names.
  5983. */
  5984. function nativeKeysIn(object) {
  5985. var result = [];
  5986. if (object != null) {
  5987. for (var key in Object(object)) {
  5988. result.push(key);
  5989. }
  5990. }
  5991. return result;
  5992. }
  5993. /**
  5994. * Converts `value` to a string using `Object.prototype.toString`.
  5995. *
  5996. * @private
  5997. * @param {*} value The value to convert.
  5998. * @returns {string} Returns the converted string.
  5999. */
  6000. function objectToString(value) {
  6001. return nativeObjectToString.call(value);
  6002. }
  6003. /**
  6004. * A specialized version of `baseRest` which transforms the rest array.
  6005. *
  6006. * @private
  6007. * @param {Function} func The function to apply a rest parameter to.
  6008. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6009. * @param {Function} transform The rest array transform.
  6010. * @returns {Function} Returns the new function.
  6011. */
  6012. function overRest(func, start, transform) {
  6013. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6014. return function() {
  6015. var args = arguments,
  6016. index = -1,
  6017. length = nativeMax(args.length - start, 0),
  6018. array = Array(length);
  6019. while (++index < length) {
  6020. array[index] = args[start + index];
  6021. }
  6022. index = -1;
  6023. var otherArgs = Array(start + 1);
  6024. while (++index < start) {
  6025. otherArgs[index] = args[index];
  6026. }
  6027. otherArgs[start] = transform(array);
  6028. return apply(func, this, otherArgs);
  6029. };
  6030. }
  6031. /**
  6032. * Gets the parent value at `path` of `object`.
  6033. *
  6034. * @private
  6035. * @param {Object} object The object to query.
  6036. * @param {Array} path The path to get the parent value of.
  6037. * @returns {*} Returns the parent value.
  6038. */
  6039. function parent(object, path) {
  6040. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6041. }
  6042. /**
  6043. * Reorder `array` according to the specified indexes where the element at
  6044. * the first index is assigned as the first element, the element at
  6045. * the second index is assigned as the second element, and so on.
  6046. *
  6047. * @private
  6048. * @param {Array} array The array to reorder.
  6049. * @param {Array} indexes The arranged array indexes.
  6050. * @returns {Array} Returns `array`.
  6051. */
  6052. function reorder(array, indexes) {
  6053. var arrLength = array.length,
  6054. length = nativeMin(indexes.length, arrLength),
  6055. oldArray = copyArray(array);
  6056. while (length--) {
  6057. var index = indexes[length];
  6058. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6059. }
  6060. return array;
  6061. }
  6062. /**
  6063. * Sets metadata for `func`.
  6064. *
  6065. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6066. * period of time, it will trip its breaker and transition to an identity
  6067. * function to avoid garbage collection pauses in V8. See
  6068. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6069. * for more details.
  6070. *
  6071. * @private
  6072. * @param {Function} func The function to associate metadata with.
  6073. * @param {*} data The metadata.
  6074. * @returns {Function} Returns `func`.
  6075. */
  6076. var setData = shortOut(baseSetData);
  6077. /**
  6078. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6079. *
  6080. * @private
  6081. * @param {Function} func The function to delay.
  6082. * @param {number} wait The number of milliseconds to delay invocation.
  6083. * @returns {number|Object} Returns the timer id or timeout object.
  6084. */
  6085. var setTimeout = ctxSetTimeout || function(func, wait) {
  6086. return root.setTimeout(func, wait);
  6087. };
  6088. /**
  6089. * Sets the `toString` method of `func` to return `string`.
  6090. *
  6091. * @private
  6092. * @param {Function} func The function to modify.
  6093. * @param {Function} string The `toString` result.
  6094. * @returns {Function} Returns `func`.
  6095. */
  6096. var setToString = shortOut(baseSetToString);
  6097. /**
  6098. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6099. * with wrapper details in a comment at the top of the source body.
  6100. *
  6101. * @private
  6102. * @param {Function} wrapper The function to modify.
  6103. * @param {Function} reference The reference function.
  6104. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6105. * @returns {Function} Returns `wrapper`.
  6106. */
  6107. function setWrapToString(wrapper, reference, bitmask) {
  6108. var source = (reference + '');
  6109. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6110. }
  6111. /**
  6112. * Creates a function that'll short out and invoke `identity` instead
  6113. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6114. * milliseconds.
  6115. *
  6116. * @private
  6117. * @param {Function} func The function to restrict.
  6118. * @returns {Function} Returns the new shortable function.
  6119. */
  6120. function shortOut(func) {
  6121. var count = 0,
  6122. lastCalled = 0;
  6123. return function() {
  6124. var stamp = nativeNow(),
  6125. remaining = HOT_SPAN - (stamp - lastCalled);
  6126. lastCalled = stamp;
  6127. if (remaining > 0) {
  6128. if (++count >= HOT_COUNT) {
  6129. return arguments[0];
  6130. }
  6131. } else {
  6132. count = 0;
  6133. }
  6134. return func.apply(undefined, arguments);
  6135. };
  6136. }
  6137. /**
  6138. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6139. *
  6140. * @private
  6141. * @param {Array} array The array to shuffle.
  6142. * @param {number} [size=array.length] The size of `array`.
  6143. * @returns {Array} Returns `array`.
  6144. */
  6145. function shuffleSelf(array, size) {
  6146. var index = -1,
  6147. length = array.length,
  6148. lastIndex = length - 1;
  6149. size = size === undefined ? length : size;
  6150. while (++index < size) {
  6151. var rand = baseRandom(index, lastIndex),
  6152. value = array[rand];
  6153. array[rand] = array[index];
  6154. array[index] = value;
  6155. }
  6156. array.length = size;
  6157. return array;
  6158. }
  6159. /**
  6160. * Converts `string` to a property path array.
  6161. *
  6162. * @private
  6163. * @param {string} string The string to convert.
  6164. * @returns {Array} Returns the property path array.
  6165. */
  6166. var stringToPath = memoizeCapped(function(string) {
  6167. var result = [];
  6168. if (reLeadingDot.test(string)) {
  6169. result.push('');
  6170. }
  6171. string.replace(rePropName, function(match, number, quote, string) {
  6172. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  6173. });
  6174. return result;
  6175. });
  6176. /**
  6177. * Converts `value` to a string key if it's not a string or symbol.
  6178. *
  6179. * @private
  6180. * @param {*} value The value to inspect.
  6181. * @returns {string|symbol} Returns the key.
  6182. */
  6183. function toKey(value) {
  6184. if (typeof value == 'string' || isSymbol(value)) {
  6185. return value;
  6186. }
  6187. var result = (value + '');
  6188. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6189. }
  6190. /**
  6191. * Converts `func` to its source code.
  6192. *
  6193. * @private
  6194. * @param {Function} func The function to convert.
  6195. * @returns {string} Returns the source code.
  6196. */
  6197. function toSource(func) {
  6198. if (func != null) {
  6199. try {
  6200. return funcToString.call(func);
  6201. } catch (e) {}
  6202. try {
  6203. return (func + '');
  6204. } catch (e) {}
  6205. }
  6206. return '';
  6207. }
  6208. /**
  6209. * Updates wrapper `details` based on `bitmask` flags.
  6210. *
  6211. * @private
  6212. * @returns {Array} details The details to modify.
  6213. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6214. * @returns {Array} Returns `details`.
  6215. */
  6216. function updateWrapDetails(details, bitmask) {
  6217. arrayEach(wrapFlags, function(pair) {
  6218. var value = '_.' + pair[0];
  6219. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6220. details.push(value);
  6221. }
  6222. });
  6223. return details.sort();
  6224. }
  6225. /**
  6226. * Creates a clone of `wrapper`.
  6227. *
  6228. * @private
  6229. * @param {Object} wrapper The wrapper to clone.
  6230. * @returns {Object} Returns the cloned wrapper.
  6231. */
  6232. function wrapperClone(wrapper) {
  6233. if (wrapper instanceof LazyWrapper) {
  6234. return wrapper.clone();
  6235. }
  6236. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6237. result.__actions__ = copyArray(wrapper.__actions__);
  6238. result.__index__ = wrapper.__index__;
  6239. result.__values__ = wrapper.__values__;
  6240. return result;
  6241. }
  6242. /*------------------------------------------------------------------------*/
  6243. /**
  6244. * Creates an array of elements split into groups the length of `size`.
  6245. * If `array` can't be split evenly, the final chunk will be the remaining
  6246. * elements.
  6247. *
  6248. * @static
  6249. * @memberOf _
  6250. * @since 3.0.0
  6251. * @category Array
  6252. * @param {Array} array The array to process.
  6253. * @param {number} [size=1] The length of each chunk
  6254. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6255. * @returns {Array} Returns the new array of chunks.
  6256. * @example
  6257. *
  6258. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6259. * // => [['a', 'b'], ['c', 'd']]
  6260. *
  6261. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6262. * // => [['a', 'b', 'c'], ['d']]
  6263. */
  6264. function chunk(array, size, guard) {
  6265. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6266. size = 1;
  6267. } else {
  6268. size = nativeMax(toInteger(size), 0);
  6269. }
  6270. var length = array == null ? 0 : array.length;
  6271. if (!length || size < 1) {
  6272. return [];
  6273. }
  6274. var index = 0,
  6275. resIndex = 0,
  6276. result = Array(nativeCeil(length / size));
  6277. while (index < length) {
  6278. result[resIndex++] = baseSlice(array, index, (index += size));
  6279. }
  6280. return result;
  6281. }
  6282. /**
  6283. * Creates an array with all falsey values removed. The values `false`, `null`,
  6284. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6285. *
  6286. * @static
  6287. * @memberOf _
  6288. * @since 0.1.0
  6289. * @category Array
  6290. * @param {Array} array The array to compact.
  6291. * @returns {Array} Returns the new array of filtered values.
  6292. * @example
  6293. *
  6294. * _.compact([0, 1, false, 2, '', 3]);
  6295. * // => [1, 2, 3]
  6296. */
  6297. function compact(array) {
  6298. var index = -1,
  6299. length = array == null ? 0 : array.length,
  6300. resIndex = 0,
  6301. result = [];
  6302. while (++index < length) {
  6303. var value = array[index];
  6304. if (value) {
  6305. result[resIndex++] = value;
  6306. }
  6307. }
  6308. return result;
  6309. }
  6310. /**
  6311. * Creates a new array concatenating `array` with any additional arrays
  6312. * and/or values.
  6313. *
  6314. * @static
  6315. * @memberOf _
  6316. * @since 4.0.0
  6317. * @category Array
  6318. * @param {Array} array The array to concatenate.
  6319. * @param {...*} [values] The values to concatenate.
  6320. * @returns {Array} Returns the new concatenated array.
  6321. * @example
  6322. *
  6323. * var array = [1];
  6324. * var other = _.concat(array, 2, [3], [[4]]);
  6325. *
  6326. * console.log(other);
  6327. * // => [1, 2, 3, [4]]
  6328. *
  6329. * console.log(array);
  6330. * // => [1]
  6331. */
  6332. function concat() {
  6333. var length = arguments.length;
  6334. if (!length) {
  6335. return [];
  6336. }
  6337. var args = Array(length - 1),
  6338. array = arguments[0],
  6339. index = length;
  6340. while (index--) {
  6341. args[index - 1] = arguments[index];
  6342. }
  6343. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6344. }
  6345. /**
  6346. * Creates an array of `array` values not included in the other given arrays
  6347. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6348. * for equality comparisons. The order and references of result values are
  6349. * determined by the first array.
  6350. *
  6351. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6352. *
  6353. * @static
  6354. * @memberOf _
  6355. * @since 0.1.0
  6356. * @category Array
  6357. * @param {Array} array The array to inspect.
  6358. * @param {...Array} [values] The values to exclude.
  6359. * @returns {Array} Returns the new array of filtered values.
  6360. * @see _.without, _.xor
  6361. * @example
  6362. *
  6363. * _.difference([2, 1], [2, 3]);
  6364. * // => [1]
  6365. */
  6366. var difference = baseRest(function(array, values) {
  6367. return isArrayLikeObject(array)
  6368. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6369. : [];
  6370. });
  6371. /**
  6372. * This method is like `_.difference` except that it accepts `iteratee` which
  6373. * is invoked for each element of `array` and `values` to generate the criterion
  6374. * by which they're compared. The order and references of result values are
  6375. * determined by the first array. The iteratee is invoked with one argument:
  6376. * (value).
  6377. *
  6378. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6379. *
  6380. * @static
  6381. * @memberOf _
  6382. * @since 4.0.0
  6383. * @category Array
  6384. * @param {Array} array The array to inspect.
  6385. * @param {...Array} [values] The values to exclude.
  6386. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6387. * @returns {Array} Returns the new array of filtered values.
  6388. * @example
  6389. *
  6390. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6391. * // => [1.2]
  6392. *
  6393. * // The `_.property` iteratee shorthand.
  6394. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6395. * // => [{ 'x': 2 }]
  6396. */
  6397. var differenceBy = baseRest(function(array, values) {
  6398. var iteratee = last(values);
  6399. if (isArrayLikeObject(iteratee)) {
  6400. iteratee = undefined;
  6401. }
  6402. return isArrayLikeObject(array)
  6403. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6404. : [];
  6405. });
  6406. /**
  6407. * This method is like `_.difference` except that it accepts `comparator`
  6408. * which is invoked to compare elements of `array` to `values`. The order and
  6409. * references of result values are determined by the first array. The comparator
  6410. * is invoked with two arguments: (arrVal, othVal).
  6411. *
  6412. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6413. *
  6414. * @static
  6415. * @memberOf _
  6416. * @since 4.0.0
  6417. * @category Array
  6418. * @param {Array} array The array to inspect.
  6419. * @param {...Array} [values] The values to exclude.
  6420. * @param {Function} [comparator] The comparator invoked per element.
  6421. * @returns {Array} Returns the new array of filtered values.
  6422. * @example
  6423. *
  6424. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6425. *
  6426. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6427. * // => [{ 'x': 2, 'y': 1 }]
  6428. */
  6429. var differenceWith = baseRest(function(array, values) {
  6430. var comparator = last(values);
  6431. if (isArrayLikeObject(comparator)) {
  6432. comparator = undefined;
  6433. }
  6434. return isArrayLikeObject(array)
  6435. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6436. : [];
  6437. });
  6438. /**
  6439. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6440. *
  6441. * @static
  6442. * @memberOf _
  6443. * @since 0.5.0
  6444. * @category Array
  6445. * @param {Array} array The array to query.
  6446. * @param {number} [n=1] The number of elements to drop.
  6447. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6448. * @returns {Array} Returns the slice of `array`.
  6449. * @example
  6450. *
  6451. * _.drop([1, 2, 3]);
  6452. * // => [2, 3]
  6453. *
  6454. * _.drop([1, 2, 3], 2);
  6455. * // => [3]
  6456. *
  6457. * _.drop([1, 2, 3], 5);
  6458. * // => []
  6459. *
  6460. * _.drop([1, 2, 3], 0);
  6461. * // => [1, 2, 3]
  6462. */
  6463. function drop(array, n, guard) {
  6464. var length = array == null ? 0 : array.length;
  6465. if (!length) {
  6466. return [];
  6467. }
  6468. n = (guard || n === undefined) ? 1 : toInteger(n);
  6469. return baseSlice(array, n < 0 ? 0 : n, length);
  6470. }
  6471. /**
  6472. * Creates a slice of `array` with `n` elements dropped from the end.
  6473. *
  6474. * @static
  6475. * @memberOf _
  6476. * @since 3.0.0
  6477. * @category Array
  6478. * @param {Array} array The array to query.
  6479. * @param {number} [n=1] The number of elements to drop.
  6480. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6481. * @returns {Array} Returns the slice of `array`.
  6482. * @example
  6483. *
  6484. * _.dropRight([1, 2, 3]);
  6485. * // => [1, 2]
  6486. *
  6487. * _.dropRight([1, 2, 3], 2);
  6488. * // => [1]
  6489. *
  6490. * _.dropRight([1, 2, 3], 5);
  6491. * // => []
  6492. *
  6493. * _.dropRight([1, 2, 3], 0);
  6494. * // => [1, 2, 3]
  6495. */
  6496. function dropRight(array, n, guard) {
  6497. var length = array == null ? 0 : array.length;
  6498. if (!length) {
  6499. return [];
  6500. }
  6501. n = (guard || n === undefined) ? 1 : toInteger(n);
  6502. n = length - n;
  6503. return baseSlice(array, 0, n < 0 ? 0 : n);
  6504. }
  6505. /**
  6506. * Creates a slice of `array` excluding elements dropped from the end.
  6507. * Elements are dropped until `predicate` returns falsey. The predicate is
  6508. * invoked with three arguments: (value, index, array).
  6509. *
  6510. * @static
  6511. * @memberOf _
  6512. * @since 3.0.0
  6513. * @category Array
  6514. * @param {Array} array The array to query.
  6515. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6516. * @returns {Array} Returns the slice of `array`.
  6517. * @example
  6518. *
  6519. * var users = [
  6520. * { 'user': 'barney', 'active': true },
  6521. * { 'user': 'fred', 'active': false },
  6522. * { 'user': 'pebbles', 'active': false }
  6523. * ];
  6524. *
  6525. * _.dropRightWhile(users, function(o) { return !o.active; });
  6526. * // => objects for ['barney']
  6527. *
  6528. * // The `_.matches` iteratee shorthand.
  6529. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6530. * // => objects for ['barney', 'fred']
  6531. *
  6532. * // The `_.matchesProperty` iteratee shorthand.
  6533. * _.dropRightWhile(users, ['active', false]);
  6534. * // => objects for ['barney']
  6535. *
  6536. * // The `_.property` iteratee shorthand.
  6537. * _.dropRightWhile(users, 'active');
  6538. * // => objects for ['barney', 'fred', 'pebbles']
  6539. */
  6540. function dropRightWhile(array, predicate) {
  6541. return (array && array.length)
  6542. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6543. : [];
  6544. }
  6545. /**
  6546. * Creates a slice of `array` excluding elements dropped from the beginning.
  6547. * Elements are dropped until `predicate` returns falsey. The predicate is
  6548. * invoked with three arguments: (value, index, array).
  6549. *
  6550. * @static
  6551. * @memberOf _
  6552. * @since 3.0.0
  6553. * @category Array
  6554. * @param {Array} array The array to query.
  6555. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6556. * @returns {Array} Returns the slice of `array`.
  6557. * @example
  6558. *
  6559. * var users = [
  6560. * { 'user': 'barney', 'active': false },
  6561. * { 'user': 'fred', 'active': false },
  6562. * { 'user': 'pebbles', 'active': true }
  6563. * ];
  6564. *
  6565. * _.dropWhile(users, function(o) { return !o.active; });
  6566. * // => objects for ['pebbles']
  6567. *
  6568. * // The `_.matches` iteratee shorthand.
  6569. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6570. * // => objects for ['fred', 'pebbles']
  6571. *
  6572. * // The `_.matchesProperty` iteratee shorthand.
  6573. * _.dropWhile(users, ['active', false]);
  6574. * // => objects for ['pebbles']
  6575. *
  6576. * // The `_.property` iteratee shorthand.
  6577. * _.dropWhile(users, 'active');
  6578. * // => objects for ['barney', 'fred', 'pebbles']
  6579. */
  6580. function dropWhile(array, predicate) {
  6581. return (array && array.length)
  6582. ? baseWhile(array, getIteratee(predicate, 3), true)
  6583. : [];
  6584. }
  6585. /**
  6586. * Fills elements of `array` with `value` from `start` up to, but not
  6587. * including, `end`.
  6588. *
  6589. * **Note:** This method mutates `array`.
  6590. *
  6591. * @static
  6592. * @memberOf _
  6593. * @since 3.2.0
  6594. * @category Array
  6595. * @param {Array} array The array to fill.
  6596. * @param {*} value The value to fill `array` with.
  6597. * @param {number} [start=0] The start position.
  6598. * @param {number} [end=array.length] The end position.
  6599. * @returns {Array} Returns `array`.
  6600. * @example
  6601. *
  6602. * var array = [1, 2, 3];
  6603. *
  6604. * _.fill(array, 'a');
  6605. * console.log(array);
  6606. * // => ['a', 'a', 'a']
  6607. *
  6608. * _.fill(Array(3), 2);
  6609. * // => [2, 2, 2]
  6610. *
  6611. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6612. * // => [4, '*', '*', 10]
  6613. */
  6614. function fill(array, value, start, end) {
  6615. var length = array == null ? 0 : array.length;
  6616. if (!length) {
  6617. return [];
  6618. }
  6619. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6620. start = 0;
  6621. end = length;
  6622. }
  6623. return baseFill(array, value, start, end);
  6624. }
  6625. /**
  6626. * This method is like `_.find` except that it returns the index of the first
  6627. * element `predicate` returns truthy for instead of the element itself.
  6628. *
  6629. * @static
  6630. * @memberOf _
  6631. * @since 1.1.0
  6632. * @category Array
  6633. * @param {Array} array The array to inspect.
  6634. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6635. * @param {number} [fromIndex=0] The index to search from.
  6636. * @returns {number} Returns the index of the found element, else `-1`.
  6637. * @example
  6638. *
  6639. * var users = [
  6640. * { 'user': 'barney', 'active': false },
  6641. * { 'user': 'fred', 'active': false },
  6642. * { 'user': 'pebbles', 'active': true }
  6643. * ];
  6644. *
  6645. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6646. * // => 0
  6647. *
  6648. * // The `_.matches` iteratee shorthand.
  6649. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6650. * // => 1
  6651. *
  6652. * // The `_.matchesProperty` iteratee shorthand.
  6653. * _.findIndex(users, ['active', false]);
  6654. * // => 0
  6655. *
  6656. * // The `_.property` iteratee shorthand.
  6657. * _.findIndex(users, 'active');
  6658. * // => 2
  6659. */
  6660. function findIndex(array, predicate, fromIndex) {
  6661. var length = array == null ? 0 : array.length;
  6662. if (!length) {
  6663. return -1;
  6664. }
  6665. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6666. if (index < 0) {
  6667. index = nativeMax(length + index, 0);
  6668. }
  6669. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6670. }
  6671. /**
  6672. * This method is like `_.findIndex` except that it iterates over elements
  6673. * of `collection` from right to left.
  6674. *
  6675. * @static
  6676. * @memberOf _
  6677. * @since 2.0.0
  6678. * @category Array
  6679. * @param {Array} array The array to inspect.
  6680. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6681. * @param {number} [fromIndex=array.length-1] The index to search from.
  6682. * @returns {number} Returns the index of the found element, else `-1`.
  6683. * @example
  6684. *
  6685. * var users = [
  6686. * { 'user': 'barney', 'active': true },
  6687. * { 'user': 'fred', 'active': false },
  6688. * { 'user': 'pebbles', 'active': false }
  6689. * ];
  6690. *
  6691. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6692. * // => 2
  6693. *
  6694. * // The `_.matches` iteratee shorthand.
  6695. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6696. * // => 0
  6697. *
  6698. * // The `_.matchesProperty` iteratee shorthand.
  6699. * _.findLastIndex(users, ['active', false]);
  6700. * // => 2
  6701. *
  6702. * // The `_.property` iteratee shorthand.
  6703. * _.findLastIndex(users, 'active');
  6704. * // => 0
  6705. */
  6706. function findLastIndex(array, predicate, fromIndex) {
  6707. var length = array == null ? 0 : array.length;
  6708. if (!length) {
  6709. return -1;
  6710. }
  6711. var index = length - 1;
  6712. if (fromIndex !== undefined) {
  6713. index = toInteger(fromIndex);
  6714. index = fromIndex < 0
  6715. ? nativeMax(length + index, 0)
  6716. : nativeMin(index, length - 1);
  6717. }
  6718. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6719. }
  6720. /**
  6721. * Flattens `array` a single level deep.
  6722. *
  6723. * @static
  6724. * @memberOf _
  6725. * @since 0.1.0
  6726. * @category Array
  6727. * @param {Array} array The array to flatten.
  6728. * @returns {Array} Returns the new flattened array.
  6729. * @example
  6730. *
  6731. * _.flatten([1, [2, [3, [4]], 5]]);
  6732. * // => [1, 2, [3, [4]], 5]
  6733. */
  6734. function flatten(array) {
  6735. var length = array == null ? 0 : array.length;
  6736. return length ? baseFlatten(array, 1) : [];
  6737. }
  6738. /**
  6739. * Recursively flattens `array`.
  6740. *
  6741. * @static
  6742. * @memberOf _
  6743. * @since 3.0.0
  6744. * @category Array
  6745. * @param {Array} array The array to flatten.
  6746. * @returns {Array} Returns the new flattened array.
  6747. * @example
  6748. *
  6749. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6750. * // => [1, 2, 3, 4, 5]
  6751. */
  6752. function flattenDeep(array) {
  6753. var length = array == null ? 0 : array.length;
  6754. return length ? baseFlatten(array, INFINITY) : [];
  6755. }
  6756. /**
  6757. * Recursively flatten `array` up to `depth` times.
  6758. *
  6759. * @static
  6760. * @memberOf _
  6761. * @since 4.4.0
  6762. * @category Array
  6763. * @param {Array} array The array to flatten.
  6764. * @param {number} [depth=1] The maximum recursion depth.
  6765. * @returns {Array} Returns the new flattened array.
  6766. * @example
  6767. *
  6768. * var array = [1, [2, [3, [4]], 5]];
  6769. *
  6770. * _.flattenDepth(array, 1);
  6771. * // => [1, 2, [3, [4]], 5]
  6772. *
  6773. * _.flattenDepth(array, 2);
  6774. * // => [1, 2, 3, [4], 5]
  6775. */
  6776. function flattenDepth(array, depth) {
  6777. var length = array == null ? 0 : array.length;
  6778. if (!length) {
  6779. return [];
  6780. }
  6781. depth = depth === undefined ? 1 : toInteger(depth);
  6782. return baseFlatten(array, depth);
  6783. }
  6784. /**
  6785. * The inverse of `_.toPairs`; this method returns an object composed
  6786. * from key-value `pairs`.
  6787. *
  6788. * @static
  6789. * @memberOf _
  6790. * @since 4.0.0
  6791. * @category Array
  6792. * @param {Array} pairs The key-value pairs.
  6793. * @returns {Object} Returns the new object.
  6794. * @example
  6795. *
  6796. * _.fromPairs([['a', 1], ['b', 2]]);
  6797. * // => { 'a': 1, 'b': 2 }
  6798. */
  6799. function fromPairs(pairs) {
  6800. var index = -1,
  6801. length = pairs == null ? 0 : pairs.length,
  6802. result = {};
  6803. while (++index < length) {
  6804. var pair = pairs[index];
  6805. result[pair[0]] = pair[1];
  6806. }
  6807. return result;
  6808. }
  6809. /**
  6810. * Gets the first element of `array`.
  6811. *
  6812. * @static
  6813. * @memberOf _
  6814. * @since 0.1.0
  6815. * @alias first
  6816. * @category Array
  6817. * @param {Array} array The array to query.
  6818. * @returns {*} Returns the first element of `array`.
  6819. * @example
  6820. *
  6821. * _.head([1, 2, 3]);
  6822. * // => 1
  6823. *
  6824. * _.head([]);
  6825. * // => undefined
  6826. */
  6827. function head(array) {
  6828. return (array && array.length) ? array[0] : undefined;
  6829. }
  6830. /**
  6831. * Gets the index at which the first occurrence of `value` is found in `array`
  6832. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6833. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6834. * offset from the end of `array`.
  6835. *
  6836. * @static
  6837. * @memberOf _
  6838. * @since 0.1.0
  6839. * @category Array
  6840. * @param {Array} array The array to inspect.
  6841. * @param {*} value The value to search for.
  6842. * @param {number} [fromIndex=0] The index to search from.
  6843. * @returns {number} Returns the index of the matched value, else `-1`.
  6844. * @example
  6845. *
  6846. * _.indexOf([1, 2, 1, 2], 2);
  6847. * // => 1
  6848. *
  6849. * // Search from the `fromIndex`.
  6850. * _.indexOf([1, 2, 1, 2], 2, 2);
  6851. * // => 3
  6852. */
  6853. function indexOf(array, value, fromIndex) {
  6854. var length = array == null ? 0 : array.length;
  6855. if (!length) {
  6856. return -1;
  6857. }
  6858. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6859. if (index < 0) {
  6860. index = nativeMax(length + index, 0);
  6861. }
  6862. return baseIndexOf(array, value, index);
  6863. }
  6864. /**
  6865. * Gets all but the last element of `array`.
  6866. *
  6867. * @static
  6868. * @memberOf _
  6869. * @since 0.1.0
  6870. * @category Array
  6871. * @param {Array} array The array to query.
  6872. * @returns {Array} Returns the slice of `array`.
  6873. * @example
  6874. *
  6875. * _.initial([1, 2, 3]);
  6876. * // => [1, 2]
  6877. */
  6878. function initial(array) {
  6879. var length = array == null ? 0 : array.length;
  6880. return length ? baseSlice(array, 0, -1) : [];
  6881. }
  6882. /**
  6883. * Creates an array of unique values that are included in all given arrays
  6884. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6885. * for equality comparisons. The order and references of result values are
  6886. * determined by the first array.
  6887. *
  6888. * @static
  6889. * @memberOf _
  6890. * @since 0.1.0
  6891. * @category Array
  6892. * @param {...Array} [arrays] The arrays to inspect.
  6893. * @returns {Array} Returns the new array of intersecting values.
  6894. * @example
  6895. *
  6896. * _.intersection([2, 1], [2, 3]);
  6897. * // => [2]
  6898. */
  6899. var intersection = baseRest(function(arrays) {
  6900. var mapped = arrayMap(arrays, castArrayLikeObject);
  6901. return (mapped.length && mapped[0] === arrays[0])
  6902. ? baseIntersection(mapped)
  6903. : [];
  6904. });
  6905. /**
  6906. * This method is like `_.intersection` except that it accepts `iteratee`
  6907. * which is invoked for each element of each `arrays` to generate the criterion
  6908. * by which they're compared. The order and references of result values are
  6909. * determined by the first array. The iteratee is invoked with one argument:
  6910. * (value).
  6911. *
  6912. * @static
  6913. * @memberOf _
  6914. * @since 4.0.0
  6915. * @category Array
  6916. * @param {...Array} [arrays] The arrays to inspect.
  6917. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6918. * @returns {Array} Returns the new array of intersecting values.
  6919. * @example
  6920. *
  6921. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6922. * // => [2.1]
  6923. *
  6924. * // The `_.property` iteratee shorthand.
  6925. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6926. * // => [{ 'x': 1 }]
  6927. */
  6928. var intersectionBy = baseRest(function(arrays) {
  6929. var iteratee = last(arrays),
  6930. mapped = arrayMap(arrays, castArrayLikeObject);
  6931. if (iteratee === last(mapped)) {
  6932. iteratee = undefined;
  6933. } else {
  6934. mapped.pop();
  6935. }
  6936. return (mapped.length && mapped[0] === arrays[0])
  6937. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6938. : [];
  6939. });
  6940. /**
  6941. * This method is like `_.intersection` except that it accepts `comparator`
  6942. * which is invoked to compare elements of `arrays`. The order and references
  6943. * of result values are determined by the first array. The comparator is
  6944. * invoked with two arguments: (arrVal, othVal).
  6945. *
  6946. * @static
  6947. * @memberOf _
  6948. * @since 4.0.0
  6949. * @category Array
  6950. * @param {...Array} [arrays] The arrays to inspect.
  6951. * @param {Function} [comparator] The comparator invoked per element.
  6952. * @returns {Array} Returns the new array of intersecting values.
  6953. * @example
  6954. *
  6955. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6956. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6957. *
  6958. * _.intersectionWith(objects, others, _.isEqual);
  6959. * // => [{ 'x': 1, 'y': 2 }]
  6960. */
  6961. var intersectionWith = baseRest(function(arrays) {
  6962. var comparator = last(arrays),
  6963. mapped = arrayMap(arrays, castArrayLikeObject);
  6964. comparator = typeof comparator == 'function' ? comparator : undefined;
  6965. if (comparator) {
  6966. mapped.pop();
  6967. }
  6968. return (mapped.length && mapped[0] === arrays[0])
  6969. ? baseIntersection(mapped, undefined, comparator)
  6970. : [];
  6971. });
  6972. /**
  6973. * Converts all elements in `array` into a string separated by `separator`.
  6974. *
  6975. * @static
  6976. * @memberOf _
  6977. * @since 4.0.0
  6978. * @category Array
  6979. * @param {Array} array The array to convert.
  6980. * @param {string} [separator=','] The element separator.
  6981. * @returns {string} Returns the joined string.
  6982. * @example
  6983. *
  6984. * _.join(['a', 'b', 'c'], '~');
  6985. * // => 'a~b~c'
  6986. */
  6987. function join(array, separator) {
  6988. return array == null ? '' : nativeJoin.call(array, separator);
  6989. }
  6990. /**
  6991. * Gets the last element of `array`.
  6992. *
  6993. * @static
  6994. * @memberOf _
  6995. * @since 0.1.0
  6996. * @category Array
  6997. * @param {Array} array The array to query.
  6998. * @returns {*} Returns the last element of `array`.
  6999. * @example
  7000. *
  7001. * _.last([1, 2, 3]);
  7002. * // => 3
  7003. */
  7004. function last(array) {
  7005. var length = array == null ? 0 : array.length;
  7006. return length ? array[length - 1] : undefined;
  7007. }
  7008. /**
  7009. * This method is like `_.indexOf` except that it iterates over elements of
  7010. * `array` from right to left.
  7011. *
  7012. * @static
  7013. * @memberOf _
  7014. * @since 0.1.0
  7015. * @category Array
  7016. * @param {Array} array The array to inspect.
  7017. * @param {*} value The value to search for.
  7018. * @param {number} [fromIndex=array.length-1] The index to search from.
  7019. * @returns {number} Returns the index of the matched value, else `-1`.
  7020. * @example
  7021. *
  7022. * _.lastIndexOf([1, 2, 1, 2], 2);
  7023. * // => 3
  7024. *
  7025. * // Search from the `fromIndex`.
  7026. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7027. * // => 1
  7028. */
  7029. function lastIndexOf(array, value, fromIndex) {
  7030. var length = array == null ? 0 : array.length;
  7031. if (!length) {
  7032. return -1;
  7033. }
  7034. var index = length;
  7035. if (fromIndex !== undefined) {
  7036. index = toInteger(fromIndex);
  7037. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7038. }
  7039. return value === value
  7040. ? strictLastIndexOf(array, value, index)
  7041. : baseFindIndex(array, baseIsNaN, index, true);
  7042. }
  7043. /**
  7044. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7045. * element from the end is returned.
  7046. *
  7047. * @static
  7048. * @memberOf _
  7049. * @since 4.11.0
  7050. * @category Array
  7051. * @param {Array} array The array to query.
  7052. * @param {number} [n=0] The index of the element to return.
  7053. * @returns {*} Returns the nth element of `array`.
  7054. * @example
  7055. *
  7056. * var array = ['a', 'b', 'c', 'd'];
  7057. *
  7058. * _.nth(array, 1);
  7059. * // => 'b'
  7060. *
  7061. * _.nth(array, -2);
  7062. * // => 'c';
  7063. */
  7064. function nth(array, n) {
  7065. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7066. }
  7067. /**
  7068. * Removes all given values from `array` using
  7069. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7070. * for equality comparisons.
  7071. *
  7072. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7073. * to remove elements from an array by predicate.
  7074. *
  7075. * @static
  7076. * @memberOf _
  7077. * @since 2.0.0
  7078. * @category Array
  7079. * @param {Array} array The array to modify.
  7080. * @param {...*} [values] The values to remove.
  7081. * @returns {Array} Returns `array`.
  7082. * @example
  7083. *
  7084. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7085. *
  7086. * _.pull(array, 'a', 'c');
  7087. * console.log(array);
  7088. * // => ['b', 'b']
  7089. */
  7090. var pull = baseRest(pullAll);
  7091. /**
  7092. * This method is like `_.pull` except that it accepts an array of values to remove.
  7093. *
  7094. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7095. *
  7096. * @static
  7097. * @memberOf _
  7098. * @since 4.0.0
  7099. * @category Array
  7100. * @param {Array} array The array to modify.
  7101. * @param {Array} values The values to remove.
  7102. * @returns {Array} Returns `array`.
  7103. * @example
  7104. *
  7105. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7106. *
  7107. * _.pullAll(array, ['a', 'c']);
  7108. * console.log(array);
  7109. * // => ['b', 'b']
  7110. */
  7111. function pullAll(array, values) {
  7112. return (array && array.length && values && values.length)
  7113. ? basePullAll(array, values)
  7114. : array;
  7115. }
  7116. /**
  7117. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7118. * invoked for each element of `array` and `values` to generate the criterion
  7119. * by which they're compared. The iteratee is invoked with one argument: (value).
  7120. *
  7121. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7122. *
  7123. * @static
  7124. * @memberOf _
  7125. * @since 4.0.0
  7126. * @category Array
  7127. * @param {Array} array The array to modify.
  7128. * @param {Array} values The values to remove.
  7129. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7130. * @returns {Array} Returns `array`.
  7131. * @example
  7132. *
  7133. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7134. *
  7135. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7136. * console.log(array);
  7137. * // => [{ 'x': 2 }]
  7138. */
  7139. function pullAllBy(array, values, iteratee) {
  7140. return (array && array.length && values && values.length)
  7141. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7142. : array;
  7143. }
  7144. /**
  7145. * This method is like `_.pullAll` except that it accepts `comparator` which
  7146. * is invoked to compare elements of `array` to `values`. The comparator is
  7147. * invoked with two arguments: (arrVal, othVal).
  7148. *
  7149. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7150. *
  7151. * @static
  7152. * @memberOf _
  7153. * @since 4.6.0
  7154. * @category Array
  7155. * @param {Array} array The array to modify.
  7156. * @param {Array} values The values to remove.
  7157. * @param {Function} [comparator] The comparator invoked per element.
  7158. * @returns {Array} Returns `array`.
  7159. * @example
  7160. *
  7161. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7162. *
  7163. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7164. * console.log(array);
  7165. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7166. */
  7167. function pullAllWith(array, values, comparator) {
  7168. return (array && array.length && values && values.length)
  7169. ? basePullAll(array, values, undefined, comparator)
  7170. : array;
  7171. }
  7172. /**
  7173. * Removes elements from `array` corresponding to `indexes` and returns an
  7174. * array of removed elements.
  7175. *
  7176. * **Note:** Unlike `_.at`, this method mutates `array`.
  7177. *
  7178. * @static
  7179. * @memberOf _
  7180. * @since 3.0.0
  7181. * @category Array
  7182. * @param {Array} array The array to modify.
  7183. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7184. * @returns {Array} Returns the new array of removed elements.
  7185. * @example
  7186. *
  7187. * var array = ['a', 'b', 'c', 'd'];
  7188. * var pulled = _.pullAt(array, [1, 3]);
  7189. *
  7190. * console.log(array);
  7191. * // => ['a', 'c']
  7192. *
  7193. * console.log(pulled);
  7194. * // => ['b', 'd']
  7195. */
  7196. var pullAt = flatRest(function(array, indexes) {
  7197. var length = array == null ? 0 : array.length,
  7198. result = baseAt(array, indexes);
  7199. basePullAt(array, arrayMap(indexes, function(index) {
  7200. return isIndex(index, length) ? +index : index;
  7201. }).sort(compareAscending));
  7202. return result;
  7203. });
  7204. /**
  7205. * Removes all elements from `array` that `predicate` returns truthy for
  7206. * and returns an array of the removed elements. The predicate is invoked
  7207. * with three arguments: (value, index, array).
  7208. *
  7209. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7210. * to pull elements from an array by value.
  7211. *
  7212. * @static
  7213. * @memberOf _
  7214. * @since 2.0.0
  7215. * @category Array
  7216. * @param {Array} array The array to modify.
  7217. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7218. * @returns {Array} Returns the new array of removed elements.
  7219. * @example
  7220. *
  7221. * var array = [1, 2, 3, 4];
  7222. * var evens = _.remove(array, function(n) {
  7223. * return n % 2 == 0;
  7224. * });
  7225. *
  7226. * console.log(array);
  7227. * // => [1, 3]
  7228. *
  7229. * console.log(evens);
  7230. * // => [2, 4]
  7231. */
  7232. function remove(array, predicate) {
  7233. var result = [];
  7234. if (!(array && array.length)) {
  7235. return result;
  7236. }
  7237. var index = -1,
  7238. indexes = [],
  7239. length = array.length;
  7240. predicate = getIteratee(predicate, 3);
  7241. while (++index < length) {
  7242. var value = array[index];
  7243. if (predicate(value, index, array)) {
  7244. result.push(value);
  7245. indexes.push(index);
  7246. }
  7247. }
  7248. basePullAt(array, indexes);
  7249. return result;
  7250. }
  7251. /**
  7252. * Reverses `array` so that the first element becomes the last, the second
  7253. * element becomes the second to last, and so on.
  7254. *
  7255. * **Note:** This method mutates `array` and is based on
  7256. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7257. *
  7258. * @static
  7259. * @memberOf _
  7260. * @since 4.0.0
  7261. * @category Array
  7262. * @param {Array} array The array to modify.
  7263. * @returns {Array} Returns `array`.
  7264. * @example
  7265. *
  7266. * var array = [1, 2, 3];
  7267. *
  7268. * _.reverse(array);
  7269. * // => [3, 2, 1]
  7270. *
  7271. * console.log(array);
  7272. * // => [3, 2, 1]
  7273. */
  7274. function reverse(array) {
  7275. return array == null ? array : nativeReverse.call(array);
  7276. }
  7277. /**
  7278. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7279. *
  7280. * **Note:** This method is used instead of
  7281. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7282. * returned.
  7283. *
  7284. * @static
  7285. * @memberOf _
  7286. * @since 3.0.0
  7287. * @category Array
  7288. * @param {Array} array The array to slice.
  7289. * @param {number} [start=0] The start position.
  7290. * @param {number} [end=array.length] The end position.
  7291. * @returns {Array} Returns the slice of `array`.
  7292. */
  7293. function slice(array, start, end) {
  7294. var length = array == null ? 0 : array.length;
  7295. if (!length) {
  7296. return [];
  7297. }
  7298. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7299. start = 0;
  7300. end = length;
  7301. }
  7302. else {
  7303. start = start == null ? 0 : toInteger(start);
  7304. end = end === undefined ? length : toInteger(end);
  7305. }
  7306. return baseSlice(array, start, end);
  7307. }
  7308. /**
  7309. * Uses a binary search to determine the lowest index at which `value`
  7310. * should be inserted into `array` in order to maintain its sort order.
  7311. *
  7312. * @static
  7313. * @memberOf _
  7314. * @since 0.1.0
  7315. * @category Array
  7316. * @param {Array} array The sorted array to inspect.
  7317. * @param {*} value The value to evaluate.
  7318. * @returns {number} Returns the index at which `value` should be inserted
  7319. * into `array`.
  7320. * @example
  7321. *
  7322. * _.sortedIndex([30, 50], 40);
  7323. * // => 1
  7324. */
  7325. function sortedIndex(array, value) {
  7326. return baseSortedIndex(array, value);
  7327. }
  7328. /**
  7329. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7330. * which is invoked for `value` and each element of `array` to compute their
  7331. * sort ranking. The iteratee is invoked with one argument: (value).
  7332. *
  7333. * @static
  7334. * @memberOf _
  7335. * @since 4.0.0
  7336. * @category Array
  7337. * @param {Array} array The sorted array to inspect.
  7338. * @param {*} value The value to evaluate.
  7339. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7340. * @returns {number} Returns the index at which `value` should be inserted
  7341. * into `array`.
  7342. * @example
  7343. *
  7344. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7345. *
  7346. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7347. * // => 0
  7348. *
  7349. * // The `_.property` iteratee shorthand.
  7350. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7351. * // => 0
  7352. */
  7353. function sortedIndexBy(array, value, iteratee) {
  7354. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7355. }
  7356. /**
  7357. * This method is like `_.indexOf` except that it performs a binary
  7358. * search on a sorted `array`.
  7359. *
  7360. * @static
  7361. * @memberOf _
  7362. * @since 4.0.0
  7363. * @category Array
  7364. * @param {Array} array The array to inspect.
  7365. * @param {*} value The value to search for.
  7366. * @returns {number} Returns the index of the matched value, else `-1`.
  7367. * @example
  7368. *
  7369. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7370. * // => 1
  7371. */
  7372. function sortedIndexOf(array, value) {
  7373. var length = array == null ? 0 : array.length;
  7374. if (length) {
  7375. var index = baseSortedIndex(array, value);
  7376. if (index < length && eq(array[index], value)) {
  7377. return index;
  7378. }
  7379. }
  7380. return -1;
  7381. }
  7382. /**
  7383. * This method is like `_.sortedIndex` except that it returns the highest
  7384. * index at which `value` should be inserted into `array` in order to
  7385. * maintain its sort order.
  7386. *
  7387. * @static
  7388. * @memberOf _
  7389. * @since 3.0.0
  7390. * @category Array
  7391. * @param {Array} array The sorted array to inspect.
  7392. * @param {*} value The value to evaluate.
  7393. * @returns {number} Returns the index at which `value` should be inserted
  7394. * into `array`.
  7395. * @example
  7396. *
  7397. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7398. * // => 4
  7399. */
  7400. function sortedLastIndex(array, value) {
  7401. return baseSortedIndex(array, value, true);
  7402. }
  7403. /**
  7404. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7405. * which is invoked for `value` and each element of `array` to compute their
  7406. * sort ranking. The iteratee is invoked with one argument: (value).
  7407. *
  7408. * @static
  7409. * @memberOf _
  7410. * @since 4.0.0
  7411. * @category Array
  7412. * @param {Array} array The sorted array to inspect.
  7413. * @param {*} value The value to evaluate.
  7414. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7415. * @returns {number} Returns the index at which `value` should be inserted
  7416. * into `array`.
  7417. * @example
  7418. *
  7419. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7420. *
  7421. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7422. * // => 1
  7423. *
  7424. * // The `_.property` iteratee shorthand.
  7425. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7426. * // => 1
  7427. */
  7428. function sortedLastIndexBy(array, value, iteratee) {
  7429. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7430. }
  7431. /**
  7432. * This method is like `_.lastIndexOf` except that it performs a binary
  7433. * search on a sorted `array`.
  7434. *
  7435. * @static
  7436. * @memberOf _
  7437. * @since 4.0.0
  7438. * @category Array
  7439. * @param {Array} array The array to inspect.
  7440. * @param {*} value The value to search for.
  7441. * @returns {number} Returns the index of the matched value, else `-1`.
  7442. * @example
  7443. *
  7444. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7445. * // => 3
  7446. */
  7447. function sortedLastIndexOf(array, value) {
  7448. var length = array == null ? 0 : array.length;
  7449. if (length) {
  7450. var index = baseSortedIndex(array, value, true) - 1;
  7451. if (eq(array[index], value)) {
  7452. return index;
  7453. }
  7454. }
  7455. return -1;
  7456. }
  7457. /**
  7458. * This method is like `_.uniq` except that it's designed and optimized
  7459. * for sorted arrays.
  7460. *
  7461. * @static
  7462. * @memberOf _
  7463. * @since 4.0.0
  7464. * @category Array
  7465. * @param {Array} array The array to inspect.
  7466. * @returns {Array} Returns the new duplicate free array.
  7467. * @example
  7468. *
  7469. * _.sortedUniq([1, 1, 2]);
  7470. * // => [1, 2]
  7471. */
  7472. function sortedUniq(array) {
  7473. return (array && array.length)
  7474. ? baseSortedUniq(array)
  7475. : [];
  7476. }
  7477. /**
  7478. * This method is like `_.uniqBy` except that it's designed and optimized
  7479. * for sorted arrays.
  7480. *
  7481. * @static
  7482. * @memberOf _
  7483. * @since 4.0.0
  7484. * @category Array
  7485. * @param {Array} array The array to inspect.
  7486. * @param {Function} [iteratee] The iteratee invoked per element.
  7487. * @returns {Array} Returns the new duplicate free array.
  7488. * @example
  7489. *
  7490. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7491. * // => [1.1, 2.3]
  7492. */
  7493. function sortedUniqBy(array, iteratee) {
  7494. return (array && array.length)
  7495. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7496. : [];
  7497. }
  7498. /**
  7499. * Gets all but the first element of `array`.
  7500. *
  7501. * @static
  7502. * @memberOf _
  7503. * @since 4.0.0
  7504. * @category Array
  7505. * @param {Array} array The array to query.
  7506. * @returns {Array} Returns the slice of `array`.
  7507. * @example
  7508. *
  7509. * _.tail([1, 2, 3]);
  7510. * // => [2, 3]
  7511. */
  7512. function tail(array) {
  7513. var length = array == null ? 0 : array.length;
  7514. return length ? baseSlice(array, 1, length) : [];
  7515. }
  7516. /**
  7517. * Creates a slice of `array` with `n` elements taken from the beginning.
  7518. *
  7519. * @static
  7520. * @memberOf _
  7521. * @since 0.1.0
  7522. * @category Array
  7523. * @param {Array} array The array to query.
  7524. * @param {number} [n=1] The number of elements to take.
  7525. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7526. * @returns {Array} Returns the slice of `array`.
  7527. * @example
  7528. *
  7529. * _.take([1, 2, 3]);
  7530. * // => [1]
  7531. *
  7532. * _.take([1, 2, 3], 2);
  7533. * // => [1, 2]
  7534. *
  7535. * _.take([1, 2, 3], 5);
  7536. * // => [1, 2, 3]
  7537. *
  7538. * _.take([1, 2, 3], 0);
  7539. * // => []
  7540. */
  7541. function take(array, n, guard) {
  7542. if (!(array && array.length)) {
  7543. return [];
  7544. }
  7545. n = (guard || n === undefined) ? 1 : toInteger(n);
  7546. return baseSlice(array, 0, n < 0 ? 0 : n);
  7547. }
  7548. /**
  7549. * Creates a slice of `array` with `n` elements taken from the end.
  7550. *
  7551. * @static
  7552. * @memberOf _
  7553. * @since 3.0.0
  7554. * @category Array
  7555. * @param {Array} array The array to query.
  7556. * @param {number} [n=1] The number of elements to take.
  7557. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7558. * @returns {Array} Returns the slice of `array`.
  7559. * @example
  7560. *
  7561. * _.takeRight([1, 2, 3]);
  7562. * // => [3]
  7563. *
  7564. * _.takeRight([1, 2, 3], 2);
  7565. * // => [2, 3]
  7566. *
  7567. * _.takeRight([1, 2, 3], 5);
  7568. * // => [1, 2, 3]
  7569. *
  7570. * _.takeRight([1, 2, 3], 0);
  7571. * // => []
  7572. */
  7573. function takeRight(array, n, guard) {
  7574. var length = array == null ? 0 : array.length;
  7575. if (!length) {
  7576. return [];
  7577. }
  7578. n = (guard || n === undefined) ? 1 : toInteger(n);
  7579. n = length - n;
  7580. return baseSlice(array, n < 0 ? 0 : n, length);
  7581. }
  7582. /**
  7583. * Creates a slice of `array` with elements taken from the end. Elements are
  7584. * taken until `predicate` returns falsey. The predicate is invoked with
  7585. * three arguments: (value, index, array).
  7586. *
  7587. * @static
  7588. * @memberOf _
  7589. * @since 3.0.0
  7590. * @category Array
  7591. * @param {Array} array The array to query.
  7592. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7593. * @returns {Array} Returns the slice of `array`.
  7594. * @example
  7595. *
  7596. * var users = [
  7597. * { 'user': 'barney', 'active': true },
  7598. * { 'user': 'fred', 'active': false },
  7599. * { 'user': 'pebbles', 'active': false }
  7600. * ];
  7601. *
  7602. * _.takeRightWhile(users, function(o) { return !o.active; });
  7603. * // => objects for ['fred', 'pebbles']
  7604. *
  7605. * // The `_.matches` iteratee shorthand.
  7606. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7607. * // => objects for ['pebbles']
  7608. *
  7609. * // The `_.matchesProperty` iteratee shorthand.
  7610. * _.takeRightWhile(users, ['active', false]);
  7611. * // => objects for ['fred', 'pebbles']
  7612. *
  7613. * // The `_.property` iteratee shorthand.
  7614. * _.takeRightWhile(users, 'active');
  7615. * // => []
  7616. */
  7617. function takeRightWhile(array, predicate) {
  7618. return (array && array.length)
  7619. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7620. : [];
  7621. }
  7622. /**
  7623. * Creates a slice of `array` with elements taken from the beginning. Elements
  7624. * are taken until `predicate` returns falsey. The predicate is invoked with
  7625. * three arguments: (value, index, array).
  7626. *
  7627. * @static
  7628. * @memberOf _
  7629. * @since 3.0.0
  7630. * @category Array
  7631. * @param {Array} array The array to query.
  7632. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7633. * @returns {Array} Returns the slice of `array`.
  7634. * @example
  7635. *
  7636. * var users = [
  7637. * { 'user': 'barney', 'active': false },
  7638. * { 'user': 'fred', 'active': false },
  7639. * { 'user': 'pebbles', 'active': true }
  7640. * ];
  7641. *
  7642. * _.takeWhile(users, function(o) { return !o.active; });
  7643. * // => objects for ['barney', 'fred']
  7644. *
  7645. * // The `_.matches` iteratee shorthand.
  7646. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7647. * // => objects for ['barney']
  7648. *
  7649. * // The `_.matchesProperty` iteratee shorthand.
  7650. * _.takeWhile(users, ['active', false]);
  7651. * // => objects for ['barney', 'fred']
  7652. *
  7653. * // The `_.property` iteratee shorthand.
  7654. * _.takeWhile(users, 'active');
  7655. * // => []
  7656. */
  7657. function takeWhile(array, predicate) {
  7658. return (array && array.length)
  7659. ? baseWhile(array, getIteratee(predicate, 3))
  7660. : [];
  7661. }
  7662. /**
  7663. * Creates an array of unique values, in order, from all given arrays using
  7664. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7665. * for equality comparisons.
  7666. *
  7667. * @static
  7668. * @memberOf _
  7669. * @since 0.1.0
  7670. * @category Array
  7671. * @param {...Array} [arrays] The arrays to inspect.
  7672. * @returns {Array} Returns the new array of combined values.
  7673. * @example
  7674. *
  7675. * _.union([2], [1, 2]);
  7676. * // => [2, 1]
  7677. */
  7678. var union = baseRest(function(arrays) {
  7679. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7680. });
  7681. /**
  7682. * This method is like `_.union` except that it accepts `iteratee` which is
  7683. * invoked for each element of each `arrays` to generate the criterion by
  7684. * which uniqueness is computed. Result values are chosen from the first
  7685. * array in which the value occurs. The iteratee is invoked with one argument:
  7686. * (value).
  7687. *
  7688. * @static
  7689. * @memberOf _
  7690. * @since 4.0.0
  7691. * @category Array
  7692. * @param {...Array} [arrays] The arrays to inspect.
  7693. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7694. * @returns {Array} Returns the new array of combined values.
  7695. * @example
  7696. *
  7697. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7698. * // => [2.1, 1.2]
  7699. *
  7700. * // The `_.property` iteratee shorthand.
  7701. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7702. * // => [{ 'x': 1 }, { 'x': 2 }]
  7703. */
  7704. var unionBy = baseRest(function(arrays) {
  7705. var iteratee = last(arrays);
  7706. if (isArrayLikeObject(iteratee)) {
  7707. iteratee = undefined;
  7708. }
  7709. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7710. });
  7711. /**
  7712. * This method is like `_.union` except that it accepts `comparator` which
  7713. * is invoked to compare elements of `arrays`. Result values are chosen from
  7714. * the first array in which the value occurs. The comparator is invoked
  7715. * with two arguments: (arrVal, othVal).
  7716. *
  7717. * @static
  7718. * @memberOf _
  7719. * @since 4.0.0
  7720. * @category Array
  7721. * @param {...Array} [arrays] The arrays to inspect.
  7722. * @param {Function} [comparator] The comparator invoked per element.
  7723. * @returns {Array} Returns the new array of combined values.
  7724. * @example
  7725. *
  7726. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7727. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7728. *
  7729. * _.unionWith(objects, others, _.isEqual);
  7730. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7731. */
  7732. var unionWith = baseRest(function(arrays) {
  7733. var comparator = last(arrays);
  7734. comparator = typeof comparator == 'function' ? comparator : undefined;
  7735. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7736. });
  7737. /**
  7738. * Creates a duplicate-free version of an array, using
  7739. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7740. * for equality comparisons, in which only the first occurrence of each element
  7741. * is kept. The order of result values is determined by the order they occur
  7742. * in the array.
  7743. *
  7744. * @static
  7745. * @memberOf _
  7746. * @since 0.1.0
  7747. * @category Array
  7748. * @param {Array} array The array to inspect.
  7749. * @returns {Array} Returns the new duplicate free array.
  7750. * @example
  7751. *
  7752. * _.uniq([2, 1, 2]);
  7753. * // => [2, 1]
  7754. */
  7755. function uniq(array) {
  7756. return (array && array.length) ? baseUniq(array) : [];
  7757. }
  7758. /**
  7759. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7760. * invoked for each element in `array` to generate the criterion by which
  7761. * uniqueness is computed. The order of result values is determined by the
  7762. * order they occur in the array. The iteratee is invoked with one argument:
  7763. * (value).
  7764. *
  7765. * @static
  7766. * @memberOf _
  7767. * @since 4.0.0
  7768. * @category Array
  7769. * @param {Array} array The array to inspect.
  7770. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7771. * @returns {Array} Returns the new duplicate free array.
  7772. * @example
  7773. *
  7774. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7775. * // => [2.1, 1.2]
  7776. *
  7777. * // The `_.property` iteratee shorthand.
  7778. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7779. * // => [{ 'x': 1 }, { 'x': 2 }]
  7780. */
  7781. function uniqBy(array, iteratee) {
  7782. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7783. }
  7784. /**
  7785. * This method is like `_.uniq` except that it accepts `comparator` which
  7786. * is invoked to compare elements of `array`. The order of result values is
  7787. * determined by the order they occur in the array.The comparator is invoked
  7788. * with two arguments: (arrVal, othVal).
  7789. *
  7790. * @static
  7791. * @memberOf _
  7792. * @since 4.0.0
  7793. * @category Array
  7794. * @param {Array} array The array to inspect.
  7795. * @param {Function} [comparator] The comparator invoked per element.
  7796. * @returns {Array} Returns the new duplicate free array.
  7797. * @example
  7798. *
  7799. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7800. *
  7801. * _.uniqWith(objects, _.isEqual);
  7802. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7803. */
  7804. function uniqWith(array, comparator) {
  7805. comparator = typeof comparator == 'function' ? comparator : undefined;
  7806. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7807. }
  7808. /**
  7809. * This method is like `_.zip` except that it accepts an array of grouped
  7810. * elements and creates an array regrouping the elements to their pre-zip
  7811. * configuration.
  7812. *
  7813. * @static
  7814. * @memberOf _
  7815. * @since 1.2.0
  7816. * @category Array
  7817. * @param {Array} array The array of grouped elements to process.
  7818. * @returns {Array} Returns the new array of regrouped elements.
  7819. * @example
  7820. *
  7821. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7822. * // => [['a', 1, true], ['b', 2, false]]
  7823. *
  7824. * _.unzip(zipped);
  7825. * // => [['a', 'b'], [1, 2], [true, false]]
  7826. */
  7827. function unzip(array) {
  7828. if (!(array && array.length)) {
  7829. return [];
  7830. }
  7831. var length = 0;
  7832. array = arrayFilter(array, function(group) {
  7833. if (isArrayLikeObject(group)) {
  7834. length = nativeMax(group.length, length);
  7835. return true;
  7836. }
  7837. });
  7838. return baseTimes(length, function(index) {
  7839. return arrayMap(array, baseProperty(index));
  7840. });
  7841. }
  7842. /**
  7843. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7844. * how regrouped values should be combined. The iteratee is invoked with the
  7845. * elements of each group: (...group).
  7846. *
  7847. * @static
  7848. * @memberOf _
  7849. * @since 3.8.0
  7850. * @category Array
  7851. * @param {Array} array The array of grouped elements to process.
  7852. * @param {Function} [iteratee=_.identity] The function to combine
  7853. * regrouped values.
  7854. * @returns {Array} Returns the new array of regrouped elements.
  7855. * @example
  7856. *
  7857. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7858. * // => [[1, 10, 100], [2, 20, 200]]
  7859. *
  7860. * _.unzipWith(zipped, _.add);
  7861. * // => [3, 30, 300]
  7862. */
  7863. function unzipWith(array, iteratee) {
  7864. if (!(array && array.length)) {
  7865. return [];
  7866. }
  7867. var result = unzip(array);
  7868. if (iteratee == null) {
  7869. return result;
  7870. }
  7871. return arrayMap(result, function(group) {
  7872. return apply(iteratee, undefined, group);
  7873. });
  7874. }
  7875. /**
  7876. * Creates an array excluding all given values using
  7877. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7878. * for equality comparisons.
  7879. *
  7880. * **Note:** Unlike `_.pull`, this method returns a new array.
  7881. *
  7882. * @static
  7883. * @memberOf _
  7884. * @since 0.1.0
  7885. * @category Array
  7886. * @param {Array} array The array to inspect.
  7887. * @param {...*} [values] The values to exclude.
  7888. * @returns {Array} Returns the new array of filtered values.
  7889. * @see _.difference, _.xor
  7890. * @example
  7891. *
  7892. * _.without([2, 1, 2, 3], 1, 2);
  7893. * // => [3]
  7894. */
  7895. var without = baseRest(function(array, values) {
  7896. return isArrayLikeObject(array)
  7897. ? baseDifference(array, values)
  7898. : [];
  7899. });
  7900. /**
  7901. * Creates an array of unique values that is the
  7902. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7903. * of the given arrays. The order of result values is determined by the order
  7904. * they occur in the arrays.
  7905. *
  7906. * @static
  7907. * @memberOf _
  7908. * @since 2.4.0
  7909. * @category Array
  7910. * @param {...Array} [arrays] The arrays to inspect.
  7911. * @returns {Array} Returns the new array of filtered values.
  7912. * @see _.difference, _.without
  7913. * @example
  7914. *
  7915. * _.xor([2, 1], [2, 3]);
  7916. * // => [1, 3]
  7917. */
  7918. var xor = baseRest(function(arrays) {
  7919. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7920. });
  7921. /**
  7922. * This method is like `_.xor` except that it accepts `iteratee` which is
  7923. * invoked for each element of each `arrays` to generate the criterion by
  7924. * which by which they're compared. The order of result values is determined
  7925. * by the order they occur in the arrays. The iteratee is invoked with one
  7926. * argument: (value).
  7927. *
  7928. * @static
  7929. * @memberOf _
  7930. * @since 4.0.0
  7931. * @category Array
  7932. * @param {...Array} [arrays] The arrays to inspect.
  7933. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7934. * @returns {Array} Returns the new array of filtered values.
  7935. * @example
  7936. *
  7937. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7938. * // => [1.2, 3.4]
  7939. *
  7940. * // The `_.property` iteratee shorthand.
  7941. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7942. * // => [{ 'x': 2 }]
  7943. */
  7944. var xorBy = baseRest(function(arrays) {
  7945. var iteratee = last(arrays);
  7946. if (isArrayLikeObject(iteratee)) {
  7947. iteratee = undefined;
  7948. }
  7949. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7950. });
  7951. /**
  7952. * This method is like `_.xor` except that it accepts `comparator` which is
  7953. * invoked to compare elements of `arrays`. The order of result values is
  7954. * determined by the order they occur in the arrays. The comparator is invoked
  7955. * with two arguments: (arrVal, othVal).
  7956. *
  7957. * @static
  7958. * @memberOf _
  7959. * @since 4.0.0
  7960. * @category Array
  7961. * @param {...Array} [arrays] The arrays to inspect.
  7962. * @param {Function} [comparator] The comparator invoked per element.
  7963. * @returns {Array} Returns the new array of filtered values.
  7964. * @example
  7965. *
  7966. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7967. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7968. *
  7969. * _.xorWith(objects, others, _.isEqual);
  7970. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7971. */
  7972. var xorWith = baseRest(function(arrays) {
  7973. var comparator = last(arrays);
  7974. comparator = typeof comparator == 'function' ? comparator : undefined;
  7975. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7976. });
  7977. /**
  7978. * Creates an array of grouped elements, the first of which contains the
  7979. * first elements of the given arrays, the second of which contains the
  7980. * second elements of the given arrays, and so on.
  7981. *
  7982. * @static
  7983. * @memberOf _
  7984. * @since 0.1.0
  7985. * @category Array
  7986. * @param {...Array} [arrays] The arrays to process.
  7987. * @returns {Array} Returns the new array of grouped elements.
  7988. * @example
  7989. *
  7990. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7991. * // => [['a', 1, true], ['b', 2, false]]
  7992. */
  7993. var zip = baseRest(unzip);
  7994. /**
  7995. * This method is like `_.fromPairs` except that it accepts two arrays,
  7996. * one of property identifiers and one of corresponding values.
  7997. *
  7998. * @static
  7999. * @memberOf _
  8000. * @since 0.4.0
  8001. * @category Array
  8002. * @param {Array} [props=[]] The property identifiers.
  8003. * @param {Array} [values=[]] The property values.
  8004. * @returns {Object} Returns the new object.
  8005. * @example
  8006. *
  8007. * _.zipObject(['a', 'b'], [1, 2]);
  8008. * // => { 'a': 1, 'b': 2 }
  8009. */
  8010. function zipObject(props, values) {
  8011. return baseZipObject(props || [], values || [], assignValue);
  8012. }
  8013. /**
  8014. * This method is like `_.zipObject` except that it supports property paths.
  8015. *
  8016. * @static
  8017. * @memberOf _
  8018. * @since 4.1.0
  8019. * @category Array
  8020. * @param {Array} [props=[]] The property identifiers.
  8021. * @param {Array} [values=[]] The property values.
  8022. * @returns {Object} Returns the new object.
  8023. * @example
  8024. *
  8025. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8026. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8027. */
  8028. function zipObjectDeep(props, values) {
  8029. return baseZipObject(props || [], values || [], baseSet);
  8030. }
  8031. /**
  8032. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8033. * how grouped values should be combined. The iteratee is invoked with the
  8034. * elements of each group: (...group).
  8035. *
  8036. * @static
  8037. * @memberOf _
  8038. * @since 3.8.0
  8039. * @category Array
  8040. * @param {...Array} [arrays] The arrays to process.
  8041. * @param {Function} [iteratee=_.identity] The function to combine
  8042. * grouped values.
  8043. * @returns {Array} Returns the new array of grouped elements.
  8044. * @example
  8045. *
  8046. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8047. * return a + b + c;
  8048. * });
  8049. * // => [111, 222]
  8050. */
  8051. var zipWith = baseRest(function(arrays) {
  8052. var length = arrays.length,
  8053. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8054. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8055. return unzipWith(arrays, iteratee);
  8056. });
  8057. /*------------------------------------------------------------------------*/
  8058. /**
  8059. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8060. * chain sequences enabled. The result of such sequences must be unwrapped
  8061. * with `_#value`.
  8062. *
  8063. * @static
  8064. * @memberOf _
  8065. * @since 1.3.0
  8066. * @category Seq
  8067. * @param {*} value The value to wrap.
  8068. * @returns {Object} Returns the new `lodash` wrapper instance.
  8069. * @example
  8070. *
  8071. * var users = [
  8072. * { 'user': 'barney', 'age': 36 },
  8073. * { 'user': 'fred', 'age': 40 },
  8074. * { 'user': 'pebbles', 'age': 1 }
  8075. * ];
  8076. *
  8077. * var youngest = _
  8078. * .chain(users)
  8079. * .sortBy('age')
  8080. * .map(function(o) {
  8081. * return o.user + ' is ' + o.age;
  8082. * })
  8083. * .head()
  8084. * .value();
  8085. * // => 'pebbles is 1'
  8086. */
  8087. function chain(value) {
  8088. var result = lodash(value);
  8089. result.__chain__ = true;
  8090. return result;
  8091. }
  8092. /**
  8093. * This method invokes `interceptor` and returns `value`. The interceptor
  8094. * is invoked with one argument; (value). The purpose of this method is to
  8095. * "tap into" a method chain sequence in order to modify intermediate results.
  8096. *
  8097. * @static
  8098. * @memberOf _
  8099. * @since 0.1.0
  8100. * @category Seq
  8101. * @param {*} value The value to provide to `interceptor`.
  8102. * @param {Function} interceptor The function to invoke.
  8103. * @returns {*} Returns `value`.
  8104. * @example
  8105. *
  8106. * _([1, 2, 3])
  8107. * .tap(function(array) {
  8108. * // Mutate input array.
  8109. * array.pop();
  8110. * })
  8111. * .reverse()
  8112. * .value();
  8113. * // => [2, 1]
  8114. */
  8115. function tap(value, interceptor) {
  8116. interceptor(value);
  8117. return value;
  8118. }
  8119. /**
  8120. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8121. * The purpose of this method is to "pass thru" values replacing intermediate
  8122. * results in a method chain sequence.
  8123. *
  8124. * @static
  8125. * @memberOf _
  8126. * @since 3.0.0
  8127. * @category Seq
  8128. * @param {*} value The value to provide to `interceptor`.
  8129. * @param {Function} interceptor The function to invoke.
  8130. * @returns {*} Returns the result of `interceptor`.
  8131. * @example
  8132. *
  8133. * _(' abc ')
  8134. * .chain()
  8135. * .trim()
  8136. * .thru(function(value) {
  8137. * return [value];
  8138. * })
  8139. * .value();
  8140. * // => ['abc']
  8141. */
  8142. function thru(value, interceptor) {
  8143. return interceptor(value);
  8144. }
  8145. /**
  8146. * This method is the wrapper version of `_.at`.
  8147. *
  8148. * @name at
  8149. * @memberOf _
  8150. * @since 1.0.0
  8151. * @category Seq
  8152. * @param {...(string|string[])} [paths] The property paths to pick.
  8153. * @returns {Object} Returns the new `lodash` wrapper instance.
  8154. * @example
  8155. *
  8156. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8157. *
  8158. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8159. * // => [3, 4]
  8160. */
  8161. var wrapperAt = flatRest(function(paths) {
  8162. var length = paths.length,
  8163. start = length ? paths[0] : 0,
  8164. value = this.__wrapped__,
  8165. interceptor = function(object) { return baseAt(object, paths); };
  8166. if (length > 1 || this.__actions__.length ||
  8167. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8168. return this.thru(interceptor);
  8169. }
  8170. value = value.slice(start, +start + (length ? 1 : 0));
  8171. value.__actions__.push({
  8172. 'func': thru,
  8173. 'args': [interceptor],
  8174. 'thisArg': undefined
  8175. });
  8176. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8177. if (length && !array.length) {
  8178. array.push(undefined);
  8179. }
  8180. return array;
  8181. });
  8182. });
  8183. /**
  8184. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8185. *
  8186. * @name chain
  8187. * @memberOf _
  8188. * @since 0.1.0
  8189. * @category Seq
  8190. * @returns {Object} Returns the new `lodash` wrapper instance.
  8191. * @example
  8192. *
  8193. * var users = [
  8194. * { 'user': 'barney', 'age': 36 },
  8195. * { 'user': 'fred', 'age': 40 }
  8196. * ];
  8197. *
  8198. * // A sequence without explicit chaining.
  8199. * _(users).head();
  8200. * // => { 'user': 'barney', 'age': 36 }
  8201. *
  8202. * // A sequence with explicit chaining.
  8203. * _(users)
  8204. * .chain()
  8205. * .head()
  8206. * .pick('user')
  8207. * .value();
  8208. * // => { 'user': 'barney' }
  8209. */
  8210. function wrapperChain() {
  8211. return chain(this);
  8212. }
  8213. /**
  8214. * Executes the chain sequence and returns the wrapped result.
  8215. *
  8216. * @name commit
  8217. * @memberOf _
  8218. * @since 3.2.0
  8219. * @category Seq
  8220. * @returns {Object} Returns the new `lodash` wrapper instance.
  8221. * @example
  8222. *
  8223. * var array = [1, 2];
  8224. * var wrapped = _(array).push(3);
  8225. *
  8226. * console.log(array);
  8227. * // => [1, 2]
  8228. *
  8229. * wrapped = wrapped.commit();
  8230. * console.log(array);
  8231. * // => [1, 2, 3]
  8232. *
  8233. * wrapped.last();
  8234. * // => 3
  8235. *
  8236. * console.log(array);
  8237. * // => [1, 2, 3]
  8238. */
  8239. function wrapperCommit() {
  8240. return new LodashWrapper(this.value(), this.__chain__);
  8241. }
  8242. /**
  8243. * Gets the next value on a wrapped object following the
  8244. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8245. *
  8246. * @name next
  8247. * @memberOf _
  8248. * @since 4.0.0
  8249. * @category Seq
  8250. * @returns {Object} Returns the next iterator value.
  8251. * @example
  8252. *
  8253. * var wrapped = _([1, 2]);
  8254. *
  8255. * wrapped.next();
  8256. * // => { 'done': false, 'value': 1 }
  8257. *
  8258. * wrapped.next();
  8259. * // => { 'done': false, 'value': 2 }
  8260. *
  8261. * wrapped.next();
  8262. * // => { 'done': true, 'value': undefined }
  8263. */
  8264. function wrapperNext() {
  8265. if (this.__values__ === undefined) {
  8266. this.__values__ = toArray(this.value());
  8267. }
  8268. var done = this.__index__ >= this.__values__.length,
  8269. value = done ? undefined : this.__values__[this.__index__++];
  8270. return { 'done': done, 'value': value };
  8271. }
  8272. /**
  8273. * Enables the wrapper to be iterable.
  8274. *
  8275. * @name Symbol.iterator
  8276. * @memberOf _
  8277. * @since 4.0.0
  8278. * @category Seq
  8279. * @returns {Object} Returns the wrapper object.
  8280. * @example
  8281. *
  8282. * var wrapped = _([1, 2]);
  8283. *
  8284. * wrapped[Symbol.iterator]() === wrapped;
  8285. * // => true
  8286. *
  8287. * Array.from(wrapped);
  8288. * // => [1, 2]
  8289. */
  8290. function wrapperToIterator() {
  8291. return this;
  8292. }
  8293. /**
  8294. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8295. *
  8296. * @name plant
  8297. * @memberOf _
  8298. * @since 3.2.0
  8299. * @category Seq
  8300. * @param {*} value The value to plant.
  8301. * @returns {Object} Returns the new `lodash` wrapper instance.
  8302. * @example
  8303. *
  8304. * function square(n) {
  8305. * return n * n;
  8306. * }
  8307. *
  8308. * var wrapped = _([1, 2]).map(square);
  8309. * var other = wrapped.plant([3, 4]);
  8310. *
  8311. * other.value();
  8312. * // => [9, 16]
  8313. *
  8314. * wrapped.value();
  8315. * // => [1, 4]
  8316. */
  8317. function wrapperPlant(value) {
  8318. var result,
  8319. parent = this;
  8320. while (parent instanceof baseLodash) {
  8321. var clone = wrapperClone(parent);
  8322. clone.__index__ = 0;
  8323. clone.__values__ = undefined;
  8324. if (result) {
  8325. previous.__wrapped__ = clone;
  8326. } else {
  8327. result = clone;
  8328. }
  8329. var previous = clone;
  8330. parent = parent.__wrapped__;
  8331. }
  8332. previous.__wrapped__ = value;
  8333. return result;
  8334. }
  8335. /**
  8336. * This method is the wrapper version of `_.reverse`.
  8337. *
  8338. * **Note:** This method mutates the wrapped array.
  8339. *
  8340. * @name reverse
  8341. * @memberOf _
  8342. * @since 0.1.0
  8343. * @category Seq
  8344. * @returns {Object} Returns the new `lodash` wrapper instance.
  8345. * @example
  8346. *
  8347. * var array = [1, 2, 3];
  8348. *
  8349. * _(array).reverse().value()
  8350. * // => [3, 2, 1]
  8351. *
  8352. * console.log(array);
  8353. * // => [3, 2, 1]
  8354. */
  8355. function wrapperReverse() {
  8356. var value = this.__wrapped__;
  8357. if (value instanceof LazyWrapper) {
  8358. var wrapped = value;
  8359. if (this.__actions__.length) {
  8360. wrapped = new LazyWrapper(this);
  8361. }
  8362. wrapped = wrapped.reverse();
  8363. wrapped.__actions__.push({
  8364. 'func': thru,
  8365. 'args': [reverse],
  8366. 'thisArg': undefined
  8367. });
  8368. return new LodashWrapper(wrapped, this.__chain__);
  8369. }
  8370. return this.thru(reverse);
  8371. }
  8372. /**
  8373. * Executes the chain sequence to resolve the unwrapped value.
  8374. *
  8375. * @name value
  8376. * @memberOf _
  8377. * @since 0.1.0
  8378. * @alias toJSON, valueOf
  8379. * @category Seq
  8380. * @returns {*} Returns the resolved unwrapped value.
  8381. * @example
  8382. *
  8383. * _([1, 2, 3]).value();
  8384. * // => [1, 2, 3]
  8385. */
  8386. function wrapperValue() {
  8387. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8388. }
  8389. /*------------------------------------------------------------------------*/
  8390. /**
  8391. * Creates an object composed of keys generated from the results of running
  8392. * each element of `collection` thru `iteratee`. The corresponding value of
  8393. * each key is the number of times the key was returned by `iteratee`. The
  8394. * iteratee is invoked with one argument: (value).
  8395. *
  8396. * @static
  8397. * @memberOf _
  8398. * @since 0.5.0
  8399. * @category Collection
  8400. * @param {Array|Object} collection The collection to iterate over.
  8401. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8402. * @returns {Object} Returns the composed aggregate object.
  8403. * @example
  8404. *
  8405. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8406. * // => { '4': 1, '6': 2 }
  8407. *
  8408. * // The `_.property` iteratee shorthand.
  8409. * _.countBy(['one', 'two', 'three'], 'length');
  8410. * // => { '3': 2, '5': 1 }
  8411. */
  8412. var countBy = createAggregator(function(result, value, key) {
  8413. if (hasOwnProperty.call(result, key)) {
  8414. ++result[key];
  8415. } else {
  8416. baseAssignValue(result, key, 1);
  8417. }
  8418. });
  8419. /**
  8420. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8421. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8422. * invoked with three arguments: (value, index|key, collection).
  8423. *
  8424. * **Note:** This method returns `true` for
  8425. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8426. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8427. * elements of empty collections.
  8428. *
  8429. * @static
  8430. * @memberOf _
  8431. * @since 0.1.0
  8432. * @category Collection
  8433. * @param {Array|Object} collection The collection to iterate over.
  8434. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8435. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8436. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8437. * else `false`.
  8438. * @example
  8439. *
  8440. * _.every([true, 1, null, 'yes'], Boolean);
  8441. * // => false
  8442. *
  8443. * var users = [
  8444. * { 'user': 'barney', 'age': 36, 'active': false },
  8445. * { 'user': 'fred', 'age': 40, 'active': false }
  8446. * ];
  8447. *
  8448. * // The `_.matches` iteratee shorthand.
  8449. * _.every(users, { 'user': 'barney', 'active': false });
  8450. * // => false
  8451. *
  8452. * // The `_.matchesProperty` iteratee shorthand.
  8453. * _.every(users, ['active', false]);
  8454. * // => true
  8455. *
  8456. * // The `_.property` iteratee shorthand.
  8457. * _.every(users, 'active');
  8458. * // => false
  8459. */
  8460. function every(collection, predicate, guard) {
  8461. var func = isArray(collection) ? arrayEvery : baseEvery;
  8462. if (guard && isIterateeCall(collection, predicate, guard)) {
  8463. predicate = undefined;
  8464. }
  8465. return func(collection, getIteratee(predicate, 3));
  8466. }
  8467. /**
  8468. * Iterates over elements of `collection`, returning an array of all elements
  8469. * `predicate` returns truthy for. The predicate is invoked with three
  8470. * arguments: (value, index|key, collection).
  8471. *
  8472. * **Note:** Unlike `_.remove`, this method returns a new array.
  8473. *
  8474. * @static
  8475. * @memberOf _
  8476. * @since 0.1.0
  8477. * @category Collection
  8478. * @param {Array|Object} collection The collection to iterate over.
  8479. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8480. * @returns {Array} Returns the new filtered array.
  8481. * @see _.reject
  8482. * @example
  8483. *
  8484. * var users = [
  8485. * { 'user': 'barney', 'age': 36, 'active': true },
  8486. * { 'user': 'fred', 'age': 40, 'active': false }
  8487. * ];
  8488. *
  8489. * _.filter(users, function(o) { return !o.active; });
  8490. * // => objects for ['fred']
  8491. *
  8492. * // The `_.matches` iteratee shorthand.
  8493. * _.filter(users, { 'age': 36, 'active': true });
  8494. * // => objects for ['barney']
  8495. *
  8496. * // The `_.matchesProperty` iteratee shorthand.
  8497. * _.filter(users, ['active', false]);
  8498. * // => objects for ['fred']
  8499. *
  8500. * // The `_.property` iteratee shorthand.
  8501. * _.filter(users, 'active');
  8502. * // => objects for ['barney']
  8503. */
  8504. function filter(collection, predicate) {
  8505. var func = isArray(collection) ? arrayFilter : baseFilter;
  8506. return func(collection, getIteratee(predicate, 3));
  8507. }
  8508. /**
  8509. * Iterates over elements of `collection`, returning the first element
  8510. * `predicate` returns truthy for. The predicate is invoked with three
  8511. * arguments: (value, index|key, collection).
  8512. *
  8513. * @static
  8514. * @memberOf _
  8515. * @since 0.1.0
  8516. * @category Collection
  8517. * @param {Array|Object} collection The collection to inspect.
  8518. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8519. * @param {number} [fromIndex=0] The index to search from.
  8520. * @returns {*} Returns the matched element, else `undefined`.
  8521. * @example
  8522. *
  8523. * var users = [
  8524. * { 'user': 'barney', 'age': 36, 'active': true },
  8525. * { 'user': 'fred', 'age': 40, 'active': false },
  8526. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8527. * ];
  8528. *
  8529. * _.find(users, function(o) { return o.age < 40; });
  8530. * // => object for 'barney'
  8531. *
  8532. * // The `_.matches` iteratee shorthand.
  8533. * _.find(users, { 'age': 1, 'active': true });
  8534. * // => object for 'pebbles'
  8535. *
  8536. * // The `_.matchesProperty` iteratee shorthand.
  8537. * _.find(users, ['active', false]);
  8538. * // => object for 'fred'
  8539. *
  8540. * // The `_.property` iteratee shorthand.
  8541. * _.find(users, 'active');
  8542. * // => object for 'barney'
  8543. */
  8544. var find = createFind(findIndex);
  8545. /**
  8546. * This method is like `_.find` except that it iterates over elements of
  8547. * `collection` from right to left.
  8548. *
  8549. * @static
  8550. * @memberOf _
  8551. * @since 2.0.0
  8552. * @category Collection
  8553. * @param {Array|Object} collection The collection to inspect.
  8554. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8555. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8556. * @returns {*} Returns the matched element, else `undefined`.
  8557. * @example
  8558. *
  8559. * _.findLast([1, 2, 3, 4], function(n) {
  8560. * return n % 2 == 1;
  8561. * });
  8562. * // => 3
  8563. */
  8564. var findLast = createFind(findLastIndex);
  8565. /**
  8566. * Creates a flattened array of values by running each element in `collection`
  8567. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8568. * with three arguments: (value, index|key, collection).
  8569. *
  8570. * @static
  8571. * @memberOf _
  8572. * @since 4.0.0
  8573. * @category Collection
  8574. * @param {Array|Object} collection The collection to iterate over.
  8575. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8576. * @returns {Array} Returns the new flattened array.
  8577. * @example
  8578. *
  8579. * function duplicate(n) {
  8580. * return [n, n];
  8581. * }
  8582. *
  8583. * _.flatMap([1, 2], duplicate);
  8584. * // => [1, 1, 2, 2]
  8585. */
  8586. function flatMap(collection, iteratee) {
  8587. return baseFlatten(map(collection, iteratee), 1);
  8588. }
  8589. /**
  8590. * This method is like `_.flatMap` except that it recursively flattens the
  8591. * mapped results.
  8592. *
  8593. * @static
  8594. * @memberOf _
  8595. * @since 4.7.0
  8596. * @category Collection
  8597. * @param {Array|Object} collection The collection to iterate over.
  8598. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8599. * @returns {Array} Returns the new flattened array.
  8600. * @example
  8601. *
  8602. * function duplicate(n) {
  8603. * return [[[n, n]]];
  8604. * }
  8605. *
  8606. * _.flatMapDeep([1, 2], duplicate);
  8607. * // => [1, 1, 2, 2]
  8608. */
  8609. function flatMapDeep(collection, iteratee) {
  8610. return baseFlatten(map(collection, iteratee), INFINITY);
  8611. }
  8612. /**
  8613. * This method is like `_.flatMap` except that it recursively flattens the
  8614. * mapped results up to `depth` times.
  8615. *
  8616. * @static
  8617. * @memberOf _
  8618. * @since 4.7.0
  8619. * @category Collection
  8620. * @param {Array|Object} collection The collection to iterate over.
  8621. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8622. * @param {number} [depth=1] The maximum recursion depth.
  8623. * @returns {Array} Returns the new flattened array.
  8624. * @example
  8625. *
  8626. * function duplicate(n) {
  8627. * return [[[n, n]]];
  8628. * }
  8629. *
  8630. * _.flatMapDepth([1, 2], duplicate, 2);
  8631. * // => [[1, 1], [2, 2]]
  8632. */
  8633. function flatMapDepth(collection, iteratee, depth) {
  8634. depth = depth === undefined ? 1 : toInteger(depth);
  8635. return baseFlatten(map(collection, iteratee), depth);
  8636. }
  8637. /**
  8638. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8639. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8640. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8641. *
  8642. * **Note:** As with other "Collections" methods, objects with a "length"
  8643. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8644. * or `_.forOwn` for object iteration.
  8645. *
  8646. * @static
  8647. * @memberOf _
  8648. * @since 0.1.0
  8649. * @alias each
  8650. * @category Collection
  8651. * @param {Array|Object} collection The collection to iterate over.
  8652. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8653. * @returns {Array|Object} Returns `collection`.
  8654. * @see _.forEachRight
  8655. * @example
  8656. *
  8657. * _.forEach([1, 2], function(value) {
  8658. * console.log(value);
  8659. * });
  8660. * // => Logs `1` then `2`.
  8661. *
  8662. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8663. * console.log(key);
  8664. * });
  8665. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8666. */
  8667. function forEach(collection, iteratee) {
  8668. var func = isArray(collection) ? arrayEach : baseEach;
  8669. return func(collection, getIteratee(iteratee, 3));
  8670. }
  8671. /**
  8672. * This method is like `_.forEach` except that it iterates over elements of
  8673. * `collection` from right to left.
  8674. *
  8675. * @static
  8676. * @memberOf _
  8677. * @since 2.0.0
  8678. * @alias eachRight
  8679. * @category Collection
  8680. * @param {Array|Object} collection The collection to iterate over.
  8681. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8682. * @returns {Array|Object} Returns `collection`.
  8683. * @see _.forEach
  8684. * @example
  8685. *
  8686. * _.forEachRight([1, 2], function(value) {
  8687. * console.log(value);
  8688. * });
  8689. * // => Logs `2` then `1`.
  8690. */
  8691. function forEachRight(collection, iteratee) {
  8692. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8693. return func(collection, getIteratee(iteratee, 3));
  8694. }
  8695. /**
  8696. * Creates an object composed of keys generated from the results of running
  8697. * each element of `collection` thru `iteratee`. The order of grouped values
  8698. * is determined by the order they occur in `collection`. The corresponding
  8699. * value of each key is an array of elements responsible for generating the
  8700. * key. The iteratee is invoked with one argument: (value).
  8701. *
  8702. * @static
  8703. * @memberOf _
  8704. * @since 0.1.0
  8705. * @category Collection
  8706. * @param {Array|Object} collection The collection to iterate over.
  8707. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8708. * @returns {Object} Returns the composed aggregate object.
  8709. * @example
  8710. *
  8711. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8712. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8713. *
  8714. * // The `_.property` iteratee shorthand.
  8715. * _.groupBy(['one', 'two', 'three'], 'length');
  8716. * // => { '3': ['one', 'two'], '5': ['three'] }
  8717. */
  8718. var groupBy = createAggregator(function(result, value, key) {
  8719. if (hasOwnProperty.call(result, key)) {
  8720. result[key].push(value);
  8721. } else {
  8722. baseAssignValue(result, key, [value]);
  8723. }
  8724. });
  8725. /**
  8726. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8727. * checked for a substring of `value`, otherwise
  8728. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8729. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8730. * the offset from the end of `collection`.
  8731. *
  8732. * @static
  8733. * @memberOf _
  8734. * @since 0.1.0
  8735. * @category Collection
  8736. * @param {Array|Object|string} collection The collection to inspect.
  8737. * @param {*} value The value to search for.
  8738. * @param {number} [fromIndex=0] The index to search from.
  8739. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8740. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8741. * @example
  8742. *
  8743. * _.includes([1, 2, 3], 1);
  8744. * // => true
  8745. *
  8746. * _.includes([1, 2, 3], 1, 2);
  8747. * // => false
  8748. *
  8749. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8750. * // => true
  8751. *
  8752. * _.includes('abcd', 'bc');
  8753. * // => true
  8754. */
  8755. function includes(collection, value, fromIndex, guard) {
  8756. collection = isArrayLike(collection) ? collection : values(collection);
  8757. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8758. var length = collection.length;
  8759. if (fromIndex < 0) {
  8760. fromIndex = nativeMax(length + fromIndex, 0);
  8761. }
  8762. return isString(collection)
  8763. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8764. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8765. }
  8766. /**
  8767. * Invokes the method at `path` of each element in `collection`, returning
  8768. * an array of the results of each invoked method. Any additional arguments
  8769. * are provided to each invoked method. If `path` is a function, it's invoked
  8770. * for, and `this` bound to, each element in `collection`.
  8771. *
  8772. * @static
  8773. * @memberOf _
  8774. * @since 4.0.0
  8775. * @category Collection
  8776. * @param {Array|Object} collection The collection to iterate over.
  8777. * @param {Array|Function|string} path The path of the method to invoke or
  8778. * the function invoked per iteration.
  8779. * @param {...*} [args] The arguments to invoke each method with.
  8780. * @returns {Array} Returns the array of results.
  8781. * @example
  8782. *
  8783. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8784. * // => [[1, 5, 7], [1, 2, 3]]
  8785. *
  8786. * _.invokeMap([123, 456], String.prototype.split, '');
  8787. * // => [['1', '2', '3'], ['4', '5', '6']]
  8788. */
  8789. var invokeMap = baseRest(function(collection, path, args) {
  8790. var index = -1,
  8791. isFunc = typeof path == 'function',
  8792. result = isArrayLike(collection) ? Array(collection.length) : [];
  8793. baseEach(collection, function(value) {
  8794. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8795. });
  8796. return result;
  8797. });
  8798. /**
  8799. * Creates an object composed of keys generated from the results of running
  8800. * each element of `collection` thru `iteratee`. The corresponding value of
  8801. * each key is the last element responsible for generating the key. The
  8802. * iteratee is invoked with one argument: (value).
  8803. *
  8804. * @static
  8805. * @memberOf _
  8806. * @since 4.0.0
  8807. * @category Collection
  8808. * @param {Array|Object} collection The collection to iterate over.
  8809. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8810. * @returns {Object} Returns the composed aggregate object.
  8811. * @example
  8812. *
  8813. * var array = [
  8814. * { 'dir': 'left', 'code': 97 },
  8815. * { 'dir': 'right', 'code': 100 }
  8816. * ];
  8817. *
  8818. * _.keyBy(array, function(o) {
  8819. * return String.fromCharCode(o.code);
  8820. * });
  8821. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8822. *
  8823. * _.keyBy(array, 'dir');
  8824. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8825. */
  8826. var keyBy = createAggregator(function(result, value, key) {
  8827. baseAssignValue(result, key, value);
  8828. });
  8829. /**
  8830. * Creates an array of values by running each element in `collection` thru
  8831. * `iteratee`. The iteratee is invoked with three arguments:
  8832. * (value, index|key, collection).
  8833. *
  8834. * Many lodash methods are guarded to work as iteratees for methods like
  8835. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8836. *
  8837. * The guarded methods are:
  8838. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8839. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8840. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8841. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8842. *
  8843. * @static
  8844. * @memberOf _
  8845. * @since 0.1.0
  8846. * @category Collection
  8847. * @param {Array|Object} collection The collection to iterate over.
  8848. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8849. * @returns {Array} Returns the new mapped array.
  8850. * @example
  8851. *
  8852. * function square(n) {
  8853. * return n * n;
  8854. * }
  8855. *
  8856. * _.map([4, 8], square);
  8857. * // => [16, 64]
  8858. *
  8859. * _.map({ 'a': 4, 'b': 8 }, square);
  8860. * // => [16, 64] (iteration order is not guaranteed)
  8861. *
  8862. * var users = [
  8863. * { 'user': 'barney' },
  8864. * { 'user': 'fred' }
  8865. * ];
  8866. *
  8867. * // The `_.property` iteratee shorthand.
  8868. * _.map(users, 'user');
  8869. * // => ['barney', 'fred']
  8870. */
  8871. function map(collection, iteratee) {
  8872. var func = isArray(collection) ? arrayMap : baseMap;
  8873. return func(collection, getIteratee(iteratee, 3));
  8874. }
  8875. /**
  8876. * This method is like `_.sortBy` except that it allows specifying the sort
  8877. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8878. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8879. * descending or "asc" for ascending sort order of corresponding values.
  8880. *
  8881. * @static
  8882. * @memberOf _
  8883. * @since 4.0.0
  8884. * @category Collection
  8885. * @param {Array|Object} collection The collection to iterate over.
  8886. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8887. * The iteratees to sort by.
  8888. * @param {string[]} [orders] The sort orders of `iteratees`.
  8889. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8890. * @returns {Array} Returns the new sorted array.
  8891. * @example
  8892. *
  8893. * var users = [
  8894. * { 'user': 'fred', 'age': 48 },
  8895. * { 'user': 'barney', 'age': 34 },
  8896. * { 'user': 'fred', 'age': 40 },
  8897. * { 'user': 'barney', 'age': 36 }
  8898. * ];
  8899. *
  8900. * // Sort by `user` in ascending order and by `age` in descending order.
  8901. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8902. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8903. */
  8904. function orderBy(collection, iteratees, orders, guard) {
  8905. if (collection == null) {
  8906. return [];
  8907. }
  8908. if (!isArray(iteratees)) {
  8909. iteratees = iteratees == null ? [] : [iteratees];
  8910. }
  8911. orders = guard ? undefined : orders;
  8912. if (!isArray(orders)) {
  8913. orders = orders == null ? [] : [orders];
  8914. }
  8915. return baseOrderBy(collection, iteratees, orders);
  8916. }
  8917. /**
  8918. * Creates an array of elements split into two groups, the first of which
  8919. * contains elements `predicate` returns truthy for, the second of which
  8920. * contains elements `predicate` returns falsey for. The predicate is
  8921. * invoked with one argument: (value).
  8922. *
  8923. * @static
  8924. * @memberOf _
  8925. * @since 3.0.0
  8926. * @category Collection
  8927. * @param {Array|Object} collection The collection to iterate over.
  8928. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8929. * @returns {Array} Returns the array of grouped elements.
  8930. * @example
  8931. *
  8932. * var users = [
  8933. * { 'user': 'barney', 'age': 36, 'active': false },
  8934. * { 'user': 'fred', 'age': 40, 'active': true },
  8935. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8936. * ];
  8937. *
  8938. * _.partition(users, function(o) { return o.active; });
  8939. * // => objects for [['fred'], ['barney', 'pebbles']]
  8940. *
  8941. * // The `_.matches` iteratee shorthand.
  8942. * _.partition(users, { 'age': 1, 'active': false });
  8943. * // => objects for [['pebbles'], ['barney', 'fred']]
  8944. *
  8945. * // The `_.matchesProperty` iteratee shorthand.
  8946. * _.partition(users, ['active', false]);
  8947. * // => objects for [['barney', 'pebbles'], ['fred']]
  8948. *
  8949. * // The `_.property` iteratee shorthand.
  8950. * _.partition(users, 'active');
  8951. * // => objects for [['fred'], ['barney', 'pebbles']]
  8952. */
  8953. var partition = createAggregator(function(result, value, key) {
  8954. result[key ? 0 : 1].push(value);
  8955. }, function() { return [[], []]; });
  8956. /**
  8957. * Reduces `collection` to a value which is the accumulated result of running
  8958. * each element in `collection` thru `iteratee`, where each successive
  8959. * invocation is supplied the return value of the previous. If `accumulator`
  8960. * is not given, the first element of `collection` is used as the initial
  8961. * value. The iteratee is invoked with four arguments:
  8962. * (accumulator, value, index|key, collection).
  8963. *
  8964. * Many lodash methods are guarded to work as iteratees for methods like
  8965. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8966. *
  8967. * The guarded methods are:
  8968. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8969. * and `sortBy`
  8970. *
  8971. * @static
  8972. * @memberOf _
  8973. * @since 0.1.0
  8974. * @category Collection
  8975. * @param {Array|Object} collection The collection to iterate over.
  8976. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8977. * @param {*} [accumulator] The initial value.
  8978. * @returns {*} Returns the accumulated value.
  8979. * @see _.reduceRight
  8980. * @example
  8981. *
  8982. * _.reduce([1, 2], function(sum, n) {
  8983. * return sum + n;
  8984. * }, 0);
  8985. * // => 3
  8986. *
  8987. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8988. * (result[value] || (result[value] = [])).push(key);
  8989. * return result;
  8990. * }, {});
  8991. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8992. */
  8993. function reduce(collection, iteratee, accumulator) {
  8994. var func = isArray(collection) ? arrayReduce : baseReduce,
  8995. initAccum = arguments.length < 3;
  8996. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8997. }
  8998. /**
  8999. * This method is like `_.reduce` except that it iterates over elements of
  9000. * `collection` from right to left.
  9001. *
  9002. * @static
  9003. * @memberOf _
  9004. * @since 0.1.0
  9005. * @category Collection
  9006. * @param {Array|Object} collection The collection to iterate over.
  9007. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9008. * @param {*} [accumulator] The initial value.
  9009. * @returns {*} Returns the accumulated value.
  9010. * @see _.reduce
  9011. * @example
  9012. *
  9013. * var array = [[0, 1], [2, 3], [4, 5]];
  9014. *
  9015. * _.reduceRight(array, function(flattened, other) {
  9016. * return flattened.concat(other);
  9017. * }, []);
  9018. * // => [4, 5, 2, 3, 0, 1]
  9019. */
  9020. function reduceRight(collection, iteratee, accumulator) {
  9021. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9022. initAccum = arguments.length < 3;
  9023. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9024. }
  9025. /**
  9026. * The opposite of `_.filter`; this method returns the elements of `collection`
  9027. * that `predicate` does **not** return truthy for.
  9028. *
  9029. * @static
  9030. * @memberOf _
  9031. * @since 0.1.0
  9032. * @category Collection
  9033. * @param {Array|Object} collection The collection to iterate over.
  9034. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9035. * @returns {Array} Returns the new filtered array.
  9036. * @see _.filter
  9037. * @example
  9038. *
  9039. * var users = [
  9040. * { 'user': 'barney', 'age': 36, 'active': false },
  9041. * { 'user': 'fred', 'age': 40, 'active': true }
  9042. * ];
  9043. *
  9044. * _.reject(users, function(o) { return !o.active; });
  9045. * // => objects for ['fred']
  9046. *
  9047. * // The `_.matches` iteratee shorthand.
  9048. * _.reject(users, { 'age': 40, 'active': true });
  9049. * // => objects for ['barney']
  9050. *
  9051. * // The `_.matchesProperty` iteratee shorthand.
  9052. * _.reject(users, ['active', false]);
  9053. * // => objects for ['fred']
  9054. *
  9055. * // The `_.property` iteratee shorthand.
  9056. * _.reject(users, 'active');
  9057. * // => objects for ['barney']
  9058. */
  9059. function reject(collection, predicate) {
  9060. var func = isArray(collection) ? arrayFilter : baseFilter;
  9061. return func(collection, negate(getIteratee(predicate, 3)));
  9062. }
  9063. /**
  9064. * Gets a random element from `collection`.
  9065. *
  9066. * @static
  9067. * @memberOf _
  9068. * @since 2.0.0
  9069. * @category Collection
  9070. * @param {Array|Object} collection The collection to sample.
  9071. * @returns {*} Returns the random element.
  9072. * @example
  9073. *
  9074. * _.sample([1, 2, 3, 4]);
  9075. * // => 2
  9076. */
  9077. function sample(collection) {
  9078. var func = isArray(collection) ? arraySample : baseSample;
  9079. return func(collection);
  9080. }
  9081. /**
  9082. * Gets `n` random elements at unique keys from `collection` up to the
  9083. * size of `collection`.
  9084. *
  9085. * @static
  9086. * @memberOf _
  9087. * @since 4.0.0
  9088. * @category Collection
  9089. * @param {Array|Object} collection The collection to sample.
  9090. * @param {number} [n=1] The number of elements to sample.
  9091. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9092. * @returns {Array} Returns the random elements.
  9093. * @example
  9094. *
  9095. * _.sampleSize([1, 2, 3], 2);
  9096. * // => [3, 1]
  9097. *
  9098. * _.sampleSize([1, 2, 3], 4);
  9099. * // => [2, 3, 1]
  9100. */
  9101. function sampleSize(collection, n, guard) {
  9102. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9103. n = 1;
  9104. } else {
  9105. n = toInteger(n);
  9106. }
  9107. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9108. return func(collection, n);
  9109. }
  9110. /**
  9111. * Creates an array of shuffled values, using a version of the
  9112. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9113. *
  9114. * @static
  9115. * @memberOf _
  9116. * @since 0.1.0
  9117. * @category Collection
  9118. * @param {Array|Object} collection The collection to shuffle.
  9119. * @returns {Array} Returns the new shuffled array.
  9120. * @example
  9121. *
  9122. * _.shuffle([1, 2, 3, 4]);
  9123. * // => [4, 1, 3, 2]
  9124. */
  9125. function shuffle(collection) {
  9126. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9127. return func(collection);
  9128. }
  9129. /**
  9130. * Gets the size of `collection` by returning its length for array-like
  9131. * values or the number of own enumerable string keyed properties for objects.
  9132. *
  9133. * @static
  9134. * @memberOf _
  9135. * @since 0.1.0
  9136. * @category Collection
  9137. * @param {Array|Object|string} collection The collection to inspect.
  9138. * @returns {number} Returns the collection size.
  9139. * @example
  9140. *
  9141. * _.size([1, 2, 3]);
  9142. * // => 3
  9143. *
  9144. * _.size({ 'a': 1, 'b': 2 });
  9145. * // => 2
  9146. *
  9147. * _.size('pebbles');
  9148. * // => 7
  9149. */
  9150. function size(collection) {
  9151. if (collection == null) {
  9152. return 0;
  9153. }
  9154. if (isArrayLike(collection)) {
  9155. return isString(collection) ? stringSize(collection) : collection.length;
  9156. }
  9157. var tag = getTag(collection);
  9158. if (tag == mapTag || tag == setTag) {
  9159. return collection.size;
  9160. }
  9161. return baseKeys(collection).length;
  9162. }
  9163. /**
  9164. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9165. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9166. * invoked with three arguments: (value, index|key, collection).
  9167. *
  9168. * @static
  9169. * @memberOf _
  9170. * @since 0.1.0
  9171. * @category Collection
  9172. * @param {Array|Object} collection The collection to iterate over.
  9173. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9174. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9175. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9176. * else `false`.
  9177. * @example
  9178. *
  9179. * _.some([null, 0, 'yes', false], Boolean);
  9180. * // => true
  9181. *
  9182. * var users = [
  9183. * { 'user': 'barney', 'active': true },
  9184. * { 'user': 'fred', 'active': false }
  9185. * ];
  9186. *
  9187. * // The `_.matches` iteratee shorthand.
  9188. * _.some(users, { 'user': 'barney', 'active': false });
  9189. * // => false
  9190. *
  9191. * // The `_.matchesProperty` iteratee shorthand.
  9192. * _.some(users, ['active', false]);
  9193. * // => true
  9194. *
  9195. * // The `_.property` iteratee shorthand.
  9196. * _.some(users, 'active');
  9197. * // => true
  9198. */
  9199. function some(collection, predicate, guard) {
  9200. var func = isArray(collection) ? arraySome : baseSome;
  9201. if (guard && isIterateeCall(collection, predicate, guard)) {
  9202. predicate = undefined;
  9203. }
  9204. return func(collection, getIteratee(predicate, 3));
  9205. }
  9206. /**
  9207. * Creates an array of elements, sorted in ascending order by the results of
  9208. * running each element in a collection thru each iteratee. This method
  9209. * performs a stable sort, that is, it preserves the original sort order of
  9210. * equal elements. The iteratees are invoked with one argument: (value).
  9211. *
  9212. * @static
  9213. * @memberOf _
  9214. * @since 0.1.0
  9215. * @category Collection
  9216. * @param {Array|Object} collection The collection to iterate over.
  9217. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9218. * The iteratees to sort by.
  9219. * @returns {Array} Returns the new sorted array.
  9220. * @example
  9221. *
  9222. * var users = [
  9223. * { 'user': 'fred', 'age': 48 },
  9224. * { 'user': 'barney', 'age': 36 },
  9225. * { 'user': 'fred', 'age': 40 },
  9226. * { 'user': 'barney', 'age': 34 }
  9227. * ];
  9228. *
  9229. * _.sortBy(users, [function(o) { return o.user; }]);
  9230. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9231. *
  9232. * _.sortBy(users, ['user', 'age']);
  9233. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9234. */
  9235. var sortBy = baseRest(function(collection, iteratees) {
  9236. if (collection == null) {
  9237. return [];
  9238. }
  9239. var length = iteratees.length;
  9240. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9241. iteratees = [];
  9242. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9243. iteratees = [iteratees[0]];
  9244. }
  9245. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9246. });
  9247. /*------------------------------------------------------------------------*/
  9248. /**
  9249. * Gets the timestamp of the number of milliseconds that have elapsed since
  9250. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9251. *
  9252. * @static
  9253. * @memberOf _
  9254. * @since 2.4.0
  9255. * @category Date
  9256. * @returns {number} Returns the timestamp.
  9257. * @example
  9258. *
  9259. * _.defer(function(stamp) {
  9260. * console.log(_.now() - stamp);
  9261. * }, _.now());
  9262. * // => Logs the number of milliseconds it took for the deferred invocation.
  9263. */
  9264. var now = ctxNow || function() {
  9265. return root.Date.now();
  9266. };
  9267. /*------------------------------------------------------------------------*/
  9268. /**
  9269. * The opposite of `_.before`; this method creates a function that invokes
  9270. * `func` once it's called `n` or more times.
  9271. *
  9272. * @static
  9273. * @memberOf _
  9274. * @since 0.1.0
  9275. * @category Function
  9276. * @param {number} n The number of calls before `func` is invoked.
  9277. * @param {Function} func The function to restrict.
  9278. * @returns {Function} Returns the new restricted function.
  9279. * @example
  9280. *
  9281. * var saves = ['profile', 'settings'];
  9282. *
  9283. * var done = _.after(saves.length, function() {
  9284. * console.log('done saving!');
  9285. * });
  9286. *
  9287. * _.forEach(saves, function(type) {
  9288. * asyncSave({ 'type': type, 'complete': done });
  9289. * });
  9290. * // => Logs 'done saving!' after the two async saves have completed.
  9291. */
  9292. function after(n, func) {
  9293. if (typeof func != 'function') {
  9294. throw new TypeError(FUNC_ERROR_TEXT);
  9295. }
  9296. n = toInteger(n);
  9297. return function() {
  9298. if (--n < 1) {
  9299. return func.apply(this, arguments);
  9300. }
  9301. };
  9302. }
  9303. /**
  9304. * Creates a function that invokes `func`, with up to `n` arguments,
  9305. * ignoring any additional arguments.
  9306. *
  9307. * @static
  9308. * @memberOf _
  9309. * @since 3.0.0
  9310. * @category Function
  9311. * @param {Function} func The function to cap arguments for.
  9312. * @param {number} [n=func.length] The arity cap.
  9313. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9314. * @returns {Function} Returns the new capped function.
  9315. * @example
  9316. *
  9317. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9318. * // => [6, 8, 10]
  9319. */
  9320. function ary(func, n, guard) {
  9321. n = guard ? undefined : n;
  9322. n = (func && n == null) ? func.length : n;
  9323. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9324. }
  9325. /**
  9326. * Creates a function that invokes `func`, with the `this` binding and arguments
  9327. * of the created function, while it's called less than `n` times. Subsequent
  9328. * calls to the created function return the result of the last `func` invocation.
  9329. *
  9330. * @static
  9331. * @memberOf _
  9332. * @since 3.0.0
  9333. * @category Function
  9334. * @param {number} n The number of calls at which `func` is no longer invoked.
  9335. * @param {Function} func The function to restrict.
  9336. * @returns {Function} Returns the new restricted function.
  9337. * @example
  9338. *
  9339. * jQuery(element).on('click', _.before(5, addContactToList));
  9340. * // => Allows adding up to 4 contacts to the list.
  9341. */
  9342. function before(n, func) {
  9343. var result;
  9344. if (typeof func != 'function') {
  9345. throw new TypeError(FUNC_ERROR_TEXT);
  9346. }
  9347. n = toInteger(n);
  9348. return function() {
  9349. if (--n > 0) {
  9350. result = func.apply(this, arguments);
  9351. }
  9352. if (n <= 1) {
  9353. func = undefined;
  9354. }
  9355. return result;
  9356. };
  9357. }
  9358. /**
  9359. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9360. * and `partials` prepended to the arguments it receives.
  9361. *
  9362. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9363. * may be used as a placeholder for partially applied arguments.
  9364. *
  9365. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9366. * property of bound functions.
  9367. *
  9368. * @static
  9369. * @memberOf _
  9370. * @since 0.1.0
  9371. * @category Function
  9372. * @param {Function} func The function to bind.
  9373. * @param {*} thisArg The `this` binding of `func`.
  9374. * @param {...*} [partials] The arguments to be partially applied.
  9375. * @returns {Function} Returns the new bound function.
  9376. * @example
  9377. *
  9378. * function greet(greeting, punctuation) {
  9379. * return greeting + ' ' + this.user + punctuation;
  9380. * }
  9381. *
  9382. * var object = { 'user': 'fred' };
  9383. *
  9384. * var bound = _.bind(greet, object, 'hi');
  9385. * bound('!');
  9386. * // => 'hi fred!'
  9387. *
  9388. * // Bound with placeholders.
  9389. * var bound = _.bind(greet, object, _, '!');
  9390. * bound('hi');
  9391. * // => 'hi fred!'
  9392. */
  9393. var bind = baseRest(function(func, thisArg, partials) {
  9394. var bitmask = WRAP_BIND_FLAG;
  9395. if (partials.length) {
  9396. var holders = replaceHolders(partials, getHolder(bind));
  9397. bitmask |= WRAP_PARTIAL_FLAG;
  9398. }
  9399. return createWrap(func, bitmask, thisArg, partials, holders);
  9400. });
  9401. /**
  9402. * Creates a function that invokes the method at `object[key]` with `partials`
  9403. * prepended to the arguments it receives.
  9404. *
  9405. * This method differs from `_.bind` by allowing bound functions to reference
  9406. * methods that may be redefined or don't yet exist. See
  9407. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9408. * for more details.
  9409. *
  9410. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9411. * builds, may be used as a placeholder for partially applied arguments.
  9412. *
  9413. * @static
  9414. * @memberOf _
  9415. * @since 0.10.0
  9416. * @category Function
  9417. * @param {Object} object The object to invoke the method on.
  9418. * @param {string} key The key of the method.
  9419. * @param {...*} [partials] The arguments to be partially applied.
  9420. * @returns {Function} Returns the new bound function.
  9421. * @example
  9422. *
  9423. * var object = {
  9424. * 'user': 'fred',
  9425. * 'greet': function(greeting, punctuation) {
  9426. * return greeting + ' ' + this.user + punctuation;
  9427. * }
  9428. * };
  9429. *
  9430. * var bound = _.bindKey(object, 'greet', 'hi');
  9431. * bound('!');
  9432. * // => 'hi fred!'
  9433. *
  9434. * object.greet = function(greeting, punctuation) {
  9435. * return greeting + 'ya ' + this.user + punctuation;
  9436. * };
  9437. *
  9438. * bound('!');
  9439. * // => 'hiya fred!'
  9440. *
  9441. * // Bound with placeholders.
  9442. * var bound = _.bindKey(object, 'greet', _, '!');
  9443. * bound('hi');
  9444. * // => 'hiya fred!'
  9445. */
  9446. var bindKey = baseRest(function(object, key, partials) {
  9447. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9448. if (partials.length) {
  9449. var holders = replaceHolders(partials, getHolder(bindKey));
  9450. bitmask |= WRAP_PARTIAL_FLAG;
  9451. }
  9452. return createWrap(key, bitmask, object, partials, holders);
  9453. });
  9454. /**
  9455. * Creates a function that accepts arguments of `func` and either invokes
  9456. * `func` returning its result, if at least `arity` number of arguments have
  9457. * been provided, or returns a function that accepts the remaining `func`
  9458. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9459. * is not sufficient.
  9460. *
  9461. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9462. * may be used as a placeholder for provided arguments.
  9463. *
  9464. * **Note:** This method doesn't set the "length" property of curried functions.
  9465. *
  9466. * @static
  9467. * @memberOf _
  9468. * @since 2.0.0
  9469. * @category Function
  9470. * @param {Function} func The function to curry.
  9471. * @param {number} [arity=func.length] The arity of `func`.
  9472. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9473. * @returns {Function} Returns the new curried function.
  9474. * @example
  9475. *
  9476. * var abc = function(a, b, c) {
  9477. * return [a, b, c];
  9478. * };
  9479. *
  9480. * var curried = _.curry(abc);
  9481. *
  9482. * curried(1)(2)(3);
  9483. * // => [1, 2, 3]
  9484. *
  9485. * curried(1, 2)(3);
  9486. * // => [1, 2, 3]
  9487. *
  9488. * curried(1, 2, 3);
  9489. * // => [1, 2, 3]
  9490. *
  9491. * // Curried with placeholders.
  9492. * curried(1)(_, 3)(2);
  9493. * // => [1, 2, 3]
  9494. */
  9495. function curry(func, arity, guard) {
  9496. arity = guard ? undefined : arity;
  9497. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9498. result.placeholder = curry.placeholder;
  9499. return result;
  9500. }
  9501. /**
  9502. * This method is like `_.curry` except that arguments are applied to `func`
  9503. * in the manner of `_.partialRight` instead of `_.partial`.
  9504. *
  9505. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9506. * builds, may be used as a placeholder for provided arguments.
  9507. *
  9508. * **Note:** This method doesn't set the "length" property of curried functions.
  9509. *
  9510. * @static
  9511. * @memberOf _
  9512. * @since 3.0.0
  9513. * @category Function
  9514. * @param {Function} func The function to curry.
  9515. * @param {number} [arity=func.length] The arity of `func`.
  9516. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9517. * @returns {Function} Returns the new curried function.
  9518. * @example
  9519. *
  9520. * var abc = function(a, b, c) {
  9521. * return [a, b, c];
  9522. * };
  9523. *
  9524. * var curried = _.curryRight(abc);
  9525. *
  9526. * curried(3)(2)(1);
  9527. * // => [1, 2, 3]
  9528. *
  9529. * curried(2, 3)(1);
  9530. * // => [1, 2, 3]
  9531. *
  9532. * curried(1, 2, 3);
  9533. * // => [1, 2, 3]
  9534. *
  9535. * // Curried with placeholders.
  9536. * curried(3)(1, _)(2);
  9537. * // => [1, 2, 3]
  9538. */
  9539. function curryRight(func, arity, guard) {
  9540. arity = guard ? undefined : arity;
  9541. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9542. result.placeholder = curryRight.placeholder;
  9543. return result;
  9544. }
  9545. /**
  9546. * Creates a debounced function that delays invoking `func` until after `wait`
  9547. * milliseconds have elapsed since the last time the debounced function was
  9548. * invoked. The debounced function comes with a `cancel` method to cancel
  9549. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9550. * Provide `options` to indicate whether `func` should be invoked on the
  9551. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9552. * with the last arguments provided to the debounced function. Subsequent
  9553. * calls to the debounced function return the result of the last `func`
  9554. * invocation.
  9555. *
  9556. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9557. * invoked on the trailing edge of the timeout only if the debounced function
  9558. * is invoked more than once during the `wait` timeout.
  9559. *
  9560. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9561. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9562. *
  9563. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9564. * for details over the differences between `_.debounce` and `_.throttle`.
  9565. *
  9566. * @static
  9567. * @memberOf _
  9568. * @since 0.1.0
  9569. * @category Function
  9570. * @param {Function} func The function to debounce.
  9571. * @param {number} [wait=0] The number of milliseconds to delay.
  9572. * @param {Object} [options={}] The options object.
  9573. * @param {boolean} [options.leading=false]
  9574. * Specify invoking on the leading edge of the timeout.
  9575. * @param {number} [options.maxWait]
  9576. * The maximum time `func` is allowed to be delayed before it's invoked.
  9577. * @param {boolean} [options.trailing=true]
  9578. * Specify invoking on the trailing edge of the timeout.
  9579. * @returns {Function} Returns the new debounced function.
  9580. * @example
  9581. *
  9582. * // Avoid costly calculations while the window size is in flux.
  9583. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9584. *
  9585. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9586. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9587. * 'leading': true,
  9588. * 'trailing': false
  9589. * }));
  9590. *
  9591. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9592. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9593. * var source = new EventSource('/stream');
  9594. * jQuery(source).on('message', debounced);
  9595. *
  9596. * // Cancel the trailing debounced invocation.
  9597. * jQuery(window).on('popstate', debounced.cancel);
  9598. */
  9599. function debounce(func, wait, options) {
  9600. var lastArgs,
  9601. lastThis,
  9602. maxWait,
  9603. result,
  9604. timerId,
  9605. lastCallTime,
  9606. lastInvokeTime = 0,
  9607. leading = false,
  9608. maxing = false,
  9609. trailing = true;
  9610. if (typeof func != 'function') {
  9611. throw new TypeError(FUNC_ERROR_TEXT);
  9612. }
  9613. wait = toNumber(wait) || 0;
  9614. if (isObject(options)) {
  9615. leading = !!options.leading;
  9616. maxing = 'maxWait' in options;
  9617. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9618. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9619. }
  9620. function invokeFunc(time) {
  9621. var args = lastArgs,
  9622. thisArg = lastThis;
  9623. lastArgs = lastThis = undefined;
  9624. lastInvokeTime = time;
  9625. result = func.apply(thisArg, args);
  9626. return result;
  9627. }
  9628. function leadingEdge(time) {
  9629. // Reset any `maxWait` timer.
  9630. lastInvokeTime = time;
  9631. // Start the timer for the trailing edge.
  9632. timerId = setTimeout(timerExpired, wait);
  9633. // Invoke the leading edge.
  9634. return leading ? invokeFunc(time) : result;
  9635. }
  9636. function remainingWait(time) {
  9637. var timeSinceLastCall = time - lastCallTime,
  9638. timeSinceLastInvoke = time - lastInvokeTime,
  9639. result = wait - timeSinceLastCall;
  9640. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  9641. }
  9642. function shouldInvoke(time) {
  9643. var timeSinceLastCall = time - lastCallTime,
  9644. timeSinceLastInvoke = time - lastInvokeTime;
  9645. // Either this is the first call, activity has stopped and we're at the
  9646. // trailing edge, the system time has gone backwards and we're treating
  9647. // it as the trailing edge, or we've hit the `maxWait` limit.
  9648. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9649. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9650. }
  9651. function timerExpired() {
  9652. var time = now();
  9653. if (shouldInvoke(time)) {
  9654. return trailingEdge(time);
  9655. }
  9656. // Restart the timer.
  9657. timerId = setTimeout(timerExpired, remainingWait(time));
  9658. }
  9659. function trailingEdge(time) {
  9660. timerId = undefined;
  9661. // Only invoke if we have `lastArgs` which means `func` has been
  9662. // debounced at least once.
  9663. if (trailing && lastArgs) {
  9664. return invokeFunc(time);
  9665. }
  9666. lastArgs = lastThis = undefined;
  9667. return result;
  9668. }
  9669. function cancel() {
  9670. if (timerId !== undefined) {
  9671. clearTimeout(timerId);
  9672. }
  9673. lastInvokeTime = 0;
  9674. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9675. }
  9676. function flush() {
  9677. return timerId === undefined ? result : trailingEdge(now());
  9678. }
  9679. function debounced() {
  9680. var time = now(),
  9681. isInvoking = shouldInvoke(time);
  9682. lastArgs = arguments;
  9683. lastThis = this;
  9684. lastCallTime = time;
  9685. if (isInvoking) {
  9686. if (timerId === undefined) {
  9687. return leadingEdge(lastCallTime);
  9688. }
  9689. if (maxing) {
  9690. // Handle invocations in a tight loop.
  9691. timerId = setTimeout(timerExpired, wait);
  9692. return invokeFunc(lastCallTime);
  9693. }
  9694. }
  9695. if (timerId === undefined) {
  9696. timerId = setTimeout(timerExpired, wait);
  9697. }
  9698. return result;
  9699. }
  9700. debounced.cancel = cancel;
  9701. debounced.flush = flush;
  9702. return debounced;
  9703. }
  9704. /**
  9705. * Defers invoking the `func` until the current call stack has cleared. Any
  9706. * additional arguments are provided to `func` when it's invoked.
  9707. *
  9708. * @static
  9709. * @memberOf _
  9710. * @since 0.1.0
  9711. * @category Function
  9712. * @param {Function} func The function to defer.
  9713. * @param {...*} [args] The arguments to invoke `func` with.
  9714. * @returns {number} Returns the timer id.
  9715. * @example
  9716. *
  9717. * _.defer(function(text) {
  9718. * console.log(text);
  9719. * }, 'deferred');
  9720. * // => Logs 'deferred' after one millisecond.
  9721. */
  9722. var defer = baseRest(function(func, args) {
  9723. return baseDelay(func, 1, args);
  9724. });
  9725. /**
  9726. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9727. * provided to `func` when it's invoked.
  9728. *
  9729. * @static
  9730. * @memberOf _
  9731. * @since 0.1.0
  9732. * @category Function
  9733. * @param {Function} func The function to delay.
  9734. * @param {number} wait The number of milliseconds to delay invocation.
  9735. * @param {...*} [args] The arguments to invoke `func` with.
  9736. * @returns {number} Returns the timer id.
  9737. * @example
  9738. *
  9739. * _.delay(function(text) {
  9740. * console.log(text);
  9741. * }, 1000, 'later');
  9742. * // => Logs 'later' after one second.
  9743. */
  9744. var delay = baseRest(function(func, wait, args) {
  9745. return baseDelay(func, toNumber(wait) || 0, args);
  9746. });
  9747. /**
  9748. * Creates a function that invokes `func` with arguments reversed.
  9749. *
  9750. * @static
  9751. * @memberOf _
  9752. * @since 4.0.0
  9753. * @category Function
  9754. * @param {Function} func The function to flip arguments for.
  9755. * @returns {Function} Returns the new flipped function.
  9756. * @example
  9757. *
  9758. * var flipped = _.flip(function() {
  9759. * return _.toArray(arguments);
  9760. * });
  9761. *
  9762. * flipped('a', 'b', 'c', 'd');
  9763. * // => ['d', 'c', 'b', 'a']
  9764. */
  9765. function flip(func) {
  9766. return createWrap(func, WRAP_FLIP_FLAG);
  9767. }
  9768. /**
  9769. * Creates a function that memoizes the result of `func`. If `resolver` is
  9770. * provided, it determines the cache key for storing the result based on the
  9771. * arguments provided to the memoized function. By default, the first argument
  9772. * provided to the memoized function is used as the map cache key. The `func`
  9773. * is invoked with the `this` binding of the memoized function.
  9774. *
  9775. * **Note:** The cache is exposed as the `cache` property on the memoized
  9776. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9777. * constructor with one whose instances implement the
  9778. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9779. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9780. *
  9781. * @static
  9782. * @memberOf _
  9783. * @since 0.1.0
  9784. * @category Function
  9785. * @param {Function} func The function to have its output memoized.
  9786. * @param {Function} [resolver] The function to resolve the cache key.
  9787. * @returns {Function} Returns the new memoized function.
  9788. * @example
  9789. *
  9790. * var object = { 'a': 1, 'b': 2 };
  9791. * var other = { 'c': 3, 'd': 4 };
  9792. *
  9793. * var values = _.memoize(_.values);
  9794. * values(object);
  9795. * // => [1, 2]
  9796. *
  9797. * values(other);
  9798. * // => [3, 4]
  9799. *
  9800. * object.a = 2;
  9801. * values(object);
  9802. * // => [1, 2]
  9803. *
  9804. * // Modify the result cache.
  9805. * values.cache.set(object, ['a', 'b']);
  9806. * values(object);
  9807. * // => ['a', 'b']
  9808. *
  9809. * // Replace `_.memoize.Cache`.
  9810. * _.memoize.Cache = WeakMap;
  9811. */
  9812. function memoize(func, resolver) {
  9813. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9814. throw new TypeError(FUNC_ERROR_TEXT);
  9815. }
  9816. var memoized = function() {
  9817. var args = arguments,
  9818. key = resolver ? resolver.apply(this, args) : args[0],
  9819. cache = memoized.cache;
  9820. if (cache.has(key)) {
  9821. return cache.get(key);
  9822. }
  9823. var result = func.apply(this, args);
  9824. memoized.cache = cache.set(key, result) || cache;
  9825. return result;
  9826. };
  9827. memoized.cache = new (memoize.Cache || MapCache);
  9828. return memoized;
  9829. }
  9830. // Expose `MapCache`.
  9831. memoize.Cache = MapCache;
  9832. /**
  9833. * Creates a function that negates the result of the predicate `func`. The
  9834. * `func` predicate is invoked with the `this` binding and arguments of the
  9835. * created function.
  9836. *
  9837. * @static
  9838. * @memberOf _
  9839. * @since 3.0.0
  9840. * @category Function
  9841. * @param {Function} predicate The predicate to negate.
  9842. * @returns {Function} Returns the new negated function.
  9843. * @example
  9844. *
  9845. * function isEven(n) {
  9846. * return n % 2 == 0;
  9847. * }
  9848. *
  9849. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9850. * // => [1, 3, 5]
  9851. */
  9852. function negate(predicate) {
  9853. if (typeof predicate != 'function') {
  9854. throw new TypeError(FUNC_ERROR_TEXT);
  9855. }
  9856. return function() {
  9857. var args = arguments;
  9858. switch (args.length) {
  9859. case 0: return !predicate.call(this);
  9860. case 1: return !predicate.call(this, args[0]);
  9861. case 2: return !predicate.call(this, args[0], args[1]);
  9862. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9863. }
  9864. return !predicate.apply(this, args);
  9865. };
  9866. }
  9867. /**
  9868. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9869. * to the function return the value of the first invocation. The `func` is
  9870. * invoked with the `this` binding and arguments of the created function.
  9871. *
  9872. * @static
  9873. * @memberOf _
  9874. * @since 0.1.0
  9875. * @category Function
  9876. * @param {Function} func The function to restrict.
  9877. * @returns {Function} Returns the new restricted function.
  9878. * @example
  9879. *
  9880. * var initialize = _.once(createApplication);
  9881. * initialize();
  9882. * initialize();
  9883. * // => `createApplication` is invoked once
  9884. */
  9885. function once(func) {
  9886. return before(2, func);
  9887. }
  9888. /**
  9889. * Creates a function that invokes `func` with its arguments transformed.
  9890. *
  9891. * @static
  9892. * @since 4.0.0
  9893. * @memberOf _
  9894. * @category Function
  9895. * @param {Function} func The function to wrap.
  9896. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9897. * The argument transforms.
  9898. * @returns {Function} Returns the new function.
  9899. * @example
  9900. *
  9901. * function doubled(n) {
  9902. * return n * 2;
  9903. * }
  9904. *
  9905. * function square(n) {
  9906. * return n * n;
  9907. * }
  9908. *
  9909. * var func = _.overArgs(function(x, y) {
  9910. * return [x, y];
  9911. * }, [square, doubled]);
  9912. *
  9913. * func(9, 3);
  9914. * // => [81, 6]
  9915. *
  9916. * func(10, 5);
  9917. * // => [100, 10]
  9918. */
  9919. var overArgs = castRest(function(func, transforms) {
  9920. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9921. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9922. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9923. var funcsLength = transforms.length;
  9924. return baseRest(function(args) {
  9925. var index = -1,
  9926. length = nativeMin(args.length, funcsLength);
  9927. while (++index < length) {
  9928. args[index] = transforms[index].call(this, args[index]);
  9929. }
  9930. return apply(func, this, args);
  9931. });
  9932. });
  9933. /**
  9934. * Creates a function that invokes `func` with `partials` prepended to the
  9935. * arguments it receives. This method is like `_.bind` except it does **not**
  9936. * alter the `this` binding.
  9937. *
  9938. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9939. * builds, may be used as a placeholder for partially applied arguments.
  9940. *
  9941. * **Note:** This method doesn't set the "length" property of partially
  9942. * applied functions.
  9943. *
  9944. * @static
  9945. * @memberOf _
  9946. * @since 0.2.0
  9947. * @category Function
  9948. * @param {Function} func The function to partially apply arguments to.
  9949. * @param {...*} [partials] The arguments to be partially applied.
  9950. * @returns {Function} Returns the new partially applied function.
  9951. * @example
  9952. *
  9953. * function greet(greeting, name) {
  9954. * return greeting + ' ' + name;
  9955. * }
  9956. *
  9957. * var sayHelloTo = _.partial(greet, 'hello');
  9958. * sayHelloTo('fred');
  9959. * // => 'hello fred'
  9960. *
  9961. * // Partially applied with placeholders.
  9962. * var greetFred = _.partial(greet, _, 'fred');
  9963. * greetFred('hi');
  9964. * // => 'hi fred'
  9965. */
  9966. var partial = baseRest(function(func, partials) {
  9967. var holders = replaceHolders(partials, getHolder(partial));
  9968. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9969. });
  9970. /**
  9971. * This method is like `_.partial` except that partially applied arguments
  9972. * are appended to the arguments it receives.
  9973. *
  9974. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9975. * builds, may be used as a placeholder for partially applied arguments.
  9976. *
  9977. * **Note:** This method doesn't set the "length" property of partially
  9978. * applied functions.
  9979. *
  9980. * @static
  9981. * @memberOf _
  9982. * @since 1.0.0
  9983. * @category Function
  9984. * @param {Function} func The function to partially apply arguments to.
  9985. * @param {...*} [partials] The arguments to be partially applied.
  9986. * @returns {Function} Returns the new partially applied function.
  9987. * @example
  9988. *
  9989. * function greet(greeting, name) {
  9990. * return greeting + ' ' + name;
  9991. * }
  9992. *
  9993. * var greetFred = _.partialRight(greet, 'fred');
  9994. * greetFred('hi');
  9995. * // => 'hi fred'
  9996. *
  9997. * // Partially applied with placeholders.
  9998. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9999. * sayHelloTo('fred');
  10000. * // => 'hello fred'
  10001. */
  10002. var partialRight = baseRest(function(func, partials) {
  10003. var holders = replaceHolders(partials, getHolder(partialRight));
  10004. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10005. });
  10006. /**
  10007. * Creates a function that invokes `func` with arguments arranged according
  10008. * to the specified `indexes` where the argument value at the first index is
  10009. * provided as the first argument, the argument value at the second index is
  10010. * provided as the second argument, and so on.
  10011. *
  10012. * @static
  10013. * @memberOf _
  10014. * @since 3.0.0
  10015. * @category Function
  10016. * @param {Function} func The function to rearrange arguments for.
  10017. * @param {...(number|number[])} indexes The arranged argument indexes.
  10018. * @returns {Function} Returns the new function.
  10019. * @example
  10020. *
  10021. * var rearged = _.rearg(function(a, b, c) {
  10022. * return [a, b, c];
  10023. * }, [2, 0, 1]);
  10024. *
  10025. * rearged('b', 'c', 'a')
  10026. * // => ['a', 'b', 'c']
  10027. */
  10028. var rearg = flatRest(function(func, indexes) {
  10029. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10030. });
  10031. /**
  10032. * Creates a function that invokes `func` with the `this` binding of the
  10033. * created function and arguments from `start` and beyond provided as
  10034. * an array.
  10035. *
  10036. * **Note:** This method is based on the
  10037. * [rest parameter](https://mdn.io/rest_parameters).
  10038. *
  10039. * @static
  10040. * @memberOf _
  10041. * @since 4.0.0
  10042. * @category Function
  10043. * @param {Function} func The function to apply a rest parameter to.
  10044. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10045. * @returns {Function} Returns the new function.
  10046. * @example
  10047. *
  10048. * var say = _.rest(function(what, names) {
  10049. * return what + ' ' + _.initial(names).join(', ') +
  10050. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10051. * });
  10052. *
  10053. * say('hello', 'fred', 'barney', 'pebbles');
  10054. * // => 'hello fred, barney, & pebbles'
  10055. */
  10056. function rest(func, start) {
  10057. if (typeof func != 'function') {
  10058. throw new TypeError(FUNC_ERROR_TEXT);
  10059. }
  10060. start = start === undefined ? start : toInteger(start);
  10061. return baseRest(func, start);
  10062. }
  10063. /**
  10064. * Creates a function that invokes `func` with the `this` binding of the
  10065. * create function and an array of arguments much like
  10066. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10067. *
  10068. * **Note:** This method is based on the
  10069. * [spread operator](https://mdn.io/spread_operator).
  10070. *
  10071. * @static
  10072. * @memberOf _
  10073. * @since 3.2.0
  10074. * @category Function
  10075. * @param {Function} func The function to spread arguments over.
  10076. * @param {number} [start=0] The start position of the spread.
  10077. * @returns {Function} Returns the new function.
  10078. * @example
  10079. *
  10080. * var say = _.spread(function(who, what) {
  10081. * return who + ' says ' + what;
  10082. * });
  10083. *
  10084. * say(['fred', 'hello']);
  10085. * // => 'fred says hello'
  10086. *
  10087. * var numbers = Promise.all([
  10088. * Promise.resolve(40),
  10089. * Promise.resolve(36)
  10090. * ]);
  10091. *
  10092. * numbers.then(_.spread(function(x, y) {
  10093. * return x + y;
  10094. * }));
  10095. * // => a Promise of 76
  10096. */
  10097. function spread(func, start) {
  10098. if (typeof func != 'function') {
  10099. throw new TypeError(FUNC_ERROR_TEXT);
  10100. }
  10101. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10102. return baseRest(function(args) {
  10103. var array = args[start],
  10104. otherArgs = castSlice(args, 0, start);
  10105. if (array) {
  10106. arrayPush(otherArgs, array);
  10107. }
  10108. return apply(func, this, otherArgs);
  10109. });
  10110. }
  10111. /**
  10112. * Creates a throttled function that only invokes `func` at most once per
  10113. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10114. * method to cancel delayed `func` invocations and a `flush` method to
  10115. * immediately invoke them. Provide `options` to indicate whether `func`
  10116. * should be invoked on the leading and/or trailing edge of the `wait`
  10117. * timeout. The `func` is invoked with the last arguments provided to the
  10118. * throttled function. Subsequent calls to the throttled function return the
  10119. * result of the last `func` invocation.
  10120. *
  10121. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10122. * invoked on the trailing edge of the timeout only if the throttled function
  10123. * is invoked more than once during the `wait` timeout.
  10124. *
  10125. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10126. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10127. *
  10128. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10129. * for details over the differences between `_.throttle` and `_.debounce`.
  10130. *
  10131. * @static
  10132. * @memberOf _
  10133. * @since 0.1.0
  10134. * @category Function
  10135. * @param {Function} func The function to throttle.
  10136. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10137. * @param {Object} [options={}] The options object.
  10138. * @param {boolean} [options.leading=true]
  10139. * Specify invoking on the leading edge of the timeout.
  10140. * @param {boolean} [options.trailing=true]
  10141. * Specify invoking on the trailing edge of the timeout.
  10142. * @returns {Function} Returns the new throttled function.
  10143. * @example
  10144. *
  10145. * // Avoid excessively updating the position while scrolling.
  10146. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10147. *
  10148. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10149. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10150. * jQuery(element).on('click', throttled);
  10151. *
  10152. * // Cancel the trailing throttled invocation.
  10153. * jQuery(window).on('popstate', throttled.cancel);
  10154. */
  10155. function throttle(func, wait, options) {
  10156. var leading = true,
  10157. trailing = true;
  10158. if (typeof func != 'function') {
  10159. throw new TypeError(FUNC_ERROR_TEXT);
  10160. }
  10161. if (isObject(options)) {
  10162. leading = 'leading' in options ? !!options.leading : leading;
  10163. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10164. }
  10165. return debounce(func, wait, {
  10166. 'leading': leading,
  10167. 'maxWait': wait,
  10168. 'trailing': trailing
  10169. });
  10170. }
  10171. /**
  10172. * Creates a function that accepts up to one argument, ignoring any
  10173. * additional arguments.
  10174. *
  10175. * @static
  10176. * @memberOf _
  10177. * @since 4.0.0
  10178. * @category Function
  10179. * @param {Function} func The function to cap arguments for.
  10180. * @returns {Function} Returns the new capped function.
  10181. * @example
  10182. *
  10183. * _.map(['6', '8', '10'], _.unary(parseInt));
  10184. * // => [6, 8, 10]
  10185. */
  10186. function unary(func) {
  10187. return ary(func, 1);
  10188. }
  10189. /**
  10190. * Creates a function that provides `value` to `wrapper` as its first
  10191. * argument. Any additional arguments provided to the function are appended
  10192. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10193. * binding of the created function.
  10194. *
  10195. * @static
  10196. * @memberOf _
  10197. * @since 0.1.0
  10198. * @category Function
  10199. * @param {*} value The value to wrap.
  10200. * @param {Function} [wrapper=identity] The wrapper function.
  10201. * @returns {Function} Returns the new function.
  10202. * @example
  10203. *
  10204. * var p = _.wrap(_.escape, function(func, text) {
  10205. * return '<p>' + func(text) + '</p>';
  10206. * });
  10207. *
  10208. * p('fred, barney, & pebbles');
  10209. * // => '<p>fred, barney, &amp; pebbles</p>'
  10210. */
  10211. function wrap(value, wrapper) {
  10212. return partial(castFunction(wrapper), value);
  10213. }
  10214. /*------------------------------------------------------------------------*/
  10215. /**
  10216. * Casts `value` as an array if it's not one.
  10217. *
  10218. * @static
  10219. * @memberOf _
  10220. * @since 4.4.0
  10221. * @category Lang
  10222. * @param {*} value The value to inspect.
  10223. * @returns {Array} Returns the cast array.
  10224. * @example
  10225. *
  10226. * _.castArray(1);
  10227. * // => [1]
  10228. *
  10229. * _.castArray({ 'a': 1 });
  10230. * // => [{ 'a': 1 }]
  10231. *
  10232. * _.castArray('abc');
  10233. * // => ['abc']
  10234. *
  10235. * _.castArray(null);
  10236. * // => [null]
  10237. *
  10238. * _.castArray(undefined);
  10239. * // => [undefined]
  10240. *
  10241. * _.castArray();
  10242. * // => []
  10243. *
  10244. * var array = [1, 2, 3];
  10245. * console.log(_.castArray(array) === array);
  10246. * // => true
  10247. */
  10248. function castArray() {
  10249. if (!arguments.length) {
  10250. return [];
  10251. }
  10252. var value = arguments[0];
  10253. return isArray(value) ? value : [value];
  10254. }
  10255. /**
  10256. * Creates a shallow clone of `value`.
  10257. *
  10258. * **Note:** This method is loosely based on the
  10259. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10260. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10261. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10262. * arrays. The own enumerable properties of `arguments` objects are cloned
  10263. * as plain objects. An empty object is returned for uncloneable values such
  10264. * as error objects, functions, DOM nodes, and WeakMaps.
  10265. *
  10266. * @static
  10267. * @memberOf _
  10268. * @since 0.1.0
  10269. * @category Lang
  10270. * @param {*} value The value to clone.
  10271. * @returns {*} Returns the cloned value.
  10272. * @see _.cloneDeep
  10273. * @example
  10274. *
  10275. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10276. *
  10277. * var shallow = _.clone(objects);
  10278. * console.log(shallow[0] === objects[0]);
  10279. * // => true
  10280. */
  10281. function clone(value) {
  10282. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10283. }
  10284. /**
  10285. * This method is like `_.clone` except that it accepts `customizer` which
  10286. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10287. * cloning is handled by the method instead. The `customizer` is invoked with
  10288. * up to four arguments; (value [, index|key, object, stack]).
  10289. *
  10290. * @static
  10291. * @memberOf _
  10292. * @since 4.0.0
  10293. * @category Lang
  10294. * @param {*} value The value to clone.
  10295. * @param {Function} [customizer] The function to customize cloning.
  10296. * @returns {*} Returns the cloned value.
  10297. * @see _.cloneDeepWith
  10298. * @example
  10299. *
  10300. * function customizer(value) {
  10301. * if (_.isElement(value)) {
  10302. * return value.cloneNode(false);
  10303. * }
  10304. * }
  10305. *
  10306. * var el = _.cloneWith(document.body, customizer);
  10307. *
  10308. * console.log(el === document.body);
  10309. * // => false
  10310. * console.log(el.nodeName);
  10311. * // => 'BODY'
  10312. * console.log(el.childNodes.length);
  10313. * // => 0
  10314. */
  10315. function cloneWith(value, customizer) {
  10316. customizer = typeof customizer == 'function' ? customizer : undefined;
  10317. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10318. }
  10319. /**
  10320. * This method is like `_.clone` except that it recursively clones `value`.
  10321. *
  10322. * @static
  10323. * @memberOf _
  10324. * @since 1.0.0
  10325. * @category Lang
  10326. * @param {*} value The value to recursively clone.
  10327. * @returns {*} Returns the deep cloned value.
  10328. * @see _.clone
  10329. * @example
  10330. *
  10331. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10332. *
  10333. * var deep = _.cloneDeep(objects);
  10334. * console.log(deep[0] === objects[0]);
  10335. * // => false
  10336. */
  10337. function cloneDeep(value) {
  10338. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10339. }
  10340. /**
  10341. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10342. *
  10343. * @static
  10344. * @memberOf _
  10345. * @since 4.0.0
  10346. * @category Lang
  10347. * @param {*} value The value to recursively clone.
  10348. * @param {Function} [customizer] The function to customize cloning.
  10349. * @returns {*} Returns the deep cloned value.
  10350. * @see _.cloneWith
  10351. * @example
  10352. *
  10353. * function customizer(value) {
  10354. * if (_.isElement(value)) {
  10355. * return value.cloneNode(true);
  10356. * }
  10357. * }
  10358. *
  10359. * var el = _.cloneDeepWith(document.body, customizer);
  10360. *
  10361. * console.log(el === document.body);
  10362. * // => false
  10363. * console.log(el.nodeName);
  10364. * // => 'BODY'
  10365. * console.log(el.childNodes.length);
  10366. * // => 20
  10367. */
  10368. function cloneDeepWith(value, customizer) {
  10369. customizer = typeof customizer == 'function' ? customizer : undefined;
  10370. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10371. }
  10372. /**
  10373. * Checks if `object` conforms to `source` by invoking the predicate
  10374. * properties of `source` with the corresponding property values of `object`.
  10375. *
  10376. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10377. * partially applied.
  10378. *
  10379. * @static
  10380. * @memberOf _
  10381. * @since 4.14.0
  10382. * @category Lang
  10383. * @param {Object} object The object to inspect.
  10384. * @param {Object} source The object of property predicates to conform to.
  10385. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10386. * @example
  10387. *
  10388. * var object = { 'a': 1, 'b': 2 };
  10389. *
  10390. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10391. * // => true
  10392. *
  10393. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10394. * // => false
  10395. */
  10396. function conformsTo(object, source) {
  10397. return source == null || baseConformsTo(object, source, keys(source));
  10398. }
  10399. /**
  10400. * Performs a
  10401. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10402. * comparison between two values to determine if they are equivalent.
  10403. *
  10404. * @static
  10405. * @memberOf _
  10406. * @since 4.0.0
  10407. * @category Lang
  10408. * @param {*} value The value to compare.
  10409. * @param {*} other The other value to compare.
  10410. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10411. * @example
  10412. *
  10413. * var object = { 'a': 1 };
  10414. * var other = { 'a': 1 };
  10415. *
  10416. * _.eq(object, object);
  10417. * // => true
  10418. *
  10419. * _.eq(object, other);
  10420. * // => false
  10421. *
  10422. * _.eq('a', 'a');
  10423. * // => true
  10424. *
  10425. * _.eq('a', Object('a'));
  10426. * // => false
  10427. *
  10428. * _.eq(NaN, NaN);
  10429. * // => true
  10430. */
  10431. function eq(value, other) {
  10432. return value === other || (value !== value && other !== other);
  10433. }
  10434. /**
  10435. * Checks if `value` is greater than `other`.
  10436. *
  10437. * @static
  10438. * @memberOf _
  10439. * @since 3.9.0
  10440. * @category Lang
  10441. * @param {*} value The value to compare.
  10442. * @param {*} other The other value to compare.
  10443. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10444. * else `false`.
  10445. * @see _.lt
  10446. * @example
  10447. *
  10448. * _.gt(3, 1);
  10449. * // => true
  10450. *
  10451. * _.gt(3, 3);
  10452. * // => false
  10453. *
  10454. * _.gt(1, 3);
  10455. * // => false
  10456. */
  10457. var gt = createRelationalOperation(baseGt);
  10458. /**
  10459. * Checks if `value` is greater than or equal to `other`.
  10460. *
  10461. * @static
  10462. * @memberOf _
  10463. * @since 3.9.0
  10464. * @category Lang
  10465. * @param {*} value The value to compare.
  10466. * @param {*} other The other value to compare.
  10467. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10468. * `other`, else `false`.
  10469. * @see _.lte
  10470. * @example
  10471. *
  10472. * _.gte(3, 1);
  10473. * // => true
  10474. *
  10475. * _.gte(3, 3);
  10476. * // => true
  10477. *
  10478. * _.gte(1, 3);
  10479. * // => false
  10480. */
  10481. var gte = createRelationalOperation(function(value, other) {
  10482. return value >= other;
  10483. });
  10484. /**
  10485. * Checks if `value` is likely an `arguments` object.
  10486. *
  10487. * @static
  10488. * @memberOf _
  10489. * @since 0.1.0
  10490. * @category Lang
  10491. * @param {*} value The value to check.
  10492. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10493. * else `false`.
  10494. * @example
  10495. *
  10496. * _.isArguments(function() { return arguments; }());
  10497. * // => true
  10498. *
  10499. * _.isArguments([1, 2, 3]);
  10500. * // => false
  10501. */
  10502. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10503. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10504. !propertyIsEnumerable.call(value, 'callee');
  10505. };
  10506. /**
  10507. * Checks if `value` is classified as an `Array` object.
  10508. *
  10509. * @static
  10510. * @memberOf _
  10511. * @since 0.1.0
  10512. * @category Lang
  10513. * @param {*} value The value to check.
  10514. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10515. * @example
  10516. *
  10517. * _.isArray([1, 2, 3]);
  10518. * // => true
  10519. *
  10520. * _.isArray(document.body.children);
  10521. * // => false
  10522. *
  10523. * _.isArray('abc');
  10524. * // => false
  10525. *
  10526. * _.isArray(_.noop);
  10527. * // => false
  10528. */
  10529. var isArray = Array.isArray;
  10530. /**
  10531. * Checks if `value` is classified as an `ArrayBuffer` object.
  10532. *
  10533. * @static
  10534. * @memberOf _
  10535. * @since 4.3.0
  10536. * @category Lang
  10537. * @param {*} value The value to check.
  10538. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10539. * @example
  10540. *
  10541. * _.isArrayBuffer(new ArrayBuffer(2));
  10542. * // => true
  10543. *
  10544. * _.isArrayBuffer(new Array(2));
  10545. * // => false
  10546. */
  10547. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10548. /**
  10549. * Checks if `value` is array-like. A value is considered array-like if it's
  10550. * not a function and has a `value.length` that's an integer greater than or
  10551. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10552. *
  10553. * @static
  10554. * @memberOf _
  10555. * @since 4.0.0
  10556. * @category Lang
  10557. * @param {*} value The value to check.
  10558. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10559. * @example
  10560. *
  10561. * _.isArrayLike([1, 2, 3]);
  10562. * // => true
  10563. *
  10564. * _.isArrayLike(document.body.children);
  10565. * // => true
  10566. *
  10567. * _.isArrayLike('abc');
  10568. * // => true
  10569. *
  10570. * _.isArrayLike(_.noop);
  10571. * // => false
  10572. */
  10573. function isArrayLike(value) {
  10574. return value != null && isLength(value.length) && !isFunction(value);
  10575. }
  10576. /**
  10577. * This method is like `_.isArrayLike` except that it also checks if `value`
  10578. * is an object.
  10579. *
  10580. * @static
  10581. * @memberOf _
  10582. * @since 4.0.0
  10583. * @category Lang
  10584. * @param {*} value The value to check.
  10585. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10586. * else `false`.
  10587. * @example
  10588. *
  10589. * _.isArrayLikeObject([1, 2, 3]);
  10590. * // => true
  10591. *
  10592. * _.isArrayLikeObject(document.body.children);
  10593. * // => true
  10594. *
  10595. * _.isArrayLikeObject('abc');
  10596. * // => false
  10597. *
  10598. * _.isArrayLikeObject(_.noop);
  10599. * // => false
  10600. */
  10601. function isArrayLikeObject(value) {
  10602. return isObjectLike(value) && isArrayLike(value);
  10603. }
  10604. /**
  10605. * Checks if `value` is classified as a boolean primitive or object.
  10606. *
  10607. * @static
  10608. * @memberOf _
  10609. * @since 0.1.0
  10610. * @category Lang
  10611. * @param {*} value The value to check.
  10612. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10613. * @example
  10614. *
  10615. * _.isBoolean(false);
  10616. * // => true
  10617. *
  10618. * _.isBoolean(null);
  10619. * // => false
  10620. */
  10621. function isBoolean(value) {
  10622. return value === true || value === false ||
  10623. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10624. }
  10625. /**
  10626. * Checks if `value` is a buffer.
  10627. *
  10628. * @static
  10629. * @memberOf _
  10630. * @since 4.3.0
  10631. * @category Lang
  10632. * @param {*} value The value to check.
  10633. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10634. * @example
  10635. *
  10636. * _.isBuffer(new Buffer(2));
  10637. * // => true
  10638. *
  10639. * _.isBuffer(new Uint8Array(2));
  10640. * // => false
  10641. */
  10642. var isBuffer = nativeIsBuffer || stubFalse;
  10643. /**
  10644. * Checks if `value` is classified as a `Date` object.
  10645. *
  10646. * @static
  10647. * @memberOf _
  10648. * @since 0.1.0
  10649. * @category Lang
  10650. * @param {*} value The value to check.
  10651. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10652. * @example
  10653. *
  10654. * _.isDate(new Date);
  10655. * // => true
  10656. *
  10657. * _.isDate('Mon April 23 2012');
  10658. * // => false
  10659. */
  10660. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10661. /**
  10662. * Checks if `value` is likely a DOM element.
  10663. *
  10664. * @static
  10665. * @memberOf _
  10666. * @since 0.1.0
  10667. * @category Lang
  10668. * @param {*} value The value to check.
  10669. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10670. * @example
  10671. *
  10672. * _.isElement(document.body);
  10673. * // => true
  10674. *
  10675. * _.isElement('<body>');
  10676. * // => false
  10677. */
  10678. function isElement(value) {
  10679. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10680. }
  10681. /**
  10682. * Checks if `value` is an empty object, collection, map, or set.
  10683. *
  10684. * Objects are considered empty if they have no own enumerable string keyed
  10685. * properties.
  10686. *
  10687. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10688. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10689. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10690. *
  10691. * @static
  10692. * @memberOf _
  10693. * @since 0.1.0
  10694. * @category Lang
  10695. * @param {*} value The value to check.
  10696. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10697. * @example
  10698. *
  10699. * _.isEmpty(null);
  10700. * // => true
  10701. *
  10702. * _.isEmpty(true);
  10703. * // => true
  10704. *
  10705. * _.isEmpty(1);
  10706. * // => true
  10707. *
  10708. * _.isEmpty([1, 2, 3]);
  10709. * // => false
  10710. *
  10711. * _.isEmpty({ 'a': 1 });
  10712. * // => false
  10713. */
  10714. function isEmpty(value) {
  10715. if (value == null) {
  10716. return true;
  10717. }
  10718. if (isArrayLike(value) &&
  10719. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10720. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10721. return !value.length;
  10722. }
  10723. var tag = getTag(value);
  10724. if (tag == mapTag || tag == setTag) {
  10725. return !value.size;
  10726. }
  10727. if (isPrototype(value)) {
  10728. return !baseKeys(value).length;
  10729. }
  10730. for (var key in value) {
  10731. if (hasOwnProperty.call(value, key)) {
  10732. return false;
  10733. }
  10734. }
  10735. return true;
  10736. }
  10737. /**
  10738. * Performs a deep comparison between two values to determine if they are
  10739. * equivalent.
  10740. *
  10741. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10742. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10743. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10744. * by their own, not inherited, enumerable properties. Functions and DOM
  10745. * nodes are compared by strict equality, i.e. `===`.
  10746. *
  10747. * @static
  10748. * @memberOf _
  10749. * @since 0.1.0
  10750. * @category Lang
  10751. * @param {*} value The value to compare.
  10752. * @param {*} other The other value to compare.
  10753. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10754. * @example
  10755. *
  10756. * var object = { 'a': 1 };
  10757. * var other = { 'a': 1 };
  10758. *
  10759. * _.isEqual(object, other);
  10760. * // => true
  10761. *
  10762. * object === other;
  10763. * // => false
  10764. */
  10765. function isEqual(value, other) {
  10766. return baseIsEqual(value, other);
  10767. }
  10768. /**
  10769. * This method is like `_.isEqual` except that it accepts `customizer` which
  10770. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10771. * are handled by the method instead. The `customizer` is invoked with up to
  10772. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10773. *
  10774. * @static
  10775. * @memberOf _
  10776. * @since 4.0.0
  10777. * @category Lang
  10778. * @param {*} value The value to compare.
  10779. * @param {*} other The other value to compare.
  10780. * @param {Function} [customizer] The function to customize comparisons.
  10781. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10782. * @example
  10783. *
  10784. * function isGreeting(value) {
  10785. * return /^h(?:i|ello)$/.test(value);
  10786. * }
  10787. *
  10788. * function customizer(objValue, othValue) {
  10789. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10790. * return true;
  10791. * }
  10792. * }
  10793. *
  10794. * var array = ['hello', 'goodbye'];
  10795. * var other = ['hi', 'goodbye'];
  10796. *
  10797. * _.isEqualWith(array, other, customizer);
  10798. * // => true
  10799. */
  10800. function isEqualWith(value, other, customizer) {
  10801. customizer = typeof customizer == 'function' ? customizer : undefined;
  10802. var result = customizer ? customizer(value, other) : undefined;
  10803. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10804. }
  10805. /**
  10806. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10807. * `SyntaxError`, `TypeError`, or `URIError` object.
  10808. *
  10809. * @static
  10810. * @memberOf _
  10811. * @since 3.0.0
  10812. * @category Lang
  10813. * @param {*} value The value to check.
  10814. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10815. * @example
  10816. *
  10817. * _.isError(new Error);
  10818. * // => true
  10819. *
  10820. * _.isError(Error);
  10821. * // => false
  10822. */
  10823. function isError(value) {
  10824. if (!isObjectLike(value)) {
  10825. return false;
  10826. }
  10827. var tag = baseGetTag(value);
  10828. return tag == errorTag || tag == domExcTag ||
  10829. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10830. }
  10831. /**
  10832. * Checks if `value` is a finite primitive number.
  10833. *
  10834. * **Note:** This method is based on
  10835. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10836. *
  10837. * @static
  10838. * @memberOf _
  10839. * @since 0.1.0
  10840. * @category Lang
  10841. * @param {*} value The value to check.
  10842. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10843. * @example
  10844. *
  10845. * _.isFinite(3);
  10846. * // => true
  10847. *
  10848. * _.isFinite(Number.MIN_VALUE);
  10849. * // => true
  10850. *
  10851. * _.isFinite(Infinity);
  10852. * // => false
  10853. *
  10854. * _.isFinite('3');
  10855. * // => false
  10856. */
  10857. function isFinite(value) {
  10858. return typeof value == 'number' && nativeIsFinite(value);
  10859. }
  10860. /**
  10861. * Checks if `value` is classified as a `Function` object.
  10862. *
  10863. * @static
  10864. * @memberOf _
  10865. * @since 0.1.0
  10866. * @category Lang
  10867. * @param {*} value The value to check.
  10868. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10869. * @example
  10870. *
  10871. * _.isFunction(_);
  10872. * // => true
  10873. *
  10874. * _.isFunction(/abc/);
  10875. * // => false
  10876. */
  10877. function isFunction(value) {
  10878. if (!isObject(value)) {
  10879. return false;
  10880. }
  10881. // The use of `Object#toString` avoids issues with the `typeof` operator
  10882. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10883. var tag = baseGetTag(value);
  10884. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10885. }
  10886. /**
  10887. * Checks if `value` is an integer.
  10888. *
  10889. * **Note:** This method is based on
  10890. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10891. *
  10892. * @static
  10893. * @memberOf _
  10894. * @since 4.0.0
  10895. * @category Lang
  10896. * @param {*} value The value to check.
  10897. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10898. * @example
  10899. *
  10900. * _.isInteger(3);
  10901. * // => true
  10902. *
  10903. * _.isInteger(Number.MIN_VALUE);
  10904. * // => false
  10905. *
  10906. * _.isInteger(Infinity);
  10907. * // => false
  10908. *
  10909. * _.isInteger('3');
  10910. * // => false
  10911. */
  10912. function isInteger(value) {
  10913. return typeof value == 'number' && value == toInteger(value);
  10914. }
  10915. /**
  10916. * Checks if `value` is a valid array-like length.
  10917. *
  10918. * **Note:** This method is loosely based on
  10919. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10920. *
  10921. * @static
  10922. * @memberOf _
  10923. * @since 4.0.0
  10924. * @category Lang
  10925. * @param {*} value The value to check.
  10926. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10927. * @example
  10928. *
  10929. * _.isLength(3);
  10930. * // => true
  10931. *
  10932. * _.isLength(Number.MIN_VALUE);
  10933. * // => false
  10934. *
  10935. * _.isLength(Infinity);
  10936. * // => false
  10937. *
  10938. * _.isLength('3');
  10939. * // => false
  10940. */
  10941. function isLength(value) {
  10942. return typeof value == 'number' &&
  10943. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10944. }
  10945. /**
  10946. * Checks if `value` is the
  10947. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10948. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10949. *
  10950. * @static
  10951. * @memberOf _
  10952. * @since 0.1.0
  10953. * @category Lang
  10954. * @param {*} value The value to check.
  10955. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10956. * @example
  10957. *
  10958. * _.isObject({});
  10959. * // => true
  10960. *
  10961. * _.isObject([1, 2, 3]);
  10962. * // => true
  10963. *
  10964. * _.isObject(_.noop);
  10965. * // => true
  10966. *
  10967. * _.isObject(null);
  10968. * // => false
  10969. */
  10970. function isObject(value) {
  10971. var type = typeof value;
  10972. return value != null && (type == 'object' || type == 'function');
  10973. }
  10974. /**
  10975. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10976. * and has a `typeof` result of "object".
  10977. *
  10978. * @static
  10979. * @memberOf _
  10980. * @since 4.0.0
  10981. * @category Lang
  10982. * @param {*} value The value to check.
  10983. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10984. * @example
  10985. *
  10986. * _.isObjectLike({});
  10987. * // => true
  10988. *
  10989. * _.isObjectLike([1, 2, 3]);
  10990. * // => true
  10991. *
  10992. * _.isObjectLike(_.noop);
  10993. * // => false
  10994. *
  10995. * _.isObjectLike(null);
  10996. * // => false
  10997. */
  10998. function isObjectLike(value) {
  10999. return value != null && typeof value == 'object';
  11000. }
  11001. /**
  11002. * Checks if `value` is classified as a `Map` object.
  11003. *
  11004. * @static
  11005. * @memberOf _
  11006. * @since 4.3.0
  11007. * @category Lang
  11008. * @param {*} value The value to check.
  11009. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11010. * @example
  11011. *
  11012. * _.isMap(new Map);
  11013. * // => true
  11014. *
  11015. * _.isMap(new WeakMap);
  11016. * // => false
  11017. */
  11018. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11019. /**
  11020. * Performs a partial deep comparison between `object` and `source` to
  11021. * determine if `object` contains equivalent property values.
  11022. *
  11023. * **Note:** This method is equivalent to `_.matches` when `source` is
  11024. * partially applied.
  11025. *
  11026. * Partial comparisons will match empty array and empty object `source`
  11027. * values against any array or object value, respectively. See `_.isEqual`
  11028. * for a list of supported value comparisons.
  11029. *
  11030. * @static
  11031. * @memberOf _
  11032. * @since 3.0.0
  11033. * @category Lang
  11034. * @param {Object} object The object to inspect.
  11035. * @param {Object} source The object of property values to match.
  11036. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11037. * @example
  11038. *
  11039. * var object = { 'a': 1, 'b': 2 };
  11040. *
  11041. * _.isMatch(object, { 'b': 2 });
  11042. * // => true
  11043. *
  11044. * _.isMatch(object, { 'b': 1 });
  11045. * // => false
  11046. */
  11047. function isMatch(object, source) {
  11048. return object === source || baseIsMatch(object, source, getMatchData(source));
  11049. }
  11050. /**
  11051. * This method is like `_.isMatch` except that it accepts `customizer` which
  11052. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11053. * are handled by the method instead. The `customizer` is invoked with five
  11054. * arguments: (objValue, srcValue, index|key, object, source).
  11055. *
  11056. * @static
  11057. * @memberOf _
  11058. * @since 4.0.0
  11059. * @category Lang
  11060. * @param {Object} object The object to inspect.
  11061. * @param {Object} source The object of property values to match.
  11062. * @param {Function} [customizer] The function to customize comparisons.
  11063. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11064. * @example
  11065. *
  11066. * function isGreeting(value) {
  11067. * return /^h(?:i|ello)$/.test(value);
  11068. * }
  11069. *
  11070. * function customizer(objValue, srcValue) {
  11071. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11072. * return true;
  11073. * }
  11074. * }
  11075. *
  11076. * var object = { 'greeting': 'hello' };
  11077. * var source = { 'greeting': 'hi' };
  11078. *
  11079. * _.isMatchWith(object, source, customizer);
  11080. * // => true
  11081. */
  11082. function isMatchWith(object, source, customizer) {
  11083. customizer = typeof customizer == 'function' ? customizer : undefined;
  11084. return baseIsMatch(object, source, getMatchData(source), customizer);
  11085. }
  11086. /**
  11087. * Checks if `value` is `NaN`.
  11088. *
  11089. * **Note:** This method is based on
  11090. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11091. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11092. * `undefined` and other non-number values.
  11093. *
  11094. * @static
  11095. * @memberOf _
  11096. * @since 0.1.0
  11097. * @category Lang
  11098. * @param {*} value The value to check.
  11099. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11100. * @example
  11101. *
  11102. * _.isNaN(NaN);
  11103. * // => true
  11104. *
  11105. * _.isNaN(new Number(NaN));
  11106. * // => true
  11107. *
  11108. * isNaN(undefined);
  11109. * // => true
  11110. *
  11111. * _.isNaN(undefined);
  11112. * // => false
  11113. */
  11114. function isNaN(value) {
  11115. // An `NaN` primitive is the only value that is not equal to itself.
  11116. // Perform the `toStringTag` check first to avoid errors with some
  11117. // ActiveX objects in IE.
  11118. return isNumber(value) && value != +value;
  11119. }
  11120. /**
  11121. * Checks if `value` is a pristine native function.
  11122. *
  11123. * **Note:** This method can't reliably detect native functions in the presence
  11124. * of the core-js package because core-js circumvents this kind of detection.
  11125. * Despite multiple requests, the core-js maintainer has made it clear: any
  11126. * attempt to fix the detection will be obstructed. As a result, we're left
  11127. * with little choice but to throw an error. Unfortunately, this also affects
  11128. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11129. * which rely on core-js.
  11130. *
  11131. * @static
  11132. * @memberOf _
  11133. * @since 3.0.0
  11134. * @category Lang
  11135. * @param {*} value The value to check.
  11136. * @returns {boolean} Returns `true` if `value` is a native function,
  11137. * else `false`.
  11138. * @example
  11139. *
  11140. * _.isNative(Array.prototype.push);
  11141. * // => true
  11142. *
  11143. * _.isNative(_);
  11144. * // => false
  11145. */
  11146. function isNative(value) {
  11147. if (isMaskable(value)) {
  11148. throw new Error(CORE_ERROR_TEXT);
  11149. }
  11150. return baseIsNative(value);
  11151. }
  11152. /**
  11153. * Checks if `value` is `null`.
  11154. *
  11155. * @static
  11156. * @memberOf _
  11157. * @since 0.1.0
  11158. * @category Lang
  11159. * @param {*} value The value to check.
  11160. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11161. * @example
  11162. *
  11163. * _.isNull(null);
  11164. * // => true
  11165. *
  11166. * _.isNull(void 0);
  11167. * // => false
  11168. */
  11169. function isNull(value) {
  11170. return value === null;
  11171. }
  11172. /**
  11173. * Checks if `value` is `null` or `undefined`.
  11174. *
  11175. * @static
  11176. * @memberOf _
  11177. * @since 4.0.0
  11178. * @category Lang
  11179. * @param {*} value The value to check.
  11180. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11181. * @example
  11182. *
  11183. * _.isNil(null);
  11184. * // => true
  11185. *
  11186. * _.isNil(void 0);
  11187. * // => true
  11188. *
  11189. * _.isNil(NaN);
  11190. * // => false
  11191. */
  11192. function isNil(value) {
  11193. return value == null;
  11194. }
  11195. /**
  11196. * Checks if `value` is classified as a `Number` primitive or object.
  11197. *
  11198. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11199. * classified as numbers, use the `_.isFinite` method.
  11200. *
  11201. * @static
  11202. * @memberOf _
  11203. * @since 0.1.0
  11204. * @category Lang
  11205. * @param {*} value The value to check.
  11206. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11207. * @example
  11208. *
  11209. * _.isNumber(3);
  11210. * // => true
  11211. *
  11212. * _.isNumber(Number.MIN_VALUE);
  11213. * // => true
  11214. *
  11215. * _.isNumber(Infinity);
  11216. * // => true
  11217. *
  11218. * _.isNumber('3');
  11219. * // => false
  11220. */
  11221. function isNumber(value) {
  11222. return typeof value == 'number' ||
  11223. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11224. }
  11225. /**
  11226. * Checks if `value` is a plain object, that is, an object created by the
  11227. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11228. *
  11229. * @static
  11230. * @memberOf _
  11231. * @since 0.8.0
  11232. * @category Lang
  11233. * @param {*} value The value to check.
  11234. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11235. * @example
  11236. *
  11237. * function Foo() {
  11238. * this.a = 1;
  11239. * }
  11240. *
  11241. * _.isPlainObject(new Foo);
  11242. * // => false
  11243. *
  11244. * _.isPlainObject([1, 2, 3]);
  11245. * // => false
  11246. *
  11247. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11248. * // => true
  11249. *
  11250. * _.isPlainObject(Object.create(null));
  11251. * // => true
  11252. */
  11253. function isPlainObject(value) {
  11254. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11255. return false;
  11256. }
  11257. var proto = getPrototype(value);
  11258. if (proto === null) {
  11259. return true;
  11260. }
  11261. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11262. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11263. funcToString.call(Ctor) == objectCtorString;
  11264. }
  11265. /**
  11266. * Checks if `value` is classified as a `RegExp` object.
  11267. *
  11268. * @static
  11269. * @memberOf _
  11270. * @since 0.1.0
  11271. * @category Lang
  11272. * @param {*} value The value to check.
  11273. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11274. * @example
  11275. *
  11276. * _.isRegExp(/abc/);
  11277. * // => true
  11278. *
  11279. * _.isRegExp('/abc/');
  11280. * // => false
  11281. */
  11282. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11283. /**
  11284. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11285. * double precision number which isn't the result of a rounded unsafe integer.
  11286. *
  11287. * **Note:** This method is based on
  11288. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11289. *
  11290. * @static
  11291. * @memberOf _
  11292. * @since 4.0.0
  11293. * @category Lang
  11294. * @param {*} value The value to check.
  11295. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11296. * @example
  11297. *
  11298. * _.isSafeInteger(3);
  11299. * // => true
  11300. *
  11301. * _.isSafeInteger(Number.MIN_VALUE);
  11302. * // => false
  11303. *
  11304. * _.isSafeInteger(Infinity);
  11305. * // => false
  11306. *
  11307. * _.isSafeInteger('3');
  11308. * // => false
  11309. */
  11310. function isSafeInteger(value) {
  11311. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11312. }
  11313. /**
  11314. * Checks if `value` is classified as a `Set` object.
  11315. *
  11316. * @static
  11317. * @memberOf _
  11318. * @since 4.3.0
  11319. * @category Lang
  11320. * @param {*} value The value to check.
  11321. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11322. * @example
  11323. *
  11324. * _.isSet(new Set);
  11325. * // => true
  11326. *
  11327. * _.isSet(new WeakSet);
  11328. * // => false
  11329. */
  11330. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11331. /**
  11332. * Checks if `value` is classified as a `String` primitive or object.
  11333. *
  11334. * @static
  11335. * @since 0.1.0
  11336. * @memberOf _
  11337. * @category Lang
  11338. * @param {*} value The value to check.
  11339. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11340. * @example
  11341. *
  11342. * _.isString('abc');
  11343. * // => true
  11344. *
  11345. * _.isString(1);
  11346. * // => false
  11347. */
  11348. function isString(value) {
  11349. return typeof value == 'string' ||
  11350. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11351. }
  11352. /**
  11353. * Checks if `value` is classified as a `Symbol` primitive or object.
  11354. *
  11355. * @static
  11356. * @memberOf _
  11357. * @since 4.0.0
  11358. * @category Lang
  11359. * @param {*} value The value to check.
  11360. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11361. * @example
  11362. *
  11363. * _.isSymbol(Symbol.iterator);
  11364. * // => true
  11365. *
  11366. * _.isSymbol('abc');
  11367. * // => false
  11368. */
  11369. function isSymbol(value) {
  11370. return typeof value == 'symbol' ||
  11371. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11372. }
  11373. /**
  11374. * Checks if `value` is classified as a typed array.
  11375. *
  11376. * @static
  11377. * @memberOf _
  11378. * @since 3.0.0
  11379. * @category Lang
  11380. * @param {*} value The value to check.
  11381. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11382. * @example
  11383. *
  11384. * _.isTypedArray(new Uint8Array);
  11385. * // => true
  11386. *
  11387. * _.isTypedArray([]);
  11388. * // => false
  11389. */
  11390. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11391. /**
  11392. * Checks if `value` is `undefined`.
  11393. *
  11394. * @static
  11395. * @since 0.1.0
  11396. * @memberOf _
  11397. * @category Lang
  11398. * @param {*} value The value to check.
  11399. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11400. * @example
  11401. *
  11402. * _.isUndefined(void 0);
  11403. * // => true
  11404. *
  11405. * _.isUndefined(null);
  11406. * // => false
  11407. */
  11408. function isUndefined(value) {
  11409. return value === undefined;
  11410. }
  11411. /**
  11412. * Checks if `value` is classified as a `WeakMap` object.
  11413. *
  11414. * @static
  11415. * @memberOf _
  11416. * @since 4.3.0
  11417. * @category Lang
  11418. * @param {*} value The value to check.
  11419. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11420. * @example
  11421. *
  11422. * _.isWeakMap(new WeakMap);
  11423. * // => true
  11424. *
  11425. * _.isWeakMap(new Map);
  11426. * // => false
  11427. */
  11428. function isWeakMap(value) {
  11429. return isObjectLike(value) && getTag(value) == weakMapTag;
  11430. }
  11431. /**
  11432. * Checks if `value` is classified as a `WeakSet` object.
  11433. *
  11434. * @static
  11435. * @memberOf _
  11436. * @since 4.3.0
  11437. * @category Lang
  11438. * @param {*} value The value to check.
  11439. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11440. * @example
  11441. *
  11442. * _.isWeakSet(new WeakSet);
  11443. * // => true
  11444. *
  11445. * _.isWeakSet(new Set);
  11446. * // => false
  11447. */
  11448. function isWeakSet(value) {
  11449. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11450. }
  11451. /**
  11452. * Checks if `value` is less than `other`.
  11453. *
  11454. * @static
  11455. * @memberOf _
  11456. * @since 3.9.0
  11457. * @category Lang
  11458. * @param {*} value The value to compare.
  11459. * @param {*} other The other value to compare.
  11460. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11461. * else `false`.
  11462. * @see _.gt
  11463. * @example
  11464. *
  11465. * _.lt(1, 3);
  11466. * // => true
  11467. *
  11468. * _.lt(3, 3);
  11469. * // => false
  11470. *
  11471. * _.lt(3, 1);
  11472. * // => false
  11473. */
  11474. var lt = createRelationalOperation(baseLt);
  11475. /**
  11476. * Checks if `value` is less than or equal to `other`.
  11477. *
  11478. * @static
  11479. * @memberOf _
  11480. * @since 3.9.0
  11481. * @category Lang
  11482. * @param {*} value The value to compare.
  11483. * @param {*} other The other value to compare.
  11484. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11485. * `other`, else `false`.
  11486. * @see _.gte
  11487. * @example
  11488. *
  11489. * _.lte(1, 3);
  11490. * // => true
  11491. *
  11492. * _.lte(3, 3);
  11493. * // => true
  11494. *
  11495. * _.lte(3, 1);
  11496. * // => false
  11497. */
  11498. var lte = createRelationalOperation(function(value, other) {
  11499. return value <= other;
  11500. });
  11501. /**
  11502. * Converts `value` to an array.
  11503. *
  11504. * @static
  11505. * @since 0.1.0
  11506. * @memberOf _
  11507. * @category Lang
  11508. * @param {*} value The value to convert.
  11509. * @returns {Array} Returns the converted array.
  11510. * @example
  11511. *
  11512. * _.toArray({ 'a': 1, 'b': 2 });
  11513. * // => [1, 2]
  11514. *
  11515. * _.toArray('abc');
  11516. * // => ['a', 'b', 'c']
  11517. *
  11518. * _.toArray(1);
  11519. * // => []
  11520. *
  11521. * _.toArray(null);
  11522. * // => []
  11523. */
  11524. function toArray(value) {
  11525. if (!value) {
  11526. return [];
  11527. }
  11528. if (isArrayLike(value)) {
  11529. return isString(value) ? stringToArray(value) : copyArray(value);
  11530. }
  11531. if (symIterator && value[symIterator]) {
  11532. return iteratorToArray(value[symIterator]());
  11533. }
  11534. var tag = getTag(value),
  11535. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11536. return func(value);
  11537. }
  11538. /**
  11539. * Converts `value` to a finite number.
  11540. *
  11541. * @static
  11542. * @memberOf _
  11543. * @since 4.12.0
  11544. * @category Lang
  11545. * @param {*} value The value to convert.
  11546. * @returns {number} Returns the converted number.
  11547. * @example
  11548. *
  11549. * _.toFinite(3.2);
  11550. * // => 3.2
  11551. *
  11552. * _.toFinite(Number.MIN_VALUE);
  11553. * // => 5e-324
  11554. *
  11555. * _.toFinite(Infinity);
  11556. * // => 1.7976931348623157e+308
  11557. *
  11558. * _.toFinite('3.2');
  11559. * // => 3.2
  11560. */
  11561. function toFinite(value) {
  11562. if (!value) {
  11563. return value === 0 ? value : 0;
  11564. }
  11565. value = toNumber(value);
  11566. if (value === INFINITY || value === -INFINITY) {
  11567. var sign = (value < 0 ? -1 : 1);
  11568. return sign * MAX_INTEGER;
  11569. }
  11570. return value === value ? value : 0;
  11571. }
  11572. /**
  11573. * Converts `value` to an integer.
  11574. *
  11575. * **Note:** This method is loosely based on
  11576. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11577. *
  11578. * @static
  11579. * @memberOf _
  11580. * @since 4.0.0
  11581. * @category Lang
  11582. * @param {*} value The value to convert.
  11583. * @returns {number} Returns the converted integer.
  11584. * @example
  11585. *
  11586. * _.toInteger(3.2);
  11587. * // => 3
  11588. *
  11589. * _.toInteger(Number.MIN_VALUE);
  11590. * // => 0
  11591. *
  11592. * _.toInteger(Infinity);
  11593. * // => 1.7976931348623157e+308
  11594. *
  11595. * _.toInteger('3.2');
  11596. * // => 3
  11597. */
  11598. function toInteger(value) {
  11599. var result = toFinite(value),
  11600. remainder = result % 1;
  11601. return result === result ? (remainder ? result - remainder : result) : 0;
  11602. }
  11603. /**
  11604. * Converts `value` to an integer suitable for use as the length of an
  11605. * array-like object.
  11606. *
  11607. * **Note:** This method is based on
  11608. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11609. *
  11610. * @static
  11611. * @memberOf _
  11612. * @since 4.0.0
  11613. * @category Lang
  11614. * @param {*} value The value to convert.
  11615. * @returns {number} Returns the converted integer.
  11616. * @example
  11617. *
  11618. * _.toLength(3.2);
  11619. * // => 3
  11620. *
  11621. * _.toLength(Number.MIN_VALUE);
  11622. * // => 0
  11623. *
  11624. * _.toLength(Infinity);
  11625. * // => 4294967295
  11626. *
  11627. * _.toLength('3.2');
  11628. * // => 3
  11629. */
  11630. function toLength(value) {
  11631. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11632. }
  11633. /**
  11634. * Converts `value` to a number.
  11635. *
  11636. * @static
  11637. * @memberOf _
  11638. * @since 4.0.0
  11639. * @category Lang
  11640. * @param {*} value The value to process.
  11641. * @returns {number} Returns the number.
  11642. * @example
  11643. *
  11644. * _.toNumber(3.2);
  11645. * // => 3.2
  11646. *
  11647. * _.toNumber(Number.MIN_VALUE);
  11648. * // => 5e-324
  11649. *
  11650. * _.toNumber(Infinity);
  11651. * // => Infinity
  11652. *
  11653. * _.toNumber('3.2');
  11654. * // => 3.2
  11655. */
  11656. function toNumber(value) {
  11657. if (typeof value == 'number') {
  11658. return value;
  11659. }
  11660. if (isSymbol(value)) {
  11661. return NAN;
  11662. }
  11663. if (isObject(value)) {
  11664. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11665. value = isObject(other) ? (other + '') : other;
  11666. }
  11667. if (typeof value != 'string') {
  11668. return value === 0 ? value : +value;
  11669. }
  11670. value = value.replace(reTrim, '');
  11671. var isBinary = reIsBinary.test(value);
  11672. return (isBinary || reIsOctal.test(value))
  11673. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11674. : (reIsBadHex.test(value) ? NAN : +value);
  11675. }
  11676. /**
  11677. * Converts `value` to a plain object flattening inherited enumerable string
  11678. * keyed properties of `value` to own properties of the plain object.
  11679. *
  11680. * @static
  11681. * @memberOf _
  11682. * @since 3.0.0
  11683. * @category Lang
  11684. * @param {*} value The value to convert.
  11685. * @returns {Object} Returns the converted plain object.
  11686. * @example
  11687. *
  11688. * function Foo() {
  11689. * this.b = 2;
  11690. * }
  11691. *
  11692. * Foo.prototype.c = 3;
  11693. *
  11694. * _.assign({ 'a': 1 }, new Foo);
  11695. * // => { 'a': 1, 'b': 2 }
  11696. *
  11697. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11698. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11699. */
  11700. function toPlainObject(value) {
  11701. return copyObject(value, keysIn(value));
  11702. }
  11703. /**
  11704. * Converts `value` to a safe integer. A safe integer can be compared and
  11705. * represented correctly.
  11706. *
  11707. * @static
  11708. * @memberOf _
  11709. * @since 4.0.0
  11710. * @category Lang
  11711. * @param {*} value The value to convert.
  11712. * @returns {number} Returns the converted integer.
  11713. * @example
  11714. *
  11715. * _.toSafeInteger(3.2);
  11716. * // => 3
  11717. *
  11718. * _.toSafeInteger(Number.MIN_VALUE);
  11719. * // => 0
  11720. *
  11721. * _.toSafeInteger(Infinity);
  11722. * // => 9007199254740991
  11723. *
  11724. * _.toSafeInteger('3.2');
  11725. * // => 3
  11726. */
  11727. function toSafeInteger(value) {
  11728. return value
  11729. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11730. : (value === 0 ? value : 0);
  11731. }
  11732. /**
  11733. * Converts `value` to a string. An empty string is returned for `null`
  11734. * and `undefined` values. The sign of `-0` is preserved.
  11735. *
  11736. * @static
  11737. * @memberOf _
  11738. * @since 4.0.0
  11739. * @category Lang
  11740. * @param {*} value The value to convert.
  11741. * @returns {string} Returns the converted string.
  11742. * @example
  11743. *
  11744. * _.toString(null);
  11745. * // => ''
  11746. *
  11747. * _.toString(-0);
  11748. * // => '-0'
  11749. *
  11750. * _.toString([1, 2, 3]);
  11751. * // => '1,2,3'
  11752. */
  11753. function toString(value) {
  11754. return value == null ? '' : baseToString(value);
  11755. }
  11756. /*------------------------------------------------------------------------*/
  11757. /**
  11758. * Assigns own enumerable string keyed properties of source objects to the
  11759. * destination object. Source objects are applied from left to right.
  11760. * Subsequent sources overwrite property assignments of previous sources.
  11761. *
  11762. * **Note:** This method mutates `object` and is loosely based on
  11763. * [`Object.assign`](https://mdn.io/Object/assign).
  11764. *
  11765. * @static
  11766. * @memberOf _
  11767. * @since 0.10.0
  11768. * @category Object
  11769. * @param {Object} object The destination object.
  11770. * @param {...Object} [sources] The source objects.
  11771. * @returns {Object} Returns `object`.
  11772. * @see _.assignIn
  11773. * @example
  11774. *
  11775. * function Foo() {
  11776. * this.a = 1;
  11777. * }
  11778. *
  11779. * function Bar() {
  11780. * this.c = 3;
  11781. * }
  11782. *
  11783. * Foo.prototype.b = 2;
  11784. * Bar.prototype.d = 4;
  11785. *
  11786. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11787. * // => { 'a': 1, 'c': 3 }
  11788. */
  11789. var assign = createAssigner(function(object, source) {
  11790. if (isPrototype(source) || isArrayLike(source)) {
  11791. copyObject(source, keys(source), object);
  11792. return;
  11793. }
  11794. for (var key in source) {
  11795. if (hasOwnProperty.call(source, key)) {
  11796. assignValue(object, key, source[key]);
  11797. }
  11798. }
  11799. });
  11800. /**
  11801. * This method is like `_.assign` except that it iterates over own and
  11802. * inherited source properties.
  11803. *
  11804. * **Note:** This method mutates `object`.
  11805. *
  11806. * @static
  11807. * @memberOf _
  11808. * @since 4.0.0
  11809. * @alias extend
  11810. * @category Object
  11811. * @param {Object} object The destination object.
  11812. * @param {...Object} [sources] The source objects.
  11813. * @returns {Object} Returns `object`.
  11814. * @see _.assign
  11815. * @example
  11816. *
  11817. * function Foo() {
  11818. * this.a = 1;
  11819. * }
  11820. *
  11821. * function Bar() {
  11822. * this.c = 3;
  11823. * }
  11824. *
  11825. * Foo.prototype.b = 2;
  11826. * Bar.prototype.d = 4;
  11827. *
  11828. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11829. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11830. */
  11831. var assignIn = createAssigner(function(object, source) {
  11832. copyObject(source, keysIn(source), object);
  11833. });
  11834. /**
  11835. * This method is like `_.assignIn` except that it accepts `customizer`
  11836. * which is invoked to produce the assigned values. If `customizer` returns
  11837. * `undefined`, assignment is handled by the method instead. The `customizer`
  11838. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11839. *
  11840. * **Note:** This method mutates `object`.
  11841. *
  11842. * @static
  11843. * @memberOf _
  11844. * @since 4.0.0
  11845. * @alias extendWith
  11846. * @category Object
  11847. * @param {Object} object The destination object.
  11848. * @param {...Object} sources The source objects.
  11849. * @param {Function} [customizer] The function to customize assigned values.
  11850. * @returns {Object} Returns `object`.
  11851. * @see _.assignWith
  11852. * @example
  11853. *
  11854. * function customizer(objValue, srcValue) {
  11855. * return _.isUndefined(objValue) ? srcValue : objValue;
  11856. * }
  11857. *
  11858. * var defaults = _.partialRight(_.assignInWith, customizer);
  11859. *
  11860. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11861. * // => { 'a': 1, 'b': 2 }
  11862. */
  11863. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11864. copyObject(source, keysIn(source), object, customizer);
  11865. });
  11866. /**
  11867. * This method is like `_.assign` except that it accepts `customizer`
  11868. * which is invoked to produce the assigned values. If `customizer` returns
  11869. * `undefined`, assignment is handled by the method instead. The `customizer`
  11870. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11871. *
  11872. * **Note:** This method mutates `object`.
  11873. *
  11874. * @static
  11875. * @memberOf _
  11876. * @since 4.0.0
  11877. * @category Object
  11878. * @param {Object} object The destination object.
  11879. * @param {...Object} sources The source objects.
  11880. * @param {Function} [customizer] The function to customize assigned values.
  11881. * @returns {Object} Returns `object`.
  11882. * @see _.assignInWith
  11883. * @example
  11884. *
  11885. * function customizer(objValue, srcValue) {
  11886. * return _.isUndefined(objValue) ? srcValue : objValue;
  11887. * }
  11888. *
  11889. * var defaults = _.partialRight(_.assignWith, customizer);
  11890. *
  11891. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11892. * // => { 'a': 1, 'b': 2 }
  11893. */
  11894. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11895. copyObject(source, keys(source), object, customizer);
  11896. });
  11897. /**
  11898. * Creates an array of values corresponding to `paths` of `object`.
  11899. *
  11900. * @static
  11901. * @memberOf _
  11902. * @since 1.0.0
  11903. * @category Object
  11904. * @param {Object} object The object to iterate over.
  11905. * @param {...(string|string[])} [paths] The property paths to pick.
  11906. * @returns {Array} Returns the picked values.
  11907. * @example
  11908. *
  11909. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11910. *
  11911. * _.at(object, ['a[0].b.c', 'a[1]']);
  11912. * // => [3, 4]
  11913. */
  11914. var at = flatRest(baseAt);
  11915. /**
  11916. * Creates an object that inherits from the `prototype` object. If a
  11917. * `properties` object is given, its own enumerable string keyed properties
  11918. * are assigned to the created object.
  11919. *
  11920. * @static
  11921. * @memberOf _
  11922. * @since 2.3.0
  11923. * @category Object
  11924. * @param {Object} prototype The object to inherit from.
  11925. * @param {Object} [properties] The properties to assign to the object.
  11926. * @returns {Object} Returns the new object.
  11927. * @example
  11928. *
  11929. * function Shape() {
  11930. * this.x = 0;
  11931. * this.y = 0;
  11932. * }
  11933. *
  11934. * function Circle() {
  11935. * Shape.call(this);
  11936. * }
  11937. *
  11938. * Circle.prototype = _.create(Shape.prototype, {
  11939. * 'constructor': Circle
  11940. * });
  11941. *
  11942. * var circle = new Circle;
  11943. * circle instanceof Circle;
  11944. * // => true
  11945. *
  11946. * circle instanceof Shape;
  11947. * // => true
  11948. */
  11949. function create(prototype, properties) {
  11950. var result = baseCreate(prototype);
  11951. return properties == null ? result : baseAssign(result, properties);
  11952. }
  11953. /**
  11954. * Assigns own and inherited enumerable string keyed properties of source
  11955. * objects to the destination object for all destination properties that
  11956. * resolve to `undefined`. Source objects are applied from left to right.
  11957. * Once a property is set, additional values of the same property are ignored.
  11958. *
  11959. * **Note:** This method mutates `object`.
  11960. *
  11961. * @static
  11962. * @since 0.1.0
  11963. * @memberOf _
  11964. * @category Object
  11965. * @param {Object} object The destination object.
  11966. * @param {...Object} [sources] The source objects.
  11967. * @returns {Object} Returns `object`.
  11968. * @see _.defaultsDeep
  11969. * @example
  11970. *
  11971. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11972. * // => { 'a': 1, 'b': 2 }
  11973. */
  11974. var defaults = baseRest(function(args) {
  11975. args.push(undefined, customDefaultsAssignIn);
  11976. return apply(assignInWith, undefined, args);
  11977. });
  11978. /**
  11979. * This method is like `_.defaults` except that it recursively assigns
  11980. * default properties.
  11981. *
  11982. * **Note:** This method mutates `object`.
  11983. *
  11984. * @static
  11985. * @memberOf _
  11986. * @since 3.10.0
  11987. * @category Object
  11988. * @param {Object} object The destination object.
  11989. * @param {...Object} [sources] The source objects.
  11990. * @returns {Object} Returns `object`.
  11991. * @see _.defaults
  11992. * @example
  11993. *
  11994. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11995. * // => { 'a': { 'b': 2, 'c': 3 } }
  11996. */
  11997. var defaultsDeep = baseRest(function(args) {
  11998. args.push(undefined, customDefaultsMerge);
  11999. return apply(mergeWith, undefined, args);
  12000. });
  12001. /**
  12002. * This method is like `_.find` except that it returns the key of the first
  12003. * element `predicate` returns truthy for instead of the element itself.
  12004. *
  12005. * @static
  12006. * @memberOf _
  12007. * @since 1.1.0
  12008. * @category Object
  12009. * @param {Object} object The object to inspect.
  12010. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12011. * @returns {string|undefined} Returns the key of the matched element,
  12012. * else `undefined`.
  12013. * @example
  12014. *
  12015. * var users = {
  12016. * 'barney': { 'age': 36, 'active': true },
  12017. * 'fred': { 'age': 40, 'active': false },
  12018. * 'pebbles': { 'age': 1, 'active': true }
  12019. * };
  12020. *
  12021. * _.findKey(users, function(o) { return o.age < 40; });
  12022. * // => 'barney' (iteration order is not guaranteed)
  12023. *
  12024. * // The `_.matches` iteratee shorthand.
  12025. * _.findKey(users, { 'age': 1, 'active': true });
  12026. * // => 'pebbles'
  12027. *
  12028. * // The `_.matchesProperty` iteratee shorthand.
  12029. * _.findKey(users, ['active', false]);
  12030. * // => 'fred'
  12031. *
  12032. * // The `_.property` iteratee shorthand.
  12033. * _.findKey(users, 'active');
  12034. * // => 'barney'
  12035. */
  12036. function findKey(object, predicate) {
  12037. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12038. }
  12039. /**
  12040. * This method is like `_.findKey` except that it iterates over elements of
  12041. * a collection in the opposite order.
  12042. *
  12043. * @static
  12044. * @memberOf _
  12045. * @since 2.0.0
  12046. * @category Object
  12047. * @param {Object} object The object to inspect.
  12048. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12049. * @returns {string|undefined} Returns the key of the matched element,
  12050. * else `undefined`.
  12051. * @example
  12052. *
  12053. * var users = {
  12054. * 'barney': { 'age': 36, 'active': true },
  12055. * 'fred': { 'age': 40, 'active': false },
  12056. * 'pebbles': { 'age': 1, 'active': true }
  12057. * };
  12058. *
  12059. * _.findLastKey(users, function(o) { return o.age < 40; });
  12060. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12061. *
  12062. * // The `_.matches` iteratee shorthand.
  12063. * _.findLastKey(users, { 'age': 36, 'active': true });
  12064. * // => 'barney'
  12065. *
  12066. * // The `_.matchesProperty` iteratee shorthand.
  12067. * _.findLastKey(users, ['active', false]);
  12068. * // => 'fred'
  12069. *
  12070. * // The `_.property` iteratee shorthand.
  12071. * _.findLastKey(users, 'active');
  12072. * // => 'pebbles'
  12073. */
  12074. function findLastKey(object, predicate) {
  12075. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12076. }
  12077. /**
  12078. * Iterates over own and inherited enumerable string keyed properties of an
  12079. * object and invokes `iteratee` for each property. The iteratee is invoked
  12080. * with three arguments: (value, key, object). Iteratee functions may exit
  12081. * iteration early by explicitly returning `false`.
  12082. *
  12083. * @static
  12084. * @memberOf _
  12085. * @since 0.3.0
  12086. * @category Object
  12087. * @param {Object} object The object to iterate over.
  12088. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12089. * @returns {Object} Returns `object`.
  12090. * @see _.forInRight
  12091. * @example
  12092. *
  12093. * function Foo() {
  12094. * this.a = 1;
  12095. * this.b = 2;
  12096. * }
  12097. *
  12098. * Foo.prototype.c = 3;
  12099. *
  12100. * _.forIn(new Foo, function(value, key) {
  12101. * console.log(key);
  12102. * });
  12103. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12104. */
  12105. function forIn(object, iteratee) {
  12106. return object == null
  12107. ? object
  12108. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12109. }
  12110. /**
  12111. * This method is like `_.forIn` except that it iterates over properties of
  12112. * `object` in the opposite order.
  12113. *
  12114. * @static
  12115. * @memberOf _
  12116. * @since 2.0.0
  12117. * @category Object
  12118. * @param {Object} object The object to iterate over.
  12119. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12120. * @returns {Object} Returns `object`.
  12121. * @see _.forIn
  12122. * @example
  12123. *
  12124. * function Foo() {
  12125. * this.a = 1;
  12126. * this.b = 2;
  12127. * }
  12128. *
  12129. * Foo.prototype.c = 3;
  12130. *
  12131. * _.forInRight(new Foo, function(value, key) {
  12132. * console.log(key);
  12133. * });
  12134. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12135. */
  12136. function forInRight(object, iteratee) {
  12137. return object == null
  12138. ? object
  12139. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12140. }
  12141. /**
  12142. * Iterates over own enumerable string keyed properties of an object and
  12143. * invokes `iteratee` for each property. The iteratee is invoked with three
  12144. * arguments: (value, key, object). Iteratee functions may exit iteration
  12145. * early by explicitly returning `false`.
  12146. *
  12147. * @static
  12148. * @memberOf _
  12149. * @since 0.3.0
  12150. * @category Object
  12151. * @param {Object} object The object to iterate over.
  12152. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12153. * @returns {Object} Returns `object`.
  12154. * @see _.forOwnRight
  12155. * @example
  12156. *
  12157. * function Foo() {
  12158. * this.a = 1;
  12159. * this.b = 2;
  12160. * }
  12161. *
  12162. * Foo.prototype.c = 3;
  12163. *
  12164. * _.forOwn(new Foo, function(value, key) {
  12165. * console.log(key);
  12166. * });
  12167. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12168. */
  12169. function forOwn(object, iteratee) {
  12170. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12171. }
  12172. /**
  12173. * This method is like `_.forOwn` except that it iterates over properties of
  12174. * `object` in the opposite order.
  12175. *
  12176. * @static
  12177. * @memberOf _
  12178. * @since 2.0.0
  12179. * @category Object
  12180. * @param {Object} object The object to iterate over.
  12181. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12182. * @returns {Object} Returns `object`.
  12183. * @see _.forOwn
  12184. * @example
  12185. *
  12186. * function Foo() {
  12187. * this.a = 1;
  12188. * this.b = 2;
  12189. * }
  12190. *
  12191. * Foo.prototype.c = 3;
  12192. *
  12193. * _.forOwnRight(new Foo, function(value, key) {
  12194. * console.log(key);
  12195. * });
  12196. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12197. */
  12198. function forOwnRight(object, iteratee) {
  12199. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12200. }
  12201. /**
  12202. * Creates an array of function property names from own enumerable properties
  12203. * of `object`.
  12204. *
  12205. * @static
  12206. * @since 0.1.0
  12207. * @memberOf _
  12208. * @category Object
  12209. * @param {Object} object The object to inspect.
  12210. * @returns {Array} Returns the function names.
  12211. * @see _.functionsIn
  12212. * @example
  12213. *
  12214. * function Foo() {
  12215. * this.a = _.constant('a');
  12216. * this.b = _.constant('b');
  12217. * }
  12218. *
  12219. * Foo.prototype.c = _.constant('c');
  12220. *
  12221. * _.functions(new Foo);
  12222. * // => ['a', 'b']
  12223. */
  12224. function functions(object) {
  12225. return object == null ? [] : baseFunctions(object, keys(object));
  12226. }
  12227. /**
  12228. * Creates an array of function property names from own and inherited
  12229. * enumerable properties of `object`.
  12230. *
  12231. * @static
  12232. * @memberOf _
  12233. * @since 4.0.0
  12234. * @category Object
  12235. * @param {Object} object The object to inspect.
  12236. * @returns {Array} Returns the function names.
  12237. * @see _.functions
  12238. * @example
  12239. *
  12240. * function Foo() {
  12241. * this.a = _.constant('a');
  12242. * this.b = _.constant('b');
  12243. * }
  12244. *
  12245. * Foo.prototype.c = _.constant('c');
  12246. *
  12247. * _.functionsIn(new Foo);
  12248. * // => ['a', 'b', 'c']
  12249. */
  12250. function functionsIn(object) {
  12251. return object == null ? [] : baseFunctions(object, keysIn(object));
  12252. }
  12253. /**
  12254. * Gets the value at `path` of `object`. If the resolved value is
  12255. * `undefined`, the `defaultValue` is returned in its place.
  12256. *
  12257. * @static
  12258. * @memberOf _
  12259. * @since 3.7.0
  12260. * @category Object
  12261. * @param {Object} object The object to query.
  12262. * @param {Array|string} path The path of the property to get.
  12263. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12264. * @returns {*} Returns the resolved value.
  12265. * @example
  12266. *
  12267. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12268. *
  12269. * _.get(object, 'a[0].b.c');
  12270. * // => 3
  12271. *
  12272. * _.get(object, ['a', '0', 'b', 'c']);
  12273. * // => 3
  12274. *
  12275. * _.get(object, 'a.b.c', 'default');
  12276. * // => 'default'
  12277. */
  12278. function get(object, path, defaultValue) {
  12279. var result = object == null ? undefined : baseGet(object, path);
  12280. return result === undefined ? defaultValue : result;
  12281. }
  12282. /**
  12283. * Checks if `path` is a direct property of `object`.
  12284. *
  12285. * @static
  12286. * @since 0.1.0
  12287. * @memberOf _
  12288. * @category Object
  12289. * @param {Object} object The object to query.
  12290. * @param {Array|string} path The path to check.
  12291. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12292. * @example
  12293. *
  12294. * var object = { 'a': { 'b': 2 } };
  12295. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12296. *
  12297. * _.has(object, 'a');
  12298. * // => true
  12299. *
  12300. * _.has(object, 'a.b');
  12301. * // => true
  12302. *
  12303. * _.has(object, ['a', 'b']);
  12304. * // => true
  12305. *
  12306. * _.has(other, 'a');
  12307. * // => false
  12308. */
  12309. function has(object, path) {
  12310. return object != null && hasPath(object, path, baseHas);
  12311. }
  12312. /**
  12313. * Checks if `path` is a direct or inherited property of `object`.
  12314. *
  12315. * @static
  12316. * @memberOf _
  12317. * @since 4.0.0
  12318. * @category Object
  12319. * @param {Object} object The object to query.
  12320. * @param {Array|string} path The path to check.
  12321. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12322. * @example
  12323. *
  12324. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12325. *
  12326. * _.hasIn(object, 'a');
  12327. * // => true
  12328. *
  12329. * _.hasIn(object, 'a.b');
  12330. * // => true
  12331. *
  12332. * _.hasIn(object, ['a', 'b']);
  12333. * // => true
  12334. *
  12335. * _.hasIn(object, 'b');
  12336. * // => false
  12337. */
  12338. function hasIn(object, path) {
  12339. return object != null && hasPath(object, path, baseHasIn);
  12340. }
  12341. /**
  12342. * Creates an object composed of the inverted keys and values of `object`.
  12343. * If `object` contains duplicate values, subsequent values overwrite
  12344. * property assignments of previous values.
  12345. *
  12346. * @static
  12347. * @memberOf _
  12348. * @since 0.7.0
  12349. * @category Object
  12350. * @param {Object} object The object to invert.
  12351. * @returns {Object} Returns the new inverted object.
  12352. * @example
  12353. *
  12354. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12355. *
  12356. * _.invert(object);
  12357. * // => { '1': 'c', '2': 'b' }
  12358. */
  12359. var invert = createInverter(function(result, value, key) {
  12360. result[value] = key;
  12361. }, constant(identity));
  12362. /**
  12363. * This method is like `_.invert` except that the inverted object is generated
  12364. * from the results of running each element of `object` thru `iteratee`. The
  12365. * corresponding inverted value of each inverted key is an array of keys
  12366. * responsible for generating the inverted value. The iteratee is invoked
  12367. * with one argument: (value).
  12368. *
  12369. * @static
  12370. * @memberOf _
  12371. * @since 4.1.0
  12372. * @category Object
  12373. * @param {Object} object The object to invert.
  12374. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12375. * @returns {Object} Returns the new inverted object.
  12376. * @example
  12377. *
  12378. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12379. *
  12380. * _.invertBy(object);
  12381. * // => { '1': ['a', 'c'], '2': ['b'] }
  12382. *
  12383. * _.invertBy(object, function(value) {
  12384. * return 'group' + value;
  12385. * });
  12386. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12387. */
  12388. var invertBy = createInverter(function(result, value, key) {
  12389. if (hasOwnProperty.call(result, value)) {
  12390. result[value].push(key);
  12391. } else {
  12392. result[value] = [key];
  12393. }
  12394. }, getIteratee);
  12395. /**
  12396. * Invokes the method at `path` of `object`.
  12397. *
  12398. * @static
  12399. * @memberOf _
  12400. * @since 4.0.0
  12401. * @category Object
  12402. * @param {Object} object The object to query.
  12403. * @param {Array|string} path The path of the method to invoke.
  12404. * @param {...*} [args] The arguments to invoke the method with.
  12405. * @returns {*} Returns the result of the invoked method.
  12406. * @example
  12407. *
  12408. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12409. *
  12410. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12411. * // => [2, 3]
  12412. */
  12413. var invoke = baseRest(baseInvoke);
  12414. /**
  12415. * Creates an array of the own enumerable property names of `object`.
  12416. *
  12417. * **Note:** Non-object values are coerced to objects. See the
  12418. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12419. * for more details.
  12420. *
  12421. * @static
  12422. * @since 0.1.0
  12423. * @memberOf _
  12424. * @category Object
  12425. * @param {Object} object The object to query.
  12426. * @returns {Array} Returns the array of property names.
  12427. * @example
  12428. *
  12429. * function Foo() {
  12430. * this.a = 1;
  12431. * this.b = 2;
  12432. * }
  12433. *
  12434. * Foo.prototype.c = 3;
  12435. *
  12436. * _.keys(new Foo);
  12437. * // => ['a', 'b'] (iteration order is not guaranteed)
  12438. *
  12439. * _.keys('hi');
  12440. * // => ['0', '1']
  12441. */
  12442. function keys(object) {
  12443. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12444. }
  12445. /**
  12446. * Creates an array of the own and inherited enumerable property names of `object`.
  12447. *
  12448. * **Note:** Non-object values are coerced to objects.
  12449. *
  12450. * @static
  12451. * @memberOf _
  12452. * @since 3.0.0
  12453. * @category Object
  12454. * @param {Object} object The object to query.
  12455. * @returns {Array} Returns the array of property names.
  12456. * @example
  12457. *
  12458. * function Foo() {
  12459. * this.a = 1;
  12460. * this.b = 2;
  12461. * }
  12462. *
  12463. * Foo.prototype.c = 3;
  12464. *
  12465. * _.keysIn(new Foo);
  12466. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12467. */
  12468. function keysIn(object) {
  12469. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12470. }
  12471. /**
  12472. * The opposite of `_.mapValues`; this method creates an object with the
  12473. * same values as `object` and keys generated by running each own enumerable
  12474. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12475. * with three arguments: (value, key, object).
  12476. *
  12477. * @static
  12478. * @memberOf _
  12479. * @since 3.8.0
  12480. * @category Object
  12481. * @param {Object} object The object to iterate over.
  12482. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12483. * @returns {Object} Returns the new mapped object.
  12484. * @see _.mapValues
  12485. * @example
  12486. *
  12487. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12488. * return key + value;
  12489. * });
  12490. * // => { 'a1': 1, 'b2': 2 }
  12491. */
  12492. function mapKeys(object, iteratee) {
  12493. var result = {};
  12494. iteratee = getIteratee(iteratee, 3);
  12495. baseForOwn(object, function(value, key, object) {
  12496. baseAssignValue(result, iteratee(value, key, object), value);
  12497. });
  12498. return result;
  12499. }
  12500. /**
  12501. * Creates an object with the same keys as `object` and values generated
  12502. * by running each own enumerable string keyed property of `object` thru
  12503. * `iteratee`. The iteratee is invoked with three arguments:
  12504. * (value, key, object).
  12505. *
  12506. * @static
  12507. * @memberOf _
  12508. * @since 2.4.0
  12509. * @category Object
  12510. * @param {Object} object The object to iterate over.
  12511. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12512. * @returns {Object} Returns the new mapped object.
  12513. * @see _.mapKeys
  12514. * @example
  12515. *
  12516. * var users = {
  12517. * 'fred': { 'user': 'fred', 'age': 40 },
  12518. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12519. * };
  12520. *
  12521. * _.mapValues(users, function(o) { return o.age; });
  12522. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12523. *
  12524. * // The `_.property` iteratee shorthand.
  12525. * _.mapValues(users, 'age');
  12526. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12527. */
  12528. function mapValues(object, iteratee) {
  12529. var result = {};
  12530. iteratee = getIteratee(iteratee, 3);
  12531. baseForOwn(object, function(value, key, object) {
  12532. baseAssignValue(result, key, iteratee(value, key, object));
  12533. });
  12534. return result;
  12535. }
  12536. /**
  12537. * This method is like `_.assign` except that it recursively merges own and
  12538. * inherited enumerable string keyed properties of source objects into the
  12539. * destination object. Source properties that resolve to `undefined` are
  12540. * skipped if a destination value exists. Array and plain object properties
  12541. * are merged recursively. Other objects and value types are overridden by
  12542. * assignment. Source objects are applied from left to right. Subsequent
  12543. * sources overwrite property assignments of previous sources.
  12544. *
  12545. * **Note:** This method mutates `object`.
  12546. *
  12547. * @static
  12548. * @memberOf _
  12549. * @since 0.5.0
  12550. * @category Object
  12551. * @param {Object} object The destination object.
  12552. * @param {...Object} [sources] The source objects.
  12553. * @returns {Object} Returns `object`.
  12554. * @example
  12555. *
  12556. * var object = {
  12557. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12558. * };
  12559. *
  12560. * var other = {
  12561. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12562. * };
  12563. *
  12564. * _.merge(object, other);
  12565. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12566. */
  12567. var merge = createAssigner(function(object, source, srcIndex) {
  12568. baseMerge(object, source, srcIndex);
  12569. });
  12570. /**
  12571. * This method is like `_.merge` except that it accepts `customizer` which
  12572. * is invoked to produce the merged values of the destination and source
  12573. * properties. If `customizer` returns `undefined`, merging is handled by the
  12574. * method instead. The `customizer` is invoked with six arguments:
  12575. * (objValue, srcValue, key, object, source, stack).
  12576. *
  12577. * **Note:** This method mutates `object`.
  12578. *
  12579. * @static
  12580. * @memberOf _
  12581. * @since 4.0.0
  12582. * @category Object
  12583. * @param {Object} object The destination object.
  12584. * @param {...Object} sources The source objects.
  12585. * @param {Function} customizer The function to customize assigned values.
  12586. * @returns {Object} Returns `object`.
  12587. * @example
  12588. *
  12589. * function customizer(objValue, srcValue) {
  12590. * if (_.isArray(objValue)) {
  12591. * return objValue.concat(srcValue);
  12592. * }
  12593. * }
  12594. *
  12595. * var object = { 'a': [1], 'b': [2] };
  12596. * var other = { 'a': [3], 'b': [4] };
  12597. *
  12598. * _.mergeWith(object, other, customizer);
  12599. * // => { 'a': [1, 3], 'b': [2, 4] }
  12600. */
  12601. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12602. baseMerge(object, source, srcIndex, customizer);
  12603. });
  12604. /**
  12605. * The opposite of `_.pick`; this method creates an object composed of the
  12606. * own and inherited enumerable property paths of `object` that are not omitted.
  12607. *
  12608. * **Note:** This method is considerably slower than `_.pick`.
  12609. *
  12610. * @static
  12611. * @since 0.1.0
  12612. * @memberOf _
  12613. * @category Object
  12614. * @param {Object} object The source object.
  12615. * @param {...(string|string[])} [paths] The property paths to omit.
  12616. * @returns {Object} Returns the new object.
  12617. * @example
  12618. *
  12619. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12620. *
  12621. * _.omit(object, ['a', 'c']);
  12622. * // => { 'b': '2' }
  12623. */
  12624. var omit = flatRest(function(object, paths) {
  12625. var result = {};
  12626. if (object == null) {
  12627. return result;
  12628. }
  12629. var isDeep = false;
  12630. paths = arrayMap(paths, function(path) {
  12631. path = castPath(path, object);
  12632. isDeep || (isDeep = path.length > 1);
  12633. return path;
  12634. });
  12635. copyObject(object, getAllKeysIn(object), result);
  12636. if (isDeep) {
  12637. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12638. }
  12639. var length = paths.length;
  12640. while (length--) {
  12641. baseUnset(result, paths[length]);
  12642. }
  12643. return result;
  12644. });
  12645. /**
  12646. * The opposite of `_.pickBy`; this method creates an object composed of
  12647. * the own and inherited enumerable string keyed properties of `object` that
  12648. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12649. * arguments: (value, key).
  12650. *
  12651. * @static
  12652. * @memberOf _
  12653. * @since 4.0.0
  12654. * @category Object
  12655. * @param {Object} object The source object.
  12656. * @param {Function} [predicate=_.identity] The function invoked per property.
  12657. * @returns {Object} Returns the new object.
  12658. * @example
  12659. *
  12660. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12661. *
  12662. * _.omitBy(object, _.isNumber);
  12663. * // => { 'b': '2' }
  12664. */
  12665. function omitBy(object, predicate) {
  12666. return pickBy(object, negate(getIteratee(predicate)));
  12667. }
  12668. /**
  12669. * Creates an object composed of the picked `object` properties.
  12670. *
  12671. * @static
  12672. * @since 0.1.0
  12673. * @memberOf _
  12674. * @category Object
  12675. * @param {Object} object The source object.
  12676. * @param {...(string|string[])} [paths] The property paths to pick.
  12677. * @returns {Object} Returns the new object.
  12678. * @example
  12679. *
  12680. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12681. *
  12682. * _.pick(object, ['a', 'c']);
  12683. * // => { 'a': 1, 'c': 3 }
  12684. */
  12685. var pick = flatRest(function(object, paths) {
  12686. return object == null ? {} : basePick(object, paths);
  12687. });
  12688. /**
  12689. * Creates an object composed of the `object` properties `predicate` returns
  12690. * truthy for. The predicate is invoked with two arguments: (value, key).
  12691. *
  12692. * @static
  12693. * @memberOf _
  12694. * @since 4.0.0
  12695. * @category Object
  12696. * @param {Object} object The source object.
  12697. * @param {Function} [predicate=_.identity] The function invoked per property.
  12698. * @returns {Object} Returns the new object.
  12699. * @example
  12700. *
  12701. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12702. *
  12703. * _.pickBy(object, _.isNumber);
  12704. * // => { 'a': 1, 'c': 3 }
  12705. */
  12706. function pickBy(object, predicate) {
  12707. if (object == null) {
  12708. return {};
  12709. }
  12710. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12711. return [prop];
  12712. });
  12713. predicate = getIteratee(predicate);
  12714. return basePickBy(object, props, function(value, path) {
  12715. return predicate(value, path[0]);
  12716. });
  12717. }
  12718. /**
  12719. * This method is like `_.get` except that if the resolved value is a
  12720. * function it's invoked with the `this` binding of its parent object and
  12721. * its result is returned.
  12722. *
  12723. * @static
  12724. * @since 0.1.0
  12725. * @memberOf _
  12726. * @category Object
  12727. * @param {Object} object The object to query.
  12728. * @param {Array|string} path The path of the property to resolve.
  12729. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12730. * @returns {*} Returns the resolved value.
  12731. * @example
  12732. *
  12733. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12734. *
  12735. * _.result(object, 'a[0].b.c1');
  12736. * // => 3
  12737. *
  12738. * _.result(object, 'a[0].b.c2');
  12739. * // => 4
  12740. *
  12741. * _.result(object, 'a[0].b.c3', 'default');
  12742. * // => 'default'
  12743. *
  12744. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12745. * // => 'default'
  12746. */
  12747. function result(object, path, defaultValue) {
  12748. path = castPath(path, object);
  12749. var index = -1,
  12750. length = path.length;
  12751. // Ensure the loop is entered when path is empty.
  12752. if (!length) {
  12753. length = 1;
  12754. object = undefined;
  12755. }
  12756. while (++index < length) {
  12757. var value = object == null ? undefined : object[toKey(path[index])];
  12758. if (value === undefined) {
  12759. index = length;
  12760. value = defaultValue;
  12761. }
  12762. object = isFunction(value) ? value.call(object) : value;
  12763. }
  12764. return object;
  12765. }
  12766. /**
  12767. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12768. * it's created. Arrays are created for missing index properties while objects
  12769. * are created for all other missing properties. Use `_.setWith` to customize
  12770. * `path` creation.
  12771. *
  12772. * **Note:** This method mutates `object`.
  12773. *
  12774. * @static
  12775. * @memberOf _
  12776. * @since 3.7.0
  12777. * @category Object
  12778. * @param {Object} object The object to modify.
  12779. * @param {Array|string} path The path of the property to set.
  12780. * @param {*} value The value to set.
  12781. * @returns {Object} Returns `object`.
  12782. * @example
  12783. *
  12784. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12785. *
  12786. * _.set(object, 'a[0].b.c', 4);
  12787. * console.log(object.a[0].b.c);
  12788. * // => 4
  12789. *
  12790. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12791. * console.log(object.x[0].y.z);
  12792. * // => 5
  12793. */
  12794. function set(object, path, value) {
  12795. return object == null ? object : baseSet(object, path, value);
  12796. }
  12797. /**
  12798. * This method is like `_.set` except that it accepts `customizer` which is
  12799. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12800. * path creation is handled by the method instead. The `customizer` is invoked
  12801. * with three arguments: (nsValue, key, nsObject).
  12802. *
  12803. * **Note:** This method mutates `object`.
  12804. *
  12805. * @static
  12806. * @memberOf _
  12807. * @since 4.0.0
  12808. * @category Object
  12809. * @param {Object} object The object to modify.
  12810. * @param {Array|string} path The path of the property to set.
  12811. * @param {*} value The value to set.
  12812. * @param {Function} [customizer] The function to customize assigned values.
  12813. * @returns {Object} Returns `object`.
  12814. * @example
  12815. *
  12816. * var object = {};
  12817. *
  12818. * _.setWith(object, '[0][1]', 'a', Object);
  12819. * // => { '0': { '1': 'a' } }
  12820. */
  12821. function setWith(object, path, value, customizer) {
  12822. customizer = typeof customizer == 'function' ? customizer : undefined;
  12823. return object == null ? object : baseSet(object, path, value, customizer);
  12824. }
  12825. /**
  12826. * Creates an array of own enumerable string keyed-value pairs for `object`
  12827. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12828. * entries are returned.
  12829. *
  12830. * @static
  12831. * @memberOf _
  12832. * @since 4.0.0
  12833. * @alias entries
  12834. * @category Object
  12835. * @param {Object} object The object to query.
  12836. * @returns {Array} Returns the key-value pairs.
  12837. * @example
  12838. *
  12839. * function Foo() {
  12840. * this.a = 1;
  12841. * this.b = 2;
  12842. * }
  12843. *
  12844. * Foo.prototype.c = 3;
  12845. *
  12846. * _.toPairs(new Foo);
  12847. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12848. */
  12849. var toPairs = createToPairs(keys);
  12850. /**
  12851. * Creates an array of own and inherited enumerable string keyed-value pairs
  12852. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12853. * or set, its entries are returned.
  12854. *
  12855. * @static
  12856. * @memberOf _
  12857. * @since 4.0.0
  12858. * @alias entriesIn
  12859. * @category Object
  12860. * @param {Object} object The object to query.
  12861. * @returns {Array} Returns the key-value pairs.
  12862. * @example
  12863. *
  12864. * function Foo() {
  12865. * this.a = 1;
  12866. * this.b = 2;
  12867. * }
  12868. *
  12869. * Foo.prototype.c = 3;
  12870. *
  12871. * _.toPairsIn(new Foo);
  12872. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12873. */
  12874. var toPairsIn = createToPairs(keysIn);
  12875. /**
  12876. * An alternative to `_.reduce`; this method transforms `object` to a new
  12877. * `accumulator` object which is the result of running each of its own
  12878. * enumerable string keyed properties thru `iteratee`, with each invocation
  12879. * potentially mutating the `accumulator` object. If `accumulator` is not
  12880. * provided, a new object with the same `[[Prototype]]` will be used. The
  12881. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12882. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12883. *
  12884. * @static
  12885. * @memberOf _
  12886. * @since 1.3.0
  12887. * @category Object
  12888. * @param {Object} object The object to iterate over.
  12889. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12890. * @param {*} [accumulator] The custom accumulator value.
  12891. * @returns {*} Returns the accumulated value.
  12892. * @example
  12893. *
  12894. * _.transform([2, 3, 4], function(result, n) {
  12895. * result.push(n *= n);
  12896. * return n % 2 == 0;
  12897. * }, []);
  12898. * // => [4, 9]
  12899. *
  12900. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12901. * (result[value] || (result[value] = [])).push(key);
  12902. * }, {});
  12903. * // => { '1': ['a', 'c'], '2': ['b'] }
  12904. */
  12905. function transform(object, iteratee, accumulator) {
  12906. var isArr = isArray(object),
  12907. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12908. iteratee = getIteratee(iteratee, 4);
  12909. if (accumulator == null) {
  12910. var Ctor = object && object.constructor;
  12911. if (isArrLike) {
  12912. accumulator = isArr ? new Ctor : [];
  12913. }
  12914. else if (isObject(object)) {
  12915. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12916. }
  12917. else {
  12918. accumulator = {};
  12919. }
  12920. }
  12921. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12922. return iteratee(accumulator, value, index, object);
  12923. });
  12924. return accumulator;
  12925. }
  12926. /**
  12927. * Removes the property at `path` of `object`.
  12928. *
  12929. * **Note:** This method mutates `object`.
  12930. *
  12931. * @static
  12932. * @memberOf _
  12933. * @since 4.0.0
  12934. * @category Object
  12935. * @param {Object} object The object to modify.
  12936. * @param {Array|string} path The path of the property to unset.
  12937. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12938. * @example
  12939. *
  12940. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12941. * _.unset(object, 'a[0].b.c');
  12942. * // => true
  12943. *
  12944. * console.log(object);
  12945. * // => { 'a': [{ 'b': {} }] };
  12946. *
  12947. * _.unset(object, ['a', '0', 'b', 'c']);
  12948. * // => true
  12949. *
  12950. * console.log(object);
  12951. * // => { 'a': [{ 'b': {} }] };
  12952. */
  12953. function unset(object, path) {
  12954. return object == null ? true : baseUnset(object, path);
  12955. }
  12956. /**
  12957. * This method is like `_.set` except that accepts `updater` to produce the
  12958. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12959. * is invoked with one argument: (value).
  12960. *
  12961. * **Note:** This method mutates `object`.
  12962. *
  12963. * @static
  12964. * @memberOf _
  12965. * @since 4.6.0
  12966. * @category Object
  12967. * @param {Object} object The object to modify.
  12968. * @param {Array|string} path The path of the property to set.
  12969. * @param {Function} updater The function to produce the updated value.
  12970. * @returns {Object} Returns `object`.
  12971. * @example
  12972. *
  12973. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12974. *
  12975. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12976. * console.log(object.a[0].b.c);
  12977. * // => 9
  12978. *
  12979. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12980. * console.log(object.x[0].y.z);
  12981. * // => 0
  12982. */
  12983. function update(object, path, updater) {
  12984. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12985. }
  12986. /**
  12987. * This method is like `_.update` except that it accepts `customizer` which is
  12988. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12989. * path creation is handled by the method instead. The `customizer` is invoked
  12990. * with three arguments: (nsValue, key, nsObject).
  12991. *
  12992. * **Note:** This method mutates `object`.
  12993. *
  12994. * @static
  12995. * @memberOf _
  12996. * @since 4.6.0
  12997. * @category Object
  12998. * @param {Object} object The object to modify.
  12999. * @param {Array|string} path The path of the property to set.
  13000. * @param {Function} updater The function to produce the updated value.
  13001. * @param {Function} [customizer] The function to customize assigned values.
  13002. * @returns {Object} Returns `object`.
  13003. * @example
  13004. *
  13005. * var object = {};
  13006. *
  13007. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13008. * // => { '0': { '1': 'a' } }
  13009. */
  13010. function updateWith(object, path, updater, customizer) {
  13011. customizer = typeof customizer == 'function' ? customizer : undefined;
  13012. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13013. }
  13014. /**
  13015. * Creates an array of the own enumerable string keyed property values of `object`.
  13016. *
  13017. * **Note:** Non-object values are coerced to objects.
  13018. *
  13019. * @static
  13020. * @since 0.1.0
  13021. * @memberOf _
  13022. * @category Object
  13023. * @param {Object} object The object to query.
  13024. * @returns {Array} Returns the array of property values.
  13025. * @example
  13026. *
  13027. * function Foo() {
  13028. * this.a = 1;
  13029. * this.b = 2;
  13030. * }
  13031. *
  13032. * Foo.prototype.c = 3;
  13033. *
  13034. * _.values(new Foo);
  13035. * // => [1, 2] (iteration order is not guaranteed)
  13036. *
  13037. * _.values('hi');
  13038. * // => ['h', 'i']
  13039. */
  13040. function values(object) {
  13041. return object == null ? [] : baseValues(object, keys(object));
  13042. }
  13043. /**
  13044. * Creates an array of the own and inherited enumerable string keyed property
  13045. * values of `object`.
  13046. *
  13047. * **Note:** Non-object values are coerced to objects.
  13048. *
  13049. * @static
  13050. * @memberOf _
  13051. * @since 3.0.0
  13052. * @category Object
  13053. * @param {Object} object The object to query.
  13054. * @returns {Array} Returns the array of property values.
  13055. * @example
  13056. *
  13057. * function Foo() {
  13058. * this.a = 1;
  13059. * this.b = 2;
  13060. * }
  13061. *
  13062. * Foo.prototype.c = 3;
  13063. *
  13064. * _.valuesIn(new Foo);
  13065. * // => [1, 2, 3] (iteration order is not guaranteed)
  13066. */
  13067. function valuesIn(object) {
  13068. return object == null ? [] : baseValues(object, keysIn(object));
  13069. }
  13070. /*------------------------------------------------------------------------*/
  13071. /**
  13072. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13073. *
  13074. * @static
  13075. * @memberOf _
  13076. * @since 4.0.0
  13077. * @category Number
  13078. * @param {number} number The number to clamp.
  13079. * @param {number} [lower] The lower bound.
  13080. * @param {number} upper The upper bound.
  13081. * @returns {number} Returns the clamped number.
  13082. * @example
  13083. *
  13084. * _.clamp(-10, -5, 5);
  13085. * // => -5
  13086. *
  13087. * _.clamp(10, -5, 5);
  13088. * // => 5
  13089. */
  13090. function clamp(number, lower, upper) {
  13091. if (upper === undefined) {
  13092. upper = lower;
  13093. lower = undefined;
  13094. }
  13095. if (upper !== undefined) {
  13096. upper = toNumber(upper);
  13097. upper = upper === upper ? upper : 0;
  13098. }
  13099. if (lower !== undefined) {
  13100. lower = toNumber(lower);
  13101. lower = lower === lower ? lower : 0;
  13102. }
  13103. return baseClamp(toNumber(number), lower, upper);
  13104. }
  13105. /**
  13106. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13107. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13108. * If `start` is greater than `end` the params are swapped to support
  13109. * negative ranges.
  13110. *
  13111. * @static
  13112. * @memberOf _
  13113. * @since 3.3.0
  13114. * @category Number
  13115. * @param {number} number The number to check.
  13116. * @param {number} [start=0] The start of the range.
  13117. * @param {number} end The end of the range.
  13118. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13119. * @see _.range, _.rangeRight
  13120. * @example
  13121. *
  13122. * _.inRange(3, 2, 4);
  13123. * // => true
  13124. *
  13125. * _.inRange(4, 8);
  13126. * // => true
  13127. *
  13128. * _.inRange(4, 2);
  13129. * // => false
  13130. *
  13131. * _.inRange(2, 2);
  13132. * // => false
  13133. *
  13134. * _.inRange(1.2, 2);
  13135. * // => true
  13136. *
  13137. * _.inRange(5.2, 4);
  13138. * // => false
  13139. *
  13140. * _.inRange(-3, -2, -6);
  13141. * // => true
  13142. */
  13143. function inRange(number, start, end) {
  13144. start = toFinite(start);
  13145. if (end === undefined) {
  13146. end = start;
  13147. start = 0;
  13148. } else {
  13149. end = toFinite(end);
  13150. }
  13151. number = toNumber(number);
  13152. return baseInRange(number, start, end);
  13153. }
  13154. /**
  13155. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13156. * If only one argument is provided a number between `0` and the given number
  13157. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13158. * floats, a floating-point number is returned instead of an integer.
  13159. *
  13160. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13161. * floating-point values which can produce unexpected results.
  13162. *
  13163. * @static
  13164. * @memberOf _
  13165. * @since 0.7.0
  13166. * @category Number
  13167. * @param {number} [lower=0] The lower bound.
  13168. * @param {number} [upper=1] The upper bound.
  13169. * @param {boolean} [floating] Specify returning a floating-point number.
  13170. * @returns {number} Returns the random number.
  13171. * @example
  13172. *
  13173. * _.random(0, 5);
  13174. * // => an integer between 0 and 5
  13175. *
  13176. * _.random(5);
  13177. * // => also an integer between 0 and 5
  13178. *
  13179. * _.random(5, true);
  13180. * // => a floating-point number between 0 and 5
  13181. *
  13182. * _.random(1.2, 5.2);
  13183. * // => a floating-point number between 1.2 and 5.2
  13184. */
  13185. function random(lower, upper, floating) {
  13186. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13187. upper = floating = undefined;
  13188. }
  13189. if (floating === undefined) {
  13190. if (typeof upper == 'boolean') {
  13191. floating = upper;
  13192. upper = undefined;
  13193. }
  13194. else if (typeof lower == 'boolean') {
  13195. floating = lower;
  13196. lower = undefined;
  13197. }
  13198. }
  13199. if (lower === undefined && upper === undefined) {
  13200. lower = 0;
  13201. upper = 1;
  13202. }
  13203. else {
  13204. lower = toFinite(lower);
  13205. if (upper === undefined) {
  13206. upper = lower;
  13207. lower = 0;
  13208. } else {
  13209. upper = toFinite(upper);
  13210. }
  13211. }
  13212. if (lower > upper) {
  13213. var temp = lower;
  13214. lower = upper;
  13215. upper = temp;
  13216. }
  13217. if (floating || lower % 1 || upper % 1) {
  13218. var rand = nativeRandom();
  13219. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13220. }
  13221. return baseRandom(lower, upper);
  13222. }
  13223. /*------------------------------------------------------------------------*/
  13224. /**
  13225. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13226. *
  13227. * @static
  13228. * @memberOf _
  13229. * @since 3.0.0
  13230. * @category String
  13231. * @param {string} [string=''] The string to convert.
  13232. * @returns {string} Returns the camel cased string.
  13233. * @example
  13234. *
  13235. * _.camelCase('Foo Bar');
  13236. * // => 'fooBar'
  13237. *
  13238. * _.camelCase('--foo-bar--');
  13239. * // => 'fooBar'
  13240. *
  13241. * _.camelCase('__FOO_BAR__');
  13242. * // => 'fooBar'
  13243. */
  13244. var camelCase = createCompounder(function(result, word, index) {
  13245. word = word.toLowerCase();
  13246. return result + (index ? capitalize(word) : word);
  13247. });
  13248. /**
  13249. * Converts the first character of `string` to upper case and the remaining
  13250. * to lower case.
  13251. *
  13252. * @static
  13253. * @memberOf _
  13254. * @since 3.0.0
  13255. * @category String
  13256. * @param {string} [string=''] The string to capitalize.
  13257. * @returns {string} Returns the capitalized string.
  13258. * @example
  13259. *
  13260. * _.capitalize('FRED');
  13261. * // => 'Fred'
  13262. */
  13263. function capitalize(string) {
  13264. return upperFirst(toString(string).toLowerCase());
  13265. }
  13266. /**
  13267. * Deburrs `string` by converting
  13268. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13269. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13270. * letters to basic Latin letters and removing
  13271. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13272. *
  13273. * @static
  13274. * @memberOf _
  13275. * @since 3.0.0
  13276. * @category String
  13277. * @param {string} [string=''] The string to deburr.
  13278. * @returns {string} Returns the deburred string.
  13279. * @example
  13280. *
  13281. * _.deburr('déjà vu');
  13282. * // => 'deja vu'
  13283. */
  13284. function deburr(string) {
  13285. string = toString(string);
  13286. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13287. }
  13288. /**
  13289. * Checks if `string` ends with the given target string.
  13290. *
  13291. * @static
  13292. * @memberOf _
  13293. * @since 3.0.0
  13294. * @category String
  13295. * @param {string} [string=''] The string to inspect.
  13296. * @param {string} [target] The string to search for.
  13297. * @param {number} [position=string.length] The position to search up to.
  13298. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13299. * else `false`.
  13300. * @example
  13301. *
  13302. * _.endsWith('abc', 'c');
  13303. * // => true
  13304. *
  13305. * _.endsWith('abc', 'b');
  13306. * // => false
  13307. *
  13308. * _.endsWith('abc', 'b', 2);
  13309. * // => true
  13310. */
  13311. function endsWith(string, target, position) {
  13312. string = toString(string);
  13313. target = baseToString(target);
  13314. var length = string.length;
  13315. position = position === undefined
  13316. ? length
  13317. : baseClamp(toInteger(position), 0, length);
  13318. var end = position;
  13319. position -= target.length;
  13320. return position >= 0 && string.slice(position, end) == target;
  13321. }
  13322. /**
  13323. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13324. * corresponding HTML entities.
  13325. *
  13326. * **Note:** No other characters are escaped. To escape additional
  13327. * characters use a third-party library like [_he_](https://mths.be/he).
  13328. *
  13329. * Though the ">" character is escaped for symmetry, characters like
  13330. * ">" and "/" don't need escaping in HTML and have no special meaning
  13331. * unless they're part of a tag or unquoted attribute value. See
  13332. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13333. * (under "semi-related fun fact") for more details.
  13334. *
  13335. * When working with HTML you should always
  13336. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13337. * XSS vectors.
  13338. *
  13339. * @static
  13340. * @since 0.1.0
  13341. * @memberOf _
  13342. * @category String
  13343. * @param {string} [string=''] The string to escape.
  13344. * @returns {string} Returns the escaped string.
  13345. * @example
  13346. *
  13347. * _.escape('fred, barney, & pebbles');
  13348. * // => 'fred, barney, &amp; pebbles'
  13349. */
  13350. function escape(string) {
  13351. string = toString(string);
  13352. return (string && reHasUnescapedHtml.test(string))
  13353. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13354. : string;
  13355. }
  13356. /**
  13357. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13358. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13359. *
  13360. * @static
  13361. * @memberOf _
  13362. * @since 3.0.0
  13363. * @category String
  13364. * @param {string} [string=''] The string to escape.
  13365. * @returns {string} Returns the escaped string.
  13366. * @example
  13367. *
  13368. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13369. * // => '\[lodash\]\(https://lodash\.com/\)'
  13370. */
  13371. function escapeRegExp(string) {
  13372. string = toString(string);
  13373. return (string && reHasRegExpChar.test(string))
  13374. ? string.replace(reRegExpChar, '\\$&')
  13375. : string;
  13376. }
  13377. /**
  13378. * Converts `string` to
  13379. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13380. *
  13381. * @static
  13382. * @memberOf _
  13383. * @since 3.0.0
  13384. * @category String
  13385. * @param {string} [string=''] The string to convert.
  13386. * @returns {string} Returns the kebab cased string.
  13387. * @example
  13388. *
  13389. * _.kebabCase('Foo Bar');
  13390. * // => 'foo-bar'
  13391. *
  13392. * _.kebabCase('fooBar');
  13393. * // => 'foo-bar'
  13394. *
  13395. * _.kebabCase('__FOO_BAR__');
  13396. * // => 'foo-bar'
  13397. */
  13398. var kebabCase = createCompounder(function(result, word, index) {
  13399. return result + (index ? '-' : '') + word.toLowerCase();
  13400. });
  13401. /**
  13402. * Converts `string`, as space separated words, to lower case.
  13403. *
  13404. * @static
  13405. * @memberOf _
  13406. * @since 4.0.0
  13407. * @category String
  13408. * @param {string} [string=''] The string to convert.
  13409. * @returns {string} Returns the lower cased string.
  13410. * @example
  13411. *
  13412. * _.lowerCase('--Foo-Bar--');
  13413. * // => 'foo bar'
  13414. *
  13415. * _.lowerCase('fooBar');
  13416. * // => 'foo bar'
  13417. *
  13418. * _.lowerCase('__FOO_BAR__');
  13419. * // => 'foo bar'
  13420. */
  13421. var lowerCase = createCompounder(function(result, word, index) {
  13422. return result + (index ? ' ' : '') + word.toLowerCase();
  13423. });
  13424. /**
  13425. * Converts the first character of `string` to lower case.
  13426. *
  13427. * @static
  13428. * @memberOf _
  13429. * @since 4.0.0
  13430. * @category String
  13431. * @param {string} [string=''] The string to convert.
  13432. * @returns {string} Returns the converted string.
  13433. * @example
  13434. *
  13435. * _.lowerFirst('Fred');
  13436. * // => 'fred'
  13437. *
  13438. * _.lowerFirst('FRED');
  13439. * // => 'fRED'
  13440. */
  13441. var lowerFirst = createCaseFirst('toLowerCase');
  13442. /**
  13443. * Pads `string` on the left and right sides if it's shorter than `length`.
  13444. * Padding characters are truncated if they can't be evenly divided by `length`.
  13445. *
  13446. * @static
  13447. * @memberOf _
  13448. * @since 3.0.0
  13449. * @category String
  13450. * @param {string} [string=''] The string to pad.
  13451. * @param {number} [length=0] The padding length.
  13452. * @param {string} [chars=' '] The string used as padding.
  13453. * @returns {string} Returns the padded string.
  13454. * @example
  13455. *
  13456. * _.pad('abc', 8);
  13457. * // => ' abc '
  13458. *
  13459. * _.pad('abc', 8, '_-');
  13460. * // => '_-abc_-_'
  13461. *
  13462. * _.pad('abc', 3);
  13463. * // => 'abc'
  13464. */
  13465. function pad(string, length, chars) {
  13466. string = toString(string);
  13467. length = toInteger(length);
  13468. var strLength = length ? stringSize(string) : 0;
  13469. if (!length || strLength >= length) {
  13470. return string;
  13471. }
  13472. var mid = (length - strLength) / 2;
  13473. return (
  13474. createPadding(nativeFloor(mid), chars) +
  13475. string +
  13476. createPadding(nativeCeil(mid), chars)
  13477. );
  13478. }
  13479. /**
  13480. * Pads `string` on the right side if it's shorter than `length`. Padding
  13481. * characters are truncated if they exceed `length`.
  13482. *
  13483. * @static
  13484. * @memberOf _
  13485. * @since 4.0.0
  13486. * @category String
  13487. * @param {string} [string=''] The string to pad.
  13488. * @param {number} [length=0] The padding length.
  13489. * @param {string} [chars=' '] The string used as padding.
  13490. * @returns {string} Returns the padded string.
  13491. * @example
  13492. *
  13493. * _.padEnd('abc', 6);
  13494. * // => 'abc '
  13495. *
  13496. * _.padEnd('abc', 6, '_-');
  13497. * // => 'abc_-_'
  13498. *
  13499. * _.padEnd('abc', 3);
  13500. * // => 'abc'
  13501. */
  13502. function padEnd(string, length, chars) {
  13503. string = toString(string);
  13504. length = toInteger(length);
  13505. var strLength = length ? stringSize(string) : 0;
  13506. return (length && strLength < length)
  13507. ? (string + createPadding(length - strLength, chars))
  13508. : string;
  13509. }
  13510. /**
  13511. * Pads `string` on the left side if it's shorter than `length`. Padding
  13512. * characters are truncated if they exceed `length`.
  13513. *
  13514. * @static
  13515. * @memberOf _
  13516. * @since 4.0.0
  13517. * @category String
  13518. * @param {string} [string=''] The string to pad.
  13519. * @param {number} [length=0] The padding length.
  13520. * @param {string} [chars=' '] The string used as padding.
  13521. * @returns {string} Returns the padded string.
  13522. * @example
  13523. *
  13524. * _.padStart('abc', 6);
  13525. * // => ' abc'
  13526. *
  13527. * _.padStart('abc', 6, '_-');
  13528. * // => '_-_abc'
  13529. *
  13530. * _.padStart('abc', 3);
  13531. * // => 'abc'
  13532. */
  13533. function padStart(string, length, chars) {
  13534. string = toString(string);
  13535. length = toInteger(length);
  13536. var strLength = length ? stringSize(string) : 0;
  13537. return (length && strLength < length)
  13538. ? (createPadding(length - strLength, chars) + string)
  13539. : string;
  13540. }
  13541. /**
  13542. * Converts `string` to an integer of the specified radix. If `radix` is
  13543. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13544. * hexadecimal, in which case a `radix` of `16` is used.
  13545. *
  13546. * **Note:** This method aligns with the
  13547. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13548. *
  13549. * @static
  13550. * @memberOf _
  13551. * @since 1.1.0
  13552. * @category String
  13553. * @param {string} string The string to convert.
  13554. * @param {number} [radix=10] The radix to interpret `value` by.
  13555. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13556. * @returns {number} Returns the converted integer.
  13557. * @example
  13558. *
  13559. * _.parseInt('08');
  13560. * // => 8
  13561. *
  13562. * _.map(['6', '08', '10'], _.parseInt);
  13563. * // => [6, 8, 10]
  13564. */
  13565. function parseInt(string, radix, guard) {
  13566. if (guard || radix == null) {
  13567. radix = 0;
  13568. } else if (radix) {
  13569. radix = +radix;
  13570. }
  13571. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13572. }
  13573. /**
  13574. * Repeats the given string `n` times.
  13575. *
  13576. * @static
  13577. * @memberOf _
  13578. * @since 3.0.0
  13579. * @category String
  13580. * @param {string} [string=''] The string to repeat.
  13581. * @param {number} [n=1] The number of times to repeat the string.
  13582. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13583. * @returns {string} Returns the repeated string.
  13584. * @example
  13585. *
  13586. * _.repeat('*', 3);
  13587. * // => '***'
  13588. *
  13589. * _.repeat('abc', 2);
  13590. * // => 'abcabc'
  13591. *
  13592. * _.repeat('abc', 0);
  13593. * // => ''
  13594. */
  13595. function repeat(string, n, guard) {
  13596. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13597. n = 1;
  13598. } else {
  13599. n = toInteger(n);
  13600. }
  13601. return baseRepeat(toString(string), n);
  13602. }
  13603. /**
  13604. * Replaces matches for `pattern` in `string` with `replacement`.
  13605. *
  13606. * **Note:** This method is based on
  13607. * [`String#replace`](https://mdn.io/String/replace).
  13608. *
  13609. * @static
  13610. * @memberOf _
  13611. * @since 4.0.0
  13612. * @category String
  13613. * @param {string} [string=''] The string to modify.
  13614. * @param {RegExp|string} pattern The pattern to replace.
  13615. * @param {Function|string} replacement The match replacement.
  13616. * @returns {string} Returns the modified string.
  13617. * @example
  13618. *
  13619. * _.replace('Hi Fred', 'Fred', 'Barney');
  13620. * // => 'Hi Barney'
  13621. */
  13622. function replace() {
  13623. var args = arguments,
  13624. string = toString(args[0]);
  13625. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13626. }
  13627. /**
  13628. * Converts `string` to
  13629. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13630. *
  13631. * @static
  13632. * @memberOf _
  13633. * @since 3.0.0
  13634. * @category String
  13635. * @param {string} [string=''] The string to convert.
  13636. * @returns {string} Returns the snake cased string.
  13637. * @example
  13638. *
  13639. * _.snakeCase('Foo Bar');
  13640. * // => 'foo_bar'
  13641. *
  13642. * _.snakeCase('fooBar');
  13643. * // => 'foo_bar'
  13644. *
  13645. * _.snakeCase('--FOO-BAR--');
  13646. * // => 'foo_bar'
  13647. */
  13648. var snakeCase = createCompounder(function(result, word, index) {
  13649. return result + (index ? '_' : '') + word.toLowerCase();
  13650. });
  13651. /**
  13652. * Splits `string` by `separator`.
  13653. *
  13654. * **Note:** This method is based on
  13655. * [`String#split`](https://mdn.io/String/split).
  13656. *
  13657. * @static
  13658. * @memberOf _
  13659. * @since 4.0.0
  13660. * @category String
  13661. * @param {string} [string=''] The string to split.
  13662. * @param {RegExp|string} separator The separator pattern to split by.
  13663. * @param {number} [limit] The length to truncate results to.
  13664. * @returns {Array} Returns the string segments.
  13665. * @example
  13666. *
  13667. * _.split('a-b-c', '-', 2);
  13668. * // => ['a', 'b']
  13669. */
  13670. function split(string, separator, limit) {
  13671. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13672. separator = limit = undefined;
  13673. }
  13674. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13675. if (!limit) {
  13676. return [];
  13677. }
  13678. string = toString(string);
  13679. if (string && (
  13680. typeof separator == 'string' ||
  13681. (separator != null && !isRegExp(separator))
  13682. )) {
  13683. separator = baseToString(separator);
  13684. if (!separator && hasUnicode(string)) {
  13685. return castSlice(stringToArray(string), 0, limit);
  13686. }
  13687. }
  13688. return string.split(separator, limit);
  13689. }
  13690. /**
  13691. * Converts `string` to
  13692. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13693. *
  13694. * @static
  13695. * @memberOf _
  13696. * @since 3.1.0
  13697. * @category String
  13698. * @param {string} [string=''] The string to convert.
  13699. * @returns {string} Returns the start cased string.
  13700. * @example
  13701. *
  13702. * _.startCase('--foo-bar--');
  13703. * // => 'Foo Bar'
  13704. *
  13705. * _.startCase('fooBar');
  13706. * // => 'Foo Bar'
  13707. *
  13708. * _.startCase('__FOO_BAR__');
  13709. * // => 'FOO BAR'
  13710. */
  13711. var startCase = createCompounder(function(result, word, index) {
  13712. return result + (index ? ' ' : '') + upperFirst(word);
  13713. });
  13714. /**
  13715. * Checks if `string` starts with the given target string.
  13716. *
  13717. * @static
  13718. * @memberOf _
  13719. * @since 3.0.0
  13720. * @category String
  13721. * @param {string} [string=''] The string to inspect.
  13722. * @param {string} [target] The string to search for.
  13723. * @param {number} [position=0] The position to search from.
  13724. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13725. * else `false`.
  13726. * @example
  13727. *
  13728. * _.startsWith('abc', 'a');
  13729. * // => true
  13730. *
  13731. * _.startsWith('abc', 'b');
  13732. * // => false
  13733. *
  13734. * _.startsWith('abc', 'b', 1);
  13735. * // => true
  13736. */
  13737. function startsWith(string, target, position) {
  13738. string = toString(string);
  13739. position = position == null
  13740. ? 0
  13741. : baseClamp(toInteger(position), 0, string.length);
  13742. target = baseToString(target);
  13743. return string.slice(position, position + target.length) == target;
  13744. }
  13745. /**
  13746. * Creates a compiled template function that can interpolate data properties
  13747. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13748. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13749. * properties may be accessed as free variables in the template. If a setting
  13750. * object is given, it takes precedence over `_.templateSettings` values.
  13751. *
  13752. * **Note:** In the development build `_.template` utilizes
  13753. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13754. * for easier debugging.
  13755. *
  13756. * For more information on precompiling templates see
  13757. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13758. *
  13759. * For more information on Chrome extension sandboxes see
  13760. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13761. *
  13762. * @static
  13763. * @since 0.1.0
  13764. * @memberOf _
  13765. * @category String
  13766. * @param {string} [string=''] The template string.
  13767. * @param {Object} [options={}] The options object.
  13768. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13769. * The HTML "escape" delimiter.
  13770. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13771. * The "evaluate" delimiter.
  13772. * @param {Object} [options.imports=_.templateSettings.imports]
  13773. * An object to import into the template as free variables.
  13774. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13775. * The "interpolate" delimiter.
  13776. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13777. * The sourceURL of the compiled template.
  13778. * @param {string} [options.variable='obj']
  13779. * The data object variable name.
  13780. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13781. * @returns {Function} Returns the compiled template function.
  13782. * @example
  13783. *
  13784. * // Use the "interpolate" delimiter to create a compiled template.
  13785. * var compiled = _.template('hello <%= user %>!');
  13786. * compiled({ 'user': 'fred' });
  13787. * // => 'hello fred!'
  13788. *
  13789. * // Use the HTML "escape" delimiter to escape data property values.
  13790. * var compiled = _.template('<b><%- value %></b>');
  13791. * compiled({ 'value': '<script>' });
  13792. * // => '<b>&lt;script&gt;</b>'
  13793. *
  13794. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13795. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13796. * compiled({ 'users': ['fred', 'barney'] });
  13797. * // => '<li>fred</li><li>barney</li>'
  13798. *
  13799. * // Use the internal `print` function in "evaluate" delimiters.
  13800. * var compiled = _.template('<% print("hello " + user); %>!');
  13801. * compiled({ 'user': 'barney' });
  13802. * // => 'hello barney!'
  13803. *
  13804. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13805. * // Disable support by replacing the "interpolate" delimiter.
  13806. * var compiled = _.template('hello ${ user }!');
  13807. * compiled({ 'user': 'pebbles' });
  13808. * // => 'hello pebbles!'
  13809. *
  13810. * // Use backslashes to treat delimiters as plain text.
  13811. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13812. * compiled({ 'value': 'ignored' });
  13813. * // => '<%- value %>'
  13814. *
  13815. * // Use the `imports` option to import `jQuery` as `jq`.
  13816. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13817. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13818. * compiled({ 'users': ['fred', 'barney'] });
  13819. * // => '<li>fred</li><li>barney</li>'
  13820. *
  13821. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13822. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13823. * compiled(data);
  13824. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13825. *
  13826. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13827. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13828. * compiled.source;
  13829. * // => function(data) {
  13830. * // var __t, __p = '';
  13831. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13832. * // return __p;
  13833. * // }
  13834. *
  13835. * // Use custom template delimiters.
  13836. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13837. * var compiled = _.template('hello {{ user }}!');
  13838. * compiled({ 'user': 'mustache' });
  13839. * // => 'hello mustache!'
  13840. *
  13841. * // Use the `source` property to inline compiled templates for meaningful
  13842. * // line numbers in error messages and stack traces.
  13843. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13844. * var JST = {\
  13845. * "main": ' + _.template(mainText).source + '\
  13846. * };\
  13847. * ');
  13848. */
  13849. function template(string, options, guard) {
  13850. // Based on John Resig's `tmpl` implementation
  13851. // (http://ejohn.org/blog/javascript-micro-templating/)
  13852. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13853. var settings = lodash.templateSettings;
  13854. if (guard && isIterateeCall(string, options, guard)) {
  13855. options = undefined;
  13856. }
  13857. string = toString(string);
  13858. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13859. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13860. importsKeys = keys(imports),
  13861. importsValues = baseValues(imports, importsKeys);
  13862. var isEscaping,
  13863. isEvaluating,
  13864. index = 0,
  13865. interpolate = options.interpolate || reNoMatch,
  13866. source = "__p += '";
  13867. // Compile the regexp to match each delimiter.
  13868. var reDelimiters = RegExp(
  13869. (options.escape || reNoMatch).source + '|' +
  13870. interpolate.source + '|' +
  13871. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13872. (options.evaluate || reNoMatch).source + '|$'
  13873. , 'g');
  13874. // Use a sourceURL for easier debugging.
  13875. var sourceURL = '//# sourceURL=' +
  13876. ('sourceURL' in options
  13877. ? options.sourceURL
  13878. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13879. ) + '\n';
  13880. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13881. interpolateValue || (interpolateValue = esTemplateValue);
  13882. // Escape characters that can't be included in string literals.
  13883. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13884. // Replace delimiters with snippets.
  13885. if (escapeValue) {
  13886. isEscaping = true;
  13887. source += "' +\n__e(" + escapeValue + ") +\n'";
  13888. }
  13889. if (evaluateValue) {
  13890. isEvaluating = true;
  13891. source += "';\n" + evaluateValue + ";\n__p += '";
  13892. }
  13893. if (interpolateValue) {
  13894. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13895. }
  13896. index = offset + match.length;
  13897. // The JS engine embedded in Adobe products needs `match` returned in
  13898. // order to produce the correct `offset` value.
  13899. return match;
  13900. });
  13901. source += "';\n";
  13902. // If `variable` is not specified wrap a with-statement around the generated
  13903. // code to add the data object to the top of the scope chain.
  13904. var variable = options.variable;
  13905. if (!variable) {
  13906. source = 'with (obj) {\n' + source + '\n}\n';
  13907. }
  13908. // Cleanup code by stripping empty strings.
  13909. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13910. .replace(reEmptyStringMiddle, '$1')
  13911. .replace(reEmptyStringTrailing, '$1;');
  13912. // Frame code as the function body.
  13913. source = 'function(' + (variable || 'obj') + ') {\n' +
  13914. (variable
  13915. ? ''
  13916. : 'obj || (obj = {});\n'
  13917. ) +
  13918. "var __t, __p = ''" +
  13919. (isEscaping
  13920. ? ', __e = _.escape'
  13921. : ''
  13922. ) +
  13923. (isEvaluating
  13924. ? ', __j = Array.prototype.join;\n' +
  13925. "function print() { __p += __j.call(arguments, '') }\n"
  13926. : ';\n'
  13927. ) +
  13928. source +
  13929. 'return __p\n}';
  13930. var result = attempt(function() {
  13931. return Function(importsKeys, sourceURL + 'return ' + source)
  13932. .apply(undefined, importsValues);
  13933. });
  13934. // Provide the compiled function's source by its `toString` method or
  13935. // the `source` property as a convenience for inlining compiled templates.
  13936. result.source = source;
  13937. if (isError(result)) {
  13938. throw result;
  13939. }
  13940. return result;
  13941. }
  13942. /**
  13943. * Converts `string`, as a whole, to lower case just like
  13944. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13945. *
  13946. * @static
  13947. * @memberOf _
  13948. * @since 4.0.0
  13949. * @category String
  13950. * @param {string} [string=''] The string to convert.
  13951. * @returns {string} Returns the lower cased string.
  13952. * @example
  13953. *
  13954. * _.toLower('--Foo-Bar--');
  13955. * // => '--foo-bar--'
  13956. *
  13957. * _.toLower('fooBar');
  13958. * // => 'foobar'
  13959. *
  13960. * _.toLower('__FOO_BAR__');
  13961. * // => '__foo_bar__'
  13962. */
  13963. function toLower(value) {
  13964. return toString(value).toLowerCase();
  13965. }
  13966. /**
  13967. * Converts `string`, as a whole, to upper case just like
  13968. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13969. *
  13970. * @static
  13971. * @memberOf _
  13972. * @since 4.0.0
  13973. * @category String
  13974. * @param {string} [string=''] The string to convert.
  13975. * @returns {string} Returns the upper cased string.
  13976. * @example
  13977. *
  13978. * _.toUpper('--foo-bar--');
  13979. * // => '--FOO-BAR--'
  13980. *
  13981. * _.toUpper('fooBar');
  13982. * // => 'FOOBAR'
  13983. *
  13984. * _.toUpper('__foo_bar__');
  13985. * // => '__FOO_BAR__'
  13986. */
  13987. function toUpper(value) {
  13988. return toString(value).toUpperCase();
  13989. }
  13990. /**
  13991. * Removes leading and trailing whitespace or specified characters from `string`.
  13992. *
  13993. * @static
  13994. * @memberOf _
  13995. * @since 3.0.0
  13996. * @category String
  13997. * @param {string} [string=''] The string to trim.
  13998. * @param {string} [chars=whitespace] The characters to trim.
  13999. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14000. * @returns {string} Returns the trimmed string.
  14001. * @example
  14002. *
  14003. * _.trim(' abc ');
  14004. * // => 'abc'
  14005. *
  14006. * _.trim('-_-abc-_-', '_-');
  14007. * // => 'abc'
  14008. *
  14009. * _.map([' foo ', ' bar '], _.trim);
  14010. * // => ['foo', 'bar']
  14011. */
  14012. function trim(string, chars, guard) {
  14013. string = toString(string);
  14014. if (string && (guard || chars === undefined)) {
  14015. return string.replace(reTrim, '');
  14016. }
  14017. if (!string || !(chars = baseToString(chars))) {
  14018. return string;
  14019. }
  14020. var strSymbols = stringToArray(string),
  14021. chrSymbols = stringToArray(chars),
  14022. start = charsStartIndex(strSymbols, chrSymbols),
  14023. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14024. return castSlice(strSymbols, start, end).join('');
  14025. }
  14026. /**
  14027. * Removes trailing whitespace or specified characters from `string`.
  14028. *
  14029. * @static
  14030. * @memberOf _
  14031. * @since 4.0.0
  14032. * @category String
  14033. * @param {string} [string=''] The string to trim.
  14034. * @param {string} [chars=whitespace] The characters to trim.
  14035. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14036. * @returns {string} Returns the trimmed string.
  14037. * @example
  14038. *
  14039. * _.trimEnd(' abc ');
  14040. * // => ' abc'
  14041. *
  14042. * _.trimEnd('-_-abc-_-', '_-');
  14043. * // => '-_-abc'
  14044. */
  14045. function trimEnd(string, chars, guard) {
  14046. string = toString(string);
  14047. if (string && (guard || chars === undefined)) {
  14048. return string.replace(reTrimEnd, '');
  14049. }
  14050. if (!string || !(chars = baseToString(chars))) {
  14051. return string;
  14052. }
  14053. var strSymbols = stringToArray(string),
  14054. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14055. return castSlice(strSymbols, 0, end).join('');
  14056. }
  14057. /**
  14058. * Removes leading whitespace or specified characters from `string`.
  14059. *
  14060. * @static
  14061. * @memberOf _
  14062. * @since 4.0.0
  14063. * @category String
  14064. * @param {string} [string=''] The string to trim.
  14065. * @param {string} [chars=whitespace] The characters to trim.
  14066. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14067. * @returns {string} Returns the trimmed string.
  14068. * @example
  14069. *
  14070. * _.trimStart(' abc ');
  14071. * // => 'abc '
  14072. *
  14073. * _.trimStart('-_-abc-_-', '_-');
  14074. * // => 'abc-_-'
  14075. */
  14076. function trimStart(string, chars, guard) {
  14077. string = toString(string);
  14078. if (string && (guard || chars === undefined)) {
  14079. return string.replace(reTrimStart, '');
  14080. }
  14081. if (!string || !(chars = baseToString(chars))) {
  14082. return string;
  14083. }
  14084. var strSymbols = stringToArray(string),
  14085. start = charsStartIndex(strSymbols, stringToArray(chars));
  14086. return castSlice(strSymbols, start).join('');
  14087. }
  14088. /**
  14089. * Truncates `string` if it's longer than the given maximum string length.
  14090. * The last characters of the truncated string are replaced with the omission
  14091. * string which defaults to "...".
  14092. *
  14093. * @static
  14094. * @memberOf _
  14095. * @since 4.0.0
  14096. * @category String
  14097. * @param {string} [string=''] The string to truncate.
  14098. * @param {Object} [options={}] The options object.
  14099. * @param {number} [options.length=30] The maximum string length.
  14100. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14101. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14102. * @returns {string} Returns the truncated string.
  14103. * @example
  14104. *
  14105. * _.truncate('hi-diddly-ho there, neighborino');
  14106. * // => 'hi-diddly-ho there, neighbo...'
  14107. *
  14108. * _.truncate('hi-diddly-ho there, neighborino', {
  14109. * 'length': 24,
  14110. * 'separator': ' '
  14111. * });
  14112. * // => 'hi-diddly-ho there,...'
  14113. *
  14114. * _.truncate('hi-diddly-ho there, neighborino', {
  14115. * 'length': 24,
  14116. * 'separator': /,? +/
  14117. * });
  14118. * // => 'hi-diddly-ho there...'
  14119. *
  14120. * _.truncate('hi-diddly-ho there, neighborino', {
  14121. * 'omission': ' [...]'
  14122. * });
  14123. * // => 'hi-diddly-ho there, neig [...]'
  14124. */
  14125. function truncate(string, options) {
  14126. var length = DEFAULT_TRUNC_LENGTH,
  14127. omission = DEFAULT_TRUNC_OMISSION;
  14128. if (isObject(options)) {
  14129. var separator = 'separator' in options ? options.separator : separator;
  14130. length = 'length' in options ? toInteger(options.length) : length;
  14131. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14132. }
  14133. string = toString(string);
  14134. var strLength = string.length;
  14135. if (hasUnicode(string)) {
  14136. var strSymbols = stringToArray(string);
  14137. strLength = strSymbols.length;
  14138. }
  14139. if (length >= strLength) {
  14140. return string;
  14141. }
  14142. var end = length - stringSize(omission);
  14143. if (end < 1) {
  14144. return omission;
  14145. }
  14146. var result = strSymbols
  14147. ? castSlice(strSymbols, 0, end).join('')
  14148. : string.slice(0, end);
  14149. if (separator === undefined) {
  14150. return result + omission;
  14151. }
  14152. if (strSymbols) {
  14153. end += (result.length - end);
  14154. }
  14155. if (isRegExp(separator)) {
  14156. if (string.slice(end).search(separator)) {
  14157. var match,
  14158. substring = result;
  14159. if (!separator.global) {
  14160. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14161. }
  14162. separator.lastIndex = 0;
  14163. while ((match = separator.exec(substring))) {
  14164. var newEnd = match.index;
  14165. }
  14166. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14167. }
  14168. } else if (string.indexOf(baseToString(separator), end) != end) {
  14169. var index = result.lastIndexOf(separator);
  14170. if (index > -1) {
  14171. result = result.slice(0, index);
  14172. }
  14173. }
  14174. return result + omission;
  14175. }
  14176. /**
  14177. * The inverse of `_.escape`; this method converts the HTML entities
  14178. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14179. * their corresponding characters.
  14180. *
  14181. * **Note:** No other HTML entities are unescaped. To unescape additional
  14182. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14183. *
  14184. * @static
  14185. * @memberOf _
  14186. * @since 0.6.0
  14187. * @category String
  14188. * @param {string} [string=''] The string to unescape.
  14189. * @returns {string} Returns the unescaped string.
  14190. * @example
  14191. *
  14192. * _.unescape('fred, barney, &amp; pebbles');
  14193. * // => 'fred, barney, & pebbles'
  14194. */
  14195. function unescape(string) {
  14196. string = toString(string);
  14197. return (string && reHasEscapedHtml.test(string))
  14198. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14199. : string;
  14200. }
  14201. /**
  14202. * Converts `string`, as space separated words, to upper case.
  14203. *
  14204. * @static
  14205. * @memberOf _
  14206. * @since 4.0.0
  14207. * @category String
  14208. * @param {string} [string=''] The string to convert.
  14209. * @returns {string} Returns the upper cased string.
  14210. * @example
  14211. *
  14212. * _.upperCase('--foo-bar');
  14213. * // => 'FOO BAR'
  14214. *
  14215. * _.upperCase('fooBar');
  14216. * // => 'FOO BAR'
  14217. *
  14218. * _.upperCase('__foo_bar__');
  14219. * // => 'FOO BAR'
  14220. */
  14221. var upperCase = createCompounder(function(result, word, index) {
  14222. return result + (index ? ' ' : '') + word.toUpperCase();
  14223. });
  14224. /**
  14225. * Converts the first character of `string` to upper case.
  14226. *
  14227. * @static
  14228. * @memberOf _
  14229. * @since 4.0.0
  14230. * @category String
  14231. * @param {string} [string=''] The string to convert.
  14232. * @returns {string} Returns the converted string.
  14233. * @example
  14234. *
  14235. * _.upperFirst('fred');
  14236. * // => 'Fred'
  14237. *
  14238. * _.upperFirst('FRED');
  14239. * // => 'FRED'
  14240. */
  14241. var upperFirst = createCaseFirst('toUpperCase');
  14242. /**
  14243. * Splits `string` into an array of its words.
  14244. *
  14245. * @static
  14246. * @memberOf _
  14247. * @since 3.0.0
  14248. * @category String
  14249. * @param {string} [string=''] The string to inspect.
  14250. * @param {RegExp|string} [pattern] The pattern to match words.
  14251. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14252. * @returns {Array} Returns the words of `string`.
  14253. * @example
  14254. *
  14255. * _.words('fred, barney, & pebbles');
  14256. * // => ['fred', 'barney', 'pebbles']
  14257. *
  14258. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14259. * // => ['fred', 'barney', '&', 'pebbles']
  14260. */
  14261. function words(string, pattern, guard) {
  14262. string = toString(string);
  14263. pattern = guard ? undefined : pattern;
  14264. if (pattern === undefined) {
  14265. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14266. }
  14267. return string.match(pattern) || [];
  14268. }
  14269. /*------------------------------------------------------------------------*/
  14270. /**
  14271. * Attempts to invoke `func`, returning either the result or the caught error
  14272. * object. Any additional arguments are provided to `func` when it's invoked.
  14273. *
  14274. * @static
  14275. * @memberOf _
  14276. * @since 3.0.0
  14277. * @category Util
  14278. * @param {Function} func The function to attempt.
  14279. * @param {...*} [args] The arguments to invoke `func` with.
  14280. * @returns {*} Returns the `func` result or error object.
  14281. * @example
  14282. *
  14283. * // Avoid throwing errors for invalid selectors.
  14284. * var elements = _.attempt(function(selector) {
  14285. * return document.querySelectorAll(selector);
  14286. * }, '>_>');
  14287. *
  14288. * if (_.isError(elements)) {
  14289. * elements = [];
  14290. * }
  14291. */
  14292. var attempt = baseRest(function(func, args) {
  14293. try {
  14294. return apply(func, undefined, args);
  14295. } catch (e) {
  14296. return isError(e) ? e : new Error(e);
  14297. }
  14298. });
  14299. /**
  14300. * Binds methods of an object to the object itself, overwriting the existing
  14301. * method.
  14302. *
  14303. * **Note:** This method doesn't set the "length" property of bound functions.
  14304. *
  14305. * @static
  14306. * @since 0.1.0
  14307. * @memberOf _
  14308. * @category Util
  14309. * @param {Object} object The object to bind and assign the bound methods to.
  14310. * @param {...(string|string[])} methodNames The object method names to bind.
  14311. * @returns {Object} Returns `object`.
  14312. * @example
  14313. *
  14314. * var view = {
  14315. * 'label': 'docs',
  14316. * 'click': function() {
  14317. * console.log('clicked ' + this.label);
  14318. * }
  14319. * };
  14320. *
  14321. * _.bindAll(view, ['click']);
  14322. * jQuery(element).on('click', view.click);
  14323. * // => Logs 'clicked docs' when clicked.
  14324. */
  14325. var bindAll = flatRest(function(object, methodNames) {
  14326. arrayEach(methodNames, function(key) {
  14327. key = toKey(key);
  14328. baseAssignValue(object, key, bind(object[key], object));
  14329. });
  14330. return object;
  14331. });
  14332. /**
  14333. * Creates a function that iterates over `pairs` and invokes the corresponding
  14334. * function of the first predicate to return truthy. The predicate-function
  14335. * pairs are invoked with the `this` binding and arguments of the created
  14336. * function.
  14337. *
  14338. * @static
  14339. * @memberOf _
  14340. * @since 4.0.0
  14341. * @category Util
  14342. * @param {Array} pairs The predicate-function pairs.
  14343. * @returns {Function} Returns the new composite function.
  14344. * @example
  14345. *
  14346. * var func = _.cond([
  14347. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14348. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14349. * [_.stubTrue, _.constant('no match')]
  14350. * ]);
  14351. *
  14352. * func({ 'a': 1, 'b': 2 });
  14353. * // => 'matches A'
  14354. *
  14355. * func({ 'a': 0, 'b': 1 });
  14356. * // => 'matches B'
  14357. *
  14358. * func({ 'a': '1', 'b': '2' });
  14359. * // => 'no match'
  14360. */
  14361. function cond(pairs) {
  14362. var length = pairs == null ? 0 : pairs.length,
  14363. toIteratee = getIteratee();
  14364. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14365. if (typeof pair[1] != 'function') {
  14366. throw new TypeError(FUNC_ERROR_TEXT);
  14367. }
  14368. return [toIteratee(pair[0]), pair[1]];
  14369. });
  14370. return baseRest(function(args) {
  14371. var index = -1;
  14372. while (++index < length) {
  14373. var pair = pairs[index];
  14374. if (apply(pair[0], this, args)) {
  14375. return apply(pair[1], this, args);
  14376. }
  14377. }
  14378. });
  14379. }
  14380. /**
  14381. * Creates a function that invokes the predicate properties of `source` with
  14382. * the corresponding property values of a given object, returning `true` if
  14383. * all predicates return truthy, else `false`.
  14384. *
  14385. * **Note:** The created function is equivalent to `_.conformsTo` with
  14386. * `source` partially applied.
  14387. *
  14388. * @static
  14389. * @memberOf _
  14390. * @since 4.0.0
  14391. * @category Util
  14392. * @param {Object} source The object of property predicates to conform to.
  14393. * @returns {Function} Returns the new spec function.
  14394. * @example
  14395. *
  14396. * var objects = [
  14397. * { 'a': 2, 'b': 1 },
  14398. * { 'a': 1, 'b': 2 }
  14399. * ];
  14400. *
  14401. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14402. * // => [{ 'a': 1, 'b': 2 }]
  14403. */
  14404. function conforms(source) {
  14405. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14406. }
  14407. /**
  14408. * Creates a function that returns `value`.
  14409. *
  14410. * @static
  14411. * @memberOf _
  14412. * @since 2.4.0
  14413. * @category Util
  14414. * @param {*} value The value to return from the new function.
  14415. * @returns {Function} Returns the new constant function.
  14416. * @example
  14417. *
  14418. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14419. *
  14420. * console.log(objects);
  14421. * // => [{ 'a': 1 }, { 'a': 1 }]
  14422. *
  14423. * console.log(objects[0] === objects[1]);
  14424. * // => true
  14425. */
  14426. function constant(value) {
  14427. return function() {
  14428. return value;
  14429. };
  14430. }
  14431. /**
  14432. * Checks `value` to determine whether a default value should be returned in
  14433. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14434. * or `undefined`.
  14435. *
  14436. * @static
  14437. * @memberOf _
  14438. * @since 4.14.0
  14439. * @category Util
  14440. * @param {*} value The value to check.
  14441. * @param {*} defaultValue The default value.
  14442. * @returns {*} Returns the resolved value.
  14443. * @example
  14444. *
  14445. * _.defaultTo(1, 10);
  14446. * // => 1
  14447. *
  14448. * _.defaultTo(undefined, 10);
  14449. * // => 10
  14450. */
  14451. function defaultTo(value, defaultValue) {
  14452. return (value == null || value !== value) ? defaultValue : value;
  14453. }
  14454. /**
  14455. * Creates a function that returns the result of invoking the given functions
  14456. * with the `this` binding of the created function, where each successive
  14457. * invocation is supplied the return value of the previous.
  14458. *
  14459. * @static
  14460. * @memberOf _
  14461. * @since 3.0.0
  14462. * @category Util
  14463. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14464. * @returns {Function} Returns the new composite function.
  14465. * @see _.flowRight
  14466. * @example
  14467. *
  14468. * function square(n) {
  14469. * return n * n;
  14470. * }
  14471. *
  14472. * var addSquare = _.flow([_.add, square]);
  14473. * addSquare(1, 2);
  14474. * // => 9
  14475. */
  14476. var flow = createFlow();
  14477. /**
  14478. * This method is like `_.flow` except that it creates a function that
  14479. * invokes the given functions from right to left.
  14480. *
  14481. * @static
  14482. * @since 3.0.0
  14483. * @memberOf _
  14484. * @category Util
  14485. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14486. * @returns {Function} Returns the new composite function.
  14487. * @see _.flow
  14488. * @example
  14489. *
  14490. * function square(n) {
  14491. * return n * n;
  14492. * }
  14493. *
  14494. * var addSquare = _.flowRight([square, _.add]);
  14495. * addSquare(1, 2);
  14496. * // => 9
  14497. */
  14498. var flowRight = createFlow(true);
  14499. /**
  14500. * This method returns the first argument it receives.
  14501. *
  14502. * @static
  14503. * @since 0.1.0
  14504. * @memberOf _
  14505. * @category Util
  14506. * @param {*} value Any value.
  14507. * @returns {*} Returns `value`.
  14508. * @example
  14509. *
  14510. * var object = { 'a': 1 };
  14511. *
  14512. * console.log(_.identity(object) === object);
  14513. * // => true
  14514. */
  14515. function identity(value) {
  14516. return value;
  14517. }
  14518. /**
  14519. * Creates a function that invokes `func` with the arguments of the created
  14520. * function. If `func` is a property name, the created function returns the
  14521. * property value for a given element. If `func` is an array or object, the
  14522. * created function returns `true` for elements that contain the equivalent
  14523. * source properties, otherwise it returns `false`.
  14524. *
  14525. * @static
  14526. * @since 4.0.0
  14527. * @memberOf _
  14528. * @category Util
  14529. * @param {*} [func=_.identity] The value to convert to a callback.
  14530. * @returns {Function} Returns the callback.
  14531. * @example
  14532. *
  14533. * var users = [
  14534. * { 'user': 'barney', 'age': 36, 'active': true },
  14535. * { 'user': 'fred', 'age': 40, 'active': false }
  14536. * ];
  14537. *
  14538. * // The `_.matches` iteratee shorthand.
  14539. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14540. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14541. *
  14542. * // The `_.matchesProperty` iteratee shorthand.
  14543. * _.filter(users, _.iteratee(['user', 'fred']));
  14544. * // => [{ 'user': 'fred', 'age': 40 }]
  14545. *
  14546. * // The `_.property` iteratee shorthand.
  14547. * _.map(users, _.iteratee('user'));
  14548. * // => ['barney', 'fred']
  14549. *
  14550. * // Create custom iteratee shorthands.
  14551. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14552. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14553. * return func.test(string);
  14554. * };
  14555. * });
  14556. *
  14557. * _.filter(['abc', 'def'], /ef/);
  14558. * // => ['def']
  14559. */
  14560. function iteratee(func) {
  14561. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14562. }
  14563. /**
  14564. * Creates a function that performs a partial deep comparison between a given
  14565. * object and `source`, returning `true` if the given object has equivalent
  14566. * property values, else `false`.
  14567. *
  14568. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14569. * partially applied.
  14570. *
  14571. * Partial comparisons will match empty array and empty object `source`
  14572. * values against any array or object value, respectively. See `_.isEqual`
  14573. * for a list of supported value comparisons.
  14574. *
  14575. * @static
  14576. * @memberOf _
  14577. * @since 3.0.0
  14578. * @category Util
  14579. * @param {Object} source The object of property values to match.
  14580. * @returns {Function} Returns the new spec function.
  14581. * @example
  14582. *
  14583. * var objects = [
  14584. * { 'a': 1, 'b': 2, 'c': 3 },
  14585. * { 'a': 4, 'b': 5, 'c': 6 }
  14586. * ];
  14587. *
  14588. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14589. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14590. */
  14591. function matches(source) {
  14592. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14593. }
  14594. /**
  14595. * Creates a function that performs a partial deep comparison between the
  14596. * value at `path` of a given object to `srcValue`, returning `true` if the
  14597. * object value is equivalent, else `false`.
  14598. *
  14599. * **Note:** Partial comparisons will match empty array and empty object
  14600. * `srcValue` values against any array or object value, respectively. See
  14601. * `_.isEqual` for a list of supported value comparisons.
  14602. *
  14603. * @static
  14604. * @memberOf _
  14605. * @since 3.2.0
  14606. * @category Util
  14607. * @param {Array|string} path The path of the property to get.
  14608. * @param {*} srcValue The value to match.
  14609. * @returns {Function} Returns the new spec function.
  14610. * @example
  14611. *
  14612. * var objects = [
  14613. * { 'a': 1, 'b': 2, 'c': 3 },
  14614. * { 'a': 4, 'b': 5, 'c': 6 }
  14615. * ];
  14616. *
  14617. * _.find(objects, _.matchesProperty('a', 4));
  14618. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14619. */
  14620. function matchesProperty(path, srcValue) {
  14621. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14622. }
  14623. /**
  14624. * Creates a function that invokes the method at `path` of a given object.
  14625. * Any additional arguments are provided to the invoked method.
  14626. *
  14627. * @static
  14628. * @memberOf _
  14629. * @since 3.7.0
  14630. * @category Util
  14631. * @param {Array|string} path The path of the method to invoke.
  14632. * @param {...*} [args] The arguments to invoke the method with.
  14633. * @returns {Function} Returns the new invoker function.
  14634. * @example
  14635. *
  14636. * var objects = [
  14637. * { 'a': { 'b': _.constant(2) } },
  14638. * { 'a': { 'b': _.constant(1) } }
  14639. * ];
  14640. *
  14641. * _.map(objects, _.method('a.b'));
  14642. * // => [2, 1]
  14643. *
  14644. * _.map(objects, _.method(['a', 'b']));
  14645. * // => [2, 1]
  14646. */
  14647. var method = baseRest(function(path, args) {
  14648. return function(object) {
  14649. return baseInvoke(object, path, args);
  14650. };
  14651. });
  14652. /**
  14653. * The opposite of `_.method`; this method creates a function that invokes
  14654. * the method at a given path of `object`. Any additional arguments are
  14655. * provided to the invoked method.
  14656. *
  14657. * @static
  14658. * @memberOf _
  14659. * @since 3.7.0
  14660. * @category Util
  14661. * @param {Object} object The object to query.
  14662. * @param {...*} [args] The arguments to invoke the method with.
  14663. * @returns {Function} Returns the new invoker function.
  14664. * @example
  14665. *
  14666. * var array = _.times(3, _.constant),
  14667. * object = { 'a': array, 'b': array, 'c': array };
  14668. *
  14669. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14670. * // => [2, 0]
  14671. *
  14672. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14673. * // => [2, 0]
  14674. */
  14675. var methodOf = baseRest(function(object, args) {
  14676. return function(path) {
  14677. return baseInvoke(object, path, args);
  14678. };
  14679. });
  14680. /**
  14681. * Adds all own enumerable string keyed function properties of a source
  14682. * object to the destination object. If `object` is a function, then methods
  14683. * are added to its prototype as well.
  14684. *
  14685. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14686. * avoid conflicts caused by modifying the original.
  14687. *
  14688. * @static
  14689. * @since 0.1.0
  14690. * @memberOf _
  14691. * @category Util
  14692. * @param {Function|Object} [object=lodash] The destination object.
  14693. * @param {Object} source The object of functions to add.
  14694. * @param {Object} [options={}] The options object.
  14695. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14696. * @returns {Function|Object} Returns `object`.
  14697. * @example
  14698. *
  14699. * function vowels(string) {
  14700. * return _.filter(string, function(v) {
  14701. * return /[aeiou]/i.test(v);
  14702. * });
  14703. * }
  14704. *
  14705. * _.mixin({ 'vowels': vowels });
  14706. * _.vowels('fred');
  14707. * // => ['e']
  14708. *
  14709. * _('fred').vowels().value();
  14710. * // => ['e']
  14711. *
  14712. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14713. * _('fred').vowels();
  14714. * // => ['e']
  14715. */
  14716. function mixin(object, source, options) {
  14717. var props = keys(source),
  14718. methodNames = baseFunctions(source, props);
  14719. if (options == null &&
  14720. !(isObject(source) && (methodNames.length || !props.length))) {
  14721. options = source;
  14722. source = object;
  14723. object = this;
  14724. methodNames = baseFunctions(source, keys(source));
  14725. }
  14726. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14727. isFunc = isFunction(object);
  14728. arrayEach(methodNames, function(methodName) {
  14729. var func = source[methodName];
  14730. object[methodName] = func;
  14731. if (isFunc) {
  14732. object.prototype[methodName] = function() {
  14733. var chainAll = this.__chain__;
  14734. if (chain || chainAll) {
  14735. var result = object(this.__wrapped__),
  14736. actions = result.__actions__ = copyArray(this.__actions__);
  14737. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14738. result.__chain__ = chainAll;
  14739. return result;
  14740. }
  14741. return func.apply(object, arrayPush([this.value()], arguments));
  14742. };
  14743. }
  14744. });
  14745. return object;
  14746. }
  14747. /**
  14748. * Reverts the `_` variable to its previous value and returns a reference to
  14749. * the `lodash` function.
  14750. *
  14751. * @static
  14752. * @since 0.1.0
  14753. * @memberOf _
  14754. * @category Util
  14755. * @returns {Function} Returns the `lodash` function.
  14756. * @example
  14757. *
  14758. * var lodash = _.noConflict();
  14759. */
  14760. function noConflict() {
  14761. if (root._ === this) {
  14762. root._ = oldDash;
  14763. }
  14764. return this;
  14765. }
  14766. /**
  14767. * This method returns `undefined`.
  14768. *
  14769. * @static
  14770. * @memberOf _
  14771. * @since 2.3.0
  14772. * @category Util
  14773. * @example
  14774. *
  14775. * _.times(2, _.noop);
  14776. * // => [undefined, undefined]
  14777. */
  14778. function noop() {
  14779. // No operation performed.
  14780. }
  14781. /**
  14782. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14783. * the nth argument from the end is returned.
  14784. *
  14785. * @static
  14786. * @memberOf _
  14787. * @since 4.0.0
  14788. * @category Util
  14789. * @param {number} [n=0] The index of the argument to return.
  14790. * @returns {Function} Returns the new pass-thru function.
  14791. * @example
  14792. *
  14793. * var func = _.nthArg(1);
  14794. * func('a', 'b', 'c', 'd');
  14795. * // => 'b'
  14796. *
  14797. * var func = _.nthArg(-2);
  14798. * func('a', 'b', 'c', 'd');
  14799. * // => 'c'
  14800. */
  14801. function nthArg(n) {
  14802. n = toInteger(n);
  14803. return baseRest(function(args) {
  14804. return baseNth(args, n);
  14805. });
  14806. }
  14807. /**
  14808. * Creates a function that invokes `iteratees` with the arguments it receives
  14809. * and returns their results.
  14810. *
  14811. * @static
  14812. * @memberOf _
  14813. * @since 4.0.0
  14814. * @category Util
  14815. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14816. * The iteratees to invoke.
  14817. * @returns {Function} Returns the new function.
  14818. * @example
  14819. *
  14820. * var func = _.over([Math.max, Math.min]);
  14821. *
  14822. * func(1, 2, 3, 4);
  14823. * // => [4, 1]
  14824. */
  14825. var over = createOver(arrayMap);
  14826. /**
  14827. * Creates a function that checks if **all** of the `predicates` return
  14828. * truthy when invoked with the arguments it receives.
  14829. *
  14830. * @static
  14831. * @memberOf _
  14832. * @since 4.0.0
  14833. * @category Util
  14834. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14835. * The predicates to check.
  14836. * @returns {Function} Returns the new function.
  14837. * @example
  14838. *
  14839. * var func = _.overEvery([Boolean, isFinite]);
  14840. *
  14841. * func('1');
  14842. * // => true
  14843. *
  14844. * func(null);
  14845. * // => false
  14846. *
  14847. * func(NaN);
  14848. * // => false
  14849. */
  14850. var overEvery = createOver(arrayEvery);
  14851. /**
  14852. * Creates a function that checks if **any** of the `predicates` return
  14853. * truthy when invoked with the arguments it receives.
  14854. *
  14855. * @static
  14856. * @memberOf _
  14857. * @since 4.0.0
  14858. * @category Util
  14859. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14860. * The predicates to check.
  14861. * @returns {Function} Returns the new function.
  14862. * @example
  14863. *
  14864. * var func = _.overSome([Boolean, isFinite]);
  14865. *
  14866. * func('1');
  14867. * // => true
  14868. *
  14869. * func(null);
  14870. * // => true
  14871. *
  14872. * func(NaN);
  14873. * // => false
  14874. */
  14875. var overSome = createOver(arraySome);
  14876. /**
  14877. * Creates a function that returns the value at `path` of a given object.
  14878. *
  14879. * @static
  14880. * @memberOf _
  14881. * @since 2.4.0
  14882. * @category Util
  14883. * @param {Array|string} path The path of the property to get.
  14884. * @returns {Function} Returns the new accessor function.
  14885. * @example
  14886. *
  14887. * var objects = [
  14888. * { 'a': { 'b': 2 } },
  14889. * { 'a': { 'b': 1 } }
  14890. * ];
  14891. *
  14892. * _.map(objects, _.property('a.b'));
  14893. * // => [2, 1]
  14894. *
  14895. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14896. * // => [1, 2]
  14897. */
  14898. function property(path) {
  14899. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14900. }
  14901. /**
  14902. * The opposite of `_.property`; this method creates a function that returns
  14903. * the value at a given path of `object`.
  14904. *
  14905. * @static
  14906. * @memberOf _
  14907. * @since 3.0.0
  14908. * @category Util
  14909. * @param {Object} object The object to query.
  14910. * @returns {Function} Returns the new accessor function.
  14911. * @example
  14912. *
  14913. * var array = [0, 1, 2],
  14914. * object = { 'a': array, 'b': array, 'c': array };
  14915. *
  14916. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14917. * // => [2, 0]
  14918. *
  14919. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14920. * // => [2, 0]
  14921. */
  14922. function propertyOf(object) {
  14923. return function(path) {
  14924. return object == null ? undefined : baseGet(object, path);
  14925. };
  14926. }
  14927. /**
  14928. * Creates an array of numbers (positive and/or negative) progressing from
  14929. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14930. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14931. * it's set to `start` with `start` then set to `0`.
  14932. *
  14933. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14934. * floating-point values which can produce unexpected results.
  14935. *
  14936. * @static
  14937. * @since 0.1.0
  14938. * @memberOf _
  14939. * @category Util
  14940. * @param {number} [start=0] The start of the range.
  14941. * @param {number} end The end of the range.
  14942. * @param {number} [step=1] The value to increment or decrement by.
  14943. * @returns {Array} Returns the range of numbers.
  14944. * @see _.inRange, _.rangeRight
  14945. * @example
  14946. *
  14947. * _.range(4);
  14948. * // => [0, 1, 2, 3]
  14949. *
  14950. * _.range(-4);
  14951. * // => [0, -1, -2, -3]
  14952. *
  14953. * _.range(1, 5);
  14954. * // => [1, 2, 3, 4]
  14955. *
  14956. * _.range(0, 20, 5);
  14957. * // => [0, 5, 10, 15]
  14958. *
  14959. * _.range(0, -4, -1);
  14960. * // => [0, -1, -2, -3]
  14961. *
  14962. * _.range(1, 4, 0);
  14963. * // => [1, 1, 1]
  14964. *
  14965. * _.range(0);
  14966. * // => []
  14967. */
  14968. var range = createRange();
  14969. /**
  14970. * This method is like `_.range` except that it populates values in
  14971. * descending order.
  14972. *
  14973. * @static
  14974. * @memberOf _
  14975. * @since 4.0.0
  14976. * @category Util
  14977. * @param {number} [start=0] The start of the range.
  14978. * @param {number} end The end of the range.
  14979. * @param {number} [step=1] The value to increment or decrement by.
  14980. * @returns {Array} Returns the range of numbers.
  14981. * @see _.inRange, _.range
  14982. * @example
  14983. *
  14984. * _.rangeRight(4);
  14985. * // => [3, 2, 1, 0]
  14986. *
  14987. * _.rangeRight(-4);
  14988. * // => [-3, -2, -1, 0]
  14989. *
  14990. * _.rangeRight(1, 5);
  14991. * // => [4, 3, 2, 1]
  14992. *
  14993. * _.rangeRight(0, 20, 5);
  14994. * // => [15, 10, 5, 0]
  14995. *
  14996. * _.rangeRight(0, -4, -1);
  14997. * // => [-3, -2, -1, 0]
  14998. *
  14999. * _.rangeRight(1, 4, 0);
  15000. * // => [1, 1, 1]
  15001. *
  15002. * _.rangeRight(0);
  15003. * // => []
  15004. */
  15005. var rangeRight = createRange(true);
  15006. /**
  15007. * This method returns a new empty array.
  15008. *
  15009. * @static
  15010. * @memberOf _
  15011. * @since 4.13.0
  15012. * @category Util
  15013. * @returns {Array} Returns the new empty array.
  15014. * @example
  15015. *
  15016. * var arrays = _.times(2, _.stubArray);
  15017. *
  15018. * console.log(arrays);
  15019. * // => [[], []]
  15020. *
  15021. * console.log(arrays[0] === arrays[1]);
  15022. * // => false
  15023. */
  15024. function stubArray() {
  15025. return [];
  15026. }
  15027. /**
  15028. * This method returns `false`.
  15029. *
  15030. * @static
  15031. * @memberOf _
  15032. * @since 4.13.0
  15033. * @category Util
  15034. * @returns {boolean} Returns `false`.
  15035. * @example
  15036. *
  15037. * _.times(2, _.stubFalse);
  15038. * // => [false, false]
  15039. */
  15040. function stubFalse() {
  15041. return false;
  15042. }
  15043. /**
  15044. * This method returns a new empty object.
  15045. *
  15046. * @static
  15047. * @memberOf _
  15048. * @since 4.13.0
  15049. * @category Util
  15050. * @returns {Object} Returns the new empty object.
  15051. * @example
  15052. *
  15053. * var objects = _.times(2, _.stubObject);
  15054. *
  15055. * console.log(objects);
  15056. * // => [{}, {}]
  15057. *
  15058. * console.log(objects[0] === objects[1]);
  15059. * // => false
  15060. */
  15061. function stubObject() {
  15062. return {};
  15063. }
  15064. /**
  15065. * This method returns an empty string.
  15066. *
  15067. * @static
  15068. * @memberOf _
  15069. * @since 4.13.0
  15070. * @category Util
  15071. * @returns {string} Returns the empty string.
  15072. * @example
  15073. *
  15074. * _.times(2, _.stubString);
  15075. * // => ['', '']
  15076. */
  15077. function stubString() {
  15078. return '';
  15079. }
  15080. /**
  15081. * This method returns `true`.
  15082. *
  15083. * @static
  15084. * @memberOf _
  15085. * @since 4.13.0
  15086. * @category Util
  15087. * @returns {boolean} Returns `true`.
  15088. * @example
  15089. *
  15090. * _.times(2, _.stubTrue);
  15091. * // => [true, true]
  15092. */
  15093. function stubTrue() {
  15094. return true;
  15095. }
  15096. /**
  15097. * Invokes the iteratee `n` times, returning an array of the results of
  15098. * each invocation. The iteratee is invoked with one argument; (index).
  15099. *
  15100. * @static
  15101. * @since 0.1.0
  15102. * @memberOf _
  15103. * @category Util
  15104. * @param {number} n The number of times to invoke `iteratee`.
  15105. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15106. * @returns {Array} Returns the array of results.
  15107. * @example
  15108. *
  15109. * _.times(3, String);
  15110. * // => ['0', '1', '2']
  15111. *
  15112. * _.times(4, _.constant(0));
  15113. * // => [0, 0, 0, 0]
  15114. */
  15115. function times(n, iteratee) {
  15116. n = toInteger(n);
  15117. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15118. return [];
  15119. }
  15120. var index = MAX_ARRAY_LENGTH,
  15121. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15122. iteratee = getIteratee(iteratee);
  15123. n -= MAX_ARRAY_LENGTH;
  15124. var result = baseTimes(length, iteratee);
  15125. while (++index < n) {
  15126. iteratee(index);
  15127. }
  15128. return result;
  15129. }
  15130. /**
  15131. * Converts `value` to a property path array.
  15132. *
  15133. * @static
  15134. * @memberOf _
  15135. * @since 4.0.0
  15136. * @category Util
  15137. * @param {*} value The value to convert.
  15138. * @returns {Array} Returns the new property path array.
  15139. * @example
  15140. *
  15141. * _.toPath('a.b.c');
  15142. * // => ['a', 'b', 'c']
  15143. *
  15144. * _.toPath('a[0].b.c');
  15145. * // => ['a', '0', 'b', 'c']
  15146. */
  15147. function toPath(value) {
  15148. if (isArray(value)) {
  15149. return arrayMap(value, toKey);
  15150. }
  15151. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15152. }
  15153. /**
  15154. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15155. *
  15156. * @static
  15157. * @since 0.1.0
  15158. * @memberOf _
  15159. * @category Util
  15160. * @param {string} [prefix=''] The value to prefix the ID with.
  15161. * @returns {string} Returns the unique ID.
  15162. * @example
  15163. *
  15164. * _.uniqueId('contact_');
  15165. * // => 'contact_104'
  15166. *
  15167. * _.uniqueId();
  15168. * // => '105'
  15169. */
  15170. function uniqueId(prefix) {
  15171. var id = ++idCounter;
  15172. return toString(prefix) + id;
  15173. }
  15174. /*------------------------------------------------------------------------*/
  15175. /**
  15176. * Adds two numbers.
  15177. *
  15178. * @static
  15179. * @memberOf _
  15180. * @since 3.4.0
  15181. * @category Math
  15182. * @param {number} augend The first number in an addition.
  15183. * @param {number} addend The second number in an addition.
  15184. * @returns {number} Returns the total.
  15185. * @example
  15186. *
  15187. * _.add(6, 4);
  15188. * // => 10
  15189. */
  15190. var add = createMathOperation(function(augend, addend) {
  15191. return augend + addend;
  15192. }, 0);
  15193. /**
  15194. * Computes `number` rounded up to `precision`.
  15195. *
  15196. * @static
  15197. * @memberOf _
  15198. * @since 3.10.0
  15199. * @category Math
  15200. * @param {number} number The number to round up.
  15201. * @param {number} [precision=0] The precision to round up to.
  15202. * @returns {number} Returns the rounded up number.
  15203. * @example
  15204. *
  15205. * _.ceil(4.006);
  15206. * // => 5
  15207. *
  15208. * _.ceil(6.004, 2);
  15209. * // => 6.01
  15210. *
  15211. * _.ceil(6040, -2);
  15212. * // => 6100
  15213. */
  15214. var ceil = createRound('ceil');
  15215. /**
  15216. * Divide two numbers.
  15217. *
  15218. * @static
  15219. * @memberOf _
  15220. * @since 4.7.0
  15221. * @category Math
  15222. * @param {number} dividend The first number in a division.
  15223. * @param {number} divisor The second number in a division.
  15224. * @returns {number} Returns the quotient.
  15225. * @example
  15226. *
  15227. * _.divide(6, 4);
  15228. * // => 1.5
  15229. */
  15230. var divide = createMathOperation(function(dividend, divisor) {
  15231. return dividend / divisor;
  15232. }, 1);
  15233. /**
  15234. * Computes `number` rounded down to `precision`.
  15235. *
  15236. * @static
  15237. * @memberOf _
  15238. * @since 3.10.0
  15239. * @category Math
  15240. * @param {number} number The number to round down.
  15241. * @param {number} [precision=0] The precision to round down to.
  15242. * @returns {number} Returns the rounded down number.
  15243. * @example
  15244. *
  15245. * _.floor(4.006);
  15246. * // => 4
  15247. *
  15248. * _.floor(0.046, 2);
  15249. * // => 0.04
  15250. *
  15251. * _.floor(4060, -2);
  15252. * // => 4000
  15253. */
  15254. var floor = createRound('floor');
  15255. /**
  15256. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15257. * `undefined` is returned.
  15258. *
  15259. * @static
  15260. * @since 0.1.0
  15261. * @memberOf _
  15262. * @category Math
  15263. * @param {Array} array The array to iterate over.
  15264. * @returns {*} Returns the maximum value.
  15265. * @example
  15266. *
  15267. * _.max([4, 2, 8, 6]);
  15268. * // => 8
  15269. *
  15270. * _.max([]);
  15271. * // => undefined
  15272. */
  15273. function max(array) {
  15274. return (array && array.length)
  15275. ? baseExtremum(array, identity, baseGt)
  15276. : undefined;
  15277. }
  15278. /**
  15279. * This method is like `_.max` except that it accepts `iteratee` which is
  15280. * invoked for each element in `array` to generate the criterion by which
  15281. * the value is ranked. The iteratee is invoked with one argument: (value).
  15282. *
  15283. * @static
  15284. * @memberOf _
  15285. * @since 4.0.0
  15286. * @category Math
  15287. * @param {Array} array The array to iterate over.
  15288. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15289. * @returns {*} Returns the maximum value.
  15290. * @example
  15291. *
  15292. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15293. *
  15294. * _.maxBy(objects, function(o) { return o.n; });
  15295. * // => { 'n': 2 }
  15296. *
  15297. * // The `_.property` iteratee shorthand.
  15298. * _.maxBy(objects, 'n');
  15299. * // => { 'n': 2 }
  15300. */
  15301. function maxBy(array, iteratee) {
  15302. return (array && array.length)
  15303. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15304. : undefined;
  15305. }
  15306. /**
  15307. * Computes the mean of the values in `array`.
  15308. *
  15309. * @static
  15310. * @memberOf _
  15311. * @since 4.0.0
  15312. * @category Math
  15313. * @param {Array} array The array to iterate over.
  15314. * @returns {number} Returns the mean.
  15315. * @example
  15316. *
  15317. * _.mean([4, 2, 8, 6]);
  15318. * // => 5
  15319. */
  15320. function mean(array) {
  15321. return baseMean(array, identity);
  15322. }
  15323. /**
  15324. * This method is like `_.mean` except that it accepts `iteratee` which is
  15325. * invoked for each element in `array` to generate the value to be averaged.
  15326. * The iteratee is invoked with one argument: (value).
  15327. *
  15328. * @static
  15329. * @memberOf _
  15330. * @since 4.7.0
  15331. * @category Math
  15332. * @param {Array} array The array to iterate over.
  15333. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15334. * @returns {number} Returns the mean.
  15335. * @example
  15336. *
  15337. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15338. *
  15339. * _.meanBy(objects, function(o) { return o.n; });
  15340. * // => 5
  15341. *
  15342. * // The `_.property` iteratee shorthand.
  15343. * _.meanBy(objects, 'n');
  15344. * // => 5
  15345. */
  15346. function meanBy(array, iteratee) {
  15347. return baseMean(array, getIteratee(iteratee, 2));
  15348. }
  15349. /**
  15350. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15351. * `undefined` is returned.
  15352. *
  15353. * @static
  15354. * @since 0.1.0
  15355. * @memberOf _
  15356. * @category Math
  15357. * @param {Array} array The array to iterate over.
  15358. * @returns {*} Returns the minimum value.
  15359. * @example
  15360. *
  15361. * _.min([4, 2, 8, 6]);
  15362. * // => 2
  15363. *
  15364. * _.min([]);
  15365. * // => undefined
  15366. */
  15367. function min(array) {
  15368. return (array && array.length)
  15369. ? baseExtremum(array, identity, baseLt)
  15370. : undefined;
  15371. }
  15372. /**
  15373. * This method is like `_.min` except that it accepts `iteratee` which is
  15374. * invoked for each element in `array` to generate the criterion by which
  15375. * the value is ranked. The iteratee is invoked with one argument: (value).
  15376. *
  15377. * @static
  15378. * @memberOf _
  15379. * @since 4.0.0
  15380. * @category Math
  15381. * @param {Array} array The array to iterate over.
  15382. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15383. * @returns {*} Returns the minimum value.
  15384. * @example
  15385. *
  15386. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15387. *
  15388. * _.minBy(objects, function(o) { return o.n; });
  15389. * // => { 'n': 1 }
  15390. *
  15391. * // The `_.property` iteratee shorthand.
  15392. * _.minBy(objects, 'n');
  15393. * // => { 'n': 1 }
  15394. */
  15395. function minBy(array, iteratee) {
  15396. return (array && array.length)
  15397. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15398. : undefined;
  15399. }
  15400. /**
  15401. * Multiply two numbers.
  15402. *
  15403. * @static
  15404. * @memberOf _
  15405. * @since 4.7.0
  15406. * @category Math
  15407. * @param {number} multiplier The first number in a multiplication.
  15408. * @param {number} multiplicand The second number in a multiplication.
  15409. * @returns {number} Returns the product.
  15410. * @example
  15411. *
  15412. * _.multiply(6, 4);
  15413. * // => 24
  15414. */
  15415. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15416. return multiplier * multiplicand;
  15417. }, 1);
  15418. /**
  15419. * Computes `number` rounded to `precision`.
  15420. *
  15421. * @static
  15422. * @memberOf _
  15423. * @since 3.10.0
  15424. * @category Math
  15425. * @param {number} number The number to round.
  15426. * @param {number} [precision=0] The precision to round to.
  15427. * @returns {number} Returns the rounded number.
  15428. * @example
  15429. *
  15430. * _.round(4.006);
  15431. * // => 4
  15432. *
  15433. * _.round(4.006, 2);
  15434. * // => 4.01
  15435. *
  15436. * _.round(4060, -2);
  15437. * // => 4100
  15438. */
  15439. var round = createRound('round');
  15440. /**
  15441. * Subtract two numbers.
  15442. *
  15443. * @static
  15444. * @memberOf _
  15445. * @since 4.0.0
  15446. * @category Math
  15447. * @param {number} minuend The first number in a subtraction.
  15448. * @param {number} subtrahend The second number in a subtraction.
  15449. * @returns {number} Returns the difference.
  15450. * @example
  15451. *
  15452. * _.subtract(6, 4);
  15453. * // => 2
  15454. */
  15455. var subtract = createMathOperation(function(minuend, subtrahend) {
  15456. return minuend - subtrahend;
  15457. }, 0);
  15458. /**
  15459. * Computes the sum of the values in `array`.
  15460. *
  15461. * @static
  15462. * @memberOf _
  15463. * @since 3.4.0
  15464. * @category Math
  15465. * @param {Array} array The array to iterate over.
  15466. * @returns {number} Returns the sum.
  15467. * @example
  15468. *
  15469. * _.sum([4, 2, 8, 6]);
  15470. * // => 20
  15471. */
  15472. function sum(array) {
  15473. return (array && array.length)
  15474. ? baseSum(array, identity)
  15475. : 0;
  15476. }
  15477. /**
  15478. * This method is like `_.sum` except that it accepts `iteratee` which is
  15479. * invoked for each element in `array` to generate the value to be summed.
  15480. * The iteratee is invoked with one argument: (value).
  15481. *
  15482. * @static
  15483. * @memberOf _
  15484. * @since 4.0.0
  15485. * @category Math
  15486. * @param {Array} array The array to iterate over.
  15487. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15488. * @returns {number} Returns the sum.
  15489. * @example
  15490. *
  15491. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15492. *
  15493. * _.sumBy(objects, function(o) { return o.n; });
  15494. * // => 20
  15495. *
  15496. * // The `_.property` iteratee shorthand.
  15497. * _.sumBy(objects, 'n');
  15498. * // => 20
  15499. */
  15500. function sumBy(array, iteratee) {
  15501. return (array && array.length)
  15502. ? baseSum(array, getIteratee(iteratee, 2))
  15503. : 0;
  15504. }
  15505. /*------------------------------------------------------------------------*/
  15506. // Add methods that return wrapped values in chain sequences.
  15507. lodash.after = after;
  15508. lodash.ary = ary;
  15509. lodash.assign = assign;
  15510. lodash.assignIn = assignIn;
  15511. lodash.assignInWith = assignInWith;
  15512. lodash.assignWith = assignWith;
  15513. lodash.at = at;
  15514. lodash.before = before;
  15515. lodash.bind = bind;
  15516. lodash.bindAll = bindAll;
  15517. lodash.bindKey = bindKey;
  15518. lodash.castArray = castArray;
  15519. lodash.chain = chain;
  15520. lodash.chunk = chunk;
  15521. lodash.compact = compact;
  15522. lodash.concat = concat;
  15523. lodash.cond = cond;
  15524. lodash.conforms = conforms;
  15525. lodash.constant = constant;
  15526. lodash.countBy = countBy;
  15527. lodash.create = create;
  15528. lodash.curry = curry;
  15529. lodash.curryRight = curryRight;
  15530. lodash.debounce = debounce;
  15531. lodash.defaults = defaults;
  15532. lodash.defaultsDeep = defaultsDeep;
  15533. lodash.defer = defer;
  15534. lodash.delay = delay;
  15535. lodash.difference = difference;
  15536. lodash.differenceBy = differenceBy;
  15537. lodash.differenceWith = differenceWith;
  15538. lodash.drop = drop;
  15539. lodash.dropRight = dropRight;
  15540. lodash.dropRightWhile = dropRightWhile;
  15541. lodash.dropWhile = dropWhile;
  15542. lodash.fill = fill;
  15543. lodash.filter = filter;
  15544. lodash.flatMap = flatMap;
  15545. lodash.flatMapDeep = flatMapDeep;
  15546. lodash.flatMapDepth = flatMapDepth;
  15547. lodash.flatten = flatten;
  15548. lodash.flattenDeep = flattenDeep;
  15549. lodash.flattenDepth = flattenDepth;
  15550. lodash.flip = flip;
  15551. lodash.flow = flow;
  15552. lodash.flowRight = flowRight;
  15553. lodash.fromPairs = fromPairs;
  15554. lodash.functions = functions;
  15555. lodash.functionsIn = functionsIn;
  15556. lodash.groupBy = groupBy;
  15557. lodash.initial = initial;
  15558. lodash.intersection = intersection;
  15559. lodash.intersectionBy = intersectionBy;
  15560. lodash.intersectionWith = intersectionWith;
  15561. lodash.invert = invert;
  15562. lodash.invertBy = invertBy;
  15563. lodash.invokeMap = invokeMap;
  15564. lodash.iteratee = iteratee;
  15565. lodash.keyBy = keyBy;
  15566. lodash.keys = keys;
  15567. lodash.keysIn = keysIn;
  15568. lodash.map = map;
  15569. lodash.mapKeys = mapKeys;
  15570. lodash.mapValues = mapValues;
  15571. lodash.matches = matches;
  15572. lodash.matchesProperty = matchesProperty;
  15573. lodash.memoize = memoize;
  15574. lodash.merge = merge;
  15575. lodash.mergeWith = mergeWith;
  15576. lodash.method = method;
  15577. lodash.methodOf = methodOf;
  15578. lodash.mixin = mixin;
  15579. lodash.negate = negate;
  15580. lodash.nthArg = nthArg;
  15581. lodash.omit = omit;
  15582. lodash.omitBy = omitBy;
  15583. lodash.once = once;
  15584. lodash.orderBy = orderBy;
  15585. lodash.over = over;
  15586. lodash.overArgs = overArgs;
  15587. lodash.overEvery = overEvery;
  15588. lodash.overSome = overSome;
  15589. lodash.partial = partial;
  15590. lodash.partialRight = partialRight;
  15591. lodash.partition = partition;
  15592. lodash.pick = pick;
  15593. lodash.pickBy = pickBy;
  15594. lodash.property = property;
  15595. lodash.propertyOf = propertyOf;
  15596. lodash.pull = pull;
  15597. lodash.pullAll = pullAll;
  15598. lodash.pullAllBy = pullAllBy;
  15599. lodash.pullAllWith = pullAllWith;
  15600. lodash.pullAt = pullAt;
  15601. lodash.range = range;
  15602. lodash.rangeRight = rangeRight;
  15603. lodash.rearg = rearg;
  15604. lodash.reject = reject;
  15605. lodash.remove = remove;
  15606. lodash.rest = rest;
  15607. lodash.reverse = reverse;
  15608. lodash.sampleSize = sampleSize;
  15609. lodash.set = set;
  15610. lodash.setWith = setWith;
  15611. lodash.shuffle = shuffle;
  15612. lodash.slice = slice;
  15613. lodash.sortBy = sortBy;
  15614. lodash.sortedUniq = sortedUniq;
  15615. lodash.sortedUniqBy = sortedUniqBy;
  15616. lodash.split = split;
  15617. lodash.spread = spread;
  15618. lodash.tail = tail;
  15619. lodash.take = take;
  15620. lodash.takeRight = takeRight;
  15621. lodash.takeRightWhile = takeRightWhile;
  15622. lodash.takeWhile = takeWhile;
  15623. lodash.tap = tap;
  15624. lodash.throttle = throttle;
  15625. lodash.thru = thru;
  15626. lodash.toArray = toArray;
  15627. lodash.toPairs = toPairs;
  15628. lodash.toPairsIn = toPairsIn;
  15629. lodash.toPath = toPath;
  15630. lodash.toPlainObject = toPlainObject;
  15631. lodash.transform = transform;
  15632. lodash.unary = unary;
  15633. lodash.union = union;
  15634. lodash.unionBy = unionBy;
  15635. lodash.unionWith = unionWith;
  15636. lodash.uniq = uniq;
  15637. lodash.uniqBy = uniqBy;
  15638. lodash.uniqWith = uniqWith;
  15639. lodash.unset = unset;
  15640. lodash.unzip = unzip;
  15641. lodash.unzipWith = unzipWith;
  15642. lodash.update = update;
  15643. lodash.updateWith = updateWith;
  15644. lodash.values = values;
  15645. lodash.valuesIn = valuesIn;
  15646. lodash.without = without;
  15647. lodash.words = words;
  15648. lodash.wrap = wrap;
  15649. lodash.xor = xor;
  15650. lodash.xorBy = xorBy;
  15651. lodash.xorWith = xorWith;
  15652. lodash.zip = zip;
  15653. lodash.zipObject = zipObject;
  15654. lodash.zipObjectDeep = zipObjectDeep;
  15655. lodash.zipWith = zipWith;
  15656. // Add aliases.
  15657. lodash.entries = toPairs;
  15658. lodash.entriesIn = toPairsIn;
  15659. lodash.extend = assignIn;
  15660. lodash.extendWith = assignInWith;
  15661. // Add methods to `lodash.prototype`.
  15662. mixin(lodash, lodash);
  15663. /*------------------------------------------------------------------------*/
  15664. // Add methods that return unwrapped values in chain sequences.
  15665. lodash.add = add;
  15666. lodash.attempt = attempt;
  15667. lodash.camelCase = camelCase;
  15668. lodash.capitalize = capitalize;
  15669. lodash.ceil = ceil;
  15670. lodash.clamp = clamp;
  15671. lodash.clone = clone;
  15672. lodash.cloneDeep = cloneDeep;
  15673. lodash.cloneDeepWith = cloneDeepWith;
  15674. lodash.cloneWith = cloneWith;
  15675. lodash.conformsTo = conformsTo;
  15676. lodash.deburr = deburr;
  15677. lodash.defaultTo = defaultTo;
  15678. lodash.divide = divide;
  15679. lodash.endsWith = endsWith;
  15680. lodash.eq = eq;
  15681. lodash.escape = escape;
  15682. lodash.escapeRegExp = escapeRegExp;
  15683. lodash.every = every;
  15684. lodash.find = find;
  15685. lodash.findIndex = findIndex;
  15686. lodash.findKey = findKey;
  15687. lodash.findLast = findLast;
  15688. lodash.findLastIndex = findLastIndex;
  15689. lodash.findLastKey = findLastKey;
  15690. lodash.floor = floor;
  15691. lodash.forEach = forEach;
  15692. lodash.forEachRight = forEachRight;
  15693. lodash.forIn = forIn;
  15694. lodash.forInRight = forInRight;
  15695. lodash.forOwn = forOwn;
  15696. lodash.forOwnRight = forOwnRight;
  15697. lodash.get = get;
  15698. lodash.gt = gt;
  15699. lodash.gte = gte;
  15700. lodash.has = has;
  15701. lodash.hasIn = hasIn;
  15702. lodash.head = head;
  15703. lodash.identity = identity;
  15704. lodash.includes = includes;
  15705. lodash.indexOf = indexOf;
  15706. lodash.inRange = inRange;
  15707. lodash.invoke = invoke;
  15708. lodash.isArguments = isArguments;
  15709. lodash.isArray = isArray;
  15710. lodash.isArrayBuffer = isArrayBuffer;
  15711. lodash.isArrayLike = isArrayLike;
  15712. lodash.isArrayLikeObject = isArrayLikeObject;
  15713. lodash.isBoolean = isBoolean;
  15714. lodash.isBuffer = isBuffer;
  15715. lodash.isDate = isDate;
  15716. lodash.isElement = isElement;
  15717. lodash.isEmpty = isEmpty;
  15718. lodash.isEqual = isEqual;
  15719. lodash.isEqualWith = isEqualWith;
  15720. lodash.isError = isError;
  15721. lodash.isFinite = isFinite;
  15722. lodash.isFunction = isFunction;
  15723. lodash.isInteger = isInteger;
  15724. lodash.isLength = isLength;
  15725. lodash.isMap = isMap;
  15726. lodash.isMatch = isMatch;
  15727. lodash.isMatchWith = isMatchWith;
  15728. lodash.isNaN = isNaN;
  15729. lodash.isNative = isNative;
  15730. lodash.isNil = isNil;
  15731. lodash.isNull = isNull;
  15732. lodash.isNumber = isNumber;
  15733. lodash.isObject = isObject;
  15734. lodash.isObjectLike = isObjectLike;
  15735. lodash.isPlainObject = isPlainObject;
  15736. lodash.isRegExp = isRegExp;
  15737. lodash.isSafeInteger = isSafeInteger;
  15738. lodash.isSet = isSet;
  15739. lodash.isString = isString;
  15740. lodash.isSymbol = isSymbol;
  15741. lodash.isTypedArray = isTypedArray;
  15742. lodash.isUndefined = isUndefined;
  15743. lodash.isWeakMap = isWeakMap;
  15744. lodash.isWeakSet = isWeakSet;
  15745. lodash.join = join;
  15746. lodash.kebabCase = kebabCase;
  15747. lodash.last = last;
  15748. lodash.lastIndexOf = lastIndexOf;
  15749. lodash.lowerCase = lowerCase;
  15750. lodash.lowerFirst = lowerFirst;
  15751. lodash.lt = lt;
  15752. lodash.lte = lte;
  15753. lodash.max = max;
  15754. lodash.maxBy = maxBy;
  15755. lodash.mean = mean;
  15756. lodash.meanBy = meanBy;
  15757. lodash.min = min;
  15758. lodash.minBy = minBy;
  15759. lodash.stubArray = stubArray;
  15760. lodash.stubFalse = stubFalse;
  15761. lodash.stubObject = stubObject;
  15762. lodash.stubString = stubString;
  15763. lodash.stubTrue = stubTrue;
  15764. lodash.multiply = multiply;
  15765. lodash.nth = nth;
  15766. lodash.noConflict = noConflict;
  15767. lodash.noop = noop;
  15768. lodash.now = now;
  15769. lodash.pad = pad;
  15770. lodash.padEnd = padEnd;
  15771. lodash.padStart = padStart;
  15772. lodash.parseInt = parseInt;
  15773. lodash.random = random;
  15774. lodash.reduce = reduce;
  15775. lodash.reduceRight = reduceRight;
  15776. lodash.repeat = repeat;
  15777. lodash.replace = replace;
  15778. lodash.result = result;
  15779. lodash.round = round;
  15780. lodash.runInContext = runInContext;
  15781. lodash.sample = sample;
  15782. lodash.size = size;
  15783. lodash.snakeCase = snakeCase;
  15784. lodash.some = some;
  15785. lodash.sortedIndex = sortedIndex;
  15786. lodash.sortedIndexBy = sortedIndexBy;
  15787. lodash.sortedIndexOf = sortedIndexOf;
  15788. lodash.sortedLastIndex = sortedLastIndex;
  15789. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15790. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15791. lodash.startCase = startCase;
  15792. lodash.startsWith = startsWith;
  15793. lodash.subtract = subtract;
  15794. lodash.sum = sum;
  15795. lodash.sumBy = sumBy;
  15796. lodash.template = template;
  15797. lodash.times = times;
  15798. lodash.toFinite = toFinite;
  15799. lodash.toInteger = toInteger;
  15800. lodash.toLength = toLength;
  15801. lodash.toLower = toLower;
  15802. lodash.toNumber = toNumber;
  15803. lodash.toSafeInteger = toSafeInteger;
  15804. lodash.toString = toString;
  15805. lodash.toUpper = toUpper;
  15806. lodash.trim = trim;
  15807. lodash.trimEnd = trimEnd;
  15808. lodash.trimStart = trimStart;
  15809. lodash.truncate = truncate;
  15810. lodash.unescape = unescape;
  15811. lodash.uniqueId = uniqueId;
  15812. lodash.upperCase = upperCase;
  15813. lodash.upperFirst = upperFirst;
  15814. // Add aliases.
  15815. lodash.each = forEach;
  15816. lodash.eachRight = forEachRight;
  15817. lodash.first = head;
  15818. mixin(lodash, (function() {
  15819. var source = {};
  15820. baseForOwn(lodash, function(func, methodName) {
  15821. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15822. source[methodName] = func;
  15823. }
  15824. });
  15825. return source;
  15826. }()), { 'chain': false });
  15827. /*------------------------------------------------------------------------*/
  15828. /**
  15829. * The semantic version number.
  15830. *
  15831. * @static
  15832. * @memberOf _
  15833. * @type {string}
  15834. */
  15835. lodash.VERSION = VERSION;
  15836. // Assign default placeholders.
  15837. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15838. lodash[methodName].placeholder = lodash;
  15839. });
  15840. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15841. arrayEach(['drop', 'take'], function(methodName, index) {
  15842. LazyWrapper.prototype[methodName] = function(n) {
  15843. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15844. var result = (this.__filtered__ && !index)
  15845. ? new LazyWrapper(this)
  15846. : this.clone();
  15847. if (result.__filtered__) {
  15848. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15849. } else {
  15850. result.__views__.push({
  15851. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15852. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15853. });
  15854. }
  15855. return result;
  15856. };
  15857. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15858. return this.reverse()[methodName](n).reverse();
  15859. };
  15860. });
  15861. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15862. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15863. var type = index + 1,
  15864. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15865. LazyWrapper.prototype[methodName] = function(iteratee) {
  15866. var result = this.clone();
  15867. result.__iteratees__.push({
  15868. 'iteratee': getIteratee(iteratee, 3),
  15869. 'type': type
  15870. });
  15871. result.__filtered__ = result.__filtered__ || isFilter;
  15872. return result;
  15873. };
  15874. });
  15875. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15876. arrayEach(['head', 'last'], function(methodName, index) {
  15877. var takeName = 'take' + (index ? 'Right' : '');
  15878. LazyWrapper.prototype[methodName] = function() {
  15879. return this[takeName](1).value()[0];
  15880. };
  15881. });
  15882. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15883. arrayEach(['initial', 'tail'], function(methodName, index) {
  15884. var dropName = 'drop' + (index ? '' : 'Right');
  15885. LazyWrapper.prototype[methodName] = function() {
  15886. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15887. };
  15888. });
  15889. LazyWrapper.prototype.compact = function() {
  15890. return this.filter(identity);
  15891. };
  15892. LazyWrapper.prototype.find = function(predicate) {
  15893. return this.filter(predicate).head();
  15894. };
  15895. LazyWrapper.prototype.findLast = function(predicate) {
  15896. return this.reverse().find(predicate);
  15897. };
  15898. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15899. if (typeof path == 'function') {
  15900. return new LazyWrapper(this);
  15901. }
  15902. return this.map(function(value) {
  15903. return baseInvoke(value, path, args);
  15904. });
  15905. });
  15906. LazyWrapper.prototype.reject = function(predicate) {
  15907. return this.filter(negate(getIteratee(predicate)));
  15908. };
  15909. LazyWrapper.prototype.slice = function(start, end) {
  15910. start = toInteger(start);
  15911. var result = this;
  15912. if (result.__filtered__ && (start > 0 || end < 0)) {
  15913. return new LazyWrapper(result);
  15914. }
  15915. if (start < 0) {
  15916. result = result.takeRight(-start);
  15917. } else if (start) {
  15918. result = result.drop(start);
  15919. }
  15920. if (end !== undefined) {
  15921. end = toInteger(end);
  15922. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15923. }
  15924. return result;
  15925. };
  15926. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15927. return this.reverse().takeWhile(predicate).reverse();
  15928. };
  15929. LazyWrapper.prototype.toArray = function() {
  15930. return this.take(MAX_ARRAY_LENGTH);
  15931. };
  15932. // Add `LazyWrapper` methods to `lodash.prototype`.
  15933. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15934. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15935. isTaker = /^(?:head|last)$/.test(methodName),
  15936. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15937. retUnwrapped = isTaker || /^find/.test(methodName);
  15938. if (!lodashFunc) {
  15939. return;
  15940. }
  15941. lodash.prototype[methodName] = function() {
  15942. var value = this.__wrapped__,
  15943. args = isTaker ? [1] : arguments,
  15944. isLazy = value instanceof LazyWrapper,
  15945. iteratee = args[0],
  15946. useLazy = isLazy || isArray(value);
  15947. var interceptor = function(value) {
  15948. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15949. return (isTaker && chainAll) ? result[0] : result;
  15950. };
  15951. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15952. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15953. isLazy = useLazy = false;
  15954. }
  15955. var chainAll = this.__chain__,
  15956. isHybrid = !!this.__actions__.length,
  15957. isUnwrapped = retUnwrapped && !chainAll,
  15958. onlyLazy = isLazy && !isHybrid;
  15959. if (!retUnwrapped && useLazy) {
  15960. value = onlyLazy ? value : new LazyWrapper(this);
  15961. var result = func.apply(value, args);
  15962. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15963. return new LodashWrapper(result, chainAll);
  15964. }
  15965. if (isUnwrapped && onlyLazy) {
  15966. return func.apply(this, args);
  15967. }
  15968. result = this.thru(interceptor);
  15969. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15970. };
  15971. });
  15972. // Add `Array` methods to `lodash.prototype`.
  15973. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15974. var func = arrayProto[methodName],
  15975. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15976. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15977. lodash.prototype[methodName] = function() {
  15978. var args = arguments;
  15979. if (retUnwrapped && !this.__chain__) {
  15980. var value = this.value();
  15981. return func.apply(isArray(value) ? value : [], args);
  15982. }
  15983. return this[chainName](function(value) {
  15984. return func.apply(isArray(value) ? value : [], args);
  15985. });
  15986. };
  15987. });
  15988. // Map minified method names to their real names.
  15989. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15990. var lodashFunc = lodash[methodName];
  15991. if (lodashFunc) {
  15992. var key = (lodashFunc.name + ''),
  15993. names = realNames[key] || (realNames[key] = []);
  15994. names.push({ 'name': methodName, 'func': lodashFunc });
  15995. }
  15996. });
  15997. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  15998. 'name': 'wrapper',
  15999. 'func': undefined
  16000. }];
  16001. // Add methods to `LazyWrapper`.
  16002. LazyWrapper.prototype.clone = lazyClone;
  16003. LazyWrapper.prototype.reverse = lazyReverse;
  16004. LazyWrapper.prototype.value = lazyValue;
  16005. // Add chain sequence methods to the `lodash` wrapper.
  16006. lodash.prototype.at = wrapperAt;
  16007. lodash.prototype.chain = wrapperChain;
  16008. lodash.prototype.commit = wrapperCommit;
  16009. lodash.prototype.next = wrapperNext;
  16010. lodash.prototype.plant = wrapperPlant;
  16011. lodash.prototype.reverse = wrapperReverse;
  16012. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16013. // Add lazy aliases.
  16014. lodash.prototype.first = lodash.prototype.head;
  16015. if (symIterator) {
  16016. lodash.prototype[symIterator] = wrapperToIterator;
  16017. }
  16018. return lodash;
  16019. });
  16020. /*--------------------------------------------------------------------------*/
  16021. // Export lodash.
  16022. var _ = runInContext();
  16023. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16024. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16025. // Expose Lodash on the global object to prevent errors when Lodash is
  16026. // loaded by a script tag in the presence of an AMD loader.
  16027. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16028. // Use `_.noConflict` to remove Lodash from the global object.
  16029. root._ = _;
  16030. // Define as an anonymous module so, through path mapping, it can be
  16031. // referenced as the "underscore" module.
  16032. define(function() {
  16033. return _;
  16034. });
  16035. }
  16036. // Check for `exports` after `define` in case a build optimizer adds it.
  16037. else if (freeModule) {
  16038. // Export for Node.js.
  16039. (freeModule.exports = _)._ = _;
  16040. // Export for CommonJS support.
  16041. freeExports._ = _;
  16042. }
  16043. else {
  16044. // Export to the global object.
  16045. root._ = _;
  16046. }
  16047. }.call(this));