lodash.js 567 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075
  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. /*eslint-disable*/
  10. (function() {
  11. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  12. var undefined;
  13. /** Used as the semantic version number. */
  14. var VERSION = '4.17.10';
  15. /** Used as the size to enable large array optimizations. */
  16. var LARGE_ARRAY_SIZE = 200;
  17. /** Error message constants. */
  18. var CORE_ERROR_TEXT =
  19. 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  20. FUNC_ERROR_TEXT = 'Expected a function';
  21. /** Used to stand-in for `undefined` hash values. */
  22. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  23. /** Used as the maximum memoize cache size. */
  24. var MAX_MEMOIZE_SIZE = 500;
  25. /** Used as the internal argument placeholder. */
  26. var PLACEHOLDER = '__lodash_placeholder__';
  27. /** Used to compose bitmasks for cloning. */
  28. var CLONE_DEEP_FLAG = 1,
  29. CLONE_FLAT_FLAG = 2,
  30. CLONE_SYMBOLS_FLAG = 4;
  31. /** Used to compose bitmasks for value comparisons. */
  32. var COMPARE_PARTIAL_FLAG = 1,
  33. COMPARE_UNORDERED_FLAG = 2;
  34. /** Used to compose bitmasks for function metadata. */
  35. var WRAP_BIND_FLAG = 1,
  36. WRAP_BIND_KEY_FLAG = 2,
  37. WRAP_CURRY_BOUND_FLAG = 4,
  38. WRAP_CURRY_FLAG = 8,
  39. WRAP_CURRY_RIGHT_FLAG = 16,
  40. WRAP_PARTIAL_FLAG = 32,
  41. WRAP_PARTIAL_RIGHT_FLAG = 64,
  42. WRAP_ARY_FLAG = 128,
  43. WRAP_REARG_FLAG = 256,
  44. WRAP_FLIP_FLAG = 512;
  45. /** Used as default options for `_.truncate`. */
  46. var DEFAULT_TRUNC_LENGTH = 30,
  47. DEFAULT_TRUNC_OMISSION = '...';
  48. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  49. var HOT_COUNT = 800,
  50. HOT_SPAN = 16;
  51. /** Used to indicate the type of lazy iteratees. */
  52. var LAZY_FILTER_FLAG = 1,
  53. LAZY_MAP_FLAG = 2,
  54. LAZY_WHILE_FLAG = 3;
  55. /** Used as references for various `Number` constants. */
  56. var INFINITY = 1 / 0,
  57. MAX_SAFE_INTEGER = 9007199254740991,
  58. MAX_INTEGER = 1.7976931348623157e308,
  59. NAN = 0 / 0;
  60. /** Used as references for the maximum length and index of an array. */
  61. var MAX_ARRAY_LENGTH = 4294967295,
  62. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  63. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  64. /** Used to associate wrap methods with their bit flags. */
  65. var wrapFlags = [
  66. ['ary', WRAP_ARY_FLAG],
  67. ['bind', WRAP_BIND_FLAG],
  68. ['bindKey', WRAP_BIND_KEY_FLAG],
  69. ['curry', WRAP_CURRY_FLAG],
  70. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  71. ['flip', WRAP_FLIP_FLAG],
  72. ['partial', WRAP_PARTIAL_FLAG],
  73. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  74. ['rearg', WRAP_REARG_FLAG]
  75. ];
  76. /** `Object#toString` result references. */
  77. var argsTag = '[object Arguments]',
  78. arrayTag = '[object Array]',
  79. asyncTag = '[object AsyncFunction]',
  80. boolTag = '[object Boolean]',
  81. dateTag = '[object Date]',
  82. domExcTag = '[object DOMException]',
  83. errorTag = '[object Error]',
  84. funcTag = '[object Function]',
  85. genTag = '[object GeneratorFunction]',
  86. mapTag = '[object Map]',
  87. numberTag = '[object Number]',
  88. nullTag = '[object Null]',
  89. objectTag = '[object Object]',
  90. promiseTag = '[object Promise]',
  91. proxyTag = '[object Proxy]',
  92. regexpTag = '[object RegExp]',
  93. setTag = '[object Set]',
  94. stringTag = '[object String]',
  95. symbolTag = '[object Symbol]',
  96. undefinedTag = '[object Undefined]',
  97. weakMapTag = '[object WeakMap]',
  98. weakSetTag = '[object WeakSet]';
  99. var arrayBufferTag = '[object ArrayBuffer]',
  100. dataViewTag = '[object DataView]',
  101. float32Tag = '[object Float32Array]',
  102. float64Tag = '[object Float64Array]',
  103. int8Tag = '[object Int8Array]',
  104. int16Tag = '[object Int16Array]',
  105. int32Tag = '[object Int32Array]',
  106. uint8Tag = '[object Uint8Array]',
  107. uint8ClampedTag = '[object Uint8ClampedArray]',
  108. uint16Tag = '[object Uint16Array]',
  109. uint32Tag = '[object Uint32Array]';
  110. /** Used to match empty string literals in compiled template source. */
  111. var reEmptyStringLeading = /\b__p \+= '';/g,
  112. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  113. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  114. /** Used to match HTML entities and HTML characters. */
  115. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  116. reUnescapedHtml = /[&<>"']/g,
  117. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  118. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  119. /** Used to match template delimiters. */
  120. var reEscape = /<%-([\s\S]+?)%>/g,
  121. reEvaluate = /<%([\s\S]+?)%>/g,
  122. reInterpolate = /<%=([\s\S]+?)%>/g;
  123. /** Used to match property names within property paths. */
  124. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  125. reIsPlainProp = /^\w*$/,
  126. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  127. /**
  128. * Used to match `RegExp`
  129. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  130. */
  131. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  132. reHasRegExpChar = RegExp(reRegExpChar.source);
  133. /** Used to match leading and trailing whitespace. */
  134. var reTrim = /^\s+|\s+$/g,
  135. reTrimStart = /^\s+/,
  136. reTrimEnd = /\s+$/;
  137. /** Used to match wrap detail comments. */
  138. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  139. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  140. reSplitDetails = /,? & /;
  141. /** Used to match words composed of alphanumeric characters. */
  142. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  143. /** Used to match backslashes in property paths. */
  144. var reEscapeChar = /\\(\\)?/g;
  145. /**
  146. * Used to match
  147. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  148. */
  149. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  150. /** Used to match `RegExp` flags from their coerced string values. */
  151. var reFlags = /\w*$/;
  152. /** Used to detect bad signed hexadecimal string values. */
  153. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  154. /** Used to detect binary string values. */
  155. var reIsBinary = /^0b[01]+$/i;
  156. /** Used to detect host constructors (Safari). */
  157. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  158. /** Used to detect octal string values. */
  159. var reIsOctal = /^0o[0-7]+$/i;
  160. /** Used to detect unsigned integer values. */
  161. var reIsUint = /^(?:0|[1-9]\d*)$/;
  162. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  163. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  164. /** Used to ensure capturing order of template delimiters. */
  165. var reNoMatch = /($^)/;
  166. /** Used to match unescaped characters in compiled string literals. */
  167. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  168. /** Used to compose unicode character classes. */
  169. var rsAstralRange = '\\ud800-\\udfff',
  170. rsComboMarksRange = '\\u0300-\\u036f',
  171. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  172. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  173. rsComboRange =
  174. rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  175. rsDingbatRange = '\\u2700-\\u27bf',
  176. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  177. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  178. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  179. rsPunctuationRange = '\\u2000-\\u206f',
  180. rsSpaceRange =
  181. ' \\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',
  182. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  183. rsVarRange = '\\ufe0e\\ufe0f',
  184. rsBreakRange =
  185. rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  186. /** Used to compose unicode capture groups. */
  187. var rsApos = "['\u2019]",
  188. rsAstral = '[' + rsAstralRange + ']',
  189. rsBreak = '[' + rsBreakRange + ']',
  190. rsCombo = '[' + rsComboRange + ']',
  191. rsDigits = '\\d+',
  192. rsDingbat = '[' + rsDingbatRange + ']',
  193. rsLower = '[' + rsLowerRange + ']',
  194. rsMisc =
  195. '[^' +
  196. rsAstralRange +
  197. rsBreakRange +
  198. rsDigits +
  199. rsDingbatRange +
  200. rsLowerRange +
  201. rsUpperRange +
  202. ']',
  203. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  204. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  205. rsNonAstral = '[^' + rsAstralRange + ']',
  206. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  207. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  208. rsUpper = '[' + rsUpperRange + ']',
  209. rsZWJ = '\\u200d';
  210. /** Used to compose unicode regexes. */
  211. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  212. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  213. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  214. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  215. reOptMod = rsModifier + '?',
  216. rsOptVar = '[' + rsVarRange + ']?',
  217. rsOptJoin =
  218. '(?:' +
  219. rsZWJ +
  220. '(?:' +
  221. [rsNonAstral, rsRegional, rsSurrPair].join('|') +
  222. ')' +
  223. rsOptVar +
  224. reOptMod +
  225. ')*',
  226. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  227. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  228. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  229. rsEmoji =
  230. '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  231. rsSymbol =
  232. '(?:' +
  233. [
  234. rsNonAstral + rsCombo + '?',
  235. rsCombo,
  236. rsRegional,
  237. rsSurrPair,
  238. rsAstral
  239. ].join('|') +
  240. ')';
  241. /** Used to match apostrophes. */
  242. var reApos = RegExp(rsApos, 'g');
  243. /**
  244. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  245. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  246. */
  247. var reComboMark = RegExp(rsCombo, 'g');
  248. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  249. var reUnicode = RegExp(
  250. rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq,
  251. 'g'
  252. );
  253. /** Used to match complex or compound words. */
  254. var reUnicodeWord = RegExp(
  255. [
  256. rsUpper +
  257. '?' +
  258. rsLower +
  259. '+' +
  260. rsOptContrLower +
  261. '(?=' +
  262. [rsBreak, rsUpper, '$'].join('|') +
  263. ')',
  264. rsMiscUpper +
  265. '+' +
  266. rsOptContrUpper +
  267. '(?=' +
  268. [rsBreak, rsUpper + rsMiscLower, '$'].join('|') +
  269. ')',
  270. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  271. rsUpper + '+' + rsOptContrUpper,
  272. rsOrdUpper,
  273. rsOrdLower,
  274. rsDigits,
  275. rsEmoji
  276. ].join('|'),
  277. 'g'
  278. );
  279. /** 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/). */
  280. var reHasUnicode = RegExp(
  281. '[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'
  282. );
  283. /** Used to detect strings that need a more robust regexp to match words. */
  284. 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 ]/;
  285. /** Used to assign default `context` object properties. */
  286. var contextProps = [
  287. 'Array',
  288. 'Buffer',
  289. 'DataView',
  290. 'Date',
  291. 'Error',
  292. 'Float32Array',
  293. 'Float64Array',
  294. 'Function',
  295. 'Int8Array',
  296. 'Int16Array',
  297. 'Int32Array',
  298. 'Map',
  299. 'Math',
  300. 'Object',
  301. 'Promise',
  302. 'RegExp',
  303. 'Set',
  304. 'String',
  305. 'Symbol',
  306. 'TypeError',
  307. 'Uint8Array',
  308. 'Uint8ClampedArray',
  309. 'Uint16Array',
  310. 'Uint32Array',
  311. 'WeakMap',
  312. '_',
  313. 'clearTimeout',
  314. 'isFinite',
  315. 'parseInt',
  316. 'setTimeout'
  317. ];
  318. /** Used to make template sourceURLs easier to identify. */
  319. var templateCounter = -1;
  320. /** Used to identify `toStringTag` values of typed arrays. */
  321. var typedArrayTags = {};
  322. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[
  323. int8Tag
  324. ] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[
  325. uint8Tag
  326. ] = typedArrayTags[uint8ClampedTag] = typedArrayTags[
  327. uint16Tag
  328. ] = typedArrayTags[uint32Tag] = true;
  329. typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[
  330. arrayBufferTag
  331. ] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[
  332. dateTag
  333. ] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[
  334. mapTag
  335. ] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[
  336. regexpTag
  337. ] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[
  338. weakMapTag
  339. ] = false;
  340. /** Used to identify `toStringTag` values supported by `_.clone`. */
  341. var cloneableTags = {};
  342. cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[
  343. arrayBufferTag
  344. ] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[
  345. dateTag
  346. ] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[
  347. int8Tag
  348. ] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[
  349. mapTag
  350. ] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[
  351. regexpTag
  352. ] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[
  353. symbolTag
  354. ] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[
  355. uint16Tag
  356. ] = cloneableTags[uint32Tag] = true;
  357. cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[
  358. weakMapTag
  359. ] = false;
  360. /** Used to map Latin Unicode letters to basic Latin letters. */
  361. var deburredLetters = {
  362. // Latin-1 Supplement block.
  363. À: 'A',
  364. Á: 'A',
  365. Â: 'A',
  366. Ã: 'A',
  367. Ä: 'A',
  368. Å: 'A',
  369. à: 'a',
  370. á: 'a',
  371. â: 'a',
  372. ã: 'a',
  373. ä: 'a',
  374. å: 'a',
  375. Ç: 'C',
  376. ç: 'c',
  377. Ð: 'D',
  378. ð: 'd',
  379. È: 'E',
  380. É: 'E',
  381. Ê: 'E',
  382. Ë: 'E',
  383. è: 'e',
  384. é: 'e',
  385. ê: 'e',
  386. ë: 'e',
  387. Ì: 'I',
  388. Í: 'I',
  389. Î: 'I',
  390. Ï: 'I',
  391. ì: 'i',
  392. í: 'i',
  393. î: 'i',
  394. ï: 'i',
  395. Ñ: 'N',
  396. ñ: 'n',
  397. Ò: 'O',
  398. Ó: 'O',
  399. Ô: 'O',
  400. Õ: 'O',
  401. Ö: 'O',
  402. Ø: 'O',
  403. ò: 'o',
  404. ó: 'o',
  405. ô: 'o',
  406. õ: 'o',
  407. ö: 'o',
  408. ø: 'o',
  409. Ù: 'U',
  410. Ú: 'U',
  411. Û: 'U',
  412. Ü: 'U',
  413. ù: 'u',
  414. ú: 'u',
  415. û: 'u',
  416. ü: 'u',
  417. Ý: 'Y',
  418. ý: 'y',
  419. ÿ: 'y',
  420. Æ: 'Ae',
  421. æ: 'ae',
  422. Þ: 'Th',
  423. þ: 'th',
  424. ß: 'ss',
  425. // Latin Extended-A block.
  426. Ā: 'A',
  427. Ă: 'A',
  428. Ą: 'A',
  429. ā: 'a',
  430. ă: 'a',
  431. ą: 'a',
  432. Ć: 'C',
  433. Ĉ: 'C',
  434. Ċ: 'C',
  435. Č: 'C',
  436. ć: 'c',
  437. ĉ: 'c',
  438. ċ: 'c',
  439. č: 'c',
  440. Ď: 'D',
  441. Đ: 'D',
  442. ď: 'd',
  443. đ: 'd',
  444. Ē: 'E',
  445. Ĕ: 'E',
  446. Ė: 'E',
  447. Ę: 'E',
  448. Ě: 'E',
  449. ē: 'e',
  450. ĕ: 'e',
  451. ė: 'e',
  452. ę: 'e',
  453. ě: 'e',
  454. Ĝ: 'G',
  455. Ğ: 'G',
  456. Ġ: 'G',
  457. Ģ: 'G',
  458. ĝ: 'g',
  459. ğ: 'g',
  460. ġ: 'g',
  461. ģ: 'g',
  462. Ĥ: 'H',
  463. Ħ: 'H',
  464. ĥ: 'h',
  465. ħ: 'h',
  466. Ĩ: 'I',
  467. Ī: 'I',
  468. Ĭ: 'I',
  469. Į: 'I',
  470. İ: 'I',
  471. ĩ: 'i',
  472. ī: 'i',
  473. ĭ: 'i',
  474. į: 'i',
  475. ı: 'i',
  476. Ĵ: 'J',
  477. ĵ: 'j',
  478. Ķ: 'K',
  479. ķ: 'k',
  480. ĸ: 'k',
  481. Ĺ: 'L',
  482. Ļ: 'L',
  483. Ľ: 'L',
  484. Ŀ: 'L',
  485. Ł: 'L',
  486. ĺ: 'l',
  487. ļ: 'l',
  488. ľ: 'l',
  489. ŀ: 'l',
  490. ł: 'l',
  491. Ń: 'N',
  492. Ņ: 'N',
  493. Ň: 'N',
  494. Ŋ: 'N',
  495. ń: 'n',
  496. ņ: 'n',
  497. ň: 'n',
  498. ŋ: 'n',
  499. Ō: 'O',
  500. Ŏ: 'O',
  501. Ő: 'O',
  502. ō: 'o',
  503. ŏ: 'o',
  504. ő: 'o',
  505. Ŕ: 'R',
  506. Ŗ: 'R',
  507. Ř: 'R',
  508. ŕ: 'r',
  509. ŗ: 'r',
  510. ř: 'r',
  511. Ś: 'S',
  512. Ŝ: 'S',
  513. Ş: 'S',
  514. Š: 'S',
  515. ś: 's',
  516. ŝ: 's',
  517. ş: 's',
  518. š: 's',
  519. Ţ: 'T',
  520. Ť: 'T',
  521. Ŧ: 'T',
  522. ţ: 't',
  523. ť: 't',
  524. ŧ: 't',
  525. Ũ: 'U',
  526. Ū: 'U',
  527. Ŭ: 'U',
  528. Ů: 'U',
  529. Ű: 'U',
  530. Ų: 'U',
  531. ũ: 'u',
  532. ū: 'u',
  533. ŭ: 'u',
  534. ů: 'u',
  535. ű: 'u',
  536. ų: 'u',
  537. Ŵ: 'W',
  538. ŵ: 'w',
  539. Ŷ: 'Y',
  540. ŷ: 'y',
  541. Ÿ: 'Y',
  542. Ź: 'Z',
  543. Ż: 'Z',
  544. Ž: 'Z',
  545. ź: 'z',
  546. ż: 'z',
  547. ž: 'z',
  548. IJ: 'IJ',
  549. ij: 'ij',
  550. Œ: 'Oe',
  551. œ: 'oe',
  552. ʼn: "'n",
  553. ſ: 's'
  554. };
  555. /** Used to map characters to HTML entities. */
  556. var htmlEscapes = {
  557. '&': '&amp;',
  558. '<': '&lt;',
  559. '>': '&gt;',
  560. '"': '&quot;',
  561. "'": '&#39;'
  562. };
  563. /** Used to map HTML entities to characters. */
  564. var htmlUnescapes = {
  565. '&amp;': '&',
  566. '&lt;': '<',
  567. '&gt;': '>',
  568. '&quot;': '"',
  569. '&#39;': "'"
  570. };
  571. /** Used to escape characters for inclusion in compiled string literals. */
  572. var stringEscapes = {
  573. '\\': '\\',
  574. "'": "'",
  575. '\n': 'n',
  576. '\r': 'r',
  577. '\u2028': 'u2028',
  578. '\u2029': 'u2029'
  579. };
  580. /** Built-in method references without a dependency on `root`. */
  581. var freeParseFloat = parseFloat,
  582. freeParseInt = parseInt;
  583. /** Detect free variable `global` from Node.js. */
  584. var freeGlobal =
  585. typeof global === 'object' && global && global.Object === Object && global;
  586. /** Detect free variable `self`. */
  587. var freeSelf =
  588. typeof self === 'object' && self && self.Object === Object && self;
  589. /** Used as a reference to the global object. */
  590. var root = freeGlobal || freeSelf || Function('return this')();
  591. /** Detect free variable `exports`. */
  592. var freeExports =
  593. typeof exports === 'object' && exports && !exports.nodeType && exports;
  594. /** Detect free variable `module`. */
  595. var freeModule =
  596. freeExports &&
  597. typeof module === 'object' &&
  598. module &&
  599. !module.nodeType &&
  600. module;
  601. /** Detect the popular CommonJS extension `module.exports`. */
  602. var moduleExports = freeModule && freeModule.exports === freeExports;
  603. /** Detect free variable `process` from Node.js. */
  604. var freeProcess = moduleExports && freeGlobal.process;
  605. /** Used to access faster Node.js helpers. */
  606. var nodeUtil = (function() {
  607. try {
  608. // Use `util.types` for Node.js 10+.
  609. var types =
  610. freeModule && freeModule.require && freeModule.require('util').types;
  611. if (types) {
  612. return types;
  613. }
  614. // Legacy `process.binding('util')` for Node.js < 10.
  615. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  616. } catch (e) { }
  617. })();
  618. /* Node.js helper references. */
  619. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  620. nodeIsDate = nodeUtil && nodeUtil.isDate,
  621. nodeIsMap = nodeUtil && nodeUtil.isMap,
  622. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  623. nodeIsSet = nodeUtil && nodeUtil.isSet,
  624. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  625. /* --------------------------------------------------------------------------*/
  626. /**
  627. * A faster alternative to `Function#apply`, this function invokes `func`
  628. * with the `this` binding of `thisArg` and the arguments of `args`.
  629. *
  630. * @private
  631. * @param {Function} func The function to invoke.
  632. * @param {*} thisArg The `this` binding of `func`.
  633. * @param {Array} args The arguments to invoke `func` with.
  634. * @returns {*} Returns the result of `func`.
  635. */
  636. function apply(func, thisArg, args) {
  637. switch (args.length) {
  638. case 0:
  639. return func.call(thisArg);
  640. case 1:
  641. return func.call(thisArg, args[0]);
  642. case 2:
  643. return func.call(thisArg, args[0], args[1]);
  644. case 3:
  645. return func.call(thisArg, args[0], args[1], args[2]);
  646. }
  647. return func.apply(thisArg, args);
  648. }
  649. /**
  650. * A specialized version of `baseAggregator` for arrays.
  651. *
  652. * @private
  653. * @param {Array} [array] The array to iterate over.
  654. * @param {Function} setter The function to set `accumulator` values.
  655. * @param {Function} iteratee The iteratee to transform keys.
  656. * @param {Object} accumulator The initial aggregated object.
  657. * @returns {Function} Returns `accumulator`.
  658. */
  659. function arrayAggregator(array, setter, iteratee, accumulator) {
  660. var index = -1,
  661. length = array == null ? 0 : array.length;
  662. while (++index < length) {
  663. var value = array[index];
  664. setter(accumulator, value, iteratee(value), array);
  665. }
  666. return accumulator;
  667. }
  668. /**
  669. * A specialized version of `_.forEach` for arrays without support for
  670. * iteratee shorthands.
  671. *
  672. * @private
  673. * @param {Array} [array] The array to iterate over.
  674. * @param {Function} iteratee The function invoked per iteration.
  675. * @returns {Array} Returns `array`.
  676. */
  677. function arrayEach(array, iteratee) {
  678. var index = -1,
  679. length = array == null ? 0 : array.length;
  680. while (++index < length) {
  681. if (iteratee(array[index], index, array) === false) {
  682. break;
  683. }
  684. }
  685. return array;
  686. }
  687. /**
  688. * A specialized version of `_.forEachRight` for arrays without support for
  689. * iteratee shorthands.
  690. *
  691. * @private
  692. * @param {Array} [array] The array to iterate over.
  693. * @param {Function} iteratee The function invoked per iteration.
  694. * @returns {Array} Returns `array`.
  695. */
  696. function arrayEachRight(array, iteratee) {
  697. var length = array == null ? 0 : array.length;
  698. while (length--) {
  699. if (iteratee(array[length], length, array) === false) {
  700. break;
  701. }
  702. }
  703. return array;
  704. }
  705. /**
  706. * A specialized version of `_.every` for arrays without support for
  707. * iteratee shorthands.
  708. *
  709. * @private
  710. * @param {Array} [array] The array to iterate over.
  711. * @param {Function} predicate The function invoked per iteration.
  712. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  713. * else `false`.
  714. */
  715. function arrayEvery(array, predicate) {
  716. var index = -1,
  717. length = array == null ? 0 : array.length;
  718. while (++index < length) {
  719. if (!predicate(array[index], index, array)) {
  720. return false;
  721. }
  722. }
  723. return true;
  724. }
  725. /**
  726. * A specialized version of `_.filter` for arrays without support for
  727. * iteratee shorthands.
  728. *
  729. * @private
  730. * @param {Array} [array] The array to iterate over.
  731. * @param {Function} predicate The function invoked per iteration.
  732. * @returns {Array} Returns the new filtered array.
  733. */
  734. function arrayFilter(array, predicate) {
  735. var index = -1,
  736. length = array == null ? 0 : array.length,
  737. resIndex = 0,
  738. result = [];
  739. while (++index < length) {
  740. var value = array[index];
  741. if (predicate(value, index, array)) {
  742. result[resIndex++] = value;
  743. }
  744. }
  745. return result;
  746. }
  747. /**
  748. * A specialized version of `_.includes` for arrays without support for
  749. * specifying an index to search from.
  750. *
  751. * @private
  752. * @param {Array} [array] The array to inspect.
  753. * @param {*} target The value to search for.
  754. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  755. */
  756. function arrayIncludes(array, value) {
  757. var length = array == null ? 0 : array.length;
  758. return !!length && baseIndexOf(array, value, 0) > -1;
  759. }
  760. /**
  761. * This function is like `arrayIncludes` except that it accepts a comparator.
  762. *
  763. * @private
  764. * @param {Array} [array] The array to inspect.
  765. * @param {*} target The value to search for.
  766. * @param {Function} comparator The comparator invoked per element.
  767. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  768. */
  769. function arrayIncludesWith(array, value, comparator) {
  770. var index = -1,
  771. length = array == null ? 0 : array.length;
  772. while (++index < length) {
  773. if (comparator(value, array[index])) {
  774. return true;
  775. }
  776. }
  777. return false;
  778. }
  779. /**
  780. * A specialized version of `_.map` for arrays without support for iteratee
  781. * shorthands.
  782. *
  783. * @private
  784. * @param {Array} [array] The array to iterate over.
  785. * @param {Function} iteratee The function invoked per iteration.
  786. * @returns {Array} Returns the new mapped array.
  787. */
  788. function arrayMap(array, iteratee) {
  789. var index = -1,
  790. length = array == null ? 0 : array.length,
  791. result = Array(length);
  792. while (++index < length) {
  793. result[index] = iteratee(array[index], index, array);
  794. }
  795. return result;
  796. }
  797. /**
  798. * Appends the elements of `values` to `array`.
  799. *
  800. * @private
  801. * @param {Array} array The array to modify.
  802. * @param {Array} values The values to append.
  803. * @returns {Array} Returns `array`.
  804. */
  805. function arrayPush(array, values) {
  806. var index = -1,
  807. length = values.length,
  808. offset = array.length;
  809. while (++index < length) {
  810. array[offset + index] = values[index];
  811. }
  812. return array;
  813. }
  814. /**
  815. * A specialized version of `_.reduce` for arrays without support for
  816. * iteratee shorthands.
  817. *
  818. * @private
  819. * @param {Array} [array] The array 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 element of `array` as
  823. * the initial value.
  824. * @returns {*} Returns the accumulated value.
  825. */
  826. function arrayReduce(array, iteratee, accumulator, initAccum) {
  827. var index = -1,
  828. length = array == null ? 0 : array.length;
  829. if (initAccum && length) {
  830. accumulator = array[++index];
  831. }
  832. while (++index < length) {
  833. accumulator = iteratee(accumulator, array[index], index, array);
  834. }
  835. return accumulator;
  836. }
  837. /**
  838. * A specialized version of `_.reduceRight` for arrays without support for
  839. * iteratee shorthands.
  840. *
  841. * @private
  842. * @param {Array} [array] The array to iterate over.
  843. * @param {Function} iteratee The function invoked per iteration.
  844. * @param {*} [accumulator] The initial value.
  845. * @param {boolean} [initAccum] Specify using the last element of `array` as
  846. * the initial value.
  847. * @returns {*} Returns the accumulated value.
  848. */
  849. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  850. var length = array == null ? 0 : array.length;
  851. if (initAccum && length) {
  852. accumulator = array[--length];
  853. }
  854. while (length--) {
  855. accumulator = iteratee(accumulator, array[length], length, array);
  856. }
  857. return accumulator;
  858. }
  859. /**
  860. * A specialized version of `_.some` for arrays without support for iteratee
  861. * shorthands.
  862. *
  863. * @private
  864. * @param {Array} [array] The array to iterate over.
  865. * @param {Function} predicate The function invoked per iteration.
  866. * @returns {boolean} Returns `true` if any element passes the predicate check,
  867. * else `false`.
  868. */
  869. function arraySome(array, predicate) {
  870. var index = -1,
  871. length = array == null ? 0 : array.length;
  872. while (++index < length) {
  873. if (predicate(array[index], index, array)) {
  874. return true;
  875. }
  876. }
  877. return false;
  878. }
  879. /**
  880. * Gets the size of an ASCII `string`.
  881. *
  882. * @private
  883. * @param {string} string The string inspect.
  884. * @returns {number} Returns the string size.
  885. */
  886. var asciiSize = baseProperty('length');
  887. /**
  888. * Converts an ASCII `string` to an array.
  889. *
  890. * @private
  891. * @param {string} string The string to convert.
  892. * @returns {Array} Returns the converted array.
  893. */
  894. function asciiToArray(string) {
  895. return string.split('');
  896. }
  897. /**
  898. * Splits an ASCII `string` into an array of its words.
  899. *
  900. * @private
  901. * @param {string} The string to inspect.
  902. * @returns {Array} Returns the words of `string`.
  903. */
  904. function asciiWords(string) {
  905. return string.match(reAsciiWord) || [];
  906. }
  907. /**
  908. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  909. * without support for iteratee shorthands, which iterates over `collection`
  910. * using `eachFunc`.
  911. *
  912. * @private
  913. * @param {Array|Object} collection The collection to inspect.
  914. * @param {Function} predicate The function invoked per iteration.
  915. * @param {Function} eachFunc The function to iterate over `collection`.
  916. * @returns {*} Returns the found element or its key, else `undefined`.
  917. */
  918. function baseFindKey(collection, predicate, eachFunc) {
  919. var result;
  920. eachFunc(collection, function(value, key, collection) {
  921. if (predicate(value, key, collection)) {
  922. result = key;
  923. return false;
  924. }
  925. });
  926. return result;
  927. }
  928. /**
  929. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  930. * support for iteratee shorthands.
  931. *
  932. * @private
  933. * @param {Array} array The array to inspect.
  934. * @param {Function} predicate The function invoked per iteration.
  935. * @param {number} fromIndex The index to search from.
  936. * @param {boolean} [fromRight] Specify iterating from right to left.
  937. * @returns {number} Returns the index of the matched value, else `-1`.
  938. */
  939. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  940. var length = array.length,
  941. index = fromIndex + (fromRight ? 1 : -1);
  942. while (fromRight ? index-- : ++index < length) {
  943. if (predicate(array[index], index, array)) {
  944. return index;
  945. }
  946. }
  947. return -1;
  948. }
  949. /**
  950. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  951. *
  952. * @private
  953. * @param {Array} array The array to inspect.
  954. * @param {*} value The value to search for.
  955. * @param {number} fromIndex The index to search from.
  956. * @returns {number} Returns the index of the matched value, else `-1`.
  957. */
  958. function baseIndexOf(array, value, fromIndex) {
  959. return value === value
  960. ? strictIndexOf(array, value, fromIndex)
  961. : baseFindIndex(array, baseIsNaN, fromIndex);
  962. }
  963. /**
  964. * This function is like `baseIndexOf` except that it accepts a comparator.
  965. *
  966. * @private
  967. * @param {Array} array The array to inspect.
  968. * @param {*} value The value to search for.
  969. * @param {number} fromIndex The index to search from.
  970. * @param {Function} comparator The comparator invoked per element.
  971. * @returns {number} Returns the index of the matched value, else `-1`.
  972. */
  973. function baseIndexOfWith(array, value, fromIndex, comparator) {
  974. var index = fromIndex - 1,
  975. length = array.length;
  976. while (++index < length) {
  977. if (comparator(array[index], value)) {
  978. return index;
  979. }
  980. }
  981. return -1;
  982. }
  983. /**
  984. * The base implementation of `_.isNaN` without support for number objects.
  985. *
  986. * @private
  987. * @param {*} value The value to check.
  988. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  989. */
  990. function baseIsNaN(value) {
  991. return value !== value;
  992. }
  993. /**
  994. * The base implementation of `_.mean` and `_.meanBy` without support for
  995. * iteratee shorthands.
  996. *
  997. * @private
  998. * @param {Array} array The array to iterate over.
  999. * @param {Function} iteratee The function invoked per iteration.
  1000. * @returns {number} Returns the mean.
  1001. */
  1002. function baseMean(array, iteratee) {
  1003. var length = array == null ? 0 : array.length;
  1004. return length ? baseSum(array, iteratee) / length : NAN;
  1005. }
  1006. /**
  1007. * The base implementation of `_.property` without support for deep paths.
  1008. *
  1009. * @private
  1010. * @param {string} key The key of the property to get.
  1011. * @returns {Function} Returns the new accessor function.
  1012. */
  1013. function baseProperty(key) {
  1014. return function(object) {
  1015. return object == null ? undefined : object[key];
  1016. };
  1017. }
  1018. /**
  1019. * The base implementation of `_.propertyOf` without support for deep paths.
  1020. *
  1021. * @private
  1022. * @param {Object} object The object to query.
  1023. * @returns {Function} Returns the new accessor function.
  1024. */
  1025. function basePropertyOf(object) {
  1026. return function(key) {
  1027. return object == null ? undefined : object[key];
  1028. };
  1029. }
  1030. /**
  1031. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  1032. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  1033. *
  1034. * @private
  1035. * @param {Array|Object} collection The collection to iterate over.
  1036. * @param {Function} iteratee The function invoked per iteration.
  1037. * @param {*} accumulator The initial value.
  1038. * @param {boolean} initAccum Specify using the first or last element of
  1039. * `collection` as the initial value.
  1040. * @param {Function} eachFunc The function to iterate over `collection`.
  1041. * @returns {*} Returns the accumulated value.
  1042. */
  1043. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  1044. eachFunc(collection, function(value, index, collection) {
  1045. accumulator = initAccum
  1046. ? ((initAccum = false), value)
  1047. : iteratee(accumulator, value, index, collection);
  1048. });
  1049. return accumulator;
  1050. }
  1051. /**
  1052. * The base implementation of `_.sortBy` which uses `comparer` to define the
  1053. * sort order of `array` and replaces criteria objects with their corresponding
  1054. * values.
  1055. *
  1056. * @private
  1057. * @param {Array} array The array to sort.
  1058. * @param {Function} comparer The function to define sort order.
  1059. * @returns {Array} Returns `array`.
  1060. */
  1061. function baseSortBy(array, comparer) {
  1062. var length = array.length;
  1063. array.sort(comparer);
  1064. while (length--) {
  1065. array[length] = array[length].value;
  1066. }
  1067. return array;
  1068. }
  1069. /**
  1070. * The base implementation of `_.sum` and `_.sumBy` without support for
  1071. * iteratee shorthands.
  1072. *
  1073. * @private
  1074. * @param {Array} array The array to iterate over.
  1075. * @param {Function} iteratee The function invoked per iteration.
  1076. * @returns {number} Returns the sum.
  1077. */
  1078. function baseSum(array, iteratee) {
  1079. var result,
  1080. index = -1,
  1081. length = array.length;
  1082. while (++index < length) {
  1083. var current = iteratee(array[index]);
  1084. if (current !== undefined) {
  1085. result = result === undefined ? current : result + current;
  1086. }
  1087. }
  1088. return result;
  1089. }
  1090. /**
  1091. * The base implementation of `_.times` without support for iteratee shorthands
  1092. * or max array length checks.
  1093. *
  1094. * @private
  1095. * @param {number} n The number of times to invoke `iteratee`.
  1096. * @param {Function} iteratee The function invoked per iteration.
  1097. * @returns {Array} Returns the array of results.
  1098. */
  1099. function baseTimes(n, iteratee) {
  1100. var index = -1,
  1101. result = Array(n);
  1102. while (++index < n) {
  1103. result[index] = iteratee(index);
  1104. }
  1105. return result;
  1106. }
  1107. /**
  1108. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  1109. * of key-value pairs for `object` corresponding to the property names of `props`.
  1110. *
  1111. * @private
  1112. * @param {Object} object The object to query.
  1113. * @param {Array} props The property names to get values for.
  1114. * @returns {Object} Returns the key-value pairs.
  1115. */
  1116. function baseToPairs(object, props) {
  1117. return arrayMap(props, function(key) {
  1118. return [key, object[key]];
  1119. });
  1120. }
  1121. /**
  1122. * The base implementation of `_.unary` without support for storing metadata.
  1123. *
  1124. * @private
  1125. * @param {Function} func The function to cap arguments for.
  1126. * @returns {Function} Returns the new capped function.
  1127. */
  1128. function baseUnary(func) {
  1129. return function(value) {
  1130. return func(value);
  1131. };
  1132. }
  1133. /**
  1134. * The base implementation of `_.values` and `_.valuesIn` which creates an
  1135. * array of `object` property values corresponding to the property names
  1136. * of `props`.
  1137. *
  1138. * @private
  1139. * @param {Object} object The object to query.
  1140. * @param {Array} props The property names to get values for.
  1141. * @returns {Object} Returns the array of property values.
  1142. */
  1143. function baseValues(object, props) {
  1144. return arrayMap(props, function(key) {
  1145. return object[key];
  1146. });
  1147. }
  1148. /**
  1149. * Checks if a `cache` value for `key` exists.
  1150. *
  1151. * @private
  1152. * @param {Object} cache The cache to query.
  1153. * @param {string} key The key of the entry to check.
  1154. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1155. */
  1156. function cacheHas(cache, key) {
  1157. return cache.has(key);
  1158. }
  1159. /**
  1160. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  1161. * that is not found in the character symbols.
  1162. *
  1163. * @private
  1164. * @param {Array} strSymbols The string symbols to inspect.
  1165. * @param {Array} chrSymbols The character symbols to find.
  1166. * @returns {number} Returns the index of the first unmatched string symbol.
  1167. */
  1168. function charsStartIndex(strSymbols, chrSymbols) {
  1169. var index = -1,
  1170. length = strSymbols.length;
  1171. while (
  1172. ++index < length &&
  1173. baseIndexOf(chrSymbols, strSymbols[index], 0) > -1
  1174. ) { }
  1175. return index;
  1176. }
  1177. /**
  1178. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  1179. * that is not found in the character symbols.
  1180. *
  1181. * @private
  1182. * @param {Array} strSymbols The string symbols to inspect.
  1183. * @param {Array} chrSymbols The character symbols to find.
  1184. * @returns {number} Returns the index of the last unmatched string symbol.
  1185. */
  1186. function charsEndIndex(strSymbols, chrSymbols) {
  1187. var index = strSymbols.length;
  1188. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) { }
  1189. return index;
  1190. }
  1191. /**
  1192. * Gets the number of `placeholder` occurrences in `array`.
  1193. *
  1194. * @private
  1195. * @param {Array} array The array to inspect.
  1196. * @param {*} placeholder The placeholder to search for.
  1197. * @returns {number} Returns the placeholder count.
  1198. */
  1199. function countHolders(array, placeholder) {
  1200. var length = array.length,
  1201. result = 0;
  1202. while (length--) {
  1203. if (array[length] === placeholder) {
  1204. ++result;
  1205. }
  1206. }
  1207. return result;
  1208. }
  1209. /**
  1210. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  1211. * letters to basic Latin letters.
  1212. *
  1213. * @private
  1214. * @param {string} letter The matched letter to deburr.
  1215. * @returns {string} Returns the deburred letter.
  1216. */
  1217. var deburrLetter = basePropertyOf(deburredLetters);
  1218. /**
  1219. * Used by `_.escape` to convert characters to HTML entities.
  1220. *
  1221. * @private
  1222. * @param {string} chr The matched character to escape.
  1223. * @returns {string} Returns the escaped character.
  1224. */
  1225. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1226. /**
  1227. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1228. *
  1229. * @private
  1230. * @param {string} chr The matched character to escape.
  1231. * @returns {string} Returns the escaped character.
  1232. */
  1233. function escapeStringChar(chr) {
  1234. return '\\' + stringEscapes[chr];
  1235. }
  1236. /**
  1237. * Gets the value at `key` of `object`.
  1238. *
  1239. * @private
  1240. * @param {Object} [object] The object to query.
  1241. * @param {string} key The key of the property to get.
  1242. * @returns {*} Returns the property value.
  1243. */
  1244. function getValue(object, key) {
  1245. return object == null ? undefined : object[key];
  1246. }
  1247. /**
  1248. * Checks if `string` contains Unicode symbols.
  1249. *
  1250. * @private
  1251. * @param {string} string The string to inspect.
  1252. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1253. */
  1254. function hasUnicode(string) {
  1255. return reHasUnicode.test(string);
  1256. }
  1257. /**
  1258. * Checks if `string` contains a word composed of Unicode symbols.
  1259. *
  1260. * @private
  1261. * @param {string} string The string to inspect.
  1262. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1263. */
  1264. function hasUnicodeWord(string) {
  1265. return reHasUnicodeWord.test(string);
  1266. }
  1267. /**
  1268. * Converts `iterator` to an array.
  1269. *
  1270. * @private
  1271. * @param {Object} iterator The iterator to convert.
  1272. * @returns {Array} Returns the converted array.
  1273. */
  1274. function iteratorToArray(iterator) {
  1275. var data,
  1276. result = [];
  1277. while (!(data = iterator.next()).done) {
  1278. result.push(data.value);
  1279. }
  1280. return result;
  1281. }
  1282. /**
  1283. * Converts `map` to its key-value pairs.
  1284. *
  1285. * @private
  1286. * @param {Object} map The map to convert.
  1287. * @returns {Array} Returns the key-value pairs.
  1288. */
  1289. function mapToArray(map) {
  1290. var index = -1,
  1291. result = Array(map.size);
  1292. map.forEach(function(value, key) {
  1293. result[++index] = [key, value];
  1294. });
  1295. return result;
  1296. }
  1297. /**
  1298. * Creates a unary function that invokes `func` with its argument transformed.
  1299. *
  1300. * @private
  1301. * @param {Function} func The function to wrap.
  1302. * @param {Function} transform The argument transform.
  1303. * @returns {Function} Returns the new function.
  1304. */
  1305. function overArg(func, transform) {
  1306. return function(arg) {
  1307. return func(transform(arg));
  1308. };
  1309. }
  1310. /**
  1311. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1312. * and returns an array of their indexes.
  1313. *
  1314. * @private
  1315. * @param {Array} array The array to modify.
  1316. * @param {*} placeholder The placeholder to replace.
  1317. * @returns {Array} Returns the new array of placeholder indexes.
  1318. */
  1319. function replaceHolders(array, placeholder) {
  1320. var index = -1,
  1321. length = array.length,
  1322. resIndex = 0,
  1323. result = [];
  1324. while (++index < length) {
  1325. var value = array[index];
  1326. if (value === placeholder || value === PLACEHOLDER) {
  1327. array[index] = PLACEHOLDER;
  1328. result[resIndex++] = index;
  1329. }
  1330. }
  1331. return result;
  1332. }
  1333. /**
  1334. * Gets the value at `key`, unless `key` is "__proto__".
  1335. *
  1336. * @private
  1337. * @param {Object} object The object to query.
  1338. * @param {string} key The key of the property to get.
  1339. * @returns {*} Returns the property value.
  1340. */
  1341. function safeGet(object, key) {
  1342. return key == '__proto__' ? undefined : object[key];
  1343. }
  1344. /**
  1345. * Converts `set` to an array of its values.
  1346. *
  1347. * @private
  1348. * @param {Object} set The set to convert.
  1349. * @returns {Array} Returns the values.
  1350. */
  1351. function setToArray(set) {
  1352. var index = -1,
  1353. result = Array(set.size);
  1354. set.forEach(function(value) {
  1355. result[++index] = value;
  1356. });
  1357. return result;
  1358. }
  1359. /**
  1360. * Converts `set` to its value-value pairs.
  1361. *
  1362. * @private
  1363. * @param {Object} set The set to convert.
  1364. * @returns {Array} Returns the value-value pairs.
  1365. */
  1366. function setToPairs(set) {
  1367. var index = -1,
  1368. result = Array(set.size);
  1369. set.forEach(function(value) {
  1370. result[++index] = [value, value];
  1371. });
  1372. return result;
  1373. }
  1374. /**
  1375. * A specialized version of `_.indexOf` which performs strict equality
  1376. * comparisons of values, i.e. `===`.
  1377. *
  1378. * @private
  1379. * @param {Array} array The array to inspect.
  1380. * @param {*} value The value to search for.
  1381. * @param {number} fromIndex The index to search from.
  1382. * @returns {number} Returns the index of the matched value, else `-1`.
  1383. */
  1384. function strictIndexOf(array, value, fromIndex) {
  1385. var index = fromIndex - 1,
  1386. length = array.length;
  1387. while (++index < length) {
  1388. if (array[index] === value) {
  1389. return index;
  1390. }
  1391. }
  1392. return -1;
  1393. }
  1394. /**
  1395. * A specialized version of `_.lastIndexOf` which performs strict equality
  1396. * comparisons of values, i.e. `===`.
  1397. *
  1398. * @private
  1399. * @param {Array} array The array to inspect.
  1400. * @param {*} value The value to search for.
  1401. * @param {number} fromIndex The index to search from.
  1402. * @returns {number} Returns the index of the matched value, else `-1`.
  1403. */
  1404. function strictLastIndexOf(array, value, fromIndex) {
  1405. var index = fromIndex + 1;
  1406. while (index--) {
  1407. if (array[index] === value) {
  1408. return index;
  1409. }
  1410. }
  1411. return index;
  1412. }
  1413. /**
  1414. * Gets the number of symbols in `string`.
  1415. *
  1416. * @private
  1417. * @param {string} string The string to inspect.
  1418. * @returns {number} Returns the string size.
  1419. */
  1420. function stringSize(string) {
  1421. return hasUnicode(string) ? unicodeSize(string) : asciiSize(string);
  1422. }
  1423. /**
  1424. * Converts `string` to an array.
  1425. *
  1426. * @private
  1427. * @param {string} string The string to convert.
  1428. * @returns {Array} Returns the converted array.
  1429. */
  1430. function stringToArray(string) {
  1431. return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string);
  1432. }
  1433. /**
  1434. * Used by `_.unescape` to convert HTML entities to characters.
  1435. *
  1436. * @private
  1437. * @param {string} chr The matched character to unescape.
  1438. * @returns {string} Returns the unescaped character.
  1439. */
  1440. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1441. /**
  1442. * Gets the size of a Unicode `string`.
  1443. *
  1444. * @private
  1445. * @param {string} string The string inspect.
  1446. * @returns {number} Returns the string size.
  1447. */
  1448. function unicodeSize(string) {
  1449. var result = (reUnicode.lastIndex = 0);
  1450. while (reUnicode.test(string)) {
  1451. ++result;
  1452. }
  1453. return result;
  1454. }
  1455. /**
  1456. * Converts a Unicode `string` to an array.
  1457. *
  1458. * @private
  1459. * @param {string} string The string to convert.
  1460. * @returns {Array} Returns the converted array.
  1461. */
  1462. function unicodeToArray(string) {
  1463. return string.match(reUnicode) || [];
  1464. }
  1465. /**
  1466. * Splits a Unicode `string` into an array of its words.
  1467. *
  1468. * @private
  1469. * @param {string} The string to inspect.
  1470. * @returns {Array} Returns the words of `string`.
  1471. */
  1472. function unicodeWords(string) {
  1473. return string.match(reUnicodeWord) || [];
  1474. }
  1475. /* --------------------------------------------------------------------------*/
  1476. /**
  1477. * Create a new pristine `lodash` function using the `context` object.
  1478. *
  1479. * @static
  1480. * @memberOf _
  1481. * @since 1.1.0
  1482. * @category Util
  1483. * @param {Object} [context=root] The context object.
  1484. * @returns {Function} Returns a new `lodash` function.
  1485. * @example
  1486. *
  1487. * _.mixin({ 'foo': _.constant('foo') });
  1488. *
  1489. * var lodash = _.runInContext();
  1490. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1491. *
  1492. * _.isFunction(_.foo);
  1493. * // => true
  1494. * _.isFunction(_.bar);
  1495. * // => false
  1496. *
  1497. * lodash.isFunction(lodash.foo);
  1498. * // => false
  1499. * lodash.isFunction(lodash.bar);
  1500. * // => true
  1501. *
  1502. * // Create a suped-up `defer` in Node.js.
  1503. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1504. */
  1505. var runInContext = function runInContext(context) {
  1506. context =
  1507. context == null
  1508. ? root
  1509. : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1510. /** Built-in constructor references. */
  1511. var Array = context.Array,
  1512. Date = context.Date,
  1513. Error = context.Error,
  1514. Function = context.Function,
  1515. Math = context.Math,
  1516. Object = context.Object,
  1517. RegExp = context.RegExp,
  1518. String = context.String,
  1519. TypeError = context.TypeError;
  1520. /** Used for built-in method references. */
  1521. var arrayProto = Array.prototype,
  1522. funcProto = Function.prototype,
  1523. objectProto = Object.prototype;
  1524. /** Used to detect overreaching core-js shims. */
  1525. var coreJsData = context['__core-js_shared__'];
  1526. /** Used to resolve the decompiled source of functions. */
  1527. var funcToString = funcProto.toString;
  1528. /** Used to check objects for own properties. */
  1529. var hasOwnProperty = objectProto.hasOwnProperty;
  1530. /** Used to generate unique IDs. */
  1531. var idCounter = 0;
  1532. /** Used to detect methods masquerading as native. */
  1533. var maskSrcKey = (function() {
  1534. var uid = /[^.]+$/.exec(
  1535. (coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO) || ''
  1536. );
  1537. return uid ? 'Symbol(src)_1.' + uid : '';
  1538. })();
  1539. /**
  1540. * Used to resolve the
  1541. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1542. * of values.
  1543. */
  1544. var nativeObjectToString = objectProto.toString;
  1545. /** Used to infer the `Object` constructor. */
  1546. var objectCtorString = funcToString.call(Object);
  1547. /** Used to restore the original `_` reference in `_.noConflict`. */
  1548. var oldDash = root._;
  1549. /** Used to detect if a method is native. */
  1550. var reIsNative = RegExp(
  1551. '^' +
  1552. funcToString
  1553. .call(hasOwnProperty)
  1554. .replace(reRegExpChar, '\\$&')
  1555. .replace(
  1556. /hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,
  1557. '$1.*?'
  1558. ) +
  1559. '$'
  1560. );
  1561. /** Built-in value references. */
  1562. var Buffer = moduleExports ? context.Buffer : undefined,
  1563. Symbol = context.Symbol,
  1564. Uint8Array = context.Uint8Array,
  1565. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1566. getPrototype = overArg(Object.getPrototypeOf, Object),
  1567. objectCreate = Object.create,
  1568. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1569. splice = arrayProto.splice,
  1570. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1571. symIterator = Symbol ? Symbol.iterator : undefined,
  1572. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1573. var defineProperty = (function() {
  1574. try {
  1575. var func = getNative(Object, 'defineProperty');
  1576. func({}, '', {});
  1577. return func;
  1578. } catch (e) { }
  1579. })();
  1580. /** Mocked built-ins. */
  1581. var ctxClearTimeout =
  1582. context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1583. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1584. ctxSetTimeout =
  1585. context.setTimeout !== root.setTimeout && context.setTimeout;
  1586. /* Built-in method references for those with the same name as other `lodash` methods. */
  1587. var nativeCeil = Math.ceil,
  1588. nativeFloor = Math.floor,
  1589. nativeGetSymbols = Object.getOwnPropertySymbols,
  1590. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1591. nativeIsFinite = context.isFinite,
  1592. nativeJoin = arrayProto.join,
  1593. nativeKeys = overArg(Object.keys, Object),
  1594. nativeMax = Math.max,
  1595. nativeMin = Math.min,
  1596. nativeNow = Date.now,
  1597. nativeParseInt = context.parseInt,
  1598. nativeRandom = Math.random,
  1599. nativeReverse = arrayProto.reverse;
  1600. /* Built-in method references that are verified to be native. */
  1601. var DataView = getNative(context, 'DataView'),
  1602. Map = getNative(context, 'Map'),
  1603. Promise = getNative(context, 'Promise'),
  1604. Set = getNative(context, 'Set'),
  1605. WeakMap = getNative(context, 'WeakMap'),
  1606. nativeCreate = getNative(Object, 'create');
  1607. /** Used to store function metadata. */
  1608. var metaMap = WeakMap && new WeakMap();
  1609. /** Used to lookup unminified function names. */
  1610. var realNames = {};
  1611. /** Used to detect maps, sets, and weakmaps. */
  1612. var dataViewCtorString = toSource(DataView),
  1613. mapCtorString = toSource(Map),
  1614. promiseCtorString = toSource(Promise),
  1615. setCtorString = toSource(Set),
  1616. weakMapCtorString = toSource(WeakMap);
  1617. /** Used to convert symbols to primitives and strings. */
  1618. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1619. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1620. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1621. /* ------------------------------------------------------------------------*/
  1622. /**
  1623. * Creates a `lodash` object which wraps `value` to enable implicit method
  1624. * chain sequences. Methods that operate on and return arrays, collections,
  1625. * and functions can be chained together. Methods that retrieve a single value
  1626. * or may return a primitive value will automatically end the chain sequence
  1627. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1628. * with `_#value`.
  1629. *
  1630. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1631. * enabled using `_.chain`.
  1632. *
  1633. * The execution of chained methods is lazy, that is, it's deferred until
  1634. * `_#value` is implicitly or explicitly called.
  1635. *
  1636. * Lazy evaluation allows several methods to support shortcut fusion.
  1637. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1638. * the creation of intermediate arrays and can greatly reduce the number of
  1639. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1640. * fusion if the section is applied to an array and iteratees accept only
  1641. * one argument. The heuristic for whether a section qualifies for shortcut
  1642. * fusion is subject to change.
  1643. *
  1644. * Chaining is supported in custom builds as long as the `_#value` method is
  1645. * directly or indirectly included in the build.
  1646. *
  1647. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1648. *
  1649. * The wrapper `Array` methods are:
  1650. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1651. *
  1652. * The wrapper `String` methods are:
  1653. * `replace` and `split`
  1654. *
  1655. * The wrapper methods that support shortcut fusion are:
  1656. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1657. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1658. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1659. *
  1660. * The chainable wrapper methods are:
  1661. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1662. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1663. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1664. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1665. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1666. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1667. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1668. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1669. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1670. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1671. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1672. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1673. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1674. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1675. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1676. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1677. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1678. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1679. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1680. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1681. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1682. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1683. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1684. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1685. *
  1686. * The wrapper methods that are **not** chainable by default are:
  1687. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1688. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1689. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1690. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1691. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1692. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1693. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1694. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1695. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1696. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1697. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1698. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1699. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1700. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1701. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1702. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1703. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1704. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1705. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1706. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1707. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1708. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1709. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1710. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1711. * `upperFirst`, `value`, and `words`
  1712. *
  1713. * @name _
  1714. * @constructor
  1715. * @category Seq
  1716. * @param {*} value The value to wrap in a `lodash` instance.
  1717. * @returns {Object} Returns the new `lodash` wrapper instance.
  1718. * @example
  1719. *
  1720. * function square(n) {
  1721. * return n * n;
  1722. * }
  1723. *
  1724. * var wrapped = _([1, 2, 3]);
  1725. *
  1726. * // Returns an unwrapped value.
  1727. * wrapped.reduce(_.add);
  1728. * // => 6
  1729. *
  1730. * // Returns a wrapped value.
  1731. * var squares = wrapped.map(square);
  1732. *
  1733. * _.isArray(squares);
  1734. * // => false
  1735. *
  1736. * _.isArray(squares.value());
  1737. * // => true
  1738. */
  1739. function lodash(value) {
  1740. if (
  1741. isObjectLike(value) &&
  1742. !isArray(value) &&
  1743. !(value instanceof LazyWrapper)
  1744. ) {
  1745. if (value instanceof LodashWrapper) {
  1746. return value;
  1747. }
  1748. if (hasOwnProperty.call(value, '__wrapped__')) {
  1749. return wrapperClone(value);
  1750. }
  1751. }
  1752. return new LodashWrapper(value);
  1753. }
  1754. /**
  1755. * The base implementation of `_.create` without support for assigning
  1756. * properties to the created object.
  1757. *
  1758. * @private
  1759. * @param {Object} proto The object to inherit from.
  1760. * @returns {Object} Returns the new object.
  1761. */
  1762. var baseCreate = (function() {
  1763. function object() { }
  1764. return function(proto) {
  1765. if (!isObject(proto)) {
  1766. return {};
  1767. }
  1768. if (objectCreate) {
  1769. return objectCreate(proto);
  1770. }
  1771. object.prototype = proto;
  1772. var result = new object();
  1773. object.prototype = undefined;
  1774. return result;
  1775. };
  1776. })();
  1777. /**
  1778. * The function whose prototype chain sequence wrappers inherit from.
  1779. *
  1780. * @private
  1781. */
  1782. function baseLodash() {
  1783. // No operation performed.
  1784. }
  1785. /**
  1786. * The base constructor for creating `lodash` wrapper objects.
  1787. *
  1788. * @private
  1789. * @param {*} value The value to wrap.
  1790. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1791. */
  1792. function LodashWrapper(value, chainAll) {
  1793. this.__wrapped__ = value;
  1794. this.__actions__ = [];
  1795. this.__chain__ = !!chainAll;
  1796. this.__index__ = 0;
  1797. this.__values__ = undefined;
  1798. }
  1799. /**
  1800. * By default, the template delimiters used by lodash are like those in
  1801. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1802. * following template settings to use alternative delimiters.
  1803. *
  1804. * @static
  1805. * @memberOf _
  1806. * @type {Object}
  1807. */
  1808. lodash.templateSettings = {
  1809. /**
  1810. * Used to detect `data` property values to be HTML-escaped.
  1811. *
  1812. * @memberOf _.templateSettings
  1813. * @type {RegExp}
  1814. */
  1815. escape: reEscape,
  1816. /**
  1817. * Used to detect code to be evaluated.
  1818. *
  1819. * @memberOf _.templateSettings
  1820. * @type {RegExp}
  1821. */
  1822. evaluate: reEvaluate,
  1823. /**
  1824. * Used to detect `data` property values to inject.
  1825. *
  1826. * @memberOf _.templateSettings
  1827. * @type {RegExp}
  1828. */
  1829. interpolate: reInterpolate,
  1830. /**
  1831. * Used to reference the data object in the template text.
  1832. *
  1833. * @memberOf _.templateSettings
  1834. * @type {string}
  1835. */
  1836. variable: '',
  1837. /**
  1838. * Used to import variables into the compiled template.
  1839. *
  1840. * @memberOf _.templateSettings
  1841. * @type {Object}
  1842. */
  1843. imports: {
  1844. /**
  1845. * A reference to the `lodash` function.
  1846. *
  1847. * @memberOf _.templateSettings.imports
  1848. * @type {Function}
  1849. */
  1850. _: lodash
  1851. }
  1852. };
  1853. // Ensure wrappers are instances of `baseLodash`.
  1854. lodash.prototype = baseLodash.prototype;
  1855. lodash.prototype.constructor = lodash;
  1856. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1857. LodashWrapper.prototype.constructor = LodashWrapper;
  1858. /* ------------------------------------------------------------------------*/
  1859. /**
  1860. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1861. *
  1862. * @private
  1863. * @constructor
  1864. * @param {*} value The value to wrap.
  1865. */
  1866. function LazyWrapper(value) {
  1867. this.__wrapped__ = value;
  1868. this.__actions__ = [];
  1869. this.__dir__ = 1;
  1870. this.__filtered__ = false;
  1871. this.__iteratees__ = [];
  1872. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1873. this.__views__ = [];
  1874. }
  1875. /**
  1876. * Creates a clone of the lazy wrapper object.
  1877. *
  1878. * @private
  1879. * @name clone
  1880. * @memberOf LazyWrapper
  1881. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1882. */
  1883. function lazyClone() {
  1884. var result = new LazyWrapper(this.__wrapped__);
  1885. result.__actions__ = copyArray(this.__actions__);
  1886. result.__dir__ = this.__dir__;
  1887. result.__filtered__ = this.__filtered__;
  1888. result.__iteratees__ = copyArray(this.__iteratees__);
  1889. result.__takeCount__ = this.__takeCount__;
  1890. result.__views__ = copyArray(this.__views__);
  1891. return result;
  1892. }
  1893. /**
  1894. * Reverses the direction of lazy iteration.
  1895. *
  1896. * @private
  1897. * @name reverse
  1898. * @memberOf LazyWrapper
  1899. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1900. */
  1901. function lazyReverse() {
  1902. if (this.__filtered__) {
  1903. var result = new LazyWrapper(this);
  1904. result.__dir__ = -1;
  1905. result.__filtered__ = true;
  1906. } else {
  1907. result = this.clone();
  1908. result.__dir__ *= -1;
  1909. }
  1910. return result;
  1911. }
  1912. /**
  1913. * Extracts the unwrapped value from its lazy wrapper.
  1914. *
  1915. * @private
  1916. * @name value
  1917. * @memberOf LazyWrapper
  1918. * @returns {*} Returns the unwrapped value.
  1919. */
  1920. function lazyValue() {
  1921. var array = this.__wrapped__.value(),
  1922. dir = this.__dir__,
  1923. isArr = isArray(array),
  1924. isRight = dir < 0,
  1925. arrLength = isArr ? array.length : 0,
  1926. view = getView(0, arrLength, this.__views__),
  1927. start = view.start,
  1928. end = view.end,
  1929. length = end - start,
  1930. index = isRight ? end : start - 1,
  1931. iteratees = this.__iteratees__,
  1932. iterLength = iteratees.length,
  1933. resIndex = 0,
  1934. takeCount = nativeMin(length, this.__takeCount__);
  1935. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1936. return baseWrapperValue(array, this.__actions__);
  1937. }
  1938. var result = [];
  1939. outer: while (length-- && resIndex < takeCount) {
  1940. index += dir;
  1941. var iterIndex = -1,
  1942. value = array[index];
  1943. while (++iterIndex < iterLength) {
  1944. var data = iteratees[iterIndex],
  1945. iteratee = data.iteratee,
  1946. type = data.type,
  1947. computed = iteratee(value);
  1948. if (type == LAZY_MAP_FLAG) {
  1949. value = computed;
  1950. } else if (!computed) {
  1951. if (type == LAZY_FILTER_FLAG) {
  1952. continue outer;
  1953. } else {
  1954. break outer;
  1955. }
  1956. }
  1957. }
  1958. result[resIndex++] = value;
  1959. }
  1960. return result;
  1961. }
  1962. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1963. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1964. LazyWrapper.prototype.constructor = LazyWrapper;
  1965. /* ------------------------------------------------------------------------*/
  1966. /**
  1967. * Creates a hash object.
  1968. *
  1969. * @private
  1970. * @constructor
  1971. * @param {Array} [entries] The key-value pairs to cache.
  1972. */
  1973. function Hash(entries) {
  1974. var index = -1,
  1975. length = entries == null ? 0 : entries.length;
  1976. this.clear();
  1977. while (++index < length) {
  1978. var entry = entries[index];
  1979. this.set(entry[0], entry[1]);
  1980. }
  1981. }
  1982. /**
  1983. * Removes all key-value entries from the hash.
  1984. *
  1985. * @private
  1986. * @name clear
  1987. * @memberOf Hash
  1988. */
  1989. function hashClear() {
  1990. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1991. this.size = 0;
  1992. }
  1993. /**
  1994. * Removes `key` and its value from the hash.
  1995. *
  1996. * @private
  1997. * @name delete
  1998. * @memberOf Hash
  1999. * @param {Object} hash The hash to modify.
  2000. * @param {string} key The key of the value to remove.
  2001. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2002. */
  2003. function hashDelete(key) {
  2004. var result = this.has(key) && delete this.__data__[key];
  2005. this.size -= result ? 1 : 0;
  2006. return result;
  2007. }
  2008. /**
  2009. * Gets the hash value for `key`.
  2010. *
  2011. * @private
  2012. * @name get
  2013. * @memberOf Hash
  2014. * @param {string} key The key of the value to get.
  2015. * @returns {*} Returns the entry value.
  2016. */
  2017. function hashGet(key) {
  2018. var data = this.__data__;
  2019. if (nativeCreate) {
  2020. var result = data[key];
  2021. return result === HASH_UNDEFINED ? undefined : result;
  2022. }
  2023. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  2024. }
  2025. /**
  2026. * Checks if a hash value for `key` exists.
  2027. *
  2028. * @private
  2029. * @name has
  2030. * @memberOf Hash
  2031. * @param {string} key The key of the entry to check.
  2032. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2033. */
  2034. function hashHas(key) {
  2035. var data = this.__data__;
  2036. return nativeCreate
  2037. ? data[key] !== undefined
  2038. : hasOwnProperty.call(data, key);
  2039. }
  2040. /**
  2041. * Sets the hash `key` to `value`.
  2042. *
  2043. * @private
  2044. * @name set
  2045. * @memberOf Hash
  2046. * @param {string} key The key of the value to set.
  2047. * @param {*} value The value to set.
  2048. * @returns {Object} Returns the hash instance.
  2049. */
  2050. function hashSet(key, value) {
  2051. var data = this.__data__;
  2052. this.size += this.has(key) ? 0 : 1;
  2053. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  2054. return this;
  2055. }
  2056. // Add methods to `Hash`.
  2057. Hash.prototype.clear = hashClear;
  2058. Hash.prototype['delete'] = hashDelete;
  2059. Hash.prototype.get = hashGet;
  2060. Hash.prototype.has = hashHas;
  2061. Hash.prototype.set = hashSet;
  2062. /* ------------------------------------------------------------------------*/
  2063. /**
  2064. * Creates an list cache object.
  2065. *
  2066. * @private
  2067. * @constructor
  2068. * @param {Array} [entries] The key-value pairs to cache.
  2069. */
  2070. function ListCache(entries) {
  2071. var index = -1,
  2072. length = entries == null ? 0 : entries.length;
  2073. this.clear();
  2074. while (++index < length) {
  2075. var entry = entries[index];
  2076. this.set(entry[0], entry[1]);
  2077. }
  2078. }
  2079. /**
  2080. * Removes all key-value entries from the list cache.
  2081. *
  2082. * @private
  2083. * @name clear
  2084. * @memberOf ListCache
  2085. */
  2086. function listCacheClear() {
  2087. this.__data__ = [];
  2088. this.size = 0;
  2089. }
  2090. /**
  2091. * Removes `key` and its value from the list cache.
  2092. *
  2093. * @private
  2094. * @name delete
  2095. * @memberOf ListCache
  2096. * @param {string} key The key of the value to remove.
  2097. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2098. */
  2099. function listCacheDelete(key) {
  2100. var data = this.__data__,
  2101. index = assocIndexOf(data, key);
  2102. if (index < 0) {
  2103. return false;
  2104. }
  2105. var lastIndex = data.length - 1;
  2106. if (index == lastIndex) {
  2107. data.pop();
  2108. } else {
  2109. splice.call(data, index, 1);
  2110. }
  2111. --this.size;
  2112. return true;
  2113. }
  2114. /**
  2115. * Gets the list cache value for `key`.
  2116. *
  2117. * @private
  2118. * @name get
  2119. * @memberOf ListCache
  2120. * @param {string} key The key of the value to get.
  2121. * @returns {*} Returns the entry value.
  2122. */
  2123. function listCacheGet(key) {
  2124. var data = this.__data__,
  2125. index = assocIndexOf(data, key);
  2126. return index < 0 ? undefined : data[index][1];
  2127. }
  2128. /**
  2129. * Checks if a list cache value for `key` exists.
  2130. *
  2131. * @private
  2132. * @name has
  2133. * @memberOf ListCache
  2134. * @param {string} key The key of the entry to check.
  2135. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2136. */
  2137. function listCacheHas(key) {
  2138. return assocIndexOf(this.__data__, key) > -1;
  2139. }
  2140. /**
  2141. * Sets the list cache `key` to `value`.
  2142. *
  2143. * @private
  2144. * @name set
  2145. * @memberOf ListCache
  2146. * @param {string} key The key of the value to set.
  2147. * @param {*} value The value to set.
  2148. * @returns {Object} Returns the list cache instance.
  2149. */
  2150. function listCacheSet(key, value) {
  2151. var data = this.__data__,
  2152. index = assocIndexOf(data, key);
  2153. if (index < 0) {
  2154. ++this.size;
  2155. data.push([key, value]);
  2156. } else {
  2157. data[index][1] = value;
  2158. }
  2159. return this;
  2160. }
  2161. // Add methods to `ListCache`.
  2162. ListCache.prototype.clear = listCacheClear;
  2163. ListCache.prototype['delete'] = listCacheDelete;
  2164. ListCache.prototype.get = listCacheGet;
  2165. ListCache.prototype.has = listCacheHas;
  2166. ListCache.prototype.set = listCacheSet;
  2167. /* ------------------------------------------------------------------------*/
  2168. /**
  2169. * Creates a map cache object to store key-value pairs.
  2170. *
  2171. * @private
  2172. * @constructor
  2173. * @param {Array} [entries] The key-value pairs to cache.
  2174. */
  2175. function MapCache(entries) {
  2176. var index = -1,
  2177. length = entries == null ? 0 : entries.length;
  2178. this.clear();
  2179. while (++index < length) {
  2180. var entry = entries[index];
  2181. this.set(entry[0], entry[1]);
  2182. }
  2183. }
  2184. /**
  2185. * Removes all key-value entries from the map.
  2186. *
  2187. * @private
  2188. * @name clear
  2189. * @memberOf MapCache
  2190. */
  2191. function mapCacheClear() {
  2192. this.size = 0;
  2193. this.__data__ = {
  2194. hash: new Hash(),
  2195. map: new (Map || ListCache)(),
  2196. string: new Hash()
  2197. };
  2198. }
  2199. /**
  2200. * Removes `key` and its value from the map.
  2201. *
  2202. * @private
  2203. * @name delete
  2204. * @memberOf MapCache
  2205. * @param {string} key The key of the value to remove.
  2206. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2207. */
  2208. function mapCacheDelete(key) {
  2209. var result = getMapData(this, key)['delete'](key);
  2210. this.size -= result ? 1 : 0;
  2211. return result;
  2212. }
  2213. /**
  2214. * Gets the map value for `key`.
  2215. *
  2216. * @private
  2217. * @name get
  2218. * @memberOf MapCache
  2219. * @param {string} key The key of the value to get.
  2220. * @returns {*} Returns the entry value.
  2221. */
  2222. function mapCacheGet(key) {
  2223. return getMapData(this, key).get(key);
  2224. }
  2225. /**
  2226. * Checks if a map value for `key` exists.
  2227. *
  2228. * @private
  2229. * @name has
  2230. * @memberOf MapCache
  2231. * @param {string} key The key of the entry to check.
  2232. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2233. */
  2234. function mapCacheHas(key) {
  2235. return getMapData(this, key).has(key);
  2236. }
  2237. /**
  2238. * Sets the map `key` to `value`.
  2239. *
  2240. * @private
  2241. * @name set
  2242. * @memberOf MapCache
  2243. * @param {string} key The key of the value to set.
  2244. * @param {*} value The value to set.
  2245. * @returns {Object} Returns the map cache instance.
  2246. */
  2247. function mapCacheSet(key, value) {
  2248. var data = getMapData(this, key),
  2249. size = data.size;
  2250. data.set(key, value);
  2251. this.size += data.size == size ? 0 : 1;
  2252. return this;
  2253. }
  2254. // Add methods to `MapCache`.
  2255. MapCache.prototype.clear = mapCacheClear;
  2256. MapCache.prototype['delete'] = mapCacheDelete;
  2257. MapCache.prototype.get = mapCacheGet;
  2258. MapCache.prototype.has = mapCacheHas;
  2259. MapCache.prototype.set = mapCacheSet;
  2260. /* ------------------------------------------------------------------------*/
  2261. /**
  2262. *
  2263. * Creates an array cache object to store unique values.
  2264. *
  2265. * @private
  2266. * @constructor
  2267. * @param {Array} [values] The values to cache.
  2268. */
  2269. function SetCache(values) {
  2270. var index = -1,
  2271. length = values == null ? 0 : values.length;
  2272. this.__data__ = new MapCache();
  2273. while (++index < length) {
  2274. this.add(values[index]);
  2275. }
  2276. }
  2277. /**
  2278. * Adds `value` to the array cache.
  2279. *
  2280. * @private
  2281. * @name add
  2282. * @memberOf SetCache
  2283. * @alias push
  2284. * @param {*} value The value to cache.
  2285. * @returns {Object} Returns the cache instance.
  2286. */
  2287. function setCacheAdd(value) {
  2288. this.__data__.set(value, HASH_UNDEFINED);
  2289. return this;
  2290. }
  2291. /**
  2292. * Checks if `value` is in the array cache.
  2293. *
  2294. * @private
  2295. * @name has
  2296. * @memberOf SetCache
  2297. * @param {*} value The value to search for.
  2298. * @returns {number} Returns `true` if `value` is found, else `false`.
  2299. */
  2300. function setCacheHas(value) {
  2301. return this.__data__.has(value);
  2302. }
  2303. // Add methods to `SetCache`.
  2304. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2305. SetCache.prototype.has = setCacheHas;
  2306. /* ------------------------------------------------------------------------*/
  2307. /**
  2308. * Creates a stack cache object to store key-value pairs.
  2309. *
  2310. * @private
  2311. * @constructor
  2312. * @param {Array} [entries] The key-value pairs to cache.
  2313. */
  2314. function Stack(entries) {
  2315. var data = (this.__data__ = new ListCache(entries));
  2316. this.size = data.size;
  2317. }
  2318. /**
  2319. * Removes all key-value entries from the stack.
  2320. *
  2321. * @private
  2322. * @name clear
  2323. * @memberOf Stack
  2324. */
  2325. function stackClear() {
  2326. this.__data__ = new ListCache();
  2327. this.size = 0;
  2328. }
  2329. /**
  2330. * Removes `key` and its value from the stack.
  2331. *
  2332. * @private
  2333. * @name delete
  2334. * @memberOf Stack
  2335. * @param {string} key The key of the value to remove.
  2336. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2337. */
  2338. function stackDelete(key) {
  2339. var data = this.__data__,
  2340. result = data['delete'](key);
  2341. this.size = data.size;
  2342. return result;
  2343. }
  2344. /**
  2345. * Gets the stack value for `key`.
  2346. *
  2347. * @private
  2348. * @name get
  2349. * @memberOf Stack
  2350. * @param {string} key The key of the value to get.
  2351. * @returns {*} Returns the entry value.
  2352. */
  2353. function stackGet(key) {
  2354. return this.__data__.get(key);
  2355. }
  2356. /**
  2357. * Checks if a stack value for `key` exists.
  2358. *
  2359. * @private
  2360. * @name has
  2361. * @memberOf Stack
  2362. * @param {string} key The key of the entry to check.
  2363. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2364. */
  2365. function stackHas(key) {
  2366. return this.__data__.has(key);
  2367. }
  2368. /**
  2369. * Sets the stack `key` to `value`.
  2370. *
  2371. * @private
  2372. * @name set
  2373. * @memberOf Stack
  2374. * @param {string} key The key of the value to set.
  2375. * @param {*} value The value to set.
  2376. * @returns {Object} Returns the stack cache instance.
  2377. */
  2378. function stackSet(key, value) {
  2379. var data = this.__data__;
  2380. if (data instanceof ListCache) {
  2381. var pairs = data.__data__;
  2382. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  2383. pairs.push([key, value]);
  2384. this.size = ++data.size;
  2385. return this;
  2386. }
  2387. data = this.__data__ = new MapCache(pairs);
  2388. }
  2389. data.set(key, value);
  2390. this.size = data.size;
  2391. return this;
  2392. }
  2393. // Add methods to `Stack`.
  2394. Stack.prototype.clear = stackClear;
  2395. Stack.prototype['delete'] = stackDelete;
  2396. Stack.prototype.get = stackGet;
  2397. Stack.prototype.has = stackHas;
  2398. Stack.prototype.set = stackSet;
  2399. /* ------------------------------------------------------------------------*/
  2400. /**
  2401. * Creates an array of the enumerable property names of the array-like `value`.
  2402. *
  2403. * @private
  2404. * @param {*} value The value to query.
  2405. * @param {boolean} inherited Specify returning inherited property names.
  2406. * @returns {Array} Returns the array of property names.
  2407. */
  2408. function arrayLikeKeys(value, inherited) {
  2409. var isArr = isArray(value),
  2410. isArg = !isArr && isArguments(value),
  2411. isBuff = !isArr && !isArg && isBuffer(value),
  2412. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2413. skipIndexes = isArr || isArg || isBuff || isType,
  2414. result = skipIndexes ? baseTimes(value.length, String) : [],
  2415. length = result.length;
  2416. for (var key in value) {
  2417. if (
  2418. (inherited || hasOwnProperty.call(value, key)) &&
  2419. !(
  2420. skipIndexes &&
  2421. // Safari 9 has enumerable `arguments.length` in strict mode.
  2422. (key == 'length' ||
  2423. // Node.js 0.10 has enumerable non-index properties on buffers.
  2424. (isBuff && (key == 'offset' || key == 'parent')) ||
  2425. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2426. (isType &&
  2427. (key == 'buffer' ||
  2428. key == 'byteLength' ||
  2429. key == 'byteOffset')) ||
  2430. // Skip index properties.
  2431. isIndex(key, length))
  2432. )
  2433. ) {
  2434. result.push(key);
  2435. }
  2436. }
  2437. return result;
  2438. }
  2439. /**
  2440. * A specialized version of `_.sample` for arrays.
  2441. *
  2442. * @private
  2443. * @param {Array} array The array to sample.
  2444. * @returns {*} Returns the random element.
  2445. */
  2446. function arraySample(array) {
  2447. var length = array.length;
  2448. return length ? array[baseRandom(0, length - 1)] : undefined;
  2449. }
  2450. /**
  2451. * A specialized version of `_.sampleSize` for arrays.
  2452. *
  2453. * @private
  2454. * @param {Array} array The array to sample.
  2455. * @param {number} n The number of elements to sample.
  2456. * @returns {Array} Returns the random elements.
  2457. */
  2458. function arraySampleSize(array, n) {
  2459. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2460. }
  2461. /**
  2462. * A specialized version of `_.shuffle` for arrays.
  2463. *
  2464. * @private
  2465. * @param {Array} array The array to shuffle.
  2466. * @returns {Array} Returns the new shuffled array.
  2467. */
  2468. function arrayShuffle(array) {
  2469. return shuffleSelf(copyArray(array));
  2470. }
  2471. /**
  2472. * This function is like `assignValue` except that it doesn't assign
  2473. * `undefined` values.
  2474. *
  2475. * @private
  2476. * @param {Object} object The object to modify.
  2477. * @param {string} key The key of the property to assign.
  2478. * @param {*} value The value to assign.
  2479. */
  2480. function assignMergeValue(object, key, value) {
  2481. if (
  2482. (value !== undefined && !eq(object[key], value)) ||
  2483. (value === undefined && !(key in object))
  2484. ) {
  2485. baseAssignValue(object, key, value);
  2486. }
  2487. }
  2488. /**
  2489. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2490. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2491. * for equality comparisons.
  2492. *
  2493. * @private
  2494. * @param {Object} object The object to modify.
  2495. * @param {string} key The key of the property to assign.
  2496. * @param {*} value The value to assign.
  2497. */
  2498. function assignValue(object, key, value) {
  2499. var objValue = object[key];
  2500. if (
  2501. !(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2502. (value === undefined && !(key in object))
  2503. ) {
  2504. baseAssignValue(object, key, value);
  2505. }
  2506. }
  2507. /**
  2508. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2509. *
  2510. * @private
  2511. * @param {Array} array The array to inspect.
  2512. * @param {*} key The key to search for.
  2513. * @returns {number} Returns the index of the matched value, else `-1`.
  2514. */
  2515. function assocIndexOf(array, key) {
  2516. var length = array.length;
  2517. while (length--) {
  2518. if (eq(array[length][0], key)) {
  2519. return length;
  2520. }
  2521. }
  2522. return -1;
  2523. }
  2524. /**
  2525. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2526. * by `iteratee` and values set by `setter`.
  2527. *
  2528. * @private
  2529. * @param {Array|Object} collection The collection to iterate over.
  2530. * @param {Function} setter The function to set `accumulator` values.
  2531. * @param {Function} iteratee The iteratee to transform keys.
  2532. * @param {Object} accumulator The initial aggregated object.
  2533. * @returns {Function} Returns `accumulator`.
  2534. */
  2535. function baseAggregator(collection, setter, iteratee, accumulator) {
  2536. baseEach(collection, function(value, key, collection) {
  2537. setter(accumulator, value, iteratee(value), collection);
  2538. });
  2539. return accumulator;
  2540. }
  2541. /**
  2542. * The base implementation of `_.assign` without support for multiple sources
  2543. * or `customizer` functions.
  2544. *
  2545. * @private
  2546. * @param {Object} object The destination object.
  2547. * @param {Object} source The source object.
  2548. * @returns {Object} Returns `object`.
  2549. */
  2550. function baseAssign(object, source) {
  2551. return object && copyObject(source, keys(source), object);
  2552. }
  2553. /**
  2554. * The base implementation of `_.assignIn` without support for multiple sources
  2555. * or `customizer` functions.
  2556. *
  2557. * @private
  2558. * @param {Object} object The destination object.
  2559. * @param {Object} source The source object.
  2560. * @returns {Object} Returns `object`.
  2561. */
  2562. function baseAssignIn(object, source) {
  2563. return object && copyObject(source, keysIn(source), object);
  2564. }
  2565. /**
  2566. * The base implementation of `assignValue` and `assignMergeValue` without
  2567. * value checks.
  2568. *
  2569. * @private
  2570. * @param {Object} object The object to modify.
  2571. * @param {string} key The key of the property to assign.
  2572. * @param {*} value The value to assign.
  2573. */
  2574. function baseAssignValue(object, key, value) {
  2575. if (key == '__proto__' && defineProperty) {
  2576. defineProperty(object, key, {
  2577. configurable: true,
  2578. enumerable: true,
  2579. value: value,
  2580. writable: true
  2581. });
  2582. } else {
  2583. object[key] = value;
  2584. }
  2585. }
  2586. /**
  2587. * The base implementation of `_.at` without support for individual paths.
  2588. *
  2589. * @private
  2590. * @param {Object} object The object to iterate over.
  2591. * @param {string[]} paths The property paths to pick.
  2592. * @returns {Array} Returns the picked elements.
  2593. */
  2594. function baseAt(object, paths) {
  2595. var index = -1,
  2596. length = paths.length,
  2597. result = Array(length),
  2598. skip = object == null;
  2599. while (++index < length) {
  2600. result[index] = skip ? undefined : get(object, paths[index]);
  2601. }
  2602. return result;
  2603. }
  2604. /**
  2605. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2606. *
  2607. * @private
  2608. * @param {number} number The number to clamp.
  2609. * @param {number} [lower] The lower bound.
  2610. * @param {number} upper The upper bound.
  2611. * @returns {number} Returns the clamped number.
  2612. */
  2613. function baseClamp(number, lower, upper) {
  2614. if (number === number) {
  2615. if (upper !== undefined) {
  2616. number = number <= upper ? number : upper;
  2617. }
  2618. if (lower !== undefined) {
  2619. number = number >= lower ? number : lower;
  2620. }
  2621. }
  2622. return number;
  2623. }
  2624. /**
  2625. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2626. * traversed objects.
  2627. *
  2628. * @private
  2629. * @param {*} value The value to clone.
  2630. * @param {boolean} bitmask The bitmask flags.
  2631. * 1 - Deep clone
  2632. * 2 - Flatten inherited properties
  2633. * 4 - Clone symbols
  2634. * @param {Function} [customizer] The function to customize cloning.
  2635. * @param {string} [key] The key of `value`.
  2636. * @param {Object} [object] The parent object of `value`.
  2637. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2638. * @returns {*} Returns the cloned value.
  2639. */
  2640. function baseClone(value, bitmask, customizer, key, object, stack) {
  2641. var result,
  2642. isDeep = bitmask & CLONE_DEEP_FLAG,
  2643. isFlat = bitmask & CLONE_FLAT_FLAG,
  2644. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2645. if (customizer) {
  2646. result = object
  2647. ? customizer(value, key, object, stack)
  2648. : customizer(value);
  2649. }
  2650. if (result !== undefined) {
  2651. return result;
  2652. }
  2653. if (!isObject(value)) {
  2654. return value;
  2655. }
  2656. var isArr = isArray(value);
  2657. if (isArr) {
  2658. result = initCloneArray(value);
  2659. if (!isDeep) {
  2660. return copyArray(value, result);
  2661. }
  2662. } else {
  2663. var tag = getTag(value),
  2664. isFunc = tag == funcTag || tag == genTag;
  2665. if (isBuffer(value)) {
  2666. return cloneBuffer(value, isDeep);
  2667. }
  2668. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2669. result = isFlat || isFunc ? {} : initCloneObject(value);
  2670. if (!isDeep) {
  2671. return isFlat
  2672. ? copySymbolsIn(value, baseAssignIn(result, value))
  2673. : copySymbols(value, baseAssign(result, value));
  2674. }
  2675. } else {
  2676. if (!cloneableTags[tag]) {
  2677. return object ? value : {};
  2678. }
  2679. result = initCloneByTag(value, tag, isDeep);
  2680. }
  2681. }
  2682. // Check for circular references and return its corresponding clone.
  2683. stack || (stack = new Stack());
  2684. var stacked = stack.get(value);
  2685. if (stacked) {
  2686. return stacked;
  2687. }
  2688. stack.set(value, result);
  2689. if (isSet(value)) {
  2690. value.forEach(function(subValue) {
  2691. result.add(
  2692. baseClone(subValue, bitmask, customizer, subValue, value, stack)
  2693. );
  2694. });
  2695. return result;
  2696. }
  2697. if (isMap(value)) {
  2698. value.forEach(function(subValue, key) {
  2699. result.set(
  2700. key,
  2701. baseClone(subValue, bitmask, customizer, key, value, stack)
  2702. );
  2703. });
  2704. return result;
  2705. }
  2706. var keysFunc = isFull
  2707. ? isFlat
  2708. ? getAllKeysIn
  2709. : getAllKeys
  2710. : isFlat
  2711. ? keysIn
  2712. : keys;
  2713. var props = isArr ? undefined : keysFunc(value);
  2714. arrayEach(props || value, function(subValue, key) {
  2715. if (props) {
  2716. key = subValue;
  2717. subValue = value[key];
  2718. }
  2719. // Recursively populate clone (susceptible to call stack limits).
  2720. assignValue(
  2721. result,
  2722. key,
  2723. baseClone(subValue, bitmask, customizer, key, value, stack)
  2724. );
  2725. });
  2726. return result;
  2727. }
  2728. /**
  2729. * The base implementation of `_.conforms` which doesn't clone `source`.
  2730. *
  2731. * @private
  2732. * @param {Object} source The object of property predicates to conform to.
  2733. * @returns {Function} Returns the new spec function.
  2734. */
  2735. function baseConforms(source) {
  2736. var props = keys(source);
  2737. return function(object) {
  2738. return baseConformsTo(object, source, props);
  2739. };
  2740. }
  2741. /**
  2742. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2743. *
  2744. * @private
  2745. * @param {Object} object The object to inspect.
  2746. * @param {Object} source The object of property predicates to conform to.
  2747. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2748. */
  2749. function baseConformsTo(object, source, props) {
  2750. var length = props.length;
  2751. if (object == null) {
  2752. return !length;
  2753. }
  2754. object = Object(object);
  2755. while (length--) {
  2756. var key = props[length],
  2757. predicate = source[key],
  2758. value = object[key];
  2759. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2760. return false;
  2761. }
  2762. }
  2763. return true;
  2764. }
  2765. /**
  2766. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2767. * to provide to `func`.
  2768. *
  2769. * @private
  2770. * @param {Function} func The function to delay.
  2771. * @param {number} wait The number of milliseconds to delay invocation.
  2772. * @param {Array} args The arguments to provide to `func`.
  2773. * @returns {number|Object} Returns the timer id or timeout object.
  2774. */
  2775. function baseDelay(func, wait, args) {
  2776. if (typeof func !== 'function') {
  2777. throw new TypeError(FUNC_ERROR_TEXT);
  2778. }
  2779. return setTimeout(function() {
  2780. func.apply(undefined, args);
  2781. }, wait);
  2782. }
  2783. /**
  2784. * The base implementation of methods like `_.difference` without support
  2785. * for excluding multiple arrays or iteratee shorthands.
  2786. *
  2787. * @private
  2788. * @param {Array} array The array to inspect.
  2789. * @param {Array} values The values to exclude.
  2790. * @param {Function} [iteratee] The iteratee invoked per element.
  2791. * @param {Function} [comparator] The comparator invoked per element.
  2792. * @returns {Array} Returns the new array of filtered values.
  2793. */
  2794. function baseDifference(array, values, iteratee, comparator) {
  2795. var index = -1,
  2796. includes = arrayIncludes,
  2797. isCommon = true,
  2798. length = array.length,
  2799. result = [],
  2800. valuesLength = values.length;
  2801. if (!length) {
  2802. return result;
  2803. }
  2804. if (iteratee) {
  2805. values = arrayMap(values, baseUnary(iteratee));
  2806. }
  2807. if (comparator) {
  2808. includes = arrayIncludesWith;
  2809. isCommon = false;
  2810. } else if (values.length >= LARGE_ARRAY_SIZE) {
  2811. includes = cacheHas;
  2812. isCommon = false;
  2813. values = new SetCache(values);
  2814. }
  2815. outer: while (++index < length) {
  2816. var value = array[index],
  2817. computed = iteratee == null ? value : iteratee(value);
  2818. value = comparator || value !== 0 ? value : 0;
  2819. if (isCommon && computed === computed) {
  2820. var valuesIndex = valuesLength;
  2821. while (valuesIndex--) {
  2822. if (values[valuesIndex] === computed) {
  2823. continue outer;
  2824. }
  2825. }
  2826. result.push(value);
  2827. } else if (!includes(values, computed, comparator)) {
  2828. result.push(value);
  2829. }
  2830. }
  2831. return result;
  2832. }
  2833. /**
  2834. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2835. *
  2836. * @private
  2837. * @param {Array|Object} collection The collection to iterate over.
  2838. * @param {Function} iteratee The function invoked per iteration.
  2839. * @returns {Array|Object} Returns `collection`.
  2840. */
  2841. var baseEach = createBaseEach(baseForOwn);
  2842. /**
  2843. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2844. *
  2845. * @private
  2846. * @param {Array|Object} collection The collection to iterate over.
  2847. * @param {Function} iteratee The function invoked per iteration.
  2848. * @returns {Array|Object} Returns `collection`.
  2849. */
  2850. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2851. /**
  2852. * The base implementation of `_.every` without support for iteratee shorthands.
  2853. *
  2854. * @private
  2855. * @param {Array|Object} collection The collection to iterate over.
  2856. * @param {Function} predicate The function invoked per iteration.
  2857. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2858. * else `false`
  2859. */
  2860. function baseEvery(collection, predicate) {
  2861. var result = true;
  2862. baseEach(collection, function(value, index, collection) {
  2863. result = !!predicate(value, index, collection);
  2864. return result;
  2865. });
  2866. return result;
  2867. }
  2868. /**
  2869. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2870. * `comparator` to determine the extremum value.
  2871. *
  2872. * @private
  2873. * @param {Array} array The array to iterate over.
  2874. * @param {Function} iteratee The iteratee invoked per iteration.
  2875. * @param {Function} comparator The comparator used to compare values.
  2876. * @returns {*} Returns the extremum value.
  2877. */
  2878. function baseExtremum(array, iteratee, comparator) {
  2879. var index = -1,
  2880. length = array.length;
  2881. while (++index < length) {
  2882. var value = array[index],
  2883. current = iteratee(value);
  2884. if (
  2885. current != null &&
  2886. (computed === undefined
  2887. ? current === current && !isSymbol(current)
  2888. : comparator(current, computed))
  2889. ) {
  2890. var computed = current,
  2891. result = value;
  2892. }
  2893. }
  2894. return result;
  2895. }
  2896. /**
  2897. * The base implementation of `_.fill` without an iteratee call guard.
  2898. *
  2899. * @private
  2900. * @param {Array} array The array to fill.
  2901. * @param {*} value The value to fill `array` with.
  2902. * @param {number} [start=0] The start position.
  2903. * @param {number} [end=array.length] The end position.
  2904. * @returns {Array} Returns `array`.
  2905. */
  2906. function baseFill(array, value, start, end) {
  2907. var length = array.length;
  2908. start = toInteger(start);
  2909. if (start < 0) {
  2910. start = -start > length ? 0 : length + start;
  2911. }
  2912. end = end === undefined || end > length ? length : toInteger(end);
  2913. if (end < 0) {
  2914. end += length;
  2915. }
  2916. end = start > end ? 0 : toLength(end);
  2917. while (start < end) {
  2918. array[start++] = value;
  2919. }
  2920. return array;
  2921. }
  2922. /**
  2923. * The base implementation of `_.filter` without support for iteratee shorthands.
  2924. *
  2925. * @private
  2926. * @param {Array|Object} collection The collection to iterate over.
  2927. * @param {Function} predicate The function invoked per iteration.
  2928. * @returns {Array} Returns the new filtered array.
  2929. */
  2930. function baseFilter(collection, predicate) {
  2931. var result = [];
  2932. baseEach(collection, function(value, index, collection) {
  2933. if (predicate(value, index, collection)) {
  2934. result.push(value);
  2935. }
  2936. });
  2937. return result;
  2938. }
  2939. /**
  2940. * The base implementation of `_.flatten` with support for restricting flattening.
  2941. *
  2942. * @private
  2943. * @param {Array} array The array to flatten.
  2944. * @param {number} depth The maximum recursion depth.
  2945. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2946. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2947. * @param {Array} [result=[]] The initial result value.
  2948. * @returns {Array} Returns the new flattened array.
  2949. */
  2950. function baseFlatten(array, depth, predicate, isStrict, result) {
  2951. var index = -1,
  2952. length = array.length;
  2953. predicate || (predicate = isFlattenable);
  2954. result || (result = []);
  2955. while (++index < length) {
  2956. var value = array[index];
  2957. if (depth > 0 && predicate(value)) {
  2958. if (depth > 1) {
  2959. // Recursively flatten arrays (susceptible to call stack limits).
  2960. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2961. } else {
  2962. arrayPush(result, value);
  2963. }
  2964. } else if (!isStrict) {
  2965. result[result.length] = value;
  2966. }
  2967. }
  2968. return result;
  2969. }
  2970. /**
  2971. * The base implementation of `baseForOwn` which iterates over `object`
  2972. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2973. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2974. *
  2975. * @private
  2976. * @param {Object} object The object to iterate over.
  2977. * @param {Function} iteratee The function invoked per iteration.
  2978. * @param {Function} keysFunc The function to get the keys of `object`.
  2979. * @returns {Object} Returns `object`.
  2980. */
  2981. var baseFor = createBaseFor();
  2982. /**
  2983. * This function is like `baseFor` except that it iterates over properties
  2984. * in the opposite order.
  2985. *
  2986. * @private
  2987. * @param {Object} object The object to iterate over.
  2988. * @param {Function} iteratee The function invoked per iteration.
  2989. * @param {Function} keysFunc The function to get the keys of `object`.
  2990. * @returns {Object} Returns `object`.
  2991. */
  2992. var baseForRight = createBaseFor(true);
  2993. /**
  2994. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2995. *
  2996. * @private
  2997. * @param {Object} object The object to iterate over.
  2998. * @param {Function} iteratee The function invoked per iteration.
  2999. * @returns {Object} Returns `object`.
  3000. */
  3001. function baseForOwn(object, iteratee) {
  3002. return object && baseFor(object, iteratee, keys);
  3003. }
  3004. /**
  3005. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  3006. *
  3007. * @private
  3008. * @param {Object} object The object to iterate over.
  3009. * @param {Function} iteratee The function invoked per iteration.
  3010. * @returns {Object} Returns `object`.
  3011. */
  3012. function baseForOwnRight(object, iteratee) {
  3013. return object && baseForRight(object, iteratee, keys);
  3014. }
  3015. /**
  3016. * The base implementation of `_.functions` which creates an array of
  3017. * `object` function property names filtered from `props`.
  3018. *
  3019. * @private
  3020. * @param {Object} object The object to inspect.
  3021. * @param {Array} props The property names to filter.
  3022. * @returns {Array} Returns the function names.
  3023. */
  3024. function baseFunctions(object, props) {
  3025. return arrayFilter(props, function(key) {
  3026. return isFunction(object[key]);
  3027. });
  3028. }
  3029. /**
  3030. * The base implementation of `_.get` without support for default values.
  3031. *
  3032. * @private
  3033. * @param {Object} object The object to query.
  3034. * @param {Array|string} path The path of the property to get.
  3035. * @returns {*} Returns the resolved value.
  3036. */
  3037. function baseGet(object, path) {
  3038. path = castPath(path, object);
  3039. var index = 0,
  3040. length = path.length;
  3041. while (object != null && index < length) {
  3042. object = object[toKey(path[index++])];
  3043. }
  3044. return index && index == length ? object : undefined;
  3045. }
  3046. /**
  3047. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  3048. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  3049. * symbols of `object`.
  3050. *
  3051. * @private
  3052. * @param {Object} object The object to query.
  3053. * @param {Function} keysFunc The function to get the keys of `object`.
  3054. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  3055. * @returns {Array} Returns the array of property names and symbols.
  3056. */
  3057. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  3058. var result = keysFunc(object);
  3059. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  3060. }
  3061. /**
  3062. * The base implementation of `getTag` without fallbacks for buggy environments.
  3063. *
  3064. * @private
  3065. * @param {*} value The value to query.
  3066. * @returns {string} Returns the `toStringTag`.
  3067. */
  3068. function baseGetTag(value) {
  3069. if (value == null) {
  3070. return value === undefined ? undefinedTag : nullTag;
  3071. }
  3072. return symToStringTag && symToStringTag in Object(value)
  3073. ? getRawTag(value)
  3074. : objectToString(value);
  3075. }
  3076. /**
  3077. * The base implementation of `_.gt` which doesn't coerce arguments.
  3078. *
  3079. * @private
  3080. * @param {*} value The value to compare.
  3081. * @param {*} other The other value to compare.
  3082. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  3083. * else `false`.
  3084. */
  3085. function baseGt(value, other) {
  3086. return value > other;
  3087. }
  3088. /**
  3089. * The base implementation of `_.has` without support for deep paths.
  3090. *
  3091. * @private
  3092. * @param {Object} [object] The object to query.
  3093. * @param {Array|string} key The key to check.
  3094. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  3095. */
  3096. function baseHas(object, key) {
  3097. return object != null && hasOwnProperty.call(object, key);
  3098. }
  3099. /**
  3100. * The base implementation of `_.hasIn` without support for deep paths.
  3101. *
  3102. * @private
  3103. * @param {Object} [object] The object to query.
  3104. * @param {Array|string} key The key to check.
  3105. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  3106. */
  3107. function baseHasIn(object, key) {
  3108. return object != null && key in Object(object);
  3109. }
  3110. /**
  3111. * The base implementation of `_.inRange` which doesn't coerce arguments.
  3112. *
  3113. * @private
  3114. * @param {number} number The number to check.
  3115. * @param {number} start The start of the range.
  3116. * @param {number} end The end of the range.
  3117. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  3118. */
  3119. function baseInRange(number, start, end) {
  3120. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  3121. }
  3122. /**
  3123. * The base implementation of methods like `_.intersection`, without support
  3124. * for iteratee shorthands, that accepts an array of arrays to inspect.
  3125. *
  3126. * @private
  3127. * @param {Array} arrays The arrays to inspect.
  3128. * @param {Function} [iteratee] The iteratee invoked per element.
  3129. * @param {Function} [comparator] The comparator invoked per element.
  3130. * @returns {Array} Returns the new array of shared values.
  3131. */
  3132. function baseIntersection(arrays, iteratee, comparator) {
  3133. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  3134. length = arrays[0].length,
  3135. othLength = arrays.length,
  3136. othIndex = othLength,
  3137. caches = Array(othLength),
  3138. maxLength = Infinity,
  3139. result = [];
  3140. while (othIndex--) {
  3141. var array = arrays[othIndex];
  3142. if (othIndex && iteratee) {
  3143. array = arrayMap(array, baseUnary(iteratee));
  3144. }
  3145. maxLength = nativeMin(array.length, maxLength);
  3146. caches[othIndex] =
  3147. !comparator && (iteratee || (length >= 120 && array.length >= 120))
  3148. ? new SetCache(othIndex && array)
  3149. : undefined;
  3150. }
  3151. array = arrays[0];
  3152. var index = -1,
  3153. seen = caches[0];
  3154. outer: while (++index < length && result.length < maxLength) {
  3155. var value = array[index],
  3156. computed = iteratee ? iteratee(value) : value;
  3157. value = comparator || value !== 0 ? value : 0;
  3158. if (
  3159. !(seen
  3160. ? cacheHas(seen, computed)
  3161. : includes(result, computed, comparator))
  3162. ) {
  3163. othIndex = othLength;
  3164. while (--othIndex) {
  3165. var cache = caches[othIndex];
  3166. if (
  3167. !(cache
  3168. ? cacheHas(cache, computed)
  3169. : includes(arrays[othIndex], computed, comparator))
  3170. ) {
  3171. continue outer;
  3172. }
  3173. }
  3174. if (seen) {
  3175. seen.push(computed);
  3176. }
  3177. result.push(value);
  3178. }
  3179. }
  3180. return result;
  3181. }
  3182. /**
  3183. * The base implementation of `_.invert` and `_.invertBy` which inverts
  3184. * `object` with values transformed by `iteratee` and set by `setter`.
  3185. *
  3186. * @private
  3187. * @param {Object} object The object to iterate over.
  3188. * @param {Function} setter The function to set `accumulator` values.
  3189. * @param {Function} iteratee The iteratee to transform values.
  3190. * @param {Object} accumulator The initial inverted object.
  3191. * @returns {Function} Returns `accumulator`.
  3192. */
  3193. function baseInverter(object, setter, iteratee, accumulator) {
  3194. baseForOwn(object, function(value, key, object) {
  3195. setter(accumulator, iteratee(value), key, object);
  3196. });
  3197. return accumulator;
  3198. }
  3199. /**
  3200. * The base implementation of `_.invoke` without support for individual
  3201. * method arguments.
  3202. *
  3203. * @private
  3204. * @param {Object} object The object to query.
  3205. * @param {Array|string} path The path of the method to invoke.
  3206. * @param {Array} args The arguments to invoke the method with.
  3207. * @returns {*} Returns the result of the invoked method.
  3208. */
  3209. function baseInvoke(object, path, args) {
  3210. path = castPath(path, object);
  3211. object = parent(object, path);
  3212. var func = object == null ? object : object[toKey(last(path))];
  3213. return func == null ? undefined : apply(func, object, args);
  3214. }
  3215. /**
  3216. * The base implementation of `_.isArguments`.
  3217. *
  3218. * @private
  3219. * @param {*} value The value to check.
  3220. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  3221. */
  3222. function baseIsArguments(value) {
  3223. return isObjectLike(value) && baseGetTag(value) == argsTag;
  3224. }
  3225. /**
  3226. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  3227. *
  3228. * @private
  3229. * @param {*} value The value to check.
  3230. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  3231. */
  3232. function baseIsArrayBuffer(value) {
  3233. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  3234. }
  3235. /**
  3236. * The base implementation of `_.isDate` without Node.js optimizations.
  3237. *
  3238. * @private
  3239. * @param {*} value The value to check.
  3240. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  3241. */
  3242. function baseIsDate(value) {
  3243. return isObjectLike(value) && baseGetTag(value) == dateTag;
  3244. }
  3245. /**
  3246. * The base implementation of `_.isEqual` which supports partial comparisons
  3247. * and tracks traversed objects.
  3248. *
  3249. * @private
  3250. * @param {*} value The value to compare.
  3251. * @param {*} other The other value to compare.
  3252. * @param {boolean} bitmask The bitmask flags.
  3253. * 1 - Unordered comparison
  3254. * 2 - Partial comparison
  3255. * @param {Function} [customizer] The function to customize comparisons.
  3256. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3257. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3258. */
  3259. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3260. if (value === other) {
  3261. return true;
  3262. }
  3263. if (
  3264. value == null ||
  3265. other == null ||
  3266. (!isObjectLike(value) && !isObjectLike(other))
  3267. ) {
  3268. return value !== value && other !== other;
  3269. }
  3270. return baseIsEqualDeep(
  3271. value,
  3272. other,
  3273. bitmask,
  3274. customizer,
  3275. baseIsEqual,
  3276. stack
  3277. );
  3278. }
  3279. /**
  3280. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3281. * deep comparisons and tracks traversed objects enabling objects with circular
  3282. * references to be compared.
  3283. *
  3284. * @private
  3285. * @param {Object} object The object to compare.
  3286. * @param {Object} other The other object to compare.
  3287. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3288. * @param {Function} customizer The function to customize comparisons.
  3289. * @param {Function} equalFunc The function to determine equivalents of values.
  3290. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3291. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3292. */
  3293. function baseIsEqualDeep(
  3294. object,
  3295. other,
  3296. bitmask,
  3297. customizer,
  3298. equalFunc,
  3299. stack
  3300. ) {
  3301. var objIsArr = isArray(object),
  3302. othIsArr = isArray(other),
  3303. objTag = objIsArr ? arrayTag : getTag(object),
  3304. othTag = othIsArr ? arrayTag : getTag(other);
  3305. objTag = objTag == argsTag ? objectTag : objTag;
  3306. othTag = othTag == argsTag ? objectTag : othTag;
  3307. var objIsObj = objTag == objectTag,
  3308. othIsObj = othTag == objectTag,
  3309. isSameTag = objTag == othTag;
  3310. if (isSameTag && isBuffer(object)) {
  3311. if (!isBuffer(other)) {
  3312. return false;
  3313. }
  3314. objIsArr = true;
  3315. objIsObj = false;
  3316. }
  3317. if (isSameTag && !objIsObj) {
  3318. stack || (stack = new Stack());
  3319. return objIsArr || isTypedArray(object)
  3320. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3321. : equalByTag(
  3322. object,
  3323. other,
  3324. objTag,
  3325. bitmask,
  3326. customizer,
  3327. equalFunc,
  3328. stack
  3329. );
  3330. }
  3331. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3332. var objIsWrapped =
  3333. objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3334. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3335. if (objIsWrapped || othIsWrapped) {
  3336. var objUnwrapped = objIsWrapped ? object.value() : object,
  3337. othUnwrapped = othIsWrapped ? other.value() : other;
  3338. stack || (stack = new Stack());
  3339. return equalFunc(
  3340. objUnwrapped,
  3341. othUnwrapped,
  3342. bitmask,
  3343. customizer,
  3344. stack
  3345. );
  3346. }
  3347. }
  3348. if (!isSameTag) {
  3349. return false;
  3350. }
  3351. stack || (stack = new Stack());
  3352. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3353. }
  3354. /**
  3355. * The base implementation of `_.isMap` without Node.js optimizations.
  3356. *
  3357. * @private
  3358. * @param {*} value The value to check.
  3359. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3360. */
  3361. function baseIsMap(value) {
  3362. return isObjectLike(value) && getTag(value) == mapTag;
  3363. }
  3364. /**
  3365. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3366. *
  3367. * @private
  3368. * @param {Object} object The object to inspect.
  3369. * @param {Object} source The object of property values to match.
  3370. * @param {Array} matchData The property names, values, and compare flags to match.
  3371. * @param {Function} [customizer] The function to customize comparisons.
  3372. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3373. */
  3374. function baseIsMatch(object, source, matchData, customizer) {
  3375. var index = matchData.length,
  3376. length = index,
  3377. noCustomizer = !customizer;
  3378. if (object == null) {
  3379. return !length;
  3380. }
  3381. object = Object(object);
  3382. while (index--) {
  3383. var data = matchData[index];
  3384. if (
  3385. noCustomizer && data[2]
  3386. ? data[1] !== object[data[0]]
  3387. : !(data[0] in object)
  3388. ) {
  3389. return false;
  3390. }
  3391. }
  3392. while (++index < length) {
  3393. data = matchData[index];
  3394. var key = data[0],
  3395. objValue = object[key],
  3396. srcValue = data[1];
  3397. if (noCustomizer && data[2]) {
  3398. if (objValue === undefined && !(key in object)) {
  3399. return false;
  3400. }
  3401. } else {
  3402. var stack = new Stack();
  3403. if (customizer) {
  3404. var result = customizer(
  3405. objValue,
  3406. srcValue,
  3407. key,
  3408. object,
  3409. source,
  3410. stack
  3411. );
  3412. }
  3413. if (
  3414. !(result === undefined
  3415. ? baseIsEqual(
  3416. srcValue,
  3417. objValue,
  3418. COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG,
  3419. customizer,
  3420. stack
  3421. )
  3422. : result)
  3423. ) {
  3424. return false;
  3425. }
  3426. }
  3427. }
  3428. return true;
  3429. }
  3430. /**
  3431. * The base implementation of `_.isNative` without bad shim checks.
  3432. *
  3433. * @private
  3434. * @param {*} value The value to check.
  3435. * @returns {boolean} Returns `true` if `value` is a native function,
  3436. * else `false`.
  3437. */
  3438. function baseIsNative(value) {
  3439. if (!isObject(value) || isMasked(value)) {
  3440. return false;
  3441. }
  3442. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3443. return pattern.test(toSource(value));
  3444. }
  3445. /**
  3446. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3447. *
  3448. * @private
  3449. * @param {*} value The value to check.
  3450. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3451. */
  3452. function baseIsRegExp(value) {
  3453. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3454. }
  3455. /**
  3456. * The base implementation of `_.isSet` without Node.js optimizations.
  3457. *
  3458. * @private
  3459. * @param {*} value The value to check.
  3460. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3461. */
  3462. function baseIsSet(value) {
  3463. return isObjectLike(value) && getTag(value) == setTag;
  3464. }
  3465. /**
  3466. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3467. *
  3468. * @private
  3469. * @param {*} value The value to check.
  3470. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3471. */
  3472. function baseIsTypedArray(value) {
  3473. return (
  3474. isObjectLike(value) &&
  3475. isLength(value.length) &&
  3476. !!typedArrayTags[baseGetTag(value)]
  3477. );
  3478. }
  3479. /**
  3480. * The base implementation of `_.iteratee`.
  3481. *
  3482. * @private
  3483. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3484. * @returns {Function} Returns the iteratee.
  3485. */
  3486. function baseIteratee(value) {
  3487. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3488. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3489. if (typeof value === 'function') {
  3490. return value;
  3491. }
  3492. if (value == null) {
  3493. return identity;
  3494. }
  3495. if (typeof value === 'object') {
  3496. return isArray(value)
  3497. ? baseMatchesProperty(value[0], value[1])
  3498. : baseMatches(value);
  3499. }
  3500. return property(value);
  3501. }
  3502. /**
  3503. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3504. *
  3505. * @private
  3506. * @param {Object} object The object to query.
  3507. * @returns {Array} Returns the array of property names.
  3508. */
  3509. function baseKeys(object) {
  3510. if (!isPrototype(object)) {
  3511. return nativeKeys(object);
  3512. }
  3513. var result = [];
  3514. for (var key in Object(object)) {
  3515. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3516. result.push(key);
  3517. }
  3518. }
  3519. return result;
  3520. }
  3521. /**
  3522. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3523. *
  3524. * @private
  3525. * @param {Object} object The object to query.
  3526. * @returns {Array} Returns the array of property names.
  3527. */
  3528. function baseKeysIn(object) {
  3529. if (!isObject(object)) {
  3530. return nativeKeysIn(object);
  3531. }
  3532. var isProto = isPrototype(object),
  3533. result = [];
  3534. for (var key in object) {
  3535. if (
  3536. !(
  3537. key == 'constructor' &&
  3538. (isProto || !hasOwnProperty.call(object, key))
  3539. )
  3540. ) {
  3541. result.push(key);
  3542. }
  3543. }
  3544. return result;
  3545. }
  3546. /**
  3547. * The base implementation of `_.lt` which doesn't coerce arguments.
  3548. *
  3549. * @private
  3550. * @param {*} value The value to compare.
  3551. * @param {*} other The other value to compare.
  3552. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3553. * else `false`.
  3554. */
  3555. function baseLt(value, other) {
  3556. return value < other;
  3557. }
  3558. /**
  3559. * The base implementation of `_.map` without support for iteratee shorthands.
  3560. *
  3561. * @private
  3562. * @param {Array|Object} collection The collection to iterate over.
  3563. * @param {Function} iteratee The function invoked per iteration.
  3564. * @returns {Array} Returns the new mapped array.
  3565. */
  3566. function baseMap(collection, iteratee) {
  3567. var index = -1,
  3568. result = isArrayLike(collection) ? Array(collection.length) : [];
  3569. baseEach(collection, function(value, key, collection) {
  3570. result[++index] = iteratee(value, key, collection);
  3571. });
  3572. return result;
  3573. }
  3574. /**
  3575. * The base implementation of `_.matches` which doesn't clone `source`.
  3576. *
  3577. * @private
  3578. * @param {Object} source The object of property values to match.
  3579. * @returns {Function} Returns the new spec function.
  3580. */
  3581. function baseMatches(source) {
  3582. var matchData = getMatchData(source);
  3583. if (matchData.length == 1 && matchData[0][2]) {
  3584. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3585. }
  3586. return function(object) {
  3587. return object === source || baseIsMatch(object, source, matchData);
  3588. };
  3589. }
  3590. /**
  3591. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3592. *
  3593. * @private
  3594. * @param {string} path The path of the property to get.
  3595. * @param {*} srcValue The value to match.
  3596. * @returns {Function} Returns the new spec function.
  3597. */
  3598. function baseMatchesProperty(path, srcValue) {
  3599. if (isKey(path) && isStrictComparable(srcValue)) {
  3600. return matchesStrictComparable(toKey(path), srcValue);
  3601. }
  3602. return function(object) {
  3603. var objValue = get(object, path);
  3604. return objValue === undefined && objValue === srcValue
  3605. ? hasIn(object, path)
  3606. : baseIsEqual(
  3607. srcValue,
  3608. objValue,
  3609. COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG
  3610. );
  3611. };
  3612. }
  3613. /**
  3614. * The base implementation of `_.merge` without support for multiple sources.
  3615. *
  3616. * @private
  3617. * @param {Object} object The destination object.
  3618. * @param {Object} source The source object.
  3619. * @param {number} srcIndex The index of `source`.
  3620. * @param {Function} [customizer] The function to customize merged values.
  3621. * @param {Object} [stack] Tracks traversed source values and their merged
  3622. * counterparts.
  3623. */
  3624. function baseMerge(object, source, srcIndex, customizer, stack) {
  3625. if (object === source) {
  3626. return;
  3627. }
  3628. baseFor(
  3629. source,
  3630. function(srcValue, key) {
  3631. if (isObject(srcValue)) {
  3632. stack || (stack = new Stack());
  3633. baseMergeDeep(
  3634. object,
  3635. source,
  3636. key,
  3637. srcIndex,
  3638. baseMerge,
  3639. customizer,
  3640. stack
  3641. );
  3642. } else {
  3643. var newValue = customizer
  3644. ? customizer(
  3645. safeGet(object, key),
  3646. srcValue,
  3647. key + '',
  3648. object,
  3649. source,
  3650. stack
  3651. )
  3652. : undefined;
  3653. if (newValue === undefined) {
  3654. newValue = srcValue;
  3655. }
  3656. assignMergeValue(object, key, newValue);
  3657. }
  3658. },
  3659. keysIn
  3660. );
  3661. }
  3662. /**
  3663. * A specialized version of `baseMerge` for arrays and objects which performs
  3664. * deep merges and tracks traversed objects enabling objects with circular
  3665. * references to be merged.
  3666. *
  3667. * @private
  3668. * @param {Object} object The destination object.
  3669. * @param {Object} source The source object.
  3670. * @param {string} key The key of the value to merge.
  3671. * @param {number} srcIndex The index of `source`.
  3672. * @param {Function} mergeFunc The function to merge values.
  3673. * @param {Function} [customizer] The function to customize assigned values.
  3674. * @param {Object} [stack] Tracks traversed source values and their merged
  3675. * counterparts.
  3676. */
  3677. function baseMergeDeep(
  3678. object,
  3679. source,
  3680. key,
  3681. srcIndex,
  3682. mergeFunc,
  3683. customizer,
  3684. stack
  3685. ) {
  3686. var objValue = safeGet(object, key),
  3687. srcValue = safeGet(source, key),
  3688. stacked = stack.get(srcValue);
  3689. if (stacked) {
  3690. assignMergeValue(object, key, stacked);
  3691. return;
  3692. }
  3693. var newValue = customizer
  3694. ? customizer(objValue, srcValue, key + '', object, source, stack)
  3695. : undefined;
  3696. var isCommon = newValue === undefined;
  3697. if (isCommon) {
  3698. var isArr = isArray(srcValue),
  3699. isBuff = !isArr && isBuffer(srcValue),
  3700. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3701. newValue = srcValue;
  3702. if (isArr || isBuff || isTyped) {
  3703. if (isArray(objValue)) {
  3704. newValue = objValue;
  3705. } else if (isArrayLikeObject(objValue)) {
  3706. newValue = copyArray(objValue);
  3707. } else if (isBuff) {
  3708. isCommon = false;
  3709. newValue = cloneBuffer(srcValue, true);
  3710. } else if (isTyped) {
  3711. isCommon = false;
  3712. newValue = cloneTypedArray(srcValue, true);
  3713. } else {
  3714. newValue = [];
  3715. }
  3716. } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3717. newValue = objValue;
  3718. if (isArguments(objValue)) {
  3719. newValue = toPlainObject(objValue);
  3720. } else if (
  3721. !isObject(objValue) ||
  3722. (srcIndex && isFunction(objValue))
  3723. ) {
  3724. newValue = initCloneObject(srcValue);
  3725. }
  3726. } else {
  3727. isCommon = false;
  3728. }
  3729. }
  3730. if (isCommon) {
  3731. // Recursively merge objects and arrays (susceptible to call stack limits).
  3732. stack.set(srcValue, newValue);
  3733. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3734. stack['delete'](srcValue);
  3735. }
  3736. assignMergeValue(object, key, newValue);
  3737. }
  3738. /**
  3739. * The base implementation of `_.nth` which doesn't coerce arguments.
  3740. *
  3741. * @private
  3742. * @param {Array} array The array to query.
  3743. * @param {number} n The index of the element to return.
  3744. * @returns {*} Returns the nth element of `array`.
  3745. */
  3746. function baseNth(array, n) {
  3747. var length = array.length;
  3748. if (!length) {
  3749. return;
  3750. }
  3751. n += n < 0 ? length : 0;
  3752. return isIndex(n, length) ? array[n] : undefined;
  3753. }
  3754. /**
  3755. * The base implementation of `_.orderBy` without param guards.
  3756. *
  3757. * @private
  3758. * @param {Array|Object} collection The collection to iterate over.
  3759. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3760. * @param {string[]} orders The sort orders of `iteratees`.
  3761. * @returns {Array} Returns the new sorted array.
  3762. */
  3763. function baseOrderBy(collection, iteratees, orders) {
  3764. var index = -1;
  3765. iteratees = arrayMap(
  3766. iteratees.length ? iteratees : [identity],
  3767. baseUnary(getIteratee())
  3768. );
  3769. var result = baseMap(collection, function(value, key, collection) {
  3770. var criteria = arrayMap(iteratees, function(iteratee) {
  3771. return iteratee(value);
  3772. });
  3773. return { criteria: criteria, index: ++index, value: value };
  3774. });
  3775. return baseSortBy(result, function(object, other) {
  3776. return compareMultiple(object, other, orders);
  3777. });
  3778. }
  3779. /**
  3780. * The base implementation of `_.pick` without support for individual
  3781. * property identifiers.
  3782. *
  3783. * @private
  3784. * @param {Object} object The source object.
  3785. * @param {string[]} paths The property paths to pick.
  3786. * @returns {Object} Returns the new object.
  3787. */
  3788. function basePick(object, paths) {
  3789. return basePickBy(object, paths, function(value, path) {
  3790. return hasIn(object, path);
  3791. });
  3792. }
  3793. /**
  3794. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3795. *
  3796. * @private
  3797. * @param {Object} object The source object.
  3798. * @param {string[]} paths The property paths to pick.
  3799. * @param {Function} predicate The function invoked per property.
  3800. * @returns {Object} Returns the new object.
  3801. */
  3802. function basePickBy(object, paths, predicate) {
  3803. var index = -1,
  3804. length = paths.length,
  3805. result = {};
  3806. while (++index < length) {
  3807. var path = paths[index],
  3808. value = baseGet(object, path);
  3809. if (predicate(value, path)) {
  3810. baseSet(result, castPath(path, object), value);
  3811. }
  3812. }
  3813. return result;
  3814. }
  3815. /**
  3816. * A specialized version of `baseProperty` which supports deep paths.
  3817. *
  3818. * @private
  3819. * @param {Array|string} path The path of the property to get.
  3820. * @returns {Function} Returns the new accessor function.
  3821. */
  3822. function basePropertyDeep(path) {
  3823. return function(object) {
  3824. return baseGet(object, path);
  3825. };
  3826. }
  3827. /**
  3828. * The base implementation of `_.pullAllBy` without support for iteratee
  3829. * shorthands.
  3830. *
  3831. * @private
  3832. * @param {Array} array The array to modify.
  3833. * @param {Array} values The values to remove.
  3834. * @param {Function} [iteratee] The iteratee invoked per element.
  3835. * @param {Function} [comparator] The comparator invoked per element.
  3836. * @returns {Array} Returns `array`.
  3837. */
  3838. function basePullAll(array, values, iteratee, comparator) {
  3839. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3840. index = -1,
  3841. length = values.length,
  3842. seen = array;
  3843. if (array === values) {
  3844. values = copyArray(values);
  3845. }
  3846. if (iteratee) {
  3847. seen = arrayMap(array, baseUnary(iteratee));
  3848. }
  3849. while (++index < length) {
  3850. var fromIndex = 0,
  3851. value = values[index],
  3852. computed = iteratee ? iteratee(value) : value;
  3853. while (
  3854. (fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1
  3855. ) {
  3856. if (seen !== array) {
  3857. splice.call(seen, fromIndex, 1);
  3858. }
  3859. splice.call(array, fromIndex, 1);
  3860. }
  3861. }
  3862. return array;
  3863. }
  3864. /**
  3865. * The base implementation of `_.pullAt` without support for individual
  3866. * indexes or capturing the removed elements.
  3867. *
  3868. * @private
  3869. * @param {Array} array The array to modify.
  3870. * @param {number[]} indexes The indexes of elements to remove.
  3871. * @returns {Array} Returns `array`.
  3872. */
  3873. function basePullAt(array, indexes) {
  3874. var length = array ? indexes.length : 0,
  3875. lastIndex = length - 1;
  3876. while (length--) {
  3877. var index = indexes[length];
  3878. if (length == lastIndex || index !== previous) {
  3879. var previous = index;
  3880. if (isIndex(index)) {
  3881. splice.call(array, index, 1);
  3882. } else {
  3883. baseUnset(array, index);
  3884. }
  3885. }
  3886. }
  3887. return array;
  3888. }
  3889. /**
  3890. * The base implementation of `_.random` without support for returning
  3891. * floating-point numbers.
  3892. *
  3893. * @private
  3894. * @param {number} lower The lower bound.
  3895. * @param {number} upper The upper bound.
  3896. * @returns {number} Returns the random number.
  3897. */
  3898. function baseRandom(lower, upper) {
  3899. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3900. }
  3901. /**
  3902. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3903. * coerce arguments.
  3904. *
  3905. * @private
  3906. * @param {number} start The start of the range.
  3907. * @param {number} end The end of the range.
  3908. * @param {number} step The value to increment or decrement by.
  3909. * @param {boolean} [fromRight] Specify iterating from right to left.
  3910. * @returns {Array} Returns the range of numbers.
  3911. */
  3912. function baseRange(start, end, step, fromRight) {
  3913. var index = -1,
  3914. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3915. result = Array(length);
  3916. while (length--) {
  3917. result[fromRight ? length : ++index] = start;
  3918. start += step;
  3919. }
  3920. return result;
  3921. }
  3922. /**
  3923. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3924. *
  3925. * @private
  3926. * @param {string} string The string to repeat.
  3927. * @param {number} n The number of times to repeat the string.
  3928. * @returns {string} Returns the repeated string.
  3929. */
  3930. function baseRepeat(string, n) {
  3931. var result = '';
  3932. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3933. return result;
  3934. }
  3935. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3936. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3937. do {
  3938. if (n % 2) {
  3939. result += string;
  3940. }
  3941. n = nativeFloor(n / 2);
  3942. if (n) {
  3943. string += string;
  3944. }
  3945. } while (n);
  3946. return result;
  3947. }
  3948. /**
  3949. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3950. *
  3951. * @private
  3952. * @param {Function} func The function to apply a rest parameter to.
  3953. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3954. * @returns {Function} Returns the new function.
  3955. */
  3956. function baseRest(func, start) {
  3957. return setToString(overRest(func, start, identity), func + '');
  3958. }
  3959. /**
  3960. * The base implementation of `_.sample`.
  3961. *
  3962. * @private
  3963. * @param {Array|Object} collection The collection to sample.
  3964. * @returns {*} Returns the random element.
  3965. */
  3966. function baseSample(collection) {
  3967. return arraySample(values(collection));
  3968. }
  3969. /**
  3970. * The base implementation of `_.sampleSize` without param guards.
  3971. *
  3972. * @private
  3973. * @param {Array|Object} collection The collection to sample.
  3974. * @param {number} n The number of elements to sample.
  3975. * @returns {Array} Returns the random elements.
  3976. */
  3977. function baseSampleSize(collection, n) {
  3978. var array = values(collection);
  3979. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3980. }
  3981. /**
  3982. * The base implementation of `_.set`.
  3983. *
  3984. * @private
  3985. * @param {Object} object The object to modify.
  3986. * @param {Array|string} path The path of the property to set.
  3987. * @param {*} value The value to set.
  3988. * @param {Function} [customizer] The function to customize path creation.
  3989. * @returns {Object} Returns `object`.
  3990. */
  3991. function baseSet(object, path, value, customizer) {
  3992. if (!isObject(object)) {
  3993. return object;
  3994. }
  3995. path = castPath(path, object);
  3996. var index = -1,
  3997. length = path.length,
  3998. lastIndex = length - 1,
  3999. nested = object;
  4000. while (nested != null && ++index < length) {
  4001. var key = toKey(path[index]),
  4002. newValue = value;
  4003. if (index != lastIndex) {
  4004. var objValue = nested[key];
  4005. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  4006. if (newValue === undefined) {
  4007. newValue = isObject(objValue)
  4008. ? objValue
  4009. : isIndex(path[index + 1])
  4010. ? []
  4011. : {};
  4012. }
  4013. }
  4014. assignValue(nested, key, newValue);
  4015. nested = nested[key];
  4016. }
  4017. return object;
  4018. }
  4019. /**
  4020. * The base implementation of `setData` without support for hot loop shorting.
  4021. *
  4022. * @private
  4023. * @param {Function} func The function to associate metadata with.
  4024. * @param {*} data The metadata.
  4025. * @returns {Function} Returns `func`.
  4026. */
  4027. var baseSetData = !metaMap
  4028. ? identity
  4029. : function(func, data) {
  4030. metaMap.set(func, data);
  4031. return func;
  4032. };
  4033. /**
  4034. * The base implementation of `setToString` without support for hot loop shorting.
  4035. *
  4036. * @private
  4037. * @param {Function} func The function to modify.
  4038. * @param {Function} string The `toString` result.
  4039. * @returns {Function} Returns `func`.
  4040. */
  4041. var baseSetToString = !defineProperty
  4042. ? identity
  4043. : function(func, string) {
  4044. return defineProperty(func, 'toString', {
  4045. configurable: true,
  4046. enumerable: false,
  4047. value: constant(string),
  4048. writable: true
  4049. });
  4050. };
  4051. /**
  4052. * The base implementation of `_.shuffle`.
  4053. *
  4054. * @private
  4055. * @param {Array|Object} collection The collection to shuffle.
  4056. * @returns {Array} Returns the new shuffled array.
  4057. */
  4058. function baseShuffle(collection) {
  4059. return shuffleSelf(values(collection));
  4060. }
  4061. /**
  4062. * The base implementation of `_.slice` without an iteratee call guard.
  4063. *
  4064. * @private
  4065. * @param {Array} array The array to slice.
  4066. * @param {number} [start=0] The start position.
  4067. * @param {number} [end=array.length] The end position.
  4068. * @returns {Array} Returns the slice of `array`.
  4069. */
  4070. function baseSlice(array, start, end) {
  4071. var index = -1,
  4072. length = array.length;
  4073. if (start < 0) {
  4074. start = -start > length ? 0 : length + start;
  4075. }
  4076. end = end > length ? length : end;
  4077. if (end < 0) {
  4078. end += length;
  4079. }
  4080. length = start > end ? 0 : (end - start) >>> 0;
  4081. start >>>= 0;
  4082. var result = Array(length);
  4083. while (++index < length) {
  4084. result[index] = array[index + start];
  4085. }
  4086. return result;
  4087. }
  4088. /**
  4089. * The base implementation of `_.some` without support for iteratee shorthands.
  4090. *
  4091. * @private
  4092. * @param {Array|Object} collection The collection to iterate over.
  4093. * @param {Function} predicate The function invoked per iteration.
  4094. * @returns {boolean} Returns `true` if any element passes the predicate check,
  4095. * else `false`.
  4096. */
  4097. function baseSome(collection, predicate) {
  4098. var result;
  4099. baseEach(collection, function(value, index, collection) {
  4100. result = predicate(value, index, collection);
  4101. return !result;
  4102. });
  4103. return !!result;
  4104. }
  4105. /**
  4106. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  4107. * performs a binary search of `array` to determine the index at which `value`
  4108. * should be inserted into `array` in order to maintain its sort order.
  4109. *
  4110. * @private
  4111. * @param {Array} array The sorted array to inspect.
  4112. * @param {*} value The value to evaluate.
  4113. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  4114. * @returns {number} Returns the index at which `value` should be inserted
  4115. * into `array`.
  4116. */
  4117. function baseSortedIndex(array, value, retHighest) {
  4118. var low = 0,
  4119. high = array == null ? low : array.length;
  4120. if (
  4121. typeof value === 'number' &&
  4122. value === value &&
  4123. high <= HALF_MAX_ARRAY_LENGTH
  4124. ) {
  4125. while (low < high) {
  4126. var mid = (low + high) >>> 1,
  4127. computed = array[mid];
  4128. if (
  4129. computed !== null &&
  4130. !isSymbol(computed) &&
  4131. (retHighest ? computed <= value : computed < value)
  4132. ) {
  4133. low = mid + 1;
  4134. } else {
  4135. high = mid;
  4136. }
  4137. }
  4138. return high;
  4139. }
  4140. return baseSortedIndexBy(array, value, identity, retHighest);
  4141. }
  4142. /**
  4143. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  4144. * which invokes `iteratee` for `value` and each element of `array` to compute
  4145. * their sort ranking. The iteratee is invoked with one argument; (value).
  4146. *
  4147. * @private
  4148. * @param {Array} array The sorted array to inspect.
  4149. * @param {*} value The value to evaluate.
  4150. * @param {Function} iteratee The iteratee invoked per element.
  4151. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  4152. * @returns {number} Returns the index at which `value` should be inserted
  4153. * into `array`.
  4154. */
  4155. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  4156. value = iteratee(value);
  4157. var low = 0,
  4158. high = array == null ? 0 : array.length,
  4159. valIsNaN = value !== value,
  4160. valIsNull = value === null,
  4161. valIsSymbol = isSymbol(value),
  4162. valIsUndefined = value === undefined;
  4163. while (low < high) {
  4164. var mid = nativeFloor((low + high) / 2),
  4165. computed = iteratee(array[mid]),
  4166. othIsDefined = computed !== undefined,
  4167. othIsNull = computed === null,
  4168. othIsReflexive = computed === computed,
  4169. othIsSymbol = isSymbol(computed);
  4170. if (valIsNaN) {
  4171. var setLow = retHighest || othIsReflexive;
  4172. } else if (valIsUndefined) {
  4173. setLow = othIsReflexive && (retHighest || othIsDefined);
  4174. } else if (valIsNull) {
  4175. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  4176. } else if (valIsSymbol) {
  4177. setLow =
  4178. othIsReflexive &&
  4179. othIsDefined &&
  4180. !othIsNull &&
  4181. (retHighest || !othIsSymbol);
  4182. } else if (othIsNull || othIsSymbol) {
  4183. setLow = false;
  4184. } else {
  4185. setLow = retHighest ? computed <= value : computed < value;
  4186. }
  4187. if (setLow) {
  4188. low = mid + 1;
  4189. } else {
  4190. high = mid;
  4191. }
  4192. }
  4193. return nativeMin(high, MAX_ARRAY_INDEX);
  4194. }
  4195. /**
  4196. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  4197. * support for iteratee shorthands.
  4198. *
  4199. * @private
  4200. * @param {Array} array The array to inspect.
  4201. * @param {Function} [iteratee] The iteratee invoked per element.
  4202. * @returns {Array} Returns the new duplicate free array.
  4203. */
  4204. function baseSortedUniq(array, iteratee) {
  4205. var index = -1,
  4206. length = array.length,
  4207. resIndex = 0,
  4208. result = [];
  4209. while (++index < length) {
  4210. var value = array[index],
  4211. computed = iteratee ? iteratee(value) : value;
  4212. if (!index || !eq(computed, seen)) {
  4213. var seen = computed;
  4214. result[resIndex++] = value === 0 ? 0 : value;
  4215. }
  4216. }
  4217. return result;
  4218. }
  4219. /**
  4220. * The base implementation of `_.toNumber` which doesn't ensure correct
  4221. * conversions of binary, hexadecimal, or octal string values.
  4222. *
  4223. * @private
  4224. * @param {*} value The value to process.
  4225. * @returns {number} Returns the number.
  4226. */
  4227. function baseToNumber(value) {
  4228. if (typeof value === 'number') {
  4229. return value;
  4230. }
  4231. if (isSymbol(value)) {
  4232. return NAN;
  4233. }
  4234. return +value;
  4235. }
  4236. /**
  4237. * The base implementation of `_.toString` which doesn't convert nullish
  4238. * values to empty strings.
  4239. *
  4240. * @private
  4241. * @param {*} value The value to process.
  4242. * @returns {string} Returns the string.
  4243. */
  4244. function baseToString(value) {
  4245. // Exit early for strings to avoid a performance hit in some environments.
  4246. if (typeof value === 'string') {
  4247. return value;
  4248. }
  4249. if (isArray(value)) {
  4250. // Recursively convert values (susceptible to call stack limits).
  4251. return arrayMap(value, baseToString) + '';
  4252. }
  4253. if (isSymbol(value)) {
  4254. return symbolToString ? symbolToString.call(value) : '';
  4255. }
  4256. var result = value + '';
  4257. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  4258. }
  4259. /**
  4260. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  4261. *
  4262. * @private
  4263. * @param {Array} array The array to inspect.
  4264. * @param {Function} [iteratee] The iteratee invoked per element.
  4265. * @param {Function} [comparator] The comparator invoked per element.
  4266. * @returns {Array} Returns the new duplicate free array.
  4267. */
  4268. function baseUniq(array, iteratee, comparator) {
  4269. var index = -1,
  4270. includes = arrayIncludes,
  4271. length = array.length,
  4272. isCommon = true,
  4273. result = [],
  4274. seen = result;
  4275. if (comparator) {
  4276. isCommon = false;
  4277. includes = arrayIncludesWith;
  4278. } else if (length >= LARGE_ARRAY_SIZE) {
  4279. var set = iteratee ? null : createSet(array);
  4280. if (set) {
  4281. return setToArray(set);
  4282. }
  4283. isCommon = false;
  4284. includes = cacheHas;
  4285. seen = new SetCache();
  4286. } else {
  4287. seen = iteratee ? [] : result;
  4288. }
  4289. outer: while (++index < length) {
  4290. var value = array[index],
  4291. computed = iteratee ? iteratee(value) : value;
  4292. value = comparator || value !== 0 ? value : 0;
  4293. if (isCommon && computed === computed) {
  4294. var seenIndex = seen.length;
  4295. while (seenIndex--) {
  4296. if (seen[seenIndex] === computed) {
  4297. continue outer;
  4298. }
  4299. }
  4300. if (iteratee) {
  4301. seen.push(computed);
  4302. }
  4303. result.push(value);
  4304. } else if (!includes(seen, computed, comparator)) {
  4305. if (seen !== result) {
  4306. seen.push(computed);
  4307. }
  4308. result.push(value);
  4309. }
  4310. }
  4311. return result;
  4312. }
  4313. /**
  4314. * The base implementation of `_.unset`.
  4315. *
  4316. * @private
  4317. * @param {Object} object The object to modify.
  4318. * @param {Array|string} path The property path to unset.
  4319. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  4320. */
  4321. function baseUnset(object, path) {
  4322. path = castPath(path, object);
  4323. object = parent(object, path);
  4324. return object == null || delete object[toKey(last(path))];
  4325. }
  4326. /**
  4327. * The base implementation of `_.update`.
  4328. *
  4329. * @private
  4330. * @param {Object} object The object to modify.
  4331. * @param {Array|string} path The path of the property to update.
  4332. * @param {Function} updater The function to produce the updated value.
  4333. * @param {Function} [customizer] The function to customize path creation.
  4334. * @returns {Object} Returns `object`.
  4335. */
  4336. function baseUpdate(object, path, updater, customizer) {
  4337. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  4338. }
  4339. /**
  4340. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  4341. * without support for iteratee shorthands.
  4342. *
  4343. * @private
  4344. * @param {Array} array The array to query.
  4345. * @param {Function} predicate The function invoked per iteration.
  4346. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4347. * @param {boolean} [fromRight] Specify iterating from right to left.
  4348. * @returns {Array} Returns the slice of `array`.
  4349. */
  4350. function baseWhile(array, predicate, isDrop, fromRight) {
  4351. var length = array.length,
  4352. index = fromRight ? length : -1;
  4353. while (
  4354. (fromRight ? index-- : ++index < length) &&
  4355. predicate(array[index], index, array)
  4356. ) { }
  4357. return isDrop
  4358. ? baseSlice(
  4359. array,
  4360. fromRight ? 0 : index,
  4361. fromRight ? index + 1 : length
  4362. )
  4363. : baseSlice(
  4364. array,
  4365. fromRight ? index + 1 : 0,
  4366. fromRight ? length : index
  4367. );
  4368. }
  4369. /**
  4370. * The base implementation of `wrapperValue` which returns the result of
  4371. * performing a sequence of actions on the unwrapped `value`, where each
  4372. * successive action is supplied the return value of the previous.
  4373. *
  4374. * @private
  4375. * @param {*} value The unwrapped value.
  4376. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4377. * @returns {*} Returns the resolved value.
  4378. */
  4379. function baseWrapperValue(value, actions) {
  4380. var result = value;
  4381. if (result instanceof LazyWrapper) {
  4382. result = result.value();
  4383. }
  4384. return arrayReduce(
  4385. actions,
  4386. function(result, action) {
  4387. return action.func.apply(
  4388. action.thisArg,
  4389. arrayPush([result], action.args)
  4390. );
  4391. },
  4392. result
  4393. );
  4394. }
  4395. /**
  4396. * The base implementation of methods like `_.xor`, without support for
  4397. * iteratee shorthands, that accepts an array of arrays to inspect.
  4398. *
  4399. * @private
  4400. * @param {Array} arrays The arrays to inspect.
  4401. * @param {Function} [iteratee] The iteratee invoked per element.
  4402. * @param {Function} [comparator] The comparator invoked per element.
  4403. * @returns {Array} Returns the new array of values.
  4404. */
  4405. function baseXor(arrays, iteratee, comparator) {
  4406. var length = arrays.length;
  4407. if (length < 2) {
  4408. return length ? baseUniq(arrays[0]) : [];
  4409. }
  4410. var index = -1,
  4411. result = Array(length);
  4412. while (++index < length) {
  4413. var array = arrays[index],
  4414. othIndex = -1;
  4415. while (++othIndex < length) {
  4416. if (othIndex != index) {
  4417. result[index] = baseDifference(
  4418. result[index] || array,
  4419. arrays[othIndex],
  4420. iteratee,
  4421. comparator
  4422. );
  4423. }
  4424. }
  4425. }
  4426. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4427. }
  4428. /**
  4429. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4430. *
  4431. * @private
  4432. * @param {Array} props The property identifiers.
  4433. * @param {Array} values The property values.
  4434. * @param {Function} assignFunc The function to assign values.
  4435. * @returns {Object} Returns the new object.
  4436. */
  4437. function baseZipObject(props, values, assignFunc) {
  4438. var index = -1,
  4439. length = props.length,
  4440. valsLength = values.length,
  4441. result = {};
  4442. while (++index < length) {
  4443. var value = index < valsLength ? values[index] : undefined;
  4444. assignFunc(result, props[index], value);
  4445. }
  4446. return result;
  4447. }
  4448. /**
  4449. * Casts `value` to an empty array if it's not an array like object.
  4450. *
  4451. * @private
  4452. * @param {*} value The value to inspect.
  4453. * @returns {Array|Object} Returns the cast array-like object.
  4454. */
  4455. function castArrayLikeObject(value) {
  4456. return isArrayLikeObject(value) ? value : [];
  4457. }
  4458. /**
  4459. * Casts `value` to `identity` if it's not a function.
  4460. *
  4461. * @private
  4462. * @param {*} value The value to inspect.
  4463. * @returns {Function} Returns cast function.
  4464. */
  4465. function castFunction(value) {
  4466. return typeof value === 'function' ? value : identity;
  4467. }
  4468. /**
  4469. * Casts `value` to a path array if it's not one.
  4470. *
  4471. * @private
  4472. * @param {*} value The value to inspect.
  4473. * @param {Object} [object] The object to query keys on.
  4474. * @returns {Array} Returns the cast property path array.
  4475. */
  4476. function castPath(value, object) {
  4477. if (isArray(value)) {
  4478. return value;
  4479. }
  4480. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4481. }
  4482. /**
  4483. * A `baseRest` alias which can be replaced with `identity` by module
  4484. * replacement plugins.
  4485. *
  4486. * @private
  4487. * @type {Function}
  4488. * @param {Function} func The function to apply a rest parameter to.
  4489. * @returns {Function} Returns the new function.
  4490. */
  4491. var castRest = baseRest;
  4492. /**
  4493. * Casts `array` to a slice if it's needed.
  4494. *
  4495. * @private
  4496. * @param {Array} array The array to inspect.
  4497. * @param {number} start The start position.
  4498. * @param {number} [end=array.length] The end position.
  4499. * @returns {Array} Returns the cast slice.
  4500. */
  4501. function castSlice(array, start, end) {
  4502. var length = array.length;
  4503. end = end === undefined ? length : end;
  4504. return !start && end >= length ? array : baseSlice(array, start, end);
  4505. }
  4506. /**
  4507. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4508. *
  4509. * @private
  4510. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4511. */
  4512. var clearTimeout =
  4513. ctxClearTimeout ||
  4514. function(id) {
  4515. return root.clearTimeout(id);
  4516. };
  4517. /**
  4518. * Creates a clone of `buffer`.
  4519. *
  4520. * @private
  4521. * @param {Buffer} buffer The buffer to clone.
  4522. * @param {boolean} [isDeep] Specify a deep clone.
  4523. * @returns {Buffer} Returns the cloned buffer.
  4524. */
  4525. function cloneBuffer(buffer, isDeep) {
  4526. if (isDeep) {
  4527. return buffer.slice();
  4528. }
  4529. var length = buffer.length,
  4530. result = allocUnsafe
  4531. ? allocUnsafe(length)
  4532. : new buffer.constructor(length);
  4533. buffer.copy(result);
  4534. return result;
  4535. }
  4536. /**
  4537. * Creates a clone of `arrayBuffer`.
  4538. *
  4539. * @private
  4540. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4541. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4542. */
  4543. function cloneArrayBuffer(arrayBuffer) {
  4544. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4545. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4546. return result;
  4547. }
  4548. /**
  4549. * Creates a clone of `dataView`.
  4550. *
  4551. * @private
  4552. * @param {Object} dataView The data view to clone.
  4553. * @param {boolean} [isDeep] Specify a deep clone.
  4554. * @returns {Object} Returns the cloned data view.
  4555. */
  4556. function cloneDataView(dataView, isDeep) {
  4557. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4558. return new dataView.constructor(
  4559. buffer,
  4560. dataView.byteOffset,
  4561. dataView.byteLength
  4562. );
  4563. }
  4564. /**
  4565. * Creates a clone of `regexp`.
  4566. *
  4567. * @private
  4568. * @param {Object} regexp The regexp to clone.
  4569. * @returns {Object} Returns the cloned regexp.
  4570. */
  4571. function cloneRegExp(regexp) {
  4572. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4573. result.lastIndex = regexp.lastIndex;
  4574. return result;
  4575. }
  4576. /**
  4577. * Creates a clone of the `symbol` object.
  4578. *
  4579. * @private
  4580. * @param {Object} symbol The symbol object to clone.
  4581. * @returns {Object} Returns the cloned symbol object.
  4582. */
  4583. function cloneSymbol(symbol) {
  4584. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4585. }
  4586. /**
  4587. * Creates a clone of `typedArray`.
  4588. *
  4589. * @private
  4590. * @param {Object} typedArray The typed array to clone.
  4591. * @param {boolean} [isDeep] Specify a deep clone.
  4592. * @returns {Object} Returns the cloned typed array.
  4593. */
  4594. function cloneTypedArray(typedArray, isDeep) {
  4595. var buffer = isDeep
  4596. ? cloneArrayBuffer(typedArray.buffer)
  4597. : typedArray.buffer;
  4598. return new typedArray.constructor(
  4599. buffer,
  4600. typedArray.byteOffset,
  4601. typedArray.length
  4602. );
  4603. }
  4604. /**
  4605. * Compares values to sort them in ascending order.
  4606. *
  4607. * @private
  4608. * @param {*} value The value to compare.
  4609. * @param {*} other The other value to compare.
  4610. * @returns {number} Returns the sort order indicator for `value`.
  4611. */
  4612. function compareAscending(value, other) {
  4613. if (value !== other) {
  4614. var valIsDefined = value !== undefined,
  4615. valIsNull = value === null,
  4616. valIsReflexive = value === value,
  4617. valIsSymbol = isSymbol(value);
  4618. var othIsDefined = other !== undefined,
  4619. othIsNull = other === null,
  4620. othIsReflexive = other === other,
  4621. othIsSymbol = isSymbol(other);
  4622. if (
  4623. (!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4624. (valIsSymbol &&
  4625. othIsDefined &&
  4626. othIsReflexive &&
  4627. !othIsNull &&
  4628. !othIsSymbol) ||
  4629. (valIsNull && othIsDefined && othIsReflexive) ||
  4630. (!valIsDefined && othIsReflexive) ||
  4631. !valIsReflexive
  4632. ) {
  4633. return 1;
  4634. }
  4635. if (
  4636. (!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4637. (othIsSymbol &&
  4638. valIsDefined &&
  4639. valIsReflexive &&
  4640. !valIsNull &&
  4641. !valIsSymbol) ||
  4642. (othIsNull && valIsDefined && valIsReflexive) ||
  4643. (!othIsDefined && valIsReflexive) ||
  4644. !othIsReflexive
  4645. ) {
  4646. return -1;
  4647. }
  4648. }
  4649. return 0;
  4650. }
  4651. /**
  4652. * Used by `_.orderBy` to compare multiple properties of a value to another
  4653. * and stable sort them.
  4654. *
  4655. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4656. * specify an order of "desc" for descending or "asc" for ascending sort order
  4657. * of corresponding values.
  4658. *
  4659. * @private
  4660. * @param {Object} object The object to compare.
  4661. * @param {Object} other The other object to compare.
  4662. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4663. * @returns {number} Returns the sort order indicator for `object`.
  4664. */
  4665. function compareMultiple(object, other, orders) {
  4666. var index = -1,
  4667. objCriteria = object.criteria,
  4668. othCriteria = other.criteria,
  4669. length = objCriteria.length,
  4670. ordersLength = orders.length;
  4671. while (++index < length) {
  4672. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4673. if (result) {
  4674. if (index >= ordersLength) {
  4675. return result;
  4676. }
  4677. var order = orders[index];
  4678. return result * (order == 'desc' ? -1 : 1);
  4679. }
  4680. }
  4681. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4682. // that causes it, under certain circumstances, to provide the same value for
  4683. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4684. // for more details.
  4685. //
  4686. // This also ensures a stable sort in V8 and other engines.
  4687. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4688. return object.index - other.index;
  4689. }
  4690. /**
  4691. * Creates an array that is the composition of partially applied arguments,
  4692. * placeholders, and provided arguments into a single array of arguments.
  4693. *
  4694. * @private
  4695. * @param {Array} args The provided arguments.
  4696. * @param {Array} partials The arguments to prepend to those provided.
  4697. * @param {Array} holders The `partials` placeholder indexes.
  4698. * @params {boolean} [isCurried] Specify composing for a curried function.
  4699. * @returns {Array} Returns the new array of composed arguments.
  4700. */
  4701. function composeArgs(args, partials, holders, isCurried) {
  4702. var argsIndex = -1,
  4703. argsLength = args.length,
  4704. holdersLength = holders.length,
  4705. leftIndex = -1,
  4706. leftLength = partials.length,
  4707. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4708. result = Array(leftLength + rangeLength),
  4709. isUncurried = !isCurried;
  4710. while (++leftIndex < leftLength) {
  4711. result[leftIndex] = partials[leftIndex];
  4712. }
  4713. while (++argsIndex < holdersLength) {
  4714. if (isUncurried || argsIndex < argsLength) {
  4715. result[holders[argsIndex]] = args[argsIndex];
  4716. }
  4717. }
  4718. while (rangeLength--) {
  4719. result[leftIndex++] = args[argsIndex++];
  4720. }
  4721. return result;
  4722. }
  4723. /**
  4724. * This function is like `composeArgs` except that the arguments composition
  4725. * is tailored for `_.partialRight`.
  4726. *
  4727. * @private
  4728. * @param {Array} args The provided arguments.
  4729. * @param {Array} partials The arguments to append to those provided.
  4730. * @param {Array} holders The `partials` placeholder indexes.
  4731. * @params {boolean} [isCurried] Specify composing for a curried function.
  4732. * @returns {Array} Returns the new array of composed arguments.
  4733. */
  4734. function composeArgsRight(args, partials, holders, isCurried) {
  4735. var argsIndex = -1,
  4736. argsLength = args.length,
  4737. holdersIndex = -1,
  4738. holdersLength = holders.length,
  4739. rightIndex = -1,
  4740. rightLength = partials.length,
  4741. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4742. result = Array(rangeLength + rightLength),
  4743. isUncurried = !isCurried;
  4744. while (++argsIndex < rangeLength) {
  4745. result[argsIndex] = args[argsIndex];
  4746. }
  4747. var offset = argsIndex;
  4748. while (++rightIndex < rightLength) {
  4749. result[offset + rightIndex] = partials[rightIndex];
  4750. }
  4751. while (++holdersIndex < holdersLength) {
  4752. if (isUncurried || argsIndex < argsLength) {
  4753. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4754. }
  4755. }
  4756. return result;
  4757. }
  4758. /**
  4759. * Copies the values of `source` to `array`.
  4760. *
  4761. * @private
  4762. * @param {Array} source The array to copy values from.
  4763. * @param {Array} [array=[]] The array to copy values to.
  4764. * @returns {Array} Returns `array`.
  4765. */
  4766. function copyArray(source, array) {
  4767. var index = -1,
  4768. length = source.length;
  4769. array || (array = Array(length));
  4770. while (++index < length) {
  4771. array[index] = source[index];
  4772. }
  4773. return array;
  4774. }
  4775. /**
  4776. * Copies properties of `source` to `object`.
  4777. *
  4778. * @private
  4779. * @param {Object} source The object to copy properties from.
  4780. * @param {Array} props The property identifiers to copy.
  4781. * @param {Object} [object={}] The object to copy properties to.
  4782. * @param {Function} [customizer] The function to customize copied values.
  4783. * @returns {Object} Returns `object`.
  4784. */
  4785. function copyObject(source, props, object, customizer) {
  4786. var isNew = !object;
  4787. object || (object = {});
  4788. var index = -1,
  4789. length = props.length;
  4790. while (++index < length) {
  4791. var key = props[index];
  4792. var newValue = customizer
  4793. ? customizer(object[key], source[key], key, object, source)
  4794. : undefined;
  4795. if (newValue === undefined) {
  4796. newValue = source[key];
  4797. }
  4798. if (isNew) {
  4799. baseAssignValue(object, key, newValue);
  4800. } else {
  4801. assignValue(object, key, newValue);
  4802. }
  4803. }
  4804. return object;
  4805. }
  4806. /**
  4807. * Copies own symbols of `source` to `object`.
  4808. *
  4809. * @private
  4810. * @param {Object} source The object to copy symbols from.
  4811. * @param {Object} [object={}] The object to copy symbols to.
  4812. * @returns {Object} Returns `object`.
  4813. */
  4814. function copySymbols(source, object) {
  4815. return copyObject(source, getSymbols(source), object);
  4816. }
  4817. /**
  4818. * Copies own and inherited symbols of `source` to `object`.
  4819. *
  4820. * @private
  4821. * @param {Object} source The object to copy symbols from.
  4822. * @param {Object} [object={}] The object to copy symbols to.
  4823. * @returns {Object} Returns `object`.
  4824. */
  4825. function copySymbolsIn(source, object) {
  4826. return copyObject(source, getSymbolsIn(source), object);
  4827. }
  4828. /**
  4829. * Creates a function like `_.groupBy`.
  4830. *
  4831. * @private
  4832. * @param {Function} setter The function to set accumulator values.
  4833. * @param {Function} [initializer] The accumulator object initializer.
  4834. * @returns {Function} Returns the new aggregator function.
  4835. */
  4836. function createAggregator(setter, initializer) {
  4837. return function(collection, iteratee) {
  4838. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4839. accumulator = initializer ? initializer() : {};
  4840. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4841. };
  4842. }
  4843. /**
  4844. * Creates a function like `_.assign`.
  4845. *
  4846. * @private
  4847. * @param {Function} assigner The function to assign values.
  4848. * @returns {Function} Returns the new assigner function.
  4849. */
  4850. function createAssigner(assigner) {
  4851. return baseRest(function(object, sources) {
  4852. var index = -1,
  4853. length = sources.length,
  4854. customizer = length > 1 ? sources[length - 1] : undefined,
  4855. guard = length > 2 ? sources[2] : undefined;
  4856. customizer =
  4857. assigner.length > 3 && typeof customizer === 'function'
  4858. ? (length--, customizer)
  4859. : undefined;
  4860. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4861. customizer = length < 3 ? undefined : customizer;
  4862. length = 1;
  4863. }
  4864. object = Object(object);
  4865. while (++index < length) {
  4866. var source = sources[index];
  4867. if (source) {
  4868. assigner(object, source, index, customizer);
  4869. }
  4870. }
  4871. return object;
  4872. });
  4873. }
  4874. /**
  4875. * Creates a `baseEach` or `baseEachRight` function.
  4876. *
  4877. * @private
  4878. * @param {Function} eachFunc The function to iterate over a collection.
  4879. * @param {boolean} [fromRight] Specify iterating from right to left.
  4880. * @returns {Function} Returns the new base function.
  4881. */
  4882. function createBaseEach(eachFunc, fromRight) {
  4883. return function(collection, iteratee) {
  4884. if (collection == null) {
  4885. return collection;
  4886. }
  4887. if (!isArrayLike(collection)) {
  4888. return eachFunc(collection, iteratee);
  4889. }
  4890. var length = collection.length,
  4891. index = fromRight ? length : -1,
  4892. iterable = Object(collection);
  4893. while (fromRight ? index-- : ++index < length) {
  4894. if (iteratee(iterable[index], index, iterable) === false) {
  4895. break;
  4896. }
  4897. }
  4898. return collection;
  4899. };
  4900. }
  4901. /**
  4902. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4903. *
  4904. * @private
  4905. * @param {boolean} [fromRight] Specify iterating from right to left.
  4906. * @returns {Function} Returns the new base function.
  4907. */
  4908. function createBaseFor(fromRight) {
  4909. return function(object, iteratee, keysFunc) {
  4910. var index = -1,
  4911. iterable = Object(object),
  4912. props = keysFunc(object),
  4913. length = props.length;
  4914. while (length--) {
  4915. var key = props[fromRight ? length : ++index];
  4916. if (iteratee(iterable[key], key, iterable) === false) {
  4917. break;
  4918. }
  4919. }
  4920. return object;
  4921. };
  4922. }
  4923. /**
  4924. * Creates a function that wraps `func` to invoke it with the optional `this`
  4925. * binding of `thisArg`.
  4926. *
  4927. * @private
  4928. * @param {Function} func The function to wrap.
  4929. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4930. * @param {*} [thisArg] The `this` binding of `func`.
  4931. * @returns {Function} Returns the new wrapped function.
  4932. */
  4933. function createBind(func, bitmask, thisArg) {
  4934. var isBind = bitmask & WRAP_BIND_FLAG,
  4935. Ctor = createCtor(func);
  4936. function wrapper() {
  4937. var fn = this && this !== root && this instanceof wrapper ? Ctor : func;
  4938. return fn.apply(isBind ? thisArg : this, arguments);
  4939. }
  4940. return wrapper;
  4941. }
  4942. /**
  4943. * Creates a function like `_.lowerFirst`.
  4944. *
  4945. * @private
  4946. * @param {string} methodName The name of the `String` case method to use.
  4947. * @returns {Function} Returns the new case function.
  4948. */
  4949. function createCaseFirst(methodName) {
  4950. return function(string) {
  4951. string = toString(string);
  4952. var strSymbols = hasUnicode(string) ? stringToArray(string) : undefined;
  4953. var chr = strSymbols ? strSymbols[0] : string.charAt(0);
  4954. var trailing = strSymbols
  4955. ? castSlice(strSymbols, 1).join('')
  4956. : string.slice(1);
  4957. return chr[methodName]() + trailing;
  4958. };
  4959. }
  4960. /**
  4961. * Creates a function like `_.camelCase`.
  4962. *
  4963. * @private
  4964. * @param {Function} callback The function to combine each word.
  4965. * @returns {Function} Returns the new compounder function.
  4966. */
  4967. function createCompounder(callback) {
  4968. return function(string) {
  4969. return arrayReduce(
  4970. words(deburr(string).replace(reApos, '')),
  4971. callback,
  4972. ''
  4973. );
  4974. };
  4975. }
  4976. /**
  4977. * Creates a function that produces an instance of `Ctor` regardless of
  4978. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4979. *
  4980. * @private
  4981. * @param {Function} Ctor The constructor to wrap.
  4982. * @returns {Function} Returns the new wrapped function.
  4983. */
  4984. function createCtor(Ctor) {
  4985. return function() {
  4986. // Use a `switch` statement to work with class constructors. See
  4987. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4988. // for more details.
  4989. var args = arguments;
  4990. switch (args.length) {
  4991. case 0:
  4992. return new Ctor();
  4993. case 1:
  4994. return new Ctor(args[0]);
  4995. case 2:
  4996. return new Ctor(args[0], args[1]);
  4997. case 3:
  4998. return new Ctor(args[0], args[1], args[2]);
  4999. case 4:
  5000. return new Ctor(args[0], args[1], args[2], args[3]);
  5001. case 5:
  5002. return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  5003. case 6:
  5004. return new Ctor(
  5005. args[0],
  5006. args[1],
  5007. args[2],
  5008. args[3],
  5009. args[4],
  5010. args[5]
  5011. );
  5012. case 7:
  5013. return new Ctor(
  5014. args[0],
  5015. args[1],
  5016. args[2],
  5017. args[3],
  5018. args[4],
  5019. args[5],
  5020. args[6]
  5021. );
  5022. }
  5023. var thisBinding = baseCreate(Ctor.prototype),
  5024. result = Ctor.apply(thisBinding, args);
  5025. // Mimic the constructor's `return` behavior.
  5026. // See https://es5.github.io/#x13.2.2 for more details.
  5027. return isObject(result) ? result : thisBinding;
  5028. };
  5029. }
  5030. /**
  5031. * Creates a function that wraps `func` to enable currying.
  5032. *
  5033. * @private
  5034. * @param {Function} func The function to wrap.
  5035. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5036. * @param {number} arity The arity of `func`.
  5037. * @returns {Function} Returns the new wrapped function.
  5038. */
  5039. function createCurry(func, bitmask, arity) {
  5040. var Ctor = createCtor(func);
  5041. function wrapper() {
  5042. var length = arguments.length,
  5043. args = Array(length),
  5044. index = length,
  5045. placeholder = getHolder(wrapper);
  5046. while (index--) {
  5047. args[index] = arguments[index];
  5048. }
  5049. var holders =
  5050. length < 3 &&
  5051. args[0] !== placeholder &&
  5052. args[length - 1] !== placeholder
  5053. ? []
  5054. : replaceHolders(args, placeholder);
  5055. length -= holders.length;
  5056. if (length < arity) {
  5057. return createRecurry(
  5058. func,
  5059. bitmask,
  5060. createHybrid,
  5061. wrapper.placeholder,
  5062. undefined,
  5063. args,
  5064. holders,
  5065. undefined,
  5066. undefined,
  5067. arity - length
  5068. );
  5069. }
  5070. var fn = this && this !== root && this instanceof wrapper ? Ctor : func;
  5071. return apply(fn, this, args);
  5072. }
  5073. return wrapper;
  5074. }
  5075. /**
  5076. * Creates a `_.find` or `_.findLast` function.
  5077. *
  5078. * @private
  5079. * @param {Function} findIndexFunc The function to find the collection index.
  5080. * @returns {Function} Returns the new find function.
  5081. */
  5082. function createFind(findIndexFunc) {
  5083. return function(collection, predicate, fromIndex) {
  5084. var iterable = Object(collection);
  5085. if (!isArrayLike(collection)) {
  5086. var iteratee = getIteratee(predicate, 3);
  5087. collection = keys(collection);
  5088. predicate = function(key) {
  5089. return iteratee(iterable[key], key, iterable);
  5090. };
  5091. }
  5092. var index = findIndexFunc(collection, predicate, fromIndex);
  5093. return index > -1
  5094. ? iterable[iteratee ? collection[index] : index]
  5095. : undefined;
  5096. };
  5097. }
  5098. /**
  5099. * Creates a `_.flow` or `_.flowRight` function.
  5100. *
  5101. * @private
  5102. * @param {boolean} [fromRight] Specify iterating from right to left.
  5103. * @returns {Function} Returns the new flow function.
  5104. */
  5105. function createFlow(fromRight) {
  5106. return flatRest(function(funcs) {
  5107. var length = funcs.length,
  5108. index = length,
  5109. prereq = LodashWrapper.prototype.thru;
  5110. if (fromRight) {
  5111. funcs.reverse();
  5112. }
  5113. while (index--) {
  5114. var func = funcs[index];
  5115. if (typeof func !== 'function') {
  5116. throw new TypeError(FUNC_ERROR_TEXT);
  5117. }
  5118. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  5119. var wrapper = new LodashWrapper([], true);
  5120. }
  5121. }
  5122. index = wrapper ? index : length;
  5123. while (++index < length) {
  5124. func = funcs[index];
  5125. var funcName = getFuncName(func),
  5126. data = funcName == 'wrapper' ? getData(func) : undefined;
  5127. if (
  5128. data &&
  5129. isLaziable(data[0]) &&
  5130. data[1] ==
  5131. (WRAP_ARY_FLAG |
  5132. WRAP_CURRY_FLAG |
  5133. WRAP_PARTIAL_FLAG |
  5134. WRAP_REARG_FLAG) &&
  5135. !data[4].length &&
  5136. data[9] == 1
  5137. ) {
  5138. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  5139. } else {
  5140. wrapper =
  5141. func.length == 1 && isLaziable(func)
  5142. ? wrapper[funcName]()
  5143. : wrapper.thru(func);
  5144. }
  5145. }
  5146. return function() {
  5147. var args = arguments,
  5148. value = args[0];
  5149. if (wrapper && args.length == 1 && isArray(value)) {
  5150. return wrapper.plant(value).value();
  5151. }
  5152. var index = 0,
  5153. result = length ? funcs[index].apply(this, args) : value;
  5154. while (++index < length) {
  5155. result = funcs[index].call(this, result);
  5156. }
  5157. return result;
  5158. };
  5159. });
  5160. }
  5161. /**
  5162. * Creates a function that wraps `func` to invoke it with optional `this`
  5163. * binding of `thisArg`, partial application, and currying.
  5164. *
  5165. * @private
  5166. * @param {Function|string} func The function or method name to wrap.
  5167. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5168. * @param {*} [thisArg] The `this` binding of `func`.
  5169. * @param {Array} [partials] The arguments to prepend to those provided to
  5170. * the new function.
  5171. * @param {Array} [holders] The `partials` placeholder indexes.
  5172. * @param {Array} [partialsRight] The arguments to append to those provided
  5173. * to the new function.
  5174. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  5175. * @param {Array} [argPos] The argument positions of the new function.
  5176. * @param {number} [ary] The arity cap of `func`.
  5177. * @param {number} [arity] The arity of `func`.
  5178. * @returns {Function} Returns the new wrapped function.
  5179. */
  5180. function createHybrid(
  5181. func,
  5182. bitmask,
  5183. thisArg,
  5184. partials,
  5185. holders,
  5186. partialsRight,
  5187. holdersRight,
  5188. argPos,
  5189. ary,
  5190. arity
  5191. ) {
  5192. var isAry = bitmask & WRAP_ARY_FLAG,
  5193. isBind = bitmask & WRAP_BIND_FLAG,
  5194. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  5195. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  5196. isFlip = bitmask & WRAP_FLIP_FLAG,
  5197. Ctor = isBindKey ? undefined : createCtor(func);
  5198. function wrapper() {
  5199. var length = arguments.length,
  5200. args = Array(length),
  5201. index = length;
  5202. while (index--) {
  5203. args[index] = arguments[index];
  5204. }
  5205. if (isCurried) {
  5206. var placeholder = getHolder(wrapper),
  5207. holdersCount = countHolders(args, placeholder);
  5208. }
  5209. if (partials) {
  5210. args = composeArgs(args, partials, holders, isCurried);
  5211. }
  5212. if (partialsRight) {
  5213. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  5214. }
  5215. length -= holdersCount;
  5216. if (isCurried && length < arity) {
  5217. var newHolders = replaceHolders(args, placeholder);
  5218. return createRecurry(
  5219. func,
  5220. bitmask,
  5221. createHybrid,
  5222. wrapper.placeholder,
  5223. thisArg,
  5224. args,
  5225. newHolders,
  5226. argPos,
  5227. ary,
  5228. arity - length
  5229. );
  5230. }
  5231. var thisBinding = isBind ? thisArg : this,
  5232. fn = isBindKey ? thisBinding[func] : func;
  5233. length = args.length;
  5234. if (argPos) {
  5235. args = reorder(args, argPos);
  5236. } else if (isFlip && length > 1) {
  5237. args.reverse();
  5238. }
  5239. if (isAry && ary < length) {
  5240. args.length = ary;
  5241. }
  5242. if (this && this !== root && this instanceof wrapper) {
  5243. fn = Ctor || createCtor(fn);
  5244. }
  5245. return fn.apply(thisBinding, args);
  5246. }
  5247. return wrapper;
  5248. }
  5249. /**
  5250. * Creates a function like `_.invertBy`.
  5251. *
  5252. * @private
  5253. * @param {Function} setter The function to set accumulator values.
  5254. * @param {Function} toIteratee The function to resolve iteratees.
  5255. * @returns {Function} Returns the new inverter function.
  5256. */
  5257. function createInverter(setter, toIteratee) {
  5258. return function(object, iteratee) {
  5259. return baseInverter(object, setter, toIteratee(iteratee), {});
  5260. };
  5261. }
  5262. /**
  5263. * Creates a function that performs a mathematical operation on two values.
  5264. *
  5265. * @private
  5266. * @param {Function} operator The function to perform the operation.
  5267. * @param {number} [defaultValue] The value used for `undefined` arguments.
  5268. * @returns {Function} Returns the new mathematical operation function.
  5269. */
  5270. function createMathOperation(operator, defaultValue) {
  5271. return function(value, other) {
  5272. var result;
  5273. if (value === undefined && other === undefined) {
  5274. return defaultValue;
  5275. }
  5276. if (value !== undefined) {
  5277. result = value;
  5278. }
  5279. if (other !== undefined) {
  5280. if (result === undefined) {
  5281. return other;
  5282. }
  5283. if (typeof value === 'string' || typeof other === 'string') {
  5284. value = baseToString(value);
  5285. other = baseToString(other);
  5286. } else {
  5287. value = baseToNumber(value);
  5288. other = baseToNumber(other);
  5289. }
  5290. result = operator(value, other);
  5291. }
  5292. return result;
  5293. };
  5294. }
  5295. /**
  5296. * Creates a function like `_.over`.
  5297. *
  5298. * @private
  5299. * @param {Function} arrayFunc The function to iterate over iteratees.
  5300. * @returns {Function} Returns the new over function.
  5301. */
  5302. function createOver(arrayFunc) {
  5303. return flatRest(function(iteratees) {
  5304. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  5305. return baseRest(function(args) {
  5306. var thisArg = this;
  5307. return arrayFunc(iteratees, function(iteratee) {
  5308. return apply(iteratee, thisArg, args);
  5309. });
  5310. });
  5311. });
  5312. }
  5313. /**
  5314. * Creates the padding for `string` based on `length`. The `chars` string
  5315. * is truncated if the number of characters exceeds `length`.
  5316. *
  5317. * @private
  5318. * @param {number} length The padding length.
  5319. * @param {string} [chars=' '] The string used as padding.
  5320. * @returns {string} Returns the padding for `string`.
  5321. */
  5322. function createPadding(length, chars) {
  5323. chars = chars === undefined ? ' ' : baseToString(chars);
  5324. var charsLength = chars.length;
  5325. if (charsLength < 2) {
  5326. return charsLength ? baseRepeat(chars, length) : chars;
  5327. }
  5328. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  5329. return hasUnicode(chars)
  5330. ? castSlice(stringToArray(result), 0, length).join('')
  5331. : result.slice(0, length);
  5332. }
  5333. /**
  5334. * Creates a function that wraps `func` to invoke it with the `this` binding
  5335. * of `thisArg` and `partials` prepended to the arguments it receives.
  5336. *
  5337. * @private
  5338. * @param {Function} func The function to wrap.
  5339. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5340. * @param {*} thisArg The `this` binding of `func`.
  5341. * @param {Array} partials The arguments to prepend to those provided to
  5342. * the new function.
  5343. * @returns {Function} Returns the new wrapped function.
  5344. */
  5345. function createPartial(func, bitmask, thisArg, partials) {
  5346. var isBind = bitmask & WRAP_BIND_FLAG,
  5347. Ctor = createCtor(func);
  5348. function wrapper() {
  5349. var argsIndex = -1,
  5350. argsLength = arguments.length,
  5351. leftIndex = -1,
  5352. leftLength = partials.length,
  5353. args = Array(leftLength + argsLength),
  5354. fn = this && this !== root && this instanceof wrapper ? Ctor : func;
  5355. while (++leftIndex < leftLength) {
  5356. args[leftIndex] = partials[leftIndex];
  5357. }
  5358. while (argsLength--) {
  5359. args[leftIndex++] = arguments[++argsIndex];
  5360. }
  5361. return apply(fn, isBind ? thisArg : this, args);
  5362. }
  5363. return wrapper;
  5364. }
  5365. /**
  5366. * Creates a `_.range` or `_.rangeRight` function.
  5367. *
  5368. * @private
  5369. * @param {boolean} [fromRight] Specify iterating from right to left.
  5370. * @returns {Function} Returns the new range function.
  5371. */
  5372. function createRange(fromRight) {
  5373. return function(start, end, step) {
  5374. if (
  5375. step &&
  5376. typeof step !== 'number' &&
  5377. isIterateeCall(start, end, step)
  5378. ) {
  5379. end = step = undefined;
  5380. }
  5381. // Ensure the sign of `-0` is preserved.
  5382. start = toFinite(start);
  5383. if (end === undefined) {
  5384. end = start;
  5385. start = 0;
  5386. } else {
  5387. end = toFinite(end);
  5388. }
  5389. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  5390. return baseRange(start, end, step, fromRight);
  5391. };
  5392. }
  5393. /**
  5394. * Creates a function that performs a relational operation on two values.
  5395. *
  5396. * @private
  5397. * @param {Function} operator The function to perform the operation.
  5398. * @returns {Function} Returns the new relational operation function.
  5399. */
  5400. function createRelationalOperation(operator) {
  5401. return function(value, other) {
  5402. if (!(typeof value === 'string' && typeof other === 'string')) {
  5403. value = toNumber(value);
  5404. other = toNumber(other);
  5405. }
  5406. return operator(value, other);
  5407. };
  5408. }
  5409. /**
  5410. * Creates a function that wraps `func` to continue currying.
  5411. *
  5412. * @private
  5413. * @param {Function} func The function to wrap.
  5414. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5415. * @param {Function} wrapFunc The function to create the `func` wrapper.
  5416. * @param {*} placeholder The placeholder value.
  5417. * @param {*} [thisArg] The `this` binding of `func`.
  5418. * @param {Array} [partials] The arguments to prepend to those provided to
  5419. * the new function.
  5420. * @param {Array} [holders] The `partials` placeholder indexes.
  5421. * @param {Array} [argPos] The argument positions of the new function.
  5422. * @param {number} [ary] The arity cap of `func`.
  5423. * @param {number} [arity] The arity of `func`.
  5424. * @returns {Function} Returns the new wrapped function.
  5425. */
  5426. function createRecurry(
  5427. func,
  5428. bitmask,
  5429. wrapFunc,
  5430. placeholder,
  5431. thisArg,
  5432. partials,
  5433. holders,
  5434. argPos,
  5435. ary,
  5436. arity
  5437. ) {
  5438. var isCurry = bitmask & WRAP_CURRY_FLAG,
  5439. newHolders = isCurry ? holders : undefined,
  5440. newHoldersRight = isCurry ? undefined : holders,
  5441. newPartials = isCurry ? partials : undefined,
  5442. newPartialsRight = isCurry ? undefined : partials;
  5443. bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
  5444. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  5445. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  5446. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  5447. }
  5448. var newData = [
  5449. func,
  5450. bitmask,
  5451. thisArg,
  5452. newPartials,
  5453. newHolders,
  5454. newPartialsRight,
  5455. newHoldersRight,
  5456. argPos,
  5457. ary,
  5458. arity
  5459. ];
  5460. var result = wrapFunc.apply(undefined, newData);
  5461. if (isLaziable(func)) {
  5462. setData(result, newData);
  5463. }
  5464. result.placeholder = placeholder;
  5465. return setWrapToString(result, func, bitmask);
  5466. }
  5467. /**
  5468. * Creates a function like `_.round`.
  5469. *
  5470. * @private
  5471. * @param {string} methodName The name of the `Math` method to use when rounding.
  5472. * @returns {Function} Returns the new round function.
  5473. */
  5474. function createRound(methodName) {
  5475. var func = Math[methodName];
  5476. return function(number, precision) {
  5477. number = toNumber(number);
  5478. precision =
  5479. precision == null ? 0 : nativeMin(toInteger(precision), 292);
  5480. if (precision) {
  5481. // Shift with exponential notation to avoid floating-point issues.
  5482. // See [MDN](https://mdn.io/round#Examples) for more details.
  5483. var pair = (toString(number) + 'e').split('e'),
  5484. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5485. pair = (toString(value) + 'e').split('e');
  5486. return +(pair[0] + 'e' + (+pair[1] - precision));
  5487. }
  5488. return func(number);
  5489. };
  5490. }
  5491. /**
  5492. * Creates a set object of `values`.
  5493. *
  5494. * @private
  5495. * @param {Array} values The values to add to the set.
  5496. * @returns {Object} Returns the new set.
  5497. */
  5498. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY)
  5499. ? noop
  5500. : function(values) {
  5501. return new Set(values);
  5502. };
  5503. /**
  5504. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5505. *
  5506. * @private
  5507. * @param {Function} keysFunc The function to get the keys of a given object.
  5508. * @returns {Function} Returns the new pairs function.
  5509. */
  5510. function createToPairs(keysFunc) {
  5511. return function(object) {
  5512. var tag = getTag(object);
  5513. if (tag == mapTag) {
  5514. return mapToArray(object);
  5515. }
  5516. if (tag == setTag) {
  5517. return setToPairs(object);
  5518. }
  5519. return baseToPairs(object, keysFunc(object));
  5520. };
  5521. }
  5522. /**
  5523. * Creates a function that either curries or invokes `func` with optional
  5524. * `this` binding and partially applied arguments.
  5525. *
  5526. * @private
  5527. * @param {Function|string} func The function or method name to wrap.
  5528. * @param {number} bitmask The bitmask flags.
  5529. * 1 - `_.bind`
  5530. * 2 - `_.bindKey`
  5531. * 4 - `_.curry` or `_.curryRight` of a bound function
  5532. * 8 - `_.curry`
  5533. * 16 - `_.curryRight`
  5534. * 32 - `_.partial`
  5535. * 64 - `_.partialRight`
  5536. * 128 - `_.rearg`
  5537. * 256 - `_.ary`
  5538. * 512 - `_.flip`
  5539. * @param {*} [thisArg] The `this` binding of `func`.
  5540. * @param {Array} [partials] The arguments to be partially applied.
  5541. * @param {Array} [holders] The `partials` placeholder indexes.
  5542. * @param {Array} [argPos] The argument positions of the new function.
  5543. * @param {number} [ary] The arity cap of `func`.
  5544. * @param {number} [arity] The arity of `func`.
  5545. * @returns {Function} Returns the new wrapped function.
  5546. */
  5547. function createWrap(
  5548. func,
  5549. bitmask,
  5550. thisArg,
  5551. partials,
  5552. holders,
  5553. argPos,
  5554. ary,
  5555. arity
  5556. ) {
  5557. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5558. if (!isBindKey && typeof func !== 'function') {
  5559. throw new TypeError(FUNC_ERROR_TEXT);
  5560. }
  5561. var length = partials ? partials.length : 0;
  5562. if (!length) {
  5563. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5564. partials = holders = undefined;
  5565. }
  5566. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5567. arity = arity === undefined ? arity : toInteger(arity);
  5568. length -= holders ? holders.length : 0;
  5569. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5570. var partialsRight = partials,
  5571. holdersRight = holders;
  5572. partials = holders = undefined;
  5573. }
  5574. var data = isBindKey ? undefined : getData(func);
  5575. var newData = [
  5576. func,
  5577. bitmask,
  5578. thisArg,
  5579. partials,
  5580. holders,
  5581. partialsRight,
  5582. holdersRight,
  5583. argPos,
  5584. ary,
  5585. arity
  5586. ];
  5587. if (data) {
  5588. mergeData(newData, data);
  5589. }
  5590. func = newData[0];
  5591. bitmask = newData[1];
  5592. thisArg = newData[2];
  5593. partials = newData[3];
  5594. holders = newData[4];
  5595. arity = newData[9] =
  5596. newData[9] === undefined
  5597. ? isBindKey
  5598. ? 0
  5599. : func.length
  5600. : nativeMax(newData[9] - length, 0);
  5601. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5602. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5603. }
  5604. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5605. var result = createBind(func, bitmask, thisArg);
  5606. } else if (
  5607. bitmask == WRAP_CURRY_FLAG ||
  5608. bitmask == WRAP_CURRY_RIGHT_FLAG
  5609. ) {
  5610. result = createCurry(func, bitmask, arity);
  5611. } else if (
  5612. (bitmask == WRAP_PARTIAL_FLAG ||
  5613. bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) &&
  5614. !holders.length
  5615. ) {
  5616. result = createPartial(func, bitmask, thisArg, partials);
  5617. } else {
  5618. result = createHybrid.apply(undefined, newData);
  5619. }
  5620. var setter = data ? baseSetData : setData;
  5621. return setWrapToString(setter(result, newData), func, bitmask);
  5622. }
  5623. /**
  5624. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5625. * of source objects to the destination object for all destination properties
  5626. * that resolve to `undefined`.
  5627. *
  5628. * @private
  5629. * @param {*} objValue The destination value.
  5630. * @param {*} srcValue The source value.
  5631. * @param {string} key The key of the property to assign.
  5632. * @param {Object} object The parent object of `objValue`.
  5633. * @returns {*} Returns the value to assign.
  5634. */
  5635. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5636. if (
  5637. objValue === undefined ||
  5638. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))
  5639. ) {
  5640. return srcValue;
  5641. }
  5642. return objValue;
  5643. }
  5644. /**
  5645. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5646. * objects into destination objects that are passed thru.
  5647. *
  5648. * @private
  5649. * @param {*} objValue The destination value.
  5650. * @param {*} srcValue The source value.
  5651. * @param {string} key The key of the property to merge.
  5652. * @param {Object} object The parent object of `objValue`.
  5653. * @param {Object} source The parent object of `srcValue`.
  5654. * @param {Object} [stack] Tracks traversed source values and their merged
  5655. * counterparts.
  5656. * @returns {*} Returns the value to assign.
  5657. */
  5658. function customDefaultsMerge(
  5659. objValue,
  5660. srcValue,
  5661. key,
  5662. object,
  5663. source,
  5664. stack
  5665. ) {
  5666. if (isObject(objValue) && isObject(srcValue)) {
  5667. // Recursively merge objects and arrays (susceptible to call stack limits).
  5668. stack.set(srcValue, objValue);
  5669. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5670. stack['delete'](srcValue);
  5671. }
  5672. return objValue;
  5673. }
  5674. /**
  5675. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5676. * objects.
  5677. *
  5678. * @private
  5679. * @param {*} value The value to inspect.
  5680. * @param {string} key The key of the property to inspect.
  5681. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5682. */
  5683. function customOmitClone(value) {
  5684. return isPlainObject(value) ? undefined : value;
  5685. }
  5686. /**
  5687. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5688. * partial deep comparisons.
  5689. *
  5690. * @private
  5691. * @param {Array} array The array to compare.
  5692. * @param {Array} other The other array to compare.
  5693. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5694. * @param {Function} customizer The function to customize comparisons.
  5695. * @param {Function} equalFunc The function to determine equivalents of values.
  5696. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5697. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5698. */
  5699. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5700. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5701. arrLength = array.length,
  5702. othLength = other.length;
  5703. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5704. return false;
  5705. }
  5706. // Assume cyclic values are equal.
  5707. var stacked = stack.get(array);
  5708. if (stacked && stack.get(other)) {
  5709. return stacked == other;
  5710. }
  5711. var index = -1,
  5712. result = true,
  5713. seen = bitmask & COMPARE_UNORDERED_FLAG ? new SetCache() : undefined;
  5714. stack.set(array, other);
  5715. stack.set(other, array);
  5716. // Ignore non-index properties.
  5717. while (++index < arrLength) {
  5718. var arrValue = array[index],
  5719. othValue = other[index];
  5720. if (customizer) {
  5721. var compared = isPartial
  5722. ? customizer(othValue, arrValue, index, other, array, stack)
  5723. : customizer(arrValue, othValue, index, array, other, stack);
  5724. }
  5725. if (compared !== undefined) {
  5726. if (compared) {
  5727. continue;
  5728. }
  5729. result = false;
  5730. break;
  5731. }
  5732. // Recursively compare arrays (susceptible to call stack limits).
  5733. if (seen) {
  5734. if (
  5735. !arraySome(other, function(othValue, othIndex) {
  5736. if (
  5737. !cacheHas(seen, othIndex) &&
  5738. (arrValue === othValue ||
  5739. equalFunc(arrValue, othValue, bitmask, customizer, stack))
  5740. ) {
  5741. return seen.push(othIndex);
  5742. }
  5743. })
  5744. ) {
  5745. result = false;
  5746. break;
  5747. }
  5748. } else if (
  5749. !(
  5750. arrValue === othValue ||
  5751. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5752. )
  5753. ) {
  5754. result = false;
  5755. break;
  5756. }
  5757. }
  5758. stack['delete'](array);
  5759. stack['delete'](other);
  5760. return result;
  5761. }
  5762. /**
  5763. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5764. * the same `toStringTag`.
  5765. *
  5766. * **Note:** This function only supports comparing values with tags of
  5767. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5768. *
  5769. * @private
  5770. * @param {Object} object The object to compare.
  5771. * @param {Object} other The other object to compare.
  5772. * @param {string} tag The `toStringTag` of the objects to compare.
  5773. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5774. * @param {Function} customizer The function to customize comparisons.
  5775. * @param {Function} equalFunc The function to determine equivalents of values.
  5776. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5777. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5778. */
  5779. function equalByTag(
  5780. object,
  5781. other,
  5782. tag,
  5783. bitmask,
  5784. customizer,
  5785. equalFunc,
  5786. stack
  5787. ) {
  5788. switch (tag) {
  5789. case dataViewTag:
  5790. if (
  5791. object.byteLength != other.byteLength ||
  5792. object.byteOffset != other.byteOffset
  5793. ) {
  5794. return false;
  5795. }
  5796. object = object.buffer;
  5797. other = other.buffer;
  5798. case arrayBufferTag:
  5799. if (
  5800. object.byteLength != other.byteLength ||
  5801. !equalFunc(new Uint8Array(object), new Uint8Array(other))
  5802. ) {
  5803. return false;
  5804. }
  5805. return true;
  5806. case boolTag:
  5807. case dateTag:
  5808. case numberTag:
  5809. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5810. // Invalid dates are coerced to `NaN`.
  5811. return eq(+object, +other);
  5812. case errorTag:
  5813. return object.name == other.name && object.message == other.message;
  5814. case regexpTag:
  5815. case stringTag:
  5816. // Coerce regexes to strings and treat strings, primitives and objects,
  5817. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5818. // for more details.
  5819. return object == other + '';
  5820. case mapTag:
  5821. var convert = mapToArray;
  5822. case setTag:
  5823. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5824. convert || (convert = setToArray);
  5825. if (object.size != other.size && !isPartial) {
  5826. return false;
  5827. }
  5828. // Assume cyclic values are equal.
  5829. var stacked = stack.get(object);
  5830. if (stacked) {
  5831. return stacked == other;
  5832. }
  5833. bitmask |= COMPARE_UNORDERED_FLAG;
  5834. // Recursively compare objects (susceptible to call stack limits).
  5835. stack.set(object, other);
  5836. var result = equalArrays(
  5837. convert(object),
  5838. convert(other),
  5839. bitmask,
  5840. customizer,
  5841. equalFunc,
  5842. stack
  5843. );
  5844. stack['delete'](object);
  5845. return result;
  5846. case symbolTag:
  5847. if (symbolValueOf) {
  5848. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5849. }
  5850. }
  5851. return false;
  5852. }
  5853. /**
  5854. * A specialized version of `baseIsEqualDeep` for objects with support for
  5855. * partial deep comparisons.
  5856. *
  5857. * @private
  5858. * @param {Object} object The object to compare.
  5859. * @param {Object} other The other object to compare.
  5860. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5861. * @param {Function} customizer The function to customize comparisons.
  5862. * @param {Function} equalFunc The function to determine equivalents of values.
  5863. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5864. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5865. */
  5866. function equalObjects(
  5867. object,
  5868. other,
  5869. bitmask,
  5870. customizer,
  5871. equalFunc,
  5872. stack
  5873. ) {
  5874. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5875. objProps = getAllKeys(object),
  5876. objLength = objProps.length,
  5877. othProps = getAllKeys(other),
  5878. othLength = othProps.length;
  5879. if (objLength != othLength && !isPartial) {
  5880. return false;
  5881. }
  5882. var index = objLength;
  5883. while (index--) {
  5884. var key = objProps[index];
  5885. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5886. return false;
  5887. }
  5888. }
  5889. // Assume cyclic values are equal.
  5890. var stacked = stack.get(object);
  5891. if (stacked && stack.get(other)) {
  5892. return stacked == other;
  5893. }
  5894. var result = true;
  5895. stack.set(object, other);
  5896. stack.set(other, object);
  5897. var skipCtor = isPartial;
  5898. while (++index < objLength) {
  5899. key = objProps[index];
  5900. var objValue = object[key],
  5901. othValue = other[key];
  5902. if (customizer) {
  5903. var compared = isPartial
  5904. ? customizer(othValue, objValue, key, other, object, stack)
  5905. : customizer(objValue, othValue, key, object, other, stack);
  5906. }
  5907. // Recursively compare objects (susceptible to call stack limits).
  5908. if (
  5909. !(compared === undefined
  5910. ? objValue === othValue ||
  5911. equalFunc(objValue, othValue, bitmask, customizer, stack)
  5912. : compared)
  5913. ) {
  5914. result = false;
  5915. break;
  5916. }
  5917. skipCtor || (skipCtor = key == 'constructor');
  5918. }
  5919. if (result && !skipCtor) {
  5920. var objCtor = object.constructor,
  5921. othCtor = other.constructor;
  5922. // Non `Object` object instances with different constructors are not equal.
  5923. if (
  5924. objCtor != othCtor &&
  5925. ('constructor' in object && 'constructor' in other) &&
  5926. !(
  5927. typeof objCtor === 'function' &&
  5928. objCtor instanceof objCtor &&
  5929. typeof othCtor === 'function' &&
  5930. othCtor instanceof othCtor
  5931. )
  5932. ) {
  5933. result = false;
  5934. }
  5935. }
  5936. stack['delete'](object);
  5937. stack['delete'](other);
  5938. return result;
  5939. }
  5940. /**
  5941. * A specialized version of `baseRest` which flattens the rest array.
  5942. *
  5943. * @private
  5944. * @param {Function} func The function to apply a rest parameter to.
  5945. * @returns {Function} Returns the new function.
  5946. */
  5947. function flatRest(func) {
  5948. return setToString(overRest(func, undefined, flatten), func + '');
  5949. }
  5950. /**
  5951. * Creates an array of own enumerable property names and symbols of `object`.
  5952. *
  5953. * @private
  5954. * @param {Object} object The object to query.
  5955. * @returns {Array} Returns the array of property names and symbols.
  5956. */
  5957. function getAllKeys(object) {
  5958. return baseGetAllKeys(object, keys, getSymbols);
  5959. }
  5960. /**
  5961. * Creates an array of own and inherited enumerable property names and
  5962. * symbols of `object`.
  5963. *
  5964. * @private
  5965. * @param {Object} object The object to query.
  5966. * @returns {Array} Returns the array of property names and symbols.
  5967. */
  5968. function getAllKeysIn(object) {
  5969. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5970. }
  5971. /**
  5972. * Gets metadata for `func`.
  5973. *
  5974. * @private
  5975. * @param {Function} func The function to query.
  5976. * @returns {*} Returns the metadata for `func`.
  5977. */
  5978. var getData = !metaMap
  5979. ? noop
  5980. : function(func) {
  5981. return metaMap.get(func);
  5982. };
  5983. /**
  5984. * Gets the name of `func`.
  5985. *
  5986. * @private
  5987. * @param {Function} func The function to query.
  5988. * @returns {string} Returns the function name.
  5989. */
  5990. function getFuncName(func) {
  5991. var result = func.name + '',
  5992. array = realNames[result],
  5993. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5994. while (length--) {
  5995. var data = array[length],
  5996. otherFunc = data.func;
  5997. if (otherFunc == null || otherFunc == func) {
  5998. return data.name;
  5999. }
  6000. }
  6001. return result;
  6002. }
  6003. /**
  6004. * Gets the argument placeholder value for `func`.
  6005. *
  6006. * @private
  6007. * @param {Function} func The function to inspect.
  6008. * @returns {*} Returns the placeholder value.
  6009. */
  6010. function getHolder(func) {
  6011. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  6012. return object.placeholder;
  6013. }
  6014. /**
  6015. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  6016. * this function returns the custom method, otherwise it returns `baseIteratee`.
  6017. * If arguments are provided, the chosen function is invoked with them and
  6018. * its result is returned.
  6019. *
  6020. * @private
  6021. * @param {*} [value] The value to convert to an iteratee.
  6022. * @param {number} [arity] The arity of the created iteratee.
  6023. * @returns {Function} Returns the chosen function or its result.
  6024. */
  6025. function getIteratee() {
  6026. var result = lodash.iteratee || iteratee;
  6027. result = result === iteratee ? baseIteratee : result;
  6028. return arguments.length ? result(arguments[0], arguments[1]) : result;
  6029. }
  6030. /**
  6031. * Gets the data for `map`.
  6032. *
  6033. * @private
  6034. * @param {Object} map The map to query.
  6035. * @param {string} key The reference key.
  6036. * @returns {*} Returns the map data.
  6037. */
  6038. function getMapData(map, key) {
  6039. var data = map.__data__;
  6040. return isKeyable(key)
  6041. ? data[typeof key === 'string' ? 'string' : 'hash']
  6042. : data.map;
  6043. }
  6044. /**
  6045. * Gets the property names, values, and compare flags of `object`.
  6046. *
  6047. * @private
  6048. * @param {Object} object The object to query.
  6049. * @returns {Array} Returns the match data of `object`.
  6050. */
  6051. function getMatchData(object) {
  6052. var result = keys(object),
  6053. length = result.length;
  6054. while (length--) {
  6055. var key = result[length],
  6056. value = object[key];
  6057. result[length] = [key, value, isStrictComparable(value)];
  6058. }
  6059. return result;
  6060. }
  6061. /**
  6062. * Gets the native function at `key` of `object`.
  6063. *
  6064. * @private
  6065. * @param {Object} object The object to query.
  6066. * @param {string} key The key of the method to get.
  6067. * @returns {*} Returns the function if it's native, else `undefined`.
  6068. */
  6069. function getNative(object, key) {
  6070. var value = getValue(object, key);
  6071. return baseIsNative(value) ? value : undefined;
  6072. }
  6073. /**
  6074. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  6075. *
  6076. * @private
  6077. * @param {*} value The value to query.
  6078. * @returns {string} Returns the raw `toStringTag`.
  6079. */
  6080. function getRawTag(value) {
  6081. var isOwn = hasOwnProperty.call(value, symToStringTag),
  6082. tag = value[symToStringTag];
  6083. try {
  6084. value[symToStringTag] = undefined;
  6085. var unmasked = true;
  6086. } catch (e) { }
  6087. var result = nativeObjectToString.call(value);
  6088. if (unmasked) {
  6089. if (isOwn) {
  6090. value[symToStringTag] = tag;
  6091. } else {
  6092. delete value[symToStringTag];
  6093. }
  6094. }
  6095. return result;
  6096. }
  6097. /**
  6098. * Creates an array of the own enumerable symbols of `object`.
  6099. *
  6100. * @private
  6101. * @param {Object} object The object to query.
  6102. * @returns {Array} Returns the array of symbols.
  6103. */
  6104. var getSymbols = !nativeGetSymbols
  6105. ? stubArray
  6106. : function(object) {
  6107. if (object == null) {
  6108. return [];
  6109. }
  6110. object = Object(object);
  6111. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  6112. return propertyIsEnumerable.call(object, symbol);
  6113. });
  6114. };
  6115. /**
  6116. * Creates an array of the own and inherited enumerable symbols of `object`.
  6117. *
  6118. * @private
  6119. * @param {Object} object The object to query.
  6120. * @returns {Array} Returns the array of symbols.
  6121. */
  6122. var getSymbolsIn = !nativeGetSymbols
  6123. ? stubArray
  6124. : function(object) {
  6125. var result = [];
  6126. while (object) {
  6127. arrayPush(result, getSymbols(object));
  6128. object = getPrototype(object);
  6129. }
  6130. return result;
  6131. };
  6132. /**
  6133. * Gets the `toStringTag` of `value`.
  6134. *
  6135. * @private
  6136. * @param {*} value The value to query.
  6137. * @returns {string} Returns the `toStringTag`.
  6138. */
  6139. var getTag = baseGetTag;
  6140. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  6141. if (
  6142. (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  6143. (Map && getTag(new Map()) != mapTag) ||
  6144. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  6145. (Set && getTag(new Set()) != setTag) ||
  6146. (WeakMap && getTag(new WeakMap()) != weakMapTag)
  6147. ) {
  6148. getTag = function(value) {
  6149. var result = baseGetTag(value),
  6150. Ctor = result == objectTag ? value.constructor : undefined,
  6151. ctorString = Ctor ? toSource(Ctor) : '';
  6152. if (ctorString) {
  6153. switch (ctorString) {
  6154. case dataViewCtorString:
  6155. return dataViewTag;
  6156. case mapCtorString:
  6157. return mapTag;
  6158. case promiseCtorString:
  6159. return promiseTag;
  6160. case setCtorString:
  6161. return setTag;
  6162. case weakMapCtorString:
  6163. return weakMapTag;
  6164. }
  6165. }
  6166. return result;
  6167. };
  6168. }
  6169. /**
  6170. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  6171. *
  6172. * @private
  6173. * @param {number} start The start of the view.
  6174. * @param {number} end The end of the view.
  6175. * @param {Array} transforms The transformations to apply to the view.
  6176. * @returns {Object} Returns an object containing the `start` and `end`
  6177. * positions of the view.
  6178. */
  6179. function getView(start, end, transforms) {
  6180. var index = -1,
  6181. length = transforms.length;
  6182. while (++index < length) {
  6183. var data = transforms[index],
  6184. size = data.size;
  6185. switch (data.type) {
  6186. case 'drop':
  6187. start += size;
  6188. break;
  6189. case 'dropRight':
  6190. end -= size;
  6191. break;
  6192. case 'take':
  6193. end = nativeMin(end, start + size);
  6194. break;
  6195. case 'takeRight':
  6196. start = nativeMax(start, end - size);
  6197. break;
  6198. }
  6199. }
  6200. return { start: start, end: end };
  6201. }
  6202. /**
  6203. * Extracts wrapper details from the `source` body comment.
  6204. *
  6205. * @private
  6206. * @param {string} source The source to inspect.
  6207. * @returns {Array} Returns the wrapper details.
  6208. */
  6209. function getWrapDetails(source) {
  6210. var match = source.match(reWrapDetails);
  6211. return match ? match[1].split(reSplitDetails) : [];
  6212. }
  6213. /**
  6214. * Checks if `path` exists on `object`.
  6215. *
  6216. * @private
  6217. * @param {Object} object The object to query.
  6218. * @param {Array|string} path The path to check.
  6219. * @param {Function} hasFunc The function to check properties.
  6220. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  6221. */
  6222. function hasPath(object, path, hasFunc) {
  6223. path = castPath(path, object);
  6224. var index = -1,
  6225. length = path.length,
  6226. result = false;
  6227. while (++index < length) {
  6228. var key = toKey(path[index]);
  6229. if (!(result = object != null && hasFunc(object, key))) {
  6230. break;
  6231. }
  6232. object = object[key];
  6233. }
  6234. if (result || ++index != length) {
  6235. return result;
  6236. }
  6237. length = object == null ? 0 : object.length;
  6238. return (
  6239. !!length &&
  6240. isLength(length) &&
  6241. isIndex(key, length) &&
  6242. (isArray(object) || isArguments(object))
  6243. );
  6244. }
  6245. /**
  6246. * Initializes an array clone.
  6247. *
  6248. * @private
  6249. * @param {Array} array The array to clone.
  6250. * @returns {Array} Returns the initialized clone.
  6251. */
  6252. function initCloneArray(array) {
  6253. var length = array.length,
  6254. result = new array.constructor(length);
  6255. // Add properties assigned by `RegExp#exec`.
  6256. if (
  6257. length &&
  6258. typeof array[0] === 'string' &&
  6259. hasOwnProperty.call(array, 'index')
  6260. ) {
  6261. result.index = array.index;
  6262. result.input = array.input;
  6263. }
  6264. return result;
  6265. }
  6266. /**
  6267. * Initializes an object clone.
  6268. *
  6269. * @private
  6270. * @param {Object} object The object to clone.
  6271. * @returns {Object} Returns the initialized clone.
  6272. */
  6273. function initCloneObject(object) {
  6274. return typeof object.constructor === 'function' && !isPrototype(object)
  6275. ? baseCreate(getPrototype(object))
  6276. : {};
  6277. }
  6278. /**
  6279. * Initializes an object clone based on its `toStringTag`.
  6280. *
  6281. * **Note:** This function only supports cloning values with tags of
  6282. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  6283. *
  6284. * @private
  6285. * @param {Object} object The object to clone.
  6286. * @param {string} tag The `toStringTag` of the object to clone.
  6287. * @param {boolean} [isDeep] Specify a deep clone.
  6288. * @returns {Object} Returns the initialized clone.
  6289. */
  6290. function initCloneByTag(object, tag, isDeep) {
  6291. var Ctor = object.constructor;
  6292. switch (tag) {
  6293. case arrayBufferTag:
  6294. return cloneArrayBuffer(object);
  6295. case boolTag:
  6296. case dateTag:
  6297. return new Ctor(+object);
  6298. case dataViewTag:
  6299. return cloneDataView(object, isDeep);
  6300. case float32Tag:
  6301. case float64Tag:
  6302. case int8Tag:
  6303. case int16Tag:
  6304. case int32Tag:
  6305. case uint8Tag:
  6306. case uint8ClampedTag:
  6307. case uint16Tag:
  6308. case uint32Tag:
  6309. return cloneTypedArray(object, isDeep);
  6310. case mapTag:
  6311. return new Ctor();
  6312. case numberTag:
  6313. case stringTag:
  6314. return new Ctor(object);
  6315. case regexpTag:
  6316. return cloneRegExp(object);
  6317. case setTag:
  6318. return new Ctor();
  6319. case symbolTag:
  6320. return cloneSymbol(object);
  6321. }
  6322. }
  6323. /**
  6324. * Inserts wrapper `details` in a comment at the top of the `source` body.
  6325. *
  6326. * @private
  6327. * @param {string} source The source to modify.
  6328. * @returns {Array} details The details to insert.
  6329. * @returns {string} Returns the modified source.
  6330. */
  6331. function insertWrapDetails(source, details) {
  6332. var length = details.length;
  6333. if (!length) {
  6334. return source;
  6335. }
  6336. var lastIndex = length - 1;
  6337. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  6338. details = details.join(length > 2 ? ', ' : ' ');
  6339. return source.replace(
  6340. reWrapComment,
  6341. '{\n/* [wrapped with ' + details + '] */\n'
  6342. );
  6343. }
  6344. /**
  6345. * Checks if `value` is a flattenable `arguments` object or array.
  6346. *
  6347. * @private
  6348. * @param {*} value The value to check.
  6349. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  6350. */
  6351. function isFlattenable(value) {
  6352. return (
  6353. isArray(value) ||
  6354. isArguments(value) ||
  6355. !!(spreadableSymbol && value && value[spreadableSymbol])
  6356. );
  6357. }
  6358. /**
  6359. * Checks if `value` is a valid array-like index.
  6360. *
  6361. * @private
  6362. * @param {*} value The value to check.
  6363. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  6364. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  6365. */
  6366. function isIndex(value, length) {
  6367. var type = typeof value;
  6368. length = length == null ? MAX_SAFE_INTEGER : length;
  6369. return (
  6370. !!length &&
  6371. (type == 'number' || (type != 'symbol' && reIsUint.test(value))) &&
  6372. (value > -1 && value % 1 == 0 && value < length)
  6373. );
  6374. }
  6375. /**
  6376. * Checks if the given arguments are from an iteratee call.
  6377. *
  6378. * @private
  6379. * @param {*} value The potential iteratee value argument.
  6380. * @param {*} index The potential iteratee index or key argument.
  6381. * @param {*} object The potential iteratee object argument.
  6382. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  6383. * else `false`.
  6384. */
  6385. function isIterateeCall(value, index, object) {
  6386. if (!isObject(object)) {
  6387. return false;
  6388. }
  6389. var type = typeof index;
  6390. if (
  6391. type == 'number'
  6392. ? isArrayLike(object) && isIndex(index, object.length)
  6393. : type == 'string' && index in object
  6394. ) {
  6395. return eq(object[index], value);
  6396. }
  6397. return false;
  6398. }
  6399. /**
  6400. * Checks if `value` is a property name and not a property path.
  6401. *
  6402. * @private
  6403. * @param {*} value The value to check.
  6404. * @param {Object} [object] The object to query keys on.
  6405. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  6406. */
  6407. function isKey(value, object) {
  6408. if (isArray(value)) {
  6409. return false;
  6410. }
  6411. var type = typeof value;
  6412. if (
  6413. type == 'number' ||
  6414. type == 'symbol' ||
  6415. type == 'boolean' ||
  6416. value == null ||
  6417. isSymbol(value)
  6418. ) {
  6419. return true;
  6420. }
  6421. return (
  6422. reIsPlainProp.test(value) ||
  6423. !reIsDeepProp.test(value) ||
  6424. (object != null && value in Object(object))
  6425. );
  6426. }
  6427. /**
  6428. * Checks if `value` is suitable for use as unique object key.
  6429. *
  6430. * @private
  6431. * @param {*} value The value to check.
  6432. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  6433. */
  6434. function isKeyable(value) {
  6435. var type = typeof value;
  6436. return type == 'string' ||
  6437. type == 'number' ||
  6438. type == 'symbol' ||
  6439. type == 'boolean'
  6440. ? value !== '__proto__'
  6441. : value === null;
  6442. }
  6443. /**
  6444. * Checks if `func` has a lazy counterpart.
  6445. *
  6446. * @private
  6447. * @param {Function} func The function to check.
  6448. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  6449. * else `false`.
  6450. */
  6451. function isLaziable(func) {
  6452. var funcName = getFuncName(func),
  6453. other = lodash[funcName];
  6454. if (typeof other !== 'function' || !(funcName in LazyWrapper.prototype)) {
  6455. return false;
  6456. }
  6457. if (func === other) {
  6458. return true;
  6459. }
  6460. var data = getData(other);
  6461. return !!data && func === data[0];
  6462. }
  6463. /**
  6464. * Checks if `func` has its source masked.
  6465. *
  6466. * @private
  6467. * @param {Function} func The function to check.
  6468. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  6469. */
  6470. function isMasked(func) {
  6471. return !!maskSrcKey && maskSrcKey in func;
  6472. }
  6473. /**
  6474. * Checks if `func` is capable of being masked.
  6475. *
  6476. * @private
  6477. * @param {*} value The value to check.
  6478. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  6479. */
  6480. var isMaskable = coreJsData ? isFunction : stubFalse;
  6481. /**
  6482. * Checks if `value` is likely a prototype object.
  6483. *
  6484. * @private
  6485. * @param {*} value The value to check.
  6486. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  6487. */
  6488. function isPrototype(value) {
  6489. var Ctor = value && value.constructor,
  6490. proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
  6491. return value === proto;
  6492. }
  6493. /**
  6494. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  6495. *
  6496. * @private
  6497. * @param {*} value The value to check.
  6498. * @returns {boolean} Returns `true` if `value` if suitable for strict
  6499. * equality comparisons, else `false`.
  6500. */
  6501. function isStrictComparable(value) {
  6502. return value === value && !isObject(value);
  6503. }
  6504. /**
  6505. * A specialized version of `matchesProperty` for source values suitable
  6506. * for strict equality comparisons, i.e. `===`.
  6507. *
  6508. * @private
  6509. * @param {string} key The key of the property to get.
  6510. * @param {*} srcValue The value to match.
  6511. * @returns {Function} Returns the new spec function.
  6512. */
  6513. function matchesStrictComparable(key, srcValue) {
  6514. return function(object) {
  6515. if (object == null) {
  6516. return false;
  6517. }
  6518. return (
  6519. object[key] === srcValue &&
  6520. (srcValue !== undefined || key in Object(object))
  6521. );
  6522. };
  6523. }
  6524. /**
  6525. * A specialized version of `_.memoize` which clears the memoized function's
  6526. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  6527. *
  6528. * @private
  6529. * @param {Function} func The function to have its output memoized.
  6530. * @returns {Function} Returns the new memoized function.
  6531. */
  6532. function memoizeCapped(func) {
  6533. var result = memoize(func, function(key) {
  6534. if (cache.size === MAX_MEMOIZE_SIZE) {
  6535. cache.clear();
  6536. }
  6537. return key;
  6538. });
  6539. var cache = result.cache;
  6540. return result;
  6541. }
  6542. /**
  6543. * Merges the function metadata of `source` into `data`.
  6544. *
  6545. * Merging metadata reduces the number of wrappers used to invoke a function.
  6546. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  6547. * may be applied regardless of execution order. Methods like `_.ary` and
  6548. * `_.rearg` modify function arguments, making the order in which they are
  6549. * executed important, preventing the merging of metadata. However, we make
  6550. * an exception for a safe combined case where curried functions have `_.ary`
  6551. * and or `_.rearg` applied.
  6552. *
  6553. * @private
  6554. * @param {Array} data The destination metadata.
  6555. * @param {Array} source The source metadata.
  6556. * @returns {Array} Returns `data`.
  6557. */
  6558. function mergeData(data, source) {
  6559. var bitmask = data[1],
  6560. srcBitmask = source[1],
  6561. newBitmask = bitmask | srcBitmask,
  6562. isCommon =
  6563. newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  6564. var isCombo =
  6565. (srcBitmask == WRAP_ARY_FLAG && bitmask == WRAP_CURRY_FLAG) ||
  6566. (srcBitmask == WRAP_ARY_FLAG &&
  6567. bitmask == WRAP_REARG_FLAG &&
  6568. data[7].length <= source[8]) ||
  6569. (srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG) &&
  6570. source[7].length <= source[8] &&
  6571. bitmask == WRAP_CURRY_FLAG);
  6572. // Exit early if metadata can't be merged.
  6573. if (!(isCommon || isCombo)) {
  6574. return data;
  6575. }
  6576. // Use source `thisArg` if available.
  6577. if (srcBitmask & WRAP_BIND_FLAG) {
  6578. data[2] = source[2];
  6579. // Set when currying a bound function.
  6580. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  6581. }
  6582. // Compose partial arguments.
  6583. var value = source[3];
  6584. if (value) {
  6585. var partials = data[3];
  6586. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  6587. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  6588. }
  6589. // Compose partial right arguments.
  6590. value = source[5];
  6591. if (value) {
  6592. partials = data[5];
  6593. data[5] = partials
  6594. ? composeArgsRight(partials, value, source[6])
  6595. : value;
  6596. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  6597. }
  6598. // Use source `argPos` if available.
  6599. value = source[7];
  6600. if (value) {
  6601. data[7] = value;
  6602. }
  6603. // Use source `ary` if it's smaller.
  6604. if (srcBitmask & WRAP_ARY_FLAG) {
  6605. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  6606. }
  6607. // Use source `arity` if one is not provided.
  6608. if (data[9] == null) {
  6609. data[9] = source[9];
  6610. }
  6611. // Use source `func` and merge bitmasks.
  6612. data[0] = source[0];
  6613. data[1] = newBitmask;
  6614. return data;
  6615. }
  6616. /**
  6617. * This function is like
  6618. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  6619. * except that it includes inherited enumerable properties.
  6620. *
  6621. * @private
  6622. * @param {Object} object The object to query.
  6623. * @returns {Array} Returns the array of property names.
  6624. */
  6625. function nativeKeysIn(object) {
  6626. var result = [];
  6627. if (object != null) {
  6628. for (var key in Object(object)) {
  6629. result.push(key);
  6630. }
  6631. }
  6632. return result;
  6633. }
  6634. /**
  6635. * Converts `value` to a string using `Object.prototype.toString`.
  6636. *
  6637. * @private
  6638. * @param {*} value The value to convert.
  6639. * @returns {string} Returns the converted string.
  6640. */
  6641. function objectToString(value) {
  6642. return nativeObjectToString.call(value);
  6643. }
  6644. /**
  6645. * A specialized version of `baseRest` which transforms the rest array.
  6646. *
  6647. * @private
  6648. * @param {Function} func The function to apply a rest parameter to.
  6649. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6650. * @param {Function} transform The rest array transform.
  6651. * @returns {Function} Returns the new function.
  6652. */
  6653. function overRest(func, start, transform) {
  6654. start = nativeMax(start === undefined ? func.length - 1 : start, 0);
  6655. return function() {
  6656. var args = arguments,
  6657. index = -1,
  6658. length = nativeMax(args.length - start, 0),
  6659. array = Array(length);
  6660. while (++index < length) {
  6661. array[index] = args[start + index];
  6662. }
  6663. index = -1;
  6664. var otherArgs = Array(start + 1);
  6665. while (++index < start) {
  6666. otherArgs[index] = args[index];
  6667. }
  6668. otherArgs[start] = transform(array);
  6669. return apply(func, this, otherArgs);
  6670. };
  6671. }
  6672. /**
  6673. * Gets the parent value at `path` of `object`.
  6674. *
  6675. * @private
  6676. * @param {Object} object The object to query.
  6677. * @param {Array} path The path to get the parent value of.
  6678. * @returns {*} Returns the parent value.
  6679. */
  6680. function parent(object, path) {
  6681. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6682. }
  6683. /**
  6684. * Reorder `array` according to the specified indexes where the element at
  6685. * the first index is assigned as the first element, the element at
  6686. * the second index is assigned as the second element, and so on.
  6687. *
  6688. * @private
  6689. * @param {Array} array The array to reorder.
  6690. * @param {Array} indexes The arranged array indexes.
  6691. * @returns {Array} Returns `array`.
  6692. */
  6693. function reorder(array, indexes) {
  6694. var arrLength = array.length,
  6695. length = nativeMin(indexes.length, arrLength),
  6696. oldArray = copyArray(array);
  6697. while (length--) {
  6698. var index = indexes[length];
  6699. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6700. }
  6701. return array;
  6702. }
  6703. /**
  6704. * Sets metadata for `func`.
  6705. *
  6706. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6707. * period of time, it will trip its breaker and transition to an identity
  6708. * function to avoid garbage collection pauses in V8. See
  6709. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6710. * for more details.
  6711. *
  6712. * @private
  6713. * @param {Function} func The function to associate metadata with.
  6714. * @param {*} data The metadata.
  6715. * @returns {Function} Returns `func`.
  6716. */
  6717. var setData = shortOut(baseSetData);
  6718. /**
  6719. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6720. *
  6721. * @private
  6722. * @param {Function} func The function to delay.
  6723. * @param {number} wait The number of milliseconds to delay invocation.
  6724. * @returns {number|Object} Returns the timer id or timeout object.
  6725. */
  6726. var setTimeout =
  6727. ctxSetTimeout ||
  6728. function(func, wait) {
  6729. return root.setTimeout(func, wait);
  6730. };
  6731. /**
  6732. * Sets the `toString` method of `func` to return `string`.
  6733. *
  6734. * @private
  6735. * @param {Function} func The function to modify.
  6736. * @param {Function} string The `toString` result.
  6737. * @returns {Function} Returns `func`.
  6738. */
  6739. var setToString = shortOut(baseSetToString);
  6740. /**
  6741. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6742. * with wrapper details in a comment at the top of the source body.
  6743. *
  6744. * @private
  6745. * @param {Function} wrapper The function to modify.
  6746. * @param {Function} reference The reference function.
  6747. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6748. * @returns {Function} Returns `wrapper`.
  6749. */
  6750. function setWrapToString(wrapper, reference, bitmask) {
  6751. var source = reference + '';
  6752. return setToString(
  6753. wrapper,
  6754. insertWrapDetails(
  6755. source,
  6756. updateWrapDetails(getWrapDetails(source), bitmask)
  6757. )
  6758. );
  6759. }
  6760. /**
  6761. * Creates a function that'll short out and invoke `identity` instead
  6762. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6763. * milliseconds.
  6764. *
  6765. * @private
  6766. * @param {Function} func The function to restrict.
  6767. * @returns {Function} Returns the new shortable function.
  6768. */
  6769. function shortOut(func) {
  6770. var count = 0,
  6771. lastCalled = 0;
  6772. return function() {
  6773. var stamp = nativeNow(),
  6774. remaining = HOT_SPAN - (stamp - lastCalled);
  6775. lastCalled = stamp;
  6776. if (remaining > 0) {
  6777. if (++count >= HOT_COUNT) {
  6778. return arguments[0];
  6779. }
  6780. } else {
  6781. count = 0;
  6782. }
  6783. return func.apply(undefined, arguments);
  6784. };
  6785. }
  6786. /**
  6787. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6788. *
  6789. * @private
  6790. * @param {Array} array The array to shuffle.
  6791. * @param {number} [size=array.length] The size of `array`.
  6792. * @returns {Array} Returns `array`.
  6793. */
  6794. function shuffleSelf(array, size) {
  6795. var index = -1,
  6796. length = array.length,
  6797. lastIndex = length - 1;
  6798. size = size === undefined ? length : size;
  6799. while (++index < size) {
  6800. var rand = baseRandom(index, lastIndex),
  6801. value = array[rand];
  6802. array[rand] = array[index];
  6803. array[index] = value;
  6804. }
  6805. array.length = size;
  6806. return array;
  6807. }
  6808. /**
  6809. * Converts `string` to a property path array.
  6810. *
  6811. * @private
  6812. * @param {string} string The string to convert.
  6813. * @returns {Array} Returns the property path array.
  6814. */
  6815. var stringToPath = memoizeCapped(function(string) {
  6816. var result = [];
  6817. if (string.charCodeAt(0) === 46 /* . */) {
  6818. result.push('');
  6819. }
  6820. string.replace(rePropName, function(match, number, quote, subString) {
  6821. result.push(
  6822. quote ? subString.replace(reEscapeChar, '$1') : number || match
  6823. );
  6824. });
  6825. return result;
  6826. });
  6827. /**
  6828. * Converts `value` to a string key if it's not a string or symbol.
  6829. *
  6830. * @private
  6831. * @param {*} value The value to inspect.
  6832. * @returns {string|symbol} Returns the key.
  6833. */
  6834. function toKey(value) {
  6835. if (typeof value === 'string' || isSymbol(value)) {
  6836. return value;
  6837. }
  6838. var result = value + '';
  6839. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  6840. }
  6841. /**
  6842. * Converts `func` to its source code.
  6843. *
  6844. * @private
  6845. * @param {Function} func The function to convert.
  6846. * @returns {string} Returns the source code.
  6847. */
  6848. function toSource(func) {
  6849. if (func != null) {
  6850. try {
  6851. return funcToString.call(func);
  6852. } catch (e) { }
  6853. try {
  6854. return func + '';
  6855. } catch (e) { }
  6856. }
  6857. return '';
  6858. }
  6859. /**
  6860. * Updates wrapper `details` based on `bitmask` flags.
  6861. *
  6862. * @private
  6863. * @returns {Array} details The details to modify.
  6864. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6865. * @returns {Array} Returns `details`.
  6866. */
  6867. function updateWrapDetails(details, bitmask) {
  6868. arrayEach(wrapFlags, function(pair) {
  6869. var value = '_.' + pair[0];
  6870. if (bitmask & pair[1] && !arrayIncludes(details, value)) {
  6871. details.push(value);
  6872. }
  6873. });
  6874. return details.sort();
  6875. }
  6876. /**
  6877. * Creates a clone of `wrapper`.
  6878. *
  6879. * @private
  6880. * @param {Object} wrapper The wrapper to clone.
  6881. * @returns {Object} Returns the cloned wrapper.
  6882. */
  6883. function wrapperClone(wrapper) {
  6884. if (wrapper instanceof LazyWrapper) {
  6885. return wrapper.clone();
  6886. }
  6887. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6888. result.__actions__ = copyArray(wrapper.__actions__);
  6889. result.__index__ = wrapper.__index__;
  6890. result.__values__ = wrapper.__values__;
  6891. return result;
  6892. }
  6893. /* ------------------------------------------------------------------------*/
  6894. /**
  6895. * Creates an array of elements split into groups the length of `size`.
  6896. * If `array` can't be split evenly, the final chunk will be the remaining
  6897. * elements.
  6898. *
  6899. * @static
  6900. * @memberOf _
  6901. * @since 3.0.0
  6902. * @category Array
  6903. * @param {Array} array The array to process.
  6904. * @param {number} [size=1] The length of each chunk
  6905. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6906. * @returns {Array} Returns the new array of chunks.
  6907. * @example
  6908. *
  6909. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6910. * // => [['a', 'b'], ['c', 'd']]
  6911. *
  6912. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6913. * // => [['a', 'b', 'c'], ['d']]
  6914. */
  6915. function chunk(array, size, guard) {
  6916. if (guard ? isIterateeCall(array, size, guard) : size === undefined) {
  6917. size = 1;
  6918. } else {
  6919. size = nativeMax(toInteger(size), 0);
  6920. }
  6921. var length = array == null ? 0 : array.length;
  6922. if (!length || size < 1) {
  6923. return [];
  6924. }
  6925. var index = 0,
  6926. resIndex = 0,
  6927. result = Array(nativeCeil(length / size));
  6928. while (index < length) {
  6929. result[resIndex++] = baseSlice(array, index, (index += size));
  6930. }
  6931. return result;
  6932. }
  6933. /**
  6934. * Creates an array with all falsey values removed. The values `false`, `null`,
  6935. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6936. *
  6937. * @static
  6938. * @memberOf _
  6939. * @since 0.1.0
  6940. * @category Array
  6941. * @param {Array} array The array to compact.
  6942. * @returns {Array} Returns the new array of filtered values.
  6943. * @example
  6944. *
  6945. * _.compact([0, 1, false, 2, '', 3]);
  6946. * // => [1, 2, 3]
  6947. */
  6948. function compact(array) {
  6949. var index = -1,
  6950. length = array == null ? 0 : array.length,
  6951. resIndex = 0,
  6952. result = [];
  6953. while (++index < length) {
  6954. var value = array[index];
  6955. if (value) {
  6956. result[resIndex++] = value;
  6957. }
  6958. }
  6959. return result;
  6960. }
  6961. /**
  6962. * Creates a new array concatenating `array` with any additional arrays
  6963. * and/or values.
  6964. *
  6965. * @static
  6966. * @memberOf _
  6967. * @since 4.0.0
  6968. * @category Array
  6969. * @param {Array} array The array to concatenate.
  6970. * @param {...*} [values] The values to concatenate.
  6971. * @returns {Array} Returns the new concatenated array.
  6972. * @example
  6973. *
  6974. * var array = [1];
  6975. * var other = _.concat(array, 2, [3], [[4]]);
  6976. *
  6977. * console.log(other);
  6978. * // => [1, 2, 3, [4]]
  6979. *
  6980. * console.log(array);
  6981. * // => [1]
  6982. */
  6983. function concat() {
  6984. var length = arguments.length;
  6985. if (!length) {
  6986. return [];
  6987. }
  6988. var args = Array(length - 1),
  6989. array = arguments[0],
  6990. index = length;
  6991. while (index--) {
  6992. args[index - 1] = arguments[index];
  6993. }
  6994. return arrayPush(
  6995. isArray(array) ? copyArray(array) : [array],
  6996. baseFlatten(args, 1)
  6997. );
  6998. }
  6999. /**
  7000. * Creates an array of `array` values not included in the other given arrays
  7001. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7002. * for equality comparisons. The order and references of result values are
  7003. * determined by the first array.
  7004. *
  7005. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  7006. *
  7007. * @static
  7008. * @memberOf _
  7009. * @since 0.1.0
  7010. * @category Array
  7011. * @param {Array} array The array to inspect.
  7012. * @param {...Array} [values] The values to exclude.
  7013. * @returns {Array} Returns the new array of filtered values.
  7014. * @see _.without, _.xor
  7015. * @example
  7016. *
  7017. * _.difference([2, 1], [2, 3]);
  7018. * // => [1]
  7019. */
  7020. var difference = baseRest(function(array, values) {
  7021. return isArrayLikeObject(array)
  7022. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  7023. : [];
  7024. });
  7025. /**
  7026. * This method is like `_.difference` except that it accepts `iteratee` which
  7027. * is invoked for each element of `array` and `values` to generate the criterion
  7028. * by which they're compared. The order and references of result values are
  7029. * determined by the first array. The iteratee is invoked with one argument:
  7030. * (value).
  7031. *
  7032. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  7033. *
  7034. * @static
  7035. * @memberOf _
  7036. * @since 4.0.0
  7037. * @category Array
  7038. * @param {Array} array The array to inspect.
  7039. * @param {...Array} [values] The values to exclude.
  7040. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7041. * @returns {Array} Returns the new array of filtered values.
  7042. * @example
  7043. *
  7044. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7045. * // => [1.2]
  7046. *
  7047. * // The `_.property` iteratee shorthand.
  7048. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  7049. * // => [{ 'x': 2 }]
  7050. */
  7051. var differenceBy = baseRest(function(array, values) {
  7052. var iteratee = last(values);
  7053. if (isArrayLikeObject(iteratee)) {
  7054. iteratee = undefined;
  7055. }
  7056. return isArrayLikeObject(array)
  7057. ? baseDifference(
  7058. array,
  7059. baseFlatten(values, 1, isArrayLikeObject, true),
  7060. getIteratee(iteratee, 2)
  7061. )
  7062. : [];
  7063. });
  7064. /**
  7065. * This method is like `_.difference` except that it accepts `comparator`
  7066. * which is invoked to compare elements of `array` to `values`. The order and
  7067. * references of result values are determined by the first array. The comparator
  7068. * is invoked with two arguments: (arrVal, othVal).
  7069. *
  7070. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  7071. *
  7072. * @static
  7073. * @memberOf _
  7074. * @since 4.0.0
  7075. * @category Array
  7076. * @param {Array} array The array to inspect.
  7077. * @param {...Array} [values] The values to exclude.
  7078. * @param {Function} [comparator] The comparator invoked per element.
  7079. * @returns {Array} Returns the new array of filtered values.
  7080. * @example
  7081. *
  7082. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7083. *
  7084. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  7085. * // => [{ 'x': 2, 'y': 1 }]
  7086. */
  7087. var differenceWith = baseRest(function(array, values) {
  7088. var comparator = last(values);
  7089. if (isArrayLikeObject(comparator)) {
  7090. comparator = undefined;
  7091. }
  7092. return isArrayLikeObject(array)
  7093. ? baseDifference(
  7094. array,
  7095. baseFlatten(values, 1, isArrayLikeObject, true),
  7096. undefined,
  7097. comparator
  7098. )
  7099. : [];
  7100. });
  7101. /**
  7102. * Creates a slice of `array` with `n` elements dropped from the beginning.
  7103. *
  7104. * @static
  7105. * @memberOf _
  7106. * @since 0.5.0
  7107. * @category Array
  7108. * @param {Array} array The array to query.
  7109. * @param {number} [n=1] The number of elements to drop.
  7110. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7111. * @returns {Array} Returns the slice of `array`.
  7112. * @example
  7113. *
  7114. * _.drop([1, 2, 3]);
  7115. * // => [2, 3]
  7116. *
  7117. * _.drop([1, 2, 3], 2);
  7118. * // => [3]
  7119. *
  7120. * _.drop([1, 2, 3], 5);
  7121. * // => []
  7122. *
  7123. * _.drop([1, 2, 3], 0);
  7124. * // => [1, 2, 3]
  7125. */
  7126. function drop(array, n, guard) {
  7127. var length = array == null ? 0 : array.length;
  7128. if (!length) {
  7129. return [];
  7130. }
  7131. n = guard || n === undefined ? 1 : toInteger(n);
  7132. return baseSlice(array, n < 0 ? 0 : n, length);
  7133. }
  7134. /**
  7135. * Creates a slice of `array` with `n` elements dropped from the end.
  7136. *
  7137. * @static
  7138. * @memberOf _
  7139. * @since 3.0.0
  7140. * @category Array
  7141. * @param {Array} array The array to query.
  7142. * @param {number} [n=1] The number of elements to drop.
  7143. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7144. * @returns {Array} Returns the slice of `array`.
  7145. * @example
  7146. *
  7147. * _.dropRight([1, 2, 3]);
  7148. * // => [1, 2]
  7149. *
  7150. * _.dropRight([1, 2, 3], 2);
  7151. * // => [1]
  7152. *
  7153. * _.dropRight([1, 2, 3], 5);
  7154. * // => []
  7155. *
  7156. * _.dropRight([1, 2, 3], 0);
  7157. * // => [1, 2, 3]
  7158. */
  7159. function dropRight(array, n, guard) {
  7160. var length = array == null ? 0 : array.length;
  7161. if (!length) {
  7162. return [];
  7163. }
  7164. n = guard || n === undefined ? 1 : toInteger(n);
  7165. n = length - n;
  7166. return baseSlice(array, 0, n < 0 ? 0 : n);
  7167. }
  7168. /**
  7169. * Creates a slice of `array` excluding elements dropped from the end.
  7170. * Elements are dropped until `predicate` returns falsey. The predicate is
  7171. * invoked with three arguments: (value, index, array).
  7172. *
  7173. * @static
  7174. * @memberOf _
  7175. * @since 3.0.0
  7176. * @category Array
  7177. * @param {Array} array The array to query.
  7178. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7179. * @returns {Array} Returns the slice of `array`.
  7180. * @example
  7181. *
  7182. * var users = [
  7183. * { 'user': 'barney', 'active': true },
  7184. * { 'user': 'fred', 'active': false },
  7185. * { 'user': 'pebbles', 'active': false }
  7186. * ];
  7187. *
  7188. * _.dropRightWhile(users, function(o) { return !o.active; });
  7189. * // => objects for ['barney']
  7190. *
  7191. * // The `_.matches` iteratee shorthand.
  7192. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  7193. * // => objects for ['barney', 'fred']
  7194. *
  7195. * // The `_.matchesProperty` iteratee shorthand.
  7196. * _.dropRightWhile(users, ['active', false]);
  7197. * // => objects for ['barney']
  7198. *
  7199. * // The `_.property` iteratee shorthand.
  7200. * _.dropRightWhile(users, 'active');
  7201. * // => objects for ['barney', 'fred', 'pebbles']
  7202. */
  7203. function dropRightWhile(array, predicate) {
  7204. return array && array.length
  7205. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  7206. : [];
  7207. }
  7208. /**
  7209. * Creates a slice of `array` excluding elements dropped from the beginning.
  7210. * Elements are dropped until `predicate` returns falsey. The predicate is
  7211. * invoked with three arguments: (value, index, array).
  7212. *
  7213. * @static
  7214. * @memberOf _
  7215. * @since 3.0.0
  7216. * @category Array
  7217. * @param {Array} array The array to query.
  7218. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7219. * @returns {Array} Returns the slice of `array`.
  7220. * @example
  7221. *
  7222. * var users = [
  7223. * { 'user': 'barney', 'active': false },
  7224. * { 'user': 'fred', 'active': false },
  7225. * { 'user': 'pebbles', 'active': true }
  7226. * ];
  7227. *
  7228. * _.dropWhile(users, function(o) { return !o.active; });
  7229. * // => objects for ['pebbles']
  7230. *
  7231. * // The `_.matches` iteratee shorthand.
  7232. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  7233. * // => objects for ['fred', 'pebbles']
  7234. *
  7235. * // The `_.matchesProperty` iteratee shorthand.
  7236. * _.dropWhile(users, ['active', false]);
  7237. * // => objects for ['pebbles']
  7238. *
  7239. * // The `_.property` iteratee shorthand.
  7240. * _.dropWhile(users, 'active');
  7241. * // => objects for ['barney', 'fred', 'pebbles']
  7242. */
  7243. function dropWhile(array, predicate) {
  7244. return array && array.length
  7245. ? baseWhile(array, getIteratee(predicate, 3), true)
  7246. : [];
  7247. }
  7248. /**
  7249. * Fills elements of `array` with `value` from `start` up to, but not
  7250. * including, `end`.
  7251. *
  7252. * **Note:** This method mutates `array`.
  7253. *
  7254. * @static
  7255. * @memberOf _
  7256. * @since 3.2.0
  7257. * @category Array
  7258. * @param {Array} array The array to fill.
  7259. * @param {*} value The value to fill `array` with.
  7260. * @param {number} [start=0] The start position.
  7261. * @param {number} [end=array.length] The end position.
  7262. * @returns {Array} Returns `array`.
  7263. * @example
  7264. *
  7265. * var array = [1, 2, 3];
  7266. *
  7267. * _.fill(array, 'a');
  7268. * console.log(array);
  7269. * // => ['a', 'a', 'a']
  7270. *
  7271. * _.fill(Array(3), 2);
  7272. * // => [2, 2, 2]
  7273. *
  7274. * _.fill([4, 6, 8, 10], '*', 1, 3);
  7275. * // => [4, '*', '*', 10]
  7276. */
  7277. function fill(array, value, start, end) {
  7278. var length = array == null ? 0 : array.length;
  7279. if (!length) {
  7280. return [];
  7281. }
  7282. if (
  7283. start &&
  7284. typeof start !== 'number' &&
  7285. isIterateeCall(array, value, start)
  7286. ) {
  7287. start = 0;
  7288. end = length;
  7289. }
  7290. return baseFill(array, value, start, end);
  7291. }
  7292. /**
  7293. * This method is like `_.find` except that it returns the index of the first
  7294. * element `predicate` returns truthy for instead of the element itself.
  7295. *
  7296. * @static
  7297. * @memberOf _
  7298. * @since 1.1.0
  7299. * @category Array
  7300. * @param {Array} array The array to inspect.
  7301. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7302. * @param {number} [fromIndex=0] The index to search from.
  7303. * @returns {number} Returns the index of the found element, else `-1`.
  7304. * @example
  7305. *
  7306. * var users = [
  7307. * { 'user': 'barney', 'active': false },
  7308. * { 'user': 'fred', 'active': false },
  7309. * { 'user': 'pebbles', 'active': true }
  7310. * ];
  7311. *
  7312. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  7313. * // => 0
  7314. *
  7315. * // The `_.matches` iteratee shorthand.
  7316. * _.findIndex(users, { 'user': 'fred', 'active': false });
  7317. * // => 1
  7318. *
  7319. * // The `_.matchesProperty` iteratee shorthand.
  7320. * _.findIndex(users, ['active', false]);
  7321. * // => 0
  7322. *
  7323. * // The `_.property` iteratee shorthand.
  7324. * _.findIndex(users, 'active');
  7325. * // => 2
  7326. */
  7327. function findIndex(array, predicate, fromIndex) {
  7328. var length = array == null ? 0 : array.length;
  7329. if (!length) {
  7330. return -1;
  7331. }
  7332. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  7333. if (index < 0) {
  7334. index = nativeMax(length + index, 0);
  7335. }
  7336. return baseFindIndex(array, getIteratee(predicate, 3), index);
  7337. }
  7338. /**
  7339. * This method is like `_.findIndex` except that it iterates over elements
  7340. * of `collection` from right to left.
  7341. *
  7342. * @static
  7343. * @memberOf _
  7344. * @since 2.0.0
  7345. * @category Array
  7346. * @param {Array} array The array to inspect.
  7347. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7348. * @param {number} [fromIndex=array.length-1] The index to search from.
  7349. * @returns {number} Returns the index of the found element, else `-1`.
  7350. * @example
  7351. *
  7352. * var users = [
  7353. * { 'user': 'barney', 'active': true },
  7354. * { 'user': 'fred', 'active': false },
  7355. * { 'user': 'pebbles', 'active': false }
  7356. * ];
  7357. *
  7358. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  7359. * // => 2
  7360. *
  7361. * // The `_.matches` iteratee shorthand.
  7362. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  7363. * // => 0
  7364. *
  7365. * // The `_.matchesProperty` iteratee shorthand.
  7366. * _.findLastIndex(users, ['active', false]);
  7367. * // => 2
  7368. *
  7369. * // The `_.property` iteratee shorthand.
  7370. * _.findLastIndex(users, 'active');
  7371. * // => 0
  7372. */
  7373. function findLastIndex(array, predicate, fromIndex) {
  7374. var length = array == null ? 0 : array.length;
  7375. if (!length) {
  7376. return -1;
  7377. }
  7378. var index = length - 1;
  7379. if (fromIndex !== undefined) {
  7380. index = toInteger(fromIndex);
  7381. index =
  7382. fromIndex < 0
  7383. ? nativeMax(length + index, 0)
  7384. : nativeMin(index, length - 1);
  7385. }
  7386. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  7387. }
  7388. /**
  7389. * Flattens `array` a single level deep.
  7390. *
  7391. * @static
  7392. * @memberOf _
  7393. * @since 0.1.0
  7394. * @category Array
  7395. * @param {Array} array The array to flatten.
  7396. * @returns {Array} Returns the new flattened array.
  7397. * @example
  7398. *
  7399. * _.flatten([1, [2, [3, [4]], 5]]);
  7400. * // => [1, 2, [3, [4]], 5]
  7401. */
  7402. function flatten(array) {
  7403. var length = array == null ? 0 : array.length;
  7404. return length ? baseFlatten(array, 1) : [];
  7405. }
  7406. /**
  7407. * Recursively flattens `array`.
  7408. *
  7409. * @static
  7410. * @memberOf _
  7411. * @since 3.0.0
  7412. * @category Array
  7413. * @param {Array} array The array to flatten.
  7414. * @returns {Array} Returns the new flattened array.
  7415. * @example
  7416. *
  7417. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  7418. * // => [1, 2, 3, 4, 5]
  7419. */
  7420. function flattenDeep(array) {
  7421. var length = array == null ? 0 : array.length;
  7422. return length ? baseFlatten(array, INFINITY) : [];
  7423. }
  7424. /**
  7425. * Recursively flatten `array` up to `depth` times.
  7426. *
  7427. * @static
  7428. * @memberOf _
  7429. * @since 4.4.0
  7430. * @category Array
  7431. * @param {Array} array The array to flatten.
  7432. * @param {number} [depth=1] The maximum recursion depth.
  7433. * @returns {Array} Returns the new flattened array.
  7434. * @example
  7435. *
  7436. * var array = [1, [2, [3, [4]], 5]];
  7437. *
  7438. * _.flattenDepth(array, 1);
  7439. * // => [1, 2, [3, [4]], 5]
  7440. *
  7441. * _.flattenDepth(array, 2);
  7442. * // => [1, 2, 3, [4], 5]
  7443. */
  7444. function flattenDepth(array, depth) {
  7445. var length = array == null ? 0 : array.length;
  7446. if (!length) {
  7447. return [];
  7448. }
  7449. depth = depth === undefined ? 1 : toInteger(depth);
  7450. return baseFlatten(array, depth);
  7451. }
  7452. /**
  7453. * The inverse of `_.toPairs`; this method returns an object composed
  7454. * from key-value `pairs`.
  7455. *
  7456. * @static
  7457. * @memberOf _
  7458. * @since 4.0.0
  7459. * @category Array
  7460. * @param {Array} pairs The key-value pairs.
  7461. * @returns {Object} Returns the new object.
  7462. * @example
  7463. *
  7464. * _.fromPairs([['a', 1], ['b', 2]]);
  7465. * // => { 'a': 1, 'b': 2 }
  7466. */
  7467. function fromPairs(pairs) {
  7468. var index = -1,
  7469. length = pairs == null ? 0 : pairs.length,
  7470. result = {};
  7471. while (++index < length) {
  7472. var pair = pairs[index];
  7473. result[pair[0]] = pair[1];
  7474. }
  7475. return result;
  7476. }
  7477. /**
  7478. * Gets the first element of `array`.
  7479. *
  7480. * @static
  7481. * @memberOf _
  7482. * @since 0.1.0
  7483. * @alias first
  7484. * @category Array
  7485. * @param {Array} array The array to query.
  7486. * @returns {*} Returns the first element of `array`.
  7487. * @example
  7488. *
  7489. * _.head([1, 2, 3]);
  7490. * // => 1
  7491. *
  7492. * _.head([]);
  7493. * // => undefined
  7494. */
  7495. function head(array) {
  7496. return array && array.length ? array[0] : undefined;
  7497. }
  7498. /**
  7499. * Gets the index at which the first occurrence of `value` is found in `array`
  7500. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7501. * for equality comparisons. If `fromIndex` is negative, it's used as the
  7502. * offset from the end of `array`.
  7503. *
  7504. * @static
  7505. * @memberOf _
  7506. * @since 0.1.0
  7507. * @category Array
  7508. * @param {Array} array The array to inspect.
  7509. * @param {*} value The value to search for.
  7510. * @param {number} [fromIndex=0] The index to search from.
  7511. * @returns {number} Returns the index of the matched value, else `-1`.
  7512. * @example
  7513. *
  7514. * _.indexOf([1, 2, 1, 2], 2);
  7515. * // => 1
  7516. *
  7517. * // Search from the `fromIndex`.
  7518. * _.indexOf([1, 2, 1, 2], 2, 2);
  7519. * // => 3
  7520. */
  7521. function indexOf(array, value, fromIndex) {
  7522. var length = array == null ? 0 : array.length;
  7523. if (!length) {
  7524. return -1;
  7525. }
  7526. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  7527. if (index < 0) {
  7528. index = nativeMax(length + index, 0);
  7529. }
  7530. return baseIndexOf(array, value, index);
  7531. }
  7532. /**
  7533. * Gets all but the last element of `array`.
  7534. *
  7535. * @static
  7536. * @memberOf _
  7537. * @since 0.1.0
  7538. * @category Array
  7539. * @param {Array} array The array to query.
  7540. * @returns {Array} Returns the slice of `array`.
  7541. * @example
  7542. *
  7543. * _.initial([1, 2, 3]);
  7544. * // => [1, 2]
  7545. */
  7546. function initial(array) {
  7547. var length = array == null ? 0 : array.length;
  7548. return length ? baseSlice(array, 0, -1) : [];
  7549. }
  7550. /**
  7551. * Creates an array of unique values that are included in all given arrays
  7552. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7553. * for equality comparisons. The order and references of result values are
  7554. * determined by the first array.
  7555. *
  7556. * @static
  7557. * @memberOf _
  7558. * @since 0.1.0
  7559. * @category Array
  7560. * @param {...Array} [arrays] The arrays to inspect.
  7561. * @returns {Array} Returns the new array of intersecting values.
  7562. * @example
  7563. *
  7564. * _.intersection([2, 1], [2, 3]);
  7565. * // => [2]
  7566. */
  7567. var intersection = baseRest(function(arrays) {
  7568. var mapped = arrayMap(arrays, castArrayLikeObject);
  7569. return mapped.length && mapped[0] === arrays[0]
  7570. ? baseIntersection(mapped)
  7571. : [];
  7572. });
  7573. /**
  7574. * This method is like `_.intersection` except that it accepts `iteratee`
  7575. * which is invoked for each element of each `arrays` to generate the criterion
  7576. * by which they're compared. The order and references of result values are
  7577. * determined by the first array. The iteratee is invoked with one argument:
  7578. * (value).
  7579. *
  7580. * @static
  7581. * @memberOf _
  7582. * @since 4.0.0
  7583. * @category Array
  7584. * @param {...Array} [arrays] The arrays to inspect.
  7585. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7586. * @returns {Array} Returns the new array of intersecting values.
  7587. * @example
  7588. *
  7589. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7590. * // => [2.1]
  7591. *
  7592. * // The `_.property` iteratee shorthand.
  7593. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7594. * // => [{ 'x': 1 }]
  7595. */
  7596. var intersectionBy = baseRest(function(arrays) {
  7597. var iteratee = last(arrays),
  7598. mapped = arrayMap(arrays, castArrayLikeObject);
  7599. if (iteratee === last(mapped)) {
  7600. iteratee = undefined;
  7601. } else {
  7602. mapped.pop();
  7603. }
  7604. return mapped.length && mapped[0] === arrays[0]
  7605. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  7606. : [];
  7607. });
  7608. /**
  7609. * This method is like `_.intersection` except that it accepts `comparator`
  7610. * which is invoked to compare elements of `arrays`. The order and references
  7611. * of result values are determined by the first array. The comparator is
  7612. * invoked with two arguments: (arrVal, othVal).
  7613. *
  7614. * @static
  7615. * @memberOf _
  7616. * @since 4.0.0
  7617. * @category Array
  7618. * @param {...Array} [arrays] The arrays to inspect.
  7619. * @param {Function} [comparator] The comparator invoked per element.
  7620. * @returns {Array} Returns the new array of intersecting values.
  7621. * @example
  7622. *
  7623. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7624. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7625. *
  7626. * _.intersectionWith(objects, others, _.isEqual);
  7627. * // => [{ 'x': 1, 'y': 2 }]
  7628. */
  7629. var intersectionWith = baseRest(function(arrays) {
  7630. var comparator = last(arrays),
  7631. mapped = arrayMap(arrays, castArrayLikeObject);
  7632. comparator = typeof comparator === 'function' ? comparator : undefined;
  7633. if (comparator) {
  7634. mapped.pop();
  7635. }
  7636. return mapped.length && mapped[0] === arrays[0]
  7637. ? baseIntersection(mapped, undefined, comparator)
  7638. : [];
  7639. });
  7640. /**
  7641. * Converts all elements in `array` into a string separated by `separator`.
  7642. *
  7643. * @static
  7644. * @memberOf _
  7645. * @since 4.0.0
  7646. * @category Array
  7647. * @param {Array} array The array to convert.
  7648. * @param {string} [separator=','] The element separator.
  7649. * @returns {string} Returns the joined string.
  7650. * @example
  7651. *
  7652. * _.join(['a', 'b', 'c'], '~');
  7653. * // => 'a~b~c'
  7654. */
  7655. function join(array, separator) {
  7656. return array == null ? '' : nativeJoin.call(array, separator);
  7657. }
  7658. /**
  7659. * Gets the last element of `array`.
  7660. *
  7661. * @static
  7662. * @memberOf _
  7663. * @since 0.1.0
  7664. * @category Array
  7665. * @param {Array} array The array to query.
  7666. * @returns {*} Returns the last element of `array`.
  7667. * @example
  7668. *
  7669. * _.last([1, 2, 3]);
  7670. * // => 3
  7671. */
  7672. function last(array) {
  7673. var length = array == null ? 0 : array.length;
  7674. return length ? array[length - 1] : undefined;
  7675. }
  7676. /**
  7677. * This method is like `_.indexOf` except that it iterates over elements of
  7678. * `array` from right to left.
  7679. *
  7680. * @static
  7681. * @memberOf _
  7682. * @since 0.1.0
  7683. * @category Array
  7684. * @param {Array} array The array to inspect.
  7685. * @param {*} value The value to search for.
  7686. * @param {number} [fromIndex=array.length-1] The index to search from.
  7687. * @returns {number} Returns the index of the matched value, else `-1`.
  7688. * @example
  7689. *
  7690. * _.lastIndexOf([1, 2, 1, 2], 2);
  7691. * // => 3
  7692. *
  7693. * // Search from the `fromIndex`.
  7694. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7695. * // => 1
  7696. */
  7697. function lastIndexOf(array, value, fromIndex) {
  7698. var length = array == null ? 0 : array.length;
  7699. if (!length) {
  7700. return -1;
  7701. }
  7702. var index = length;
  7703. if (fromIndex !== undefined) {
  7704. index = toInteger(fromIndex);
  7705. index =
  7706. index < 0
  7707. ? nativeMax(length + index, 0)
  7708. : nativeMin(index, length - 1);
  7709. }
  7710. return value === value
  7711. ? strictLastIndexOf(array, value, index)
  7712. : baseFindIndex(array, baseIsNaN, index, true);
  7713. }
  7714. /**
  7715. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7716. * element from the end is returned.
  7717. *
  7718. * @static
  7719. * @memberOf _
  7720. * @since 4.11.0
  7721. * @category Array
  7722. * @param {Array} array The array to query.
  7723. * @param {number} [n=0] The index of the element to return.
  7724. * @returns {*} Returns the nth element of `array`.
  7725. * @example
  7726. *
  7727. * var array = ['a', 'b', 'c', 'd'];
  7728. *
  7729. * _.nth(array, 1);
  7730. * // => 'b'
  7731. *
  7732. * _.nth(array, -2);
  7733. * // => 'c';
  7734. */
  7735. function nth(array, n) {
  7736. return array && array.length ? baseNth(array, toInteger(n)) : undefined;
  7737. }
  7738. /**
  7739. * Removes all given values from `array` using
  7740. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7741. * for equality comparisons.
  7742. *
  7743. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7744. * to remove elements from an array by predicate.
  7745. *
  7746. * @static
  7747. * @memberOf _
  7748. * @since 2.0.0
  7749. * @category Array
  7750. * @param {Array} array The array to modify.
  7751. * @param {...*} [values] The values to remove.
  7752. * @returns {Array} Returns `array`.
  7753. * @example
  7754. *
  7755. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7756. *
  7757. * _.pull(array, 'a', 'c');
  7758. * console.log(array);
  7759. * // => ['b', 'b']
  7760. */
  7761. var pull = baseRest(pullAll);
  7762. /**
  7763. * This method is like `_.pull` except that it accepts an array of values to remove.
  7764. *
  7765. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7766. *
  7767. * @static
  7768. * @memberOf _
  7769. * @since 4.0.0
  7770. * @category Array
  7771. * @param {Array} array The array to modify.
  7772. * @param {Array} values The values to remove.
  7773. * @returns {Array} Returns `array`.
  7774. * @example
  7775. *
  7776. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7777. *
  7778. * _.pullAll(array, ['a', 'c']);
  7779. * console.log(array);
  7780. * // => ['b', 'b']
  7781. */
  7782. function pullAll(array, values) {
  7783. return array && array.length && values && values.length
  7784. ? basePullAll(array, values)
  7785. : array;
  7786. }
  7787. /**
  7788. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7789. * invoked for each element of `array` and `values` to generate the criterion
  7790. * by which they're compared. The iteratee is invoked with one argument: (value).
  7791. *
  7792. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7793. *
  7794. * @static
  7795. * @memberOf _
  7796. * @since 4.0.0
  7797. * @category Array
  7798. * @param {Array} array The array to modify.
  7799. * @param {Array} values The values to remove.
  7800. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7801. * @returns {Array} Returns `array`.
  7802. * @example
  7803. *
  7804. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7805. *
  7806. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7807. * console.log(array);
  7808. * // => [{ 'x': 2 }]
  7809. */
  7810. function pullAllBy(array, values, iteratee) {
  7811. return array && array.length && values && values.length
  7812. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7813. : array;
  7814. }
  7815. /**
  7816. * This method is like `_.pullAll` except that it accepts `comparator` which
  7817. * is invoked to compare elements of `array` to `values`. The comparator is
  7818. * invoked with two arguments: (arrVal, othVal).
  7819. *
  7820. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7821. *
  7822. * @static
  7823. * @memberOf _
  7824. * @since 4.6.0
  7825. * @category Array
  7826. * @param {Array} array The array to modify.
  7827. * @param {Array} values The values to remove.
  7828. * @param {Function} [comparator] The comparator invoked per element.
  7829. * @returns {Array} Returns `array`.
  7830. * @example
  7831. *
  7832. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7833. *
  7834. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7835. * console.log(array);
  7836. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7837. */
  7838. function pullAllWith(array, values, comparator) {
  7839. return array && array.length && values && values.length
  7840. ? basePullAll(array, values, undefined, comparator)
  7841. : array;
  7842. }
  7843. /**
  7844. * Removes elements from `array` corresponding to `indexes` and returns an
  7845. * array of removed elements.
  7846. *
  7847. * **Note:** Unlike `_.at`, this method mutates `array`.
  7848. *
  7849. * @static
  7850. * @memberOf _
  7851. * @since 3.0.0
  7852. * @category Array
  7853. * @param {Array} array The array to modify.
  7854. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7855. * @returns {Array} Returns the new array of removed elements.
  7856. * @example
  7857. *
  7858. * var array = ['a', 'b', 'c', 'd'];
  7859. * var pulled = _.pullAt(array, [1, 3]);
  7860. *
  7861. * console.log(array);
  7862. * // => ['a', 'c']
  7863. *
  7864. * console.log(pulled);
  7865. * // => ['b', 'd']
  7866. */
  7867. var pullAt = flatRest(function(array, indexes) {
  7868. var length = array == null ? 0 : array.length,
  7869. result = baseAt(array, indexes);
  7870. basePullAt(
  7871. array,
  7872. arrayMap(indexes, function(index) {
  7873. return isIndex(index, length) ? +index : index;
  7874. }).sort(compareAscending)
  7875. );
  7876. return result;
  7877. });
  7878. /**
  7879. * Removes all elements from `array` that `predicate` returns truthy for
  7880. * and returns an array of the removed elements. The predicate is invoked
  7881. * with three arguments: (value, index, array).
  7882. *
  7883. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7884. * to pull elements from an array by value.
  7885. *
  7886. * @static
  7887. * @memberOf _
  7888. * @since 2.0.0
  7889. * @category Array
  7890. * @param {Array} array The array to modify.
  7891. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7892. * @returns {Array} Returns the new array of removed elements.
  7893. * @example
  7894. *
  7895. * var array = [1, 2, 3, 4];
  7896. * var evens = _.remove(array, function(n) {
  7897. * return n % 2 == 0;
  7898. * });
  7899. *
  7900. * console.log(array);
  7901. * // => [1, 3]
  7902. *
  7903. * console.log(evens);
  7904. * // => [2, 4]
  7905. */
  7906. function remove(array, predicate) {
  7907. var result = [];
  7908. if (!(array && array.length)) {
  7909. return result;
  7910. }
  7911. var index = -1,
  7912. indexes = [],
  7913. length = array.length;
  7914. predicate = getIteratee(predicate, 3);
  7915. while (++index < length) {
  7916. var value = array[index];
  7917. if (predicate(value, index, array)) {
  7918. result.push(value);
  7919. indexes.push(index);
  7920. }
  7921. }
  7922. basePullAt(array, indexes);
  7923. return result;
  7924. }
  7925. /**
  7926. * Reverses `array` so that the first element becomes the last, the second
  7927. * element becomes the second to last, and so on.
  7928. *
  7929. * **Note:** This method mutates `array` and is based on
  7930. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7931. *
  7932. * @static
  7933. * @memberOf _
  7934. * @since 4.0.0
  7935. * @category Array
  7936. * @param {Array} array The array to modify.
  7937. * @returns {Array} Returns `array`.
  7938. * @example
  7939. *
  7940. * var array = [1, 2, 3];
  7941. *
  7942. * _.reverse(array);
  7943. * // => [3, 2, 1]
  7944. *
  7945. * console.log(array);
  7946. * // => [3, 2, 1]
  7947. */
  7948. function reverse(array) {
  7949. return array == null ? array : nativeReverse.call(array);
  7950. }
  7951. /**
  7952. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7953. *
  7954. * **Note:** This method is used instead of
  7955. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7956. * returned.
  7957. *
  7958. * @static
  7959. * @memberOf _
  7960. * @since 3.0.0
  7961. * @category Array
  7962. * @param {Array} array The array to slice.
  7963. * @param {number} [start=0] The start position.
  7964. * @param {number} [end=array.length] The end position.
  7965. * @returns {Array} Returns the slice of `array`.
  7966. */
  7967. function slice(array, start, end) {
  7968. var length = array == null ? 0 : array.length;
  7969. if (!length) {
  7970. return [];
  7971. }
  7972. if (end && typeof end !== 'number' && isIterateeCall(array, start, end)) {
  7973. start = 0;
  7974. end = length;
  7975. } else {
  7976. start = start == null ? 0 : toInteger(start);
  7977. end = end === undefined ? length : toInteger(end);
  7978. }
  7979. return baseSlice(array, start, end);
  7980. }
  7981. /**
  7982. * Uses a binary search to determine the lowest index at which `value`
  7983. * should be inserted into `array` in order to maintain its sort order.
  7984. *
  7985. * @static
  7986. * @memberOf _
  7987. * @since 0.1.0
  7988. * @category Array
  7989. * @param {Array} array The sorted array to inspect.
  7990. * @param {*} value The value to evaluate.
  7991. * @returns {number} Returns the index at which `value` should be inserted
  7992. * into `array`.
  7993. * @example
  7994. *
  7995. * _.sortedIndex([30, 50], 40);
  7996. * // => 1
  7997. */
  7998. function sortedIndex(array, value) {
  7999. return baseSortedIndex(array, value);
  8000. }
  8001. /**
  8002. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  8003. * which is invoked for `value` and each element of `array` to compute their
  8004. * sort ranking. The iteratee is invoked with one argument: (value).
  8005. *
  8006. * @static
  8007. * @memberOf _
  8008. * @since 4.0.0
  8009. * @category Array
  8010. * @param {Array} array The sorted array to inspect.
  8011. * @param {*} value The value to evaluate.
  8012. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8013. * @returns {number} Returns the index at which `value` should be inserted
  8014. * into `array`.
  8015. * @example
  8016. *
  8017. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  8018. *
  8019. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  8020. * // => 0
  8021. *
  8022. * // The `_.property` iteratee shorthand.
  8023. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  8024. * // => 0
  8025. */
  8026. function sortedIndexBy(array, value, iteratee) {
  8027. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  8028. }
  8029. /**
  8030. * This method is like `_.indexOf` except that it performs a binary
  8031. * search on a sorted `array`.
  8032. *
  8033. * @static
  8034. * @memberOf _
  8035. * @since 4.0.0
  8036. * @category Array
  8037. * @param {Array} array The array to inspect.
  8038. * @param {*} value The value to search for.
  8039. * @returns {number} Returns the index of the matched value, else `-1`.
  8040. * @example
  8041. *
  8042. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  8043. * // => 1
  8044. */
  8045. function sortedIndexOf(array, value) {
  8046. var length = array == null ? 0 : array.length;
  8047. if (length) {
  8048. var index = baseSortedIndex(array, value);
  8049. if (index < length && eq(array[index], value)) {
  8050. return index;
  8051. }
  8052. }
  8053. return -1;
  8054. }
  8055. /**
  8056. * This method is like `_.sortedIndex` except that it returns the highest
  8057. * index at which `value` should be inserted into `array` in order to
  8058. * maintain its sort order.
  8059. *
  8060. * @static
  8061. * @memberOf _
  8062. * @since 3.0.0
  8063. * @category Array
  8064. * @param {Array} array The sorted array to inspect.
  8065. * @param {*} value The value to evaluate.
  8066. * @returns {number} Returns the index at which `value` should be inserted
  8067. * into `array`.
  8068. * @example
  8069. *
  8070. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  8071. * // => 4
  8072. */
  8073. function sortedLastIndex(array, value) {
  8074. return baseSortedIndex(array, value, true);
  8075. }
  8076. /**
  8077. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  8078. * which is invoked for `value` and each element of `array` to compute their
  8079. * sort ranking. The iteratee is invoked with one argument: (value).
  8080. *
  8081. * @static
  8082. * @memberOf _
  8083. * @since 4.0.0
  8084. * @category Array
  8085. * @param {Array} array The sorted array to inspect.
  8086. * @param {*} value The value to evaluate.
  8087. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8088. * @returns {number} Returns the index at which `value` should be inserted
  8089. * into `array`.
  8090. * @example
  8091. *
  8092. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  8093. *
  8094. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  8095. * // => 1
  8096. *
  8097. * // The `_.property` iteratee shorthand.
  8098. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  8099. * // => 1
  8100. */
  8101. function sortedLastIndexBy(array, value, iteratee) {
  8102. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  8103. }
  8104. /**
  8105. * This method is like `_.lastIndexOf` except that it performs a binary
  8106. * search on a sorted `array`.
  8107. *
  8108. * @static
  8109. * @memberOf _
  8110. * @since 4.0.0
  8111. * @category Array
  8112. * @param {Array} array The array to inspect.
  8113. * @param {*} value The value to search for.
  8114. * @returns {number} Returns the index of the matched value, else `-1`.
  8115. * @example
  8116. *
  8117. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  8118. * // => 3
  8119. */
  8120. function sortedLastIndexOf(array, value) {
  8121. var length = array == null ? 0 : array.length;
  8122. if (length) {
  8123. var index = baseSortedIndex(array, value, true) - 1;
  8124. if (eq(array[index], value)) {
  8125. return index;
  8126. }
  8127. }
  8128. return -1;
  8129. }
  8130. /**
  8131. * This method is like `_.uniq` except that it's designed and optimized
  8132. * for sorted arrays.
  8133. *
  8134. * @static
  8135. * @memberOf _
  8136. * @since 4.0.0
  8137. * @category Array
  8138. * @param {Array} array The array to inspect.
  8139. * @returns {Array} Returns the new duplicate free array.
  8140. * @example
  8141. *
  8142. * _.sortedUniq([1, 1, 2]);
  8143. * // => [1, 2]
  8144. */
  8145. function sortedUniq(array) {
  8146. return array && array.length ? baseSortedUniq(array) : [];
  8147. }
  8148. /**
  8149. * This method is like `_.uniqBy` except that it's designed and optimized
  8150. * for sorted arrays.
  8151. *
  8152. * @static
  8153. * @memberOf _
  8154. * @since 4.0.0
  8155. * @category Array
  8156. * @param {Array} array The array to inspect.
  8157. * @param {Function} [iteratee] The iteratee invoked per element.
  8158. * @returns {Array} Returns the new duplicate free array.
  8159. * @example
  8160. *
  8161. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  8162. * // => [1.1, 2.3]
  8163. */
  8164. function sortedUniqBy(array, iteratee) {
  8165. return array && array.length
  8166. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  8167. : [];
  8168. }
  8169. /**
  8170. * Gets all but the first element of `array`.
  8171. *
  8172. * @static
  8173. * @memberOf _
  8174. * @since 4.0.0
  8175. * @category Array
  8176. * @param {Array} array The array to query.
  8177. * @returns {Array} Returns the slice of `array`.
  8178. * @example
  8179. *
  8180. * _.tail([1, 2, 3]);
  8181. * // => [2, 3]
  8182. */
  8183. function tail(array) {
  8184. var length = array == null ? 0 : array.length;
  8185. return length ? baseSlice(array, 1, length) : [];
  8186. }
  8187. /**
  8188. * Creates a slice of `array` with `n` elements taken from the beginning.
  8189. *
  8190. * @static
  8191. * @memberOf _
  8192. * @since 0.1.0
  8193. * @category Array
  8194. * @param {Array} array The array to query.
  8195. * @param {number} [n=1] The number of elements to take.
  8196. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8197. * @returns {Array} Returns the slice of `array`.
  8198. * @example
  8199. *
  8200. * _.take([1, 2, 3]);
  8201. * // => [1]
  8202. *
  8203. * _.take([1, 2, 3], 2);
  8204. * // => [1, 2]
  8205. *
  8206. * _.take([1, 2, 3], 5);
  8207. * // => [1, 2, 3]
  8208. *
  8209. * _.take([1, 2, 3], 0);
  8210. * // => []
  8211. */
  8212. function take(array, n, guard) {
  8213. if (!(array && array.length)) {
  8214. return [];
  8215. }
  8216. n = guard || n === undefined ? 1 : toInteger(n);
  8217. return baseSlice(array, 0, n < 0 ? 0 : n);
  8218. }
  8219. /**
  8220. * Creates a slice of `array` with `n` elements taken from the end.
  8221. *
  8222. * @static
  8223. * @memberOf _
  8224. * @since 3.0.0
  8225. * @category Array
  8226. * @param {Array} array The array to query.
  8227. * @param {number} [n=1] The number of elements to take.
  8228. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8229. * @returns {Array} Returns the slice of `array`.
  8230. * @example
  8231. *
  8232. * _.takeRight([1, 2, 3]);
  8233. * // => [3]
  8234. *
  8235. * _.takeRight([1, 2, 3], 2);
  8236. * // => [2, 3]
  8237. *
  8238. * _.takeRight([1, 2, 3], 5);
  8239. * // => [1, 2, 3]
  8240. *
  8241. * _.takeRight([1, 2, 3], 0);
  8242. * // => []
  8243. */
  8244. function takeRight(array, n, guard) {
  8245. var length = array == null ? 0 : array.length;
  8246. if (!length) {
  8247. return [];
  8248. }
  8249. n = guard || n === undefined ? 1 : toInteger(n);
  8250. n = length - n;
  8251. return baseSlice(array, n < 0 ? 0 : n, length);
  8252. }
  8253. /**
  8254. * Creates a slice of `array` with elements taken from the end. Elements are
  8255. * taken until `predicate` returns falsey. The predicate is invoked with
  8256. * three arguments: (value, index, array).
  8257. *
  8258. * @static
  8259. * @memberOf _
  8260. * @since 3.0.0
  8261. * @category Array
  8262. * @param {Array} array The array to query.
  8263. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8264. * @returns {Array} Returns the slice of `array`.
  8265. * @example
  8266. *
  8267. * var users = [
  8268. * { 'user': 'barney', 'active': true },
  8269. * { 'user': 'fred', 'active': false },
  8270. * { 'user': 'pebbles', 'active': false }
  8271. * ];
  8272. *
  8273. * _.takeRightWhile(users, function(o) { return !o.active; });
  8274. * // => objects for ['fred', 'pebbles']
  8275. *
  8276. * // The `_.matches` iteratee shorthand.
  8277. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  8278. * // => objects for ['pebbles']
  8279. *
  8280. * // The `_.matchesProperty` iteratee shorthand.
  8281. * _.takeRightWhile(users, ['active', false]);
  8282. * // => objects for ['fred', 'pebbles']
  8283. *
  8284. * // The `_.property` iteratee shorthand.
  8285. * _.takeRightWhile(users, 'active');
  8286. * // => []
  8287. */
  8288. function takeRightWhile(array, predicate) {
  8289. return array && array.length
  8290. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  8291. : [];
  8292. }
  8293. /**
  8294. * Creates a slice of `array` with elements taken from the beginning. Elements
  8295. * are taken until `predicate` returns falsey. The predicate is invoked with
  8296. * three arguments: (value, index, array).
  8297. *
  8298. * @static
  8299. * @memberOf _
  8300. * @since 3.0.0
  8301. * @category Array
  8302. * @param {Array} array The array to query.
  8303. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8304. * @returns {Array} Returns the slice of `array`.
  8305. * @example
  8306. *
  8307. * var users = [
  8308. * { 'user': 'barney', 'active': false },
  8309. * { 'user': 'fred', 'active': false },
  8310. * { 'user': 'pebbles', 'active': true }
  8311. * ];
  8312. *
  8313. * _.takeWhile(users, function(o) { return !o.active; });
  8314. * // => objects for ['barney', 'fred']
  8315. *
  8316. * // The `_.matches` iteratee shorthand.
  8317. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  8318. * // => objects for ['barney']
  8319. *
  8320. * // The `_.matchesProperty` iteratee shorthand.
  8321. * _.takeWhile(users, ['active', false]);
  8322. * // => objects for ['barney', 'fred']
  8323. *
  8324. * // The `_.property` iteratee shorthand.
  8325. * _.takeWhile(users, 'active');
  8326. * // => []
  8327. */
  8328. function takeWhile(array, predicate) {
  8329. return array && array.length
  8330. ? baseWhile(array, getIteratee(predicate, 3))
  8331. : [];
  8332. }
  8333. /**
  8334. * Creates an array of unique values, in order, from all given arrays using
  8335. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8336. * for equality comparisons.
  8337. *
  8338. * @static
  8339. * @memberOf _
  8340. * @since 0.1.0
  8341. * @category Array
  8342. * @param {...Array} [arrays] The arrays to inspect.
  8343. * @returns {Array} Returns the new array of combined values.
  8344. * @example
  8345. *
  8346. * _.union([2], [1, 2]);
  8347. * // => [2, 1]
  8348. */
  8349. var union = baseRest(function(arrays) {
  8350. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  8351. });
  8352. /**
  8353. * This method is like `_.union` except that it accepts `iteratee` which is
  8354. * invoked for each element of each `arrays` to generate the criterion by
  8355. * which uniqueness is computed. Result values are chosen from the first
  8356. * array in which the value occurs. The iteratee is invoked with one argument:
  8357. * (value).
  8358. *
  8359. * @static
  8360. * @memberOf _
  8361. * @since 4.0.0
  8362. * @category Array
  8363. * @param {...Array} [arrays] The arrays to inspect.
  8364. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8365. * @returns {Array} Returns the new array of combined values.
  8366. * @example
  8367. *
  8368. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  8369. * // => [2.1, 1.2]
  8370. *
  8371. * // The `_.property` iteratee shorthand.
  8372. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  8373. * // => [{ 'x': 1 }, { 'x': 2 }]
  8374. */
  8375. var unionBy = baseRest(function(arrays) {
  8376. var iteratee = last(arrays);
  8377. if (isArrayLikeObject(iteratee)) {
  8378. iteratee = undefined;
  8379. }
  8380. return baseUniq(
  8381. baseFlatten(arrays, 1, isArrayLikeObject, true),
  8382. getIteratee(iteratee, 2)
  8383. );
  8384. });
  8385. /**
  8386. * This method is like `_.union` except that it accepts `comparator` which
  8387. * is invoked to compare elements of `arrays`. Result values are chosen from
  8388. * the first array in which the value occurs. The comparator is invoked
  8389. * with two arguments: (arrVal, othVal).
  8390. *
  8391. * @static
  8392. * @memberOf _
  8393. * @since 4.0.0
  8394. * @category Array
  8395. * @param {...Array} [arrays] The arrays to inspect.
  8396. * @param {Function} [comparator] The comparator invoked per element.
  8397. * @returns {Array} Returns the new array of combined values.
  8398. * @example
  8399. *
  8400. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8401. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8402. *
  8403. * _.unionWith(objects, others, _.isEqual);
  8404. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8405. */
  8406. var unionWith = baseRest(function(arrays) {
  8407. var comparator = last(arrays);
  8408. comparator = typeof comparator === 'function' ? comparator : undefined;
  8409. return baseUniq(
  8410. baseFlatten(arrays, 1, isArrayLikeObject, true),
  8411. undefined,
  8412. comparator
  8413. );
  8414. });
  8415. /**
  8416. * Creates a duplicate-free version of an array, using
  8417. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8418. * for equality comparisons, in which only the first occurrence of each element
  8419. * is kept. The order of result values is determined by the order they occur
  8420. * in the array.
  8421. *
  8422. * @static
  8423. * @memberOf _
  8424. * @since 0.1.0
  8425. * @category Array
  8426. * @param {Array} array The array to inspect.
  8427. * @returns {Array} Returns the new duplicate free array.
  8428. * @example
  8429. *
  8430. * _.uniq([2, 1, 2]);
  8431. * // => [2, 1]
  8432. */
  8433. function uniq(array) {
  8434. return array && array.length ? baseUniq(array) : [];
  8435. }
  8436. /**
  8437. * This method is like `_.uniq` except that it accepts `iteratee` which is
  8438. * invoked for each element in `array` to generate the criterion by which
  8439. * uniqueness is computed. The order of result values is determined by the
  8440. * order they occur in the array. The iteratee is invoked with one argument:
  8441. * (value).
  8442. *
  8443. * @static
  8444. * @memberOf _
  8445. * @since 4.0.0
  8446. * @category Array
  8447. * @param {Array} array The array to inspect.
  8448. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8449. * @returns {Array} Returns the new duplicate free array.
  8450. * @example
  8451. *
  8452. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  8453. * // => [2.1, 1.2]
  8454. *
  8455. * // The `_.property` iteratee shorthand.
  8456. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  8457. * // => [{ 'x': 1 }, { 'x': 2 }]
  8458. */
  8459. function uniqBy(array, iteratee) {
  8460. return array && array.length
  8461. ? baseUniq(array, getIteratee(iteratee, 2))
  8462. : [];
  8463. }
  8464. /**
  8465. * This method is like `_.uniq` except that it accepts `comparator` which
  8466. * is invoked to compare elements of `array`. The order of result values is
  8467. * determined by the order they occur in the array.The comparator is invoked
  8468. * with two arguments: (arrVal, othVal).
  8469. *
  8470. * @static
  8471. * @memberOf _
  8472. * @since 4.0.0
  8473. * @category Array
  8474. * @param {Array} array The array to inspect.
  8475. * @param {Function} [comparator] The comparator invoked per element.
  8476. * @returns {Array} Returns the new duplicate free array.
  8477. * @example
  8478. *
  8479. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8480. *
  8481. * _.uniqWith(objects, _.isEqual);
  8482. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  8483. */
  8484. function uniqWith(array, comparator) {
  8485. comparator = typeof comparator === 'function' ? comparator : undefined;
  8486. return array && array.length
  8487. ? baseUniq(array, undefined, comparator)
  8488. : [];
  8489. }
  8490. /**
  8491. * This method is like `_.zip` except that it accepts an array of grouped
  8492. * elements and creates an array regrouping the elements to their pre-zip
  8493. * configuration.
  8494. *
  8495. * @static
  8496. * @memberOf _
  8497. * @since 1.2.0
  8498. * @category Array
  8499. * @param {Array} array The array of grouped elements to process.
  8500. * @returns {Array} Returns the new array of regrouped elements.
  8501. * @example
  8502. *
  8503. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  8504. * // => [['a', 1, true], ['b', 2, false]]
  8505. *
  8506. * _.unzip(zipped);
  8507. * // => [['a', 'b'], [1, 2], [true, false]]
  8508. */
  8509. function unzip(array) {
  8510. if (!(array && array.length)) {
  8511. return [];
  8512. }
  8513. var length = 0;
  8514. array = arrayFilter(array, function(group) {
  8515. if (isArrayLikeObject(group)) {
  8516. length = nativeMax(group.length, length);
  8517. return true;
  8518. }
  8519. });
  8520. return baseTimes(length, function(index) {
  8521. return arrayMap(array, baseProperty(index));
  8522. });
  8523. }
  8524. /**
  8525. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  8526. * how regrouped values should be combined. The iteratee is invoked with the
  8527. * elements of each group: (...group).
  8528. *
  8529. * @static
  8530. * @memberOf _
  8531. * @since 3.8.0
  8532. * @category Array
  8533. * @param {Array} array The array of grouped elements to process.
  8534. * @param {Function} [iteratee=_.identity] The function to combine
  8535. * regrouped values.
  8536. * @returns {Array} Returns the new array of regrouped elements.
  8537. * @example
  8538. *
  8539. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  8540. * // => [[1, 10, 100], [2, 20, 200]]
  8541. *
  8542. * _.unzipWith(zipped, _.add);
  8543. * // => [3, 30, 300]
  8544. */
  8545. function unzipWith(array, iteratee) {
  8546. if (!(array && array.length)) {
  8547. return [];
  8548. }
  8549. var result = unzip(array);
  8550. if (iteratee == null) {
  8551. return result;
  8552. }
  8553. return arrayMap(result, function(group) {
  8554. return apply(iteratee, undefined, group);
  8555. });
  8556. }
  8557. /**
  8558. * Creates an array excluding all given values using
  8559. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8560. * for equality comparisons.
  8561. *
  8562. * **Note:** Unlike `_.pull`, this method returns a new array.
  8563. *
  8564. * @static
  8565. * @memberOf _
  8566. * @since 0.1.0
  8567. * @category Array
  8568. * @param {Array} array The array to inspect.
  8569. * @param {...*} [values] The values to exclude.
  8570. * @returns {Array} Returns the new array of filtered values.
  8571. * @see _.difference, _.xor
  8572. * @example
  8573. *
  8574. * _.without([2, 1, 2, 3], 1, 2);
  8575. * // => [3]
  8576. */
  8577. var without = baseRest(function(array, values) {
  8578. return isArrayLikeObject(array) ? baseDifference(array, values) : [];
  8579. });
  8580. /**
  8581. * Creates an array of unique values that is the
  8582. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  8583. * of the given arrays. The order of result values is determined by the order
  8584. * they occur in the arrays.
  8585. *
  8586. * @static
  8587. * @memberOf _
  8588. * @since 2.4.0
  8589. * @category Array
  8590. * @param {...Array} [arrays] The arrays to inspect.
  8591. * @returns {Array} Returns the new array of filtered values.
  8592. * @see _.difference, _.without
  8593. * @example
  8594. *
  8595. * _.xor([2, 1], [2, 3]);
  8596. * // => [1, 3]
  8597. */
  8598. var xor = baseRest(function(arrays) {
  8599. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  8600. });
  8601. /**
  8602. * This method is like `_.xor` except that it accepts `iteratee` which is
  8603. * invoked for each element of each `arrays` to generate the criterion by
  8604. * which by which they're compared. The order of result values is determined
  8605. * by the order they occur in the arrays. The iteratee is invoked with one
  8606. * argument: (value).
  8607. *
  8608. * @static
  8609. * @memberOf _
  8610. * @since 4.0.0
  8611. * @category Array
  8612. * @param {...Array} [arrays] The arrays to inspect.
  8613. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8614. * @returns {Array} Returns the new array of filtered values.
  8615. * @example
  8616. *
  8617. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  8618. * // => [1.2, 3.4]
  8619. *
  8620. * // The `_.property` iteratee shorthand.
  8621. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  8622. * // => [{ 'x': 2 }]
  8623. */
  8624. var xorBy = baseRest(function(arrays) {
  8625. var iteratee = last(arrays);
  8626. if (isArrayLikeObject(iteratee)) {
  8627. iteratee = undefined;
  8628. }
  8629. return baseXor(
  8630. arrayFilter(arrays, isArrayLikeObject),
  8631. getIteratee(iteratee, 2)
  8632. );
  8633. });
  8634. /**
  8635. * This method is like `_.xor` except that it accepts `comparator` which is
  8636. * invoked to compare elements of `arrays`. The order of result values is
  8637. * determined by the order they occur in the arrays. The comparator is invoked
  8638. * with two arguments: (arrVal, othVal).
  8639. *
  8640. * @static
  8641. * @memberOf _
  8642. * @since 4.0.0
  8643. * @category Array
  8644. * @param {...Array} [arrays] The arrays to inspect.
  8645. * @param {Function} [comparator] The comparator invoked per element.
  8646. * @returns {Array} Returns the new array of filtered values.
  8647. * @example
  8648. *
  8649. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8650. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8651. *
  8652. * _.xorWith(objects, others, _.isEqual);
  8653. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8654. */
  8655. var xorWith = baseRest(function(arrays) {
  8656. var comparator = last(arrays);
  8657. comparator = typeof comparator === 'function' ? comparator : undefined;
  8658. return baseXor(
  8659. arrayFilter(arrays, isArrayLikeObject),
  8660. undefined,
  8661. comparator
  8662. );
  8663. });
  8664. /**
  8665. * Creates an array of grouped elements, the first of which contains the
  8666. * first elements of the given arrays, the second of which contains the
  8667. * second elements of the given arrays, and so on.
  8668. *
  8669. * @static
  8670. * @memberOf _
  8671. * @since 0.1.0
  8672. * @category Array
  8673. * @param {...Array} [arrays] The arrays to process.
  8674. * @returns {Array} Returns the new array of grouped elements.
  8675. * @example
  8676. *
  8677. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8678. * // => [['a', 1, true], ['b', 2, false]]
  8679. */
  8680. var zip = baseRest(unzip);
  8681. /**
  8682. * This method is like `_.fromPairs` except that it accepts two arrays,
  8683. * one of property identifiers and one of corresponding values.
  8684. *
  8685. * @static
  8686. * @memberOf _
  8687. * @since 0.4.0
  8688. * @category Array
  8689. * @param {Array} [props=[]] The property identifiers.
  8690. * @param {Array} [values=[]] The property values.
  8691. * @returns {Object} Returns the new object.
  8692. * @example
  8693. *
  8694. * _.zipObject(['a', 'b'], [1, 2]);
  8695. * // => { 'a': 1, 'b': 2 }
  8696. */
  8697. function zipObject(props, values) {
  8698. return baseZipObject(props || [], values || [], assignValue);
  8699. }
  8700. /**
  8701. * This method is like `_.zipObject` except that it supports property paths.
  8702. *
  8703. * @static
  8704. * @memberOf _
  8705. * @since 4.1.0
  8706. * @category Array
  8707. * @param {Array} [props=[]] The property identifiers.
  8708. * @param {Array} [values=[]] The property values.
  8709. * @returns {Object} Returns the new object.
  8710. * @example
  8711. *
  8712. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8713. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8714. */
  8715. function zipObjectDeep(props, values) {
  8716. return baseZipObject(props || [], values || [], baseSet);
  8717. }
  8718. /**
  8719. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8720. * how grouped values should be combined. The iteratee is invoked with the
  8721. * elements of each group: (...group).
  8722. *
  8723. * @static
  8724. * @memberOf _
  8725. * @since 3.8.0
  8726. * @category Array
  8727. * @param {...Array} [arrays] The arrays to process.
  8728. * @param {Function} [iteratee=_.identity] The function to combine
  8729. * grouped values.
  8730. * @returns {Array} Returns the new array of grouped elements.
  8731. * @example
  8732. *
  8733. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8734. * return a + b + c;
  8735. * });
  8736. * // => [111, 222]
  8737. */
  8738. var zipWith = baseRest(function(arrays) {
  8739. var length = arrays.length,
  8740. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8741. iteratee =
  8742. typeof iteratee === 'function' ? (arrays.pop(), iteratee) : undefined;
  8743. return unzipWith(arrays, iteratee);
  8744. });
  8745. /* ------------------------------------------------------------------------*/
  8746. /**
  8747. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8748. * chain sequences enabled. The result of such sequences must be unwrapped
  8749. * with `_#value`.
  8750. *
  8751. * @static
  8752. * @memberOf _
  8753. * @since 1.3.0
  8754. * @category Seq
  8755. * @param {*} value The value to wrap.
  8756. * @returns {Object} Returns the new `lodash` wrapper instance.
  8757. * @example
  8758. *
  8759. * var users = [
  8760. * { 'user': 'barney', 'age': 36 },
  8761. * { 'user': 'fred', 'age': 40 },
  8762. * { 'user': 'pebbles', 'age': 1 }
  8763. * ];
  8764. *
  8765. * var youngest = _
  8766. * .chain(users)
  8767. * .sortBy('age')
  8768. * .map(function(o) {
  8769. * return o.user + ' is ' + o.age;
  8770. * })
  8771. * .head()
  8772. * .value();
  8773. * // => 'pebbles is 1'
  8774. */
  8775. function chain(value) {
  8776. var result = lodash(value);
  8777. result.__chain__ = true;
  8778. return result;
  8779. }
  8780. /**
  8781. * This method invokes `interceptor` and returns `value`. The interceptor
  8782. * is invoked with one argument; (value). The purpose of this method is to
  8783. * "tap into" a method chain sequence in order to modify intermediate results.
  8784. *
  8785. * @static
  8786. * @memberOf _
  8787. * @since 0.1.0
  8788. * @category Seq
  8789. * @param {*} value The value to provide to `interceptor`.
  8790. * @param {Function} interceptor The function to invoke.
  8791. * @returns {*} Returns `value`.
  8792. * @example
  8793. *
  8794. * _([1, 2, 3])
  8795. * .tap(function(array) {
  8796. * // Mutate input array.
  8797. * array.pop();
  8798. * })
  8799. * .reverse()
  8800. * .value();
  8801. * // => [2, 1]
  8802. */
  8803. function tap(value, interceptor) {
  8804. interceptor(value);
  8805. return value;
  8806. }
  8807. /**
  8808. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8809. * The purpose of this method is to "pass thru" values replacing intermediate
  8810. * results in a method chain sequence.
  8811. *
  8812. * @static
  8813. * @memberOf _
  8814. * @since 3.0.0
  8815. * @category Seq
  8816. * @param {*} value The value to provide to `interceptor`.
  8817. * @param {Function} interceptor The function to invoke.
  8818. * @returns {*} Returns the result of `interceptor`.
  8819. * @example
  8820. *
  8821. * _(' abc ')
  8822. * .chain()
  8823. * .trim()
  8824. * .thru(function(value) {
  8825. * return [value];
  8826. * })
  8827. * .value();
  8828. * // => ['abc']
  8829. */
  8830. function thru(value, interceptor) {
  8831. return interceptor(value);
  8832. }
  8833. /**
  8834. * This method is the wrapper version of `_.at`.
  8835. *
  8836. * @name at
  8837. * @memberOf _
  8838. * @since 1.0.0
  8839. * @category Seq
  8840. * @param {...(string|string[])} [paths] The property paths to pick.
  8841. * @returns {Object} Returns the new `lodash` wrapper instance.
  8842. * @example
  8843. *
  8844. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8845. *
  8846. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8847. * // => [3, 4]
  8848. */
  8849. var wrapperAt = flatRest(function(paths) {
  8850. var length = paths.length,
  8851. start = length ? paths[0] : 0,
  8852. value = this.__wrapped__,
  8853. interceptor = function(object) {
  8854. return baseAt(object, paths);
  8855. };
  8856. if (
  8857. length > 1 ||
  8858. this.__actions__.length ||
  8859. !(value instanceof LazyWrapper) ||
  8860. !isIndex(start)
  8861. ) {
  8862. return this.thru(interceptor);
  8863. }
  8864. value = value.slice(start, +start + (length ? 1 : 0));
  8865. value.__actions__.push({
  8866. func: thru,
  8867. args: [interceptor],
  8868. thisArg: undefined
  8869. });
  8870. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8871. if (length && !array.length) {
  8872. array.push(undefined);
  8873. }
  8874. return array;
  8875. });
  8876. });
  8877. /**
  8878. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8879. *
  8880. * @name chain
  8881. * @memberOf _
  8882. * @since 0.1.0
  8883. * @category Seq
  8884. * @returns {Object} Returns the new `lodash` wrapper instance.
  8885. * @example
  8886. *
  8887. * var users = [
  8888. * { 'user': 'barney', 'age': 36 },
  8889. * { 'user': 'fred', 'age': 40 }
  8890. * ];
  8891. *
  8892. * // A sequence without explicit chaining.
  8893. * _(users).head();
  8894. * // => { 'user': 'barney', 'age': 36 }
  8895. *
  8896. * // A sequence with explicit chaining.
  8897. * _(users)
  8898. * .chain()
  8899. * .head()
  8900. * .pick('user')
  8901. * .value();
  8902. * // => { 'user': 'barney' }
  8903. */
  8904. function wrapperChain() {
  8905. return chain(this);
  8906. }
  8907. /**
  8908. * Executes the chain sequence and returns the wrapped result.
  8909. *
  8910. * @name commit
  8911. * @memberOf _
  8912. * @since 3.2.0
  8913. * @category Seq
  8914. * @returns {Object} Returns the new `lodash` wrapper instance.
  8915. * @example
  8916. *
  8917. * var array = [1, 2];
  8918. * var wrapped = _(array).push(3);
  8919. *
  8920. * console.log(array);
  8921. * // => [1, 2]
  8922. *
  8923. * wrapped = wrapped.commit();
  8924. * console.log(array);
  8925. * // => [1, 2, 3]
  8926. *
  8927. * wrapped.last();
  8928. * // => 3
  8929. *
  8930. * console.log(array);
  8931. * // => [1, 2, 3]
  8932. */
  8933. function wrapperCommit() {
  8934. return new LodashWrapper(this.value(), this.__chain__);
  8935. }
  8936. /**
  8937. * Gets the next value on a wrapped object following the
  8938. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8939. *
  8940. * @name next
  8941. * @memberOf _
  8942. * @since 4.0.0
  8943. * @category Seq
  8944. * @returns {Object} Returns the next iterator value.
  8945. * @example
  8946. *
  8947. * var wrapped = _([1, 2]);
  8948. *
  8949. * wrapped.next();
  8950. * // => { 'done': false, 'value': 1 }
  8951. *
  8952. * wrapped.next();
  8953. * // => { 'done': false, 'value': 2 }
  8954. *
  8955. * wrapped.next();
  8956. * // => { 'done': true, 'value': undefined }
  8957. */
  8958. function wrapperNext() {
  8959. if (this.__values__ === undefined) {
  8960. this.__values__ = toArray(this.value());
  8961. }
  8962. var done = this.__index__ >= this.__values__.length,
  8963. value = done ? undefined : this.__values__[this.__index__++];
  8964. return { done: done, value: value };
  8965. }
  8966. /**
  8967. * Enables the wrapper to be iterable.
  8968. *
  8969. * @name Symbol.iterator
  8970. * @memberOf _
  8971. * @since 4.0.0
  8972. * @category Seq
  8973. * @returns {Object} Returns the wrapper object.
  8974. * @example
  8975. *
  8976. * var wrapped = _([1, 2]);
  8977. *
  8978. * wrapped[Symbol.iterator]() === wrapped;
  8979. * // => true
  8980. *
  8981. * Array.from(wrapped);
  8982. * // => [1, 2]
  8983. */
  8984. function wrapperToIterator() {
  8985. return this;
  8986. }
  8987. /**
  8988. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8989. *
  8990. * @name plant
  8991. * @memberOf _
  8992. * @since 3.2.0
  8993. * @category Seq
  8994. * @param {*} value The value to plant.
  8995. * @returns {Object} Returns the new `lodash` wrapper instance.
  8996. * @example
  8997. *
  8998. * function square(n) {
  8999. * return n * n;
  9000. * }
  9001. *
  9002. * var wrapped = _([1, 2]).map(square);
  9003. * var other = wrapped.plant([3, 4]);
  9004. *
  9005. * other.value();
  9006. * // => [9, 16]
  9007. *
  9008. * wrapped.value();
  9009. * // => [1, 4]
  9010. */
  9011. function wrapperPlant(value) {
  9012. var result,
  9013. parent = this;
  9014. while (parent instanceof baseLodash) {
  9015. var clone = wrapperClone(parent);
  9016. clone.__index__ = 0;
  9017. clone.__values__ = undefined;
  9018. if (result) {
  9019. previous.__wrapped__ = clone;
  9020. } else {
  9021. result = clone;
  9022. }
  9023. var previous = clone;
  9024. parent = parent.__wrapped__;
  9025. }
  9026. previous.__wrapped__ = value;
  9027. return result;
  9028. }
  9029. /**
  9030. * This method is the wrapper version of `_.reverse`.
  9031. *
  9032. * **Note:** This method mutates the wrapped array.
  9033. *
  9034. * @name reverse
  9035. * @memberOf _
  9036. * @since 0.1.0
  9037. * @category Seq
  9038. * @returns {Object} Returns the new `lodash` wrapper instance.
  9039. * @example
  9040. *
  9041. * var array = [1, 2, 3];
  9042. *
  9043. * _(array).reverse().value()
  9044. * // => [3, 2, 1]
  9045. *
  9046. * console.log(array);
  9047. * // => [3, 2, 1]
  9048. */
  9049. function wrapperReverse() {
  9050. var value = this.__wrapped__;
  9051. if (value instanceof LazyWrapper) {
  9052. var wrapped = value;
  9053. if (this.__actions__.length) {
  9054. wrapped = new LazyWrapper(this);
  9055. }
  9056. wrapped = wrapped.reverse();
  9057. wrapped.__actions__.push({
  9058. func: thru,
  9059. args: [reverse],
  9060. thisArg: undefined
  9061. });
  9062. return new LodashWrapper(wrapped, this.__chain__);
  9063. }
  9064. return this.thru(reverse);
  9065. }
  9066. /**
  9067. * Executes the chain sequence to resolve the unwrapped value.
  9068. *
  9069. * @name value
  9070. * @memberOf _
  9071. * @since 0.1.0
  9072. * @alias toJSON, valueOf
  9073. * @category Seq
  9074. * @returns {*} Returns the resolved unwrapped value.
  9075. * @example
  9076. *
  9077. * _([1, 2, 3]).value();
  9078. * // => [1, 2, 3]
  9079. */
  9080. function wrapperValue() {
  9081. return baseWrapperValue(this.__wrapped__, this.__actions__);
  9082. }
  9083. /* ------------------------------------------------------------------------*/
  9084. /**
  9085. * Creates an object composed of keys generated from the results of running
  9086. * each element of `collection` thru `iteratee`. The corresponding value of
  9087. * each key is the number of times the key was returned by `iteratee`. The
  9088. * iteratee is invoked with one argument: (value).
  9089. *
  9090. * @static
  9091. * @memberOf _
  9092. * @since 0.5.0
  9093. * @category Collection
  9094. * @param {Array|Object} collection The collection to iterate over.
  9095. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  9096. * @returns {Object} Returns the composed aggregate object.
  9097. * @example
  9098. *
  9099. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  9100. * // => { '4': 1, '6': 2 }
  9101. *
  9102. * // The `_.property` iteratee shorthand.
  9103. * _.countBy(['one', 'two', 'three'], 'length');
  9104. * // => { '3': 2, '5': 1 }
  9105. */
  9106. var countBy = createAggregator(function(result, value, key) {
  9107. if (hasOwnProperty.call(result, key)) {
  9108. ++result[key];
  9109. } else {
  9110. baseAssignValue(result, key, 1);
  9111. }
  9112. });
  9113. /**
  9114. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  9115. * Iteration is stopped once `predicate` returns falsey. The predicate is
  9116. * invoked with three arguments: (value, index|key, collection).
  9117. *
  9118. * **Note:** This method returns `true` for
  9119. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  9120. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  9121. * elements of empty collections.
  9122. *
  9123. * @static
  9124. * @memberOf _
  9125. * @since 0.1.0
  9126. * @category Collection
  9127. * @param {Array|Object} collection The collection to iterate over.
  9128. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9129. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9130. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  9131. * else `false`.
  9132. * @example
  9133. *
  9134. * _.every([true, 1, null, 'yes'], Boolean);
  9135. * // => false
  9136. *
  9137. * var users = [
  9138. * { 'user': 'barney', 'age': 36, 'active': false },
  9139. * { 'user': 'fred', 'age': 40, 'active': false }
  9140. * ];
  9141. *
  9142. * // The `_.matches` iteratee shorthand.
  9143. * _.every(users, { 'user': 'barney', 'active': false });
  9144. * // => false
  9145. *
  9146. * // The `_.matchesProperty` iteratee shorthand.
  9147. * _.every(users, ['active', false]);
  9148. * // => true
  9149. *
  9150. * // The `_.property` iteratee shorthand.
  9151. * _.every(users, 'active');
  9152. * // => false
  9153. */
  9154. function every(collection, predicate, guard) {
  9155. var func = isArray(collection) ? arrayEvery : baseEvery;
  9156. if (guard && isIterateeCall(collection, predicate, guard)) {
  9157. predicate = undefined;
  9158. }
  9159. return func(collection, getIteratee(predicate, 3));
  9160. }
  9161. /**
  9162. * Iterates over elements of `collection`, returning an array of all elements
  9163. * `predicate` returns truthy for. The predicate is invoked with three
  9164. * arguments: (value, index|key, collection).
  9165. *
  9166. * **Note:** Unlike `_.remove`, this method returns a new array.
  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. * @returns {Array} Returns the new filtered array.
  9175. * @see _.reject
  9176. * @example
  9177. *
  9178. * var users = [
  9179. * { 'user': 'barney', 'age': 36, 'active': true },
  9180. * { 'user': 'fred', 'age': 40, 'active': false }
  9181. * ];
  9182. *
  9183. * _.filter(users, function(o) { return !o.active; });
  9184. * // => objects for ['fred']
  9185. *
  9186. * // The `_.matches` iteratee shorthand.
  9187. * _.filter(users, { 'age': 36, 'active': true });
  9188. * // => objects for ['barney']
  9189. *
  9190. * // The `_.matchesProperty` iteratee shorthand.
  9191. * _.filter(users, ['active', false]);
  9192. * // => objects for ['fred']
  9193. *
  9194. * // The `_.property` iteratee shorthand.
  9195. * _.filter(users, 'active');
  9196. * // => objects for ['barney']
  9197. */
  9198. function filter(collection, predicate) {
  9199. var func = isArray(collection) ? arrayFilter : baseFilter;
  9200. return func(collection, getIteratee(predicate, 3));
  9201. }
  9202. /**
  9203. * Iterates over elements of `collection`, returning the first element
  9204. * `predicate` returns truthy for. The predicate is invoked with three
  9205. * arguments: (value, index|key, collection).
  9206. *
  9207. * @static
  9208. * @memberOf _
  9209. * @since 0.1.0
  9210. * @category Collection
  9211. * @param {Array|Object} collection The collection to inspect.
  9212. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9213. * @param {number} [fromIndex=0] The index to search from.
  9214. * @returns {*} Returns the matched element, else `undefined`.
  9215. * @example
  9216. *
  9217. * var users = [
  9218. * { 'user': 'barney', 'age': 36, 'active': true },
  9219. * { 'user': 'fred', 'age': 40, 'active': false },
  9220. * { 'user': 'pebbles', 'age': 1, 'active': true }
  9221. * ];
  9222. *
  9223. * _.find(users, function(o) { return o.age < 40; });
  9224. * // => object for 'barney'
  9225. *
  9226. * // The `_.matches` iteratee shorthand.
  9227. * _.find(users, { 'age': 1, 'active': true });
  9228. * // => object for 'pebbles'
  9229. *
  9230. * // The `_.matchesProperty` iteratee shorthand.
  9231. * _.find(users, ['active', false]);
  9232. * // => object for 'fred'
  9233. *
  9234. * // The `_.property` iteratee shorthand.
  9235. * _.find(users, 'active');
  9236. * // => object for 'barney'
  9237. */
  9238. var find = createFind(findIndex);
  9239. /**
  9240. * This method is like `_.find` except that it iterates over elements of
  9241. * `collection` from right to left.
  9242. *
  9243. * @static
  9244. * @memberOf _
  9245. * @since 2.0.0
  9246. * @category Collection
  9247. * @param {Array|Object} collection The collection to inspect.
  9248. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9249. * @param {number} [fromIndex=collection.length-1] The index to search from.
  9250. * @returns {*} Returns the matched element, else `undefined`.
  9251. * @example
  9252. *
  9253. * _.findLast([1, 2, 3, 4], function(n) {
  9254. * return n % 2 == 1;
  9255. * });
  9256. * // => 3
  9257. */
  9258. var findLast = createFind(findLastIndex);
  9259. /**
  9260. * Creates a flattened array of values by running each element in `collection`
  9261. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  9262. * with three arguments: (value, index|key, collection).
  9263. *
  9264. * @static
  9265. * @memberOf _
  9266. * @since 4.0.0
  9267. * @category Collection
  9268. * @param {Array|Object} collection The collection to iterate over.
  9269. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9270. * @returns {Array} Returns the new flattened array.
  9271. * @example
  9272. *
  9273. * function duplicate(n) {
  9274. * return [n, n];
  9275. * }
  9276. *
  9277. * _.flatMap([1, 2], duplicate);
  9278. * // => [1, 1, 2, 2]
  9279. */
  9280. function flatMap(collection, iteratee) {
  9281. return baseFlatten(map(collection, iteratee), 1);
  9282. }
  9283. /**
  9284. * This method is like `_.flatMap` except that it recursively flattens the
  9285. * mapped results.
  9286. *
  9287. * @static
  9288. * @memberOf _
  9289. * @since 4.7.0
  9290. * @category Collection
  9291. * @param {Array|Object} collection The collection to iterate over.
  9292. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9293. * @returns {Array} Returns the new flattened array.
  9294. * @example
  9295. *
  9296. * function duplicate(n) {
  9297. * return [[[n, n]]];
  9298. * }
  9299. *
  9300. * _.flatMapDeep([1, 2], duplicate);
  9301. * // => [1, 1, 2, 2]
  9302. */
  9303. function flatMapDeep(collection, iteratee) {
  9304. return baseFlatten(map(collection, iteratee), INFINITY);
  9305. }
  9306. /**
  9307. * This method is like `_.flatMap` except that it recursively flattens the
  9308. * mapped results up to `depth` times.
  9309. *
  9310. * @static
  9311. * @memberOf _
  9312. * @since 4.7.0
  9313. * @category Collection
  9314. * @param {Array|Object} collection The collection to iterate over.
  9315. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9316. * @param {number} [depth=1] The maximum recursion depth.
  9317. * @returns {Array} Returns the new flattened array.
  9318. * @example
  9319. *
  9320. * function duplicate(n) {
  9321. * return [[[n, n]]];
  9322. * }
  9323. *
  9324. * _.flatMapDepth([1, 2], duplicate, 2);
  9325. * // => [[1, 1], [2, 2]]
  9326. */
  9327. function flatMapDepth(collection, iteratee, depth) {
  9328. depth = depth === undefined ? 1 : toInteger(depth);
  9329. return baseFlatten(map(collection, iteratee), depth);
  9330. }
  9331. /**
  9332. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  9333. * The iteratee is invoked with three arguments: (value, index|key, collection).
  9334. * Iteratee functions may exit iteration early by explicitly returning `false`.
  9335. *
  9336. * **Note:** As with other "Collections" methods, objects with a "length"
  9337. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  9338. * or `_.forOwn` for object iteration.
  9339. *
  9340. * @static
  9341. * @memberOf _
  9342. * @since 0.1.0
  9343. * @alias each
  9344. * @category Collection
  9345. * @param {Array|Object} collection The collection to iterate over.
  9346. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9347. * @returns {Array|Object} Returns `collection`.
  9348. * @see _.forEachRight
  9349. * @example
  9350. *
  9351. * _.forEach([1, 2], function(value) {
  9352. * console.log(value);
  9353. * });
  9354. * // => Logs `1` then `2`.
  9355. *
  9356. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  9357. * console.log(key);
  9358. * });
  9359. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  9360. */
  9361. function forEach(collection, iteratee) {
  9362. var func = isArray(collection) ? arrayEach : baseEach;
  9363. return func(collection, getIteratee(iteratee, 3));
  9364. }
  9365. /**
  9366. * This method is like `_.forEach` except that it iterates over elements of
  9367. * `collection` from right to left.
  9368. *
  9369. * @static
  9370. * @memberOf _
  9371. * @since 2.0.0
  9372. * @alias eachRight
  9373. * @category Collection
  9374. * @param {Array|Object} collection The collection to iterate over.
  9375. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9376. * @returns {Array|Object} Returns `collection`.
  9377. * @see _.forEach
  9378. * @example
  9379. *
  9380. * _.forEachRight([1, 2], function(value) {
  9381. * console.log(value);
  9382. * });
  9383. * // => Logs `2` then `1`.
  9384. */
  9385. function forEachRight(collection, iteratee) {
  9386. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  9387. return func(collection, getIteratee(iteratee, 3));
  9388. }
  9389. /**
  9390. * Creates an object composed of keys generated from the results of running
  9391. * each element of `collection` thru `iteratee`. The order of grouped values
  9392. * is determined by the order they occur in `collection`. The corresponding
  9393. * value of each key is an array of elements responsible for generating the
  9394. * key. The iteratee is invoked with one argument: (value).
  9395. *
  9396. * @static
  9397. * @memberOf _
  9398. * @since 0.1.0
  9399. * @category Collection
  9400. * @param {Array|Object} collection The collection to iterate over.
  9401. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  9402. * @returns {Object} Returns the composed aggregate object.
  9403. * @example
  9404. *
  9405. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  9406. * // => { '4': [4.2], '6': [6.1, 6.3] }
  9407. *
  9408. * // The `_.property` iteratee shorthand.
  9409. * _.groupBy(['one', 'two', 'three'], 'length');
  9410. * // => { '3': ['one', 'two'], '5': ['three'] }
  9411. */
  9412. var groupBy = createAggregator(function(result, value, key) {
  9413. if (hasOwnProperty.call(result, key)) {
  9414. result[key].push(value);
  9415. } else {
  9416. baseAssignValue(result, key, [value]);
  9417. }
  9418. });
  9419. /**
  9420. * Checks if `value` is in `collection`. If `collection` is a string, it's
  9421. * checked for a substring of `value`, otherwise
  9422. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9423. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  9424. * the offset from the end of `collection`.
  9425. *
  9426. * @static
  9427. * @memberOf _
  9428. * @since 0.1.0
  9429. * @category Collection
  9430. * @param {Array|Object|string} collection The collection to inspect.
  9431. * @param {*} value The value to search for.
  9432. * @param {number} [fromIndex=0] The index to search from.
  9433. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  9434. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  9435. * @example
  9436. *
  9437. * _.includes([1, 2, 3], 1);
  9438. * // => true
  9439. *
  9440. * _.includes([1, 2, 3], 1, 2);
  9441. * // => false
  9442. *
  9443. * _.includes({ 'a': 1, 'b': 2 }, 1);
  9444. * // => true
  9445. *
  9446. * _.includes('abcd', 'bc');
  9447. * // => true
  9448. */
  9449. function includes(collection, value, fromIndex, guard) {
  9450. collection = isArrayLike(collection) ? collection : values(collection);
  9451. fromIndex = fromIndex && !guard ? toInteger(fromIndex) : 0;
  9452. var length = collection.length;
  9453. if (fromIndex < 0) {
  9454. fromIndex = nativeMax(length + fromIndex, 0);
  9455. }
  9456. return isString(collection)
  9457. ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1
  9458. : !!length && baseIndexOf(collection, value, fromIndex) > -1;
  9459. }
  9460. /**
  9461. * Invokes the method at `path` of each element in `collection`, returning
  9462. * an array of the results of each invoked method. Any additional arguments
  9463. * are provided to each invoked method. If `path` is a function, it's invoked
  9464. * for, and `this` bound to, each element in `collection`.
  9465. *
  9466. * @static
  9467. * @memberOf _
  9468. * @since 4.0.0
  9469. * @category Collection
  9470. * @param {Array|Object} collection The collection to iterate over.
  9471. * @param {Array|Function|string} path The path of the method to invoke or
  9472. * the function invoked per iteration.
  9473. * @param {...*} [args] The arguments to invoke each method with.
  9474. * @returns {Array} Returns the array of results.
  9475. * @example
  9476. *
  9477. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  9478. * // => [[1, 5, 7], [1, 2, 3]]
  9479. *
  9480. * _.invokeMap([123, 456], String.prototype.split, '');
  9481. * // => [['1', '2', '3'], ['4', '5', '6']]
  9482. */
  9483. var invokeMap = baseRest(function(collection, path, args) {
  9484. var index = -1,
  9485. isFunc = typeof path === 'function',
  9486. result = isArrayLike(collection) ? Array(collection.length) : [];
  9487. baseEach(collection, function(value) {
  9488. result[++index] = isFunc
  9489. ? apply(path, value, args)
  9490. : baseInvoke(value, path, args);
  9491. });
  9492. return result;
  9493. });
  9494. /**
  9495. * Creates an object composed of keys generated from the results of running
  9496. * each element of `collection` thru `iteratee`. The corresponding value of
  9497. * each key is the last element responsible for generating the key. The
  9498. * iteratee is invoked with one argument: (value).
  9499. *
  9500. * @static
  9501. * @memberOf _
  9502. * @since 4.0.0
  9503. * @category Collection
  9504. * @param {Array|Object} collection The collection to iterate over.
  9505. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  9506. * @returns {Object} Returns the composed aggregate object.
  9507. * @example
  9508. *
  9509. * var array = [
  9510. * { 'dir': 'left', 'code': 97 },
  9511. * { 'dir': 'right', 'code': 100 }
  9512. * ];
  9513. *
  9514. * _.keyBy(array, function(o) {
  9515. * return String.fromCharCode(o.code);
  9516. * });
  9517. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  9518. *
  9519. * _.keyBy(array, 'dir');
  9520. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  9521. */
  9522. var keyBy = createAggregator(function(result, value, key) {
  9523. baseAssignValue(result, key, value);
  9524. });
  9525. /**
  9526. * Creates an array of values by running each element in `collection` thru
  9527. * `iteratee`. The iteratee is invoked with three arguments:
  9528. * (value, index|key, collection).
  9529. *
  9530. * Many lodash methods are guarded to work as iteratees for methods like
  9531. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  9532. *
  9533. * The guarded methods are:
  9534. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  9535. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  9536. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  9537. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  9538. *
  9539. * @static
  9540. * @memberOf _
  9541. * @since 0.1.0
  9542. * @category Collection
  9543. * @param {Array|Object} collection The collection to iterate over.
  9544. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9545. * @returns {Array} Returns the new mapped array.
  9546. * @example
  9547. *
  9548. * function square(n) {
  9549. * return n * n;
  9550. * }
  9551. *
  9552. * _.map([4, 8], square);
  9553. * // => [16, 64]
  9554. *
  9555. * _.map({ 'a': 4, 'b': 8 }, square);
  9556. * // => [16, 64] (iteration order is not guaranteed)
  9557. *
  9558. * var users = [
  9559. * { 'user': 'barney' },
  9560. * { 'user': 'fred' }
  9561. * ];
  9562. *
  9563. * // The `_.property` iteratee shorthand.
  9564. * _.map(users, 'user');
  9565. * // => ['barney', 'fred']
  9566. */
  9567. function map(collection, iteratee) {
  9568. var func = isArray(collection) ? arrayMap : baseMap;
  9569. return func(collection, getIteratee(iteratee, 3));
  9570. }
  9571. /**
  9572. * This method is like `_.sortBy` except that it allows specifying the sort
  9573. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  9574. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  9575. * descending or "asc" for ascending sort order of corresponding values.
  9576. *
  9577. * @static
  9578. * @memberOf _
  9579. * @since 4.0.0
  9580. * @category Collection
  9581. * @param {Array|Object} collection The collection to iterate over.
  9582. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  9583. * The iteratees to sort by.
  9584. * @param {string[]} [orders] The sort orders of `iteratees`.
  9585. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  9586. * @returns {Array} Returns the new sorted array.
  9587. * @example
  9588. *
  9589. * var users = [
  9590. * { 'user': 'fred', 'age': 48 },
  9591. * { 'user': 'barney', 'age': 34 },
  9592. * { 'user': 'fred', 'age': 40 },
  9593. * { 'user': 'barney', 'age': 36 }
  9594. * ];
  9595. *
  9596. * // Sort by `user` in ascending order and by `age` in descending order.
  9597. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  9598. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9599. */
  9600. function orderBy(collection, iteratees, orders, guard) {
  9601. if (collection == null) {
  9602. return [];
  9603. }
  9604. if (!isArray(iteratees)) {
  9605. iteratees = iteratees == null ? [] : [iteratees];
  9606. }
  9607. orders = guard ? undefined : orders;
  9608. if (!isArray(orders)) {
  9609. orders = orders == null ? [] : [orders];
  9610. }
  9611. return baseOrderBy(collection, iteratees, orders);
  9612. }
  9613. /**
  9614. * Creates an array of elements split into two groups, the first of which
  9615. * contains elements `predicate` returns truthy for, the second of which
  9616. * contains elements `predicate` returns falsey for. The predicate is
  9617. * invoked with one argument: (value).
  9618. *
  9619. * @static
  9620. * @memberOf _
  9621. * @since 3.0.0
  9622. * @category Collection
  9623. * @param {Array|Object} collection The collection to iterate over.
  9624. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9625. * @returns {Array} Returns the array of grouped elements.
  9626. * @example
  9627. *
  9628. * var users = [
  9629. * { 'user': 'barney', 'age': 36, 'active': false },
  9630. * { 'user': 'fred', 'age': 40, 'active': true },
  9631. * { 'user': 'pebbles', 'age': 1, 'active': false }
  9632. * ];
  9633. *
  9634. * _.partition(users, function(o) { return o.active; });
  9635. * // => objects for [['fred'], ['barney', 'pebbles']]
  9636. *
  9637. * // The `_.matches` iteratee shorthand.
  9638. * _.partition(users, { 'age': 1, 'active': false });
  9639. * // => objects for [['pebbles'], ['barney', 'fred']]
  9640. *
  9641. * // The `_.matchesProperty` iteratee shorthand.
  9642. * _.partition(users, ['active', false]);
  9643. * // => objects for [['barney', 'pebbles'], ['fred']]
  9644. *
  9645. * // The `_.property` iteratee shorthand.
  9646. * _.partition(users, 'active');
  9647. * // => objects for [['fred'], ['barney', 'pebbles']]
  9648. */
  9649. var partition = createAggregator(
  9650. function(result, value, key) {
  9651. result[key ? 0 : 1].push(value);
  9652. },
  9653. function() {
  9654. return [[], []];
  9655. }
  9656. );
  9657. /**
  9658. * Reduces `collection` to a value which is the accumulated result of running
  9659. * each element in `collection` thru `iteratee`, where each successive
  9660. * invocation is supplied the return value of the previous. If `accumulator`
  9661. * is not given, the first element of `collection` is used as the initial
  9662. * value. The iteratee is invoked with four arguments:
  9663. * (accumulator, value, index|key, collection).
  9664. *
  9665. * Many lodash methods are guarded to work as iteratees for methods like
  9666. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9667. *
  9668. * The guarded methods are:
  9669. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9670. * and `sortBy`
  9671. *
  9672. * @static
  9673. * @memberOf _
  9674. * @since 0.1.0
  9675. * @category Collection
  9676. * @param {Array|Object} collection The collection to iterate over.
  9677. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9678. * @param {*} [accumulator] The initial value.
  9679. * @returns {*} Returns the accumulated value.
  9680. * @see _.reduceRight
  9681. * @example
  9682. *
  9683. * _.reduce([1, 2], function(sum, n) {
  9684. * return sum + n;
  9685. * }, 0);
  9686. * // => 3
  9687. *
  9688. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9689. * (result[value] || (result[value] = [])).push(key);
  9690. * return result;
  9691. * }, {});
  9692. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9693. */
  9694. function reduce(collection, iteratee, accumulator) {
  9695. var func = isArray(collection) ? arrayReduce : baseReduce,
  9696. initAccum = arguments.length < 3;
  9697. return func(
  9698. collection,
  9699. getIteratee(iteratee, 4),
  9700. accumulator,
  9701. initAccum,
  9702. baseEach
  9703. );
  9704. }
  9705. /**
  9706. * This method is like `_.reduce` except that it iterates over elements of
  9707. * `collection` from right to left.
  9708. *
  9709. * @static
  9710. * @memberOf _
  9711. * @since 0.1.0
  9712. * @category Collection
  9713. * @param {Array|Object} collection The collection to iterate over.
  9714. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9715. * @param {*} [accumulator] The initial value.
  9716. * @returns {*} Returns the accumulated value.
  9717. * @see _.reduce
  9718. * @example
  9719. *
  9720. * var array = [[0, 1], [2, 3], [4, 5]];
  9721. *
  9722. * _.reduceRight(array, function(flattened, other) {
  9723. * return flattened.concat(other);
  9724. * }, []);
  9725. * // => [4, 5, 2, 3, 0, 1]
  9726. */
  9727. function reduceRight(collection, iteratee, accumulator) {
  9728. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9729. initAccum = arguments.length < 3;
  9730. return func(
  9731. collection,
  9732. getIteratee(iteratee, 4),
  9733. accumulator,
  9734. initAccum,
  9735. baseEachRight
  9736. );
  9737. }
  9738. /**
  9739. * The opposite of `_.filter`; this method returns the elements of `collection`
  9740. * that `predicate` does **not** return truthy for.
  9741. *
  9742. * @static
  9743. * @memberOf _
  9744. * @since 0.1.0
  9745. * @category Collection
  9746. * @param {Array|Object} collection The collection to iterate over.
  9747. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9748. * @returns {Array} Returns the new filtered array.
  9749. * @see _.filter
  9750. * @example
  9751. *
  9752. * var users = [
  9753. * { 'user': 'barney', 'age': 36, 'active': false },
  9754. * { 'user': 'fred', 'age': 40, 'active': true }
  9755. * ];
  9756. *
  9757. * _.reject(users, function(o) { return !o.active; });
  9758. * // => objects for ['fred']
  9759. *
  9760. * // The `_.matches` iteratee shorthand.
  9761. * _.reject(users, { 'age': 40, 'active': true });
  9762. * // => objects for ['barney']
  9763. *
  9764. * // The `_.matchesProperty` iteratee shorthand.
  9765. * _.reject(users, ['active', false]);
  9766. * // => objects for ['fred']
  9767. *
  9768. * // The `_.property` iteratee shorthand.
  9769. * _.reject(users, 'active');
  9770. * // => objects for ['barney']
  9771. */
  9772. function reject(collection, predicate) {
  9773. var func = isArray(collection) ? arrayFilter : baseFilter;
  9774. return func(collection, negate(getIteratee(predicate, 3)));
  9775. }
  9776. /**
  9777. * Gets a random element from `collection`.
  9778. *
  9779. * @static
  9780. * @memberOf _
  9781. * @since 2.0.0
  9782. * @category Collection
  9783. * @param {Array|Object} collection The collection to sample.
  9784. * @returns {*} Returns the random element.
  9785. * @example
  9786. *
  9787. * _.sample([1, 2, 3, 4]);
  9788. * // => 2
  9789. */
  9790. function sample(collection) {
  9791. var func = isArray(collection) ? arraySample : baseSample;
  9792. return func(collection);
  9793. }
  9794. /**
  9795. * Gets `n` random elements at unique keys from `collection` up to the
  9796. * size of `collection`.
  9797. *
  9798. * @static
  9799. * @memberOf _
  9800. * @since 4.0.0
  9801. * @category Collection
  9802. * @param {Array|Object} collection The collection to sample.
  9803. * @param {number} [n=1] The number of elements to sample.
  9804. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9805. * @returns {Array} Returns the random elements.
  9806. * @example
  9807. *
  9808. * _.sampleSize([1, 2, 3], 2);
  9809. * // => [3, 1]
  9810. *
  9811. * _.sampleSize([1, 2, 3], 4);
  9812. * // => [2, 3, 1]
  9813. */
  9814. function sampleSize(collection, n, guard) {
  9815. if (guard ? isIterateeCall(collection, n, guard) : n === undefined) {
  9816. n = 1;
  9817. } else {
  9818. n = toInteger(n);
  9819. }
  9820. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9821. return func(collection, n);
  9822. }
  9823. /**
  9824. * Creates an array of shuffled values, using a version of the
  9825. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9826. *
  9827. * @static
  9828. * @memberOf _
  9829. * @since 0.1.0
  9830. * @category Collection
  9831. * @param {Array|Object} collection The collection to shuffle.
  9832. * @returns {Array} Returns the new shuffled array.
  9833. * @example
  9834. *
  9835. * _.shuffle([1, 2, 3, 4]);
  9836. * // => [4, 1, 3, 2]
  9837. */
  9838. function shuffle(collection) {
  9839. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9840. return func(collection);
  9841. }
  9842. /**
  9843. * Gets the size of `collection` by returning its length for array-like
  9844. * values or the number of own enumerable string keyed properties for objects.
  9845. *
  9846. * @static
  9847. * @memberOf _
  9848. * @since 0.1.0
  9849. * @category Collection
  9850. * @param {Array|Object|string} collection The collection to inspect.
  9851. * @returns {number} Returns the collection size.
  9852. * @example
  9853. *
  9854. * _.size([1, 2, 3]);
  9855. * // => 3
  9856. *
  9857. * _.size({ 'a': 1, 'b': 2 });
  9858. * // => 2
  9859. *
  9860. * _.size('pebbles');
  9861. * // => 7
  9862. */
  9863. function size(collection) {
  9864. if (collection == null) {
  9865. return 0;
  9866. }
  9867. if (isArrayLike(collection)) {
  9868. return isString(collection)
  9869. ? stringSize(collection)
  9870. : collection.length;
  9871. }
  9872. var tag = getTag(collection);
  9873. if (tag == mapTag || tag == setTag) {
  9874. return collection.size;
  9875. }
  9876. return baseKeys(collection).length;
  9877. }
  9878. /**
  9879. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9880. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9881. * invoked with three arguments: (value, index|key, collection).
  9882. *
  9883. * @static
  9884. * @memberOf _
  9885. * @since 0.1.0
  9886. * @category Collection
  9887. * @param {Array|Object} collection The collection to iterate over.
  9888. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9889. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9890. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9891. * else `false`.
  9892. * @example
  9893. *
  9894. * _.some([null, 0, 'yes', false], Boolean);
  9895. * // => true
  9896. *
  9897. * var users = [
  9898. * { 'user': 'barney', 'active': true },
  9899. * { 'user': 'fred', 'active': false }
  9900. * ];
  9901. *
  9902. * // The `_.matches` iteratee shorthand.
  9903. * _.some(users, { 'user': 'barney', 'active': false });
  9904. * // => false
  9905. *
  9906. * // The `_.matchesProperty` iteratee shorthand.
  9907. * _.some(users, ['active', false]);
  9908. * // => true
  9909. *
  9910. * // The `_.property` iteratee shorthand.
  9911. * _.some(users, 'active');
  9912. * // => true
  9913. */
  9914. function some(collection, predicate, guard) {
  9915. var func = isArray(collection) ? arraySome : baseSome;
  9916. if (guard && isIterateeCall(collection, predicate, guard)) {
  9917. predicate = undefined;
  9918. }
  9919. return func(collection, getIteratee(predicate, 3));
  9920. }
  9921. /**
  9922. * Creates an array of elements, sorted in ascending order by the results of
  9923. * running each element in a collection thru each iteratee. This method
  9924. * performs a stable sort, that is, it preserves the original sort order of
  9925. * equal elements. The iteratees are invoked with one argument: (value).
  9926. *
  9927. * @static
  9928. * @memberOf _
  9929. * @since 0.1.0
  9930. * @category Collection
  9931. * @param {Array|Object} collection The collection to iterate over.
  9932. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9933. * The iteratees to sort by.
  9934. * @returns {Array} Returns the new sorted array.
  9935. * @example
  9936. *
  9937. * var users = [
  9938. * { 'user': 'fred', 'age': 48 },
  9939. * { 'user': 'barney', 'age': 36 },
  9940. * { 'user': 'fred', 'age': 40 },
  9941. * { 'user': 'barney', 'age': 34 }
  9942. * ];
  9943. *
  9944. * _.sortBy(users, [function(o) { return o.user; }]);
  9945. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9946. *
  9947. * _.sortBy(users, ['user', 'age']);
  9948. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9949. */
  9950. var sortBy = baseRest(function(collection, iteratees) {
  9951. if (collection == null) {
  9952. return [];
  9953. }
  9954. var length = iteratees.length;
  9955. if (
  9956. length > 1 &&
  9957. isIterateeCall(collection, iteratees[0], iteratees[1])
  9958. ) {
  9959. iteratees = [];
  9960. } else if (
  9961. length > 2 &&
  9962. isIterateeCall(iteratees[0], iteratees[1], iteratees[2])
  9963. ) {
  9964. iteratees = [iteratees[0]];
  9965. }
  9966. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9967. });
  9968. /* ------------------------------------------------------------------------*/
  9969. /**
  9970. * Gets the timestamp of the number of milliseconds that have elapsed since
  9971. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9972. *
  9973. * @static
  9974. * @memberOf _
  9975. * @since 2.4.0
  9976. * @category Date
  9977. * @returns {number} Returns the timestamp.
  9978. * @example
  9979. *
  9980. * _.defer(function(stamp) {
  9981. * console.log(_.now() - stamp);
  9982. * }, _.now());
  9983. * // => Logs the number of milliseconds it took for the deferred invocation.
  9984. */
  9985. var now =
  9986. ctxNow ||
  9987. function() {
  9988. return root.Date.now();
  9989. };
  9990. /* ------------------------------------------------------------------------*/
  9991. /**
  9992. * The opposite of `_.before`; this method creates a function that invokes
  9993. * `func` once it's called `n` or more times.
  9994. *
  9995. * @static
  9996. * @memberOf _
  9997. * @since 0.1.0
  9998. * @category Function
  9999. * @param {number} n The number of calls before `func` is invoked.
  10000. * @param {Function} func The function to restrict.
  10001. * @returns {Function} Returns the new restricted function.
  10002. * @example
  10003. *
  10004. * var saves = ['profile', 'settings'];
  10005. *
  10006. * var done = _.after(saves.length, function() {
  10007. * console.log('done saving!');
  10008. * });
  10009. *
  10010. * _.forEach(saves, function(type) {
  10011. * asyncSave({ 'type': type, 'complete': done });
  10012. * });
  10013. * // => Logs 'done saving!' after the two async saves have completed.
  10014. */
  10015. function after(n, func) {
  10016. if (typeof func !== 'function') {
  10017. throw new TypeError(FUNC_ERROR_TEXT);
  10018. }
  10019. n = toInteger(n);
  10020. return function() {
  10021. if (--n < 1) {
  10022. return func.apply(this, arguments);
  10023. }
  10024. };
  10025. }
  10026. /**
  10027. * Creates a function that invokes `func`, with up to `n` arguments,
  10028. * ignoring any additional arguments.
  10029. *
  10030. * @static
  10031. * @memberOf _
  10032. * @since 3.0.0
  10033. * @category Function
  10034. * @param {Function} func The function to cap arguments for.
  10035. * @param {number} [n=func.length] The arity cap.
  10036. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10037. * @returns {Function} Returns the new capped function.
  10038. * @example
  10039. *
  10040. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  10041. * // => [6, 8, 10]
  10042. */
  10043. function ary(func, n, guard) {
  10044. n = guard ? undefined : n;
  10045. n = func && n == null ? func.length : n;
  10046. return createWrap(
  10047. func,
  10048. WRAP_ARY_FLAG,
  10049. undefined,
  10050. undefined,
  10051. undefined,
  10052. undefined,
  10053. n
  10054. );
  10055. }
  10056. /**
  10057. * Creates a function that invokes `func`, with the `this` binding and arguments
  10058. * of the created function, while it's called less than `n` times. Subsequent
  10059. * calls to the created function return the result of the last `func` invocation.
  10060. *
  10061. * @static
  10062. * @memberOf _
  10063. * @since 3.0.0
  10064. * @category Function
  10065. * @param {number} n The number of calls at which `func` is no longer invoked.
  10066. * @param {Function} func The function to restrict.
  10067. * @returns {Function} Returns the new restricted function.
  10068. * @example
  10069. *
  10070. * jQuery(element).on('click', _.before(5, addContactToList));
  10071. * // => Allows adding up to 4 contacts to the list.
  10072. */
  10073. function before(n, func) {
  10074. var result;
  10075. if (typeof func !== 'function') {
  10076. throw new TypeError(FUNC_ERROR_TEXT);
  10077. }
  10078. n = toInteger(n);
  10079. return function() {
  10080. if (--n > 0) {
  10081. result = func.apply(this, arguments);
  10082. }
  10083. if (n <= 1) {
  10084. func = undefined;
  10085. }
  10086. return result;
  10087. };
  10088. }
  10089. /**
  10090. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  10091. * and `partials` prepended to the arguments it receives.
  10092. *
  10093. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  10094. * may be used as a placeholder for partially applied arguments.
  10095. *
  10096. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  10097. * property of bound functions.
  10098. *
  10099. * @static
  10100. * @memberOf _
  10101. * @since 0.1.0
  10102. * @category Function
  10103. * @param {Function} func The function to bind.
  10104. * @param {*} thisArg The `this` binding of `func`.
  10105. * @param {...*} [partials] The arguments to be partially applied.
  10106. * @returns {Function} Returns the new bound function.
  10107. * @example
  10108. *
  10109. * function greet(greeting, punctuation) {
  10110. * return greeting + ' ' + this.user + punctuation;
  10111. * }
  10112. *
  10113. * var object = { 'user': 'fred' };
  10114. *
  10115. * var bound = _.bind(greet, object, 'hi');
  10116. * bound('!');
  10117. * // => 'hi fred!'
  10118. *
  10119. * // Bound with placeholders.
  10120. * var bound = _.bind(greet, object, _, '!');
  10121. * bound('hi');
  10122. * // => 'hi fred!'
  10123. */
  10124. var bind = baseRest(function(func, thisArg, partials) {
  10125. var bitmask = WRAP_BIND_FLAG;
  10126. if (partials.length) {
  10127. var holders = replaceHolders(partials, getHolder(bind));
  10128. bitmask |= WRAP_PARTIAL_FLAG;
  10129. }
  10130. return createWrap(func, bitmask, thisArg, partials, holders);
  10131. });
  10132. /**
  10133. * Creates a function that invokes the method at `object[key]` with `partials`
  10134. * prepended to the arguments it receives.
  10135. *
  10136. * This method differs from `_.bind` by allowing bound functions to reference
  10137. * methods that may be redefined or don't yet exist. See
  10138. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  10139. * for more details.
  10140. *
  10141. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  10142. * builds, may be used as a placeholder for partially applied arguments.
  10143. *
  10144. * @static
  10145. * @memberOf _
  10146. * @since 0.10.0
  10147. * @category Function
  10148. * @param {Object} object The object to invoke the method on.
  10149. * @param {string} key The key of the method.
  10150. * @param {...*} [partials] The arguments to be partially applied.
  10151. * @returns {Function} Returns the new bound function.
  10152. * @example
  10153. *
  10154. * var object = {
  10155. * 'user': 'fred',
  10156. * 'greet': function(greeting, punctuation) {
  10157. * return greeting + ' ' + this.user + punctuation;
  10158. * }
  10159. * };
  10160. *
  10161. * var bound = _.bindKey(object, 'greet', 'hi');
  10162. * bound('!');
  10163. * // => 'hi fred!'
  10164. *
  10165. * object.greet = function(greeting, punctuation) {
  10166. * return greeting + 'ya ' + this.user + punctuation;
  10167. * };
  10168. *
  10169. * bound('!');
  10170. * // => 'hiya fred!'
  10171. *
  10172. * // Bound with placeholders.
  10173. * var bound = _.bindKey(object, 'greet', _, '!');
  10174. * bound('hi');
  10175. * // => 'hiya fred!'
  10176. */
  10177. var bindKey = baseRest(function(object, key, partials) {
  10178. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  10179. if (partials.length) {
  10180. var holders = replaceHolders(partials, getHolder(bindKey));
  10181. bitmask |= WRAP_PARTIAL_FLAG;
  10182. }
  10183. return createWrap(key, bitmask, object, partials, holders);
  10184. });
  10185. /**
  10186. * Creates a function that accepts arguments of `func` and either invokes
  10187. * `func` returning its result, if at least `arity` number of arguments have
  10188. * been provided, or returns a function that accepts the remaining `func`
  10189. * arguments, and so on. The arity of `func` may be specified if `func.length`
  10190. * is not sufficient.
  10191. *
  10192. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  10193. * may be used as a placeholder for provided arguments.
  10194. *
  10195. * **Note:** This method doesn't set the "length" property of curried functions.
  10196. *
  10197. * @static
  10198. * @memberOf _
  10199. * @since 2.0.0
  10200. * @category Function
  10201. * @param {Function} func The function to curry.
  10202. * @param {number} [arity=func.length] The arity of `func`.
  10203. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10204. * @returns {Function} Returns the new curried function.
  10205. * @example
  10206. *
  10207. * var abc = function(a, b, c) {
  10208. * return [a, b, c];
  10209. * };
  10210. *
  10211. * var curried = _.curry(abc);
  10212. *
  10213. * curried(1)(2)(3);
  10214. * // => [1, 2, 3]
  10215. *
  10216. * curried(1, 2)(3);
  10217. * // => [1, 2, 3]
  10218. *
  10219. * curried(1, 2, 3);
  10220. * // => [1, 2, 3]
  10221. *
  10222. * // Curried with placeholders.
  10223. * curried(1)(_, 3)(2);
  10224. * // => [1, 2, 3]
  10225. */
  10226. function curry(func, arity, guard) {
  10227. arity = guard ? undefined : arity;
  10228. var result = createWrap(
  10229. func,
  10230. WRAP_CURRY_FLAG,
  10231. undefined,
  10232. undefined,
  10233. undefined,
  10234. undefined,
  10235. undefined,
  10236. arity
  10237. );
  10238. result.placeholder = curry.placeholder;
  10239. return result;
  10240. }
  10241. /**
  10242. * This method is like `_.curry` except that arguments are applied to `func`
  10243. * in the manner of `_.partialRight` instead of `_.partial`.
  10244. *
  10245. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  10246. * builds, may be used as a placeholder for provided arguments.
  10247. *
  10248. * **Note:** This method doesn't set the "length" property of curried functions.
  10249. *
  10250. * @static
  10251. * @memberOf _
  10252. * @since 3.0.0
  10253. * @category Function
  10254. * @param {Function} func The function to curry.
  10255. * @param {number} [arity=func.length] The arity of `func`.
  10256. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10257. * @returns {Function} Returns the new curried function.
  10258. * @example
  10259. *
  10260. * var abc = function(a, b, c) {
  10261. * return [a, b, c];
  10262. * };
  10263. *
  10264. * var curried = _.curryRight(abc);
  10265. *
  10266. * curried(3)(2)(1);
  10267. * // => [1, 2, 3]
  10268. *
  10269. * curried(2, 3)(1);
  10270. * // => [1, 2, 3]
  10271. *
  10272. * curried(1, 2, 3);
  10273. * // => [1, 2, 3]
  10274. *
  10275. * // Curried with placeholders.
  10276. * curried(3)(1, _)(2);
  10277. * // => [1, 2, 3]
  10278. */
  10279. function curryRight(func, arity, guard) {
  10280. arity = guard ? undefined : arity;
  10281. var result = createWrap(
  10282. func,
  10283. WRAP_CURRY_RIGHT_FLAG,
  10284. undefined,
  10285. undefined,
  10286. undefined,
  10287. undefined,
  10288. undefined,
  10289. arity
  10290. );
  10291. result.placeholder = curryRight.placeholder;
  10292. return result;
  10293. }
  10294. /**
  10295. * Creates a debounced function that delays invoking `func` until after `wait`
  10296. * milliseconds have elapsed since the last time the debounced function was
  10297. * invoked. The debounced function comes with a `cancel` method to cancel
  10298. * delayed `func` invocations and a `flush` method to immediately invoke them.
  10299. * Provide `options` to indicate whether `func` should be invoked on the
  10300. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  10301. * with the last arguments provided to the debounced function. Subsequent
  10302. * calls to the debounced function return the result of the last `func`
  10303. * invocation.
  10304. *
  10305. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10306. * invoked on the trailing edge of the timeout only if the debounced function
  10307. * is invoked more than once during the `wait` timeout.
  10308. *
  10309. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10310. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10311. *
  10312. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10313. * for details over the differences between `_.debounce` and `_.throttle`.
  10314. *
  10315. * @static
  10316. * @memberOf _
  10317. * @since 0.1.0
  10318. * @category Function
  10319. * @param {Function} func The function to debounce.
  10320. * @param {number} [wait=0] The number of milliseconds to delay.
  10321. * @param {Object} [options={}] The options object.
  10322. * @param {boolean} [options.leading=false]
  10323. * Specify invoking on the leading edge of the timeout.
  10324. * @param {number} [options.maxWait]
  10325. * The maximum time `func` is allowed to be delayed before it's invoked.
  10326. * @param {boolean} [options.trailing=true]
  10327. * Specify invoking on the trailing edge of the timeout.
  10328. * @returns {Function} Returns the new debounced function.
  10329. * @example
  10330. *
  10331. * // Avoid costly calculations while the window size is in flux.
  10332. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  10333. *
  10334. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  10335. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  10336. * 'leading': true,
  10337. * 'trailing': false
  10338. * }));
  10339. *
  10340. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  10341. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  10342. * var source = new EventSource('/stream');
  10343. * jQuery(source).on('message', debounced);
  10344. *
  10345. * // Cancel the trailing debounced invocation.
  10346. * jQuery(window).on('popstate', debounced.cancel);
  10347. */
  10348. function debounce(func, wait, options) {
  10349. var lastArgs,
  10350. lastThis,
  10351. maxWait,
  10352. result,
  10353. timerId,
  10354. lastCallTime,
  10355. lastInvokeTime = 0,
  10356. leading = false,
  10357. maxing = false,
  10358. trailing = true;
  10359. if (typeof func !== 'function') {
  10360. throw new TypeError(FUNC_ERROR_TEXT);
  10361. }
  10362. wait = toNumber(wait) || 0;
  10363. if (isObject(options)) {
  10364. leading = !!options.leading;
  10365. maxing = 'maxWait' in options;
  10366. maxWait = maxing
  10367. ? nativeMax(toNumber(options.maxWait) || 0, wait)
  10368. : maxWait;
  10369. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10370. }
  10371. function invokeFunc(time) {
  10372. var args = lastArgs,
  10373. thisArg = lastThis;
  10374. lastArgs = lastThis = undefined;
  10375. lastInvokeTime = time;
  10376. result = func.apply(thisArg, args);
  10377. return result;
  10378. }
  10379. function leadingEdge(time) {
  10380. // Reset any `maxWait` timer.
  10381. lastInvokeTime = time;
  10382. // Start the timer for the trailing edge.
  10383. timerId = setTimeout(timerExpired, wait);
  10384. // Invoke the leading edge.
  10385. return leading ? invokeFunc(time) : result;
  10386. }
  10387. function remainingWait(time) {
  10388. var timeSinceLastCall = time - lastCallTime,
  10389. timeSinceLastInvoke = time - lastInvokeTime,
  10390. timeWaiting = wait - timeSinceLastCall;
  10391. return maxing
  10392. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  10393. : timeWaiting;
  10394. }
  10395. function shouldInvoke(time) {
  10396. var timeSinceLastCall = time - lastCallTime,
  10397. timeSinceLastInvoke = time - lastInvokeTime;
  10398. // Either this is the first call, activity has stopped and we're at the
  10399. // trailing edge, the system time has gone backwards and we're treating
  10400. // it as the trailing edge, or we've hit the `maxWait` limit.
  10401. return (
  10402. lastCallTime === undefined ||
  10403. timeSinceLastCall >= wait ||
  10404. timeSinceLastCall < 0 ||
  10405. (maxing && timeSinceLastInvoke >= maxWait)
  10406. );
  10407. }
  10408. function timerExpired() {
  10409. var time = now();
  10410. if (shouldInvoke(time)) {
  10411. return trailingEdge(time);
  10412. }
  10413. // Restart the timer.
  10414. timerId = setTimeout(timerExpired, remainingWait(time));
  10415. }
  10416. function trailingEdge(time) {
  10417. timerId = undefined;
  10418. // Only invoke if we have `lastArgs` which means `func` has been
  10419. // debounced at least once.
  10420. if (trailing && lastArgs) {
  10421. return invokeFunc(time);
  10422. }
  10423. lastArgs = lastThis = undefined;
  10424. return result;
  10425. }
  10426. function cancel() {
  10427. if (timerId !== undefined) {
  10428. clearTimeout(timerId);
  10429. }
  10430. lastInvokeTime = 0;
  10431. lastArgs = lastCallTime = lastThis = timerId = undefined;
  10432. }
  10433. function flush() {
  10434. return timerId === undefined ? result : trailingEdge(now());
  10435. }
  10436. function debounced() {
  10437. var time = now(),
  10438. isInvoking = shouldInvoke(time);
  10439. lastArgs = arguments;
  10440. lastThis = this;
  10441. lastCallTime = time;
  10442. if (isInvoking) {
  10443. if (timerId === undefined) {
  10444. return leadingEdge(lastCallTime);
  10445. }
  10446. if (maxing) {
  10447. // Handle invocations in a tight loop.
  10448. timerId = setTimeout(timerExpired, wait);
  10449. return invokeFunc(lastCallTime);
  10450. }
  10451. }
  10452. if (timerId === undefined) {
  10453. timerId = setTimeout(timerExpired, wait);
  10454. }
  10455. return result;
  10456. }
  10457. debounced.cancel = cancel;
  10458. debounced.flush = flush;
  10459. return debounced;
  10460. }
  10461. /**
  10462. * Defers invoking the `func` until the current call stack has cleared. Any
  10463. * additional arguments are provided to `func` when it's invoked.
  10464. *
  10465. * @static
  10466. * @memberOf _
  10467. * @since 0.1.0
  10468. * @category Function
  10469. * @param {Function} func The function to defer.
  10470. * @param {...*} [args] The arguments to invoke `func` with.
  10471. * @returns {number} Returns the timer id.
  10472. * @example
  10473. *
  10474. * _.defer(function(text) {
  10475. * console.log(text);
  10476. * }, 'deferred');
  10477. * // => Logs 'deferred' after one millisecond.
  10478. */
  10479. var defer = baseRest(function(func, args) {
  10480. return baseDelay(func, 1, args);
  10481. });
  10482. /**
  10483. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  10484. * provided to `func` when it's invoked.
  10485. *
  10486. * @static
  10487. * @memberOf _
  10488. * @since 0.1.0
  10489. * @category Function
  10490. * @param {Function} func The function to delay.
  10491. * @param {number} wait The number of milliseconds to delay invocation.
  10492. * @param {...*} [args] The arguments to invoke `func` with.
  10493. * @returns {number} Returns the timer id.
  10494. * @example
  10495. *
  10496. * _.delay(function(text) {
  10497. * console.log(text);
  10498. * }, 1000, 'later');
  10499. * // => Logs 'later' after one second.
  10500. */
  10501. var delay = baseRest(function(func, wait, args) {
  10502. return baseDelay(func, toNumber(wait) || 0, args);
  10503. });
  10504. /**
  10505. * Creates a function that invokes `func` with arguments reversed.
  10506. *
  10507. * @static
  10508. * @memberOf _
  10509. * @since 4.0.0
  10510. * @category Function
  10511. * @param {Function} func The function to flip arguments for.
  10512. * @returns {Function} Returns the new flipped function.
  10513. * @example
  10514. *
  10515. * var flipped = _.flip(function() {
  10516. * return _.toArray(arguments);
  10517. * });
  10518. *
  10519. * flipped('a', 'b', 'c', 'd');
  10520. * // => ['d', 'c', 'b', 'a']
  10521. */
  10522. function flip(func) {
  10523. return createWrap(func, WRAP_FLIP_FLAG);
  10524. }
  10525. /**
  10526. * Creates a function that memoizes the result of `func`. If `resolver` is
  10527. * provided, it determines the cache key for storing the result based on the
  10528. * arguments provided to the memoized function. By default, the first argument
  10529. * provided to the memoized function is used as the map cache key. The `func`
  10530. * is invoked with the `this` binding of the memoized function.
  10531. *
  10532. * **Note:** The cache is exposed as the `cache` property on the memoized
  10533. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  10534. * constructor with one whose instances implement the
  10535. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  10536. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  10537. *
  10538. * @static
  10539. * @memberOf _
  10540. * @since 0.1.0
  10541. * @category Function
  10542. * @param {Function} func The function to have its output memoized.
  10543. * @param {Function} [resolver] The function to resolve the cache key.
  10544. * @returns {Function} Returns the new memoized function.
  10545. * @example
  10546. *
  10547. * var object = { 'a': 1, 'b': 2 };
  10548. * var other = { 'c': 3, 'd': 4 };
  10549. *
  10550. * var values = _.memoize(_.values);
  10551. * values(object);
  10552. * // => [1, 2]
  10553. *
  10554. * values(other);
  10555. * // => [3, 4]
  10556. *
  10557. * object.a = 2;
  10558. * values(object);
  10559. * // => [1, 2]
  10560. *
  10561. * // Modify the result cache.
  10562. * values.cache.set(object, ['a', 'b']);
  10563. * values(object);
  10564. * // => ['a', 'b']
  10565. *
  10566. * // Replace `_.memoize.Cache`.
  10567. * _.memoize.Cache = WeakMap;
  10568. */
  10569. function memoize(func, resolver) {
  10570. if (
  10571. typeof func !== 'function' ||
  10572. (resolver != null && typeof resolver !== 'function')
  10573. ) {
  10574. throw new TypeError(FUNC_ERROR_TEXT);
  10575. }
  10576. var memoized = function() {
  10577. var args = arguments,
  10578. key = resolver ? resolver.apply(this, args) : args[0],
  10579. cache = memoized.cache;
  10580. if (cache.has(key)) {
  10581. return cache.get(key);
  10582. }
  10583. var result = func.apply(this, args);
  10584. memoized.cache = cache.set(key, result) || cache;
  10585. return result;
  10586. };
  10587. memoized.cache = new (memoize.Cache || MapCache)();
  10588. return memoized;
  10589. }
  10590. // Expose `MapCache`.
  10591. memoize.Cache = MapCache;
  10592. /**
  10593. * Creates a function that negates the result of the predicate `func`. The
  10594. * `func` predicate is invoked with the `this` binding and arguments of the
  10595. * created function.
  10596. *
  10597. * @static
  10598. * @memberOf _
  10599. * @since 3.0.0
  10600. * @category Function
  10601. * @param {Function} predicate The predicate to negate.
  10602. * @returns {Function} Returns the new negated function.
  10603. * @example
  10604. *
  10605. * function isEven(n) {
  10606. * return n % 2 == 0;
  10607. * }
  10608. *
  10609. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  10610. * // => [1, 3, 5]
  10611. */
  10612. function negate(predicate) {
  10613. if (typeof predicate !== 'function') {
  10614. throw new TypeError(FUNC_ERROR_TEXT);
  10615. }
  10616. return function() {
  10617. var args = arguments;
  10618. switch (args.length) {
  10619. case 0:
  10620. return !predicate.call(this);
  10621. case 1:
  10622. return !predicate.call(this, args[0]);
  10623. case 2:
  10624. return !predicate.call(this, args[0], args[1]);
  10625. case 3:
  10626. return !predicate.call(this, args[0], args[1], args[2]);
  10627. }
  10628. return !predicate.apply(this, args);
  10629. };
  10630. }
  10631. /**
  10632. * Creates a function that is restricted to invoking `func` once. Repeat calls
  10633. * to the function return the value of the first invocation. The `func` is
  10634. * invoked with the `this` binding and arguments of the created function.
  10635. *
  10636. * @static
  10637. * @memberOf _
  10638. * @since 0.1.0
  10639. * @category Function
  10640. * @param {Function} func The function to restrict.
  10641. * @returns {Function} Returns the new restricted function.
  10642. * @example
  10643. *
  10644. * var initialize = _.once(createApplication);
  10645. * initialize();
  10646. * initialize();
  10647. * // => `createApplication` is invoked once
  10648. */
  10649. function once(func) {
  10650. return before(2, func);
  10651. }
  10652. /**
  10653. * Creates a function that invokes `func` with its arguments transformed.
  10654. *
  10655. * @static
  10656. * @since 4.0.0
  10657. * @memberOf _
  10658. * @category Function
  10659. * @param {Function} func The function to wrap.
  10660. * @param {...(Function|Function[])} [transforms=[_.identity]]
  10661. * The argument transforms.
  10662. * @returns {Function} Returns the new function.
  10663. * @example
  10664. *
  10665. * function doubled(n) {
  10666. * return n * 2;
  10667. * }
  10668. *
  10669. * function square(n) {
  10670. * return n * n;
  10671. * }
  10672. *
  10673. * var func = _.overArgs(function(x, y) {
  10674. * return [x, y];
  10675. * }, [square, doubled]);
  10676. *
  10677. * func(9, 3);
  10678. * // => [81, 6]
  10679. *
  10680. * func(10, 5);
  10681. * // => [100, 10]
  10682. */
  10683. var overArgs = castRest(function(func, transforms) {
  10684. transforms =
  10685. transforms.length == 1 && isArray(transforms[0])
  10686. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  10687. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  10688. var funcsLength = transforms.length;
  10689. return baseRest(function(args) {
  10690. var index = -1,
  10691. length = nativeMin(args.length, funcsLength);
  10692. while (++index < length) {
  10693. args[index] = transforms[index].call(this, args[index]);
  10694. }
  10695. return apply(func, this, args);
  10696. });
  10697. });
  10698. /**
  10699. * Creates a function that invokes `func` with `partials` prepended to the
  10700. * arguments it receives. This method is like `_.bind` except it does **not**
  10701. * alter the `this` binding.
  10702. *
  10703. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  10704. * builds, may be used as a placeholder for partially applied arguments.
  10705. *
  10706. * **Note:** This method doesn't set the "length" property of partially
  10707. * applied functions.
  10708. *
  10709. * @static
  10710. * @memberOf _
  10711. * @since 0.2.0
  10712. * @category Function
  10713. * @param {Function} func The function to partially apply arguments to.
  10714. * @param {...*} [partials] The arguments to be partially applied.
  10715. * @returns {Function} Returns the new partially applied function.
  10716. * @example
  10717. *
  10718. * function greet(greeting, name) {
  10719. * return greeting + ' ' + name;
  10720. * }
  10721. *
  10722. * var sayHelloTo = _.partial(greet, 'hello');
  10723. * sayHelloTo('fred');
  10724. * // => 'hello fred'
  10725. *
  10726. * // Partially applied with placeholders.
  10727. * var greetFred = _.partial(greet, _, 'fred');
  10728. * greetFred('hi');
  10729. * // => 'hi fred'
  10730. */
  10731. var partial = baseRest(function(func, partials) {
  10732. var holders = replaceHolders(partials, getHolder(partial));
  10733. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10734. });
  10735. /**
  10736. * This method is like `_.partial` except that partially applied arguments
  10737. * are appended to the arguments it receives.
  10738. *
  10739. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10740. * builds, may be used as a placeholder for partially applied arguments.
  10741. *
  10742. * **Note:** This method doesn't set the "length" property of partially
  10743. * applied functions.
  10744. *
  10745. * @static
  10746. * @memberOf _
  10747. * @since 1.0.0
  10748. * @category Function
  10749. * @param {Function} func The function to partially apply arguments to.
  10750. * @param {...*} [partials] The arguments to be partially applied.
  10751. * @returns {Function} Returns the new partially applied function.
  10752. * @example
  10753. *
  10754. * function greet(greeting, name) {
  10755. * return greeting + ' ' + name;
  10756. * }
  10757. *
  10758. * var greetFred = _.partialRight(greet, 'fred');
  10759. * greetFred('hi');
  10760. * // => 'hi fred'
  10761. *
  10762. * // Partially applied with placeholders.
  10763. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10764. * sayHelloTo('fred');
  10765. * // => 'hello fred'
  10766. */
  10767. var partialRight = baseRest(function(func, partials) {
  10768. var holders = replaceHolders(partials, getHolder(partialRight));
  10769. return createWrap(
  10770. func,
  10771. WRAP_PARTIAL_RIGHT_FLAG,
  10772. undefined,
  10773. partials,
  10774. holders
  10775. );
  10776. });
  10777. /**
  10778. * Creates a function that invokes `func` with arguments arranged according
  10779. * to the specified `indexes` where the argument value at the first index is
  10780. * provided as the first argument, the argument value at the second index is
  10781. * provided as the second argument, and so on.
  10782. *
  10783. * @static
  10784. * @memberOf _
  10785. * @since 3.0.0
  10786. * @category Function
  10787. * @param {Function} func The function to rearrange arguments for.
  10788. * @param {...(number|number[])} indexes The arranged argument indexes.
  10789. * @returns {Function} Returns the new function.
  10790. * @example
  10791. *
  10792. * var rearged = _.rearg(function(a, b, c) {
  10793. * return [a, b, c];
  10794. * }, [2, 0, 1]);
  10795. *
  10796. * rearged('b', 'c', 'a')
  10797. * // => ['a', 'b', 'c']
  10798. */
  10799. var rearg = flatRest(function(func, indexes) {
  10800. return createWrap(
  10801. func,
  10802. WRAP_REARG_FLAG,
  10803. undefined,
  10804. undefined,
  10805. undefined,
  10806. indexes
  10807. );
  10808. });
  10809. /**
  10810. * Creates a function that invokes `func` with the `this` binding of the
  10811. * created function and arguments from `start` and beyond provided as
  10812. * an array.
  10813. *
  10814. * **Note:** This method is based on the
  10815. * [rest parameter](https://mdn.io/rest_parameters).
  10816. *
  10817. * @static
  10818. * @memberOf _
  10819. * @since 4.0.0
  10820. * @category Function
  10821. * @param {Function} func The function to apply a rest parameter to.
  10822. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10823. * @returns {Function} Returns the new function.
  10824. * @example
  10825. *
  10826. * var say = _.rest(function(what, names) {
  10827. * return what + ' ' + _.initial(names).join(', ') +
  10828. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10829. * });
  10830. *
  10831. * say('hello', 'fred', 'barney', 'pebbles');
  10832. * // => 'hello fred, barney, & pebbles'
  10833. */
  10834. function rest(func, start) {
  10835. if (typeof func !== 'function') {
  10836. throw new TypeError(FUNC_ERROR_TEXT);
  10837. }
  10838. start = start === undefined ? start : toInteger(start);
  10839. return baseRest(func, start);
  10840. }
  10841. /**
  10842. * Creates a function that invokes `func` with the `this` binding of the
  10843. * create function and an array of arguments much like
  10844. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10845. *
  10846. * **Note:** This method is based on the
  10847. * [spread operator](https://mdn.io/spread_operator).
  10848. *
  10849. * @static
  10850. * @memberOf _
  10851. * @since 3.2.0
  10852. * @category Function
  10853. * @param {Function} func The function to spread arguments over.
  10854. * @param {number} [start=0] The start position of the spread.
  10855. * @returns {Function} Returns the new function.
  10856. * @example
  10857. *
  10858. * var say = _.spread(function(who, what) {
  10859. * return who + ' says ' + what;
  10860. * });
  10861. *
  10862. * say(['fred', 'hello']);
  10863. * // => 'fred says hello'
  10864. *
  10865. * var numbers = Promise.all([
  10866. * Promise.resolve(40),
  10867. * Promise.resolve(36)
  10868. * ]);
  10869. *
  10870. * numbers.then(_.spread(function(x, y) {
  10871. * return x + y;
  10872. * }));
  10873. * // => a Promise of 76
  10874. */
  10875. function spread(func, start) {
  10876. if (typeof func !== 'function') {
  10877. throw new TypeError(FUNC_ERROR_TEXT);
  10878. }
  10879. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10880. return baseRest(function(args) {
  10881. var array = args[start],
  10882. otherArgs = castSlice(args, 0, start);
  10883. if (array) {
  10884. arrayPush(otherArgs, array);
  10885. }
  10886. return apply(func, this, otherArgs);
  10887. });
  10888. }
  10889. /**
  10890. * Creates a throttled function that only invokes `func` at most once per
  10891. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10892. * method to cancel delayed `func` invocations and a `flush` method to
  10893. * immediately invoke them. Provide `options` to indicate whether `func`
  10894. * should be invoked on the leading and/or trailing edge of the `wait`
  10895. * timeout. The `func` is invoked with the last arguments provided to the
  10896. * throttled function. Subsequent calls to the throttled function return the
  10897. * result of the last `func` invocation.
  10898. *
  10899. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10900. * invoked on the trailing edge of the timeout only if the throttled function
  10901. * is invoked more than once during the `wait` timeout.
  10902. *
  10903. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10904. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10905. *
  10906. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10907. * for details over the differences between `_.throttle` and `_.debounce`.
  10908. *
  10909. * @static
  10910. * @memberOf _
  10911. * @since 0.1.0
  10912. * @category Function
  10913. * @param {Function} func The function to throttle.
  10914. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10915. * @param {Object} [options={}] The options object.
  10916. * @param {boolean} [options.leading=true]
  10917. * Specify invoking on the leading edge of the timeout.
  10918. * @param {boolean} [options.trailing=true]
  10919. * Specify invoking on the trailing edge of the timeout.
  10920. * @returns {Function} Returns the new throttled function.
  10921. * @example
  10922. *
  10923. * // Avoid excessively updating the position while scrolling.
  10924. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10925. *
  10926. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10927. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10928. * jQuery(element).on('click', throttled);
  10929. *
  10930. * // Cancel the trailing throttled invocation.
  10931. * jQuery(window).on('popstate', throttled.cancel);
  10932. */
  10933. function throttle(func, wait, options) {
  10934. var leading = true,
  10935. trailing = true;
  10936. if (typeof func !== 'function') {
  10937. throw new TypeError(FUNC_ERROR_TEXT);
  10938. }
  10939. if (isObject(options)) {
  10940. leading = 'leading' in options ? !!options.leading : leading;
  10941. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10942. }
  10943. return debounce(func, wait, {
  10944. leading: leading,
  10945. maxWait: wait,
  10946. trailing: trailing
  10947. });
  10948. }
  10949. /**
  10950. * Creates a function that accepts up to one argument, ignoring any
  10951. * additional arguments.
  10952. *
  10953. * @static
  10954. * @memberOf _
  10955. * @since 4.0.0
  10956. * @category Function
  10957. * @param {Function} func The function to cap arguments for.
  10958. * @returns {Function} Returns the new capped function.
  10959. * @example
  10960. *
  10961. * _.map(['6', '8', '10'], _.unary(parseInt));
  10962. * // => [6, 8, 10]
  10963. */
  10964. function unary(func) {
  10965. return ary(func, 1);
  10966. }
  10967. /**
  10968. * Creates a function that provides `value` to `wrapper` as its first
  10969. * argument. Any additional arguments provided to the function are appended
  10970. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10971. * binding of the created function.
  10972. *
  10973. * @static
  10974. * @memberOf _
  10975. * @since 0.1.0
  10976. * @category Function
  10977. * @param {*} value The value to wrap.
  10978. * @param {Function} [wrapper=identity] The wrapper function.
  10979. * @returns {Function} Returns the new function.
  10980. * @example
  10981. *
  10982. * var p = _.wrap(_.escape, function(func, text) {
  10983. * return '<p>' + func(text) + '</p>';
  10984. * });
  10985. *
  10986. * p('fred, barney, & pebbles');
  10987. * // => '<p>fred, barney, &amp; pebbles</p>'
  10988. */
  10989. function wrap(value, wrapper) {
  10990. return partial(castFunction(wrapper), value);
  10991. }
  10992. /* ------------------------------------------------------------------------*/
  10993. /**
  10994. * Casts `value` as an array if it's not one.
  10995. *
  10996. * @static
  10997. * @memberOf _
  10998. * @since 4.4.0
  10999. * @category Lang
  11000. * @param {*} value The value to inspect.
  11001. * @returns {Array} Returns the cast array.
  11002. * @example
  11003. *
  11004. * _.castArray(1);
  11005. * // => [1]
  11006. *
  11007. * _.castArray({ 'a': 1 });
  11008. * // => [{ 'a': 1 }]
  11009. *
  11010. * _.castArray('abc');
  11011. * // => ['abc']
  11012. *
  11013. * _.castArray(null);
  11014. * // => [null]
  11015. *
  11016. * _.castArray(undefined);
  11017. * // => [undefined]
  11018. *
  11019. * _.castArray();
  11020. * // => []
  11021. *
  11022. * var array = [1, 2, 3];
  11023. * console.log(_.castArray(array) === array);
  11024. * // => true
  11025. */
  11026. function castArray() {
  11027. if (!arguments.length) {
  11028. return [];
  11029. }
  11030. var value = arguments[0];
  11031. return isArray(value) ? value : [value];
  11032. }
  11033. /**
  11034. * Creates a shallow clone of `value`.
  11035. *
  11036. * **Note:** This method is loosely based on the
  11037. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  11038. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  11039. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  11040. * arrays. The own enumerable properties of `arguments` objects are cloned
  11041. * as plain objects. An empty object is returned for uncloneable values such
  11042. * as error objects, functions, DOM nodes, and WeakMaps.
  11043. *
  11044. * @static
  11045. * @memberOf _
  11046. * @since 0.1.0
  11047. * @category Lang
  11048. * @param {*} value The value to clone.
  11049. * @returns {*} Returns the cloned value.
  11050. * @see _.cloneDeep
  11051. * @example
  11052. *
  11053. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  11054. *
  11055. * var shallow = _.clone(objects);
  11056. * console.log(shallow[0] === objects[0]);
  11057. * // => true
  11058. */
  11059. function clone(value) {
  11060. return baseClone(value, CLONE_SYMBOLS_FLAG);
  11061. }
  11062. /**
  11063. * This method is like `_.clone` except that it accepts `customizer` which
  11064. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  11065. * cloning is handled by the method instead. The `customizer` is invoked with
  11066. * up to four arguments; (value [, index|key, object, stack]).
  11067. *
  11068. * @static
  11069. * @memberOf _
  11070. * @since 4.0.0
  11071. * @category Lang
  11072. * @param {*} value The value to clone.
  11073. * @param {Function} [customizer] The function to customize cloning.
  11074. * @returns {*} Returns the cloned value.
  11075. * @see _.cloneDeepWith
  11076. * @example
  11077. *
  11078. * function customizer(value) {
  11079. * if (_.isElement(value)) {
  11080. * return value.cloneNode(false);
  11081. * }
  11082. * }
  11083. *
  11084. * var el = _.cloneWith(document.body, customizer);
  11085. *
  11086. * console.log(el === document.body);
  11087. * // => false
  11088. * console.log(el.nodeName);
  11089. * // => 'BODY'
  11090. * console.log(el.childNodes.length);
  11091. * // => 0
  11092. */
  11093. function cloneWith(value, customizer) {
  11094. customizer = typeof customizer === 'function' ? customizer : undefined;
  11095. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  11096. }
  11097. /**
  11098. * This method is like `_.clone` except that it recursively clones `value`.
  11099. *
  11100. * @static
  11101. * @memberOf _
  11102. * @since 1.0.0
  11103. * @category Lang
  11104. * @param {*} value The value to recursively clone.
  11105. * @returns {*} Returns the deep cloned value.
  11106. * @see _.clone
  11107. * @example
  11108. *
  11109. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  11110. *
  11111. * var deep = _.cloneDeep(objects);
  11112. * console.log(deep[0] === objects[0]);
  11113. * // => false
  11114. */
  11115. function cloneDeep(value) {
  11116. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  11117. }
  11118. /**
  11119. * This method is like `_.cloneWith` except that it recursively clones `value`.
  11120. *
  11121. * @static
  11122. * @memberOf _
  11123. * @since 4.0.0
  11124. * @category Lang
  11125. * @param {*} value The value to recursively clone.
  11126. * @param {Function} [customizer] The function to customize cloning.
  11127. * @returns {*} Returns the deep cloned value.
  11128. * @see _.cloneWith
  11129. * @example
  11130. *
  11131. * function customizer(value) {
  11132. * if (_.isElement(value)) {
  11133. * return value.cloneNode(true);
  11134. * }
  11135. * }
  11136. *
  11137. * var el = _.cloneDeepWith(document.body, customizer);
  11138. *
  11139. * console.log(el === document.body);
  11140. * // => false
  11141. * console.log(el.nodeName);
  11142. * // => 'BODY'
  11143. * console.log(el.childNodes.length);
  11144. * // => 20
  11145. */
  11146. function cloneDeepWith(value, customizer) {
  11147. customizer = typeof customizer === 'function' ? customizer : undefined;
  11148. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  11149. }
  11150. /**
  11151. * Checks if `object` conforms to `source` by invoking the predicate
  11152. * properties of `source` with the corresponding property values of `object`.
  11153. *
  11154. * **Note:** This method is equivalent to `_.conforms` when `source` is
  11155. * partially applied.
  11156. *
  11157. * @static
  11158. * @memberOf _
  11159. * @since 4.14.0
  11160. * @category Lang
  11161. * @param {Object} object The object to inspect.
  11162. * @param {Object} source The object of property predicates to conform to.
  11163. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  11164. * @example
  11165. *
  11166. * var object = { 'a': 1, 'b': 2 };
  11167. *
  11168. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  11169. * // => true
  11170. *
  11171. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  11172. * // => false
  11173. */
  11174. function conformsTo(object, source) {
  11175. return source == null || baseConformsTo(object, source, keys(source));
  11176. }
  11177. /**
  11178. * Performs a
  11179. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  11180. * comparison between two values to determine if they are equivalent.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @since 4.0.0
  11185. * @category Lang
  11186. * @param {*} value The value to compare.
  11187. * @param {*} other The other value to compare.
  11188. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  11189. * @example
  11190. *
  11191. * var object = { 'a': 1 };
  11192. * var other = { 'a': 1 };
  11193. *
  11194. * _.eq(object, object);
  11195. * // => true
  11196. *
  11197. * _.eq(object, other);
  11198. * // => false
  11199. *
  11200. * _.eq('a', 'a');
  11201. * // => true
  11202. *
  11203. * _.eq('a', Object('a'));
  11204. * // => false
  11205. *
  11206. * _.eq(NaN, NaN);
  11207. * // => true
  11208. */
  11209. function eq(value, other) {
  11210. return value === other || (value !== value && other !== other);
  11211. }
  11212. /**
  11213. * Checks if `value` is greater than `other`.
  11214. *
  11215. * @static
  11216. * @memberOf _
  11217. * @since 3.9.0
  11218. * @category Lang
  11219. * @param {*} value The value to compare.
  11220. * @param {*} other The other value to compare.
  11221. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  11222. * else `false`.
  11223. * @see _.lt
  11224. * @example
  11225. *
  11226. * _.gt(3, 1);
  11227. * // => true
  11228. *
  11229. * _.gt(3, 3);
  11230. * // => false
  11231. *
  11232. * _.gt(1, 3);
  11233. * // => false
  11234. */
  11235. var gt = createRelationalOperation(baseGt);
  11236. /**
  11237. * Checks if `value` is greater than or equal to `other`.
  11238. *
  11239. * @static
  11240. * @memberOf _
  11241. * @since 3.9.0
  11242. * @category Lang
  11243. * @param {*} value The value to compare.
  11244. * @param {*} other The other value to compare.
  11245. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  11246. * `other`, else `false`.
  11247. * @see _.lte
  11248. * @example
  11249. *
  11250. * _.gte(3, 1);
  11251. * // => true
  11252. *
  11253. * _.gte(3, 3);
  11254. * // => true
  11255. *
  11256. * _.gte(1, 3);
  11257. * // => false
  11258. */
  11259. var gte = createRelationalOperation(function(value, other) {
  11260. return value >= other;
  11261. });
  11262. /**
  11263. * Checks if `value` is likely an `arguments` object.
  11264. *
  11265. * @static
  11266. * @memberOf _
  11267. * @since 0.1.0
  11268. * @category Lang
  11269. * @param {*} value The value to check.
  11270. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  11271. * else `false`.
  11272. * @example
  11273. *
  11274. * _.isArguments(function() { return arguments; }());
  11275. * // => true
  11276. *
  11277. * _.isArguments([1, 2, 3]);
  11278. * // => false
  11279. */
  11280. var isArguments = baseIsArguments(
  11281. (function() {
  11282. return arguments;
  11283. })()
  11284. )
  11285. ? baseIsArguments
  11286. : function(value) {
  11287. return (
  11288. isObjectLike(value) &&
  11289. hasOwnProperty.call(value, 'callee') &&
  11290. !propertyIsEnumerable.call(value, 'callee')
  11291. );
  11292. };
  11293. /**
  11294. * Checks if `value` is classified as an `Array` object.
  11295. *
  11296. * @static
  11297. * @memberOf _
  11298. * @since 0.1.0
  11299. * @category Lang
  11300. * @param {*} value The value to check.
  11301. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  11302. * @example
  11303. *
  11304. * _.isArray([1, 2, 3]);
  11305. * // => true
  11306. *
  11307. * _.isArray(document.body.children);
  11308. * // => false
  11309. *
  11310. * _.isArray('abc');
  11311. * // => false
  11312. *
  11313. * _.isArray(_.noop);
  11314. * // => false
  11315. */
  11316. var isArray = Array.isArray;
  11317. /**
  11318. * Checks if `value` is classified as an `ArrayBuffer` object.
  11319. *
  11320. * @static
  11321. * @memberOf _
  11322. * @since 4.3.0
  11323. * @category Lang
  11324. * @param {*} value The value to check.
  11325. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  11326. * @example
  11327. *
  11328. * _.isArrayBuffer(new ArrayBuffer(2));
  11329. * // => true
  11330. *
  11331. * _.isArrayBuffer(new Array(2));
  11332. * // => false
  11333. */
  11334. var isArrayBuffer = nodeIsArrayBuffer
  11335. ? baseUnary(nodeIsArrayBuffer)
  11336. : baseIsArrayBuffer;
  11337. /**
  11338. * Checks if `value` is array-like. A value is considered array-like if it's
  11339. * not a function and has a `value.length` that's an integer greater than or
  11340. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  11341. *
  11342. * @static
  11343. * @memberOf _
  11344. * @since 4.0.0
  11345. * @category Lang
  11346. * @param {*} value The value to check.
  11347. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  11348. * @example
  11349. *
  11350. * _.isArrayLike([1, 2, 3]);
  11351. * // => true
  11352. *
  11353. * _.isArrayLike(document.body.children);
  11354. * // => true
  11355. *
  11356. * _.isArrayLike('abc');
  11357. * // => true
  11358. *
  11359. * _.isArrayLike(_.noop);
  11360. * // => false
  11361. */
  11362. function isArrayLike(value) {
  11363. return value != null && isLength(value.length) && !isFunction(value);
  11364. }
  11365. /**
  11366. * This method is like `_.isArrayLike` except that it also checks if `value`
  11367. * is an object.
  11368. *
  11369. * @static
  11370. * @memberOf _
  11371. * @since 4.0.0
  11372. * @category Lang
  11373. * @param {*} value The value to check.
  11374. * @returns {boolean} Returns `true` if `value` is an array-like object,
  11375. * else `false`.
  11376. * @example
  11377. *
  11378. * _.isArrayLikeObject([1, 2, 3]);
  11379. * // => true
  11380. *
  11381. * _.isArrayLikeObject(document.body.children);
  11382. * // => true
  11383. *
  11384. * _.isArrayLikeObject('abc');
  11385. * // => false
  11386. *
  11387. * _.isArrayLikeObject(_.noop);
  11388. * // => false
  11389. */
  11390. function isArrayLikeObject(value) {
  11391. return isObjectLike(value) && isArrayLike(value);
  11392. }
  11393. /**
  11394. * Checks if `value` is classified as a boolean primitive or object.
  11395. *
  11396. * @static
  11397. * @memberOf _
  11398. * @since 0.1.0
  11399. * @category Lang
  11400. * @param {*} value The value to check.
  11401. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  11402. * @example
  11403. *
  11404. * _.isBoolean(false);
  11405. * // => true
  11406. *
  11407. * _.isBoolean(null);
  11408. * // => false
  11409. */
  11410. function isBoolean(value) {
  11411. return (
  11412. value === true ||
  11413. value === false ||
  11414. (isObjectLike(value) && baseGetTag(value) == boolTag)
  11415. );
  11416. }
  11417. /**
  11418. * Checks if `value` is a buffer.
  11419. *
  11420. * @static
  11421. * @memberOf _
  11422. * @since 4.3.0
  11423. * @category Lang
  11424. * @param {*} value The value to check.
  11425. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  11426. * @example
  11427. *
  11428. * _.isBuffer(new Buffer(2));
  11429. * // => true
  11430. *
  11431. * _.isBuffer(new Uint8Array(2));
  11432. * // => false
  11433. */
  11434. var isBuffer = nativeIsBuffer || stubFalse;
  11435. /**
  11436. * Checks if `value` is classified as a `Date` object.
  11437. *
  11438. * @static
  11439. * @memberOf _
  11440. * @since 0.1.0
  11441. * @category Lang
  11442. * @param {*} value The value to check.
  11443. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  11444. * @example
  11445. *
  11446. * _.isDate(new Date);
  11447. * // => true
  11448. *
  11449. * _.isDate('Mon April 23 2012');
  11450. * // => false
  11451. */
  11452. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  11453. /**
  11454. * Checks if `value` is likely a DOM element.
  11455. *
  11456. * @static
  11457. * @memberOf _
  11458. * @since 0.1.0
  11459. * @category Lang
  11460. * @param {*} value The value to check.
  11461. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  11462. * @example
  11463. *
  11464. * _.isElement(document.body);
  11465. * // => true
  11466. *
  11467. * _.isElement('<body>');
  11468. * // => false
  11469. */
  11470. function isElement(value) {
  11471. return (
  11472. isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value)
  11473. );
  11474. }
  11475. /**
  11476. * Checks if `value` is an empty object, collection, map, or set.
  11477. *
  11478. * Objects are considered empty if they have no own enumerable string keyed
  11479. * properties.
  11480. *
  11481. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  11482. * jQuery-like collections are considered empty if they have a `length` of `0`.
  11483. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  11484. *
  11485. * @static
  11486. * @memberOf _
  11487. * @since 0.1.0
  11488. * @category Lang
  11489. * @param {*} value The value to check.
  11490. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  11491. * @example
  11492. *
  11493. * _.isEmpty(null);
  11494. * // => true
  11495. *
  11496. * _.isEmpty(true);
  11497. * // => true
  11498. *
  11499. * _.isEmpty(1);
  11500. * // => true
  11501. *
  11502. * _.isEmpty([1, 2, 3]);
  11503. * // => false
  11504. *
  11505. * _.isEmpty({ 'a': 1 });
  11506. * // => false
  11507. */
  11508. function isEmpty(value) {
  11509. if (value == null) {
  11510. return true;
  11511. }
  11512. if (
  11513. isArrayLike(value) &&
  11514. (isArray(value) ||
  11515. typeof value === 'string' ||
  11516. typeof value.splice === 'function' ||
  11517. isBuffer(value) ||
  11518. isTypedArray(value) ||
  11519. isArguments(value))
  11520. ) {
  11521. return !value.length;
  11522. }
  11523. var tag = getTag(value);
  11524. if (tag == mapTag || tag == setTag) {
  11525. return !value.size;
  11526. }
  11527. if (isPrototype(value)) {
  11528. return !baseKeys(value).length;
  11529. }
  11530. for (var key in value) {
  11531. if (hasOwnProperty.call(value, key)) {
  11532. return false;
  11533. }
  11534. }
  11535. return true;
  11536. }
  11537. /**
  11538. * Performs a deep comparison between two values to determine if they are
  11539. * equivalent.
  11540. *
  11541. * **Note:** This method supports comparing arrays, array buffers, booleans,
  11542. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  11543. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  11544. * by their own, not inherited, enumerable properties. Functions and DOM
  11545. * nodes are compared by strict equality, i.e. `===`.
  11546. *
  11547. * @static
  11548. * @memberOf _
  11549. * @since 0.1.0
  11550. * @category Lang
  11551. * @param {*} value The value to compare.
  11552. * @param {*} other The other value to compare.
  11553. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  11554. * @example
  11555. *
  11556. * var object = { 'a': 1 };
  11557. * var other = { 'a': 1 };
  11558. *
  11559. * _.isEqual(object, other);
  11560. * // => true
  11561. *
  11562. * object === other;
  11563. * // => false
  11564. */
  11565. function isEqual(value, other) {
  11566. return baseIsEqual(value, other);
  11567. }
  11568. /**
  11569. * This method is like `_.isEqual` except that it accepts `customizer` which
  11570. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11571. * are handled by the method instead. The `customizer` is invoked with up to
  11572. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  11573. *
  11574. * @static
  11575. * @memberOf _
  11576. * @since 4.0.0
  11577. * @category Lang
  11578. * @param {*} value The value to compare.
  11579. * @param {*} other The other value to compare.
  11580. * @param {Function} [customizer] The function to customize comparisons.
  11581. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  11582. * @example
  11583. *
  11584. * function isGreeting(value) {
  11585. * return /^h(?:i|ello)$/.test(value);
  11586. * }
  11587. *
  11588. * function customizer(objValue, othValue) {
  11589. * if (isGreeting(objValue) && isGreeting(othValue)) {
  11590. * return true;
  11591. * }
  11592. * }
  11593. *
  11594. * var array = ['hello', 'goodbye'];
  11595. * var other = ['hi', 'goodbye'];
  11596. *
  11597. * _.isEqualWith(array, other, customizer);
  11598. * // => true
  11599. */
  11600. function isEqualWith(value, other, customizer) {
  11601. customizer = typeof customizer === 'function' ? customizer : undefined;
  11602. var result = customizer ? customizer(value, other) : undefined;
  11603. return result === undefined
  11604. ? baseIsEqual(value, other, undefined, customizer)
  11605. : !!result;
  11606. }
  11607. /**
  11608. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  11609. * `SyntaxError`, `TypeError`, or `URIError` object.
  11610. *
  11611. * @static
  11612. * @memberOf _
  11613. * @since 3.0.0
  11614. * @category Lang
  11615. * @param {*} value The value to check.
  11616. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  11617. * @example
  11618. *
  11619. * _.isError(new Error);
  11620. * // => true
  11621. *
  11622. * _.isError(Error);
  11623. * // => false
  11624. */
  11625. function isError(value) {
  11626. if (!isObjectLike(value)) {
  11627. return false;
  11628. }
  11629. var tag = baseGetTag(value);
  11630. return (
  11631. tag == errorTag ||
  11632. tag == domExcTag ||
  11633. (typeof value.message === 'string' &&
  11634. typeof value.name === 'string' &&
  11635. !isPlainObject(value))
  11636. );
  11637. }
  11638. /**
  11639. * Checks if `value` is a finite primitive number.
  11640. *
  11641. * **Note:** This method is based on
  11642. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  11643. *
  11644. * @static
  11645. * @memberOf _
  11646. * @since 0.1.0
  11647. * @category Lang
  11648. * @param {*} value The value to check.
  11649. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  11650. * @example
  11651. *
  11652. * _.isFinite(3);
  11653. * // => true
  11654. *
  11655. * _.isFinite(Number.MIN_VALUE);
  11656. * // => true
  11657. *
  11658. * _.isFinite(Infinity);
  11659. * // => false
  11660. *
  11661. * _.isFinite('3');
  11662. * // => false
  11663. */
  11664. function isFinite(value) {
  11665. return typeof value === 'number' && nativeIsFinite(value);
  11666. }
  11667. /**
  11668. * Checks if `value` is classified as a `Function` object.
  11669. *
  11670. * @static
  11671. * @memberOf _
  11672. * @since 0.1.0
  11673. * @category Lang
  11674. * @param {*} value The value to check.
  11675. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  11676. * @example
  11677. *
  11678. * _.isFunction(_);
  11679. * // => true
  11680. *
  11681. * _.isFunction(/abc/);
  11682. * // => false
  11683. */
  11684. function isFunction(value) {
  11685. if (!isObject(value)) {
  11686. return false;
  11687. }
  11688. // The use of `Object#toString` avoids issues with the `typeof` operator
  11689. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  11690. var tag = baseGetTag(value);
  11691. return (
  11692. tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag
  11693. );
  11694. }
  11695. /**
  11696. * Checks if `value` is an integer.
  11697. *
  11698. * **Note:** This method is based on
  11699. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  11700. *
  11701. * @static
  11702. * @memberOf _
  11703. * @since 4.0.0
  11704. * @category Lang
  11705. * @param {*} value The value to check.
  11706. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  11707. * @example
  11708. *
  11709. * _.isInteger(3);
  11710. * // => true
  11711. *
  11712. * _.isInteger(Number.MIN_VALUE);
  11713. * // => false
  11714. *
  11715. * _.isInteger(Infinity);
  11716. * // => false
  11717. *
  11718. * _.isInteger('3');
  11719. * // => false
  11720. */
  11721. function isInteger(value) {
  11722. return typeof value === 'number' && value == toInteger(value);
  11723. }
  11724. /**
  11725. * Checks if `value` is a valid array-like length.
  11726. *
  11727. * **Note:** This method is loosely based on
  11728. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11729. *
  11730. * @static
  11731. * @memberOf _
  11732. * @since 4.0.0
  11733. * @category Lang
  11734. * @param {*} value The value to check.
  11735. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  11736. * @example
  11737. *
  11738. * _.isLength(3);
  11739. * // => true
  11740. *
  11741. * _.isLength(Number.MIN_VALUE);
  11742. * // => false
  11743. *
  11744. * _.isLength(Infinity);
  11745. * // => false
  11746. *
  11747. * _.isLength('3');
  11748. * // => false
  11749. */
  11750. function isLength(value) {
  11751. return (
  11752. typeof value === 'number' &&
  11753. value > -1 &&
  11754. value % 1 == 0 &&
  11755. value <= MAX_SAFE_INTEGER
  11756. );
  11757. }
  11758. /**
  11759. * Checks if `value` is the
  11760. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  11761. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11762. *
  11763. * @static
  11764. * @memberOf _
  11765. * @since 0.1.0
  11766. * @category Lang
  11767. * @param {*} value The value to check.
  11768. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11769. * @example
  11770. *
  11771. * _.isObject({});
  11772. * // => true
  11773. *
  11774. * _.isObject([1, 2, 3]);
  11775. * // => true
  11776. *
  11777. * _.isObject(_.noop);
  11778. * // => true
  11779. *
  11780. * _.isObject(null);
  11781. * // => false
  11782. */
  11783. function isObject(value) {
  11784. var type = typeof value;
  11785. return value != null && (type == 'object' || type == 'function');
  11786. }
  11787. /**
  11788. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11789. * and has a `typeof` result of "object".
  11790. *
  11791. * @static
  11792. * @memberOf _
  11793. * @since 4.0.0
  11794. * @category Lang
  11795. * @param {*} value The value to check.
  11796. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11797. * @example
  11798. *
  11799. * _.isObjectLike({});
  11800. * // => true
  11801. *
  11802. * _.isObjectLike([1, 2, 3]);
  11803. * // => true
  11804. *
  11805. * _.isObjectLike(_.noop);
  11806. * // => false
  11807. *
  11808. * _.isObjectLike(null);
  11809. * // => false
  11810. */
  11811. function isObjectLike(value) {
  11812. return value != null && typeof value === 'object';
  11813. }
  11814. /**
  11815. * Checks if `value` is classified as a `Map` object.
  11816. *
  11817. * @static
  11818. * @memberOf _
  11819. * @since 4.3.0
  11820. * @category Lang
  11821. * @param {*} value The value to check.
  11822. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11823. * @example
  11824. *
  11825. * _.isMap(new Map);
  11826. * // => true
  11827. *
  11828. * _.isMap(new WeakMap);
  11829. * // => false
  11830. */
  11831. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11832. /**
  11833. * Performs a partial deep comparison between `object` and `source` to
  11834. * determine if `object` contains equivalent property values.
  11835. *
  11836. * **Note:** This method is equivalent to `_.matches` when `source` is
  11837. * partially applied.
  11838. *
  11839. * Partial comparisons will match empty array and empty object `source`
  11840. * values against any array or object value, respectively. See `_.isEqual`
  11841. * for a list of supported value comparisons.
  11842. *
  11843. * @static
  11844. * @memberOf _
  11845. * @since 3.0.0
  11846. * @category Lang
  11847. * @param {Object} object The object to inspect.
  11848. * @param {Object} source The object of property values to match.
  11849. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11850. * @example
  11851. *
  11852. * var object = { 'a': 1, 'b': 2 };
  11853. *
  11854. * _.isMatch(object, { 'b': 2 });
  11855. * // => true
  11856. *
  11857. * _.isMatch(object, { 'b': 1 });
  11858. * // => false
  11859. */
  11860. function isMatch(object, source) {
  11861. return (
  11862. object === source || baseIsMatch(object, source, getMatchData(source))
  11863. );
  11864. }
  11865. /**
  11866. * This method is like `_.isMatch` except that it accepts `customizer` which
  11867. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11868. * are handled by the method instead. The `customizer` is invoked with five
  11869. * arguments: (objValue, srcValue, index|key, object, source).
  11870. *
  11871. * @static
  11872. * @memberOf _
  11873. * @since 4.0.0
  11874. * @category Lang
  11875. * @param {Object} object The object to inspect.
  11876. * @param {Object} source The object of property values to match.
  11877. * @param {Function} [customizer] The function to customize comparisons.
  11878. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11879. * @example
  11880. *
  11881. * function isGreeting(value) {
  11882. * return /^h(?:i|ello)$/.test(value);
  11883. * }
  11884. *
  11885. * function customizer(objValue, srcValue) {
  11886. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11887. * return true;
  11888. * }
  11889. * }
  11890. *
  11891. * var object = { 'greeting': 'hello' };
  11892. * var source = { 'greeting': 'hi' };
  11893. *
  11894. * _.isMatchWith(object, source, customizer);
  11895. * // => true
  11896. */
  11897. function isMatchWith(object, source, customizer) {
  11898. customizer = typeof customizer === 'function' ? customizer : undefined;
  11899. return baseIsMatch(object, source, getMatchData(source), customizer);
  11900. }
  11901. /**
  11902. * Checks if `value` is `NaN`.
  11903. *
  11904. * **Note:** This method is based on
  11905. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11906. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11907. * `undefined` and other non-number values.
  11908. *
  11909. * @static
  11910. * @memberOf _
  11911. * @since 0.1.0
  11912. * @category Lang
  11913. * @param {*} value The value to check.
  11914. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11915. * @example
  11916. *
  11917. * _.isNaN(NaN);
  11918. * // => true
  11919. *
  11920. * _.isNaN(new Number(NaN));
  11921. * // => true
  11922. *
  11923. * isNaN(undefined);
  11924. * // => true
  11925. *
  11926. * _.isNaN(undefined);
  11927. * // => false
  11928. */
  11929. function isNaN(value) {
  11930. // An `NaN` primitive is the only value that is not equal to itself.
  11931. // Perform the `toStringTag` check first to avoid errors with some
  11932. // ActiveX objects in IE.
  11933. return isNumber(value) && value != +value;
  11934. }
  11935. /**
  11936. * Checks if `value` is a pristine native function.
  11937. *
  11938. * **Note:** This method can't reliably detect native functions in the presence
  11939. * of the core-js package because core-js circumvents this kind of detection.
  11940. * Despite multiple requests, the core-js maintainer has made it clear: any
  11941. * attempt to fix the detection will be obstructed. As a result, we're left
  11942. * with little choice but to throw an error. Unfortunately, this also affects
  11943. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11944. * which rely on core-js.
  11945. *
  11946. * @static
  11947. * @memberOf _
  11948. * @since 3.0.0
  11949. * @category Lang
  11950. * @param {*} value The value to check.
  11951. * @returns {boolean} Returns `true` if `value` is a native function,
  11952. * else `false`.
  11953. * @example
  11954. *
  11955. * _.isNative(Array.prototype.push);
  11956. * // => true
  11957. *
  11958. * _.isNative(_);
  11959. * // => false
  11960. */
  11961. function isNative(value) {
  11962. if (isMaskable(value)) {
  11963. throw new Error(CORE_ERROR_TEXT);
  11964. }
  11965. return baseIsNative(value);
  11966. }
  11967. /**
  11968. * Checks if `value` is `null`.
  11969. *
  11970. * @static
  11971. * @memberOf _
  11972. * @since 0.1.0
  11973. * @category Lang
  11974. * @param {*} value The value to check.
  11975. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11976. * @example
  11977. *
  11978. * _.isNull(null);
  11979. * // => true
  11980. *
  11981. * _.isNull(void 0);
  11982. * // => false
  11983. */
  11984. function isNull(value) {
  11985. return value === null;
  11986. }
  11987. /**
  11988. * Checks if `value` is `null` or `undefined`.
  11989. *
  11990. * @static
  11991. * @memberOf _
  11992. * @since 4.0.0
  11993. * @category Lang
  11994. * @param {*} value The value to check.
  11995. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11996. * @example
  11997. *
  11998. * _.isNil(null);
  11999. * // => true
  12000. *
  12001. * _.isNil(void 0);
  12002. * // => true
  12003. *
  12004. * _.isNil(NaN);
  12005. * // => false
  12006. */
  12007. function isNil(value) {
  12008. return value == null;
  12009. }
  12010. /**
  12011. * Checks if `value` is classified as a `Number` primitive or object.
  12012. *
  12013. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  12014. * classified as numbers, use the `_.isFinite` method.
  12015. *
  12016. * @static
  12017. * @memberOf _
  12018. * @since 0.1.0
  12019. * @category Lang
  12020. * @param {*} value The value to check.
  12021. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  12022. * @example
  12023. *
  12024. * _.isNumber(3);
  12025. * // => true
  12026. *
  12027. * _.isNumber(Number.MIN_VALUE);
  12028. * // => true
  12029. *
  12030. * _.isNumber(Infinity);
  12031. * // => true
  12032. *
  12033. * _.isNumber('3');
  12034. * // => false
  12035. */
  12036. function isNumber(value) {
  12037. return (
  12038. typeof value === 'number' ||
  12039. (isObjectLike(value) && baseGetTag(value) == numberTag)
  12040. );
  12041. }
  12042. /**
  12043. * Checks if `value` is a plain object, that is, an object created by the
  12044. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  12045. *
  12046. * @static
  12047. * @memberOf _
  12048. * @since 0.8.0
  12049. * @category Lang
  12050. * @param {*} value The value to check.
  12051. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  12052. * @example
  12053. *
  12054. * function Foo() {
  12055. * this.a = 1;
  12056. * }
  12057. *
  12058. * _.isPlainObject(new Foo);
  12059. * // => false
  12060. *
  12061. * _.isPlainObject([1, 2, 3]);
  12062. * // => false
  12063. *
  12064. * _.isPlainObject({ 'x': 0, 'y': 0 });
  12065. * // => true
  12066. *
  12067. * _.isPlainObject(Object.create(null));
  12068. * // => true
  12069. */
  12070. function isPlainObject(value) {
  12071. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  12072. return false;
  12073. }
  12074. var proto = getPrototype(value);
  12075. if (proto === null) {
  12076. return true;
  12077. }
  12078. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  12079. return (
  12080. typeof Ctor === 'function' &&
  12081. Ctor instanceof Ctor &&
  12082. funcToString.call(Ctor) == objectCtorString
  12083. );
  12084. }
  12085. /**
  12086. * Checks if `value` is classified as a `RegExp` object.
  12087. *
  12088. * @static
  12089. * @memberOf _
  12090. * @since 0.1.0
  12091. * @category Lang
  12092. * @param {*} value The value to check.
  12093. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  12094. * @example
  12095. *
  12096. * _.isRegExp(/abc/);
  12097. * // => true
  12098. *
  12099. * _.isRegExp('/abc/');
  12100. * // => false
  12101. */
  12102. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  12103. /**
  12104. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  12105. * double precision number which isn't the result of a rounded unsafe integer.
  12106. *
  12107. * **Note:** This method is based on
  12108. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  12109. *
  12110. * @static
  12111. * @memberOf _
  12112. * @since 4.0.0
  12113. * @category Lang
  12114. * @param {*} value The value to check.
  12115. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  12116. * @example
  12117. *
  12118. * _.isSafeInteger(3);
  12119. * // => true
  12120. *
  12121. * _.isSafeInteger(Number.MIN_VALUE);
  12122. * // => false
  12123. *
  12124. * _.isSafeInteger(Infinity);
  12125. * // => false
  12126. *
  12127. * _.isSafeInteger('3');
  12128. * // => false
  12129. */
  12130. function isSafeInteger(value) {
  12131. return (
  12132. isInteger(value) &&
  12133. value >= -MAX_SAFE_INTEGER &&
  12134. value <= MAX_SAFE_INTEGER
  12135. );
  12136. }
  12137. /**
  12138. * Checks if `value` is classified as a `Set` object.
  12139. *
  12140. * @static
  12141. * @memberOf _
  12142. * @since 4.3.0
  12143. * @category Lang
  12144. * @param {*} value The value to check.
  12145. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  12146. * @example
  12147. *
  12148. * _.isSet(new Set);
  12149. * // => true
  12150. *
  12151. * _.isSet(new WeakSet);
  12152. * // => false
  12153. */
  12154. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  12155. /**
  12156. * Checks if `value` is classified as a `String` primitive or object.
  12157. *
  12158. * @static
  12159. * @since 0.1.0
  12160. * @memberOf _
  12161. * @category Lang
  12162. * @param {*} value The value to check.
  12163. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  12164. * @example
  12165. *
  12166. * _.isString('abc');
  12167. * // => true
  12168. *
  12169. * _.isString(1);
  12170. * // => false
  12171. */
  12172. function isString(value) {
  12173. return (
  12174. typeof value === 'string' ||
  12175. (!isArray(value) &&
  12176. isObjectLike(value) &&
  12177. baseGetTag(value) == stringTag)
  12178. );
  12179. }
  12180. /**
  12181. * Checks if `value` is classified as a `Symbol` primitive or object.
  12182. *
  12183. * @static
  12184. * @memberOf _
  12185. * @since 4.0.0
  12186. * @category Lang
  12187. * @param {*} value The value to check.
  12188. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  12189. * @example
  12190. *
  12191. * _.isSymbol(Symbol.iterator);
  12192. * // => true
  12193. *
  12194. * _.isSymbol('abc');
  12195. * // => false
  12196. */
  12197. function isSymbol(value) {
  12198. return (
  12199. typeof value === 'symbol' ||
  12200. (isObjectLike(value) && baseGetTag(value) == symbolTag)
  12201. );
  12202. }
  12203. /**
  12204. * Checks if `value` is classified as a typed array.
  12205. *
  12206. * @static
  12207. * @memberOf _
  12208. * @since 3.0.0
  12209. * @category Lang
  12210. * @param {*} value The value to check.
  12211. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  12212. * @example
  12213. *
  12214. * _.isTypedArray(new Uint8Array);
  12215. * // => true
  12216. *
  12217. * _.isTypedArray([]);
  12218. * // => false
  12219. */
  12220. var isTypedArray = nodeIsTypedArray
  12221. ? baseUnary(nodeIsTypedArray)
  12222. : baseIsTypedArray;
  12223. /**
  12224. * Checks if `value` is `undefined`.
  12225. *
  12226. * @static
  12227. * @since 0.1.0
  12228. * @memberOf _
  12229. * @category Lang
  12230. * @param {*} value The value to check.
  12231. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  12232. * @example
  12233. *
  12234. * _.isUndefined(void 0);
  12235. * // => true
  12236. *
  12237. * _.isUndefined(null);
  12238. * // => false
  12239. */
  12240. function isUndefined(value) {
  12241. return value === undefined;
  12242. }
  12243. /**
  12244. * Checks if `value` is classified as a `WeakMap` object.
  12245. *
  12246. * @static
  12247. * @memberOf _
  12248. * @since 4.3.0
  12249. * @category Lang
  12250. * @param {*} value The value to check.
  12251. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  12252. * @example
  12253. *
  12254. * _.isWeakMap(new WeakMap);
  12255. * // => true
  12256. *
  12257. * _.isWeakMap(new Map);
  12258. * // => false
  12259. */
  12260. function isWeakMap(value) {
  12261. return isObjectLike(value) && getTag(value) == weakMapTag;
  12262. }
  12263. /**
  12264. * Checks if `value` is classified as a `WeakSet` object.
  12265. *
  12266. * @static
  12267. * @memberOf _
  12268. * @since 4.3.0
  12269. * @category Lang
  12270. * @param {*} value The value to check.
  12271. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  12272. * @example
  12273. *
  12274. * _.isWeakSet(new WeakSet);
  12275. * // => true
  12276. *
  12277. * _.isWeakSet(new Set);
  12278. * // => false
  12279. */
  12280. function isWeakSet(value) {
  12281. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  12282. }
  12283. /**
  12284. * Checks if `value` is less than `other`.
  12285. *
  12286. * @static
  12287. * @memberOf _
  12288. * @since 3.9.0
  12289. * @category Lang
  12290. * @param {*} value The value to compare.
  12291. * @param {*} other The other value to compare.
  12292. * @returns {boolean} Returns `true` if `value` is less than `other`,
  12293. * else `false`.
  12294. * @see _.gt
  12295. * @example
  12296. *
  12297. * _.lt(1, 3);
  12298. * // => true
  12299. *
  12300. * _.lt(3, 3);
  12301. * // => false
  12302. *
  12303. * _.lt(3, 1);
  12304. * // => false
  12305. */
  12306. var lt = createRelationalOperation(baseLt);
  12307. /**
  12308. * Checks if `value` is less than or equal to `other`.
  12309. *
  12310. * @static
  12311. * @memberOf _
  12312. * @since 3.9.0
  12313. * @category Lang
  12314. * @param {*} value The value to compare.
  12315. * @param {*} other The other value to compare.
  12316. * @returns {boolean} Returns `true` if `value` is less than or equal to
  12317. * `other`, else `false`.
  12318. * @see _.gte
  12319. * @example
  12320. *
  12321. * _.lte(1, 3);
  12322. * // => true
  12323. *
  12324. * _.lte(3, 3);
  12325. * // => true
  12326. *
  12327. * _.lte(3, 1);
  12328. * // => false
  12329. */
  12330. var lte = createRelationalOperation(function(value, other) {
  12331. return value <= other;
  12332. });
  12333. /**
  12334. * Converts `value` to an array.
  12335. *
  12336. * @static
  12337. * @since 0.1.0
  12338. * @memberOf _
  12339. * @category Lang
  12340. * @param {*} value The value to convert.
  12341. * @returns {Array} Returns the converted array.
  12342. * @example
  12343. *
  12344. * _.toArray({ 'a': 1, 'b': 2 });
  12345. * // => [1, 2]
  12346. *
  12347. * _.toArray('abc');
  12348. * // => ['a', 'b', 'c']
  12349. *
  12350. * _.toArray(1);
  12351. * // => []
  12352. *
  12353. * _.toArray(null);
  12354. * // => []
  12355. */
  12356. function toArray(value) {
  12357. if (!value) {
  12358. return [];
  12359. }
  12360. if (isArrayLike(value)) {
  12361. return isString(value) ? stringToArray(value) : copyArray(value);
  12362. }
  12363. if (symIterator && value[symIterator]) {
  12364. return iteratorToArray(value[symIterator]());
  12365. }
  12366. var tag = getTag(value),
  12367. func = tag == mapTag ? mapToArray : tag == setTag ? setToArray : values;
  12368. return func(value);
  12369. }
  12370. /**
  12371. * Converts `value` to a finite number.
  12372. *
  12373. * @static
  12374. * @memberOf _
  12375. * @since 4.12.0
  12376. * @category Lang
  12377. * @param {*} value The value to convert.
  12378. * @returns {number} Returns the converted number.
  12379. * @example
  12380. *
  12381. * _.toFinite(3.2);
  12382. * // => 3.2
  12383. *
  12384. * _.toFinite(Number.MIN_VALUE);
  12385. * // => 5e-324
  12386. *
  12387. * _.toFinite(Infinity);
  12388. * // => 1.7976931348623157e+308
  12389. *
  12390. * _.toFinite('3.2');
  12391. * // => 3.2
  12392. */
  12393. function toFinite(value) {
  12394. if (!value) {
  12395. return value === 0 ? value : 0;
  12396. }
  12397. value = toNumber(value);
  12398. if (value === INFINITY || value === -INFINITY) {
  12399. var sign = value < 0 ? -1 : 1;
  12400. return sign * MAX_INTEGER;
  12401. }
  12402. return value === value ? value : 0;
  12403. }
  12404. /**
  12405. * Converts `value` to an integer.
  12406. *
  12407. * **Note:** This method is loosely based on
  12408. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  12409. *
  12410. * @static
  12411. * @memberOf _
  12412. * @since 4.0.0
  12413. * @category Lang
  12414. * @param {*} value The value to convert.
  12415. * @returns {number} Returns the converted integer.
  12416. * @example
  12417. *
  12418. * _.toInteger(3.2);
  12419. * // => 3
  12420. *
  12421. * _.toInteger(Number.MIN_VALUE);
  12422. * // => 0
  12423. *
  12424. * _.toInteger(Infinity);
  12425. * // => 1.7976931348623157e+308
  12426. *
  12427. * _.toInteger('3.2');
  12428. * // => 3
  12429. */
  12430. function toInteger(value) {
  12431. var result = toFinite(value),
  12432. remainder = result % 1;
  12433. return result === result ? (remainder ? result - remainder : result) : 0;
  12434. }
  12435. /**
  12436. * Converts `value` to an integer suitable for use as the length of an
  12437. * array-like object.
  12438. *
  12439. * **Note:** This method is based on
  12440. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  12441. *
  12442. * @static
  12443. * @memberOf _
  12444. * @since 4.0.0
  12445. * @category Lang
  12446. * @param {*} value The value to convert.
  12447. * @returns {number} Returns the converted integer.
  12448. * @example
  12449. *
  12450. * _.toLength(3.2);
  12451. * // => 3
  12452. *
  12453. * _.toLength(Number.MIN_VALUE);
  12454. * // => 0
  12455. *
  12456. * _.toLength(Infinity);
  12457. * // => 4294967295
  12458. *
  12459. * _.toLength('3.2');
  12460. * // => 3
  12461. */
  12462. function toLength(value) {
  12463. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  12464. }
  12465. /**
  12466. * Converts `value` to a number.
  12467. *
  12468. * @static
  12469. * @memberOf _
  12470. * @since 4.0.0
  12471. * @category Lang
  12472. * @param {*} value The value to process.
  12473. * @returns {number} Returns the number.
  12474. * @example
  12475. *
  12476. * _.toNumber(3.2);
  12477. * // => 3.2
  12478. *
  12479. * _.toNumber(Number.MIN_VALUE);
  12480. * // => 5e-324
  12481. *
  12482. * _.toNumber(Infinity);
  12483. * // => Infinity
  12484. *
  12485. * _.toNumber('3.2');
  12486. * // => 3.2
  12487. */
  12488. function toNumber(value) {
  12489. if (typeof value === 'number') {
  12490. return value;
  12491. }
  12492. if (isSymbol(value)) {
  12493. return NAN;
  12494. }
  12495. if (isObject(value)) {
  12496. var other =
  12497. typeof value.valueOf === 'function' ? value.valueOf() : value;
  12498. value = isObject(other) ? other + '' : other;
  12499. }
  12500. if (typeof value !== 'string') {
  12501. return value === 0 ? value : +value;
  12502. }
  12503. value = value.replace(reTrim, '');
  12504. var isBinary = reIsBinary.test(value);
  12505. return isBinary || reIsOctal.test(value)
  12506. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  12507. : reIsBadHex.test(value)
  12508. ? NAN
  12509. : +value;
  12510. }
  12511. /**
  12512. * Converts `value` to a plain object flattening inherited enumerable string
  12513. * keyed properties of `value` to own properties of the plain object.
  12514. *
  12515. * @static
  12516. * @memberOf _
  12517. * @since 3.0.0
  12518. * @category Lang
  12519. * @param {*} value The value to convert.
  12520. * @returns {Object} Returns the converted plain object.
  12521. * @example
  12522. *
  12523. * function Foo() {
  12524. * this.b = 2;
  12525. * }
  12526. *
  12527. * Foo.prototype.c = 3;
  12528. *
  12529. * _.assign({ 'a': 1 }, new Foo);
  12530. * // => { 'a': 1, 'b': 2 }
  12531. *
  12532. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  12533. * // => { 'a': 1, 'b': 2, 'c': 3 }
  12534. */
  12535. function toPlainObject(value) {
  12536. return copyObject(value, keysIn(value));
  12537. }
  12538. /**
  12539. * Converts `value` to a safe integer. A safe integer can be compared and
  12540. * represented correctly.
  12541. *
  12542. * @static
  12543. * @memberOf _
  12544. * @since 4.0.0
  12545. * @category Lang
  12546. * @param {*} value The value to convert.
  12547. * @returns {number} Returns the converted integer.
  12548. * @example
  12549. *
  12550. * _.toSafeInteger(3.2);
  12551. * // => 3
  12552. *
  12553. * _.toSafeInteger(Number.MIN_VALUE);
  12554. * // => 0
  12555. *
  12556. * _.toSafeInteger(Infinity);
  12557. * // => 9007199254740991
  12558. *
  12559. * _.toSafeInteger('3.2');
  12560. * // => 3
  12561. */
  12562. function toSafeInteger(value) {
  12563. return value
  12564. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  12565. : value === 0
  12566. ? value
  12567. : 0;
  12568. }
  12569. /**
  12570. * Converts `value` to a string. An empty string is returned for `null`
  12571. * and `undefined` values. The sign of `-0` is preserved.
  12572. *
  12573. * @static
  12574. * @memberOf _
  12575. * @since 4.0.0
  12576. * @category Lang
  12577. * @param {*} value The value to convert.
  12578. * @returns {string} Returns the converted string.
  12579. * @example
  12580. *
  12581. * _.toString(null);
  12582. * // => ''
  12583. *
  12584. * _.toString(-0);
  12585. * // => '-0'
  12586. *
  12587. * _.toString([1, 2, 3]);
  12588. * // => '1,2,3'
  12589. */
  12590. function toString(value) {
  12591. return value == null ? '' : baseToString(value);
  12592. }
  12593. /* ------------------------------------------------------------------------*/
  12594. /**
  12595. * Assigns own enumerable string keyed properties of source objects to the
  12596. * destination object. Source objects are applied from left to right.
  12597. * Subsequent sources overwrite property assignments of previous sources.
  12598. *
  12599. * **Note:** This method mutates `object` and is loosely based on
  12600. * [`Object.assign`](https://mdn.io/Object/assign).
  12601. *
  12602. * @static
  12603. * @memberOf _
  12604. * @since 0.10.0
  12605. * @category Object
  12606. * @param {Object} object The destination object.
  12607. * @param {...Object} [sources] The source objects.
  12608. * @returns {Object} Returns `object`.
  12609. * @see _.assignIn
  12610. * @example
  12611. *
  12612. * function Foo() {
  12613. * this.a = 1;
  12614. * }
  12615. *
  12616. * function Bar() {
  12617. * this.c = 3;
  12618. * }
  12619. *
  12620. * Foo.prototype.b = 2;
  12621. * Bar.prototype.d = 4;
  12622. *
  12623. * _.assign({ 'a': 0 }, new Foo, new Bar);
  12624. * // => { 'a': 1, 'c': 3 }
  12625. */
  12626. var assign = createAssigner(function(object, source) {
  12627. if (isPrototype(source) || isArrayLike(source)) {
  12628. copyObject(source, keys(source), object);
  12629. return;
  12630. }
  12631. for (var key in source) {
  12632. if (hasOwnProperty.call(source, key)) {
  12633. assignValue(object, key, source[key]);
  12634. }
  12635. }
  12636. });
  12637. /**
  12638. * This method is like `_.assign` except that it iterates over own and
  12639. * inherited source properties.
  12640. *
  12641. * **Note:** This method mutates `object`.
  12642. *
  12643. * @static
  12644. * @memberOf _
  12645. * @since 4.0.0
  12646. * @alias extend
  12647. * @category Object
  12648. * @param {Object} object The destination object.
  12649. * @param {...Object} [sources] The source objects.
  12650. * @returns {Object} Returns `object`.
  12651. * @see _.assign
  12652. * @example
  12653. *
  12654. * function Foo() {
  12655. * this.a = 1;
  12656. * }
  12657. *
  12658. * function Bar() {
  12659. * this.c = 3;
  12660. * }
  12661. *
  12662. * Foo.prototype.b = 2;
  12663. * Bar.prototype.d = 4;
  12664. *
  12665. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  12666. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  12667. */
  12668. var assignIn = createAssigner(function(object, source) {
  12669. copyObject(source, keysIn(source), object);
  12670. });
  12671. /**
  12672. * This method is like `_.assignIn` except that it accepts `customizer`
  12673. * which is invoked to produce the assigned values. If `customizer` returns
  12674. * `undefined`, assignment is handled by the method instead. The `customizer`
  12675. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  12676. *
  12677. * **Note:** This method mutates `object`.
  12678. *
  12679. * @static
  12680. * @memberOf _
  12681. * @since 4.0.0
  12682. * @alias extendWith
  12683. * @category Object
  12684. * @param {Object} object The destination object.
  12685. * @param {...Object} sources The source objects.
  12686. * @param {Function} [customizer] The function to customize assigned values.
  12687. * @returns {Object} Returns `object`.
  12688. * @see _.assignWith
  12689. * @example
  12690. *
  12691. * function customizer(objValue, srcValue) {
  12692. * return _.isUndefined(objValue) ? srcValue : objValue;
  12693. * }
  12694. *
  12695. * var defaults = _.partialRight(_.assignInWith, customizer);
  12696. *
  12697. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12698. * // => { 'a': 1, 'b': 2 }
  12699. */
  12700. var assignInWith = createAssigner(function(
  12701. object,
  12702. source,
  12703. srcIndex,
  12704. customizer
  12705. ) {
  12706. copyObject(source, keysIn(source), object, customizer);
  12707. });
  12708. /**
  12709. * This method is like `_.assign` except that it accepts `customizer`
  12710. * which is invoked to produce the assigned values. If `customizer` returns
  12711. * `undefined`, assignment is handled by the method instead. The `customizer`
  12712. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  12713. *
  12714. * **Note:** This method mutates `object`.
  12715. *
  12716. * @static
  12717. * @memberOf _
  12718. * @since 4.0.0
  12719. * @category Object
  12720. * @param {Object} object The destination object.
  12721. * @param {...Object} sources The source objects.
  12722. * @param {Function} [customizer] The function to customize assigned values.
  12723. * @returns {Object} Returns `object`.
  12724. * @see _.assignInWith
  12725. * @example
  12726. *
  12727. * function customizer(objValue, srcValue) {
  12728. * return _.isUndefined(objValue) ? srcValue : objValue;
  12729. * }
  12730. *
  12731. * var defaults = _.partialRight(_.assignWith, customizer);
  12732. *
  12733. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12734. * // => { 'a': 1, 'b': 2 }
  12735. */
  12736. var assignWith = createAssigner(function(
  12737. object,
  12738. source,
  12739. srcIndex,
  12740. customizer
  12741. ) {
  12742. copyObject(source, keys(source), object, customizer);
  12743. });
  12744. /**
  12745. * Creates an array of values corresponding to `paths` of `object`.
  12746. *
  12747. * @static
  12748. * @memberOf _
  12749. * @since 1.0.0
  12750. * @category Object
  12751. * @param {Object} object The object to iterate over.
  12752. * @param {...(string|string[])} [paths] The property paths to pick.
  12753. * @returns {Array} Returns the picked values.
  12754. * @example
  12755. *
  12756. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  12757. *
  12758. * _.at(object, ['a[0].b.c', 'a[1]']);
  12759. * // => [3, 4]
  12760. */
  12761. var at = flatRest(baseAt);
  12762. /**
  12763. * Creates an object that inherits from the `prototype` object. If a
  12764. * `properties` object is given, its own enumerable string keyed properties
  12765. * are assigned to the created object.
  12766. *
  12767. * @static
  12768. * @memberOf _
  12769. * @since 2.3.0
  12770. * @category Object
  12771. * @param {Object} prototype The object to inherit from.
  12772. * @param {Object} [properties] The properties to assign to the object.
  12773. * @returns {Object} Returns the new object.
  12774. * @example
  12775. *
  12776. * function Shape() {
  12777. * this.x = 0;
  12778. * this.y = 0;
  12779. * }
  12780. *
  12781. * function Circle() {
  12782. * Shape.call(this);
  12783. * }
  12784. *
  12785. * Circle.prototype = _.create(Shape.prototype, {
  12786. * 'constructor': Circle
  12787. * });
  12788. *
  12789. * var circle = new Circle;
  12790. * circle instanceof Circle;
  12791. * // => true
  12792. *
  12793. * circle instanceof Shape;
  12794. * // => true
  12795. */
  12796. function create(prototype, properties) {
  12797. var result = baseCreate(prototype);
  12798. return properties == null ? result : baseAssign(result, properties);
  12799. }
  12800. /**
  12801. * Assigns own and inherited enumerable string keyed properties of source
  12802. * objects to the destination object for all destination properties that
  12803. * resolve to `undefined`. Source objects are applied from left to right.
  12804. * Once a property is set, additional values of the same property are ignored.
  12805. *
  12806. * **Note:** This method mutates `object`.
  12807. *
  12808. * @static
  12809. * @since 0.1.0
  12810. * @memberOf _
  12811. * @category Object
  12812. * @param {Object} object The destination object.
  12813. * @param {...Object} [sources] The source objects.
  12814. * @returns {Object} Returns `object`.
  12815. * @see _.defaultsDeep
  12816. * @example
  12817. *
  12818. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12819. * // => { 'a': 1, 'b': 2 }
  12820. */
  12821. var defaults = baseRest(function(object, sources) {
  12822. object = Object(object);
  12823. var index = -1;
  12824. var length = sources.length;
  12825. var guard = length > 2 ? sources[2] : undefined;
  12826. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  12827. length = 1;
  12828. }
  12829. while (++index < length) {
  12830. var source = sources[index];
  12831. var props = keysIn(source);
  12832. var propsIndex = -1;
  12833. var propsLength = props.length;
  12834. while (++propsIndex < propsLength) {
  12835. var key = props[propsIndex];
  12836. var value = object[key];
  12837. if (
  12838. value === undefined ||
  12839. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))
  12840. ) {
  12841. object[key] = source[key];
  12842. }
  12843. }
  12844. }
  12845. return object;
  12846. });
  12847. /**
  12848. * This method is like `_.defaults` except that it recursively assigns
  12849. * default properties.
  12850. *
  12851. * **Note:** This method mutates `object`.
  12852. *
  12853. * @static
  12854. * @memberOf _
  12855. * @since 3.10.0
  12856. * @category Object
  12857. * @param {Object} object The destination object.
  12858. * @param {...Object} [sources] The source objects.
  12859. * @returns {Object} Returns `object`.
  12860. * @see _.defaults
  12861. * @example
  12862. *
  12863. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12864. * // => { 'a': { 'b': 2, 'c': 3 } }
  12865. */
  12866. var defaultsDeep = baseRest(function(args) {
  12867. args.push(undefined, customDefaultsMerge);
  12868. return apply(mergeWith, undefined, args);
  12869. });
  12870. /**
  12871. * This method is like `_.find` except that it returns the key of the first
  12872. * element `predicate` returns truthy for instead of the element itself.
  12873. *
  12874. * @static
  12875. * @memberOf _
  12876. * @since 1.1.0
  12877. * @category Object
  12878. * @param {Object} object The object to inspect.
  12879. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12880. * @returns {string|undefined} Returns the key of the matched element,
  12881. * else `undefined`.
  12882. * @example
  12883. *
  12884. * var users = {
  12885. * 'barney': { 'age': 36, 'active': true },
  12886. * 'fred': { 'age': 40, 'active': false },
  12887. * 'pebbles': { 'age': 1, 'active': true }
  12888. * };
  12889. *
  12890. * _.findKey(users, function(o) { return o.age < 40; });
  12891. * // => 'barney' (iteration order is not guaranteed)
  12892. *
  12893. * // The `_.matches` iteratee shorthand.
  12894. * _.findKey(users, { 'age': 1, 'active': true });
  12895. * // => 'pebbles'
  12896. *
  12897. * // The `_.matchesProperty` iteratee shorthand.
  12898. * _.findKey(users, ['active', false]);
  12899. * // => 'fred'
  12900. *
  12901. * // The `_.property` iteratee shorthand.
  12902. * _.findKey(users, 'active');
  12903. * // => 'barney'
  12904. */
  12905. function findKey(object, predicate) {
  12906. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12907. }
  12908. /**
  12909. * This method is like `_.findKey` except that it iterates over elements of
  12910. * a collection in the opposite order.
  12911. *
  12912. * @static
  12913. * @memberOf _
  12914. * @since 2.0.0
  12915. * @category Object
  12916. * @param {Object} object The object to inspect.
  12917. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12918. * @returns {string|undefined} Returns the key of the matched element,
  12919. * else `undefined`.
  12920. * @example
  12921. *
  12922. * var users = {
  12923. * 'barney': { 'age': 36, 'active': true },
  12924. * 'fred': { 'age': 40, 'active': false },
  12925. * 'pebbles': { 'age': 1, 'active': true }
  12926. * };
  12927. *
  12928. * _.findLastKey(users, function(o) { return o.age < 40; });
  12929. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12930. *
  12931. * // The `_.matches` iteratee shorthand.
  12932. * _.findLastKey(users, { 'age': 36, 'active': true });
  12933. * // => 'barney'
  12934. *
  12935. * // The `_.matchesProperty` iteratee shorthand.
  12936. * _.findLastKey(users, ['active', false]);
  12937. * // => 'fred'
  12938. *
  12939. * // The `_.property` iteratee shorthand.
  12940. * _.findLastKey(users, 'active');
  12941. * // => 'pebbles'
  12942. */
  12943. function findLastKey(object, predicate) {
  12944. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12945. }
  12946. /**
  12947. * Iterates over own and inherited enumerable string keyed properties of an
  12948. * object and invokes `iteratee` for each property. The iteratee is invoked
  12949. * with three arguments: (value, key, object). Iteratee functions may exit
  12950. * iteration early by explicitly returning `false`.
  12951. *
  12952. * @static
  12953. * @memberOf _
  12954. * @since 0.3.0
  12955. * @category Object
  12956. * @param {Object} object The object to iterate over.
  12957. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12958. * @returns {Object} Returns `object`.
  12959. * @see _.forInRight
  12960. * @example
  12961. *
  12962. * function Foo() {
  12963. * this.a = 1;
  12964. * this.b = 2;
  12965. * }
  12966. *
  12967. * Foo.prototype.c = 3;
  12968. *
  12969. * _.forIn(new Foo, function(value, key) {
  12970. * console.log(key);
  12971. * });
  12972. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12973. */
  12974. function forIn(object, iteratee) {
  12975. return object == null
  12976. ? object
  12977. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12978. }
  12979. /**
  12980. * This method is like `_.forIn` except that it iterates over properties of
  12981. * `object` in the opposite order.
  12982. *
  12983. * @static
  12984. * @memberOf _
  12985. * @since 2.0.0
  12986. * @category Object
  12987. * @param {Object} object The object to iterate over.
  12988. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12989. * @returns {Object} Returns `object`.
  12990. * @see _.forIn
  12991. * @example
  12992. *
  12993. * function Foo() {
  12994. * this.a = 1;
  12995. * this.b = 2;
  12996. * }
  12997. *
  12998. * Foo.prototype.c = 3;
  12999. *
  13000. * _.forInRight(new Foo, function(value, key) {
  13001. * console.log(key);
  13002. * });
  13003. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  13004. */
  13005. function forInRight(object, iteratee) {
  13006. return object == null
  13007. ? object
  13008. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  13009. }
  13010. /**
  13011. * Iterates over own enumerable string keyed properties of an object and
  13012. * invokes `iteratee` for each property. The iteratee is invoked with three
  13013. * arguments: (value, key, object). Iteratee functions may exit iteration
  13014. * early by explicitly returning `false`.
  13015. *
  13016. * @static
  13017. * @memberOf _
  13018. * @since 0.3.0
  13019. * @category Object
  13020. * @param {Object} object The object to iterate over.
  13021. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13022. * @returns {Object} Returns `object`.
  13023. * @see _.forOwnRight
  13024. * @example
  13025. *
  13026. * function Foo() {
  13027. * this.a = 1;
  13028. * this.b = 2;
  13029. * }
  13030. *
  13031. * Foo.prototype.c = 3;
  13032. *
  13033. * _.forOwn(new Foo, function(value, key) {
  13034. * console.log(key);
  13035. * });
  13036. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  13037. */
  13038. function forOwn(object, iteratee) {
  13039. return object && baseForOwn(object, getIteratee(iteratee, 3));
  13040. }
  13041. /**
  13042. * This method is like `_.forOwn` except that it iterates over properties of
  13043. * `object` in the opposite order.
  13044. *
  13045. * @static
  13046. * @memberOf _
  13047. * @since 2.0.0
  13048. * @category Object
  13049. * @param {Object} object The object to iterate over.
  13050. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13051. * @returns {Object} Returns `object`.
  13052. * @see _.forOwn
  13053. * @example
  13054. *
  13055. * function Foo() {
  13056. * this.a = 1;
  13057. * this.b = 2;
  13058. * }
  13059. *
  13060. * Foo.prototype.c = 3;
  13061. *
  13062. * _.forOwnRight(new Foo, function(value, key) {
  13063. * console.log(key);
  13064. * });
  13065. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  13066. */
  13067. function forOwnRight(object, iteratee) {
  13068. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  13069. }
  13070. /**
  13071. * Creates an array of function property names from own enumerable properties
  13072. * of `object`.
  13073. *
  13074. * @static
  13075. * @since 0.1.0
  13076. * @memberOf _
  13077. * @category Object
  13078. * @param {Object} object The object to inspect.
  13079. * @returns {Array} Returns the function names.
  13080. * @see _.functionsIn
  13081. * @example
  13082. *
  13083. * function Foo() {
  13084. * this.a = _.constant('a');
  13085. * this.b = _.constant('b');
  13086. * }
  13087. *
  13088. * Foo.prototype.c = _.constant('c');
  13089. *
  13090. * _.functions(new Foo);
  13091. * // => ['a', 'b']
  13092. */
  13093. function functions(object) {
  13094. return object == null ? [] : baseFunctions(object, keys(object));
  13095. }
  13096. /**
  13097. * Creates an array of function property names from own and inherited
  13098. * enumerable properties of `object`.
  13099. *
  13100. * @static
  13101. * @memberOf _
  13102. * @since 4.0.0
  13103. * @category Object
  13104. * @param {Object} object The object to inspect.
  13105. * @returns {Array} Returns the function names.
  13106. * @see _.functions
  13107. * @example
  13108. *
  13109. * function Foo() {
  13110. * this.a = _.constant('a');
  13111. * this.b = _.constant('b');
  13112. * }
  13113. *
  13114. * Foo.prototype.c = _.constant('c');
  13115. *
  13116. * _.functionsIn(new Foo);
  13117. * // => ['a', 'b', 'c']
  13118. */
  13119. function functionsIn(object) {
  13120. return object == null ? [] : baseFunctions(object, keysIn(object));
  13121. }
  13122. /**
  13123. * Gets the value at `path` of `object`. If the resolved value is
  13124. * `undefined`, the `defaultValue` is returned in its place.
  13125. *
  13126. * @static
  13127. * @memberOf _
  13128. * @since 3.7.0
  13129. * @category Object
  13130. * @param {Object} object The object to query.
  13131. * @param {Array|string} path The path of the property to get.
  13132. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  13133. * @returns {*} Returns the resolved value.
  13134. * @example
  13135. *
  13136. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13137. *
  13138. * _.get(object, 'a[0].b.c');
  13139. * // => 3
  13140. *
  13141. * _.get(object, ['a', '0', 'b', 'c']);
  13142. * // => 3
  13143. *
  13144. * _.get(object, 'a.b.c', 'default');
  13145. * // => 'default'
  13146. */
  13147. function get(object, path, defaultValue) {
  13148. var result = object == null ? undefined : baseGet(object, path);
  13149. return result === undefined ? defaultValue : result;
  13150. }
  13151. /**
  13152. * Checks if `path` is a direct property of `object`.
  13153. *
  13154. * @static
  13155. * @since 0.1.0
  13156. * @memberOf _
  13157. * @category Object
  13158. * @param {Object} object The object to query.
  13159. * @param {Array|string} path The path to check.
  13160. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13161. * @example
  13162. *
  13163. * var object = { 'a': { 'b': 2 } };
  13164. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  13165. *
  13166. * _.has(object, 'a');
  13167. * // => true
  13168. *
  13169. * _.has(object, 'a.b');
  13170. * // => true
  13171. *
  13172. * _.has(object, ['a', 'b']);
  13173. * // => true
  13174. *
  13175. * _.has(other, 'a');
  13176. * // => false
  13177. */
  13178. function has(object, path) {
  13179. return object != null && hasPath(object, path, baseHas);
  13180. }
  13181. /**
  13182. * Checks if `path` is a direct or inherited property of `object`.
  13183. *
  13184. * @static
  13185. * @memberOf _
  13186. * @since 4.0.0
  13187. * @category Object
  13188. * @param {Object} object The object to query.
  13189. * @param {Array|string} path The path to check.
  13190. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13191. * @example
  13192. *
  13193. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  13194. *
  13195. * _.hasIn(object, 'a');
  13196. * // => true
  13197. *
  13198. * _.hasIn(object, 'a.b');
  13199. * // => true
  13200. *
  13201. * _.hasIn(object, ['a', 'b']);
  13202. * // => true
  13203. *
  13204. * _.hasIn(object, 'b');
  13205. * // => false
  13206. */
  13207. function hasIn(object, path) {
  13208. return object != null && hasPath(object, path, baseHasIn);
  13209. }
  13210. /**
  13211. * Creates an object composed of the inverted keys and values of `object`.
  13212. * If `object` contains duplicate values, subsequent values overwrite
  13213. * property assignments of previous values.
  13214. *
  13215. * @static
  13216. * @memberOf _
  13217. * @since 0.7.0
  13218. * @category Object
  13219. * @param {Object} object The object to invert.
  13220. * @returns {Object} Returns the new inverted object.
  13221. * @example
  13222. *
  13223. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  13224. *
  13225. * _.invert(object);
  13226. * // => { '1': 'c', '2': 'b' }
  13227. */
  13228. var invert = createInverter(function(result, value, key) {
  13229. if (value != null && typeof value.toString !== 'function') {
  13230. value = nativeObjectToString.call(value);
  13231. }
  13232. result[value] = key;
  13233. }, constant(identity));
  13234. /**
  13235. * This method is like `_.invert` except that the inverted object is generated
  13236. * from the results of running each element of `object` thru `iteratee`. The
  13237. * corresponding inverted value of each inverted key is an array of keys
  13238. * responsible for generating the inverted value. The iteratee is invoked
  13239. * with one argument: (value).
  13240. *
  13241. * @static
  13242. * @memberOf _
  13243. * @since 4.1.0
  13244. * @category Object
  13245. * @param {Object} object The object to invert.
  13246. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  13247. * @returns {Object} Returns the new inverted object.
  13248. * @example
  13249. *
  13250. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  13251. *
  13252. * _.invertBy(object);
  13253. * // => { '1': ['a', 'c'], '2': ['b'] }
  13254. *
  13255. * _.invertBy(object, function(value) {
  13256. * return 'group' + value;
  13257. * });
  13258. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  13259. */
  13260. var invertBy = createInverter(function(result, value, key) {
  13261. if (value != null && typeof value.toString !== 'function') {
  13262. value = nativeObjectToString.call(value);
  13263. }
  13264. if (hasOwnProperty.call(result, value)) {
  13265. result[value].push(key);
  13266. } else {
  13267. result[value] = [key];
  13268. }
  13269. }, getIteratee);
  13270. /**
  13271. * Invokes the method at `path` of `object`.
  13272. *
  13273. * @static
  13274. * @memberOf _
  13275. * @since 4.0.0
  13276. * @category Object
  13277. * @param {Object} object The object to query.
  13278. * @param {Array|string} path The path of the method to invoke.
  13279. * @param {...*} [args] The arguments to invoke the method with.
  13280. * @returns {*} Returns the result of the invoked method.
  13281. * @example
  13282. *
  13283. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  13284. *
  13285. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  13286. * // => [2, 3]
  13287. */
  13288. var invoke = baseRest(baseInvoke);
  13289. /**
  13290. * Creates an array of the own enumerable property names of `object`.
  13291. *
  13292. * **Note:** Non-object values are coerced to objects. See the
  13293. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  13294. * for more details.
  13295. *
  13296. * @static
  13297. * @since 0.1.0
  13298. * @memberOf _
  13299. * @category Object
  13300. * @param {Object} object The object to query.
  13301. * @returns {Array} Returns the array of property names.
  13302. * @example
  13303. *
  13304. * function Foo() {
  13305. * this.a = 1;
  13306. * this.b = 2;
  13307. * }
  13308. *
  13309. * Foo.prototype.c = 3;
  13310. *
  13311. * _.keys(new Foo);
  13312. * // => ['a', 'b'] (iteration order is not guaranteed)
  13313. *
  13314. * _.keys('hi');
  13315. * // => ['0', '1']
  13316. */
  13317. function keys(object) {
  13318. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  13319. }
  13320. /**
  13321. * Creates an array of the own and inherited enumerable property names of `object`.
  13322. *
  13323. * **Note:** Non-object values are coerced to objects.
  13324. *
  13325. * @static
  13326. * @memberOf _
  13327. * @since 3.0.0
  13328. * @category Object
  13329. * @param {Object} object The object to query.
  13330. * @returns {Array} Returns the array of property names.
  13331. * @example
  13332. *
  13333. * function Foo() {
  13334. * this.a = 1;
  13335. * this.b = 2;
  13336. * }
  13337. *
  13338. * Foo.prototype.c = 3;
  13339. *
  13340. * _.keysIn(new Foo);
  13341. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  13342. */
  13343. function keysIn(object) {
  13344. return isArrayLike(object)
  13345. ? arrayLikeKeys(object, true)
  13346. : baseKeysIn(object);
  13347. }
  13348. /**
  13349. * The opposite of `_.mapValues`; this method creates an object with the
  13350. * same values as `object` and keys generated by running each own enumerable
  13351. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  13352. * with three arguments: (value, key, object).
  13353. *
  13354. * @static
  13355. * @memberOf _
  13356. * @since 3.8.0
  13357. * @category Object
  13358. * @param {Object} object The object to iterate over.
  13359. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13360. * @returns {Object} Returns the new mapped object.
  13361. * @see _.mapValues
  13362. * @example
  13363. *
  13364. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  13365. * return key + value;
  13366. * });
  13367. * // => { 'a1': 1, 'b2': 2 }
  13368. */
  13369. function mapKeys(object, iteratee) {
  13370. var result = {};
  13371. iteratee = getIteratee(iteratee, 3);
  13372. baseForOwn(object, function(value, key, object) {
  13373. baseAssignValue(result, iteratee(value, key, object), value);
  13374. });
  13375. return result;
  13376. }
  13377. /**
  13378. * Creates an object with the same keys as `object` and values generated
  13379. * by running each own enumerable string keyed property of `object` thru
  13380. * `iteratee`. The iteratee is invoked with three arguments:
  13381. * (value, key, object).
  13382. *
  13383. * @static
  13384. * @memberOf _
  13385. * @since 2.4.0
  13386. * @category Object
  13387. * @param {Object} object The object to iterate over.
  13388. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13389. * @returns {Object} Returns the new mapped object.
  13390. * @see _.mapKeys
  13391. * @example
  13392. *
  13393. * var users = {
  13394. * 'fred': { 'user': 'fred', 'age': 40 },
  13395. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  13396. * };
  13397. *
  13398. * _.mapValues(users, function(o) { return o.age; });
  13399. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  13400. *
  13401. * // The `_.property` iteratee shorthand.
  13402. * _.mapValues(users, 'age');
  13403. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  13404. */
  13405. function mapValues(object, iteratee) {
  13406. var result = {};
  13407. iteratee = getIteratee(iteratee, 3);
  13408. baseForOwn(object, function(value, key, object) {
  13409. baseAssignValue(result, key, iteratee(value, key, object));
  13410. });
  13411. return result;
  13412. }
  13413. /**
  13414. * This method is like `_.assign` except that it recursively merges own and
  13415. * inherited enumerable string keyed properties of source objects into the
  13416. * destination object. Source properties that resolve to `undefined` are
  13417. * skipped if a destination value exists. Array and plain object properties
  13418. * are merged recursively. Other objects and value types are overridden by
  13419. * assignment. Source objects are applied from left to right. Subsequent
  13420. * sources overwrite property assignments of previous sources.
  13421. *
  13422. * **Note:** This method mutates `object`.
  13423. *
  13424. * @static
  13425. * @memberOf _
  13426. * @since 0.5.0
  13427. * @category Object
  13428. * @param {Object} object The destination object.
  13429. * @param {...Object} [sources] The source objects.
  13430. * @returns {Object} Returns `object`.
  13431. * @example
  13432. *
  13433. * var object = {
  13434. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  13435. * };
  13436. *
  13437. * var other = {
  13438. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  13439. * };
  13440. *
  13441. * _.merge(object, other);
  13442. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  13443. */
  13444. var merge = createAssigner(function(object, source, srcIndex) {
  13445. baseMerge(object, source, srcIndex);
  13446. });
  13447. /**
  13448. * This method is like `_.merge` except that it accepts `customizer` which
  13449. * is invoked to produce the merged values of the destination and source
  13450. * properties. If `customizer` returns `undefined`, merging is handled by the
  13451. * method instead. The `customizer` is invoked with six arguments:
  13452. * (objValue, srcValue, key, object, source, stack).
  13453. *
  13454. * **Note:** This method mutates `object`.
  13455. *
  13456. * @static
  13457. * @memberOf _
  13458. * @since 4.0.0
  13459. * @category Object
  13460. * @param {Object} object The destination object.
  13461. * @param {...Object} sources The source objects.
  13462. * @param {Function} customizer The function to customize assigned values.
  13463. * @returns {Object} Returns `object`.
  13464. * @example
  13465. *
  13466. * function customizer(objValue, srcValue) {
  13467. * if (_.isArray(objValue)) {
  13468. * return objValue.concat(srcValue);
  13469. * }
  13470. * }
  13471. *
  13472. * var object = { 'a': [1], 'b': [2] };
  13473. * var other = { 'a': [3], 'b': [4] };
  13474. *
  13475. * _.mergeWith(object, other, customizer);
  13476. * // => { 'a': [1, 3], 'b': [2, 4] }
  13477. */
  13478. var mergeWith = createAssigner(function(
  13479. object,
  13480. source,
  13481. srcIndex,
  13482. customizer
  13483. ) {
  13484. baseMerge(object, source, srcIndex, customizer);
  13485. });
  13486. /**
  13487. * The opposite of `_.pick`; this method creates an object composed of the
  13488. * own and inherited enumerable property paths of `object` that are not omitted.
  13489. *
  13490. * **Note:** This method is considerably slower than `_.pick`.
  13491. *
  13492. * @static
  13493. * @since 0.1.0
  13494. * @memberOf _
  13495. * @category Object
  13496. * @param {Object} object The source object.
  13497. * @param {...(string|string[])} [paths] The property paths to omit.
  13498. * @returns {Object} Returns the new object.
  13499. * @example
  13500. *
  13501. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  13502. *
  13503. * _.omit(object, ['a', 'c']);
  13504. * // => { 'b': '2' }
  13505. */
  13506. var omit = flatRest(function(object, paths) {
  13507. var result = {};
  13508. if (object == null) {
  13509. return result;
  13510. }
  13511. var isDeep = false;
  13512. paths = arrayMap(paths, function(path) {
  13513. path = castPath(path, object);
  13514. isDeep || (isDeep = path.length > 1);
  13515. return path;
  13516. });
  13517. copyObject(object, getAllKeysIn(object), result);
  13518. if (isDeep) {
  13519. result = baseClone(
  13520. result,
  13521. CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG,
  13522. customOmitClone
  13523. );
  13524. }
  13525. var length = paths.length;
  13526. while (length--) {
  13527. baseUnset(result, paths[length]);
  13528. }
  13529. return result;
  13530. });
  13531. /**
  13532. * The opposite of `_.pickBy`; this method creates an object composed of
  13533. * the own and inherited enumerable string keyed properties of `object` that
  13534. * `predicate` doesn't return truthy for. The predicate is invoked with two
  13535. * arguments: (value, key).
  13536. *
  13537. * @static
  13538. * @memberOf _
  13539. * @since 4.0.0
  13540. * @category Object
  13541. * @param {Object} object The source object.
  13542. * @param {Function} [predicate=_.identity] The function invoked per property.
  13543. * @returns {Object} Returns the new object.
  13544. * @example
  13545. *
  13546. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  13547. *
  13548. * _.omitBy(object, _.isNumber);
  13549. * // => { 'b': '2' }
  13550. */
  13551. function omitBy(object, predicate) {
  13552. return pickBy(object, negate(getIteratee(predicate)));
  13553. }
  13554. /**
  13555. * Creates an object composed of the picked `object` properties.
  13556. *
  13557. * @static
  13558. * @since 0.1.0
  13559. * @memberOf _
  13560. * @category Object
  13561. * @param {Object} object The source object.
  13562. * @param {...(string|string[])} [paths] The property paths to pick.
  13563. * @returns {Object} Returns the new object.
  13564. * @example
  13565. *
  13566. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  13567. *
  13568. * _.pick(object, ['a', 'c']);
  13569. * // => { 'a': 1, 'c': 3 }
  13570. */
  13571. var pick = flatRest(function(object, paths) {
  13572. return object == null ? {} : basePick(object, paths);
  13573. });
  13574. /**
  13575. * Creates an object composed of the `object` properties `predicate` returns
  13576. * truthy for. The predicate is invoked with two arguments: (value, key).
  13577. *
  13578. * @static
  13579. * @memberOf _
  13580. * @since 4.0.0
  13581. * @category Object
  13582. * @param {Object} object The source object.
  13583. * @param {Function} [predicate=_.identity] The function invoked per property.
  13584. * @returns {Object} Returns the new object.
  13585. * @example
  13586. *
  13587. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  13588. *
  13589. * _.pickBy(object, _.isNumber);
  13590. * // => { 'a': 1, 'c': 3 }
  13591. */
  13592. function pickBy(object, predicate) {
  13593. if (object == null) {
  13594. return {};
  13595. }
  13596. var props = arrayMap(getAllKeysIn(object), function(prop) {
  13597. return [prop];
  13598. });
  13599. predicate = getIteratee(predicate);
  13600. return basePickBy(object, props, function(value, path) {
  13601. return predicate(value, path[0]);
  13602. });
  13603. }
  13604. /**
  13605. * This method is like `_.get` except that if the resolved value is a
  13606. * function it's invoked with the `this` binding of its parent object and
  13607. * its result is returned.
  13608. *
  13609. * @static
  13610. * @since 0.1.0
  13611. * @memberOf _
  13612. * @category Object
  13613. * @param {Object} object The object to query.
  13614. * @param {Array|string} path The path of the property to resolve.
  13615. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  13616. * @returns {*} Returns the resolved value.
  13617. * @example
  13618. *
  13619. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  13620. *
  13621. * _.result(object, 'a[0].b.c1');
  13622. * // => 3
  13623. *
  13624. * _.result(object, 'a[0].b.c2');
  13625. * // => 4
  13626. *
  13627. * _.result(object, 'a[0].b.c3', 'default');
  13628. * // => 'default'
  13629. *
  13630. * _.result(object, 'a[0].b.c3', _.constant('default'));
  13631. * // => 'default'
  13632. */
  13633. function result(object, path, defaultValue) {
  13634. path = castPath(path, object);
  13635. var index = -1,
  13636. length = path.length;
  13637. // Ensure the loop is entered when path is empty.
  13638. if (!length) {
  13639. length = 1;
  13640. object = undefined;
  13641. }
  13642. while (++index < length) {
  13643. var value = object == null ? undefined : object[toKey(path[index])];
  13644. if (value === undefined) {
  13645. index = length;
  13646. value = defaultValue;
  13647. }
  13648. object = isFunction(value) ? value.call(object) : value;
  13649. }
  13650. return object;
  13651. }
  13652. /**
  13653. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  13654. * it's created. Arrays are created for missing index properties while objects
  13655. * are created for all other missing properties. Use `_.setWith` to customize
  13656. * `path` creation.
  13657. *
  13658. * **Note:** This method mutates `object`.
  13659. *
  13660. * @static
  13661. * @memberOf _
  13662. * @since 3.7.0
  13663. * @category Object
  13664. * @param {Object} object The object to modify.
  13665. * @param {Array|string} path The path of the property to set.
  13666. * @param {*} value The value to set.
  13667. * @returns {Object} Returns `object`.
  13668. * @example
  13669. *
  13670. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13671. *
  13672. * _.set(object, 'a[0].b.c', 4);
  13673. * console.log(object.a[0].b.c);
  13674. * // => 4
  13675. *
  13676. * _.set(object, ['x', '0', 'y', 'z'], 5);
  13677. * console.log(object.x[0].y.z);
  13678. * // => 5
  13679. */
  13680. function set(object, path, value) {
  13681. return object == null ? object : baseSet(object, path, value);
  13682. }
  13683. /**
  13684. * This method is like `_.set` except that it accepts `customizer` which is
  13685. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13686. * path creation is handled by the method instead. The `customizer` is invoked
  13687. * with three arguments: (nsValue, key, nsObject).
  13688. *
  13689. * **Note:** This method mutates `object`.
  13690. *
  13691. * @static
  13692. * @memberOf _
  13693. * @since 4.0.0
  13694. * @category Object
  13695. * @param {Object} object The object to modify.
  13696. * @param {Array|string} path The path of the property to set.
  13697. * @param {*} value The value to set.
  13698. * @param {Function} [customizer] The function to customize assigned values.
  13699. * @returns {Object} Returns `object`.
  13700. * @example
  13701. *
  13702. * var object = {};
  13703. *
  13704. * _.setWith(object, '[0][1]', 'a', Object);
  13705. * // => { '0': { '1': 'a' } }
  13706. */
  13707. function setWith(object, path, value, customizer) {
  13708. customizer = typeof customizer === 'function' ? customizer : undefined;
  13709. return object == null ? object : baseSet(object, path, value, customizer);
  13710. }
  13711. /**
  13712. * Creates an array of own enumerable string keyed-value pairs for `object`
  13713. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  13714. * entries are returned.
  13715. *
  13716. * @static
  13717. * @memberOf _
  13718. * @since 4.0.0
  13719. * @alias entries
  13720. * @category Object
  13721. * @param {Object} object The object to query.
  13722. * @returns {Array} Returns the key-value pairs.
  13723. * @example
  13724. *
  13725. * function Foo() {
  13726. * this.a = 1;
  13727. * this.b = 2;
  13728. * }
  13729. *
  13730. * Foo.prototype.c = 3;
  13731. *
  13732. * _.toPairs(new Foo);
  13733. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  13734. */
  13735. var toPairs = createToPairs(keys);
  13736. /**
  13737. * Creates an array of own and inherited enumerable string keyed-value pairs
  13738. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  13739. * or set, its entries are returned.
  13740. *
  13741. * @static
  13742. * @memberOf _
  13743. * @since 4.0.0
  13744. * @alias entriesIn
  13745. * @category Object
  13746. * @param {Object} object The object to query.
  13747. * @returns {Array} Returns the key-value pairs.
  13748. * @example
  13749. *
  13750. * function Foo() {
  13751. * this.a = 1;
  13752. * this.b = 2;
  13753. * }
  13754. *
  13755. * Foo.prototype.c = 3;
  13756. *
  13757. * _.toPairsIn(new Foo);
  13758. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  13759. */
  13760. var toPairsIn = createToPairs(keysIn);
  13761. /**
  13762. * An alternative to `_.reduce`; this method transforms `object` to a new
  13763. * `accumulator` object which is the result of running each of its own
  13764. * enumerable string keyed properties thru `iteratee`, with each invocation
  13765. * potentially mutating the `accumulator` object. If `accumulator` is not
  13766. * provided, a new object with the same `[[Prototype]]` will be used. The
  13767. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  13768. * Iteratee functions may exit iteration early by explicitly returning `false`.
  13769. *
  13770. * @static
  13771. * @memberOf _
  13772. * @since 1.3.0
  13773. * @category Object
  13774. * @param {Object} object The object to iterate over.
  13775. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13776. * @param {*} [accumulator] The custom accumulator value.
  13777. * @returns {*} Returns the accumulated value.
  13778. * @example
  13779. *
  13780. * _.transform([2, 3, 4], function(result, n) {
  13781. * result.push(n *= n);
  13782. * return n % 2 == 0;
  13783. * }, []);
  13784. * // => [4, 9]
  13785. *
  13786. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  13787. * (result[value] || (result[value] = [])).push(key);
  13788. * }, {});
  13789. * // => { '1': ['a', 'c'], '2': ['b'] }
  13790. */
  13791. function transform(object, iteratee, accumulator) {
  13792. var isArr = isArray(object),
  13793. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  13794. iteratee = getIteratee(iteratee, 4);
  13795. if (accumulator == null) {
  13796. var Ctor = object && object.constructor;
  13797. if (isArrLike) {
  13798. accumulator = isArr ? new Ctor() : [];
  13799. } else if (isObject(object)) {
  13800. accumulator = isFunction(Ctor)
  13801. ? baseCreate(getPrototype(object))
  13802. : {};
  13803. } else {
  13804. accumulator = {};
  13805. }
  13806. }
  13807. (isArrLike ? arrayEach : baseForOwn)(object, function(
  13808. value,
  13809. index,
  13810. object
  13811. ) {
  13812. return iteratee(accumulator, value, index, object);
  13813. });
  13814. return accumulator;
  13815. }
  13816. /**
  13817. * Removes the property at `path` of `object`.
  13818. *
  13819. * **Note:** This method mutates `object`.
  13820. *
  13821. * @static
  13822. * @memberOf _
  13823. * @since 4.0.0
  13824. * @category Object
  13825. * @param {Object} object The object to modify.
  13826. * @param {Array|string} path The path of the property to unset.
  13827. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13828. * @example
  13829. *
  13830. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13831. * _.unset(object, 'a[0].b.c');
  13832. * // => true
  13833. *
  13834. * console.log(object);
  13835. * // => { 'a': [{ 'b': {} }] };
  13836. *
  13837. * _.unset(object, ['a', '0', 'b', 'c']);
  13838. * // => true
  13839. *
  13840. * console.log(object);
  13841. * // => { 'a': [{ 'b': {} }] };
  13842. */
  13843. function unset(object, path) {
  13844. return object == null ? true : baseUnset(object, path);
  13845. }
  13846. /**
  13847. * This method is like `_.set` except that accepts `updater` to produce the
  13848. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13849. * is invoked with one argument: (value).
  13850. *
  13851. * **Note:** This method mutates `object`.
  13852. *
  13853. * @static
  13854. * @memberOf _
  13855. * @since 4.6.0
  13856. * @category Object
  13857. * @param {Object} object The object to modify.
  13858. * @param {Array|string} path The path of the property to set.
  13859. * @param {Function} updater The function to produce the updated value.
  13860. * @returns {Object} Returns `object`.
  13861. * @example
  13862. *
  13863. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13864. *
  13865. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13866. * console.log(object.a[0].b.c);
  13867. * // => 9
  13868. *
  13869. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13870. * console.log(object.x[0].y.z);
  13871. * // => 0
  13872. */
  13873. function update(object, path, updater) {
  13874. return object == null
  13875. ? object
  13876. : baseUpdate(object, path, castFunction(updater));
  13877. }
  13878. /**
  13879. * This method is like `_.update` except that it accepts `customizer` which is
  13880. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13881. * path creation is handled by the method instead. The `customizer` is invoked
  13882. * with three arguments: (nsValue, key, nsObject).
  13883. *
  13884. * **Note:** This method mutates `object`.
  13885. *
  13886. * @static
  13887. * @memberOf _
  13888. * @since 4.6.0
  13889. * @category Object
  13890. * @param {Object} object The object to modify.
  13891. * @param {Array|string} path The path of the property to set.
  13892. * @param {Function} updater The function to produce the updated value.
  13893. * @param {Function} [customizer] The function to customize assigned values.
  13894. * @returns {Object} Returns `object`.
  13895. * @example
  13896. *
  13897. * var object = {};
  13898. *
  13899. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13900. * // => { '0': { '1': 'a' } }
  13901. */
  13902. function updateWith(object, path, updater, customizer) {
  13903. customizer = typeof customizer === 'function' ? customizer : undefined;
  13904. return object == null
  13905. ? object
  13906. : baseUpdate(object, path, castFunction(updater), customizer);
  13907. }
  13908. /**
  13909. * Creates an array of the own enumerable string keyed property values of `object`.
  13910. *
  13911. * **Note:** Non-object values are coerced to objects.
  13912. *
  13913. * @static
  13914. * @since 0.1.0
  13915. * @memberOf _
  13916. * @category Object
  13917. * @param {Object} object The object to query.
  13918. * @returns {Array} Returns the array of property values.
  13919. * @example
  13920. *
  13921. * function Foo() {
  13922. * this.a = 1;
  13923. * this.b = 2;
  13924. * }
  13925. *
  13926. * Foo.prototype.c = 3;
  13927. *
  13928. * _.values(new Foo);
  13929. * // => [1, 2] (iteration order is not guaranteed)
  13930. *
  13931. * _.values('hi');
  13932. * // => ['h', 'i']
  13933. */
  13934. function values(object) {
  13935. return object == null ? [] : baseValues(object, keys(object));
  13936. }
  13937. /**
  13938. * Creates an array of the own and inherited enumerable string keyed property
  13939. * values of `object`.
  13940. *
  13941. * **Note:** Non-object values are coerced to objects.
  13942. *
  13943. * @static
  13944. * @memberOf _
  13945. * @since 3.0.0
  13946. * @category Object
  13947. * @param {Object} object The object to query.
  13948. * @returns {Array} Returns the array of property values.
  13949. * @example
  13950. *
  13951. * function Foo() {
  13952. * this.a = 1;
  13953. * this.b = 2;
  13954. * }
  13955. *
  13956. * Foo.prototype.c = 3;
  13957. *
  13958. * _.valuesIn(new Foo);
  13959. * // => [1, 2, 3] (iteration order is not guaranteed)
  13960. */
  13961. function valuesIn(object) {
  13962. return object == null ? [] : baseValues(object, keysIn(object));
  13963. }
  13964. /* ------------------------------------------------------------------------*/
  13965. /**
  13966. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13967. *
  13968. * @static
  13969. * @memberOf _
  13970. * @since 4.0.0
  13971. * @category Number
  13972. * @param {number} number The number to clamp.
  13973. * @param {number} [lower] The lower bound.
  13974. * @param {number} upper The upper bound.
  13975. * @returns {number} Returns the clamped number.
  13976. * @example
  13977. *
  13978. * _.clamp(-10, -5, 5);
  13979. * // => -5
  13980. *
  13981. * _.clamp(10, -5, 5);
  13982. * // => 5
  13983. */
  13984. function clamp(number, lower, upper) {
  13985. if (upper === undefined) {
  13986. upper = lower;
  13987. lower = undefined;
  13988. }
  13989. if (upper !== undefined) {
  13990. upper = toNumber(upper);
  13991. upper = upper === upper ? upper : 0;
  13992. }
  13993. if (lower !== undefined) {
  13994. lower = toNumber(lower);
  13995. lower = lower === lower ? lower : 0;
  13996. }
  13997. return baseClamp(toNumber(number), lower, upper);
  13998. }
  13999. /**
  14000. * Checks if `n` is between `start` and up to, but not including, `end`. If
  14001. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  14002. * If `start` is greater than `end` the params are swapped to support
  14003. * negative ranges.
  14004. *
  14005. * @static
  14006. * @memberOf _
  14007. * @since 3.3.0
  14008. * @category Number
  14009. * @param {number} number The number to check.
  14010. * @param {number} [start=0] The start of the range.
  14011. * @param {number} end The end of the range.
  14012. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  14013. * @see _.range, _.rangeRight
  14014. * @example
  14015. *
  14016. * _.inRange(3, 2, 4);
  14017. * // => true
  14018. *
  14019. * _.inRange(4, 8);
  14020. * // => true
  14021. *
  14022. * _.inRange(4, 2);
  14023. * // => false
  14024. *
  14025. * _.inRange(2, 2);
  14026. * // => false
  14027. *
  14028. * _.inRange(1.2, 2);
  14029. * // => true
  14030. *
  14031. * _.inRange(5.2, 4);
  14032. * // => false
  14033. *
  14034. * _.inRange(-3, -2, -6);
  14035. * // => true
  14036. */
  14037. function inRange(number, start, end) {
  14038. start = toFinite(start);
  14039. if (end === undefined) {
  14040. end = start;
  14041. start = 0;
  14042. } else {
  14043. end = toFinite(end);
  14044. }
  14045. number = toNumber(number);
  14046. return baseInRange(number, start, end);
  14047. }
  14048. /**
  14049. * Produces a random number between the inclusive `lower` and `upper` bounds.
  14050. * If only one argument is provided a number between `0` and the given number
  14051. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  14052. * floats, a floating-point number is returned instead of an integer.
  14053. *
  14054. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14055. * floating-point values which can produce unexpected results.
  14056. *
  14057. * @static
  14058. * @memberOf _
  14059. * @since 0.7.0
  14060. * @category Number
  14061. * @param {number} [lower=0] The lower bound.
  14062. * @param {number} [upper=1] The upper bound.
  14063. * @param {boolean} [floating] Specify returning a floating-point number.
  14064. * @returns {number} Returns the random number.
  14065. * @example
  14066. *
  14067. * _.random(0, 5);
  14068. * // => an integer between 0 and 5
  14069. *
  14070. * _.random(5);
  14071. * // => also an integer between 0 and 5
  14072. *
  14073. * _.random(5, true);
  14074. * // => a floating-point number between 0 and 5
  14075. *
  14076. * _.random(1.2, 5.2);
  14077. * // => a floating-point number between 1.2 and 5.2
  14078. */
  14079. function random(lower, upper, floating) {
  14080. if (
  14081. floating &&
  14082. typeof floating !== 'boolean' &&
  14083. isIterateeCall(lower, upper, floating)
  14084. ) {
  14085. upper = floating = undefined;
  14086. }
  14087. if (floating === undefined) {
  14088. if (typeof upper === 'boolean') {
  14089. floating = upper;
  14090. upper = undefined;
  14091. } else if (typeof lower === 'boolean') {
  14092. floating = lower;
  14093. lower = undefined;
  14094. }
  14095. }
  14096. if (lower === undefined && upper === undefined) {
  14097. lower = 0;
  14098. upper = 1;
  14099. } else {
  14100. lower = toFinite(lower);
  14101. if (upper === undefined) {
  14102. upper = lower;
  14103. lower = 0;
  14104. } else {
  14105. upper = toFinite(upper);
  14106. }
  14107. }
  14108. if (lower > upper) {
  14109. var temp = lower;
  14110. lower = upper;
  14111. upper = temp;
  14112. }
  14113. if (floating || lower % 1 || upper % 1) {
  14114. var rand = nativeRandom();
  14115. return nativeMin(
  14116. lower +
  14117. rand *
  14118. (upper -
  14119. lower +
  14120. freeParseFloat('1e-' + ((rand + '').length - 1))),
  14121. upper
  14122. );
  14123. }
  14124. return baseRandom(lower, upper);
  14125. }
  14126. /* ------------------------------------------------------------------------*/
  14127. /**
  14128. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  14129. *
  14130. * @static
  14131. * @memberOf _
  14132. * @since 3.0.0
  14133. * @category String
  14134. * @param {string} [string=''] The string to convert.
  14135. * @returns {string} Returns the camel cased string.
  14136. * @example
  14137. *
  14138. * _.camelCase('Foo Bar');
  14139. * // => 'fooBar'
  14140. *
  14141. * _.camelCase('--foo-bar--');
  14142. * // => 'fooBar'
  14143. *
  14144. * _.camelCase('__FOO_BAR__');
  14145. * // => 'fooBar'
  14146. */
  14147. var camelCase = createCompounder(function(result, word, index) {
  14148. word = word.toLowerCase();
  14149. return result + (index ? capitalize(word) : word);
  14150. });
  14151. /**
  14152. * Converts the first character of `string` to upper case and the remaining
  14153. * to lower case.
  14154. *
  14155. * @static
  14156. * @memberOf _
  14157. * @since 3.0.0
  14158. * @category String
  14159. * @param {string} [string=''] The string to capitalize.
  14160. * @returns {string} Returns the capitalized string.
  14161. * @example
  14162. *
  14163. * _.capitalize('FRED');
  14164. * // => 'Fred'
  14165. */
  14166. function capitalize(string) {
  14167. return upperFirst(toString(string).toLowerCase());
  14168. }
  14169. /**
  14170. * Deburrs `string` by converting
  14171. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  14172. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  14173. * letters to basic Latin letters and removing
  14174. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  14175. *
  14176. * @static
  14177. * @memberOf _
  14178. * @since 3.0.0
  14179. * @category String
  14180. * @param {string} [string=''] The string to deburr.
  14181. * @returns {string} Returns the deburred string.
  14182. * @example
  14183. *
  14184. * _.deburr('déjà vu');
  14185. * // => 'deja vu'
  14186. */
  14187. function deburr(string) {
  14188. string = toString(string);
  14189. return (
  14190. string && string.replace(reLatin, deburrLetter).replace(reComboMark, '')
  14191. );
  14192. }
  14193. /**
  14194. * Checks if `string` ends with the given target string.
  14195. *
  14196. * @static
  14197. * @memberOf _
  14198. * @since 3.0.0
  14199. * @category String
  14200. * @param {string} [string=''] The string to inspect.
  14201. * @param {string} [target] The string to search for.
  14202. * @param {number} [position=string.length] The position to search up to.
  14203. * @returns {boolean} Returns `true` if `string` ends with `target`,
  14204. * else `false`.
  14205. * @example
  14206. *
  14207. * _.endsWith('abc', 'c');
  14208. * // => true
  14209. *
  14210. * _.endsWith('abc', 'b');
  14211. * // => false
  14212. *
  14213. * _.endsWith('abc', 'b', 2);
  14214. * // => true
  14215. */
  14216. function endsWith(string, target, position) {
  14217. string = toString(string);
  14218. target = baseToString(target);
  14219. var length = string.length;
  14220. position =
  14221. position === undefined
  14222. ? length
  14223. : baseClamp(toInteger(position), 0, length);
  14224. var end = position;
  14225. position -= target.length;
  14226. return position >= 0 && string.slice(position, end) == target;
  14227. }
  14228. /**
  14229. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  14230. * corresponding HTML entities.
  14231. *
  14232. * **Note:** No other characters are escaped. To escape additional
  14233. * characters use a third-party library like [_he_](https://mths.be/he).
  14234. *
  14235. * Though the ">" character is escaped for symmetry, characters like
  14236. * ">" and "/" don't need escaping in HTML and have no special meaning
  14237. * unless they're part of a tag or unquoted attribute value. See
  14238. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  14239. * (under "semi-related fun fact") for more details.
  14240. *
  14241. * When working with HTML you should always
  14242. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  14243. * XSS vectors.
  14244. *
  14245. * @static
  14246. * @since 0.1.0
  14247. * @memberOf _
  14248. * @category String
  14249. * @param {string} [string=''] The string to escape.
  14250. * @returns {string} Returns the escaped string.
  14251. * @example
  14252. *
  14253. * _.escape('fred, barney, & pebbles');
  14254. * // => 'fred, barney, &amp; pebbles'
  14255. */
  14256. function escape(string) {
  14257. string = toString(string);
  14258. return string && reHasUnescapedHtml.test(string)
  14259. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  14260. : string;
  14261. }
  14262. /**
  14263. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  14264. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  14265. *
  14266. * @static
  14267. * @memberOf _
  14268. * @since 3.0.0
  14269. * @category String
  14270. * @param {string} [string=''] The string to escape.
  14271. * @returns {string} Returns the escaped string.
  14272. * @example
  14273. *
  14274. * _.escapeRegExp('[lodash](https://lodash.com/)');
  14275. * // => '\[lodash\]\(https://lodash\.com/\)'
  14276. */
  14277. function escapeRegExp(string) {
  14278. string = toString(string);
  14279. return string && reHasRegExpChar.test(string)
  14280. ? string.replace(reRegExpChar, '\\$&')
  14281. : string;
  14282. }
  14283. /**
  14284. * Converts `string` to
  14285. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  14286. *
  14287. * @static
  14288. * @memberOf _
  14289. * @since 3.0.0
  14290. * @category String
  14291. * @param {string} [string=''] The string to convert.
  14292. * @returns {string} Returns the kebab cased string.
  14293. * @example
  14294. *
  14295. * _.kebabCase('Foo Bar');
  14296. * // => 'foo-bar'
  14297. *
  14298. * _.kebabCase('fooBar');
  14299. * // => 'foo-bar'
  14300. *
  14301. * _.kebabCase('__FOO_BAR__');
  14302. * // => 'foo-bar'
  14303. */
  14304. var kebabCase = createCompounder(function(result, word, index) {
  14305. return result + (index ? '-' : '') + word.toLowerCase();
  14306. });
  14307. /**
  14308. * Converts `string`, as space separated words, to lower case.
  14309. *
  14310. * @static
  14311. * @memberOf _
  14312. * @since 4.0.0
  14313. * @category String
  14314. * @param {string} [string=''] The string to convert.
  14315. * @returns {string} Returns the lower cased string.
  14316. * @example
  14317. *
  14318. * _.lowerCase('--Foo-Bar--');
  14319. * // => 'foo bar'
  14320. *
  14321. * _.lowerCase('fooBar');
  14322. * // => 'foo bar'
  14323. *
  14324. * _.lowerCase('__FOO_BAR__');
  14325. * // => 'foo bar'
  14326. */
  14327. var lowerCase = createCompounder(function(result, word, index) {
  14328. return result + (index ? ' ' : '') + word.toLowerCase();
  14329. });
  14330. /**
  14331. * Converts the first character of `string` to lower case.
  14332. *
  14333. * @static
  14334. * @memberOf _
  14335. * @since 4.0.0
  14336. * @category String
  14337. * @param {string} [string=''] The string to convert.
  14338. * @returns {string} Returns the converted string.
  14339. * @example
  14340. *
  14341. * _.lowerFirst('Fred');
  14342. * // => 'fred'
  14343. *
  14344. * _.lowerFirst('FRED');
  14345. * // => 'fRED'
  14346. */
  14347. var lowerFirst = createCaseFirst('toLowerCase');
  14348. /**
  14349. * Pads `string` on the left and right sides if it's shorter than `length`.
  14350. * Padding characters are truncated if they can't be evenly divided by `length`.
  14351. *
  14352. * @static
  14353. * @memberOf _
  14354. * @since 3.0.0
  14355. * @category String
  14356. * @param {string} [string=''] The string to pad.
  14357. * @param {number} [length=0] The padding length.
  14358. * @param {string} [chars=' '] The string used as padding.
  14359. * @returns {string} Returns the padded string.
  14360. * @example
  14361. *
  14362. * _.pad('abc', 8);
  14363. * // => ' abc '
  14364. *
  14365. * _.pad('abc', 8, '_-');
  14366. * // => '_-abc_-_'
  14367. *
  14368. * _.pad('abc', 3);
  14369. * // => 'abc'
  14370. */
  14371. function pad(string, length, chars) {
  14372. string = toString(string);
  14373. length = toInteger(length);
  14374. var strLength = length ? stringSize(string) : 0;
  14375. if (!length || strLength >= length) {
  14376. return string;
  14377. }
  14378. var mid = (length - strLength) / 2;
  14379. return (
  14380. createPadding(nativeFloor(mid), chars) +
  14381. string +
  14382. createPadding(nativeCeil(mid), chars)
  14383. );
  14384. }
  14385. /**
  14386. * Pads `string` on the right side if it's shorter than `length`. Padding
  14387. * characters are truncated if they exceed `length`.
  14388. *
  14389. * @static
  14390. * @memberOf _
  14391. * @since 4.0.0
  14392. * @category String
  14393. * @param {string} [string=''] The string to pad.
  14394. * @param {number} [length=0] The padding length.
  14395. * @param {string} [chars=' '] The string used as padding.
  14396. * @returns {string} Returns the padded string.
  14397. * @example
  14398. *
  14399. * _.padEnd('abc', 6);
  14400. * // => 'abc '
  14401. *
  14402. * _.padEnd('abc', 6, '_-');
  14403. * // => 'abc_-_'
  14404. *
  14405. * _.padEnd('abc', 3);
  14406. * // => 'abc'
  14407. */
  14408. function padEnd(string, length, chars) {
  14409. string = toString(string);
  14410. length = toInteger(length);
  14411. var strLength = length ? stringSize(string) : 0;
  14412. return length && strLength < length
  14413. ? string + createPadding(length - strLength, chars)
  14414. : string;
  14415. }
  14416. /**
  14417. * Pads `string` on the left side if it's shorter than `length`. Padding
  14418. * characters are truncated if they exceed `length`.
  14419. *
  14420. * @static
  14421. * @memberOf _
  14422. * @since 4.0.0
  14423. * @category String
  14424. * @param {string} [string=''] The string to pad.
  14425. * @param {number} [length=0] The padding length.
  14426. * @param {string} [chars=' '] The string used as padding.
  14427. * @returns {string} Returns the padded string.
  14428. * @example
  14429. *
  14430. * _.padStart('abc', 6);
  14431. * // => ' abc'
  14432. *
  14433. * _.padStart('abc', 6, '_-');
  14434. * // => '_-_abc'
  14435. *
  14436. * _.padStart('abc', 3);
  14437. * // => 'abc'
  14438. */
  14439. function padStart(string, length, chars) {
  14440. string = toString(string);
  14441. length = toInteger(length);
  14442. var strLength = length ? stringSize(string) : 0;
  14443. return length && strLength < length
  14444. ? createPadding(length - strLength, chars) + string
  14445. : string;
  14446. }
  14447. /**
  14448. * Converts `string` to an integer of the specified radix. If `radix` is
  14449. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  14450. * hexadecimal, in which case a `radix` of `16` is used.
  14451. *
  14452. * **Note:** This method aligns with the
  14453. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  14454. *
  14455. * @static
  14456. * @memberOf _
  14457. * @since 1.1.0
  14458. * @category String
  14459. * @param {string} string The string to convert.
  14460. * @param {number} [radix=10] The radix to interpret `value` by.
  14461. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14462. * @returns {number} Returns the converted integer.
  14463. * @example
  14464. *
  14465. * _.parseInt('08');
  14466. * // => 8
  14467. *
  14468. * _.map(['6', '08', '10'], _.parseInt);
  14469. * // => [6, 8, 10]
  14470. */
  14471. function parseInt(string, radix, guard) {
  14472. if (guard || radix == null) {
  14473. radix = 0;
  14474. } else if (radix) {
  14475. radix = +radix;
  14476. }
  14477. return nativeParseInt(
  14478. toString(string).replace(reTrimStart, ''),
  14479. radix || 0
  14480. );
  14481. }
  14482. /**
  14483. * Repeats the given string `n` times.
  14484. *
  14485. * @static
  14486. * @memberOf _
  14487. * @since 3.0.0
  14488. * @category String
  14489. * @param {string} [string=''] The string to repeat.
  14490. * @param {number} [n=1] The number of times to repeat the string.
  14491. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14492. * @returns {string} Returns the repeated string.
  14493. * @example
  14494. *
  14495. * _.repeat('*', 3);
  14496. * // => '***'
  14497. *
  14498. * _.repeat('abc', 2);
  14499. * // => 'abcabc'
  14500. *
  14501. * _.repeat('abc', 0);
  14502. * // => ''
  14503. */
  14504. function repeat(string, n, guard) {
  14505. if (guard ? isIterateeCall(string, n, guard) : n === undefined) {
  14506. n = 1;
  14507. } else {
  14508. n = toInteger(n);
  14509. }
  14510. return baseRepeat(toString(string), n);
  14511. }
  14512. /**
  14513. * Replaces matches for `pattern` in `string` with `replacement`.
  14514. *
  14515. * **Note:** This method is based on
  14516. * [`String#replace`](https://mdn.io/String/replace).
  14517. *
  14518. * @static
  14519. * @memberOf _
  14520. * @since 4.0.0
  14521. * @category String
  14522. * @param {string} [string=''] The string to modify.
  14523. * @param {RegExp|string} pattern The pattern to replace.
  14524. * @param {Function|string} replacement The match replacement.
  14525. * @returns {string} Returns the modified string.
  14526. * @example
  14527. *
  14528. * _.replace('Hi Fred', 'Fred', 'Barney');
  14529. * // => 'Hi Barney'
  14530. */
  14531. function replace() {
  14532. var args = arguments,
  14533. string = toString(args[0]);
  14534. return args.length < 3 ? string : string.replace(args[1], args[2]);
  14535. }
  14536. /**
  14537. * Converts `string` to
  14538. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  14539. *
  14540. * @static
  14541. * @memberOf _
  14542. * @since 3.0.0
  14543. * @category String
  14544. * @param {string} [string=''] The string to convert.
  14545. * @returns {string} Returns the snake cased string.
  14546. * @example
  14547. *
  14548. * _.snakeCase('Foo Bar');
  14549. * // => 'foo_bar'
  14550. *
  14551. * _.snakeCase('fooBar');
  14552. * // => 'foo_bar'
  14553. *
  14554. * _.snakeCase('--FOO-BAR--');
  14555. * // => 'foo_bar'
  14556. */
  14557. var snakeCase = createCompounder(function(result, word, index) {
  14558. return result + (index ? '_' : '') + word.toLowerCase();
  14559. });
  14560. /**
  14561. * Splits `string` by `separator`.
  14562. *
  14563. * **Note:** This method is based on
  14564. * [`String#split`](https://mdn.io/String/split).
  14565. *
  14566. * @static
  14567. * @memberOf _
  14568. * @since 4.0.0
  14569. * @category String
  14570. * @param {string} [string=''] The string to split.
  14571. * @param {RegExp|string} separator The separator pattern to split by.
  14572. * @param {number} [limit] The length to truncate results to.
  14573. * @returns {Array} Returns the string segments.
  14574. * @example
  14575. *
  14576. * _.split('a-b-c', '-', 2);
  14577. * // => ['a', 'b']
  14578. */
  14579. function split(string, separator, limit) {
  14580. if (
  14581. limit &&
  14582. typeof limit !== 'number' &&
  14583. isIterateeCall(string, separator, limit)
  14584. ) {
  14585. separator = limit = undefined;
  14586. }
  14587. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  14588. if (!limit) {
  14589. return [];
  14590. }
  14591. string = toString(string);
  14592. if (
  14593. string &&
  14594. (typeof separator === 'string' ||
  14595. (separator != null && !isRegExp(separator)))
  14596. ) {
  14597. separator = baseToString(separator);
  14598. if (!separator && hasUnicode(string)) {
  14599. return castSlice(stringToArray(string), 0, limit);
  14600. }
  14601. }
  14602. return string.split(separator, limit);
  14603. }
  14604. /**
  14605. * Converts `string` to
  14606. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  14607. *
  14608. * @static
  14609. * @memberOf _
  14610. * @since 3.1.0
  14611. * @category String
  14612. * @param {string} [string=''] The string to convert.
  14613. * @returns {string} Returns the start cased string.
  14614. * @example
  14615. *
  14616. * _.startCase('--foo-bar--');
  14617. * // => 'Foo Bar'
  14618. *
  14619. * _.startCase('fooBar');
  14620. * // => 'Foo Bar'
  14621. *
  14622. * _.startCase('__FOO_BAR__');
  14623. * // => 'FOO BAR'
  14624. */
  14625. var startCase = createCompounder(function(result, word, index) {
  14626. return result + (index ? ' ' : '') + upperFirst(word);
  14627. });
  14628. /**
  14629. * Checks if `string` starts with the given target string.
  14630. *
  14631. * @static
  14632. * @memberOf _
  14633. * @since 3.0.0
  14634. * @category String
  14635. * @param {string} [string=''] The string to inspect.
  14636. * @param {string} [target] The string to search for.
  14637. * @param {number} [position=0] The position to search from.
  14638. * @returns {boolean} Returns `true` if `string` starts with `target`,
  14639. * else `false`.
  14640. * @example
  14641. *
  14642. * _.startsWith('abc', 'a');
  14643. * // => true
  14644. *
  14645. * _.startsWith('abc', 'b');
  14646. * // => false
  14647. *
  14648. * _.startsWith('abc', 'b', 1);
  14649. * // => true
  14650. */
  14651. function startsWith(string, target, position) {
  14652. string = toString(string);
  14653. position =
  14654. position == null ? 0 : baseClamp(toInteger(position), 0, string.length);
  14655. target = baseToString(target);
  14656. return string.slice(position, position + target.length) == target;
  14657. }
  14658. /**
  14659. * Creates a compiled template function that can interpolate data properties
  14660. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  14661. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  14662. * properties may be accessed as free variables in the template. If a setting
  14663. * object is given, it takes precedence over `_.templateSettings` values.
  14664. *
  14665. * **Note:** In the development build `_.template` utilizes
  14666. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  14667. * for easier debugging.
  14668. *
  14669. * For more information on precompiling templates see
  14670. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  14671. *
  14672. * For more information on Chrome extension sandboxes see
  14673. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  14674. *
  14675. * @static
  14676. * @since 0.1.0
  14677. * @memberOf _
  14678. * @category String
  14679. * @param {string} [string=''] The template string.
  14680. * @param {Object} [options={}] The options object.
  14681. * @param {RegExp} [options.escape=_.templateSettings.escape]
  14682. * The HTML "escape" delimiter.
  14683. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  14684. * The "evaluate" delimiter.
  14685. * @param {Object} [options.imports=_.templateSettings.imports]
  14686. * An object to import into the template as free variables.
  14687. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  14688. * The "interpolate" delimiter.
  14689. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  14690. * The sourceURL of the compiled template.
  14691. * @param {string} [options.variable='obj']
  14692. * The data object variable name.
  14693. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14694. * @returns {Function} Returns the compiled template function.
  14695. * @example
  14696. *
  14697. * // Use the "interpolate" delimiter to create a compiled template.
  14698. * var compiled = _.template('hello <%= user %>!');
  14699. * compiled({ 'user': 'fred' });
  14700. * // => 'hello fred!'
  14701. *
  14702. * // Use the HTML "escape" delimiter to escape data property values.
  14703. * var compiled = _.template('<b><%- value %></b>');
  14704. * compiled({ 'value': '<script>' });
  14705. * // => '<b>&lt;script&gt;</b>'
  14706. *
  14707. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  14708. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  14709. * compiled({ 'users': ['fred', 'barney'] });
  14710. * // => '<li>fred</li><li>barney</li>'
  14711. *
  14712. * // Use the internal `print` function in "evaluate" delimiters.
  14713. * var compiled = _.template('<% print("hello " + user); %>!');
  14714. * compiled({ 'user': 'barney' });
  14715. * // => 'hello barney!'
  14716. *
  14717. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  14718. * // Disable support by replacing the "interpolate" delimiter.
  14719. * var compiled = _.template('hello ${ user }!');
  14720. * compiled({ 'user': 'pebbles' });
  14721. * // => 'hello pebbles!'
  14722. *
  14723. * // Use backslashes to treat delimiters as plain text.
  14724. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  14725. * compiled({ 'value': 'ignored' });
  14726. * // => '<%- value %>'
  14727. *
  14728. * // Use the `imports` option to import `jQuery` as `jq`.
  14729. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  14730. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  14731. * compiled({ 'users': ['fred', 'barney'] });
  14732. * // => '<li>fred</li><li>barney</li>'
  14733. *
  14734. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  14735. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  14736. * compiled(data);
  14737. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  14738. *
  14739. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  14740. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  14741. * compiled.source;
  14742. * // => function(data) {
  14743. * // var __t, __p = '';
  14744. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  14745. * // return __p;
  14746. * // }
  14747. *
  14748. * // Use custom template delimiters.
  14749. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  14750. * var compiled = _.template('hello {{ user }}!');
  14751. * compiled({ 'user': 'mustache' });
  14752. * // => 'hello mustache!'
  14753. *
  14754. * // Use the `source` property to inline compiled templates for meaningful
  14755. * // line numbers in error messages and stack traces.
  14756. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  14757. * var JST = {\
  14758. * "main": ' + _.template(mainText).source + '\
  14759. * };\
  14760. * ');
  14761. */
  14762. function template(string, options, guard) {
  14763. // Based on John Resig's `tmpl` implementation
  14764. // (http://ejohn.org/blog/javascript-micro-templating/)
  14765. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  14766. var settings = lodash.templateSettings;
  14767. if (guard && isIterateeCall(string, options, guard)) {
  14768. options = undefined;
  14769. }
  14770. string = toString(string);
  14771. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  14772. var imports = assignInWith(
  14773. {},
  14774. options.imports,
  14775. settings.imports,
  14776. customDefaultsAssignIn
  14777. ),
  14778. importsKeys = keys(imports),
  14779. importsValues = baseValues(imports, importsKeys);
  14780. var isEscaping,
  14781. isEvaluating,
  14782. index = 0,
  14783. interpolate = options.interpolate || reNoMatch,
  14784. source = "__p += '";
  14785. // Compile the regexp to match each delimiter.
  14786. var reDelimiters = RegExp(
  14787. (options.escape || reNoMatch).source +
  14788. '|' +
  14789. interpolate.source +
  14790. '|' +
  14791. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source +
  14792. '|' +
  14793. (options.evaluate || reNoMatch).source +
  14794. '|$',
  14795. 'g'
  14796. );
  14797. // Use a sourceURL for easier debugging.
  14798. var sourceURL =
  14799. '//# sourceURL=' +
  14800. ('sourceURL' in options
  14801. ? options.sourceURL
  14802. : 'lodash.templateSources[' + ++templateCounter + ']') +
  14803. '\n';
  14804. string.replace(reDelimiters, function(
  14805. match,
  14806. escapeValue,
  14807. interpolateValue,
  14808. esTemplateValue,
  14809. evaluateValue,
  14810. offset
  14811. ) {
  14812. interpolateValue || (interpolateValue = esTemplateValue);
  14813. // Escape characters that can't be included in string literals.
  14814. source += string
  14815. .slice(index, offset)
  14816. .replace(reUnescapedString, escapeStringChar);
  14817. // Replace delimiters with snippets.
  14818. if (escapeValue) {
  14819. isEscaping = true;
  14820. source += "' +\n__e(" + escapeValue + ") +\n'";
  14821. }
  14822. if (evaluateValue) {
  14823. isEvaluating = true;
  14824. source += "';\n" + evaluateValue + ";\n__p += '";
  14825. }
  14826. if (interpolateValue) {
  14827. source +=
  14828. "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  14829. }
  14830. index = offset + match.length;
  14831. // The JS engine embedded in Adobe products needs `match` returned in
  14832. // order to produce the correct `offset` value.
  14833. return match;
  14834. });
  14835. source += "';\n";
  14836. // If `variable` is not specified wrap a with-statement around the generated
  14837. // code to add the data object to the top of the scope chain.
  14838. var variable = options.variable;
  14839. if (!variable) {
  14840. source = 'with (obj) {\n' + source + '\n}\n';
  14841. }
  14842. // Cleanup code by stripping empty strings.
  14843. source = (isEvaluating
  14844. ? source.replace(reEmptyStringLeading, '')
  14845. : source
  14846. )
  14847. .replace(reEmptyStringMiddle, '$1')
  14848. .replace(reEmptyStringTrailing, '$1;');
  14849. // Frame code as the function body.
  14850. source =
  14851. 'function(' +
  14852. (variable || 'obj') +
  14853. ') {\n' +
  14854. (variable ? '' : 'obj || (obj = {});\n') +
  14855. "var __t, __p = ''" +
  14856. (isEscaping ? ', __e = _.escape' : '') +
  14857. (isEvaluating
  14858. ? ', __j = Array.prototype.join;\n' +
  14859. "function print() { __p += __j.call(arguments, '') }\n"
  14860. : ';\n') +
  14861. source +
  14862. 'return __p\n}';
  14863. var result = attempt(function() {
  14864. return Function(importsKeys, sourceURL + 'return ' + source).apply(
  14865. undefined,
  14866. importsValues
  14867. );
  14868. });
  14869. // Provide the compiled function's source by its `toString` method or
  14870. // the `source` property as a convenience for inlining compiled templates.
  14871. result.source = source;
  14872. if (isError(result)) {
  14873. throw result;
  14874. }
  14875. return result;
  14876. }
  14877. /**
  14878. * Converts `string`, as a whole, to lower case just like
  14879. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14880. *
  14881. * @static
  14882. * @memberOf _
  14883. * @since 4.0.0
  14884. * @category String
  14885. * @param {string} [string=''] The string to convert.
  14886. * @returns {string} Returns the lower cased string.
  14887. * @example
  14888. *
  14889. * _.toLower('--Foo-Bar--');
  14890. * // => '--foo-bar--'
  14891. *
  14892. * _.toLower('fooBar');
  14893. * // => 'foobar'
  14894. *
  14895. * _.toLower('__FOO_BAR__');
  14896. * // => '__foo_bar__'
  14897. */
  14898. function toLower(value) {
  14899. return toString(value).toLowerCase();
  14900. }
  14901. /**
  14902. * Converts `string`, as a whole, to upper case just like
  14903. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14904. *
  14905. * @static
  14906. * @memberOf _
  14907. * @since 4.0.0
  14908. * @category String
  14909. * @param {string} [string=''] The string to convert.
  14910. * @returns {string} Returns the upper cased string.
  14911. * @example
  14912. *
  14913. * _.toUpper('--foo-bar--');
  14914. * // => '--FOO-BAR--'
  14915. *
  14916. * _.toUpper('fooBar');
  14917. * // => 'FOOBAR'
  14918. *
  14919. * _.toUpper('__foo_bar__');
  14920. * // => '__FOO_BAR__'
  14921. */
  14922. function toUpper(value) {
  14923. return toString(value).toUpperCase();
  14924. }
  14925. /**
  14926. * Removes leading and trailing whitespace or specified characters from `string`.
  14927. *
  14928. * @static
  14929. * @memberOf _
  14930. * @since 3.0.0
  14931. * @category String
  14932. * @param {string} [string=''] The string to trim.
  14933. * @param {string} [chars=whitespace] The characters to trim.
  14934. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14935. * @returns {string} Returns the trimmed string.
  14936. * @example
  14937. *
  14938. * _.trim(' abc ');
  14939. * // => 'abc'
  14940. *
  14941. * _.trim('-_-abc-_-', '_-');
  14942. * // => 'abc'
  14943. *
  14944. * _.map([' foo ', ' bar '], _.trim);
  14945. * // => ['foo', 'bar']
  14946. */
  14947. function trim(string, chars, guard) {
  14948. string = toString(string);
  14949. if (string && (guard || chars === undefined)) {
  14950. return string.replace(reTrim, '');
  14951. }
  14952. if (!string || !(chars = baseToString(chars))) {
  14953. return string;
  14954. }
  14955. var strSymbols = stringToArray(string),
  14956. chrSymbols = stringToArray(chars),
  14957. start = charsStartIndex(strSymbols, chrSymbols),
  14958. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14959. return castSlice(strSymbols, start, end).join('');
  14960. }
  14961. /**
  14962. * Removes trailing whitespace or specified characters from `string`.
  14963. *
  14964. * @static
  14965. * @memberOf _
  14966. * @since 4.0.0
  14967. * @category String
  14968. * @param {string} [string=''] The string to trim.
  14969. * @param {string} [chars=whitespace] The characters to trim.
  14970. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14971. * @returns {string} Returns the trimmed string.
  14972. * @example
  14973. *
  14974. * _.trimEnd(' abc ');
  14975. * // => ' abc'
  14976. *
  14977. * _.trimEnd('-_-abc-_-', '_-');
  14978. * // => '-_-abc'
  14979. */
  14980. function trimEnd(string, chars, guard) {
  14981. string = toString(string);
  14982. if (string && (guard || chars === undefined)) {
  14983. return string.replace(reTrimEnd, '');
  14984. }
  14985. if (!string || !(chars = baseToString(chars))) {
  14986. return string;
  14987. }
  14988. var strSymbols = stringToArray(string),
  14989. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14990. return castSlice(strSymbols, 0, end).join('');
  14991. }
  14992. /**
  14993. * Removes leading whitespace or specified characters from `string`.
  14994. *
  14995. * @static
  14996. * @memberOf _
  14997. * @since 4.0.0
  14998. * @category String
  14999. * @param {string} [string=''] The string to trim.
  15000. * @param {string} [chars=whitespace] The characters to trim.
  15001. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15002. * @returns {string} Returns the trimmed string.
  15003. * @example
  15004. *
  15005. * _.trimStart(' abc ');
  15006. * // => 'abc '
  15007. *
  15008. * _.trimStart('-_-abc-_-', '_-');
  15009. * // => 'abc-_-'
  15010. */
  15011. function trimStart(string, chars, guard) {
  15012. string = toString(string);
  15013. if (string && (guard || chars === undefined)) {
  15014. return string.replace(reTrimStart, '');
  15015. }
  15016. if (!string || !(chars = baseToString(chars))) {
  15017. return string;
  15018. }
  15019. var strSymbols = stringToArray(string),
  15020. start = charsStartIndex(strSymbols, stringToArray(chars));
  15021. return castSlice(strSymbols, start).join('');
  15022. }
  15023. /**
  15024. * Truncates `string` if it's longer than the given maximum string length.
  15025. * The last characters of the truncated string are replaced with the omission
  15026. * string which defaults to "...".
  15027. *
  15028. * @static
  15029. * @memberOf _
  15030. * @since 4.0.0
  15031. * @category String
  15032. * @param {string} [string=''] The string to truncate.
  15033. * @param {Object} [options={}] The options object.
  15034. * @param {number} [options.length=30] The maximum string length.
  15035. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  15036. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  15037. * @returns {string} Returns the truncated string.
  15038. * @example
  15039. *
  15040. * _.truncate('hi-diddly-ho there, neighborino');
  15041. * // => 'hi-diddly-ho there, neighbo...'
  15042. *
  15043. * _.truncate('hi-diddly-ho there, neighborino', {
  15044. * 'length': 24,
  15045. * 'separator': ' '
  15046. * });
  15047. * // => 'hi-diddly-ho there,...'
  15048. *
  15049. * _.truncate('hi-diddly-ho there, neighborino', {
  15050. * 'length': 24,
  15051. * 'separator': /,? +/
  15052. * });
  15053. * // => 'hi-diddly-ho there...'
  15054. *
  15055. * _.truncate('hi-diddly-ho there, neighborino', {
  15056. * 'omission': ' [...]'
  15057. * });
  15058. * // => 'hi-diddly-ho there, neig [...]'
  15059. */
  15060. function truncate(string, options) {
  15061. var length = DEFAULT_TRUNC_LENGTH,
  15062. omission = DEFAULT_TRUNC_OMISSION;
  15063. if (isObject(options)) {
  15064. var separator = 'separator' in options ? options.separator : separator;
  15065. length = 'length' in options ? toInteger(options.length) : length;
  15066. omission =
  15067. 'omission' in options ? baseToString(options.omission) : omission;
  15068. }
  15069. string = toString(string);
  15070. var strLength = string.length;
  15071. if (hasUnicode(string)) {
  15072. var strSymbols = stringToArray(string);
  15073. strLength = strSymbols.length;
  15074. }
  15075. if (length >= strLength) {
  15076. return string;
  15077. }
  15078. var end = length - stringSize(omission);
  15079. if (end < 1) {
  15080. return omission;
  15081. }
  15082. var result = strSymbols
  15083. ? castSlice(strSymbols, 0, end).join('')
  15084. : string.slice(0, end);
  15085. if (separator === undefined) {
  15086. return result + omission;
  15087. }
  15088. if (strSymbols) {
  15089. end += result.length - end;
  15090. }
  15091. if (isRegExp(separator)) {
  15092. if (string.slice(end).search(separator)) {
  15093. var match,
  15094. substring = result;
  15095. if (!separator.global) {
  15096. separator = RegExp(
  15097. separator.source,
  15098. toString(reFlags.exec(separator)) + 'g'
  15099. );
  15100. }
  15101. separator.lastIndex = 0;
  15102. while ((match = separator.exec(substring))) {
  15103. var newEnd = match.index;
  15104. }
  15105. result = result.slice(0, newEnd === undefined ? end : newEnd);
  15106. }
  15107. } else if (string.indexOf(baseToString(separator), end) != end) {
  15108. var index = result.lastIndexOf(separator);
  15109. if (index > -1) {
  15110. result = result.slice(0, index);
  15111. }
  15112. }
  15113. return result + omission;
  15114. }
  15115. /**
  15116. * The inverse of `_.escape`; this method converts the HTML entities
  15117. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  15118. * their corresponding characters.
  15119. *
  15120. * **Note:** No other HTML entities are unescaped. To unescape additional
  15121. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  15122. *
  15123. * @static
  15124. * @memberOf _
  15125. * @since 0.6.0
  15126. * @category String
  15127. * @param {string} [string=''] The string to unescape.
  15128. * @returns {string} Returns the unescaped string.
  15129. * @example
  15130. *
  15131. * _.unescape('fred, barney, &amp; pebbles');
  15132. * // => 'fred, barney, & pebbles'
  15133. */
  15134. function unescape(string) {
  15135. string = toString(string);
  15136. return string && reHasEscapedHtml.test(string)
  15137. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  15138. : string;
  15139. }
  15140. /**
  15141. * Converts `string`, as space separated words, to upper case.
  15142. *
  15143. * @static
  15144. * @memberOf _
  15145. * @since 4.0.0
  15146. * @category String
  15147. * @param {string} [string=''] The string to convert.
  15148. * @returns {string} Returns the upper cased string.
  15149. * @example
  15150. *
  15151. * _.upperCase('--foo-bar');
  15152. * // => 'FOO BAR'
  15153. *
  15154. * _.upperCase('fooBar');
  15155. * // => 'FOO BAR'
  15156. *
  15157. * _.upperCase('__foo_bar__');
  15158. * // => 'FOO BAR'
  15159. */
  15160. var upperCase = createCompounder(function(result, word, index) {
  15161. return result + (index ? ' ' : '') + word.toUpperCase();
  15162. });
  15163. /**
  15164. * Converts the first character of `string` to upper case.
  15165. *
  15166. * @static
  15167. * @memberOf _
  15168. * @since 4.0.0
  15169. * @category String
  15170. * @param {string} [string=''] The string to convert.
  15171. * @returns {string} Returns the converted string.
  15172. * @example
  15173. *
  15174. * _.upperFirst('fred');
  15175. * // => 'Fred'
  15176. *
  15177. * _.upperFirst('FRED');
  15178. * // => 'FRED'
  15179. */
  15180. var upperFirst = createCaseFirst('toUpperCase');
  15181. /**
  15182. * Splits `string` into an array of its words.
  15183. *
  15184. * @static
  15185. * @memberOf _
  15186. * @since 3.0.0
  15187. * @category String
  15188. * @param {string} [string=''] The string to inspect.
  15189. * @param {RegExp|string} [pattern] The pattern to match words.
  15190. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15191. * @returns {Array} Returns the words of `string`.
  15192. * @example
  15193. *
  15194. * _.words('fred, barney, & pebbles');
  15195. * // => ['fred', 'barney', 'pebbles']
  15196. *
  15197. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  15198. * // => ['fred', 'barney', '&', 'pebbles']
  15199. */
  15200. function words(string, pattern, guard) {
  15201. string = toString(string);
  15202. pattern = guard ? undefined : pattern;
  15203. if (pattern === undefined) {
  15204. return hasUnicodeWord(string)
  15205. ? unicodeWords(string)
  15206. : asciiWords(string);
  15207. }
  15208. return string.match(pattern) || [];
  15209. }
  15210. /* ------------------------------------------------------------------------*/
  15211. /**
  15212. * Attempts to invoke `func`, returning either the result or the caught error
  15213. * object. Any additional arguments are provided to `func` when it's invoked.
  15214. *
  15215. * @static
  15216. * @memberOf _
  15217. * @since 3.0.0
  15218. * @category Util
  15219. * @param {Function} func The function to attempt.
  15220. * @param {...*} [args] The arguments to invoke `func` with.
  15221. * @returns {*} Returns the `func` result or error object.
  15222. * @example
  15223. *
  15224. * // Avoid throwing errors for invalid selectors.
  15225. * var elements = _.attempt(function(selector) {
  15226. * return document.querySelectorAll(selector);
  15227. * }, '>_>');
  15228. *
  15229. * if (_.isError(elements)) {
  15230. * elements = [];
  15231. * }
  15232. */
  15233. var attempt = baseRest(function(func, args) {
  15234. try {
  15235. return apply(func, undefined, args);
  15236. } catch (e) {
  15237. return isError(e) ? e : new Error(e);
  15238. }
  15239. });
  15240. /**
  15241. * Binds methods of an object to the object itself, overwriting the existing
  15242. * method.
  15243. *
  15244. * **Note:** This method doesn't set the "length" property of bound functions.
  15245. *
  15246. * @static
  15247. * @since 0.1.0
  15248. * @memberOf _
  15249. * @category Util
  15250. * @param {Object} object The object to bind and assign the bound methods to.
  15251. * @param {...(string|string[])} methodNames The object method names to bind.
  15252. * @returns {Object} Returns `object`.
  15253. * @example
  15254. *
  15255. * var view = {
  15256. * 'label': 'docs',
  15257. * 'click': function() {
  15258. * console.log('clicked ' + this.label);
  15259. * }
  15260. * };
  15261. *
  15262. * _.bindAll(view, ['click']);
  15263. * jQuery(element).on('click', view.click);
  15264. * // => Logs 'clicked docs' when clicked.
  15265. */
  15266. var bindAll = flatRest(function(object, methodNames) {
  15267. arrayEach(methodNames, function(key) {
  15268. key = toKey(key);
  15269. baseAssignValue(object, key, bind(object[key], object));
  15270. });
  15271. return object;
  15272. });
  15273. /**
  15274. * Creates a function that iterates over `pairs` and invokes the corresponding
  15275. * function of the first predicate to return truthy. The predicate-function
  15276. * pairs are invoked with the `this` binding and arguments of the created
  15277. * function.
  15278. *
  15279. * @static
  15280. * @memberOf _
  15281. * @since 4.0.0
  15282. * @category Util
  15283. * @param {Array} pairs The predicate-function pairs.
  15284. * @returns {Function} Returns the new composite function.
  15285. * @example
  15286. *
  15287. * var func = _.cond([
  15288. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  15289. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  15290. * [_.stubTrue, _.constant('no match')]
  15291. * ]);
  15292. *
  15293. * func({ 'a': 1, 'b': 2 });
  15294. * // => 'matches A'
  15295. *
  15296. * func({ 'a': 0, 'b': 1 });
  15297. * // => 'matches B'
  15298. *
  15299. * func({ 'a': '1', 'b': '2' });
  15300. * // => 'no match'
  15301. */
  15302. function cond(pairs) {
  15303. var length = pairs == null ? 0 : pairs.length,
  15304. toIteratee = getIteratee();
  15305. pairs = !length
  15306. ? []
  15307. : arrayMap(pairs, function(pair) {
  15308. if (typeof pair[1] !== 'function') {
  15309. throw new TypeError(FUNC_ERROR_TEXT);
  15310. }
  15311. return [toIteratee(pair[0]), pair[1]];
  15312. });
  15313. return baseRest(function(args) {
  15314. var index = -1;
  15315. while (++index < length) {
  15316. var pair = pairs[index];
  15317. if (apply(pair[0], this, args)) {
  15318. return apply(pair[1], this, args);
  15319. }
  15320. }
  15321. });
  15322. }
  15323. /**
  15324. * Creates a function that invokes the predicate properties of `source` with
  15325. * the corresponding property values of a given object, returning `true` if
  15326. * all predicates return truthy, else `false`.
  15327. *
  15328. * **Note:** The created function is equivalent to `_.conformsTo` with
  15329. * `source` partially applied.
  15330. *
  15331. * @static
  15332. * @memberOf _
  15333. * @since 4.0.0
  15334. * @category Util
  15335. * @param {Object} source The object of property predicates to conform to.
  15336. * @returns {Function} Returns the new spec function.
  15337. * @example
  15338. *
  15339. * var objects = [
  15340. * { 'a': 2, 'b': 1 },
  15341. * { 'a': 1, 'b': 2 }
  15342. * ];
  15343. *
  15344. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  15345. * // => [{ 'a': 1, 'b': 2 }]
  15346. */
  15347. function conforms(source) {
  15348. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  15349. }
  15350. /**
  15351. * Creates a function that returns `value`.
  15352. *
  15353. * @static
  15354. * @memberOf _
  15355. * @since 2.4.0
  15356. * @category Util
  15357. * @param {*} value The value to return from the new function.
  15358. * @returns {Function} Returns the new constant function.
  15359. * @example
  15360. *
  15361. * var objects = _.times(2, _.constant({ 'a': 1 }));
  15362. *
  15363. * console.log(objects);
  15364. * // => [{ 'a': 1 }, { 'a': 1 }]
  15365. *
  15366. * console.log(objects[0] === objects[1]);
  15367. * // => true
  15368. */
  15369. function constant(value) {
  15370. return function() {
  15371. return value;
  15372. };
  15373. }
  15374. /**
  15375. * Checks `value` to determine whether a default value should be returned in
  15376. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  15377. * or `undefined`.
  15378. *
  15379. * @static
  15380. * @memberOf _
  15381. * @since 4.14.0
  15382. * @category Util
  15383. * @param {*} value The value to check.
  15384. * @param {*} defaultValue The default value.
  15385. * @returns {*} Returns the resolved value.
  15386. * @example
  15387. *
  15388. * _.defaultTo(1, 10);
  15389. * // => 1
  15390. *
  15391. * _.defaultTo(undefined, 10);
  15392. * // => 10
  15393. */
  15394. function defaultTo(value, defaultValue) {
  15395. return value == null || value !== value ? defaultValue : value;
  15396. }
  15397. /**
  15398. * Creates a function that returns the result of invoking the given functions
  15399. * with the `this` binding of the created function, where each successive
  15400. * invocation is supplied the return value of the previous.
  15401. *
  15402. * @static
  15403. * @memberOf _
  15404. * @since 3.0.0
  15405. * @category Util
  15406. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  15407. * @returns {Function} Returns the new composite function.
  15408. * @see _.flowRight
  15409. * @example
  15410. *
  15411. * function square(n) {
  15412. * return n * n;
  15413. * }
  15414. *
  15415. * var addSquare = _.flow([_.add, square]);
  15416. * addSquare(1, 2);
  15417. * // => 9
  15418. */
  15419. var flow = createFlow();
  15420. /**
  15421. * This method is like `_.flow` except that it creates a function that
  15422. * invokes the given functions from right to left.
  15423. *
  15424. * @static
  15425. * @since 3.0.0
  15426. * @memberOf _
  15427. * @category Util
  15428. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  15429. * @returns {Function} Returns the new composite function.
  15430. * @see _.flow
  15431. * @example
  15432. *
  15433. * function square(n) {
  15434. * return n * n;
  15435. * }
  15436. *
  15437. * var addSquare = _.flowRight([square, _.add]);
  15438. * addSquare(1, 2);
  15439. * // => 9
  15440. */
  15441. var flowRight = createFlow(true);
  15442. /**
  15443. * This method returns the first argument it receives.
  15444. *
  15445. * @static
  15446. * @since 0.1.0
  15447. * @memberOf _
  15448. * @category Util
  15449. * @param {*} value Any value.
  15450. * @returns {*} Returns `value`.
  15451. * @example
  15452. *
  15453. * var object = { 'a': 1 };
  15454. *
  15455. * console.log(_.identity(object) === object);
  15456. * // => true
  15457. */
  15458. function identity(value) {
  15459. return value;
  15460. }
  15461. /**
  15462. * Creates a function that invokes `func` with the arguments of the created
  15463. * function. If `func` is a property name, the created function returns the
  15464. * property value for a given element. If `func` is an array or object, the
  15465. * created function returns `true` for elements that contain the equivalent
  15466. * source properties, otherwise it returns `false`.
  15467. *
  15468. * @static
  15469. * @since 4.0.0
  15470. * @memberOf _
  15471. * @category Util
  15472. * @param {*} [func=_.identity] The value to convert to a callback.
  15473. * @returns {Function} Returns the callback.
  15474. * @example
  15475. *
  15476. * var users = [
  15477. * { 'user': 'barney', 'age': 36, 'active': true },
  15478. * { 'user': 'fred', 'age': 40, 'active': false }
  15479. * ];
  15480. *
  15481. * // The `_.matches` iteratee shorthand.
  15482. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  15483. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  15484. *
  15485. * // The `_.matchesProperty` iteratee shorthand.
  15486. * _.filter(users, _.iteratee(['user', 'fred']));
  15487. * // => [{ 'user': 'fred', 'age': 40 }]
  15488. *
  15489. * // The `_.property` iteratee shorthand.
  15490. * _.map(users, _.iteratee('user'));
  15491. * // => ['barney', 'fred']
  15492. *
  15493. * // Create custom iteratee shorthands.
  15494. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  15495. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  15496. * return func.test(string);
  15497. * };
  15498. * });
  15499. *
  15500. * _.filter(['abc', 'def'], /ef/);
  15501. * // => ['def']
  15502. */
  15503. function iteratee(func) {
  15504. return baseIteratee(
  15505. typeof func === 'function' ? func : baseClone(func, CLONE_DEEP_FLAG)
  15506. );
  15507. }
  15508. /**
  15509. * Creates a function that performs a partial deep comparison between a given
  15510. * object and `source`, returning `true` if the given object has equivalent
  15511. * property values, else `false`.
  15512. *
  15513. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  15514. * partially applied.
  15515. *
  15516. * Partial comparisons will match empty array and empty object `source`
  15517. * values against any array or object value, respectively. See `_.isEqual`
  15518. * for a list of supported value comparisons.
  15519. *
  15520. * @static
  15521. * @memberOf _
  15522. * @since 3.0.0
  15523. * @category Util
  15524. * @param {Object} source The object of property values to match.
  15525. * @returns {Function} Returns the new spec function.
  15526. * @example
  15527. *
  15528. * var objects = [
  15529. * { 'a': 1, 'b': 2, 'c': 3 },
  15530. * { 'a': 4, 'b': 5, 'c': 6 }
  15531. * ];
  15532. *
  15533. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  15534. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  15535. */
  15536. function matches(source) {
  15537. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  15538. }
  15539. /**
  15540. * Creates a function that performs a partial deep comparison between the
  15541. * value at `path` of a given object to `srcValue`, returning `true` if the
  15542. * object value is equivalent, else `false`.
  15543. *
  15544. * **Note:** Partial comparisons will match empty array and empty object
  15545. * `srcValue` values against any array or object value, respectively. See
  15546. * `_.isEqual` for a list of supported value comparisons.
  15547. *
  15548. * @static
  15549. * @memberOf _
  15550. * @since 3.2.0
  15551. * @category Util
  15552. * @param {Array|string} path The path of the property to get.
  15553. * @param {*} srcValue The value to match.
  15554. * @returns {Function} Returns the new spec function.
  15555. * @example
  15556. *
  15557. * var objects = [
  15558. * { 'a': 1, 'b': 2, 'c': 3 },
  15559. * { 'a': 4, 'b': 5, 'c': 6 }
  15560. * ];
  15561. *
  15562. * _.find(objects, _.matchesProperty('a', 4));
  15563. * // => { 'a': 4, 'b': 5, 'c': 6 }
  15564. */
  15565. function matchesProperty(path, srcValue) {
  15566. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  15567. }
  15568. /**
  15569. * Creates a function that invokes the method at `path` of a given object.
  15570. * Any additional arguments are provided to the invoked method.
  15571. *
  15572. * @static
  15573. * @memberOf _
  15574. * @since 3.7.0
  15575. * @category Util
  15576. * @param {Array|string} path The path of the method to invoke.
  15577. * @param {...*} [args] The arguments to invoke the method with.
  15578. * @returns {Function} Returns the new invoker function.
  15579. * @example
  15580. *
  15581. * var objects = [
  15582. * { 'a': { 'b': _.constant(2) } },
  15583. * { 'a': { 'b': _.constant(1) } }
  15584. * ];
  15585. *
  15586. * _.map(objects, _.method('a.b'));
  15587. * // => [2, 1]
  15588. *
  15589. * _.map(objects, _.method(['a', 'b']));
  15590. * // => [2, 1]
  15591. */
  15592. var method = baseRest(function(path, args) {
  15593. return function(object) {
  15594. return baseInvoke(object, path, args);
  15595. };
  15596. });
  15597. /**
  15598. * The opposite of `_.method`; this method creates a function that invokes
  15599. * the method at a given path of `object`. Any additional arguments are
  15600. * provided to the invoked method.
  15601. *
  15602. * @static
  15603. * @memberOf _
  15604. * @since 3.7.0
  15605. * @category Util
  15606. * @param {Object} object The object to query.
  15607. * @param {...*} [args] The arguments to invoke the method with.
  15608. * @returns {Function} Returns the new invoker function.
  15609. * @example
  15610. *
  15611. * var array = _.times(3, _.constant),
  15612. * object = { 'a': array, 'b': array, 'c': array };
  15613. *
  15614. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  15615. * // => [2, 0]
  15616. *
  15617. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  15618. * // => [2, 0]
  15619. */
  15620. var methodOf = baseRest(function(object, args) {
  15621. return function(path) {
  15622. return baseInvoke(object, path, args);
  15623. };
  15624. });
  15625. /**
  15626. * Adds all own enumerable string keyed function properties of a source
  15627. * object to the destination object. If `object` is a function, then methods
  15628. * are added to its prototype as well.
  15629. *
  15630. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  15631. * avoid conflicts caused by modifying the original.
  15632. *
  15633. * @static
  15634. * @since 0.1.0
  15635. * @memberOf _
  15636. * @category Util
  15637. * @param {Function|Object} [object=lodash] The destination object.
  15638. * @param {Object} source The object of functions to add.
  15639. * @param {Object} [options={}] The options object.
  15640. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  15641. * @returns {Function|Object} Returns `object`.
  15642. * @example
  15643. *
  15644. * function vowels(string) {
  15645. * return _.filter(string, function(v) {
  15646. * return /[aeiou]/i.test(v);
  15647. * });
  15648. * }
  15649. *
  15650. * _.mixin({ 'vowels': vowels });
  15651. * _.vowels('fred');
  15652. * // => ['e']
  15653. *
  15654. * _('fred').vowels().value();
  15655. * // => ['e']
  15656. *
  15657. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  15658. * _('fred').vowels();
  15659. * // => ['e']
  15660. */
  15661. function mixin(object, source, options) {
  15662. var props = keys(source),
  15663. methodNames = baseFunctions(source, props);
  15664. if (
  15665. options == null &&
  15666. !(isObject(source) && (methodNames.length || !props.length))
  15667. ) {
  15668. options = source;
  15669. source = object;
  15670. object = this;
  15671. methodNames = baseFunctions(source, keys(source));
  15672. }
  15673. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  15674. isFunc = isFunction(object);
  15675. arrayEach(methodNames, function(methodName) {
  15676. var func = source[methodName];
  15677. object[methodName] = func;
  15678. if (isFunc) {
  15679. object.prototype[methodName] = function() {
  15680. var chainAll = this.__chain__;
  15681. if (chain || chainAll) {
  15682. var result = object(this.__wrapped__),
  15683. actions = (result.__actions__ = copyArray(this.__actions__));
  15684. actions.push({ func: func, args: arguments, thisArg: object });
  15685. result.__chain__ = chainAll;
  15686. return result;
  15687. }
  15688. return func.apply(object, arrayPush([this.value()], arguments));
  15689. };
  15690. }
  15691. });
  15692. return object;
  15693. }
  15694. /**
  15695. * Reverts the `_` variable to its previous value and returns a reference to
  15696. * the `lodash` function.
  15697. *
  15698. * @static
  15699. * @since 0.1.0
  15700. * @memberOf _
  15701. * @category Util
  15702. * @returns {Function} Returns the `lodash` function.
  15703. * @example
  15704. *
  15705. * var lodash = _.noConflict();
  15706. */
  15707. function noConflict() {
  15708. if (root._ === this) {
  15709. root._ = oldDash;
  15710. }
  15711. return this;
  15712. }
  15713. /**
  15714. * This method returns `undefined`.
  15715. *
  15716. * @static
  15717. * @memberOf _
  15718. * @since 2.3.0
  15719. * @category Util
  15720. * @example
  15721. *
  15722. * _.times(2, _.noop);
  15723. * // => [undefined, undefined]
  15724. */
  15725. function noop() {
  15726. // No operation performed.
  15727. }
  15728. /**
  15729. * Creates a function that gets the argument at index `n`. If `n` is negative,
  15730. * the nth argument from the end is returned.
  15731. *
  15732. * @static
  15733. * @memberOf _
  15734. * @since 4.0.0
  15735. * @category Util
  15736. * @param {number} [n=0] The index of the argument to return.
  15737. * @returns {Function} Returns the new pass-thru function.
  15738. * @example
  15739. *
  15740. * var func = _.nthArg(1);
  15741. * func('a', 'b', 'c', 'd');
  15742. * // => 'b'
  15743. *
  15744. * var func = _.nthArg(-2);
  15745. * func('a', 'b', 'c', 'd');
  15746. * // => 'c'
  15747. */
  15748. function nthArg(n) {
  15749. n = toInteger(n);
  15750. return baseRest(function(args) {
  15751. return baseNth(args, n);
  15752. });
  15753. }
  15754. /**
  15755. * Creates a function that invokes `iteratees` with the arguments it receives
  15756. * and returns their results.
  15757. *
  15758. * @static
  15759. * @memberOf _
  15760. * @since 4.0.0
  15761. * @category Util
  15762. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  15763. * The iteratees to invoke.
  15764. * @returns {Function} Returns the new function.
  15765. * @example
  15766. *
  15767. * var func = _.over([Math.max, Math.min]);
  15768. *
  15769. * func(1, 2, 3, 4);
  15770. * // => [4, 1]
  15771. */
  15772. var over = createOver(arrayMap);
  15773. /**
  15774. * Creates a function that checks if **all** of the `predicates` return
  15775. * truthy when invoked with the arguments it receives.
  15776. *
  15777. * @static
  15778. * @memberOf _
  15779. * @since 4.0.0
  15780. * @category Util
  15781. * @param {...(Function|Function[])} [predicates=[_.identity]]
  15782. * The predicates to check.
  15783. * @returns {Function} Returns the new function.
  15784. * @example
  15785. *
  15786. * var func = _.overEvery([Boolean, isFinite]);
  15787. *
  15788. * func('1');
  15789. * // => true
  15790. *
  15791. * func(null);
  15792. * // => false
  15793. *
  15794. * func(NaN);
  15795. * // => false
  15796. */
  15797. var overEvery = createOver(arrayEvery);
  15798. /**
  15799. * Creates a function that checks if **any** of the `predicates` return
  15800. * truthy when invoked with the arguments it receives.
  15801. *
  15802. * @static
  15803. * @memberOf _
  15804. * @since 4.0.0
  15805. * @category Util
  15806. * @param {...(Function|Function[])} [predicates=[_.identity]]
  15807. * The predicates to check.
  15808. * @returns {Function} Returns the new function.
  15809. * @example
  15810. *
  15811. * var func = _.overSome([Boolean, isFinite]);
  15812. *
  15813. * func('1');
  15814. * // => true
  15815. *
  15816. * func(null);
  15817. * // => true
  15818. *
  15819. * func(NaN);
  15820. * // => false
  15821. */
  15822. var overSome = createOver(arraySome);
  15823. /**
  15824. * Creates a function that returns the value at `path` of a given object.
  15825. *
  15826. * @static
  15827. * @memberOf _
  15828. * @since 2.4.0
  15829. * @category Util
  15830. * @param {Array|string} path The path of the property to get.
  15831. * @returns {Function} Returns the new accessor function.
  15832. * @example
  15833. *
  15834. * var objects = [
  15835. * { 'a': { 'b': 2 } },
  15836. * { 'a': { 'b': 1 } }
  15837. * ];
  15838. *
  15839. * _.map(objects, _.property('a.b'));
  15840. * // => [2, 1]
  15841. *
  15842. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  15843. * // => [1, 2]
  15844. */
  15845. function property(path) {
  15846. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  15847. }
  15848. /**
  15849. * The opposite of `_.property`; this method creates a function that returns
  15850. * the value at a given path of `object`.
  15851. *
  15852. * @static
  15853. * @memberOf _
  15854. * @since 3.0.0
  15855. * @category Util
  15856. * @param {Object} object The object to query.
  15857. * @returns {Function} Returns the new accessor function.
  15858. * @example
  15859. *
  15860. * var array = [0, 1, 2],
  15861. * object = { 'a': array, 'b': array, 'c': array };
  15862. *
  15863. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15864. * // => [2, 0]
  15865. *
  15866. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15867. * // => [2, 0]
  15868. */
  15869. function propertyOf(object) {
  15870. return function(path) {
  15871. return object == null ? undefined : baseGet(object, path);
  15872. };
  15873. }
  15874. /**
  15875. * Creates an array of numbers (positive and/or negative) progressing from
  15876. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15877. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15878. * it's set to `start` with `start` then set to `0`.
  15879. *
  15880. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15881. * floating-point values which can produce unexpected results.
  15882. *
  15883. * @static
  15884. * @since 0.1.0
  15885. * @memberOf _
  15886. * @category Util
  15887. * @param {number} [start=0] The start of the range.
  15888. * @param {number} end The end of the range.
  15889. * @param {number} [step=1] The value to increment or decrement by.
  15890. * @returns {Array} Returns the range of numbers.
  15891. * @see _.inRange, _.rangeRight
  15892. * @example
  15893. *
  15894. * _.range(4);
  15895. * // => [0, 1, 2, 3]
  15896. *
  15897. * _.range(-4);
  15898. * // => [0, -1, -2, -3]
  15899. *
  15900. * _.range(1, 5);
  15901. * // => [1, 2, 3, 4]
  15902. *
  15903. * _.range(0, 20, 5);
  15904. * // => [0, 5, 10, 15]
  15905. *
  15906. * _.range(0, -4, -1);
  15907. * // => [0, -1, -2, -3]
  15908. *
  15909. * _.range(1, 4, 0);
  15910. * // => [1, 1, 1]
  15911. *
  15912. * _.range(0);
  15913. * // => []
  15914. */
  15915. var range = createRange();
  15916. /**
  15917. * This method is like `_.range` except that it populates values in
  15918. * descending order.
  15919. *
  15920. * @static
  15921. * @memberOf _
  15922. * @since 4.0.0
  15923. * @category Util
  15924. * @param {number} [start=0] The start of the range.
  15925. * @param {number} end The end of the range.
  15926. * @param {number} [step=1] The value to increment or decrement by.
  15927. * @returns {Array} Returns the range of numbers.
  15928. * @see _.inRange, _.range
  15929. * @example
  15930. *
  15931. * _.rangeRight(4);
  15932. * // => [3, 2, 1, 0]
  15933. *
  15934. * _.rangeRight(-4);
  15935. * // => [-3, -2, -1, 0]
  15936. *
  15937. * _.rangeRight(1, 5);
  15938. * // => [4, 3, 2, 1]
  15939. *
  15940. * _.rangeRight(0, 20, 5);
  15941. * // => [15, 10, 5, 0]
  15942. *
  15943. * _.rangeRight(0, -4, -1);
  15944. * // => [-3, -2, -1, 0]
  15945. *
  15946. * _.rangeRight(1, 4, 0);
  15947. * // => [1, 1, 1]
  15948. *
  15949. * _.rangeRight(0);
  15950. * // => []
  15951. */
  15952. var rangeRight = createRange(true);
  15953. /**
  15954. * This method returns a new empty array.
  15955. *
  15956. * @static
  15957. * @memberOf _
  15958. * @since 4.13.0
  15959. * @category Util
  15960. * @returns {Array} Returns the new empty array.
  15961. * @example
  15962. *
  15963. * var arrays = _.times(2, _.stubArray);
  15964. *
  15965. * console.log(arrays);
  15966. * // => [[], []]
  15967. *
  15968. * console.log(arrays[0] === arrays[1]);
  15969. * // => false
  15970. */
  15971. function stubArray() {
  15972. return [];
  15973. }
  15974. /**
  15975. * This method returns `false`.
  15976. *
  15977. * @static
  15978. * @memberOf _
  15979. * @since 4.13.0
  15980. * @category Util
  15981. * @returns {boolean} Returns `false`.
  15982. * @example
  15983. *
  15984. * _.times(2, _.stubFalse);
  15985. * // => [false, false]
  15986. */
  15987. function stubFalse() {
  15988. return false;
  15989. }
  15990. /**
  15991. * This method returns a new empty object.
  15992. *
  15993. * @static
  15994. * @memberOf _
  15995. * @since 4.13.0
  15996. * @category Util
  15997. * @returns {Object} Returns the new empty object.
  15998. * @example
  15999. *
  16000. * var objects = _.times(2, _.stubObject);
  16001. *
  16002. * console.log(objects);
  16003. * // => [{}, {}]
  16004. *
  16005. * console.log(objects[0] === objects[1]);
  16006. * // => false
  16007. */
  16008. function stubObject() {
  16009. return {};
  16010. }
  16011. /**
  16012. * This method returns an empty string.
  16013. *
  16014. * @static
  16015. * @memberOf _
  16016. * @since 4.13.0
  16017. * @category Util
  16018. * @returns {string} Returns the empty string.
  16019. * @example
  16020. *
  16021. * _.times(2, _.stubString);
  16022. * // => ['', '']
  16023. */
  16024. function stubString() {
  16025. return '';
  16026. }
  16027. /**
  16028. * This method returns `true`.
  16029. *
  16030. * @static
  16031. * @memberOf _
  16032. * @since 4.13.0
  16033. * @category Util
  16034. * @returns {boolean} Returns `true`.
  16035. * @example
  16036. *
  16037. * _.times(2, _.stubTrue);
  16038. * // => [true, true]
  16039. */
  16040. function stubTrue() {
  16041. return true;
  16042. }
  16043. /**
  16044. * Invokes the iteratee `n` times, returning an array of the results of
  16045. * each invocation. The iteratee is invoked with one argument; (index).
  16046. *
  16047. * @static
  16048. * @since 0.1.0
  16049. * @memberOf _
  16050. * @category Util
  16051. * @param {number} n The number of times to invoke `iteratee`.
  16052. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  16053. * @returns {Array} Returns the array of results.
  16054. * @example
  16055. *
  16056. * _.times(3, String);
  16057. * // => ['0', '1', '2']
  16058. *
  16059. * _.times(4, _.constant(0));
  16060. * // => [0, 0, 0, 0]
  16061. */
  16062. function times(n, iteratee) {
  16063. n = toInteger(n);
  16064. if (n < 1 || n > MAX_SAFE_INTEGER) {
  16065. return [];
  16066. }
  16067. var index = MAX_ARRAY_LENGTH,
  16068. length = nativeMin(n, MAX_ARRAY_LENGTH);
  16069. iteratee = getIteratee(iteratee);
  16070. n -= MAX_ARRAY_LENGTH;
  16071. var result = baseTimes(length, iteratee);
  16072. while (++index < n) {
  16073. iteratee(index);
  16074. }
  16075. return result;
  16076. }
  16077. /**
  16078. * Converts `value` to a property path array.
  16079. *
  16080. * @static
  16081. * @memberOf _
  16082. * @since 4.0.0
  16083. * @category Util
  16084. * @param {*} value The value to convert.
  16085. * @returns {Array} Returns the new property path array.
  16086. * @example
  16087. *
  16088. * _.toPath('a.b.c');
  16089. * // => ['a', 'b', 'c']
  16090. *
  16091. * _.toPath('a[0].b.c');
  16092. * // => ['a', '0', 'b', 'c']
  16093. */
  16094. function toPath(value) {
  16095. if (isArray(value)) {
  16096. return arrayMap(value, toKey);
  16097. }
  16098. return isSymbol(value)
  16099. ? [value]
  16100. : copyArray(stringToPath(toString(value)));
  16101. }
  16102. /**
  16103. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  16104. *
  16105. * @static
  16106. * @since 0.1.0
  16107. * @memberOf _
  16108. * @category Util
  16109. * @param {string} [prefix=''] The value to prefix the ID with.
  16110. * @returns {string} Returns the unique ID.
  16111. * @example
  16112. *
  16113. * _.uniqueId('contact_');
  16114. * // => 'contact_104'
  16115. *
  16116. * _.uniqueId();
  16117. * // => '105'
  16118. */
  16119. function uniqueId(prefix) {
  16120. var id = ++idCounter;
  16121. return toString(prefix) + id;
  16122. }
  16123. /* ------------------------------------------------------------------------*/
  16124. /**
  16125. * Adds two numbers.
  16126. *
  16127. * @static
  16128. * @memberOf _
  16129. * @since 3.4.0
  16130. * @category Math
  16131. * @param {number} augend The first number in an addition.
  16132. * @param {number} addend The second number in an addition.
  16133. * @returns {number} Returns the total.
  16134. * @example
  16135. *
  16136. * _.add(6, 4);
  16137. * // => 10
  16138. */
  16139. var add = createMathOperation(function(augend, addend) {
  16140. return augend + addend;
  16141. }, 0);
  16142. /**
  16143. * Computes `number` rounded up to `precision`.
  16144. *
  16145. * @static
  16146. * @memberOf _
  16147. * @since 3.10.0
  16148. * @category Math
  16149. * @param {number} number The number to round up.
  16150. * @param {number} [precision=0] The precision to round up to.
  16151. * @returns {number} Returns the rounded up number.
  16152. * @example
  16153. *
  16154. * _.ceil(4.006);
  16155. * // => 5
  16156. *
  16157. * _.ceil(6.004, 2);
  16158. * // => 6.01
  16159. *
  16160. * _.ceil(6040, -2);
  16161. * // => 6100
  16162. */
  16163. var ceil = createRound('ceil');
  16164. /**
  16165. * Divide two numbers.
  16166. *
  16167. * @static
  16168. * @memberOf _
  16169. * @since 4.7.0
  16170. * @category Math
  16171. * @param {number} dividend The first number in a division.
  16172. * @param {number} divisor The second number in a division.
  16173. * @returns {number} Returns the quotient.
  16174. * @example
  16175. *
  16176. * _.divide(6, 4);
  16177. * // => 1.5
  16178. */
  16179. var divide = createMathOperation(function(dividend, divisor) {
  16180. return dividend / divisor;
  16181. }, 1);
  16182. /**
  16183. * Computes `number` rounded down to `precision`.
  16184. *
  16185. * @static
  16186. * @memberOf _
  16187. * @since 3.10.0
  16188. * @category Math
  16189. * @param {number} number The number to round down.
  16190. * @param {number} [precision=0] The precision to round down to.
  16191. * @returns {number} Returns the rounded down number.
  16192. * @example
  16193. *
  16194. * _.floor(4.006);
  16195. * // => 4
  16196. *
  16197. * _.floor(0.046, 2);
  16198. * // => 0.04
  16199. *
  16200. * _.floor(4060, -2);
  16201. * // => 4000
  16202. */
  16203. var floor = createRound('floor');
  16204. /**
  16205. * Computes the maximum value of `array`. If `array` is empty or falsey,
  16206. * `undefined` is returned.
  16207. *
  16208. * @static
  16209. * @since 0.1.0
  16210. * @memberOf _
  16211. * @category Math
  16212. * @param {Array} array The array to iterate over.
  16213. * @returns {*} Returns the maximum value.
  16214. * @example
  16215. *
  16216. * _.max([4, 2, 8, 6]);
  16217. * // => 8
  16218. *
  16219. * _.max([]);
  16220. * // => undefined
  16221. */
  16222. function max(array) {
  16223. return array && array.length
  16224. ? baseExtremum(array, identity, baseGt)
  16225. : undefined;
  16226. }
  16227. /**
  16228. * This method is like `_.max` except that it accepts `iteratee` which is
  16229. * invoked for each element in `array` to generate the criterion by which
  16230. * the value is ranked. The iteratee is invoked with one argument: (value).
  16231. *
  16232. * @static
  16233. * @memberOf _
  16234. * @since 4.0.0
  16235. * @category Math
  16236. * @param {Array} array The array to iterate over.
  16237. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  16238. * @returns {*} Returns the maximum value.
  16239. * @example
  16240. *
  16241. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  16242. *
  16243. * _.maxBy(objects, function(o) { return o.n; });
  16244. * // => { 'n': 2 }
  16245. *
  16246. * // The `_.property` iteratee shorthand.
  16247. * _.maxBy(objects, 'n');
  16248. * // => { 'n': 2 }
  16249. */
  16250. function maxBy(array, iteratee) {
  16251. return array && array.length
  16252. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  16253. : undefined;
  16254. }
  16255. /**
  16256. * Computes the mean of the values in `array`.
  16257. *
  16258. * @static
  16259. * @memberOf _
  16260. * @since 4.0.0
  16261. * @category Math
  16262. * @param {Array} array The array to iterate over.
  16263. * @returns {number} Returns the mean.
  16264. * @example
  16265. *
  16266. * _.mean([4, 2, 8, 6]);
  16267. * // => 5
  16268. */
  16269. function mean(array) {
  16270. return baseMean(array, identity);
  16271. }
  16272. /**
  16273. * This method is like `_.mean` except that it accepts `iteratee` which is
  16274. * invoked for each element in `array` to generate the value to be averaged.
  16275. * The iteratee is invoked with one argument: (value).
  16276. *
  16277. * @static
  16278. * @memberOf _
  16279. * @since 4.7.0
  16280. * @category Math
  16281. * @param {Array} array The array to iterate over.
  16282. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  16283. * @returns {number} Returns the mean.
  16284. * @example
  16285. *
  16286. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  16287. *
  16288. * _.meanBy(objects, function(o) { return o.n; });
  16289. * // => 5
  16290. *
  16291. * // The `_.property` iteratee shorthand.
  16292. * _.meanBy(objects, 'n');
  16293. * // => 5
  16294. */
  16295. function meanBy(array, iteratee) {
  16296. return baseMean(array, getIteratee(iteratee, 2));
  16297. }
  16298. /**
  16299. * Computes the minimum value of `array`. If `array` is empty or falsey,
  16300. * `undefined` is returned.
  16301. *
  16302. * @static
  16303. * @since 0.1.0
  16304. * @memberOf _
  16305. * @category Math
  16306. * @param {Array} array The array to iterate over.
  16307. * @returns {*} Returns the minimum value.
  16308. * @example
  16309. *
  16310. * _.min([4, 2, 8, 6]);
  16311. * // => 2
  16312. *
  16313. * _.min([]);
  16314. * // => undefined
  16315. */
  16316. function min(array) {
  16317. return array && array.length
  16318. ? baseExtremum(array, identity, baseLt)
  16319. : undefined;
  16320. }
  16321. /**
  16322. * This method is like `_.min` except that it accepts `iteratee` which is
  16323. * invoked for each element in `array` to generate the criterion by which
  16324. * the value is ranked. The iteratee is invoked with one argument: (value).
  16325. *
  16326. * @static
  16327. * @memberOf _
  16328. * @since 4.0.0
  16329. * @category Math
  16330. * @param {Array} array The array to iterate over.
  16331. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  16332. * @returns {*} Returns the minimum value.
  16333. * @example
  16334. *
  16335. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  16336. *
  16337. * _.minBy(objects, function(o) { return o.n; });
  16338. * // => { 'n': 1 }
  16339. *
  16340. * // The `_.property` iteratee shorthand.
  16341. * _.minBy(objects, 'n');
  16342. * // => { 'n': 1 }
  16343. */
  16344. function minBy(array, iteratee) {
  16345. return array && array.length
  16346. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  16347. : undefined;
  16348. }
  16349. /**
  16350. * Multiply two numbers.
  16351. *
  16352. * @static
  16353. * @memberOf _
  16354. * @since 4.7.0
  16355. * @category Math
  16356. * @param {number} multiplier The first number in a multiplication.
  16357. * @param {number} multiplicand The second number in a multiplication.
  16358. * @returns {number} Returns the product.
  16359. * @example
  16360. *
  16361. * _.multiply(6, 4);
  16362. * // => 24
  16363. */
  16364. var multiply = createMathOperation(function(multiplier, multiplicand) {
  16365. return multiplier * multiplicand;
  16366. }, 1);
  16367. /**
  16368. * Computes `number` rounded to `precision`.
  16369. *
  16370. * @static
  16371. * @memberOf _
  16372. * @since 3.10.0
  16373. * @category Math
  16374. * @param {number} number The number to round.
  16375. * @param {number} [precision=0] The precision to round to.
  16376. * @returns {number} Returns the rounded number.
  16377. * @example
  16378. *
  16379. * _.round(4.006);
  16380. * // => 4
  16381. *
  16382. * _.round(4.006, 2);
  16383. * // => 4.01
  16384. *
  16385. * _.round(4060, -2);
  16386. * // => 4100
  16387. */
  16388. var round = createRound('round');
  16389. /**
  16390. * Subtract two numbers.
  16391. *
  16392. * @static
  16393. * @memberOf _
  16394. * @since 4.0.0
  16395. * @category Math
  16396. * @param {number} minuend The first number in a subtraction.
  16397. * @param {number} subtrahend The second number in a subtraction.
  16398. * @returns {number} Returns the difference.
  16399. * @example
  16400. *
  16401. * _.subtract(6, 4);
  16402. * // => 2
  16403. */
  16404. var subtract = createMathOperation(function(minuend, subtrahend) {
  16405. return minuend - subtrahend;
  16406. }, 0);
  16407. /**
  16408. * Computes the sum of the values in `array`.
  16409. *
  16410. * @static
  16411. * @memberOf _
  16412. * @since 3.4.0
  16413. * @category Math
  16414. * @param {Array} array The array to iterate over.
  16415. * @returns {number} Returns the sum.
  16416. * @example
  16417. *
  16418. * _.sum([4, 2, 8, 6]);
  16419. * // => 20
  16420. */
  16421. function sum(array) {
  16422. return array && array.length ? baseSum(array, identity) : 0;
  16423. }
  16424. /**
  16425. * This method is like `_.sum` except that it accepts `iteratee` which is
  16426. * invoked for each element in `array` to generate the value to be summed.
  16427. * The iteratee is invoked with one argument: (value).
  16428. *
  16429. * @static
  16430. * @memberOf _
  16431. * @since 4.0.0
  16432. * @category Math
  16433. * @param {Array} array The array to iterate over.
  16434. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  16435. * @returns {number} Returns the sum.
  16436. * @example
  16437. *
  16438. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  16439. *
  16440. * _.sumBy(objects, function(o) { return o.n; });
  16441. * // => 20
  16442. *
  16443. * // The `_.property` iteratee shorthand.
  16444. * _.sumBy(objects, 'n');
  16445. * // => 20
  16446. */
  16447. function sumBy(array, iteratee) {
  16448. return array && array.length
  16449. ? baseSum(array, getIteratee(iteratee, 2))
  16450. : 0;
  16451. }
  16452. /* ------------------------------------------------------------------------*/
  16453. // Add methods that return wrapped values in chain sequences.
  16454. lodash.after = after;
  16455. lodash.ary = ary;
  16456. lodash.assign = assign;
  16457. lodash.assignIn = assignIn;
  16458. lodash.assignInWith = assignInWith;
  16459. lodash.assignWith = assignWith;
  16460. lodash.at = at;
  16461. lodash.before = before;
  16462. lodash.bind = bind;
  16463. lodash.bindAll = bindAll;
  16464. lodash.bindKey = bindKey;
  16465. lodash.castArray = castArray;
  16466. lodash.chain = chain;
  16467. lodash.chunk = chunk;
  16468. lodash.compact = compact;
  16469. lodash.concat = concat;
  16470. lodash.cond = cond;
  16471. lodash.conforms = conforms;
  16472. lodash.constant = constant;
  16473. lodash.countBy = countBy;
  16474. lodash.create = create;
  16475. lodash.curry = curry;
  16476. lodash.curryRight = curryRight;
  16477. lodash.debounce = debounce;
  16478. lodash.defaults = defaults;
  16479. lodash.defaultsDeep = defaultsDeep;
  16480. lodash.defer = defer;
  16481. lodash.delay = delay;
  16482. lodash.difference = difference;
  16483. lodash.differenceBy = differenceBy;
  16484. lodash.differenceWith = differenceWith;
  16485. lodash.drop = drop;
  16486. lodash.dropRight = dropRight;
  16487. lodash.dropRightWhile = dropRightWhile;
  16488. lodash.dropWhile = dropWhile;
  16489. lodash.fill = fill;
  16490. lodash.filter = filter;
  16491. lodash.flatMap = flatMap;
  16492. lodash.flatMapDeep = flatMapDeep;
  16493. lodash.flatMapDepth = flatMapDepth;
  16494. lodash.flatten = flatten;
  16495. lodash.flattenDeep = flattenDeep;
  16496. lodash.flattenDepth = flattenDepth;
  16497. lodash.flip = flip;
  16498. lodash.flow = flow;
  16499. lodash.flowRight = flowRight;
  16500. lodash.fromPairs = fromPairs;
  16501. lodash.functions = functions;
  16502. lodash.functionsIn = functionsIn;
  16503. lodash.groupBy = groupBy;
  16504. lodash.initial = initial;
  16505. lodash.intersection = intersection;
  16506. lodash.intersectionBy = intersectionBy;
  16507. lodash.intersectionWith = intersectionWith;
  16508. lodash.invert = invert;
  16509. lodash.invertBy = invertBy;
  16510. lodash.invokeMap = invokeMap;
  16511. lodash.iteratee = iteratee;
  16512. lodash.keyBy = keyBy;
  16513. lodash.keys = keys;
  16514. lodash.keysIn = keysIn;
  16515. lodash.map = map;
  16516. lodash.mapKeys = mapKeys;
  16517. lodash.mapValues = mapValues;
  16518. lodash.matches = matches;
  16519. lodash.matchesProperty = matchesProperty;
  16520. lodash.memoize = memoize;
  16521. lodash.merge = merge;
  16522. lodash.mergeWith = mergeWith;
  16523. lodash.method = method;
  16524. lodash.methodOf = methodOf;
  16525. lodash.mixin = mixin;
  16526. lodash.negate = negate;
  16527. lodash.nthArg = nthArg;
  16528. lodash.omit = omit;
  16529. lodash.omitBy = omitBy;
  16530. lodash.once = once;
  16531. lodash.orderBy = orderBy;
  16532. lodash.over = over;
  16533. lodash.overArgs = overArgs;
  16534. lodash.overEvery = overEvery;
  16535. lodash.overSome = overSome;
  16536. lodash.partial = partial;
  16537. lodash.partialRight = partialRight;
  16538. lodash.partition = partition;
  16539. lodash.pick = pick;
  16540. lodash.pickBy = pickBy;
  16541. lodash.property = property;
  16542. lodash.propertyOf = propertyOf;
  16543. lodash.pull = pull;
  16544. lodash.pullAll = pullAll;
  16545. lodash.pullAllBy = pullAllBy;
  16546. lodash.pullAllWith = pullAllWith;
  16547. lodash.pullAt = pullAt;
  16548. lodash.range = range;
  16549. lodash.rangeRight = rangeRight;
  16550. lodash.rearg = rearg;
  16551. lodash.reject = reject;
  16552. lodash.remove = remove;
  16553. lodash.rest = rest;
  16554. lodash.reverse = reverse;
  16555. lodash.sampleSize = sampleSize;
  16556. lodash.set = set;
  16557. lodash.setWith = setWith;
  16558. lodash.shuffle = shuffle;
  16559. lodash.slice = slice;
  16560. lodash.sortBy = sortBy;
  16561. lodash.sortedUniq = sortedUniq;
  16562. lodash.sortedUniqBy = sortedUniqBy;
  16563. lodash.split = split;
  16564. lodash.spread = spread;
  16565. lodash.tail = tail;
  16566. lodash.take = take;
  16567. lodash.takeRight = takeRight;
  16568. lodash.takeRightWhile = takeRightWhile;
  16569. lodash.takeWhile = takeWhile;
  16570. lodash.tap = tap;
  16571. lodash.throttle = throttle;
  16572. lodash.thru = thru;
  16573. lodash.toArray = toArray;
  16574. lodash.toPairs = toPairs;
  16575. lodash.toPairsIn = toPairsIn;
  16576. lodash.toPath = toPath;
  16577. lodash.toPlainObject = toPlainObject;
  16578. lodash.transform = transform;
  16579. lodash.unary = unary;
  16580. lodash.union = union;
  16581. lodash.unionBy = unionBy;
  16582. lodash.unionWith = unionWith;
  16583. lodash.uniq = uniq;
  16584. lodash.uniqBy = uniqBy;
  16585. lodash.uniqWith = uniqWith;
  16586. lodash.unset = unset;
  16587. lodash.unzip = unzip;
  16588. lodash.unzipWith = unzipWith;
  16589. lodash.update = update;
  16590. lodash.updateWith = updateWith;
  16591. lodash.values = values;
  16592. lodash.valuesIn = valuesIn;
  16593. lodash.without = without;
  16594. lodash.words = words;
  16595. lodash.wrap = wrap;
  16596. lodash.xor = xor;
  16597. lodash.xorBy = xorBy;
  16598. lodash.xorWith = xorWith;
  16599. lodash.zip = zip;
  16600. lodash.zipObject = zipObject;
  16601. lodash.zipObjectDeep = zipObjectDeep;
  16602. lodash.zipWith = zipWith;
  16603. // Add aliases.
  16604. lodash.entries = toPairs;
  16605. lodash.entriesIn = toPairsIn;
  16606. lodash.extend = assignIn;
  16607. lodash.extendWith = assignInWith;
  16608. // Add methods to `lodash.prototype`.
  16609. mixin(lodash, lodash);
  16610. /* ------------------------------------------------------------------------*/
  16611. // Add methods that return unwrapped values in chain sequences.
  16612. lodash.add = add;
  16613. lodash.attempt = attempt;
  16614. lodash.camelCase = camelCase;
  16615. lodash.capitalize = capitalize;
  16616. lodash.ceil = ceil;
  16617. lodash.clamp = clamp;
  16618. lodash.clone = clone;
  16619. lodash.cloneDeep = cloneDeep;
  16620. lodash.cloneDeepWith = cloneDeepWith;
  16621. lodash.cloneWith = cloneWith;
  16622. lodash.conformsTo = conformsTo;
  16623. lodash.deburr = deburr;
  16624. lodash.defaultTo = defaultTo;
  16625. lodash.divide = divide;
  16626. lodash.endsWith = endsWith;
  16627. lodash.eq = eq;
  16628. lodash.escape = escape;
  16629. lodash.escapeRegExp = escapeRegExp;
  16630. lodash.every = every;
  16631. lodash.find = find;
  16632. lodash.findIndex = findIndex;
  16633. lodash.findKey = findKey;
  16634. lodash.findLast = findLast;
  16635. lodash.findLastIndex = findLastIndex;
  16636. lodash.findLastKey = findLastKey;
  16637. lodash.floor = floor;
  16638. lodash.forEach = forEach;
  16639. lodash.forEachRight = forEachRight;
  16640. lodash.forIn = forIn;
  16641. lodash.forInRight = forInRight;
  16642. lodash.forOwn = forOwn;
  16643. lodash.forOwnRight = forOwnRight;
  16644. lodash.get = get;
  16645. lodash.gt = gt;
  16646. lodash.gte = gte;
  16647. lodash.has = has;
  16648. lodash.hasIn = hasIn;
  16649. lodash.head = head;
  16650. lodash.identity = identity;
  16651. lodash.includes = includes;
  16652. lodash.indexOf = indexOf;
  16653. lodash.inRange = inRange;
  16654. lodash.invoke = invoke;
  16655. lodash.isArguments = isArguments;
  16656. lodash.isArray = isArray;
  16657. lodash.isArrayBuffer = isArrayBuffer;
  16658. lodash.isArrayLike = isArrayLike;
  16659. lodash.isArrayLikeObject = isArrayLikeObject;
  16660. lodash.isBoolean = isBoolean;
  16661. lodash.isBuffer = isBuffer;
  16662. lodash.isDate = isDate;
  16663. lodash.isElement = isElement;
  16664. lodash.isEmpty = isEmpty;
  16665. lodash.isEqual = isEqual;
  16666. lodash.isEqualWith = isEqualWith;
  16667. lodash.isError = isError;
  16668. lodash.isFinite = isFinite;
  16669. lodash.isFunction = isFunction;
  16670. lodash.isInteger = isInteger;
  16671. lodash.isLength = isLength;
  16672. lodash.isMap = isMap;
  16673. lodash.isMatch = isMatch;
  16674. lodash.isMatchWith = isMatchWith;
  16675. lodash.isNaN = isNaN;
  16676. lodash.isNative = isNative;
  16677. lodash.isNil = isNil;
  16678. lodash.isNull = isNull;
  16679. lodash.isNumber = isNumber;
  16680. lodash.isObject = isObject;
  16681. lodash.isObjectLike = isObjectLike;
  16682. lodash.isPlainObject = isPlainObject;
  16683. lodash.isRegExp = isRegExp;
  16684. lodash.isSafeInteger = isSafeInteger;
  16685. lodash.isSet = isSet;
  16686. lodash.isString = isString;
  16687. lodash.isSymbol = isSymbol;
  16688. lodash.isTypedArray = isTypedArray;
  16689. lodash.isUndefined = isUndefined;
  16690. lodash.isWeakMap = isWeakMap;
  16691. lodash.isWeakSet = isWeakSet;
  16692. lodash.join = join;
  16693. lodash.kebabCase = kebabCase;
  16694. lodash.last = last;
  16695. lodash.lastIndexOf = lastIndexOf;
  16696. lodash.lowerCase = lowerCase;
  16697. lodash.lowerFirst = lowerFirst;
  16698. lodash.lt = lt;
  16699. lodash.lte = lte;
  16700. lodash.max = max;
  16701. lodash.maxBy = maxBy;
  16702. lodash.mean = mean;
  16703. lodash.meanBy = meanBy;
  16704. lodash.min = min;
  16705. lodash.minBy = minBy;
  16706. lodash.stubArray = stubArray;
  16707. lodash.stubFalse = stubFalse;
  16708. lodash.stubObject = stubObject;
  16709. lodash.stubString = stubString;
  16710. lodash.stubTrue = stubTrue;
  16711. lodash.multiply = multiply;
  16712. lodash.nth = nth;
  16713. lodash.noConflict = noConflict;
  16714. lodash.noop = noop;
  16715. lodash.now = now;
  16716. lodash.pad = pad;
  16717. lodash.padEnd = padEnd;
  16718. lodash.padStart = padStart;
  16719. lodash.parseInt = parseInt;
  16720. lodash.random = random;
  16721. lodash.reduce = reduce;
  16722. lodash.reduceRight = reduceRight;
  16723. lodash.repeat = repeat;
  16724. lodash.replace = replace;
  16725. lodash.result = result;
  16726. lodash.round = round;
  16727. lodash.runInContext = runInContext;
  16728. lodash.sample = sample;
  16729. lodash.size = size;
  16730. lodash.snakeCase = snakeCase;
  16731. lodash.some = some;
  16732. lodash.sortedIndex = sortedIndex;
  16733. lodash.sortedIndexBy = sortedIndexBy;
  16734. lodash.sortedIndexOf = sortedIndexOf;
  16735. lodash.sortedLastIndex = sortedLastIndex;
  16736. lodash.sortedLastIndexBy = sortedLastIndexBy;
  16737. lodash.sortedLastIndexOf = sortedLastIndexOf;
  16738. lodash.startCase = startCase;
  16739. lodash.startsWith = startsWith;
  16740. lodash.subtract = subtract;
  16741. lodash.sum = sum;
  16742. lodash.sumBy = sumBy;
  16743. lodash.template = template;
  16744. lodash.times = times;
  16745. lodash.toFinite = toFinite;
  16746. lodash.toInteger = toInteger;
  16747. lodash.toLength = toLength;
  16748. lodash.toLower = toLower;
  16749. lodash.toNumber = toNumber;
  16750. lodash.toSafeInteger = toSafeInteger;
  16751. lodash.toString = toString;
  16752. lodash.toUpper = toUpper;
  16753. lodash.trim = trim;
  16754. lodash.trimEnd = trimEnd;
  16755. lodash.trimStart = trimStart;
  16756. lodash.truncate = truncate;
  16757. lodash.unescape = unescape;
  16758. lodash.uniqueId = uniqueId;
  16759. lodash.upperCase = upperCase;
  16760. lodash.upperFirst = upperFirst;
  16761. // Add aliases.
  16762. lodash.each = forEach;
  16763. lodash.eachRight = forEachRight;
  16764. lodash.first = head;
  16765. mixin(
  16766. lodash,
  16767. (function() {
  16768. var source = {};
  16769. baseForOwn(lodash, function(func, methodName) {
  16770. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  16771. source[methodName] = func;
  16772. }
  16773. });
  16774. return source;
  16775. })(),
  16776. { chain: false }
  16777. );
  16778. /* ------------------------------------------------------------------------*/
  16779. /**
  16780. * The semantic version number.
  16781. *
  16782. * @static
  16783. * @memberOf _
  16784. * @type {string}
  16785. */
  16786. lodash.VERSION = VERSION;
  16787. // Assign default placeholders.
  16788. arrayEach(
  16789. ['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'],
  16790. function(methodName) {
  16791. lodash[methodName].placeholder = lodash;
  16792. }
  16793. );
  16794. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  16795. arrayEach(['drop', 'take'], function(methodName, index) {
  16796. LazyWrapper.prototype[methodName] = function(n) {
  16797. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  16798. var result =
  16799. this.__filtered__ && !index ? new LazyWrapper(this) : this.clone();
  16800. if (result.__filtered__) {
  16801. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  16802. } else {
  16803. result.__views__.push({
  16804. size: nativeMin(n, MAX_ARRAY_LENGTH),
  16805. type: methodName + (result.__dir__ < 0 ? 'Right' : '')
  16806. });
  16807. }
  16808. return result;
  16809. };
  16810. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  16811. return this.reverse()
  16812. [methodName](n)
  16813. .reverse();
  16814. };
  16815. });
  16816. // Add `LazyWrapper` methods that accept an `iteratee` value.
  16817. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  16818. var type = index + 1,
  16819. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  16820. LazyWrapper.prototype[methodName] = function(iteratee) {
  16821. var result = this.clone();
  16822. result.__iteratees__.push({
  16823. iteratee: getIteratee(iteratee, 3),
  16824. type: type
  16825. });
  16826. result.__filtered__ = result.__filtered__ || isFilter;
  16827. return result;
  16828. };
  16829. });
  16830. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  16831. arrayEach(['head', 'last'], function(methodName, index) {
  16832. var takeName = 'take' + (index ? 'Right' : '');
  16833. LazyWrapper.prototype[methodName] = function() {
  16834. return this[takeName](1).value()[0];
  16835. };
  16836. });
  16837. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  16838. arrayEach(['initial', 'tail'], function(methodName, index) {
  16839. var dropName = 'drop' + (index ? '' : 'Right');
  16840. LazyWrapper.prototype[methodName] = function() {
  16841. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  16842. };
  16843. });
  16844. LazyWrapper.prototype.compact = function() {
  16845. return this.filter(identity);
  16846. };
  16847. LazyWrapper.prototype.find = function(predicate) {
  16848. return this.filter(predicate).head();
  16849. };
  16850. LazyWrapper.prototype.findLast = function(predicate) {
  16851. return this.reverse().find(predicate);
  16852. };
  16853. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  16854. if (typeof path === 'function') {
  16855. return new LazyWrapper(this);
  16856. }
  16857. return this.map(function(value) {
  16858. return baseInvoke(value, path, args);
  16859. });
  16860. });
  16861. LazyWrapper.prototype.reject = function(predicate) {
  16862. return this.filter(negate(getIteratee(predicate)));
  16863. };
  16864. LazyWrapper.prototype.slice = function(start, end) {
  16865. start = toInteger(start);
  16866. var result = this;
  16867. if (result.__filtered__ && (start > 0 || end < 0)) {
  16868. return new LazyWrapper(result);
  16869. }
  16870. if (start < 0) {
  16871. result = result.takeRight(-start);
  16872. } else if (start) {
  16873. result = result.drop(start);
  16874. }
  16875. if (end !== undefined) {
  16876. end = toInteger(end);
  16877. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16878. }
  16879. return result;
  16880. };
  16881. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16882. return this.reverse()
  16883. .takeWhile(predicate)
  16884. .reverse();
  16885. };
  16886. LazyWrapper.prototype.toArray = function() {
  16887. return this.take(MAX_ARRAY_LENGTH);
  16888. };
  16889. // Add `LazyWrapper` methods to `lodash.prototype`.
  16890. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16891. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16892. isTaker = /^(?:head|last)$/.test(methodName),
  16893. lodashFunc =
  16894. lodash[
  16895. isTaker
  16896. ? 'take' + (methodName == 'last' ? 'Right' : '')
  16897. : methodName
  16898. ],
  16899. retUnwrapped = isTaker || /^find/.test(methodName);
  16900. if (!lodashFunc) {
  16901. return;
  16902. }
  16903. lodash.prototype[methodName] = function() {
  16904. var value = this.__wrapped__,
  16905. args = isTaker ? [1] : arguments,
  16906. isLazy = value instanceof LazyWrapper,
  16907. iteratee = args[0],
  16908. useLazy = isLazy || isArray(value);
  16909. var interceptor = function(value) {
  16910. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16911. return isTaker && chainAll ? result[0] : result;
  16912. };
  16913. if (
  16914. useLazy &&
  16915. checkIteratee &&
  16916. typeof iteratee === 'function' &&
  16917. iteratee.length != 1
  16918. ) {
  16919. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16920. isLazy = useLazy = false;
  16921. }
  16922. var chainAll = this.__chain__,
  16923. isHybrid = !!this.__actions__.length,
  16924. isUnwrapped = retUnwrapped && !chainAll,
  16925. onlyLazy = isLazy && !isHybrid;
  16926. if (!retUnwrapped && useLazy) {
  16927. value = onlyLazy ? value : new LazyWrapper(this);
  16928. var result = func.apply(value, args);
  16929. result.__actions__.push({
  16930. func: thru,
  16931. args: [interceptor],
  16932. thisArg: undefined
  16933. });
  16934. return new LodashWrapper(result, chainAll);
  16935. }
  16936. if (isUnwrapped && onlyLazy) {
  16937. return func.apply(this, args);
  16938. }
  16939. result = this.thru(interceptor);
  16940. return isUnwrapped
  16941. ? isTaker
  16942. ? result.value()[0]
  16943. : result.value()
  16944. : result;
  16945. };
  16946. });
  16947. // Add `Array` methods to `lodash.prototype`.
  16948. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(
  16949. methodName
  16950. ) {
  16951. var func = arrayProto[methodName],
  16952. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16953. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16954. lodash.prototype[methodName] = function() {
  16955. var args = arguments;
  16956. if (retUnwrapped && !this.__chain__) {
  16957. var value = this.value();
  16958. return func.apply(isArray(value) ? value : [], args);
  16959. }
  16960. return this[chainName](function(value) {
  16961. return func.apply(isArray(value) ? value : [], args);
  16962. });
  16963. };
  16964. });
  16965. // Map minified method names to their real names.
  16966. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16967. var lodashFunc = lodash[methodName];
  16968. if (lodashFunc) {
  16969. var key = lodashFunc.name + '',
  16970. names = realNames[key] || (realNames[key] = []);
  16971. names.push({ name: methodName, func: lodashFunc });
  16972. }
  16973. });
  16974. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [
  16975. {
  16976. name: 'wrapper',
  16977. func: undefined
  16978. }
  16979. ];
  16980. // Add methods to `LazyWrapper`.
  16981. LazyWrapper.prototype.clone = lazyClone;
  16982. LazyWrapper.prototype.reverse = lazyReverse;
  16983. LazyWrapper.prototype.value = lazyValue;
  16984. // Add chain sequence methods to the `lodash` wrapper.
  16985. lodash.prototype.at = wrapperAt;
  16986. lodash.prototype.chain = wrapperChain;
  16987. lodash.prototype.commit = wrapperCommit;
  16988. lodash.prototype.next = wrapperNext;
  16989. lodash.prototype.plant = wrapperPlant;
  16990. lodash.prototype.reverse = wrapperReverse;
  16991. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16992. // Add lazy aliases.
  16993. lodash.prototype.first = lodash.prototype.head;
  16994. if (symIterator) {
  16995. lodash.prototype[symIterator] = wrapperToIterator;
  16996. }
  16997. return lodash;
  16998. };
  16999. /* --------------------------------------------------------------------------*/
  17000. // Export lodash.
  17001. var _ = runInContext();
  17002. // Some AMD build optimizers, like r.js, check for condition patterns like:
  17003. if (
  17004. typeof define === 'function' &&
  17005. typeof define.amd === 'object' &&
  17006. define.amd
  17007. ) {
  17008. // Expose Lodash on the global object to prevent errors when Lodash is
  17009. // loaded by a script tag in the presence of an AMD loader.
  17010. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  17011. // Use `_.noConflict` to remove Lodash from the global object.
  17012. root._ = _;
  17013. // Define as an anonymous module so, through path mapping, it can be
  17014. // referenced as the "underscore" module.
  17015. define(function() {
  17016. return _;
  17017. });
  17018. }
  17019. // Check for `exports` after `define` in case a build optimizer adds it.
  17020. else if (freeModule) {
  17021. // Export for Node.js.
  17022. (freeModule.exports = _)._ = _;
  17023. // Export for CommonJS support.
  17024. freeExports._ = _;
  17025. } else {
  17026. // Export to the global object.
  17027. root._ = _;
  17028. }
  17029. }.call(this));