lodash.js 533 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.18.1';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function',
  19. INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`',
  20. INVALID_TEMPL_IMPORTS_ERROR_TEXT = 'Invalid `imports` option passed into `_.template`';
  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.7976931348623157e+308,
  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 whitespace. */
  134. var reTrimStart = /^\s+/;
  135. /** Used to match a single whitespace character. */
  136. var reWhitespace = /\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. /**
  144. * Used to validate the `validate` option in `_.template` variable.
  145. *
  146. * Forbids characters which could potentially change the meaning of the function argument definition:
  147. * - "()," (modification of function parameters)
  148. * - "=" (default value)
  149. * - "[]{}" (destructuring of function parameters)
  150. * - "/" (beginning of a comment)
  151. * - whitespace
  152. */
  153. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  154. /** Used to match backslashes in property paths. */
  155. var reEscapeChar = /\\(\\)?/g;
  156. /**
  157. * Used to match
  158. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  159. */
  160. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  161. /** Used to match `RegExp` flags from their coerced string values. */
  162. var reFlags = /\w*$/;
  163. /** Used to detect bad signed hexadecimal string values. */
  164. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  165. /** Used to detect binary string values. */
  166. var reIsBinary = /^0b[01]+$/i;
  167. /** Used to detect host constructors (Safari). */
  168. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  169. /** Used to detect octal string values. */
  170. var reIsOctal = /^0o[0-7]+$/i;
  171. /** Used to detect unsigned integer values. */
  172. var reIsUint = /^(?:0|[1-9]\d*)$/;
  173. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  174. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  175. /** Used to ensure capturing order of template delimiters. */
  176. var reNoMatch = /($^)/;
  177. /** Used to match unescaped characters in compiled string literals. */
  178. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  179. /** Used to compose unicode character classes. */
  180. var rsAstralRange = '\\ud800-\\udfff',
  181. rsComboMarksRange = '\\u0300-\\u036f',
  182. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  183. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  184. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  185. rsDingbatRange = '\\u2700-\\u27bf',
  186. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  187. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  188. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  189. rsPunctuationRange = '\\u2000-\\u206f',
  190. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  191. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  192. rsVarRange = '\\ufe0e\\ufe0f',
  193. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  194. /** Used to compose unicode capture groups. */
  195. var rsApos = "['\u2019]",
  196. rsAstral = '[' + rsAstralRange + ']',
  197. rsBreak = '[' + rsBreakRange + ']',
  198. rsCombo = '[' + rsComboRange + ']',
  199. rsDigits = '\\d+',
  200. rsDingbat = '[' + rsDingbatRange + ']',
  201. rsLower = '[' + rsLowerRange + ']',
  202. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  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 = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  218. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  219. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  220. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  221. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  222. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  223. /** Used to match apostrophes. */
  224. var reApos = RegExp(rsApos, 'g');
  225. /**
  226. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  227. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  228. */
  229. var reComboMark = RegExp(rsCombo, 'g');
  230. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  231. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  232. /** Used to match complex or compound words. */
  233. var reUnicodeWord = RegExp([
  234. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  235. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  236. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  237. rsUpper + '+' + rsOptContrUpper,
  238. rsOrdUpper,
  239. rsOrdLower,
  240. rsDigits,
  241. rsEmoji
  242. ].join('|'), 'g');
  243. /** 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/). */
  244. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  245. /** Used to detect strings that need a more robust regexp to match words. */
  246. 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 ]/;
  247. /** Used to assign default `context` object properties. */
  248. var contextProps = [
  249. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  250. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  251. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  252. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  253. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  254. ];
  255. /** Used to make template sourceURLs easier to identify. */
  256. var templateCounter = -1;
  257. /** Used to identify `toStringTag` values of typed arrays. */
  258. var typedArrayTags = {};
  259. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  260. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  261. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  262. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  263. typedArrayTags[uint32Tag] = true;
  264. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  265. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  266. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  267. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  268. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  269. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  270. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  271. typedArrayTags[weakMapTag] = false;
  272. /** Used to identify `toStringTag` values supported by `_.clone`. */
  273. var cloneableTags = {};
  274. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  275. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  276. cloneableTags[boolTag] = cloneableTags[dateTag] =
  277. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  278. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  279. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  280. cloneableTags[numberTag] = cloneableTags[objectTag] =
  281. cloneableTags[regexpTag] = cloneableTags[setTag] =
  282. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  283. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  284. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  285. cloneableTags[errorTag] = cloneableTags[funcTag] =
  286. cloneableTags[weakMapTag] = false;
  287. /** Used to map Latin Unicode letters to basic Latin letters. */
  288. var deburredLetters = {
  289. // Latin-1 Supplement block.
  290. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  291. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  292. '\xc7': 'C', '\xe7': 'c',
  293. '\xd0': 'D', '\xf0': 'd',
  294. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  295. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  296. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  297. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  298. '\xd1': 'N', '\xf1': 'n',
  299. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  300. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  301. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  302. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  303. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  304. '\xc6': 'Ae', '\xe6': 'ae',
  305. '\xde': 'Th', '\xfe': 'th',
  306. '\xdf': 'ss',
  307. // Latin Extended-A block.
  308. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  309. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  310. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  311. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  312. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  313. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  314. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  315. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  316. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  317. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  318. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  319. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  320. '\u0134': 'J', '\u0135': 'j',
  321. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  322. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  323. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  324. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  325. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  326. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  327. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  328. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  329. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  330. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  331. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  332. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  333. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  334. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  335. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  336. '\u0174': 'W', '\u0175': 'w',
  337. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  338. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  339. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  340. '\u0132': 'IJ', '\u0133': 'ij',
  341. '\u0152': 'Oe', '\u0153': 'oe',
  342. '\u0149': "'n", '\u017f': 's'
  343. };
  344. /** Used to map characters to HTML entities. */
  345. var htmlEscapes = {
  346. '&': '&amp;',
  347. '<': '&lt;',
  348. '>': '&gt;',
  349. '"': '&quot;',
  350. "'": '&#39;'
  351. };
  352. /** Used to map HTML entities to characters. */
  353. var htmlUnescapes = {
  354. '&amp;': '&',
  355. '&lt;': '<',
  356. '&gt;': '>',
  357. '&quot;': '"',
  358. '&#39;': "'"
  359. };
  360. /** Used to escape characters for inclusion in compiled string literals. */
  361. var stringEscapes = {
  362. '\\': '\\',
  363. "'": "'",
  364. '\n': 'n',
  365. '\r': 'r',
  366. '\u2028': 'u2028',
  367. '\u2029': 'u2029'
  368. };
  369. /** Built-in method references without a dependency on `root`. */
  370. var freeParseFloat = parseFloat,
  371. freeParseInt = parseInt;
  372. /** Detect free variable `global` from Node.js. */
  373. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  374. /** Detect free variable `self`. */
  375. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  376. /** Used as a reference to the global object. */
  377. var root = freeGlobal || freeSelf || Function('return this')();
  378. /** Detect free variable `exports`. */
  379. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  380. /** Detect free variable `module`. */
  381. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  382. /** Detect the popular CommonJS extension `module.exports`. */
  383. var moduleExports = freeModule && freeModule.exports === freeExports;
  384. /** Detect free variable `process` from Node.js. */
  385. var freeProcess = moduleExports && freeGlobal.process;
  386. /** Used to access faster Node.js helpers. */
  387. var nodeUtil = (function() {
  388. try {
  389. // Use `util.types` for Node.js 10+.
  390. var types = freeModule && freeModule.require && freeModule.require('util').types;
  391. if (types) {
  392. return types;
  393. }
  394. // Legacy `process.binding('util')` for Node.js < 10.
  395. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  396. } catch (e) {}
  397. }());
  398. /* Node.js helper references. */
  399. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  400. nodeIsDate = nodeUtil && nodeUtil.isDate,
  401. nodeIsMap = nodeUtil && nodeUtil.isMap,
  402. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  403. nodeIsSet = nodeUtil && nodeUtil.isSet,
  404. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  405. /*--------------------------------------------------------------------------*/
  406. /**
  407. * A faster alternative to `Function#apply`, this function invokes `func`
  408. * with the `this` binding of `thisArg` and the arguments of `args`.
  409. *
  410. * @private
  411. * @param {Function} func The function to invoke.
  412. * @param {*} thisArg The `this` binding of `func`.
  413. * @param {Array} args The arguments to invoke `func` with.
  414. * @returns {*} Returns the result of `func`.
  415. */
  416. function apply(func, thisArg, args) {
  417. switch (args.length) {
  418. case 0: return func.call(thisArg);
  419. case 1: return func.call(thisArg, args[0]);
  420. case 2: return func.call(thisArg, args[0], args[1]);
  421. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  422. }
  423. return func.apply(thisArg, args);
  424. }
  425. /**
  426. * A specialized version of `baseAggregator` for arrays.
  427. *
  428. * @private
  429. * @param {Array} [array] The array to iterate over.
  430. * @param {Function} setter The function to set `accumulator` values.
  431. * @param {Function} iteratee The iteratee to transform keys.
  432. * @param {Object} accumulator The initial aggregated object.
  433. * @returns {Function} Returns `accumulator`.
  434. */
  435. function arrayAggregator(array, setter, iteratee, accumulator) {
  436. var index = -1,
  437. length = array == null ? 0 : array.length;
  438. while (++index < length) {
  439. var value = array[index];
  440. setter(accumulator, value, iteratee(value), array);
  441. }
  442. return accumulator;
  443. }
  444. /**
  445. * A specialized version of `_.forEach` for arrays without support for
  446. * iteratee shorthands.
  447. *
  448. * @private
  449. * @param {Array} [array] The array to iterate over.
  450. * @param {Function} iteratee The function invoked per iteration.
  451. * @returns {Array} Returns `array`.
  452. */
  453. function arrayEach(array, iteratee) {
  454. var index = -1,
  455. length = array == null ? 0 : array.length;
  456. while (++index < length) {
  457. if (iteratee(array[index], index, array) === false) {
  458. break;
  459. }
  460. }
  461. return array;
  462. }
  463. /**
  464. * A specialized version of `_.forEachRight` for arrays without support for
  465. * iteratee shorthands.
  466. *
  467. * @private
  468. * @param {Array} [array] The array to iterate over.
  469. * @param {Function} iteratee The function invoked per iteration.
  470. * @returns {Array} Returns `array`.
  471. */
  472. function arrayEachRight(array, iteratee) {
  473. var length = array == null ? 0 : array.length;
  474. while (length--) {
  475. if (iteratee(array[length], length, array) === false) {
  476. break;
  477. }
  478. }
  479. return array;
  480. }
  481. /**
  482. * A specialized version of `_.every` for arrays without support for
  483. * iteratee shorthands.
  484. *
  485. * @private
  486. * @param {Array} [array] The array to iterate over.
  487. * @param {Function} predicate The function invoked per iteration.
  488. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  489. * else `false`.
  490. */
  491. function arrayEvery(array, predicate) {
  492. var index = -1,
  493. length = array == null ? 0 : array.length;
  494. while (++index < length) {
  495. if (!predicate(array[index], index, array)) {
  496. return false;
  497. }
  498. }
  499. return true;
  500. }
  501. /**
  502. * A specialized version of `_.filter` for arrays without support for
  503. * iteratee shorthands.
  504. *
  505. * @private
  506. * @param {Array} [array] The array to iterate over.
  507. * @param {Function} predicate The function invoked per iteration.
  508. * @returns {Array} Returns the new filtered array.
  509. */
  510. function arrayFilter(array, predicate) {
  511. var index = -1,
  512. length = array == null ? 0 : array.length,
  513. resIndex = 0,
  514. result = [];
  515. while (++index < length) {
  516. var value = array[index];
  517. if (predicate(value, index, array)) {
  518. result[resIndex++] = value;
  519. }
  520. }
  521. return result;
  522. }
  523. /**
  524. * A specialized version of `_.includes` for arrays without support for
  525. * specifying an index to search from.
  526. *
  527. * @private
  528. * @param {Array} [array] The array to inspect.
  529. * @param {*} target The value to search for.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludes(array, value) {
  533. var length = array == null ? 0 : array.length;
  534. return !!length && baseIndexOf(array, value, 0) > -1;
  535. }
  536. /**
  537. * This function is like `arrayIncludes` except that it accepts a comparator.
  538. *
  539. * @private
  540. * @param {Array} [array] The array to inspect.
  541. * @param {*} target The value to search for.
  542. * @param {Function} comparator The comparator invoked per element.
  543. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  544. */
  545. function arrayIncludesWith(array, value, comparator) {
  546. var index = -1,
  547. length = array == null ? 0 : array.length;
  548. while (++index < length) {
  549. if (comparator(value, array[index])) {
  550. return true;
  551. }
  552. }
  553. return false;
  554. }
  555. /**
  556. * A specialized version of `_.map` for arrays without support for iteratee
  557. * shorthands.
  558. *
  559. * @private
  560. * @param {Array} [array] The array to iterate over.
  561. * @param {Function} iteratee The function invoked per iteration.
  562. * @returns {Array} Returns the new mapped array.
  563. */
  564. function arrayMap(array, iteratee) {
  565. var index = -1,
  566. length = array == null ? 0 : array.length,
  567. result = Array(length);
  568. while (++index < length) {
  569. result[index] = iteratee(array[index], index, array);
  570. }
  571. return result;
  572. }
  573. /**
  574. * Appends the elements of `values` to `array`.
  575. *
  576. * @private
  577. * @param {Array} array The array to modify.
  578. * @param {Array} values The values to append.
  579. * @returns {Array} Returns `array`.
  580. */
  581. function arrayPush(array, values) {
  582. var index = -1,
  583. length = values.length,
  584. offset = array.length;
  585. while (++index < length) {
  586. array[offset + index] = values[index];
  587. }
  588. return array;
  589. }
  590. /**
  591. * A specialized version of `_.reduce` for arrays without support for
  592. * iteratee shorthands.
  593. *
  594. * @private
  595. * @param {Array} [array] The array to iterate over.
  596. * @param {Function} iteratee The function invoked per iteration.
  597. * @param {*} [accumulator] The initial value.
  598. * @param {boolean} [initAccum] Specify using the first element of `array` as
  599. * the initial value.
  600. * @returns {*} Returns the accumulated value.
  601. */
  602. function arrayReduce(array, iteratee, accumulator, initAccum) {
  603. var index = -1,
  604. length = array == null ? 0 : array.length;
  605. if (initAccum && length) {
  606. accumulator = array[++index];
  607. }
  608. while (++index < length) {
  609. accumulator = iteratee(accumulator, array[index], index, array);
  610. }
  611. return accumulator;
  612. }
  613. /**
  614. * A specialized version of `_.reduceRight` for arrays without support for
  615. * iteratee shorthands.
  616. *
  617. * @private
  618. * @param {Array} [array] The array to iterate over.
  619. * @param {Function} iteratee The function invoked per iteration.
  620. * @param {*} [accumulator] The initial value.
  621. * @param {boolean} [initAccum] Specify using the last element of `array` as
  622. * the initial value.
  623. * @returns {*} Returns the accumulated value.
  624. */
  625. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  626. var length = array == null ? 0 : array.length;
  627. if (initAccum && length) {
  628. accumulator = array[--length];
  629. }
  630. while (length--) {
  631. accumulator = iteratee(accumulator, array[length], length, array);
  632. }
  633. return accumulator;
  634. }
  635. /**
  636. * A specialized version of `_.some` for arrays without support for iteratee
  637. * shorthands.
  638. *
  639. * @private
  640. * @param {Array} [array] The array to iterate over.
  641. * @param {Function} predicate The function invoked per iteration.
  642. * @returns {boolean} Returns `true` if any element passes the predicate check,
  643. * else `false`.
  644. */
  645. function arraySome(array, predicate) {
  646. var index = -1,
  647. length = array == null ? 0 : array.length;
  648. while (++index < length) {
  649. if (predicate(array[index], index, array)) {
  650. return true;
  651. }
  652. }
  653. return false;
  654. }
  655. /**
  656. * Gets the size of an ASCII `string`.
  657. *
  658. * @private
  659. * @param {string} string The string inspect.
  660. * @returns {number} Returns the string size.
  661. */
  662. var asciiSize = baseProperty('length');
  663. /**
  664. * Converts an ASCII `string` to an array.
  665. *
  666. * @private
  667. * @param {string} string The string to convert.
  668. * @returns {Array} Returns the converted array.
  669. */
  670. function asciiToArray(string) {
  671. return string.split('');
  672. }
  673. /**
  674. * Splits an ASCII `string` into an array of its words.
  675. *
  676. * @private
  677. * @param {string} The string to inspect.
  678. * @returns {Array} Returns the words of `string`.
  679. */
  680. function asciiWords(string) {
  681. return string.match(reAsciiWord) || [];
  682. }
  683. /**
  684. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  685. * without support for iteratee shorthands, which iterates over `collection`
  686. * using `eachFunc`.
  687. *
  688. * @private
  689. * @param {Array|Object} collection The collection to inspect.
  690. * @param {Function} predicate The function invoked per iteration.
  691. * @param {Function} eachFunc The function to iterate over `collection`.
  692. * @returns {*} Returns the found element or its key, else `undefined`.
  693. */
  694. function baseFindKey(collection, predicate, eachFunc) {
  695. var result;
  696. eachFunc(collection, function(value, key, collection) {
  697. if (predicate(value, key, collection)) {
  698. result = key;
  699. return false;
  700. }
  701. });
  702. return result;
  703. }
  704. /**
  705. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  706. * support for iteratee shorthands.
  707. *
  708. * @private
  709. * @param {Array} array The array to inspect.
  710. * @param {Function} predicate The function invoked per iteration.
  711. * @param {number} fromIndex The index to search from.
  712. * @param {boolean} [fromRight] Specify iterating from right to left.
  713. * @returns {number} Returns the index of the matched value, else `-1`.
  714. */
  715. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  716. var length = array.length,
  717. index = fromIndex + (fromRight ? 1 : -1);
  718. while ((fromRight ? index-- : ++index < length)) {
  719. if (predicate(array[index], index, array)) {
  720. return index;
  721. }
  722. }
  723. return -1;
  724. }
  725. /**
  726. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  727. *
  728. * @private
  729. * @param {Array} array The array to inspect.
  730. * @param {*} value The value to search for.
  731. * @param {number} fromIndex The index to search from.
  732. * @returns {number} Returns the index of the matched value, else `-1`.
  733. */
  734. function baseIndexOf(array, value, fromIndex) {
  735. return value === value
  736. ? strictIndexOf(array, value, fromIndex)
  737. : baseFindIndex(array, baseIsNaN, fromIndex);
  738. }
  739. /**
  740. * This function is like `baseIndexOf` except that it accepts a comparator.
  741. *
  742. * @private
  743. * @param {Array} array The array to inspect.
  744. * @param {*} value The value to search for.
  745. * @param {number} fromIndex The index to search from.
  746. * @param {Function} comparator The comparator invoked per element.
  747. * @returns {number} Returns the index of the matched value, else `-1`.
  748. */
  749. function baseIndexOfWith(array, value, fromIndex, comparator) {
  750. var index = fromIndex - 1,
  751. length = array.length;
  752. while (++index < length) {
  753. if (comparator(array[index], value)) {
  754. return index;
  755. }
  756. }
  757. return -1;
  758. }
  759. /**
  760. * The base implementation of `_.isNaN` without support for number objects.
  761. *
  762. * @private
  763. * @param {*} value The value to check.
  764. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  765. */
  766. function baseIsNaN(value) {
  767. return value !== value;
  768. }
  769. /**
  770. * The base implementation of `_.mean` and `_.meanBy` without support for
  771. * iteratee shorthands.
  772. *
  773. * @private
  774. * @param {Array} array The array to iterate over.
  775. * @param {Function} iteratee The function invoked per iteration.
  776. * @returns {number} Returns the mean.
  777. */
  778. function baseMean(array, iteratee) {
  779. var length = array == null ? 0 : array.length;
  780. return length ? (baseSum(array, iteratee) / length) : NAN;
  781. }
  782. /**
  783. * The base implementation of `_.property` without support for deep paths.
  784. *
  785. * @private
  786. * @param {string} key The key of the property to get.
  787. * @returns {Function} Returns the new accessor function.
  788. */
  789. function baseProperty(key) {
  790. return function(object) {
  791. return object == null ? undefined : object[key];
  792. };
  793. }
  794. /**
  795. * The base implementation of `_.propertyOf` without support for deep paths.
  796. *
  797. * @private
  798. * @param {Object} object The object to query.
  799. * @returns {Function} Returns the new accessor function.
  800. */
  801. function basePropertyOf(object) {
  802. return function(key) {
  803. return object == null ? undefined : object[key];
  804. };
  805. }
  806. /**
  807. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  808. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  809. *
  810. * @private
  811. * @param {Array|Object} collection The collection to iterate over.
  812. * @param {Function} iteratee The function invoked per iteration.
  813. * @param {*} accumulator The initial value.
  814. * @param {boolean} initAccum Specify using the first or last element of
  815. * `collection` as the initial value.
  816. * @param {Function} eachFunc The function to iterate over `collection`.
  817. * @returns {*} Returns the accumulated value.
  818. */
  819. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  820. eachFunc(collection, function(value, index, collection) {
  821. accumulator = initAccum
  822. ? (initAccum = false, value)
  823. : iteratee(accumulator, value, index, collection);
  824. });
  825. return accumulator;
  826. }
  827. /**
  828. * The base implementation of `_.sortBy` which uses `comparer` to define the
  829. * sort order of `array` and replaces criteria objects with their corresponding
  830. * values.
  831. *
  832. * @private
  833. * @param {Array} array The array to sort.
  834. * @param {Function} comparer The function to define sort order.
  835. * @returns {Array} Returns `array`.
  836. */
  837. function baseSortBy(array, comparer) {
  838. var length = array.length;
  839. array.sort(comparer);
  840. while (length--) {
  841. array[length] = array[length].value;
  842. }
  843. return array;
  844. }
  845. /**
  846. * The base implementation of `_.sum` and `_.sumBy` without support for
  847. * iteratee shorthands.
  848. *
  849. * @private
  850. * @param {Array} array The array to iterate over.
  851. * @param {Function} iteratee The function invoked per iteration.
  852. * @returns {number} Returns the sum.
  853. */
  854. function baseSum(array, iteratee) {
  855. var result,
  856. index = -1,
  857. length = array.length;
  858. while (++index < length) {
  859. var current = iteratee(array[index]);
  860. if (current !== undefined) {
  861. result = result === undefined ? current : (result + current);
  862. }
  863. }
  864. return result;
  865. }
  866. /**
  867. * The base implementation of `_.times` without support for iteratee shorthands
  868. * or max array length checks.
  869. *
  870. * @private
  871. * @param {number} n The number of times to invoke `iteratee`.
  872. * @param {Function} iteratee The function invoked per iteration.
  873. * @returns {Array} Returns the array of results.
  874. */
  875. function baseTimes(n, iteratee) {
  876. var index = -1,
  877. result = Array(n);
  878. while (++index < n) {
  879. result[index] = iteratee(index);
  880. }
  881. return result;
  882. }
  883. /**
  884. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  885. * of key-value pairs for `object` corresponding to the property names of `props`.
  886. *
  887. * @private
  888. * @param {Object} object The object to query.
  889. * @param {Array} props The property names to get values for.
  890. * @returns {Object} Returns the key-value pairs.
  891. */
  892. function baseToPairs(object, props) {
  893. return arrayMap(props, function(key) {
  894. return [key, object[key]];
  895. });
  896. }
  897. /**
  898. * The base implementation of `_.trim`.
  899. *
  900. * @private
  901. * @param {string} string The string to trim.
  902. * @returns {string} Returns the trimmed string.
  903. */
  904. function baseTrim(string) {
  905. return string
  906. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  907. : string;
  908. }
  909. /**
  910. * The base implementation of `_.unary` without support for storing metadata.
  911. *
  912. * @private
  913. * @param {Function} func The function to cap arguments for.
  914. * @returns {Function} Returns the new capped function.
  915. */
  916. function baseUnary(func) {
  917. return function(value) {
  918. return func(value);
  919. };
  920. }
  921. /**
  922. * The base implementation of `_.values` and `_.valuesIn` which creates an
  923. * array of `object` property values corresponding to the property names
  924. * of `props`.
  925. *
  926. * @private
  927. * @param {Object} object The object to query.
  928. * @param {Array} props The property names to get values for.
  929. * @returns {Object} Returns the array of property values.
  930. */
  931. function baseValues(object, props) {
  932. return arrayMap(props, function(key) {
  933. return object[key];
  934. });
  935. }
  936. /**
  937. * Checks if a `cache` value for `key` exists.
  938. *
  939. * @private
  940. * @param {Object} cache The cache to query.
  941. * @param {string} key The key of the entry to check.
  942. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  943. */
  944. function cacheHas(cache, key) {
  945. return cache.has(key);
  946. }
  947. /**
  948. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  949. * that is not found in the character symbols.
  950. *
  951. * @private
  952. * @param {Array} strSymbols The string symbols to inspect.
  953. * @param {Array} chrSymbols The character symbols to find.
  954. * @returns {number} Returns the index of the first unmatched string symbol.
  955. */
  956. function charsStartIndex(strSymbols, chrSymbols) {
  957. var index = -1,
  958. length = strSymbols.length;
  959. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  960. return index;
  961. }
  962. /**
  963. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  964. * that is not found in the character symbols.
  965. *
  966. * @private
  967. * @param {Array} strSymbols The string symbols to inspect.
  968. * @param {Array} chrSymbols The character symbols to find.
  969. * @returns {number} Returns the index of the last unmatched string symbol.
  970. */
  971. function charsEndIndex(strSymbols, chrSymbols) {
  972. var index = strSymbols.length;
  973. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  974. return index;
  975. }
  976. /**
  977. * Gets the number of `placeholder` occurrences in `array`.
  978. *
  979. * @private
  980. * @param {Array} array The array to inspect.
  981. * @param {*} placeholder The placeholder to search for.
  982. * @returns {number} Returns the placeholder count.
  983. */
  984. function countHolders(array, placeholder) {
  985. var length = array.length,
  986. result = 0;
  987. while (length--) {
  988. if (array[length] === placeholder) {
  989. ++result;
  990. }
  991. }
  992. return result;
  993. }
  994. /**
  995. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  996. * letters to basic Latin letters.
  997. *
  998. * @private
  999. * @param {string} letter The matched letter to deburr.
  1000. * @returns {string} Returns the deburred letter.
  1001. */
  1002. var deburrLetter = basePropertyOf(deburredLetters);
  1003. /**
  1004. * Used by `_.escape` to convert characters to HTML entities.
  1005. *
  1006. * @private
  1007. * @param {string} chr The matched character to escape.
  1008. * @returns {string} Returns the escaped character.
  1009. */
  1010. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1011. /**
  1012. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1013. *
  1014. * @private
  1015. * @param {string} chr The matched character to escape.
  1016. * @returns {string} Returns the escaped character.
  1017. */
  1018. function escapeStringChar(chr) {
  1019. return '\\' + stringEscapes[chr];
  1020. }
  1021. /**
  1022. * Gets the value at `key` of `object`.
  1023. *
  1024. * @private
  1025. * @param {Object} [object] The object to query.
  1026. * @param {string} key The key of the property to get.
  1027. * @returns {*} Returns the property value.
  1028. */
  1029. function getValue(object, key) {
  1030. return object == null ? undefined : object[key];
  1031. }
  1032. /**
  1033. * Checks if `string` contains Unicode symbols.
  1034. *
  1035. * @private
  1036. * @param {string} string The string to inspect.
  1037. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1038. */
  1039. function hasUnicode(string) {
  1040. return reHasUnicode.test(string);
  1041. }
  1042. /**
  1043. * Checks if `string` contains a word composed of Unicode symbols.
  1044. *
  1045. * @private
  1046. * @param {string} string The string to inspect.
  1047. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1048. */
  1049. function hasUnicodeWord(string) {
  1050. return reHasUnicodeWord.test(string);
  1051. }
  1052. /**
  1053. * Converts `iterator` to an array.
  1054. *
  1055. * @private
  1056. * @param {Object} iterator The iterator to convert.
  1057. * @returns {Array} Returns the converted array.
  1058. */
  1059. function iteratorToArray(iterator) {
  1060. var data,
  1061. result = [];
  1062. while (!(data = iterator.next()).done) {
  1063. result.push(data.value);
  1064. }
  1065. return result;
  1066. }
  1067. /**
  1068. * Converts `map` to its key-value pairs.
  1069. *
  1070. * @private
  1071. * @param {Object} map The map to convert.
  1072. * @returns {Array} Returns the key-value pairs.
  1073. */
  1074. function mapToArray(map) {
  1075. var index = -1,
  1076. result = Array(map.size);
  1077. map.forEach(function(value, key) {
  1078. result[++index] = [key, value];
  1079. });
  1080. return result;
  1081. }
  1082. /**
  1083. * Creates a unary function that invokes `func` with its argument transformed.
  1084. *
  1085. * @private
  1086. * @param {Function} func The function to wrap.
  1087. * @param {Function} transform The argument transform.
  1088. * @returns {Function} Returns the new function.
  1089. */
  1090. function overArg(func, transform) {
  1091. return function(arg) {
  1092. return func(transform(arg));
  1093. };
  1094. }
  1095. /**
  1096. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1097. * and returns an array of their indexes.
  1098. *
  1099. * @private
  1100. * @param {Array} array The array to modify.
  1101. * @param {*} placeholder The placeholder to replace.
  1102. * @returns {Array} Returns the new array of placeholder indexes.
  1103. */
  1104. function replaceHolders(array, placeholder) {
  1105. var index = -1,
  1106. length = array.length,
  1107. resIndex = 0,
  1108. result = [];
  1109. while (++index < length) {
  1110. var value = array[index];
  1111. if (value === placeholder || value === PLACEHOLDER) {
  1112. array[index] = PLACEHOLDER;
  1113. result[resIndex++] = index;
  1114. }
  1115. }
  1116. return result;
  1117. }
  1118. /**
  1119. * Converts `set` to an array of its values.
  1120. *
  1121. * @private
  1122. * @param {Object} set The set to convert.
  1123. * @returns {Array} Returns the values.
  1124. */
  1125. function setToArray(set) {
  1126. var index = -1,
  1127. result = Array(set.size);
  1128. set.forEach(function(value) {
  1129. result[++index] = value;
  1130. });
  1131. return result;
  1132. }
  1133. /**
  1134. * Converts `set` to its value-value pairs.
  1135. *
  1136. * @private
  1137. * @param {Object} set The set to convert.
  1138. * @returns {Array} Returns the value-value pairs.
  1139. */
  1140. function setToPairs(set) {
  1141. var index = -1,
  1142. result = Array(set.size);
  1143. set.forEach(function(value) {
  1144. result[++index] = [value, value];
  1145. });
  1146. return result;
  1147. }
  1148. /**
  1149. * A specialized version of `_.indexOf` which performs strict equality
  1150. * comparisons of values, i.e. `===`.
  1151. *
  1152. * @private
  1153. * @param {Array} array The array to inspect.
  1154. * @param {*} value The value to search for.
  1155. * @param {number} fromIndex The index to search from.
  1156. * @returns {number} Returns the index of the matched value, else `-1`.
  1157. */
  1158. function strictIndexOf(array, value, fromIndex) {
  1159. var index = fromIndex - 1,
  1160. length = array.length;
  1161. while (++index < length) {
  1162. if (array[index] === value) {
  1163. return index;
  1164. }
  1165. }
  1166. return -1;
  1167. }
  1168. /**
  1169. * A specialized version of `_.lastIndexOf` which performs strict equality
  1170. * comparisons of values, i.e. `===`.
  1171. *
  1172. * @private
  1173. * @param {Array} array The array to inspect.
  1174. * @param {*} value The value to search for.
  1175. * @param {number} fromIndex The index to search from.
  1176. * @returns {number} Returns the index of the matched value, else `-1`.
  1177. */
  1178. function strictLastIndexOf(array, value, fromIndex) {
  1179. var index = fromIndex + 1;
  1180. while (index--) {
  1181. if (array[index] === value) {
  1182. return index;
  1183. }
  1184. }
  1185. return index;
  1186. }
  1187. /**
  1188. * Gets the number of symbols in `string`.
  1189. *
  1190. * @private
  1191. * @param {string} string The string to inspect.
  1192. * @returns {number} Returns the string size.
  1193. */
  1194. function stringSize(string) {
  1195. return hasUnicode(string)
  1196. ? unicodeSize(string)
  1197. : asciiSize(string);
  1198. }
  1199. /**
  1200. * Converts `string` to an array.
  1201. *
  1202. * @private
  1203. * @param {string} string The string to convert.
  1204. * @returns {Array} Returns the converted array.
  1205. */
  1206. function stringToArray(string) {
  1207. return hasUnicode(string)
  1208. ? unicodeToArray(string)
  1209. : asciiToArray(string);
  1210. }
  1211. /**
  1212. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  1213. * character of `string`.
  1214. *
  1215. * @private
  1216. * @param {string} string The string to inspect.
  1217. * @returns {number} Returns the index of the last non-whitespace character.
  1218. */
  1219. function trimmedEndIndex(string) {
  1220. var index = string.length;
  1221. while (index-- && reWhitespace.test(string.charAt(index))) {}
  1222. return index;
  1223. }
  1224. /**
  1225. * Used by `_.unescape` to convert HTML entities to characters.
  1226. *
  1227. * @private
  1228. * @param {string} chr The matched character to unescape.
  1229. * @returns {string} Returns the unescaped character.
  1230. */
  1231. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1232. /**
  1233. * Gets the size of a Unicode `string`.
  1234. *
  1235. * @private
  1236. * @param {string} string The string inspect.
  1237. * @returns {number} Returns the string size.
  1238. */
  1239. function unicodeSize(string) {
  1240. var result = reUnicode.lastIndex = 0;
  1241. while (reUnicode.test(string)) {
  1242. ++result;
  1243. }
  1244. return result;
  1245. }
  1246. /**
  1247. * Converts a Unicode `string` to an array.
  1248. *
  1249. * @private
  1250. * @param {string} string The string to convert.
  1251. * @returns {Array} Returns the converted array.
  1252. */
  1253. function unicodeToArray(string) {
  1254. return string.match(reUnicode) || [];
  1255. }
  1256. /**
  1257. * Splits a Unicode `string` into an array of its words.
  1258. *
  1259. * @private
  1260. * @param {string} The string to inspect.
  1261. * @returns {Array} Returns the words of `string`.
  1262. */
  1263. function unicodeWords(string) {
  1264. return string.match(reUnicodeWord) || [];
  1265. }
  1266. /*--------------------------------------------------------------------------*/
  1267. /**
  1268. * Create a new pristine `lodash` function using the `context` object.
  1269. *
  1270. * @static
  1271. * @memberOf _
  1272. * @since 1.1.0
  1273. * @category Util
  1274. * @param {Object} [context=root] The context object.
  1275. * @returns {Function} Returns a new `lodash` function.
  1276. * @example
  1277. *
  1278. * _.mixin({ 'foo': _.constant('foo') });
  1279. *
  1280. * var lodash = _.runInContext();
  1281. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1282. *
  1283. * _.isFunction(_.foo);
  1284. * // => true
  1285. * _.isFunction(_.bar);
  1286. * // => false
  1287. *
  1288. * lodash.isFunction(lodash.foo);
  1289. * // => false
  1290. * lodash.isFunction(lodash.bar);
  1291. * // => true
  1292. *
  1293. * // Create a suped-up `defer` in Node.js.
  1294. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1295. */
  1296. var runInContext = (function runInContext(context) {
  1297. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1298. /** Built-in constructor references. */
  1299. var Array = context.Array,
  1300. Date = context.Date,
  1301. Error = context.Error,
  1302. Function = context.Function,
  1303. Math = context.Math,
  1304. Object = context.Object,
  1305. RegExp = context.RegExp,
  1306. String = context.String,
  1307. TypeError = context.TypeError;
  1308. /** Used for built-in method references. */
  1309. var arrayProto = Array.prototype,
  1310. funcProto = Function.prototype,
  1311. objectProto = Object.prototype;
  1312. /** Used to detect overreaching core-js shims. */
  1313. var coreJsData = context['__core-js_shared__'];
  1314. /** Used to resolve the decompiled source of functions. */
  1315. var funcToString = funcProto.toString;
  1316. /** Used to check objects for own properties. */
  1317. var hasOwnProperty = objectProto.hasOwnProperty;
  1318. /** Used to generate unique IDs. */
  1319. var idCounter = 0;
  1320. /** Used to detect methods masquerading as native. */
  1321. var maskSrcKey = (function() {
  1322. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1323. return uid ? ('Symbol(src)_1.' + uid) : '';
  1324. }());
  1325. /**
  1326. * Used to resolve the
  1327. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1328. * of values.
  1329. */
  1330. var nativeObjectToString = objectProto.toString;
  1331. /** Used to infer the `Object` constructor. */
  1332. var objectCtorString = funcToString.call(Object);
  1333. /** Used to restore the original `_` reference in `_.noConflict`. */
  1334. var oldDash = root._;
  1335. /** Used to detect if a method is native. */
  1336. var reIsNative = RegExp('^' +
  1337. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1338. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1339. );
  1340. /** Built-in value references. */
  1341. var Buffer = moduleExports ? context.Buffer : undefined,
  1342. Symbol = context.Symbol,
  1343. Uint8Array = context.Uint8Array,
  1344. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1345. getPrototype = overArg(Object.getPrototypeOf, Object),
  1346. objectCreate = Object.create,
  1347. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1348. splice = arrayProto.splice,
  1349. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1350. symIterator = Symbol ? Symbol.iterator : undefined,
  1351. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1352. var defineProperty = (function() {
  1353. try {
  1354. var func = getNative(Object, 'defineProperty');
  1355. func({}, '', {});
  1356. return func;
  1357. } catch (e) {}
  1358. }());
  1359. /** Mocked built-ins. */
  1360. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1361. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1362. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1363. /* Built-in method references for those with the same name as other `lodash` methods. */
  1364. var nativeCeil = Math.ceil,
  1365. nativeFloor = Math.floor,
  1366. nativeGetSymbols = Object.getOwnPropertySymbols,
  1367. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1368. nativeIsFinite = context.isFinite,
  1369. nativeJoin = arrayProto.join,
  1370. nativeKeys = overArg(Object.keys, Object),
  1371. nativeMax = Math.max,
  1372. nativeMin = Math.min,
  1373. nativeNow = Date.now,
  1374. nativeParseInt = context.parseInt,
  1375. nativeRandom = Math.random,
  1376. nativeReverse = arrayProto.reverse;
  1377. /* Built-in method references that are verified to be native. */
  1378. var DataView = getNative(context, 'DataView'),
  1379. Map = getNative(context, 'Map'),
  1380. Promise = getNative(context, 'Promise'),
  1381. Set = getNative(context, 'Set'),
  1382. WeakMap = getNative(context, 'WeakMap'),
  1383. nativeCreate = getNative(Object, 'create');
  1384. /** Used to store function metadata. */
  1385. var metaMap = WeakMap && new WeakMap;
  1386. /** Used to lookup unminified function names. */
  1387. var realNames = {};
  1388. /** Used to detect maps, sets, and weakmaps. */
  1389. var dataViewCtorString = toSource(DataView),
  1390. mapCtorString = toSource(Map),
  1391. promiseCtorString = toSource(Promise),
  1392. setCtorString = toSource(Set),
  1393. weakMapCtorString = toSource(WeakMap);
  1394. /** Used to convert symbols to primitives and strings. */
  1395. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1396. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1397. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1398. /*------------------------------------------------------------------------*/
  1399. /**
  1400. * Creates a `lodash` object which wraps `value` to enable implicit method
  1401. * chain sequences. Methods that operate on and return arrays, collections,
  1402. * and functions can be chained together. Methods that retrieve a single value
  1403. * or may return a primitive value will automatically end the chain sequence
  1404. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1405. * with `_#value`.
  1406. *
  1407. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1408. * enabled using `_.chain`.
  1409. *
  1410. * The execution of chained methods is lazy, that is, it's deferred until
  1411. * `_#value` is implicitly or explicitly called.
  1412. *
  1413. * Lazy evaluation allows several methods to support shortcut fusion.
  1414. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1415. * the creation of intermediate arrays and can greatly reduce the number of
  1416. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1417. * fusion if the section is applied to an array and iteratees accept only
  1418. * one argument. The heuristic for whether a section qualifies for shortcut
  1419. * fusion is subject to change.
  1420. *
  1421. * Chaining is supported in custom builds as long as the `_#value` method is
  1422. * directly or indirectly included in the build.
  1423. *
  1424. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1425. *
  1426. * The wrapper `Array` methods are:
  1427. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1428. *
  1429. * The wrapper `String` methods are:
  1430. * `replace` and `split`
  1431. *
  1432. * The wrapper methods that support shortcut fusion are:
  1433. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1434. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1435. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1436. *
  1437. * The chainable wrapper methods are:
  1438. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1439. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1440. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1441. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1442. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1443. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1444. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1445. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1446. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1447. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1448. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1449. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1450. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1451. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1452. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1453. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1454. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1455. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1456. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1457. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1458. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1459. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1460. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1461. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1462. *
  1463. * The wrapper methods that are **not** chainable by default are:
  1464. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1465. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1466. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1467. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1468. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1469. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1470. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1471. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1472. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1473. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1474. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1475. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1476. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1477. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1478. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1479. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1480. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1481. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1482. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1483. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1484. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1485. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1486. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1487. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1488. * `upperFirst`, `value`, and `words`
  1489. *
  1490. * @name _
  1491. * @constructor
  1492. * @category Seq
  1493. * @param {*} value The value to wrap in a `lodash` instance.
  1494. * @returns {Object} Returns the new `lodash` wrapper instance.
  1495. * @example
  1496. *
  1497. * function square(n) {
  1498. * return n * n;
  1499. * }
  1500. *
  1501. * var wrapped = _([1, 2, 3]);
  1502. *
  1503. * // Returns an unwrapped value.
  1504. * wrapped.reduce(_.add);
  1505. * // => 6
  1506. *
  1507. * // Returns a wrapped value.
  1508. * var squares = wrapped.map(square);
  1509. *
  1510. * _.isArray(squares);
  1511. * // => false
  1512. *
  1513. * _.isArray(squares.value());
  1514. * // => true
  1515. */
  1516. function lodash(value) {
  1517. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1518. if (value instanceof LodashWrapper) {
  1519. return value;
  1520. }
  1521. if (hasOwnProperty.call(value, '__wrapped__')) {
  1522. return wrapperClone(value);
  1523. }
  1524. }
  1525. return new LodashWrapper(value);
  1526. }
  1527. /**
  1528. * The base implementation of `_.create` without support for assigning
  1529. * properties to the created object.
  1530. *
  1531. * @private
  1532. * @param {Object} proto The object to inherit from.
  1533. * @returns {Object} Returns the new object.
  1534. */
  1535. var baseCreate = (function() {
  1536. function object() {}
  1537. return function(proto) {
  1538. if (!isObject(proto)) {
  1539. return {};
  1540. }
  1541. if (objectCreate) {
  1542. return objectCreate(proto);
  1543. }
  1544. object.prototype = proto;
  1545. var result = new object;
  1546. object.prototype = undefined;
  1547. return result;
  1548. };
  1549. }());
  1550. /**
  1551. * The function whose prototype chain sequence wrappers inherit from.
  1552. *
  1553. * @private
  1554. */
  1555. function baseLodash() {
  1556. // No operation performed.
  1557. }
  1558. /**
  1559. * The base constructor for creating `lodash` wrapper objects.
  1560. *
  1561. * @private
  1562. * @param {*} value The value to wrap.
  1563. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1564. */
  1565. function LodashWrapper(value, chainAll) {
  1566. this.__wrapped__ = value;
  1567. this.__actions__ = [];
  1568. this.__chain__ = !!chainAll;
  1569. this.__index__ = 0;
  1570. this.__values__ = undefined;
  1571. }
  1572. /**
  1573. * By default, the template delimiters used by lodash are like those in
  1574. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1575. * following template settings to use alternative delimiters.
  1576. *
  1577. * **Security:** See
  1578. * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md)
  1579. * — `_.template` is insecure and will be removed in v5.
  1580. *
  1581. * @static
  1582. * @memberOf _
  1583. * @type {Object}
  1584. */
  1585. lodash.templateSettings = {
  1586. /**
  1587. * Used to detect `data` property values to be HTML-escaped.
  1588. *
  1589. * @memberOf _.templateSettings
  1590. * @type {RegExp}
  1591. */
  1592. 'escape': reEscape,
  1593. /**
  1594. * Used to detect code to be evaluated.
  1595. *
  1596. * @memberOf _.templateSettings
  1597. * @type {RegExp}
  1598. */
  1599. 'evaluate': reEvaluate,
  1600. /**
  1601. * Used to detect `data` property values to inject.
  1602. *
  1603. * @memberOf _.templateSettings
  1604. * @type {RegExp}
  1605. */
  1606. 'interpolate': reInterpolate,
  1607. /**
  1608. * Used to reference the data object in the template text.
  1609. *
  1610. * @memberOf _.templateSettings
  1611. * @type {string}
  1612. */
  1613. 'variable': '',
  1614. /**
  1615. * Used to import variables into the compiled template.
  1616. *
  1617. * @memberOf _.templateSettings
  1618. * @type {Object}
  1619. */
  1620. 'imports': {
  1621. /**
  1622. * A reference to the `lodash` function.
  1623. *
  1624. * @memberOf _.templateSettings.imports
  1625. * @type {Function}
  1626. */
  1627. '_': lodash
  1628. }
  1629. };
  1630. // Ensure wrappers are instances of `baseLodash`.
  1631. lodash.prototype = baseLodash.prototype;
  1632. lodash.prototype.constructor = lodash;
  1633. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1634. LodashWrapper.prototype.constructor = LodashWrapper;
  1635. /*------------------------------------------------------------------------*/
  1636. /**
  1637. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1638. *
  1639. * @private
  1640. * @constructor
  1641. * @param {*} value The value to wrap.
  1642. */
  1643. function LazyWrapper(value) {
  1644. this.__wrapped__ = value;
  1645. this.__actions__ = [];
  1646. this.__dir__ = 1;
  1647. this.__filtered__ = false;
  1648. this.__iteratees__ = [];
  1649. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1650. this.__views__ = [];
  1651. }
  1652. /**
  1653. * Creates a clone of the lazy wrapper object.
  1654. *
  1655. * @private
  1656. * @name clone
  1657. * @memberOf LazyWrapper
  1658. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1659. */
  1660. function lazyClone() {
  1661. var result = new LazyWrapper(this.__wrapped__);
  1662. result.__actions__ = copyArray(this.__actions__);
  1663. result.__dir__ = this.__dir__;
  1664. result.__filtered__ = this.__filtered__;
  1665. result.__iteratees__ = copyArray(this.__iteratees__);
  1666. result.__takeCount__ = this.__takeCount__;
  1667. result.__views__ = copyArray(this.__views__);
  1668. return result;
  1669. }
  1670. /**
  1671. * Reverses the direction of lazy iteration.
  1672. *
  1673. * @private
  1674. * @name reverse
  1675. * @memberOf LazyWrapper
  1676. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1677. */
  1678. function lazyReverse() {
  1679. if (this.__filtered__) {
  1680. var result = new LazyWrapper(this);
  1681. result.__dir__ = -1;
  1682. result.__filtered__ = true;
  1683. } else {
  1684. result = this.clone();
  1685. result.__dir__ *= -1;
  1686. }
  1687. return result;
  1688. }
  1689. /**
  1690. * Extracts the unwrapped value from its lazy wrapper.
  1691. *
  1692. * @private
  1693. * @name value
  1694. * @memberOf LazyWrapper
  1695. * @returns {*} Returns the unwrapped value.
  1696. */
  1697. function lazyValue() {
  1698. var array = this.__wrapped__.value(),
  1699. dir = this.__dir__,
  1700. isArr = isArray(array),
  1701. isRight = dir < 0,
  1702. arrLength = isArr ? array.length : 0,
  1703. view = getView(0, arrLength, this.__views__),
  1704. start = view.start,
  1705. end = view.end,
  1706. length = end - start,
  1707. index = isRight ? end : (start - 1),
  1708. iteratees = this.__iteratees__,
  1709. iterLength = iteratees.length,
  1710. resIndex = 0,
  1711. takeCount = nativeMin(length, this.__takeCount__);
  1712. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1713. return baseWrapperValue(array, this.__actions__);
  1714. }
  1715. var result = [];
  1716. outer:
  1717. while (length-- && resIndex < takeCount) {
  1718. index += dir;
  1719. var iterIndex = -1,
  1720. value = array[index];
  1721. while (++iterIndex < iterLength) {
  1722. var data = iteratees[iterIndex],
  1723. iteratee = data.iteratee,
  1724. type = data.type,
  1725. computed = iteratee(value);
  1726. if (type == LAZY_MAP_FLAG) {
  1727. value = computed;
  1728. } else if (!computed) {
  1729. if (type == LAZY_FILTER_FLAG) {
  1730. continue outer;
  1731. } else {
  1732. break outer;
  1733. }
  1734. }
  1735. }
  1736. result[resIndex++] = value;
  1737. }
  1738. return result;
  1739. }
  1740. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1741. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1742. LazyWrapper.prototype.constructor = LazyWrapper;
  1743. /*------------------------------------------------------------------------*/
  1744. /**
  1745. * Creates a hash object.
  1746. *
  1747. * @private
  1748. * @constructor
  1749. * @param {Array} [entries] The key-value pairs to cache.
  1750. */
  1751. function Hash(entries) {
  1752. var index = -1,
  1753. length = entries == null ? 0 : entries.length;
  1754. this.clear();
  1755. while (++index < length) {
  1756. var entry = entries[index];
  1757. this.set(entry[0], entry[1]);
  1758. }
  1759. }
  1760. /**
  1761. * Removes all key-value entries from the hash.
  1762. *
  1763. * @private
  1764. * @name clear
  1765. * @memberOf Hash
  1766. */
  1767. function hashClear() {
  1768. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1769. this.size = 0;
  1770. }
  1771. /**
  1772. * Removes `key` and its value from the hash.
  1773. *
  1774. * @private
  1775. * @name delete
  1776. * @memberOf Hash
  1777. * @param {Object} hash The hash to modify.
  1778. * @param {string} key The key of the value to remove.
  1779. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1780. */
  1781. function hashDelete(key) {
  1782. var result = this.has(key) && delete this.__data__[key];
  1783. this.size -= result ? 1 : 0;
  1784. return result;
  1785. }
  1786. /**
  1787. * Gets the hash value for `key`.
  1788. *
  1789. * @private
  1790. * @name get
  1791. * @memberOf Hash
  1792. * @param {string} key The key of the value to get.
  1793. * @returns {*} Returns the entry value.
  1794. */
  1795. function hashGet(key) {
  1796. var data = this.__data__;
  1797. if (nativeCreate) {
  1798. var result = data[key];
  1799. return result === HASH_UNDEFINED ? undefined : result;
  1800. }
  1801. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1802. }
  1803. /**
  1804. * Checks if a hash value for `key` exists.
  1805. *
  1806. * @private
  1807. * @name has
  1808. * @memberOf Hash
  1809. * @param {string} key The key of the entry to check.
  1810. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1811. */
  1812. function hashHas(key) {
  1813. var data = this.__data__;
  1814. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1815. }
  1816. /**
  1817. * Sets the hash `key` to `value`.
  1818. *
  1819. * @private
  1820. * @name set
  1821. * @memberOf Hash
  1822. * @param {string} key The key of the value to set.
  1823. * @param {*} value The value to set.
  1824. * @returns {Object} Returns the hash instance.
  1825. */
  1826. function hashSet(key, value) {
  1827. var data = this.__data__;
  1828. this.size += this.has(key) ? 0 : 1;
  1829. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1830. return this;
  1831. }
  1832. // Add methods to `Hash`.
  1833. Hash.prototype.clear = hashClear;
  1834. Hash.prototype['delete'] = hashDelete;
  1835. Hash.prototype.get = hashGet;
  1836. Hash.prototype.has = hashHas;
  1837. Hash.prototype.set = hashSet;
  1838. /*------------------------------------------------------------------------*/
  1839. /**
  1840. * Creates an list cache object.
  1841. *
  1842. * @private
  1843. * @constructor
  1844. * @param {Array} [entries] The key-value pairs to cache.
  1845. */
  1846. function ListCache(entries) {
  1847. var index = -1,
  1848. length = entries == null ? 0 : entries.length;
  1849. this.clear();
  1850. while (++index < length) {
  1851. var entry = entries[index];
  1852. this.set(entry[0], entry[1]);
  1853. }
  1854. }
  1855. /**
  1856. * Removes all key-value entries from the list cache.
  1857. *
  1858. * @private
  1859. * @name clear
  1860. * @memberOf ListCache
  1861. */
  1862. function listCacheClear() {
  1863. this.__data__ = [];
  1864. this.size = 0;
  1865. }
  1866. /**
  1867. * Removes `key` and its value from the list cache.
  1868. *
  1869. * @private
  1870. * @name delete
  1871. * @memberOf ListCache
  1872. * @param {string} key The key of the value to remove.
  1873. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1874. */
  1875. function listCacheDelete(key) {
  1876. var data = this.__data__,
  1877. index = assocIndexOf(data, key);
  1878. if (index < 0) {
  1879. return false;
  1880. }
  1881. var lastIndex = data.length - 1;
  1882. if (index == lastIndex) {
  1883. data.pop();
  1884. } else {
  1885. splice.call(data, index, 1);
  1886. }
  1887. --this.size;
  1888. return true;
  1889. }
  1890. /**
  1891. * Gets the list cache value for `key`.
  1892. *
  1893. * @private
  1894. * @name get
  1895. * @memberOf ListCache
  1896. * @param {string} key The key of the value to get.
  1897. * @returns {*} Returns the entry value.
  1898. */
  1899. function listCacheGet(key) {
  1900. var data = this.__data__,
  1901. index = assocIndexOf(data, key);
  1902. return index < 0 ? undefined : data[index][1];
  1903. }
  1904. /**
  1905. * Checks if a list cache value for `key` exists.
  1906. *
  1907. * @private
  1908. * @name has
  1909. * @memberOf ListCache
  1910. * @param {string} key The key of the entry to check.
  1911. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1912. */
  1913. function listCacheHas(key) {
  1914. return assocIndexOf(this.__data__, key) > -1;
  1915. }
  1916. /**
  1917. * Sets the list cache `key` to `value`.
  1918. *
  1919. * @private
  1920. * @name set
  1921. * @memberOf ListCache
  1922. * @param {string} key The key of the value to set.
  1923. * @param {*} value The value to set.
  1924. * @returns {Object} Returns the list cache instance.
  1925. */
  1926. function listCacheSet(key, value) {
  1927. var data = this.__data__,
  1928. index = assocIndexOf(data, key);
  1929. if (index < 0) {
  1930. ++this.size;
  1931. data.push([key, value]);
  1932. } else {
  1933. data[index][1] = value;
  1934. }
  1935. return this;
  1936. }
  1937. // Add methods to `ListCache`.
  1938. ListCache.prototype.clear = listCacheClear;
  1939. ListCache.prototype['delete'] = listCacheDelete;
  1940. ListCache.prototype.get = listCacheGet;
  1941. ListCache.prototype.has = listCacheHas;
  1942. ListCache.prototype.set = listCacheSet;
  1943. /*------------------------------------------------------------------------*/
  1944. /**
  1945. * Creates a map cache object to store key-value pairs.
  1946. *
  1947. * @private
  1948. * @constructor
  1949. * @param {Array} [entries] The key-value pairs to cache.
  1950. */
  1951. function MapCache(entries) {
  1952. var index = -1,
  1953. length = entries == null ? 0 : entries.length;
  1954. this.clear();
  1955. while (++index < length) {
  1956. var entry = entries[index];
  1957. this.set(entry[0], entry[1]);
  1958. }
  1959. }
  1960. /**
  1961. * Removes all key-value entries from the map.
  1962. *
  1963. * @private
  1964. * @name clear
  1965. * @memberOf MapCache
  1966. */
  1967. function mapCacheClear() {
  1968. this.size = 0;
  1969. this.__data__ = {
  1970. 'hash': new Hash,
  1971. 'map': new (Map || ListCache),
  1972. 'string': new Hash
  1973. };
  1974. }
  1975. /**
  1976. * Removes `key` and its value from the map.
  1977. *
  1978. * @private
  1979. * @name delete
  1980. * @memberOf MapCache
  1981. * @param {string} key The key of the value to remove.
  1982. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1983. */
  1984. function mapCacheDelete(key) {
  1985. var result = getMapData(this, key)['delete'](key);
  1986. this.size -= result ? 1 : 0;
  1987. return result;
  1988. }
  1989. /**
  1990. * Gets the map value for `key`.
  1991. *
  1992. * @private
  1993. * @name get
  1994. * @memberOf MapCache
  1995. * @param {string} key The key of the value to get.
  1996. * @returns {*} Returns the entry value.
  1997. */
  1998. function mapCacheGet(key) {
  1999. return getMapData(this, key).get(key);
  2000. }
  2001. /**
  2002. * Checks if a map value for `key` exists.
  2003. *
  2004. * @private
  2005. * @name has
  2006. * @memberOf MapCache
  2007. * @param {string} key The key of the entry to check.
  2008. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2009. */
  2010. function mapCacheHas(key) {
  2011. return getMapData(this, key).has(key);
  2012. }
  2013. /**
  2014. * Sets the map `key` to `value`.
  2015. *
  2016. * @private
  2017. * @name set
  2018. * @memberOf MapCache
  2019. * @param {string} key The key of the value to set.
  2020. * @param {*} value The value to set.
  2021. * @returns {Object} Returns the map cache instance.
  2022. */
  2023. function mapCacheSet(key, value) {
  2024. var data = getMapData(this, key),
  2025. size = data.size;
  2026. data.set(key, value);
  2027. this.size += data.size == size ? 0 : 1;
  2028. return this;
  2029. }
  2030. // Add methods to `MapCache`.
  2031. MapCache.prototype.clear = mapCacheClear;
  2032. MapCache.prototype['delete'] = mapCacheDelete;
  2033. MapCache.prototype.get = mapCacheGet;
  2034. MapCache.prototype.has = mapCacheHas;
  2035. MapCache.prototype.set = mapCacheSet;
  2036. /*------------------------------------------------------------------------*/
  2037. /**
  2038. *
  2039. * Creates an array cache object to store unique values.
  2040. *
  2041. * @private
  2042. * @constructor
  2043. * @param {Array} [values] The values to cache.
  2044. */
  2045. function SetCache(values) {
  2046. var index = -1,
  2047. length = values == null ? 0 : values.length;
  2048. this.__data__ = new MapCache;
  2049. while (++index < length) {
  2050. this.add(values[index]);
  2051. }
  2052. }
  2053. /**
  2054. * Adds `value` to the array cache.
  2055. *
  2056. * @private
  2057. * @name add
  2058. * @memberOf SetCache
  2059. * @alias push
  2060. * @param {*} value The value to cache.
  2061. * @returns {Object} Returns the cache instance.
  2062. */
  2063. function setCacheAdd(value) {
  2064. this.__data__.set(value, HASH_UNDEFINED);
  2065. return this;
  2066. }
  2067. /**
  2068. * Checks if `value` is in the array cache.
  2069. *
  2070. * @private
  2071. * @name has
  2072. * @memberOf SetCache
  2073. * @param {*} value The value to search for.
  2074. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  2075. */
  2076. function setCacheHas(value) {
  2077. return this.__data__.has(value);
  2078. }
  2079. // Add methods to `SetCache`.
  2080. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2081. SetCache.prototype.has = setCacheHas;
  2082. /*------------------------------------------------------------------------*/
  2083. /**
  2084. * Creates a stack cache object to store key-value pairs.
  2085. *
  2086. * @private
  2087. * @constructor
  2088. * @param {Array} [entries] The key-value pairs to cache.
  2089. */
  2090. function Stack(entries) {
  2091. var data = this.__data__ = new ListCache(entries);
  2092. this.size = data.size;
  2093. }
  2094. /**
  2095. * Removes all key-value entries from the stack.
  2096. *
  2097. * @private
  2098. * @name clear
  2099. * @memberOf Stack
  2100. */
  2101. function stackClear() {
  2102. this.__data__ = new ListCache;
  2103. this.size = 0;
  2104. }
  2105. /**
  2106. * Removes `key` and its value from the stack.
  2107. *
  2108. * @private
  2109. * @name delete
  2110. * @memberOf Stack
  2111. * @param {string} key The key of the value to remove.
  2112. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2113. */
  2114. function stackDelete(key) {
  2115. var data = this.__data__,
  2116. result = data['delete'](key);
  2117. this.size = data.size;
  2118. return result;
  2119. }
  2120. /**
  2121. * Gets the stack value for `key`.
  2122. *
  2123. * @private
  2124. * @name get
  2125. * @memberOf Stack
  2126. * @param {string} key The key of the value to get.
  2127. * @returns {*} Returns the entry value.
  2128. */
  2129. function stackGet(key) {
  2130. return this.__data__.get(key);
  2131. }
  2132. /**
  2133. * Checks if a stack value for `key` exists.
  2134. *
  2135. * @private
  2136. * @name has
  2137. * @memberOf Stack
  2138. * @param {string} key The key of the entry to check.
  2139. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2140. */
  2141. function stackHas(key) {
  2142. return this.__data__.has(key);
  2143. }
  2144. /**
  2145. * Sets the stack `key` to `value`.
  2146. *
  2147. * @private
  2148. * @name set
  2149. * @memberOf Stack
  2150. * @param {string} key The key of the value to set.
  2151. * @param {*} value The value to set.
  2152. * @returns {Object} Returns the stack cache instance.
  2153. */
  2154. function stackSet(key, value) {
  2155. var data = this.__data__;
  2156. if (data instanceof ListCache) {
  2157. var pairs = data.__data__;
  2158. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2159. pairs.push([key, value]);
  2160. this.size = ++data.size;
  2161. return this;
  2162. }
  2163. data = this.__data__ = new MapCache(pairs);
  2164. }
  2165. data.set(key, value);
  2166. this.size = data.size;
  2167. return this;
  2168. }
  2169. // Add methods to `Stack`.
  2170. Stack.prototype.clear = stackClear;
  2171. Stack.prototype['delete'] = stackDelete;
  2172. Stack.prototype.get = stackGet;
  2173. Stack.prototype.has = stackHas;
  2174. Stack.prototype.set = stackSet;
  2175. /*------------------------------------------------------------------------*/
  2176. /**
  2177. * Creates an array of the enumerable property names of the array-like `value`.
  2178. *
  2179. * @private
  2180. * @param {*} value The value to query.
  2181. * @param {boolean} inherited Specify returning inherited property names.
  2182. * @returns {Array} Returns the array of property names.
  2183. */
  2184. function arrayLikeKeys(value, inherited) {
  2185. var isArr = isArray(value),
  2186. isArg = !isArr && isArguments(value),
  2187. isBuff = !isArr && !isArg && isBuffer(value),
  2188. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2189. skipIndexes = isArr || isArg || isBuff || isType,
  2190. result = skipIndexes ? baseTimes(value.length, String) : [],
  2191. length = result.length;
  2192. for (var key in value) {
  2193. if ((inherited || hasOwnProperty.call(value, key)) &&
  2194. !(skipIndexes && (
  2195. // Safari 9 has enumerable `arguments.length` in strict mode.
  2196. key == 'length' ||
  2197. // Node.js 0.10 has enumerable non-index properties on buffers.
  2198. (isBuff && (key == 'offset' || key == 'parent')) ||
  2199. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2200. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2201. // Skip index properties.
  2202. isIndex(key, length)
  2203. ))) {
  2204. result.push(key);
  2205. }
  2206. }
  2207. return result;
  2208. }
  2209. /**
  2210. * A specialized version of `_.sample` for arrays.
  2211. *
  2212. * @private
  2213. * @param {Array} array The array to sample.
  2214. * @returns {*} Returns the random element.
  2215. */
  2216. function arraySample(array) {
  2217. var length = array.length;
  2218. return length ? array[baseRandom(0, length - 1)] : undefined;
  2219. }
  2220. /**
  2221. * A specialized version of `_.sampleSize` for arrays.
  2222. *
  2223. * @private
  2224. * @param {Array} array The array to sample.
  2225. * @param {number} n The number of elements to sample.
  2226. * @returns {Array} Returns the random elements.
  2227. */
  2228. function arraySampleSize(array, n) {
  2229. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2230. }
  2231. /**
  2232. * A specialized version of `_.shuffle` for arrays.
  2233. *
  2234. * @private
  2235. * @param {Array} array The array to shuffle.
  2236. * @returns {Array} Returns the new shuffled array.
  2237. */
  2238. function arrayShuffle(array) {
  2239. return shuffleSelf(copyArray(array));
  2240. }
  2241. /**
  2242. * This function is like `assignValue` except that it doesn't assign
  2243. * `undefined` values.
  2244. *
  2245. * @private
  2246. * @param {Object} object The object to modify.
  2247. * @param {string} key The key of the property to assign.
  2248. * @param {*} value The value to assign.
  2249. */
  2250. function assignMergeValue(object, key, value) {
  2251. if ((value !== undefined && !eq(object[key], value)) ||
  2252. (value === undefined && !(key in object))) {
  2253. baseAssignValue(object, key, value);
  2254. }
  2255. }
  2256. /**
  2257. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2258. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2259. * for equality comparisons.
  2260. *
  2261. * @private
  2262. * @param {Object} object The object to modify.
  2263. * @param {string} key The key of the property to assign.
  2264. * @param {*} value The value to assign.
  2265. */
  2266. function assignValue(object, key, value) {
  2267. var objValue = object[key];
  2268. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2269. (value === undefined && !(key in object))) {
  2270. baseAssignValue(object, key, value);
  2271. }
  2272. }
  2273. /**
  2274. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2275. *
  2276. * @private
  2277. * @param {Array} array The array to inspect.
  2278. * @param {*} key The key to search for.
  2279. * @returns {number} Returns the index of the matched value, else `-1`.
  2280. */
  2281. function assocIndexOf(array, key) {
  2282. var length = array.length;
  2283. while (length--) {
  2284. if (eq(array[length][0], key)) {
  2285. return length;
  2286. }
  2287. }
  2288. return -1;
  2289. }
  2290. /**
  2291. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2292. * by `iteratee` and values set by `setter`.
  2293. *
  2294. * @private
  2295. * @param {Array|Object} collection The collection to iterate over.
  2296. * @param {Function} setter The function to set `accumulator` values.
  2297. * @param {Function} iteratee The iteratee to transform keys.
  2298. * @param {Object} accumulator The initial aggregated object.
  2299. * @returns {Function} Returns `accumulator`.
  2300. */
  2301. function baseAggregator(collection, setter, iteratee, accumulator) {
  2302. baseEach(collection, function(value, key, collection) {
  2303. setter(accumulator, value, iteratee(value), collection);
  2304. });
  2305. return accumulator;
  2306. }
  2307. /**
  2308. * The base implementation of `_.assign` without support for multiple sources
  2309. * or `customizer` functions.
  2310. *
  2311. * @private
  2312. * @param {Object} object The destination object.
  2313. * @param {Object} source The source object.
  2314. * @returns {Object} Returns `object`.
  2315. */
  2316. function baseAssign(object, source) {
  2317. return object && copyObject(source, keys(source), object);
  2318. }
  2319. /**
  2320. * The base implementation of `_.assignIn` without support for multiple sources
  2321. * or `customizer` functions.
  2322. *
  2323. * @private
  2324. * @param {Object} object The destination object.
  2325. * @param {Object} source The source object.
  2326. * @returns {Object} Returns `object`.
  2327. */
  2328. function baseAssignIn(object, source) {
  2329. return object && copyObject(source, keysIn(source), object);
  2330. }
  2331. /**
  2332. * The base implementation of `assignValue` and `assignMergeValue` without
  2333. * value checks.
  2334. *
  2335. * @private
  2336. * @param {Object} object The object to modify.
  2337. * @param {string} key The key of the property to assign.
  2338. * @param {*} value The value to assign.
  2339. */
  2340. function baseAssignValue(object, key, value) {
  2341. if (key == '__proto__' && defineProperty) {
  2342. defineProperty(object, key, {
  2343. 'configurable': true,
  2344. 'enumerable': true,
  2345. 'value': value,
  2346. 'writable': true
  2347. });
  2348. } else {
  2349. object[key] = value;
  2350. }
  2351. }
  2352. /**
  2353. * The base implementation of `_.at` without support for individual paths.
  2354. *
  2355. * @private
  2356. * @param {Object} object The object to iterate over.
  2357. * @param {string[]} paths The property paths to pick.
  2358. * @returns {Array} Returns the picked elements.
  2359. */
  2360. function baseAt(object, paths) {
  2361. var index = -1,
  2362. length = paths.length,
  2363. result = Array(length),
  2364. skip = object == null;
  2365. while (++index < length) {
  2366. result[index] = skip ? undefined : get(object, paths[index]);
  2367. }
  2368. return result;
  2369. }
  2370. /**
  2371. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2372. *
  2373. * @private
  2374. * @param {number} number The number to clamp.
  2375. * @param {number} [lower] The lower bound.
  2376. * @param {number} upper The upper bound.
  2377. * @returns {number} Returns the clamped number.
  2378. */
  2379. function baseClamp(number, lower, upper) {
  2380. if (number === number) {
  2381. if (upper !== undefined) {
  2382. number = number <= upper ? number : upper;
  2383. }
  2384. if (lower !== undefined) {
  2385. number = number >= lower ? number : lower;
  2386. }
  2387. }
  2388. return number;
  2389. }
  2390. /**
  2391. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2392. * traversed objects.
  2393. *
  2394. * @private
  2395. * @param {*} value The value to clone.
  2396. * @param {boolean} bitmask The bitmask flags.
  2397. * 1 - Deep clone
  2398. * 2 - Flatten inherited properties
  2399. * 4 - Clone symbols
  2400. * @param {Function} [customizer] The function to customize cloning.
  2401. * @param {string} [key] The key of `value`.
  2402. * @param {Object} [object] The parent object of `value`.
  2403. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2404. * @returns {*} Returns the cloned value.
  2405. */
  2406. function baseClone(value, bitmask, customizer, key, object, stack) {
  2407. var result,
  2408. isDeep = bitmask & CLONE_DEEP_FLAG,
  2409. isFlat = bitmask & CLONE_FLAT_FLAG,
  2410. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2411. if (customizer) {
  2412. result = object ? customizer(value, key, object, stack) : customizer(value);
  2413. }
  2414. if (result !== undefined) {
  2415. return result;
  2416. }
  2417. if (!isObject(value)) {
  2418. return value;
  2419. }
  2420. var isArr = isArray(value);
  2421. if (isArr) {
  2422. result = initCloneArray(value);
  2423. if (!isDeep) {
  2424. return copyArray(value, result);
  2425. }
  2426. } else {
  2427. var tag = getTag(value),
  2428. isFunc = tag == funcTag || tag == genTag;
  2429. if (isBuffer(value)) {
  2430. return cloneBuffer(value, isDeep);
  2431. }
  2432. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2433. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2434. if (!isDeep) {
  2435. return isFlat
  2436. ? copySymbolsIn(value, baseAssignIn(result, value))
  2437. : copySymbols(value, baseAssign(result, value));
  2438. }
  2439. } else {
  2440. if (!cloneableTags[tag]) {
  2441. return object ? value : {};
  2442. }
  2443. result = initCloneByTag(value, tag, isDeep);
  2444. }
  2445. }
  2446. // Check for circular references and return its corresponding clone.
  2447. stack || (stack = new Stack);
  2448. var stacked = stack.get(value);
  2449. if (stacked) {
  2450. return stacked;
  2451. }
  2452. stack.set(value, result);
  2453. if (isSet(value)) {
  2454. value.forEach(function(subValue) {
  2455. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2456. });
  2457. } else if (isMap(value)) {
  2458. value.forEach(function(subValue, key) {
  2459. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2460. });
  2461. }
  2462. var keysFunc = isFull
  2463. ? (isFlat ? getAllKeysIn : getAllKeys)
  2464. : (isFlat ? keysIn : keys);
  2465. var props = isArr ? undefined : keysFunc(value);
  2466. arrayEach(props || value, function(subValue, key) {
  2467. if (props) {
  2468. key = subValue;
  2469. subValue = value[key];
  2470. }
  2471. // Recursively populate clone (susceptible to call stack limits).
  2472. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2473. });
  2474. return result;
  2475. }
  2476. /**
  2477. * The base implementation of `_.conforms` which doesn't clone `source`.
  2478. *
  2479. * @private
  2480. * @param {Object} source The object of property predicates to conform to.
  2481. * @returns {Function} Returns the new spec function.
  2482. */
  2483. function baseConforms(source) {
  2484. var props = keys(source);
  2485. return function(object) {
  2486. return baseConformsTo(object, source, props);
  2487. };
  2488. }
  2489. /**
  2490. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2491. *
  2492. * @private
  2493. * @param {Object} object The object to inspect.
  2494. * @param {Object} source The object of property predicates to conform to.
  2495. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2496. */
  2497. function baseConformsTo(object, source, props) {
  2498. var length = props.length;
  2499. if (object == null) {
  2500. return !length;
  2501. }
  2502. object = Object(object);
  2503. while (length--) {
  2504. var key = props[length],
  2505. predicate = source[key],
  2506. value = object[key];
  2507. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2508. return false;
  2509. }
  2510. }
  2511. return true;
  2512. }
  2513. /**
  2514. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2515. * to provide to `func`.
  2516. *
  2517. * @private
  2518. * @param {Function} func The function to delay.
  2519. * @param {number} wait The number of milliseconds to delay invocation.
  2520. * @param {Array} args The arguments to provide to `func`.
  2521. * @returns {number|Object} Returns the timer id or timeout object.
  2522. */
  2523. function baseDelay(func, wait, args) {
  2524. if (typeof func != 'function') {
  2525. throw new TypeError(FUNC_ERROR_TEXT);
  2526. }
  2527. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2528. }
  2529. /**
  2530. * The base implementation of methods like `_.difference` without support
  2531. * for excluding multiple arrays or iteratee shorthands.
  2532. *
  2533. * @private
  2534. * @param {Array} array The array to inspect.
  2535. * @param {Array} values The values to exclude.
  2536. * @param {Function} [iteratee] The iteratee invoked per element.
  2537. * @param {Function} [comparator] The comparator invoked per element.
  2538. * @returns {Array} Returns the new array of filtered values.
  2539. */
  2540. function baseDifference(array, values, iteratee, comparator) {
  2541. var index = -1,
  2542. includes = arrayIncludes,
  2543. isCommon = true,
  2544. length = array.length,
  2545. result = [],
  2546. valuesLength = values.length;
  2547. if (!length) {
  2548. return result;
  2549. }
  2550. if (iteratee) {
  2551. values = arrayMap(values, baseUnary(iteratee));
  2552. }
  2553. if (comparator) {
  2554. includes = arrayIncludesWith;
  2555. isCommon = false;
  2556. }
  2557. else if (values.length >= LARGE_ARRAY_SIZE) {
  2558. includes = cacheHas;
  2559. isCommon = false;
  2560. values = new SetCache(values);
  2561. }
  2562. outer:
  2563. while (++index < length) {
  2564. var value = array[index],
  2565. computed = iteratee == null ? value : iteratee(value);
  2566. value = (comparator || value !== 0) ? value : 0;
  2567. if (isCommon && computed === computed) {
  2568. var valuesIndex = valuesLength;
  2569. while (valuesIndex--) {
  2570. if (values[valuesIndex] === computed) {
  2571. continue outer;
  2572. }
  2573. }
  2574. result.push(value);
  2575. }
  2576. else if (!includes(values, computed, comparator)) {
  2577. result.push(value);
  2578. }
  2579. }
  2580. return result;
  2581. }
  2582. /**
  2583. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2584. *
  2585. * @private
  2586. * @param {Array|Object} collection The collection to iterate over.
  2587. * @param {Function} iteratee The function invoked per iteration.
  2588. * @returns {Array|Object} Returns `collection`.
  2589. */
  2590. var baseEach = createBaseEach(baseForOwn);
  2591. /**
  2592. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2593. *
  2594. * @private
  2595. * @param {Array|Object} collection The collection to iterate over.
  2596. * @param {Function} iteratee The function invoked per iteration.
  2597. * @returns {Array|Object} Returns `collection`.
  2598. */
  2599. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2600. /**
  2601. * The base implementation of `_.every` without support for iteratee shorthands.
  2602. *
  2603. * @private
  2604. * @param {Array|Object} collection The collection to iterate over.
  2605. * @param {Function} predicate The function invoked per iteration.
  2606. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2607. * else `false`
  2608. */
  2609. function baseEvery(collection, predicate) {
  2610. var result = true;
  2611. baseEach(collection, function(value, index, collection) {
  2612. result = !!predicate(value, index, collection);
  2613. return result;
  2614. });
  2615. return result;
  2616. }
  2617. /**
  2618. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2619. * `comparator` to determine the extremum value.
  2620. *
  2621. * @private
  2622. * @param {Array} array The array to iterate over.
  2623. * @param {Function} iteratee The iteratee invoked per iteration.
  2624. * @param {Function} comparator The comparator used to compare values.
  2625. * @returns {*} Returns the extremum value.
  2626. */
  2627. function baseExtremum(array, iteratee, comparator) {
  2628. var index = -1,
  2629. length = array.length;
  2630. while (++index < length) {
  2631. var value = array[index],
  2632. current = iteratee(value);
  2633. if (current != null && (computed === undefined
  2634. ? (current === current && !isSymbol(current))
  2635. : comparator(current, computed)
  2636. )) {
  2637. var computed = current,
  2638. result = value;
  2639. }
  2640. }
  2641. return result;
  2642. }
  2643. /**
  2644. * The base implementation of `_.fill` without an iteratee call guard.
  2645. *
  2646. * @private
  2647. * @param {Array} array The array to fill.
  2648. * @param {*} value The value to fill `array` with.
  2649. * @param {number} [start=0] The start position.
  2650. * @param {number} [end=array.length] The end position.
  2651. * @returns {Array} Returns `array`.
  2652. */
  2653. function baseFill(array, value, start, end) {
  2654. var length = array.length;
  2655. start = toInteger(start);
  2656. if (start < 0) {
  2657. start = -start > length ? 0 : (length + start);
  2658. }
  2659. end = (end === undefined || end > length) ? length : toInteger(end);
  2660. if (end < 0) {
  2661. end += length;
  2662. }
  2663. end = start > end ? 0 : toLength(end);
  2664. while (start < end) {
  2665. array[start++] = value;
  2666. }
  2667. return array;
  2668. }
  2669. /**
  2670. * The base implementation of `_.filter` without support for iteratee shorthands.
  2671. *
  2672. * @private
  2673. * @param {Array|Object} collection The collection to iterate over.
  2674. * @param {Function} predicate The function invoked per iteration.
  2675. * @returns {Array} Returns the new filtered array.
  2676. */
  2677. function baseFilter(collection, predicate) {
  2678. var result = [];
  2679. baseEach(collection, function(value, index, collection) {
  2680. if (predicate(value, index, collection)) {
  2681. result.push(value);
  2682. }
  2683. });
  2684. return result;
  2685. }
  2686. /**
  2687. * The base implementation of `_.flatten` with support for restricting flattening.
  2688. *
  2689. * @private
  2690. * @param {Array} array The array to flatten.
  2691. * @param {number} depth The maximum recursion depth.
  2692. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2693. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2694. * @param {Array} [result=[]] The initial result value.
  2695. * @returns {Array} Returns the new flattened array.
  2696. */
  2697. function baseFlatten(array, depth, predicate, isStrict, result) {
  2698. var index = -1,
  2699. length = array.length;
  2700. predicate || (predicate = isFlattenable);
  2701. result || (result = []);
  2702. while (++index < length) {
  2703. var value = array[index];
  2704. if (depth > 0 && predicate(value)) {
  2705. if (depth > 1) {
  2706. // Recursively flatten arrays (susceptible to call stack limits).
  2707. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2708. } else {
  2709. arrayPush(result, value);
  2710. }
  2711. } else if (!isStrict) {
  2712. result[result.length] = value;
  2713. }
  2714. }
  2715. return result;
  2716. }
  2717. /**
  2718. * The base implementation of `baseForOwn` which iterates over `object`
  2719. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2720. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2721. *
  2722. * @private
  2723. * @param {Object} object The object to iterate over.
  2724. * @param {Function} iteratee The function invoked per iteration.
  2725. * @param {Function} keysFunc The function to get the keys of `object`.
  2726. * @returns {Object} Returns `object`.
  2727. */
  2728. var baseFor = createBaseFor();
  2729. /**
  2730. * This function is like `baseFor` except that it iterates over properties
  2731. * in the opposite order.
  2732. *
  2733. * @private
  2734. * @param {Object} object The object to iterate over.
  2735. * @param {Function} iteratee The function invoked per iteration.
  2736. * @param {Function} keysFunc The function to get the keys of `object`.
  2737. * @returns {Object} Returns `object`.
  2738. */
  2739. var baseForRight = createBaseFor(true);
  2740. /**
  2741. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2742. *
  2743. * @private
  2744. * @param {Object} object The object to iterate over.
  2745. * @param {Function} iteratee The function invoked per iteration.
  2746. * @returns {Object} Returns `object`.
  2747. */
  2748. function baseForOwn(object, iteratee) {
  2749. return object && baseFor(object, iteratee, keys);
  2750. }
  2751. /**
  2752. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2753. *
  2754. * @private
  2755. * @param {Object} object The object to iterate over.
  2756. * @param {Function} iteratee The function invoked per iteration.
  2757. * @returns {Object} Returns `object`.
  2758. */
  2759. function baseForOwnRight(object, iteratee) {
  2760. return object && baseForRight(object, iteratee, keys);
  2761. }
  2762. /**
  2763. * The base implementation of `_.functions` which creates an array of
  2764. * `object` function property names filtered from `props`.
  2765. *
  2766. * @private
  2767. * @param {Object} object The object to inspect.
  2768. * @param {Array} props The property names to filter.
  2769. * @returns {Array} Returns the function names.
  2770. */
  2771. function baseFunctions(object, props) {
  2772. return arrayFilter(props, function(key) {
  2773. return isFunction(object[key]);
  2774. });
  2775. }
  2776. /**
  2777. * The base implementation of `_.get` without support for default values.
  2778. *
  2779. * @private
  2780. * @param {Object} object The object to query.
  2781. * @param {Array|string} path The path of the property to get.
  2782. * @returns {*} Returns the resolved value.
  2783. */
  2784. function baseGet(object, path) {
  2785. path = castPath(path, object);
  2786. var index = 0,
  2787. length = path.length;
  2788. while (object != null && index < length) {
  2789. object = object[toKey(path[index++])];
  2790. }
  2791. return (index && index == length) ? object : undefined;
  2792. }
  2793. /**
  2794. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2795. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2796. * symbols of `object`.
  2797. *
  2798. * @private
  2799. * @param {Object} object The object to query.
  2800. * @param {Function} keysFunc The function to get the keys of `object`.
  2801. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2802. * @returns {Array} Returns the array of property names and symbols.
  2803. */
  2804. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2805. var result = keysFunc(object);
  2806. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2807. }
  2808. /**
  2809. * The base implementation of `getTag` without fallbacks for buggy environments.
  2810. *
  2811. * @private
  2812. * @param {*} value The value to query.
  2813. * @returns {string} Returns the `toStringTag`.
  2814. */
  2815. function baseGetTag(value) {
  2816. if (value == null) {
  2817. return value === undefined ? undefinedTag : nullTag;
  2818. }
  2819. return (symToStringTag && symToStringTag in Object(value))
  2820. ? getRawTag(value)
  2821. : objectToString(value);
  2822. }
  2823. /**
  2824. * The base implementation of `_.gt` which doesn't coerce arguments.
  2825. *
  2826. * @private
  2827. * @param {*} value The value to compare.
  2828. * @param {*} other The other value to compare.
  2829. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2830. * else `false`.
  2831. */
  2832. function baseGt(value, other) {
  2833. return value > other;
  2834. }
  2835. /**
  2836. * The base implementation of `_.has` without support for deep paths.
  2837. *
  2838. * @private
  2839. * @param {Object} [object] The object to query.
  2840. * @param {Array|string} key The key to check.
  2841. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2842. */
  2843. function baseHas(object, key) {
  2844. return object != null && hasOwnProperty.call(object, key);
  2845. }
  2846. /**
  2847. * The base implementation of `_.hasIn` without support for deep paths.
  2848. *
  2849. * @private
  2850. * @param {Object} [object] The object to query.
  2851. * @param {Array|string} key The key to check.
  2852. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2853. */
  2854. function baseHasIn(object, key) {
  2855. return object != null && key in Object(object);
  2856. }
  2857. /**
  2858. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2859. *
  2860. * @private
  2861. * @param {number} number The number to check.
  2862. * @param {number} start The start of the range.
  2863. * @param {number} end The end of the range.
  2864. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2865. */
  2866. function baseInRange(number, start, end) {
  2867. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2868. }
  2869. /**
  2870. * The base implementation of methods like `_.intersection`, without support
  2871. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2872. *
  2873. * @private
  2874. * @param {Array} arrays The arrays to inspect.
  2875. * @param {Function} [iteratee] The iteratee invoked per element.
  2876. * @param {Function} [comparator] The comparator invoked per element.
  2877. * @returns {Array} Returns the new array of shared values.
  2878. */
  2879. function baseIntersection(arrays, iteratee, comparator) {
  2880. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2881. length = arrays[0].length,
  2882. othLength = arrays.length,
  2883. othIndex = othLength,
  2884. caches = Array(othLength),
  2885. maxLength = Infinity,
  2886. result = [];
  2887. while (othIndex--) {
  2888. var array = arrays[othIndex];
  2889. if (othIndex && iteratee) {
  2890. array = arrayMap(array, baseUnary(iteratee));
  2891. }
  2892. maxLength = nativeMin(array.length, maxLength);
  2893. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2894. ? new SetCache(othIndex && array)
  2895. : undefined;
  2896. }
  2897. array = arrays[0];
  2898. var index = -1,
  2899. seen = caches[0];
  2900. outer:
  2901. while (++index < length && result.length < maxLength) {
  2902. var value = array[index],
  2903. computed = iteratee ? iteratee(value) : value;
  2904. value = (comparator || value !== 0) ? value : 0;
  2905. if (!(seen
  2906. ? cacheHas(seen, computed)
  2907. : includes(result, computed, comparator)
  2908. )) {
  2909. othIndex = othLength;
  2910. while (--othIndex) {
  2911. var cache = caches[othIndex];
  2912. if (!(cache
  2913. ? cacheHas(cache, computed)
  2914. : includes(arrays[othIndex], computed, comparator))
  2915. ) {
  2916. continue outer;
  2917. }
  2918. }
  2919. if (seen) {
  2920. seen.push(computed);
  2921. }
  2922. result.push(value);
  2923. }
  2924. }
  2925. return result;
  2926. }
  2927. /**
  2928. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2929. * `object` with values transformed by `iteratee` and set by `setter`.
  2930. *
  2931. * @private
  2932. * @param {Object} object The object to iterate over.
  2933. * @param {Function} setter The function to set `accumulator` values.
  2934. * @param {Function} iteratee The iteratee to transform values.
  2935. * @param {Object} accumulator The initial inverted object.
  2936. * @returns {Function} Returns `accumulator`.
  2937. */
  2938. function baseInverter(object, setter, iteratee, accumulator) {
  2939. baseForOwn(object, function(value, key, object) {
  2940. setter(accumulator, iteratee(value), key, object);
  2941. });
  2942. return accumulator;
  2943. }
  2944. /**
  2945. * The base implementation of `_.invoke` without support for individual
  2946. * method arguments.
  2947. *
  2948. * @private
  2949. * @param {Object} object The object to query.
  2950. * @param {Array|string} path The path of the method to invoke.
  2951. * @param {Array} args The arguments to invoke the method with.
  2952. * @returns {*} Returns the result of the invoked method.
  2953. */
  2954. function baseInvoke(object, path, args) {
  2955. path = castPath(path, object);
  2956. object = parent(object, path);
  2957. var func = object == null ? object : object[toKey(last(path))];
  2958. return func == null ? undefined : apply(func, object, args);
  2959. }
  2960. /**
  2961. * The base implementation of `_.isArguments`.
  2962. *
  2963. * @private
  2964. * @param {*} value The value to check.
  2965. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2966. */
  2967. function baseIsArguments(value) {
  2968. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2969. }
  2970. /**
  2971. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2972. *
  2973. * @private
  2974. * @param {*} value The value to check.
  2975. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2976. */
  2977. function baseIsArrayBuffer(value) {
  2978. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2979. }
  2980. /**
  2981. * The base implementation of `_.isDate` without Node.js optimizations.
  2982. *
  2983. * @private
  2984. * @param {*} value The value to check.
  2985. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2986. */
  2987. function baseIsDate(value) {
  2988. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2989. }
  2990. /**
  2991. * The base implementation of `_.isEqual` which supports partial comparisons
  2992. * and tracks traversed objects.
  2993. *
  2994. * @private
  2995. * @param {*} value The value to compare.
  2996. * @param {*} other The other value to compare.
  2997. * @param {boolean} bitmask The bitmask flags.
  2998. * 1 - Unordered comparison
  2999. * 2 - Partial comparison
  3000. * @param {Function} [customizer] The function to customize comparisons.
  3001. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3002. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3003. */
  3004. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3005. if (value === other) {
  3006. return true;
  3007. }
  3008. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  3009. return value !== value && other !== other;
  3010. }
  3011. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  3012. }
  3013. /**
  3014. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3015. * deep comparisons and tracks traversed objects enabling objects with circular
  3016. * references to be compared.
  3017. *
  3018. * @private
  3019. * @param {Object} object The object to compare.
  3020. * @param {Object} other The other object to compare.
  3021. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3022. * @param {Function} customizer The function to customize comparisons.
  3023. * @param {Function} equalFunc The function to determine equivalents of values.
  3024. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3025. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3026. */
  3027. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3028. var objIsArr = isArray(object),
  3029. othIsArr = isArray(other),
  3030. objTag = objIsArr ? arrayTag : getTag(object),
  3031. othTag = othIsArr ? arrayTag : getTag(other);
  3032. objTag = objTag == argsTag ? objectTag : objTag;
  3033. othTag = othTag == argsTag ? objectTag : othTag;
  3034. var objIsObj = objTag == objectTag,
  3035. othIsObj = othTag == objectTag,
  3036. isSameTag = objTag == othTag;
  3037. if (isSameTag && isBuffer(object)) {
  3038. if (!isBuffer(other)) {
  3039. return false;
  3040. }
  3041. objIsArr = true;
  3042. objIsObj = false;
  3043. }
  3044. if (isSameTag && !objIsObj) {
  3045. stack || (stack = new Stack);
  3046. return (objIsArr || isTypedArray(object))
  3047. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3048. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3049. }
  3050. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3051. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3052. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3053. if (objIsWrapped || othIsWrapped) {
  3054. var objUnwrapped = objIsWrapped ? object.value() : object,
  3055. othUnwrapped = othIsWrapped ? other.value() : other;
  3056. stack || (stack = new Stack);
  3057. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3058. }
  3059. }
  3060. if (!isSameTag) {
  3061. return false;
  3062. }
  3063. stack || (stack = new Stack);
  3064. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3065. }
  3066. /**
  3067. * The base implementation of `_.isMap` without Node.js optimizations.
  3068. *
  3069. * @private
  3070. * @param {*} value The value to check.
  3071. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3072. */
  3073. function baseIsMap(value) {
  3074. return isObjectLike(value) && getTag(value) == mapTag;
  3075. }
  3076. /**
  3077. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3078. *
  3079. * @private
  3080. * @param {Object} object The object to inspect.
  3081. * @param {Object} source The object of property values to match.
  3082. * @param {Array} matchData The property names, values, and compare flags to match.
  3083. * @param {Function} [customizer] The function to customize comparisons.
  3084. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3085. */
  3086. function baseIsMatch(object, source, matchData, customizer) {
  3087. var index = matchData.length,
  3088. length = index,
  3089. noCustomizer = !customizer;
  3090. if (object == null) {
  3091. return !length;
  3092. }
  3093. object = Object(object);
  3094. while (index--) {
  3095. var data = matchData[index];
  3096. if ((noCustomizer && data[2])
  3097. ? data[1] !== object[data[0]]
  3098. : !(data[0] in object)
  3099. ) {
  3100. return false;
  3101. }
  3102. }
  3103. while (++index < length) {
  3104. data = matchData[index];
  3105. var key = data[0],
  3106. objValue = object[key],
  3107. srcValue = data[1];
  3108. if (noCustomizer && data[2]) {
  3109. if (objValue === undefined && !(key in object)) {
  3110. return false;
  3111. }
  3112. } else {
  3113. var stack = new Stack;
  3114. if (customizer) {
  3115. var result = customizer(objValue, srcValue, key, object, source, stack);
  3116. }
  3117. if (!(result === undefined
  3118. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3119. : result
  3120. )) {
  3121. return false;
  3122. }
  3123. }
  3124. }
  3125. return true;
  3126. }
  3127. /**
  3128. * The base implementation of `_.isNative` without bad shim checks.
  3129. *
  3130. * @private
  3131. * @param {*} value The value to check.
  3132. * @returns {boolean} Returns `true` if `value` is a native function,
  3133. * else `false`.
  3134. */
  3135. function baseIsNative(value) {
  3136. if (!isObject(value) || isMasked(value)) {
  3137. return false;
  3138. }
  3139. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3140. return pattern.test(toSource(value));
  3141. }
  3142. /**
  3143. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3144. *
  3145. * @private
  3146. * @param {*} value The value to check.
  3147. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3148. */
  3149. function baseIsRegExp(value) {
  3150. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3151. }
  3152. /**
  3153. * The base implementation of `_.isSet` without Node.js optimizations.
  3154. *
  3155. * @private
  3156. * @param {*} value The value to check.
  3157. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3158. */
  3159. function baseIsSet(value) {
  3160. return isObjectLike(value) && getTag(value) == setTag;
  3161. }
  3162. /**
  3163. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3164. *
  3165. * @private
  3166. * @param {*} value The value to check.
  3167. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3168. */
  3169. function baseIsTypedArray(value) {
  3170. return isObjectLike(value) &&
  3171. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3172. }
  3173. /**
  3174. * The base implementation of `_.iteratee`.
  3175. *
  3176. * @private
  3177. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3178. * @returns {Function} Returns the iteratee.
  3179. */
  3180. function baseIteratee(value) {
  3181. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3182. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3183. if (typeof value == 'function') {
  3184. return value;
  3185. }
  3186. if (value == null) {
  3187. return identity;
  3188. }
  3189. if (typeof value == 'object') {
  3190. return isArray(value)
  3191. ? baseMatchesProperty(value[0], value[1])
  3192. : baseMatches(value);
  3193. }
  3194. return property(value);
  3195. }
  3196. /**
  3197. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3198. *
  3199. * @private
  3200. * @param {Object} object The object to query.
  3201. * @returns {Array} Returns the array of property names.
  3202. */
  3203. function baseKeys(object) {
  3204. if (!isPrototype(object)) {
  3205. return nativeKeys(object);
  3206. }
  3207. var result = [];
  3208. for (var key in Object(object)) {
  3209. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3210. result.push(key);
  3211. }
  3212. }
  3213. return result;
  3214. }
  3215. /**
  3216. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3217. *
  3218. * @private
  3219. * @param {Object} object The object to query.
  3220. * @returns {Array} Returns the array of property names.
  3221. */
  3222. function baseKeysIn(object) {
  3223. if (!isObject(object)) {
  3224. return nativeKeysIn(object);
  3225. }
  3226. var isProto = isPrototype(object),
  3227. result = [];
  3228. for (var key in object) {
  3229. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3230. result.push(key);
  3231. }
  3232. }
  3233. return result;
  3234. }
  3235. /**
  3236. * The base implementation of `_.lt` which doesn't coerce arguments.
  3237. *
  3238. * @private
  3239. * @param {*} value The value to compare.
  3240. * @param {*} other The other value to compare.
  3241. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3242. * else `false`.
  3243. */
  3244. function baseLt(value, other) {
  3245. return value < other;
  3246. }
  3247. /**
  3248. * The base implementation of `_.map` without support for iteratee shorthands.
  3249. *
  3250. * @private
  3251. * @param {Array|Object} collection The collection to iterate over.
  3252. * @param {Function} iteratee The function invoked per iteration.
  3253. * @returns {Array} Returns the new mapped array.
  3254. */
  3255. function baseMap(collection, iteratee) {
  3256. var index = -1,
  3257. result = isArrayLike(collection) ? Array(collection.length) : [];
  3258. baseEach(collection, function(value, key, collection) {
  3259. result[++index] = iteratee(value, key, collection);
  3260. });
  3261. return result;
  3262. }
  3263. /**
  3264. * The base implementation of `_.matches` which doesn't clone `source`.
  3265. *
  3266. * @private
  3267. * @param {Object} source The object of property values to match.
  3268. * @returns {Function} Returns the new spec function.
  3269. */
  3270. function baseMatches(source) {
  3271. var matchData = getMatchData(source);
  3272. if (matchData.length == 1 && matchData[0][2]) {
  3273. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3274. }
  3275. return function(object) {
  3276. return object === source || baseIsMatch(object, source, matchData);
  3277. };
  3278. }
  3279. /**
  3280. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3281. *
  3282. * @private
  3283. * @param {string} path The path of the property to get.
  3284. * @param {*} srcValue The value to match.
  3285. * @returns {Function} Returns the new spec function.
  3286. */
  3287. function baseMatchesProperty(path, srcValue) {
  3288. if (isKey(path) && isStrictComparable(srcValue)) {
  3289. return matchesStrictComparable(toKey(path), srcValue);
  3290. }
  3291. return function(object) {
  3292. var objValue = get(object, path);
  3293. return (objValue === undefined && objValue === srcValue)
  3294. ? hasIn(object, path)
  3295. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3296. };
  3297. }
  3298. /**
  3299. * The base implementation of `_.merge` without support for multiple sources.
  3300. *
  3301. * @private
  3302. * @param {Object} object The destination object.
  3303. * @param {Object} source The source object.
  3304. * @param {number} srcIndex The index of `source`.
  3305. * @param {Function} [customizer] The function to customize merged values.
  3306. * @param {Object} [stack] Tracks traversed source values and their merged
  3307. * counterparts.
  3308. */
  3309. function baseMerge(object, source, srcIndex, customizer, stack) {
  3310. if (object === source) {
  3311. return;
  3312. }
  3313. baseFor(source, function(srcValue, key) {
  3314. stack || (stack = new Stack);
  3315. if (isObject(srcValue)) {
  3316. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3317. }
  3318. else {
  3319. var newValue = customizer
  3320. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3321. : undefined;
  3322. if (newValue === undefined) {
  3323. newValue = srcValue;
  3324. }
  3325. assignMergeValue(object, key, newValue);
  3326. }
  3327. }, keysIn);
  3328. }
  3329. /**
  3330. * A specialized version of `baseMerge` for arrays and objects which performs
  3331. * deep merges and tracks traversed objects enabling objects with circular
  3332. * references to be merged.
  3333. *
  3334. * @private
  3335. * @param {Object} object The destination object.
  3336. * @param {Object} source The source object.
  3337. * @param {string} key The key of the value to merge.
  3338. * @param {number} srcIndex The index of `source`.
  3339. * @param {Function} mergeFunc The function to merge values.
  3340. * @param {Function} [customizer] The function to customize assigned values.
  3341. * @param {Object} [stack] Tracks traversed source values and their merged
  3342. * counterparts.
  3343. */
  3344. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3345. var objValue = safeGet(object, key),
  3346. srcValue = safeGet(source, key),
  3347. stacked = stack.get(srcValue);
  3348. if (stacked) {
  3349. assignMergeValue(object, key, stacked);
  3350. return;
  3351. }
  3352. var newValue = customizer
  3353. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3354. : undefined;
  3355. var isCommon = newValue === undefined;
  3356. if (isCommon) {
  3357. var isArr = isArray(srcValue),
  3358. isBuff = !isArr && isBuffer(srcValue),
  3359. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3360. newValue = srcValue;
  3361. if (isArr || isBuff || isTyped) {
  3362. if (isArray(objValue)) {
  3363. newValue = objValue;
  3364. }
  3365. else if (isArrayLikeObject(objValue)) {
  3366. newValue = copyArray(objValue);
  3367. }
  3368. else if (isBuff) {
  3369. isCommon = false;
  3370. newValue = cloneBuffer(srcValue, true);
  3371. }
  3372. else if (isTyped) {
  3373. isCommon = false;
  3374. newValue = cloneTypedArray(srcValue, true);
  3375. }
  3376. else {
  3377. newValue = [];
  3378. }
  3379. }
  3380. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3381. newValue = objValue;
  3382. if (isArguments(objValue)) {
  3383. newValue = toPlainObject(objValue);
  3384. }
  3385. else if (!isObject(objValue) || isFunction(objValue)) {
  3386. newValue = initCloneObject(srcValue);
  3387. }
  3388. }
  3389. else {
  3390. isCommon = false;
  3391. }
  3392. }
  3393. if (isCommon) {
  3394. // Recursively merge objects and arrays (susceptible to call stack limits).
  3395. stack.set(srcValue, newValue);
  3396. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3397. stack['delete'](srcValue);
  3398. }
  3399. assignMergeValue(object, key, newValue);
  3400. }
  3401. /**
  3402. * The base implementation of `_.nth` which doesn't coerce arguments.
  3403. *
  3404. * @private
  3405. * @param {Array} array The array to query.
  3406. * @param {number} n The index of the element to return.
  3407. * @returns {*} Returns the nth element of `array`.
  3408. */
  3409. function baseNth(array, n) {
  3410. var length = array.length;
  3411. if (!length) {
  3412. return;
  3413. }
  3414. n += n < 0 ? length : 0;
  3415. return isIndex(n, length) ? array[n] : undefined;
  3416. }
  3417. /**
  3418. * The base implementation of `_.orderBy` without param guards.
  3419. *
  3420. * @private
  3421. * @param {Array|Object} collection The collection to iterate over.
  3422. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3423. * @param {string[]} orders The sort orders of `iteratees`.
  3424. * @returns {Array} Returns the new sorted array.
  3425. */
  3426. function baseOrderBy(collection, iteratees, orders) {
  3427. if (iteratees.length) {
  3428. iteratees = arrayMap(iteratees, function(iteratee) {
  3429. if (isArray(iteratee)) {
  3430. return function(value) {
  3431. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  3432. };
  3433. }
  3434. return iteratee;
  3435. });
  3436. } else {
  3437. iteratees = [identity];
  3438. }
  3439. var index = -1;
  3440. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  3441. var result = baseMap(collection, function(value, key, collection) {
  3442. var criteria = arrayMap(iteratees, function(iteratee) {
  3443. return iteratee(value);
  3444. });
  3445. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3446. });
  3447. return baseSortBy(result, function(object, other) {
  3448. return compareMultiple(object, other, orders);
  3449. });
  3450. }
  3451. /**
  3452. * The base implementation of `_.pick` without support for individual
  3453. * property identifiers.
  3454. *
  3455. * @private
  3456. * @param {Object} object The source object.
  3457. * @param {string[]} paths The property paths to pick.
  3458. * @returns {Object} Returns the new object.
  3459. */
  3460. function basePick(object, paths) {
  3461. return basePickBy(object, paths, function(value, path) {
  3462. return hasIn(object, path);
  3463. });
  3464. }
  3465. /**
  3466. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3467. *
  3468. * @private
  3469. * @param {Object} object The source object.
  3470. * @param {string[]} paths The property paths to pick.
  3471. * @param {Function} predicate The function invoked per property.
  3472. * @returns {Object} Returns the new object.
  3473. */
  3474. function basePickBy(object, paths, predicate) {
  3475. var index = -1,
  3476. length = paths.length,
  3477. result = {};
  3478. while (++index < length) {
  3479. var path = paths[index],
  3480. value = baseGet(object, path);
  3481. if (predicate(value, path)) {
  3482. baseSet(result, castPath(path, object), value);
  3483. }
  3484. }
  3485. return result;
  3486. }
  3487. /**
  3488. * A specialized version of `baseProperty` which supports deep paths.
  3489. *
  3490. * @private
  3491. * @param {Array|string} path The path of the property to get.
  3492. * @returns {Function} Returns the new accessor function.
  3493. */
  3494. function basePropertyDeep(path) {
  3495. return function(object) {
  3496. return baseGet(object, path);
  3497. };
  3498. }
  3499. /**
  3500. * The base implementation of `_.pullAllBy` without support for iteratee
  3501. * shorthands.
  3502. *
  3503. * @private
  3504. * @param {Array} array The array to modify.
  3505. * @param {Array} values The values to remove.
  3506. * @param {Function} [iteratee] The iteratee invoked per element.
  3507. * @param {Function} [comparator] The comparator invoked per element.
  3508. * @returns {Array} Returns `array`.
  3509. */
  3510. function basePullAll(array, values, iteratee, comparator) {
  3511. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3512. index = -1,
  3513. length = values.length,
  3514. seen = array;
  3515. if (array === values) {
  3516. values = copyArray(values);
  3517. }
  3518. if (iteratee) {
  3519. seen = arrayMap(array, baseUnary(iteratee));
  3520. }
  3521. while (++index < length) {
  3522. var fromIndex = 0,
  3523. value = values[index],
  3524. computed = iteratee ? iteratee(value) : value;
  3525. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3526. if (seen !== array) {
  3527. splice.call(seen, fromIndex, 1);
  3528. }
  3529. splice.call(array, fromIndex, 1);
  3530. }
  3531. }
  3532. return array;
  3533. }
  3534. /**
  3535. * The base implementation of `_.pullAt` without support for individual
  3536. * indexes or capturing the removed elements.
  3537. *
  3538. * @private
  3539. * @param {Array} array The array to modify.
  3540. * @param {number[]} indexes The indexes of elements to remove.
  3541. * @returns {Array} Returns `array`.
  3542. */
  3543. function basePullAt(array, indexes) {
  3544. var length = array ? indexes.length : 0,
  3545. lastIndex = length - 1;
  3546. while (length--) {
  3547. var index = indexes[length];
  3548. if (length == lastIndex || index !== previous) {
  3549. var previous = index;
  3550. if (isIndex(index)) {
  3551. splice.call(array, index, 1);
  3552. } else {
  3553. baseUnset(array, index);
  3554. }
  3555. }
  3556. }
  3557. return array;
  3558. }
  3559. /**
  3560. * The base implementation of `_.random` without support for returning
  3561. * floating-point numbers.
  3562. *
  3563. * @private
  3564. * @param {number} lower The lower bound.
  3565. * @param {number} upper The upper bound.
  3566. * @returns {number} Returns the random number.
  3567. */
  3568. function baseRandom(lower, upper) {
  3569. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3570. }
  3571. /**
  3572. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3573. * coerce arguments.
  3574. *
  3575. * @private
  3576. * @param {number} start The start of the range.
  3577. * @param {number} end The end of the range.
  3578. * @param {number} step The value to increment or decrement by.
  3579. * @param {boolean} [fromRight] Specify iterating from right to left.
  3580. * @returns {Array} Returns the range of numbers.
  3581. */
  3582. function baseRange(start, end, step, fromRight) {
  3583. var index = -1,
  3584. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3585. result = Array(length);
  3586. while (length--) {
  3587. result[fromRight ? length : ++index] = start;
  3588. start += step;
  3589. }
  3590. return result;
  3591. }
  3592. /**
  3593. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3594. *
  3595. * @private
  3596. * @param {string} string The string to repeat.
  3597. * @param {number} n The number of times to repeat the string.
  3598. * @returns {string} Returns the repeated string.
  3599. */
  3600. function baseRepeat(string, n) {
  3601. var result = '';
  3602. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3603. return result;
  3604. }
  3605. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3606. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3607. do {
  3608. if (n % 2) {
  3609. result += string;
  3610. }
  3611. n = nativeFloor(n / 2);
  3612. if (n) {
  3613. string += string;
  3614. }
  3615. } while (n);
  3616. return result;
  3617. }
  3618. /**
  3619. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3620. *
  3621. * @private
  3622. * @param {Function} func The function to apply a rest parameter to.
  3623. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3624. * @returns {Function} Returns the new function.
  3625. */
  3626. function baseRest(func, start) {
  3627. return setToString(overRest(func, start, identity), func + '');
  3628. }
  3629. /**
  3630. * The base implementation of `_.sample`.
  3631. *
  3632. * @private
  3633. * @param {Array|Object} collection The collection to sample.
  3634. * @returns {*} Returns the random element.
  3635. */
  3636. function baseSample(collection) {
  3637. return arraySample(values(collection));
  3638. }
  3639. /**
  3640. * The base implementation of `_.sampleSize` without param guards.
  3641. *
  3642. * @private
  3643. * @param {Array|Object} collection The collection to sample.
  3644. * @param {number} n The number of elements to sample.
  3645. * @returns {Array} Returns the random elements.
  3646. */
  3647. function baseSampleSize(collection, n) {
  3648. var array = values(collection);
  3649. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3650. }
  3651. /**
  3652. * The base implementation of `_.set`.
  3653. *
  3654. * @private
  3655. * @param {Object} object The object to modify.
  3656. * @param {Array|string} path The path of the property to set.
  3657. * @param {*} value The value to set.
  3658. * @param {Function} [customizer] The function to customize path creation.
  3659. * @returns {Object} Returns `object`.
  3660. */
  3661. function baseSet(object, path, value, customizer) {
  3662. if (!isObject(object)) {
  3663. return object;
  3664. }
  3665. path = castPath(path, object);
  3666. var index = -1,
  3667. length = path.length,
  3668. lastIndex = length - 1,
  3669. nested = object;
  3670. while (nested != null && ++index < length) {
  3671. var key = toKey(path[index]),
  3672. newValue = value;
  3673. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  3674. return object;
  3675. }
  3676. if (index != lastIndex) {
  3677. var objValue = nested[key];
  3678. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3679. if (newValue === undefined) {
  3680. newValue = isObject(objValue)
  3681. ? objValue
  3682. : (isIndex(path[index + 1]) ? [] : {});
  3683. }
  3684. }
  3685. assignValue(nested, key, newValue);
  3686. nested = nested[key];
  3687. }
  3688. return object;
  3689. }
  3690. /**
  3691. * The base implementation of `setData` without support for hot loop shorting.
  3692. *
  3693. * @private
  3694. * @param {Function} func The function to associate metadata with.
  3695. * @param {*} data The metadata.
  3696. * @returns {Function} Returns `func`.
  3697. */
  3698. var baseSetData = !metaMap ? identity : function(func, data) {
  3699. metaMap.set(func, data);
  3700. return func;
  3701. };
  3702. /**
  3703. * The base implementation of `setToString` without support for hot loop shorting.
  3704. *
  3705. * @private
  3706. * @param {Function} func The function to modify.
  3707. * @param {Function} string The `toString` result.
  3708. * @returns {Function} Returns `func`.
  3709. */
  3710. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3711. return defineProperty(func, 'toString', {
  3712. 'configurable': true,
  3713. 'enumerable': false,
  3714. 'value': constant(string),
  3715. 'writable': true
  3716. });
  3717. };
  3718. /**
  3719. * The base implementation of `_.shuffle`.
  3720. *
  3721. * @private
  3722. * @param {Array|Object} collection The collection to shuffle.
  3723. * @returns {Array} Returns the new shuffled array.
  3724. */
  3725. function baseShuffle(collection) {
  3726. return shuffleSelf(values(collection));
  3727. }
  3728. /**
  3729. * The base implementation of `_.slice` without an iteratee call guard.
  3730. *
  3731. * @private
  3732. * @param {Array} array The array to slice.
  3733. * @param {number} [start=0] The start position.
  3734. * @param {number} [end=array.length] The end position.
  3735. * @returns {Array} Returns the slice of `array`.
  3736. */
  3737. function baseSlice(array, start, end) {
  3738. var index = -1,
  3739. length = array.length;
  3740. if (start < 0) {
  3741. start = -start > length ? 0 : (length + start);
  3742. }
  3743. end = end > length ? length : end;
  3744. if (end < 0) {
  3745. end += length;
  3746. }
  3747. length = start > end ? 0 : ((end - start) >>> 0);
  3748. start >>>= 0;
  3749. var result = Array(length);
  3750. while (++index < length) {
  3751. result[index] = array[index + start];
  3752. }
  3753. return result;
  3754. }
  3755. /**
  3756. * The base implementation of `_.some` without support for iteratee shorthands.
  3757. *
  3758. * @private
  3759. * @param {Array|Object} collection The collection to iterate over.
  3760. * @param {Function} predicate The function invoked per iteration.
  3761. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3762. * else `false`.
  3763. */
  3764. function baseSome(collection, predicate) {
  3765. var result;
  3766. baseEach(collection, function(value, index, collection) {
  3767. result = predicate(value, index, collection);
  3768. return !result;
  3769. });
  3770. return !!result;
  3771. }
  3772. /**
  3773. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3774. * performs a binary search of `array` to determine the index at which `value`
  3775. * should be inserted into `array` in order to maintain its sort order.
  3776. *
  3777. * @private
  3778. * @param {Array} array The sorted array to inspect.
  3779. * @param {*} value The value to evaluate.
  3780. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3781. * @returns {number} Returns the index at which `value` should be inserted
  3782. * into `array`.
  3783. */
  3784. function baseSortedIndex(array, value, retHighest) {
  3785. var low = 0,
  3786. high = array == null ? low : array.length;
  3787. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3788. while (low < high) {
  3789. var mid = (low + high) >>> 1,
  3790. computed = array[mid];
  3791. if (computed !== null && !isSymbol(computed) &&
  3792. (retHighest ? (computed <= value) : (computed < value))) {
  3793. low = mid + 1;
  3794. } else {
  3795. high = mid;
  3796. }
  3797. }
  3798. return high;
  3799. }
  3800. return baseSortedIndexBy(array, value, identity, retHighest);
  3801. }
  3802. /**
  3803. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3804. * which invokes `iteratee` for `value` and each element of `array` to compute
  3805. * their sort ranking. The iteratee is invoked with one argument; (value).
  3806. *
  3807. * @private
  3808. * @param {Array} array The sorted array to inspect.
  3809. * @param {*} value The value to evaluate.
  3810. * @param {Function} iteratee The iteratee invoked per element.
  3811. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3812. * @returns {number} Returns the index at which `value` should be inserted
  3813. * into `array`.
  3814. */
  3815. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3816. var low = 0,
  3817. high = array == null ? 0 : array.length;
  3818. if (high === 0) {
  3819. return 0;
  3820. }
  3821. value = iteratee(value);
  3822. var valIsNaN = value !== value,
  3823. valIsNull = value === null,
  3824. valIsSymbol = isSymbol(value),
  3825. valIsUndefined = value === undefined;
  3826. while (low < high) {
  3827. var mid = nativeFloor((low + high) / 2),
  3828. computed = iteratee(array[mid]),
  3829. othIsDefined = computed !== undefined,
  3830. othIsNull = computed === null,
  3831. othIsReflexive = computed === computed,
  3832. othIsSymbol = isSymbol(computed);
  3833. if (valIsNaN) {
  3834. var setLow = retHighest || othIsReflexive;
  3835. } else if (valIsUndefined) {
  3836. setLow = othIsReflexive && (retHighest || othIsDefined);
  3837. } else if (valIsNull) {
  3838. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3839. } else if (valIsSymbol) {
  3840. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3841. } else if (othIsNull || othIsSymbol) {
  3842. setLow = false;
  3843. } else {
  3844. setLow = retHighest ? (computed <= value) : (computed < value);
  3845. }
  3846. if (setLow) {
  3847. low = mid + 1;
  3848. } else {
  3849. high = mid;
  3850. }
  3851. }
  3852. return nativeMin(high, MAX_ARRAY_INDEX);
  3853. }
  3854. /**
  3855. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3856. * support for iteratee shorthands.
  3857. *
  3858. * @private
  3859. * @param {Array} array The array to inspect.
  3860. * @param {Function} [iteratee] The iteratee invoked per element.
  3861. * @returns {Array} Returns the new duplicate free array.
  3862. */
  3863. function baseSortedUniq(array, iteratee) {
  3864. var index = -1,
  3865. length = array.length,
  3866. resIndex = 0,
  3867. result = [];
  3868. while (++index < length) {
  3869. var value = array[index],
  3870. computed = iteratee ? iteratee(value) : value;
  3871. if (!index || !eq(computed, seen)) {
  3872. var seen = computed;
  3873. result[resIndex++] = value === 0 ? 0 : value;
  3874. }
  3875. }
  3876. return result;
  3877. }
  3878. /**
  3879. * The base implementation of `_.toNumber` which doesn't ensure correct
  3880. * conversions of binary, hexadecimal, or octal string values.
  3881. *
  3882. * @private
  3883. * @param {*} value The value to process.
  3884. * @returns {number} Returns the number.
  3885. */
  3886. function baseToNumber(value) {
  3887. if (typeof value == 'number') {
  3888. return value;
  3889. }
  3890. if (isSymbol(value)) {
  3891. return NAN;
  3892. }
  3893. return +value;
  3894. }
  3895. /**
  3896. * The base implementation of `_.toString` which doesn't convert nullish
  3897. * values to empty strings.
  3898. *
  3899. * @private
  3900. * @param {*} value The value to process.
  3901. * @returns {string} Returns the string.
  3902. */
  3903. function baseToString(value) {
  3904. // Exit early for strings to avoid a performance hit in some environments.
  3905. if (typeof value == 'string') {
  3906. return value;
  3907. }
  3908. if (isArray(value)) {
  3909. // Recursively convert values (susceptible to call stack limits).
  3910. return arrayMap(value, baseToString) + '';
  3911. }
  3912. if (isSymbol(value)) {
  3913. return symbolToString ? symbolToString.call(value) : '';
  3914. }
  3915. var result = (value + '');
  3916. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3917. }
  3918. /**
  3919. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3920. *
  3921. * @private
  3922. * @param {Array} array The array to inspect.
  3923. * @param {Function} [iteratee] The iteratee invoked per element.
  3924. * @param {Function} [comparator] The comparator invoked per element.
  3925. * @returns {Array} Returns the new duplicate free array.
  3926. */
  3927. function baseUniq(array, iteratee, comparator) {
  3928. var index = -1,
  3929. includes = arrayIncludes,
  3930. length = array.length,
  3931. isCommon = true,
  3932. result = [],
  3933. seen = result;
  3934. if (comparator) {
  3935. isCommon = false;
  3936. includes = arrayIncludesWith;
  3937. }
  3938. else if (length >= LARGE_ARRAY_SIZE) {
  3939. var set = iteratee ? null : createSet(array);
  3940. if (set) {
  3941. return setToArray(set);
  3942. }
  3943. isCommon = false;
  3944. includes = cacheHas;
  3945. seen = new SetCache;
  3946. }
  3947. else {
  3948. seen = iteratee ? [] : result;
  3949. }
  3950. outer:
  3951. while (++index < length) {
  3952. var value = array[index],
  3953. computed = iteratee ? iteratee(value) : value;
  3954. value = (comparator || value !== 0) ? value : 0;
  3955. if (isCommon && computed === computed) {
  3956. var seenIndex = seen.length;
  3957. while (seenIndex--) {
  3958. if (seen[seenIndex] === computed) {
  3959. continue outer;
  3960. }
  3961. }
  3962. if (iteratee) {
  3963. seen.push(computed);
  3964. }
  3965. result.push(value);
  3966. }
  3967. else if (!includes(seen, computed, comparator)) {
  3968. if (seen !== result) {
  3969. seen.push(computed);
  3970. }
  3971. result.push(value);
  3972. }
  3973. }
  3974. return result;
  3975. }
  3976. /**
  3977. * The base implementation of `_.unset`.
  3978. *
  3979. * @private
  3980. * @param {Object} object The object to modify.
  3981. * @param {Array|string} path The property path to unset.
  3982. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3983. */
  3984. function baseUnset(object, path) {
  3985. path = castPath(path, object);
  3986. // Prevent prototype pollution:
  3987. // https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg
  3988. // https://github.com/lodash/lodash/security/advisories/GHSA-f23m-r3pf-42rh
  3989. var index = -1,
  3990. length = path.length;
  3991. if (!length) {
  3992. return true;
  3993. }
  3994. while (++index < length) {
  3995. var key = toKey(path[index]);
  3996. // Always block "__proto__" anywhere in the path if it's not expected
  3997. if (key === '__proto__' && !hasOwnProperty.call(object, '__proto__')) {
  3998. return false;
  3999. }
  4000. // Block constructor/prototype as non-terminal traversal keys to prevent
  4001. // escaping the object graph into built-in constructors and prototypes.
  4002. if ((key === 'constructor' || key === 'prototype') && index < length - 1) {
  4003. return false;
  4004. }
  4005. }
  4006. var obj = parent(object, path);
  4007. return obj == null || delete obj[toKey(last(path))];
  4008. }
  4009. /**
  4010. * The base implementation of `_.update`.
  4011. *
  4012. * @private
  4013. * @param {Object} object The object to modify.
  4014. * @param {Array|string} path The path of the property to update.
  4015. * @param {Function} updater The function to produce the updated value.
  4016. * @param {Function} [customizer] The function to customize path creation.
  4017. * @returns {Object} Returns `object`.
  4018. */
  4019. function baseUpdate(object, path, updater, customizer) {
  4020. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  4021. }
  4022. /**
  4023. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  4024. * without support for iteratee shorthands.
  4025. *
  4026. * @private
  4027. * @param {Array} array The array to query.
  4028. * @param {Function} predicate The function invoked per iteration.
  4029. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4030. * @param {boolean} [fromRight] Specify iterating from right to left.
  4031. * @returns {Array} Returns the slice of `array`.
  4032. */
  4033. function baseWhile(array, predicate, isDrop, fromRight) {
  4034. var length = array.length,
  4035. index = fromRight ? length : -1;
  4036. while ((fromRight ? index-- : ++index < length) &&
  4037. predicate(array[index], index, array)) {}
  4038. return isDrop
  4039. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4040. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4041. }
  4042. /**
  4043. * The base implementation of `wrapperValue` which returns the result of
  4044. * performing a sequence of actions on the unwrapped `value`, where each
  4045. * successive action is supplied the return value of the previous.
  4046. *
  4047. * @private
  4048. * @param {*} value The unwrapped value.
  4049. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4050. * @returns {*} Returns the resolved value.
  4051. */
  4052. function baseWrapperValue(value, actions) {
  4053. var result = value;
  4054. if (result instanceof LazyWrapper) {
  4055. result = result.value();
  4056. }
  4057. return arrayReduce(actions, function(result, action) {
  4058. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  4059. }, result);
  4060. }
  4061. /**
  4062. * The base implementation of methods like `_.xor`, without support for
  4063. * iteratee shorthands, that accepts an array of arrays to inspect.
  4064. *
  4065. * @private
  4066. * @param {Array} arrays The arrays to inspect.
  4067. * @param {Function} [iteratee] The iteratee invoked per element.
  4068. * @param {Function} [comparator] The comparator invoked per element.
  4069. * @returns {Array} Returns the new array of values.
  4070. */
  4071. function baseXor(arrays, iteratee, comparator) {
  4072. var length = arrays.length;
  4073. if (length < 2) {
  4074. return length ? baseUniq(arrays[0]) : [];
  4075. }
  4076. var index = -1,
  4077. result = Array(length);
  4078. while (++index < length) {
  4079. var array = arrays[index],
  4080. othIndex = -1;
  4081. while (++othIndex < length) {
  4082. if (othIndex != index) {
  4083. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4084. }
  4085. }
  4086. }
  4087. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4088. }
  4089. /**
  4090. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4091. *
  4092. * @private
  4093. * @param {Array} props The property identifiers.
  4094. * @param {Array} values The property values.
  4095. * @param {Function} assignFunc The function to assign values.
  4096. * @returns {Object} Returns the new object.
  4097. */
  4098. function baseZipObject(props, values, assignFunc) {
  4099. var index = -1,
  4100. length = props.length,
  4101. valsLength = values.length,
  4102. result = {};
  4103. while (++index < length) {
  4104. var value = index < valsLength ? values[index] : undefined;
  4105. assignFunc(result, props[index], value);
  4106. }
  4107. return result;
  4108. }
  4109. /**
  4110. * Casts `value` to an empty array if it's not an array like object.
  4111. *
  4112. * @private
  4113. * @param {*} value The value to inspect.
  4114. * @returns {Array|Object} Returns the cast array-like object.
  4115. */
  4116. function castArrayLikeObject(value) {
  4117. return isArrayLikeObject(value) ? value : [];
  4118. }
  4119. /**
  4120. * Casts `value` to `identity` if it's not a function.
  4121. *
  4122. * @private
  4123. * @param {*} value The value to inspect.
  4124. * @returns {Function} Returns cast function.
  4125. */
  4126. function castFunction(value) {
  4127. return typeof value == 'function' ? value : identity;
  4128. }
  4129. /**
  4130. * Casts `value` to a path array if it's not one.
  4131. *
  4132. * @private
  4133. * @param {*} value The value to inspect.
  4134. * @param {Object} [object] The object to query keys on.
  4135. * @returns {Array} Returns the cast property path array.
  4136. */
  4137. function castPath(value, object) {
  4138. if (isArray(value)) {
  4139. return value;
  4140. }
  4141. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4142. }
  4143. /**
  4144. * A `baseRest` alias which can be replaced with `identity` by module
  4145. * replacement plugins.
  4146. *
  4147. * @private
  4148. * @type {Function}
  4149. * @param {Function} func The function to apply a rest parameter to.
  4150. * @returns {Function} Returns the new function.
  4151. */
  4152. var castRest = baseRest;
  4153. /**
  4154. * Casts `array` to a slice if it's needed.
  4155. *
  4156. * @private
  4157. * @param {Array} array The array to inspect.
  4158. * @param {number} start The start position.
  4159. * @param {number} [end=array.length] The end position.
  4160. * @returns {Array} Returns the cast slice.
  4161. */
  4162. function castSlice(array, start, end) {
  4163. var length = array.length;
  4164. end = end === undefined ? length : end;
  4165. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4166. }
  4167. /**
  4168. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4169. *
  4170. * @private
  4171. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4172. */
  4173. var clearTimeout = ctxClearTimeout || function(id) {
  4174. return root.clearTimeout(id);
  4175. };
  4176. /**
  4177. * Creates a clone of `buffer`.
  4178. *
  4179. * @private
  4180. * @param {Buffer} buffer The buffer to clone.
  4181. * @param {boolean} [isDeep] Specify a deep clone.
  4182. * @returns {Buffer} Returns the cloned buffer.
  4183. */
  4184. function cloneBuffer(buffer, isDeep) {
  4185. if (isDeep) {
  4186. return buffer.slice();
  4187. }
  4188. var length = buffer.length,
  4189. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4190. buffer.copy(result);
  4191. return result;
  4192. }
  4193. /**
  4194. * Creates a clone of `arrayBuffer`.
  4195. *
  4196. * @private
  4197. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4198. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4199. */
  4200. function cloneArrayBuffer(arrayBuffer) {
  4201. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4202. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4203. return result;
  4204. }
  4205. /**
  4206. * Creates a clone of `dataView`.
  4207. *
  4208. * @private
  4209. * @param {Object} dataView The data view to clone.
  4210. * @param {boolean} [isDeep] Specify a deep clone.
  4211. * @returns {Object} Returns the cloned data view.
  4212. */
  4213. function cloneDataView(dataView, isDeep) {
  4214. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4215. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4216. }
  4217. /**
  4218. * Creates a clone of `regexp`.
  4219. *
  4220. * @private
  4221. * @param {Object} regexp The regexp to clone.
  4222. * @returns {Object} Returns the cloned regexp.
  4223. */
  4224. function cloneRegExp(regexp) {
  4225. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4226. result.lastIndex = regexp.lastIndex;
  4227. return result;
  4228. }
  4229. /**
  4230. * Creates a clone of the `symbol` object.
  4231. *
  4232. * @private
  4233. * @param {Object} symbol The symbol object to clone.
  4234. * @returns {Object} Returns the cloned symbol object.
  4235. */
  4236. function cloneSymbol(symbol) {
  4237. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4238. }
  4239. /**
  4240. * Creates a clone of `typedArray`.
  4241. *
  4242. * @private
  4243. * @param {Object} typedArray The typed array to clone.
  4244. * @param {boolean} [isDeep] Specify a deep clone.
  4245. * @returns {Object} Returns the cloned typed array.
  4246. */
  4247. function cloneTypedArray(typedArray, isDeep) {
  4248. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4249. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4250. }
  4251. /**
  4252. * Compares values to sort them in ascending order.
  4253. *
  4254. * @private
  4255. * @param {*} value The value to compare.
  4256. * @param {*} other The other value to compare.
  4257. * @returns {number} Returns the sort order indicator for `value`.
  4258. */
  4259. function compareAscending(value, other) {
  4260. if (value !== other) {
  4261. var valIsDefined = value !== undefined,
  4262. valIsNull = value === null,
  4263. valIsReflexive = value === value,
  4264. valIsSymbol = isSymbol(value);
  4265. var othIsDefined = other !== undefined,
  4266. othIsNull = other === null,
  4267. othIsReflexive = other === other,
  4268. othIsSymbol = isSymbol(other);
  4269. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4270. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4271. (valIsNull && othIsDefined && othIsReflexive) ||
  4272. (!valIsDefined && othIsReflexive) ||
  4273. !valIsReflexive) {
  4274. return 1;
  4275. }
  4276. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4277. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4278. (othIsNull && valIsDefined && valIsReflexive) ||
  4279. (!othIsDefined && valIsReflexive) ||
  4280. !othIsReflexive) {
  4281. return -1;
  4282. }
  4283. }
  4284. return 0;
  4285. }
  4286. /**
  4287. * Used by `_.orderBy` to compare multiple properties of a value to another
  4288. * and stable sort them.
  4289. *
  4290. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4291. * specify an order of "desc" for descending or "asc" for ascending sort order
  4292. * of corresponding values.
  4293. *
  4294. * @private
  4295. * @param {Object} object The object to compare.
  4296. * @param {Object} other The other object to compare.
  4297. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4298. * @returns {number} Returns the sort order indicator for `object`.
  4299. */
  4300. function compareMultiple(object, other, orders) {
  4301. var index = -1,
  4302. objCriteria = object.criteria,
  4303. othCriteria = other.criteria,
  4304. length = objCriteria.length,
  4305. ordersLength = orders.length;
  4306. while (++index < length) {
  4307. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4308. if (result) {
  4309. if (index >= ordersLength) {
  4310. return result;
  4311. }
  4312. var order = orders[index];
  4313. return result * (order == 'desc' ? -1 : 1);
  4314. }
  4315. }
  4316. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4317. // that causes it, under certain circumstances, to provide the same value for
  4318. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4319. // for more details.
  4320. //
  4321. // This also ensures a stable sort in V8 and other engines.
  4322. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4323. return object.index - other.index;
  4324. }
  4325. /**
  4326. * Creates an array that is the composition of partially applied arguments,
  4327. * placeholders, and provided arguments into a single array of arguments.
  4328. *
  4329. * @private
  4330. * @param {Array} args The provided arguments.
  4331. * @param {Array} partials The arguments to prepend to those provided.
  4332. * @param {Array} holders The `partials` placeholder indexes.
  4333. * @params {boolean} [isCurried] Specify composing for a curried function.
  4334. * @returns {Array} Returns the new array of composed arguments.
  4335. */
  4336. function composeArgs(args, partials, holders, isCurried) {
  4337. var argsIndex = -1,
  4338. argsLength = args.length,
  4339. holdersLength = holders.length,
  4340. leftIndex = -1,
  4341. leftLength = partials.length,
  4342. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4343. result = Array(leftLength + rangeLength),
  4344. isUncurried = !isCurried;
  4345. while (++leftIndex < leftLength) {
  4346. result[leftIndex] = partials[leftIndex];
  4347. }
  4348. while (++argsIndex < holdersLength) {
  4349. if (isUncurried || argsIndex < argsLength) {
  4350. result[holders[argsIndex]] = args[argsIndex];
  4351. }
  4352. }
  4353. while (rangeLength--) {
  4354. result[leftIndex++] = args[argsIndex++];
  4355. }
  4356. return result;
  4357. }
  4358. /**
  4359. * This function is like `composeArgs` except that the arguments composition
  4360. * is tailored for `_.partialRight`.
  4361. *
  4362. * @private
  4363. * @param {Array} args The provided arguments.
  4364. * @param {Array} partials The arguments to append to those provided.
  4365. * @param {Array} holders The `partials` placeholder indexes.
  4366. * @params {boolean} [isCurried] Specify composing for a curried function.
  4367. * @returns {Array} Returns the new array of composed arguments.
  4368. */
  4369. function composeArgsRight(args, partials, holders, isCurried) {
  4370. var argsIndex = -1,
  4371. argsLength = args.length,
  4372. holdersIndex = -1,
  4373. holdersLength = holders.length,
  4374. rightIndex = -1,
  4375. rightLength = partials.length,
  4376. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4377. result = Array(rangeLength + rightLength),
  4378. isUncurried = !isCurried;
  4379. while (++argsIndex < rangeLength) {
  4380. result[argsIndex] = args[argsIndex];
  4381. }
  4382. var offset = argsIndex;
  4383. while (++rightIndex < rightLength) {
  4384. result[offset + rightIndex] = partials[rightIndex];
  4385. }
  4386. while (++holdersIndex < holdersLength) {
  4387. if (isUncurried || argsIndex < argsLength) {
  4388. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4389. }
  4390. }
  4391. return result;
  4392. }
  4393. /**
  4394. * Copies the values of `source` to `array`.
  4395. *
  4396. * @private
  4397. * @param {Array} source The array to copy values from.
  4398. * @param {Array} [array=[]] The array to copy values to.
  4399. * @returns {Array} Returns `array`.
  4400. */
  4401. function copyArray(source, array) {
  4402. var index = -1,
  4403. length = source.length;
  4404. array || (array = Array(length));
  4405. while (++index < length) {
  4406. array[index] = source[index];
  4407. }
  4408. return array;
  4409. }
  4410. /**
  4411. * Copies properties of `source` to `object`.
  4412. *
  4413. * @private
  4414. * @param {Object} source The object to copy properties from.
  4415. * @param {Array} props The property identifiers to copy.
  4416. * @param {Object} [object={}] The object to copy properties to.
  4417. * @param {Function} [customizer] The function to customize copied values.
  4418. * @returns {Object} Returns `object`.
  4419. */
  4420. function copyObject(source, props, object, customizer) {
  4421. var isNew = !object;
  4422. object || (object = {});
  4423. var index = -1,
  4424. length = props.length;
  4425. while (++index < length) {
  4426. var key = props[index];
  4427. var newValue = customizer
  4428. ? customizer(object[key], source[key], key, object, source)
  4429. : undefined;
  4430. if (newValue === undefined) {
  4431. newValue = source[key];
  4432. }
  4433. if (isNew) {
  4434. baseAssignValue(object, key, newValue);
  4435. } else {
  4436. assignValue(object, key, newValue);
  4437. }
  4438. }
  4439. return object;
  4440. }
  4441. /**
  4442. * Copies own symbols of `source` to `object`.
  4443. *
  4444. * @private
  4445. * @param {Object} source The object to copy symbols from.
  4446. * @param {Object} [object={}] The object to copy symbols to.
  4447. * @returns {Object} Returns `object`.
  4448. */
  4449. function copySymbols(source, object) {
  4450. return copyObject(source, getSymbols(source), object);
  4451. }
  4452. /**
  4453. * Copies own and inherited symbols of `source` to `object`.
  4454. *
  4455. * @private
  4456. * @param {Object} source The object to copy symbols from.
  4457. * @param {Object} [object={}] The object to copy symbols to.
  4458. * @returns {Object} Returns `object`.
  4459. */
  4460. function copySymbolsIn(source, object) {
  4461. return copyObject(source, getSymbolsIn(source), object);
  4462. }
  4463. /**
  4464. * Creates a function like `_.groupBy`.
  4465. *
  4466. * @private
  4467. * @param {Function} setter The function to set accumulator values.
  4468. * @param {Function} [initializer] The accumulator object initializer.
  4469. * @returns {Function} Returns the new aggregator function.
  4470. */
  4471. function createAggregator(setter, initializer) {
  4472. return function(collection, iteratee) {
  4473. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4474. accumulator = initializer ? initializer() : {};
  4475. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4476. };
  4477. }
  4478. /**
  4479. * Creates a function like `_.assign`.
  4480. *
  4481. * @private
  4482. * @param {Function} assigner The function to assign values.
  4483. * @returns {Function} Returns the new assigner function.
  4484. */
  4485. function createAssigner(assigner) {
  4486. return baseRest(function(object, sources) {
  4487. var index = -1,
  4488. length = sources.length,
  4489. customizer = length > 1 ? sources[length - 1] : undefined,
  4490. guard = length > 2 ? sources[2] : undefined;
  4491. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4492. ? (length--, customizer)
  4493. : undefined;
  4494. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4495. customizer = length < 3 ? undefined : customizer;
  4496. length = 1;
  4497. }
  4498. object = Object(object);
  4499. while (++index < length) {
  4500. var source = sources[index];
  4501. if (source) {
  4502. assigner(object, source, index, customizer);
  4503. }
  4504. }
  4505. return object;
  4506. });
  4507. }
  4508. /**
  4509. * Creates a `baseEach` or `baseEachRight` function.
  4510. *
  4511. * @private
  4512. * @param {Function} eachFunc The function to iterate over a collection.
  4513. * @param {boolean} [fromRight] Specify iterating from right to left.
  4514. * @returns {Function} Returns the new base function.
  4515. */
  4516. function createBaseEach(eachFunc, fromRight) {
  4517. return function(collection, iteratee) {
  4518. if (collection == null) {
  4519. return collection;
  4520. }
  4521. if (!isArrayLike(collection)) {
  4522. return eachFunc(collection, iteratee);
  4523. }
  4524. var length = collection.length,
  4525. index = fromRight ? length : -1,
  4526. iterable = Object(collection);
  4527. while ((fromRight ? index-- : ++index < length)) {
  4528. if (iteratee(iterable[index], index, iterable) === false) {
  4529. break;
  4530. }
  4531. }
  4532. return collection;
  4533. };
  4534. }
  4535. /**
  4536. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4537. *
  4538. * @private
  4539. * @param {boolean} [fromRight] Specify iterating from right to left.
  4540. * @returns {Function} Returns the new base function.
  4541. */
  4542. function createBaseFor(fromRight) {
  4543. return function(object, iteratee, keysFunc) {
  4544. var index = -1,
  4545. iterable = Object(object),
  4546. props = keysFunc(object),
  4547. length = props.length;
  4548. while (length--) {
  4549. var key = props[fromRight ? length : ++index];
  4550. if (iteratee(iterable[key], key, iterable) === false) {
  4551. break;
  4552. }
  4553. }
  4554. return object;
  4555. };
  4556. }
  4557. /**
  4558. * Creates a function that wraps `func` to invoke it with the optional `this`
  4559. * binding of `thisArg`.
  4560. *
  4561. * @private
  4562. * @param {Function} func The function to wrap.
  4563. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4564. * @param {*} [thisArg] The `this` binding of `func`.
  4565. * @returns {Function} Returns the new wrapped function.
  4566. */
  4567. function createBind(func, bitmask, thisArg) {
  4568. var isBind = bitmask & WRAP_BIND_FLAG,
  4569. Ctor = createCtor(func);
  4570. function wrapper() {
  4571. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4572. return fn.apply(isBind ? thisArg : this, arguments);
  4573. }
  4574. return wrapper;
  4575. }
  4576. /**
  4577. * Creates a function like `_.lowerFirst`.
  4578. *
  4579. * @private
  4580. * @param {string} methodName The name of the `String` case method to use.
  4581. * @returns {Function} Returns the new case function.
  4582. */
  4583. function createCaseFirst(methodName) {
  4584. return function(string) {
  4585. string = toString(string);
  4586. var strSymbols = hasUnicode(string)
  4587. ? stringToArray(string)
  4588. : undefined;
  4589. var chr = strSymbols
  4590. ? strSymbols[0]
  4591. : string.charAt(0);
  4592. var trailing = strSymbols
  4593. ? castSlice(strSymbols, 1).join('')
  4594. : string.slice(1);
  4595. return chr[methodName]() + trailing;
  4596. };
  4597. }
  4598. /**
  4599. * Creates a function like `_.camelCase`.
  4600. *
  4601. * @private
  4602. * @param {Function} callback The function to combine each word.
  4603. * @returns {Function} Returns the new compounder function.
  4604. */
  4605. function createCompounder(callback) {
  4606. return function(string) {
  4607. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4608. };
  4609. }
  4610. /**
  4611. * Creates a function that produces an instance of `Ctor` regardless of
  4612. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4613. *
  4614. * @private
  4615. * @param {Function} Ctor The constructor to wrap.
  4616. * @returns {Function} Returns the new wrapped function.
  4617. */
  4618. function createCtor(Ctor) {
  4619. return function() {
  4620. // Use a `switch` statement to work with class constructors. See
  4621. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4622. // for more details.
  4623. var args = arguments;
  4624. switch (args.length) {
  4625. case 0: return new Ctor;
  4626. case 1: return new Ctor(args[0]);
  4627. case 2: return new Ctor(args[0], args[1]);
  4628. case 3: return new Ctor(args[0], args[1], args[2]);
  4629. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4630. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4631. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4632. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4633. }
  4634. var thisBinding = baseCreate(Ctor.prototype),
  4635. result = Ctor.apply(thisBinding, args);
  4636. // Mimic the constructor's `return` behavior.
  4637. // See https://es5.github.io/#x13.2.2 for more details.
  4638. return isObject(result) ? result : thisBinding;
  4639. };
  4640. }
  4641. /**
  4642. * Creates a function that wraps `func` to enable currying.
  4643. *
  4644. * @private
  4645. * @param {Function} func The function to wrap.
  4646. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4647. * @param {number} arity The arity of `func`.
  4648. * @returns {Function} Returns the new wrapped function.
  4649. */
  4650. function createCurry(func, bitmask, arity) {
  4651. var Ctor = createCtor(func);
  4652. function wrapper() {
  4653. var length = arguments.length,
  4654. args = Array(length),
  4655. index = length,
  4656. placeholder = getHolder(wrapper);
  4657. while (index--) {
  4658. args[index] = arguments[index];
  4659. }
  4660. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4661. ? []
  4662. : replaceHolders(args, placeholder);
  4663. length -= holders.length;
  4664. if (length < arity) {
  4665. return createRecurry(
  4666. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4667. args, holders, undefined, undefined, arity - length);
  4668. }
  4669. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4670. return apply(fn, this, args);
  4671. }
  4672. return wrapper;
  4673. }
  4674. /**
  4675. * Creates a `_.find` or `_.findLast` function.
  4676. *
  4677. * @private
  4678. * @param {Function} findIndexFunc The function to find the collection index.
  4679. * @returns {Function} Returns the new find function.
  4680. */
  4681. function createFind(findIndexFunc) {
  4682. return function(collection, predicate, fromIndex) {
  4683. var iterable = Object(collection);
  4684. if (!isArrayLike(collection)) {
  4685. var iteratee = getIteratee(predicate, 3);
  4686. collection = keys(collection);
  4687. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4688. }
  4689. var index = findIndexFunc(collection, predicate, fromIndex);
  4690. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4691. };
  4692. }
  4693. /**
  4694. * Creates a `_.flow` or `_.flowRight` function.
  4695. *
  4696. * @private
  4697. * @param {boolean} [fromRight] Specify iterating from right to left.
  4698. * @returns {Function} Returns the new flow function.
  4699. */
  4700. function createFlow(fromRight) {
  4701. return flatRest(function(funcs) {
  4702. var length = funcs.length,
  4703. index = length,
  4704. prereq = LodashWrapper.prototype.thru;
  4705. if (fromRight) {
  4706. funcs.reverse();
  4707. }
  4708. while (index--) {
  4709. var func = funcs[index];
  4710. if (typeof func != 'function') {
  4711. throw new TypeError(FUNC_ERROR_TEXT);
  4712. }
  4713. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4714. var wrapper = new LodashWrapper([], true);
  4715. }
  4716. }
  4717. index = wrapper ? index : length;
  4718. while (++index < length) {
  4719. func = funcs[index];
  4720. var funcName = getFuncName(func),
  4721. data = funcName == 'wrapper' ? getData(func) : undefined;
  4722. if (data && isLaziable(data[0]) &&
  4723. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4724. !data[4].length && data[9] == 1
  4725. ) {
  4726. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4727. } else {
  4728. wrapper = (func.length == 1 && isLaziable(func))
  4729. ? wrapper[funcName]()
  4730. : wrapper.thru(func);
  4731. }
  4732. }
  4733. return function() {
  4734. var args = arguments,
  4735. value = args[0];
  4736. if (wrapper && args.length == 1 && isArray(value)) {
  4737. return wrapper.plant(value).value();
  4738. }
  4739. var index = 0,
  4740. result = length ? funcs[index].apply(this, args) : value;
  4741. while (++index < length) {
  4742. result = funcs[index].call(this, result);
  4743. }
  4744. return result;
  4745. };
  4746. });
  4747. }
  4748. /**
  4749. * Creates a function that wraps `func` to invoke it with optional `this`
  4750. * binding of `thisArg`, partial application, and currying.
  4751. *
  4752. * @private
  4753. * @param {Function|string} func The function or method name to wrap.
  4754. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4755. * @param {*} [thisArg] The `this` binding of `func`.
  4756. * @param {Array} [partials] The arguments to prepend to those provided to
  4757. * the new function.
  4758. * @param {Array} [holders] The `partials` placeholder indexes.
  4759. * @param {Array} [partialsRight] The arguments to append to those provided
  4760. * to the new function.
  4761. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4762. * @param {Array} [argPos] The argument positions of the new function.
  4763. * @param {number} [ary] The arity cap of `func`.
  4764. * @param {number} [arity] The arity of `func`.
  4765. * @returns {Function} Returns the new wrapped function.
  4766. */
  4767. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4768. var isAry = bitmask & WRAP_ARY_FLAG,
  4769. isBind = bitmask & WRAP_BIND_FLAG,
  4770. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4771. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4772. isFlip = bitmask & WRAP_FLIP_FLAG,
  4773. Ctor = isBindKey ? undefined : createCtor(func);
  4774. function wrapper() {
  4775. var length = arguments.length,
  4776. args = Array(length),
  4777. index = length;
  4778. while (index--) {
  4779. args[index] = arguments[index];
  4780. }
  4781. if (isCurried) {
  4782. var placeholder = getHolder(wrapper),
  4783. holdersCount = countHolders(args, placeholder);
  4784. }
  4785. if (partials) {
  4786. args = composeArgs(args, partials, holders, isCurried);
  4787. }
  4788. if (partialsRight) {
  4789. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4790. }
  4791. length -= holdersCount;
  4792. if (isCurried && length < arity) {
  4793. var newHolders = replaceHolders(args, placeholder);
  4794. return createRecurry(
  4795. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4796. args, newHolders, argPos, ary, arity - length
  4797. );
  4798. }
  4799. var thisBinding = isBind ? thisArg : this,
  4800. fn = isBindKey ? thisBinding[func] : func;
  4801. length = args.length;
  4802. if (argPos) {
  4803. args = reorder(args, argPos);
  4804. } else if (isFlip && length > 1) {
  4805. args.reverse();
  4806. }
  4807. if (isAry && ary < length) {
  4808. args.length = ary;
  4809. }
  4810. if (this && this !== root && this instanceof wrapper) {
  4811. fn = Ctor || createCtor(fn);
  4812. }
  4813. return fn.apply(thisBinding, args);
  4814. }
  4815. return wrapper;
  4816. }
  4817. /**
  4818. * Creates a function like `_.invertBy`.
  4819. *
  4820. * @private
  4821. * @param {Function} setter The function to set accumulator values.
  4822. * @param {Function} toIteratee The function to resolve iteratees.
  4823. * @returns {Function} Returns the new inverter function.
  4824. */
  4825. function createInverter(setter, toIteratee) {
  4826. return function(object, iteratee) {
  4827. return baseInverter(object, setter, toIteratee(iteratee), {});
  4828. };
  4829. }
  4830. /**
  4831. * Creates a function that performs a mathematical operation on two values.
  4832. *
  4833. * @private
  4834. * @param {Function} operator The function to perform the operation.
  4835. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4836. * @returns {Function} Returns the new mathematical operation function.
  4837. */
  4838. function createMathOperation(operator, defaultValue) {
  4839. return function(value, other) {
  4840. var result;
  4841. if (value === undefined && other === undefined) {
  4842. return defaultValue;
  4843. }
  4844. if (value !== undefined) {
  4845. result = value;
  4846. }
  4847. if (other !== undefined) {
  4848. if (result === undefined) {
  4849. return other;
  4850. }
  4851. if (typeof value == 'string' || typeof other == 'string') {
  4852. value = baseToString(value);
  4853. other = baseToString(other);
  4854. } else {
  4855. value = baseToNumber(value);
  4856. other = baseToNumber(other);
  4857. }
  4858. result = operator(value, other);
  4859. }
  4860. return result;
  4861. };
  4862. }
  4863. /**
  4864. * Creates a function like `_.over`.
  4865. *
  4866. * @private
  4867. * @param {Function} arrayFunc The function to iterate over iteratees.
  4868. * @returns {Function} Returns the new over function.
  4869. */
  4870. function createOver(arrayFunc) {
  4871. return flatRest(function(iteratees) {
  4872. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4873. return baseRest(function(args) {
  4874. var thisArg = this;
  4875. return arrayFunc(iteratees, function(iteratee) {
  4876. return apply(iteratee, thisArg, args);
  4877. });
  4878. });
  4879. });
  4880. }
  4881. /**
  4882. * Creates the padding for `string` based on `length`. The `chars` string
  4883. * is truncated if the number of characters exceeds `length`.
  4884. *
  4885. * @private
  4886. * @param {number} length The padding length.
  4887. * @param {string} [chars=' '] The string used as padding.
  4888. * @returns {string} Returns the padding for `string`.
  4889. */
  4890. function createPadding(length, chars) {
  4891. chars = chars === undefined ? ' ' : baseToString(chars);
  4892. var charsLength = chars.length;
  4893. if (charsLength < 2) {
  4894. return charsLength ? baseRepeat(chars, length) : chars;
  4895. }
  4896. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4897. return hasUnicode(chars)
  4898. ? castSlice(stringToArray(result), 0, length).join('')
  4899. : result.slice(0, length);
  4900. }
  4901. /**
  4902. * Creates a function that wraps `func` to invoke it with the `this` binding
  4903. * of `thisArg` and `partials` prepended to the arguments it receives.
  4904. *
  4905. * @private
  4906. * @param {Function} func The function to wrap.
  4907. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4908. * @param {*} thisArg The `this` binding of `func`.
  4909. * @param {Array} partials The arguments to prepend to those provided to
  4910. * the new function.
  4911. * @returns {Function} Returns the new wrapped function.
  4912. */
  4913. function createPartial(func, bitmask, thisArg, partials) {
  4914. var isBind = bitmask & WRAP_BIND_FLAG,
  4915. Ctor = createCtor(func);
  4916. function wrapper() {
  4917. var argsIndex = -1,
  4918. argsLength = arguments.length,
  4919. leftIndex = -1,
  4920. leftLength = partials.length,
  4921. args = Array(leftLength + argsLength),
  4922. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4923. while (++leftIndex < leftLength) {
  4924. args[leftIndex] = partials[leftIndex];
  4925. }
  4926. while (argsLength--) {
  4927. args[leftIndex++] = arguments[++argsIndex];
  4928. }
  4929. return apply(fn, isBind ? thisArg : this, args);
  4930. }
  4931. return wrapper;
  4932. }
  4933. /**
  4934. * Creates a `_.range` or `_.rangeRight` function.
  4935. *
  4936. * @private
  4937. * @param {boolean} [fromRight] Specify iterating from right to left.
  4938. * @returns {Function} Returns the new range function.
  4939. */
  4940. function createRange(fromRight) {
  4941. return function(start, end, step) {
  4942. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4943. end = step = undefined;
  4944. }
  4945. // Ensure the sign of `-0` is preserved.
  4946. start = toFinite(start);
  4947. if (end === undefined) {
  4948. end = start;
  4949. start = 0;
  4950. } else {
  4951. end = toFinite(end);
  4952. }
  4953. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4954. return baseRange(start, end, step, fromRight);
  4955. };
  4956. }
  4957. /**
  4958. * Creates a function that performs a relational operation on two values.
  4959. *
  4960. * @private
  4961. * @param {Function} operator The function to perform the operation.
  4962. * @returns {Function} Returns the new relational operation function.
  4963. */
  4964. function createRelationalOperation(operator) {
  4965. return function(value, other) {
  4966. if (!(typeof value == 'string' && typeof other == 'string')) {
  4967. value = toNumber(value);
  4968. other = toNumber(other);
  4969. }
  4970. return operator(value, other);
  4971. };
  4972. }
  4973. /**
  4974. * Creates a function that wraps `func` to continue currying.
  4975. *
  4976. * @private
  4977. * @param {Function} func The function to wrap.
  4978. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4979. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4980. * @param {*} placeholder The placeholder value.
  4981. * @param {*} [thisArg] The `this` binding of `func`.
  4982. * @param {Array} [partials] The arguments to prepend to those provided to
  4983. * the new function.
  4984. * @param {Array} [holders] The `partials` placeholder indexes.
  4985. * @param {Array} [argPos] The argument positions of the new function.
  4986. * @param {number} [ary] The arity cap of `func`.
  4987. * @param {number} [arity] The arity of `func`.
  4988. * @returns {Function} Returns the new wrapped function.
  4989. */
  4990. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4991. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4992. newHolders = isCurry ? holders : undefined,
  4993. newHoldersRight = isCurry ? undefined : holders,
  4994. newPartials = isCurry ? partials : undefined,
  4995. newPartialsRight = isCurry ? undefined : partials;
  4996. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4997. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4998. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4999. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  5000. }
  5001. var newData = [
  5002. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  5003. newHoldersRight, argPos, ary, arity
  5004. ];
  5005. var result = wrapFunc.apply(undefined, newData);
  5006. if (isLaziable(func)) {
  5007. setData(result, newData);
  5008. }
  5009. result.placeholder = placeholder;
  5010. return setWrapToString(result, func, bitmask);
  5011. }
  5012. /**
  5013. * Creates a function like `_.round`.
  5014. *
  5015. * @private
  5016. * @param {string} methodName The name of the `Math` method to use when rounding.
  5017. * @returns {Function} Returns the new round function.
  5018. */
  5019. function createRound(methodName) {
  5020. var func = Math[methodName];
  5021. return function(number, precision) {
  5022. number = toNumber(number);
  5023. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  5024. if (precision && nativeIsFinite(number)) {
  5025. // Shift with exponential notation to avoid floating-point issues.
  5026. // See [MDN](https://mdn.io/round#Examples) for more details.
  5027. var pair = (toString(number) + 'e').split('e'),
  5028. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5029. pair = (toString(value) + 'e').split('e');
  5030. return +(pair[0] + 'e' + (+pair[1] - precision));
  5031. }
  5032. return func(number);
  5033. };
  5034. }
  5035. /**
  5036. * Creates a set object of `values`.
  5037. *
  5038. * @private
  5039. * @param {Array} values The values to add to the set.
  5040. * @returns {Object} Returns the new set.
  5041. */
  5042. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5043. return new Set(values);
  5044. };
  5045. /**
  5046. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5047. *
  5048. * @private
  5049. * @param {Function} keysFunc The function to get the keys of a given object.
  5050. * @returns {Function} Returns the new pairs function.
  5051. */
  5052. function createToPairs(keysFunc) {
  5053. return function(object) {
  5054. var tag = getTag(object);
  5055. if (tag == mapTag) {
  5056. return mapToArray(object);
  5057. }
  5058. if (tag == setTag) {
  5059. return setToPairs(object);
  5060. }
  5061. return baseToPairs(object, keysFunc(object));
  5062. };
  5063. }
  5064. /**
  5065. * Creates a function that either curries or invokes `func` with optional
  5066. * `this` binding and partially applied arguments.
  5067. *
  5068. * @private
  5069. * @param {Function|string} func The function or method name to wrap.
  5070. * @param {number} bitmask The bitmask flags.
  5071. * 1 - `_.bind`
  5072. * 2 - `_.bindKey`
  5073. * 4 - `_.curry` or `_.curryRight` of a bound function
  5074. * 8 - `_.curry`
  5075. * 16 - `_.curryRight`
  5076. * 32 - `_.partial`
  5077. * 64 - `_.partialRight`
  5078. * 128 - `_.rearg`
  5079. * 256 - `_.ary`
  5080. * 512 - `_.flip`
  5081. * @param {*} [thisArg] The `this` binding of `func`.
  5082. * @param {Array} [partials] The arguments to be partially applied.
  5083. * @param {Array} [holders] The `partials` placeholder indexes.
  5084. * @param {Array} [argPos] The argument positions of the new function.
  5085. * @param {number} [ary] The arity cap of `func`.
  5086. * @param {number} [arity] The arity of `func`.
  5087. * @returns {Function} Returns the new wrapped function.
  5088. */
  5089. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5090. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5091. if (!isBindKey && typeof func != 'function') {
  5092. throw new TypeError(FUNC_ERROR_TEXT);
  5093. }
  5094. var length = partials ? partials.length : 0;
  5095. if (!length) {
  5096. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5097. partials = holders = undefined;
  5098. }
  5099. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5100. arity = arity === undefined ? arity : toInteger(arity);
  5101. length -= holders ? holders.length : 0;
  5102. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5103. var partialsRight = partials,
  5104. holdersRight = holders;
  5105. partials = holders = undefined;
  5106. }
  5107. var data = isBindKey ? undefined : getData(func);
  5108. var newData = [
  5109. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5110. argPos, ary, arity
  5111. ];
  5112. if (data) {
  5113. mergeData(newData, data);
  5114. }
  5115. func = newData[0];
  5116. bitmask = newData[1];
  5117. thisArg = newData[2];
  5118. partials = newData[3];
  5119. holders = newData[4];
  5120. arity = newData[9] = newData[9] === undefined
  5121. ? (isBindKey ? 0 : func.length)
  5122. : nativeMax(newData[9] - length, 0);
  5123. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5124. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5125. }
  5126. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5127. var result = createBind(func, bitmask, thisArg);
  5128. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5129. result = createCurry(func, bitmask, arity);
  5130. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5131. result = createPartial(func, bitmask, thisArg, partials);
  5132. } else {
  5133. result = createHybrid.apply(undefined, newData);
  5134. }
  5135. var setter = data ? baseSetData : setData;
  5136. return setWrapToString(setter(result, newData), func, bitmask);
  5137. }
  5138. /**
  5139. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5140. * of source objects to the destination object for all destination properties
  5141. * that resolve to `undefined`.
  5142. *
  5143. * @private
  5144. * @param {*} objValue The destination value.
  5145. * @param {*} srcValue The source value.
  5146. * @param {string} key The key of the property to assign.
  5147. * @param {Object} object The parent object of `objValue`.
  5148. * @returns {*} Returns the value to assign.
  5149. */
  5150. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5151. if (objValue === undefined ||
  5152. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5153. return srcValue;
  5154. }
  5155. return objValue;
  5156. }
  5157. /**
  5158. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5159. * objects into destination objects that are passed thru.
  5160. *
  5161. * @private
  5162. * @param {*} objValue The destination value.
  5163. * @param {*} srcValue The source value.
  5164. * @param {string} key The key of the property to merge.
  5165. * @param {Object} object The parent object of `objValue`.
  5166. * @param {Object} source The parent object of `srcValue`.
  5167. * @param {Object} [stack] Tracks traversed source values and their merged
  5168. * counterparts.
  5169. * @returns {*} Returns the value to assign.
  5170. */
  5171. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5172. if (isObject(objValue) && isObject(srcValue)) {
  5173. // Recursively merge objects and arrays (susceptible to call stack limits).
  5174. stack.set(srcValue, objValue);
  5175. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5176. stack['delete'](srcValue);
  5177. }
  5178. return objValue;
  5179. }
  5180. /**
  5181. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5182. * objects.
  5183. *
  5184. * @private
  5185. * @param {*} value The value to inspect.
  5186. * @param {string} key The key of the property to inspect.
  5187. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5188. */
  5189. function customOmitClone(value) {
  5190. return isPlainObject(value) ? undefined : value;
  5191. }
  5192. /**
  5193. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5194. * partial deep comparisons.
  5195. *
  5196. * @private
  5197. * @param {Array} array The array to compare.
  5198. * @param {Array} other The other array to compare.
  5199. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5200. * @param {Function} customizer The function to customize comparisons.
  5201. * @param {Function} equalFunc The function to determine equivalents of values.
  5202. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5203. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5204. */
  5205. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5206. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5207. arrLength = array.length,
  5208. othLength = other.length;
  5209. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5210. return false;
  5211. }
  5212. // Check that cyclic values are equal.
  5213. var arrStacked = stack.get(array);
  5214. var othStacked = stack.get(other);
  5215. if (arrStacked && othStacked) {
  5216. return arrStacked == other && othStacked == array;
  5217. }
  5218. var index = -1,
  5219. result = true,
  5220. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5221. stack.set(array, other);
  5222. stack.set(other, array);
  5223. // Ignore non-index properties.
  5224. while (++index < arrLength) {
  5225. var arrValue = array[index],
  5226. othValue = other[index];
  5227. if (customizer) {
  5228. var compared = isPartial
  5229. ? customizer(othValue, arrValue, index, other, array, stack)
  5230. : customizer(arrValue, othValue, index, array, other, stack);
  5231. }
  5232. if (compared !== undefined) {
  5233. if (compared) {
  5234. continue;
  5235. }
  5236. result = false;
  5237. break;
  5238. }
  5239. // Recursively compare arrays (susceptible to call stack limits).
  5240. if (seen) {
  5241. if (!arraySome(other, function(othValue, othIndex) {
  5242. if (!cacheHas(seen, othIndex) &&
  5243. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5244. return seen.push(othIndex);
  5245. }
  5246. })) {
  5247. result = false;
  5248. break;
  5249. }
  5250. } else if (!(
  5251. arrValue === othValue ||
  5252. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5253. )) {
  5254. result = false;
  5255. break;
  5256. }
  5257. }
  5258. stack['delete'](array);
  5259. stack['delete'](other);
  5260. return result;
  5261. }
  5262. /**
  5263. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5264. * the same `toStringTag`.
  5265. *
  5266. * **Note:** This function only supports comparing values with tags of
  5267. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5268. *
  5269. * @private
  5270. * @param {Object} object The object to compare.
  5271. * @param {Object} other The other object to compare.
  5272. * @param {string} tag The `toStringTag` of the objects to compare.
  5273. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5274. * @param {Function} customizer The function to customize comparisons.
  5275. * @param {Function} equalFunc The function to determine equivalents of values.
  5276. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5277. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5278. */
  5279. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5280. switch (tag) {
  5281. case dataViewTag:
  5282. if ((object.byteLength != other.byteLength) ||
  5283. (object.byteOffset != other.byteOffset)) {
  5284. return false;
  5285. }
  5286. object = object.buffer;
  5287. other = other.buffer;
  5288. case arrayBufferTag:
  5289. if ((object.byteLength != other.byteLength) ||
  5290. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5291. return false;
  5292. }
  5293. return true;
  5294. case boolTag:
  5295. case dateTag:
  5296. case numberTag:
  5297. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5298. // Invalid dates are coerced to `NaN`.
  5299. return eq(+object, +other);
  5300. case errorTag:
  5301. return object.name == other.name && object.message == other.message;
  5302. case regexpTag:
  5303. case stringTag:
  5304. // Coerce regexes to strings and treat strings, primitives and objects,
  5305. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5306. // for more details.
  5307. return object == (other + '');
  5308. case mapTag:
  5309. var convert = mapToArray;
  5310. case setTag:
  5311. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5312. convert || (convert = setToArray);
  5313. if (object.size != other.size && !isPartial) {
  5314. return false;
  5315. }
  5316. // Assume cyclic values are equal.
  5317. var stacked = stack.get(object);
  5318. if (stacked) {
  5319. return stacked == other;
  5320. }
  5321. bitmask |= COMPARE_UNORDERED_FLAG;
  5322. // Recursively compare objects (susceptible to call stack limits).
  5323. stack.set(object, other);
  5324. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5325. stack['delete'](object);
  5326. return result;
  5327. case symbolTag:
  5328. if (symbolValueOf) {
  5329. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5330. }
  5331. }
  5332. return false;
  5333. }
  5334. /**
  5335. * A specialized version of `baseIsEqualDeep` for objects with support for
  5336. * partial deep comparisons.
  5337. *
  5338. * @private
  5339. * @param {Object} object The object to compare.
  5340. * @param {Object} other The other object to compare.
  5341. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5342. * @param {Function} customizer The function to customize comparisons.
  5343. * @param {Function} equalFunc The function to determine equivalents of values.
  5344. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5345. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5346. */
  5347. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5348. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5349. objProps = getAllKeys(object),
  5350. objLength = objProps.length,
  5351. othProps = getAllKeys(other),
  5352. othLength = othProps.length;
  5353. if (objLength != othLength && !isPartial) {
  5354. return false;
  5355. }
  5356. var index = objLength;
  5357. while (index--) {
  5358. var key = objProps[index];
  5359. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5360. return false;
  5361. }
  5362. }
  5363. // Check that cyclic values are equal.
  5364. var objStacked = stack.get(object);
  5365. var othStacked = stack.get(other);
  5366. if (objStacked && othStacked) {
  5367. return objStacked == other && othStacked == object;
  5368. }
  5369. var result = true;
  5370. stack.set(object, other);
  5371. stack.set(other, object);
  5372. var skipCtor = isPartial;
  5373. while (++index < objLength) {
  5374. key = objProps[index];
  5375. var objValue = object[key],
  5376. othValue = other[key];
  5377. if (customizer) {
  5378. var compared = isPartial
  5379. ? customizer(othValue, objValue, key, other, object, stack)
  5380. : customizer(objValue, othValue, key, object, other, stack);
  5381. }
  5382. // Recursively compare objects (susceptible to call stack limits).
  5383. if (!(compared === undefined
  5384. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5385. : compared
  5386. )) {
  5387. result = false;
  5388. break;
  5389. }
  5390. skipCtor || (skipCtor = key == 'constructor');
  5391. }
  5392. if (result && !skipCtor) {
  5393. var objCtor = object.constructor,
  5394. othCtor = other.constructor;
  5395. // Non `Object` object instances with different constructors are not equal.
  5396. if (objCtor != othCtor &&
  5397. ('constructor' in object && 'constructor' in other) &&
  5398. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5399. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5400. result = false;
  5401. }
  5402. }
  5403. stack['delete'](object);
  5404. stack['delete'](other);
  5405. return result;
  5406. }
  5407. /**
  5408. * A specialized version of `baseRest` which flattens the rest array.
  5409. *
  5410. * @private
  5411. * @param {Function} func The function to apply a rest parameter to.
  5412. * @returns {Function} Returns the new function.
  5413. */
  5414. function flatRest(func) {
  5415. return setToString(overRest(func, undefined, flatten), func + '');
  5416. }
  5417. /**
  5418. * Creates an array of own enumerable property names and symbols of `object`.
  5419. *
  5420. * @private
  5421. * @param {Object} object The object to query.
  5422. * @returns {Array} Returns the array of property names and symbols.
  5423. */
  5424. function getAllKeys(object) {
  5425. return baseGetAllKeys(object, keys, getSymbols);
  5426. }
  5427. /**
  5428. * Creates an array of own and inherited enumerable property names and
  5429. * symbols of `object`.
  5430. *
  5431. * @private
  5432. * @param {Object} object The object to query.
  5433. * @returns {Array} Returns the array of property names and symbols.
  5434. */
  5435. function getAllKeysIn(object) {
  5436. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5437. }
  5438. /**
  5439. * Gets metadata for `func`.
  5440. *
  5441. * @private
  5442. * @param {Function} func The function to query.
  5443. * @returns {*} Returns the metadata for `func`.
  5444. */
  5445. var getData = !metaMap ? noop : function(func) {
  5446. return metaMap.get(func);
  5447. };
  5448. /**
  5449. * Gets the name of `func`.
  5450. *
  5451. * @private
  5452. * @param {Function} func The function to query.
  5453. * @returns {string} Returns the function name.
  5454. */
  5455. function getFuncName(func) {
  5456. var result = (func.name + ''),
  5457. array = realNames[result],
  5458. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5459. while (length--) {
  5460. var data = array[length],
  5461. otherFunc = data.func;
  5462. if (otherFunc == null || otherFunc == func) {
  5463. return data.name;
  5464. }
  5465. }
  5466. return result;
  5467. }
  5468. /**
  5469. * Gets the argument placeholder value for `func`.
  5470. *
  5471. * @private
  5472. * @param {Function} func The function to inspect.
  5473. * @returns {*} Returns the placeholder value.
  5474. */
  5475. function getHolder(func) {
  5476. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5477. return object.placeholder;
  5478. }
  5479. /**
  5480. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5481. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5482. * If arguments are provided, the chosen function is invoked with them and
  5483. * its result is returned.
  5484. *
  5485. * @private
  5486. * @param {*} [value] The value to convert to an iteratee.
  5487. * @param {number} [arity] The arity of the created iteratee.
  5488. * @returns {Function} Returns the chosen function or its result.
  5489. */
  5490. function getIteratee() {
  5491. var result = lodash.iteratee || iteratee;
  5492. result = result === iteratee ? baseIteratee : result;
  5493. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5494. }
  5495. /**
  5496. * Gets the data for `map`.
  5497. *
  5498. * @private
  5499. * @param {Object} map The map to query.
  5500. * @param {string} key The reference key.
  5501. * @returns {*} Returns the map data.
  5502. */
  5503. function getMapData(map, key) {
  5504. var data = map.__data__;
  5505. return isKeyable(key)
  5506. ? data[typeof key == 'string' ? 'string' : 'hash']
  5507. : data.map;
  5508. }
  5509. /**
  5510. * Gets the property names, values, and compare flags of `object`.
  5511. *
  5512. * @private
  5513. * @param {Object} object The object to query.
  5514. * @returns {Array} Returns the match data of `object`.
  5515. */
  5516. function getMatchData(object) {
  5517. var result = keys(object),
  5518. length = result.length;
  5519. while (length--) {
  5520. var key = result[length],
  5521. value = object[key];
  5522. result[length] = [key, value, isStrictComparable(value)];
  5523. }
  5524. return result;
  5525. }
  5526. /**
  5527. * Gets the native function at `key` of `object`.
  5528. *
  5529. * @private
  5530. * @param {Object} object The object to query.
  5531. * @param {string} key The key of the method to get.
  5532. * @returns {*} Returns the function if it's native, else `undefined`.
  5533. */
  5534. function getNative(object, key) {
  5535. var value = getValue(object, key);
  5536. return baseIsNative(value) ? value : undefined;
  5537. }
  5538. /**
  5539. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5540. *
  5541. * @private
  5542. * @param {*} value The value to query.
  5543. * @returns {string} Returns the raw `toStringTag`.
  5544. */
  5545. function getRawTag(value) {
  5546. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5547. tag = value[symToStringTag];
  5548. try {
  5549. value[symToStringTag] = undefined;
  5550. var unmasked = true;
  5551. } catch (e) {}
  5552. var result = nativeObjectToString.call(value);
  5553. if (unmasked) {
  5554. if (isOwn) {
  5555. value[symToStringTag] = tag;
  5556. } else {
  5557. delete value[symToStringTag];
  5558. }
  5559. }
  5560. return result;
  5561. }
  5562. /**
  5563. * Creates an array of the own enumerable symbols of `object`.
  5564. *
  5565. * @private
  5566. * @param {Object} object The object to query.
  5567. * @returns {Array} Returns the array of symbols.
  5568. */
  5569. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5570. if (object == null) {
  5571. return [];
  5572. }
  5573. object = Object(object);
  5574. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5575. return propertyIsEnumerable.call(object, symbol);
  5576. });
  5577. };
  5578. /**
  5579. * Creates an array of the own and inherited enumerable symbols of `object`.
  5580. *
  5581. * @private
  5582. * @param {Object} object The object to query.
  5583. * @returns {Array} Returns the array of symbols.
  5584. */
  5585. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5586. var result = [];
  5587. while (object) {
  5588. arrayPush(result, getSymbols(object));
  5589. object = getPrototype(object);
  5590. }
  5591. return result;
  5592. };
  5593. /**
  5594. * Gets the `toStringTag` of `value`.
  5595. *
  5596. * @private
  5597. * @param {*} value The value to query.
  5598. * @returns {string} Returns the `toStringTag`.
  5599. */
  5600. var getTag = baseGetTag;
  5601. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5602. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5603. (Map && getTag(new Map) != mapTag) ||
  5604. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5605. (Set && getTag(new Set) != setTag) ||
  5606. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5607. getTag = function(value) {
  5608. var result = baseGetTag(value),
  5609. Ctor = result == objectTag ? value.constructor : undefined,
  5610. ctorString = Ctor ? toSource(Ctor) : '';
  5611. if (ctorString) {
  5612. switch (ctorString) {
  5613. case dataViewCtorString: return dataViewTag;
  5614. case mapCtorString: return mapTag;
  5615. case promiseCtorString: return promiseTag;
  5616. case setCtorString: return setTag;
  5617. case weakMapCtorString: return weakMapTag;
  5618. }
  5619. }
  5620. return result;
  5621. };
  5622. }
  5623. /**
  5624. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5625. *
  5626. * @private
  5627. * @param {number} start The start of the view.
  5628. * @param {number} end The end of the view.
  5629. * @param {Array} transforms The transformations to apply to the view.
  5630. * @returns {Object} Returns an object containing the `start` and `end`
  5631. * positions of the view.
  5632. */
  5633. function getView(start, end, transforms) {
  5634. var index = -1,
  5635. length = transforms.length;
  5636. while (++index < length) {
  5637. var data = transforms[index],
  5638. size = data.size;
  5639. switch (data.type) {
  5640. case 'drop': start += size; break;
  5641. case 'dropRight': end -= size; break;
  5642. case 'take': end = nativeMin(end, start + size); break;
  5643. case 'takeRight': start = nativeMax(start, end - size); break;
  5644. }
  5645. }
  5646. return { 'start': start, 'end': end };
  5647. }
  5648. /**
  5649. * Extracts wrapper details from the `source` body comment.
  5650. *
  5651. * @private
  5652. * @param {string} source The source to inspect.
  5653. * @returns {Array} Returns the wrapper details.
  5654. */
  5655. function getWrapDetails(source) {
  5656. var match = source.match(reWrapDetails);
  5657. return match ? match[1].split(reSplitDetails) : [];
  5658. }
  5659. /**
  5660. * Checks if `path` exists on `object`.
  5661. *
  5662. * @private
  5663. * @param {Object} object The object to query.
  5664. * @param {Array|string} path The path to check.
  5665. * @param {Function} hasFunc The function to check properties.
  5666. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5667. */
  5668. function hasPath(object, path, hasFunc) {
  5669. path = castPath(path, object);
  5670. var index = -1,
  5671. length = path.length,
  5672. result = false;
  5673. while (++index < length) {
  5674. var key = toKey(path[index]);
  5675. if (!(result = object != null && hasFunc(object, key))) {
  5676. break;
  5677. }
  5678. object = object[key];
  5679. }
  5680. if (result || ++index != length) {
  5681. return result;
  5682. }
  5683. length = object == null ? 0 : object.length;
  5684. return !!length && isLength(length) && isIndex(key, length) &&
  5685. (isArray(object) || isArguments(object));
  5686. }
  5687. /**
  5688. * Initializes an array clone.
  5689. *
  5690. * @private
  5691. * @param {Array} array The array to clone.
  5692. * @returns {Array} Returns the initialized clone.
  5693. */
  5694. function initCloneArray(array) {
  5695. var length = array.length,
  5696. result = new array.constructor(length);
  5697. // Add properties assigned by `RegExp#exec`.
  5698. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5699. result.index = array.index;
  5700. result.input = array.input;
  5701. }
  5702. return result;
  5703. }
  5704. /**
  5705. * Initializes an object clone.
  5706. *
  5707. * @private
  5708. * @param {Object} object The object to clone.
  5709. * @returns {Object} Returns the initialized clone.
  5710. */
  5711. function initCloneObject(object) {
  5712. return (typeof object.constructor == 'function' && !isPrototype(object))
  5713. ? baseCreate(getPrototype(object))
  5714. : {};
  5715. }
  5716. /**
  5717. * Initializes an object clone based on its `toStringTag`.
  5718. *
  5719. * **Note:** This function only supports cloning values with tags of
  5720. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5721. *
  5722. * @private
  5723. * @param {Object} object The object to clone.
  5724. * @param {string} tag The `toStringTag` of the object to clone.
  5725. * @param {boolean} [isDeep] Specify a deep clone.
  5726. * @returns {Object} Returns the initialized clone.
  5727. */
  5728. function initCloneByTag(object, tag, isDeep) {
  5729. var Ctor = object.constructor;
  5730. switch (tag) {
  5731. case arrayBufferTag:
  5732. return cloneArrayBuffer(object);
  5733. case boolTag:
  5734. case dateTag:
  5735. return new Ctor(+object);
  5736. case dataViewTag:
  5737. return cloneDataView(object, isDeep);
  5738. case float32Tag: case float64Tag:
  5739. case int8Tag: case int16Tag: case int32Tag:
  5740. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5741. return cloneTypedArray(object, isDeep);
  5742. case mapTag:
  5743. return new Ctor;
  5744. case numberTag:
  5745. case stringTag:
  5746. return new Ctor(object);
  5747. case regexpTag:
  5748. return cloneRegExp(object);
  5749. case setTag:
  5750. return new Ctor;
  5751. case symbolTag:
  5752. return cloneSymbol(object);
  5753. }
  5754. }
  5755. /**
  5756. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5757. *
  5758. * @private
  5759. * @param {string} source The source to modify.
  5760. * @returns {Array} details The details to insert.
  5761. * @returns {string} Returns the modified source.
  5762. */
  5763. function insertWrapDetails(source, details) {
  5764. var length = details.length;
  5765. if (!length) {
  5766. return source;
  5767. }
  5768. var lastIndex = length - 1;
  5769. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5770. details = details.join(length > 2 ? ', ' : ' ');
  5771. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5772. }
  5773. /**
  5774. * Checks if `value` is a flattenable `arguments` object or array.
  5775. *
  5776. * @private
  5777. * @param {*} value The value to check.
  5778. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5779. */
  5780. function isFlattenable(value) {
  5781. return isArray(value) || isArguments(value) ||
  5782. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5783. }
  5784. /**
  5785. * Checks if `value` is a valid array-like index.
  5786. *
  5787. * @private
  5788. * @param {*} value The value to check.
  5789. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5790. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5791. */
  5792. function isIndex(value, length) {
  5793. var type = typeof value;
  5794. length = length == null ? MAX_SAFE_INTEGER : length;
  5795. return !!length &&
  5796. (type == 'number' ||
  5797. (type != 'symbol' && reIsUint.test(value))) &&
  5798. (value > -1 && value % 1 == 0 && value < length);
  5799. }
  5800. /**
  5801. * Checks if the given arguments are from an iteratee call.
  5802. *
  5803. * @private
  5804. * @param {*} value The potential iteratee value argument.
  5805. * @param {*} index The potential iteratee index or key argument.
  5806. * @param {*} object The potential iteratee object argument.
  5807. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5808. * else `false`.
  5809. */
  5810. function isIterateeCall(value, index, object) {
  5811. if (!isObject(object)) {
  5812. return false;
  5813. }
  5814. var type = typeof index;
  5815. if (type == 'number'
  5816. ? (isArrayLike(object) && isIndex(index, object.length))
  5817. : (type == 'string' && index in object)
  5818. ) {
  5819. return eq(object[index], value);
  5820. }
  5821. return false;
  5822. }
  5823. /**
  5824. * Checks if `value` is a property name and not a property path.
  5825. *
  5826. * @private
  5827. * @param {*} value The value to check.
  5828. * @param {Object} [object] The object to query keys on.
  5829. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5830. */
  5831. function isKey(value, object) {
  5832. if (isArray(value)) {
  5833. return false;
  5834. }
  5835. var type = typeof value;
  5836. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5837. value == null || isSymbol(value)) {
  5838. return true;
  5839. }
  5840. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5841. (object != null && value in Object(object));
  5842. }
  5843. /**
  5844. * Checks if `value` is suitable for use as unique object key.
  5845. *
  5846. * @private
  5847. * @param {*} value The value to check.
  5848. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5849. */
  5850. function isKeyable(value) {
  5851. var type = typeof value;
  5852. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5853. ? (value !== '__proto__')
  5854. : (value === null);
  5855. }
  5856. /**
  5857. * Checks if `func` has a lazy counterpart.
  5858. *
  5859. * @private
  5860. * @param {Function} func The function to check.
  5861. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5862. * else `false`.
  5863. */
  5864. function isLaziable(func) {
  5865. var funcName = getFuncName(func),
  5866. other = lodash[funcName];
  5867. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5868. return false;
  5869. }
  5870. if (func === other) {
  5871. return true;
  5872. }
  5873. var data = getData(other);
  5874. return !!data && func === data[0];
  5875. }
  5876. /**
  5877. * Checks if `func` has its source masked.
  5878. *
  5879. * @private
  5880. * @param {Function} func The function to check.
  5881. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5882. */
  5883. function isMasked(func) {
  5884. return !!maskSrcKey && (maskSrcKey in func);
  5885. }
  5886. /**
  5887. * Checks if `func` is capable of being masked.
  5888. *
  5889. * @private
  5890. * @param {*} value The value to check.
  5891. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5892. */
  5893. var isMaskable = coreJsData ? isFunction : stubFalse;
  5894. /**
  5895. * Checks if `value` is likely a prototype object.
  5896. *
  5897. * @private
  5898. * @param {*} value The value to check.
  5899. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5900. */
  5901. function isPrototype(value) {
  5902. var Ctor = value && value.constructor,
  5903. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5904. return value === proto;
  5905. }
  5906. /**
  5907. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5908. *
  5909. * @private
  5910. * @param {*} value The value to check.
  5911. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5912. * equality comparisons, else `false`.
  5913. */
  5914. function isStrictComparable(value) {
  5915. return value === value && !isObject(value);
  5916. }
  5917. /**
  5918. * A specialized version of `matchesProperty` for source values suitable
  5919. * for strict equality comparisons, i.e. `===`.
  5920. *
  5921. * @private
  5922. * @param {string} key The key of the property to get.
  5923. * @param {*} srcValue The value to match.
  5924. * @returns {Function} Returns the new spec function.
  5925. */
  5926. function matchesStrictComparable(key, srcValue) {
  5927. return function(object) {
  5928. if (object == null) {
  5929. return false;
  5930. }
  5931. return object[key] === srcValue &&
  5932. (srcValue !== undefined || (key in Object(object)));
  5933. };
  5934. }
  5935. /**
  5936. * A specialized version of `_.memoize` which clears the memoized function's
  5937. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5938. *
  5939. * @private
  5940. * @param {Function} func The function to have its output memoized.
  5941. * @returns {Function} Returns the new memoized function.
  5942. */
  5943. function memoizeCapped(func) {
  5944. var result = memoize(func, function(key) {
  5945. if (cache.size === MAX_MEMOIZE_SIZE) {
  5946. cache.clear();
  5947. }
  5948. return key;
  5949. });
  5950. var cache = result.cache;
  5951. return result;
  5952. }
  5953. /**
  5954. * Merges the function metadata of `source` into `data`.
  5955. *
  5956. * Merging metadata reduces the number of wrappers used to invoke a function.
  5957. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5958. * may be applied regardless of execution order. Methods like `_.ary` and
  5959. * `_.rearg` modify function arguments, making the order in which they are
  5960. * executed important, preventing the merging of metadata. However, we make
  5961. * an exception for a safe combined case where curried functions have `_.ary`
  5962. * and or `_.rearg` applied.
  5963. *
  5964. * @private
  5965. * @param {Array} data The destination metadata.
  5966. * @param {Array} source The source metadata.
  5967. * @returns {Array} Returns `data`.
  5968. */
  5969. function mergeData(data, source) {
  5970. var bitmask = data[1],
  5971. srcBitmask = source[1],
  5972. newBitmask = bitmask | srcBitmask,
  5973. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5974. var isCombo =
  5975. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5976. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5977. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5978. // Exit early if metadata can't be merged.
  5979. if (!(isCommon || isCombo)) {
  5980. return data;
  5981. }
  5982. // Use source `thisArg` if available.
  5983. if (srcBitmask & WRAP_BIND_FLAG) {
  5984. data[2] = source[2];
  5985. // Set when currying a bound function.
  5986. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5987. }
  5988. // Compose partial arguments.
  5989. var value = source[3];
  5990. if (value) {
  5991. var partials = data[3];
  5992. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5993. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5994. }
  5995. // Compose partial right arguments.
  5996. value = source[5];
  5997. if (value) {
  5998. partials = data[5];
  5999. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  6000. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  6001. }
  6002. // Use source `argPos` if available.
  6003. value = source[7];
  6004. if (value) {
  6005. data[7] = value;
  6006. }
  6007. // Use source `ary` if it's smaller.
  6008. if (srcBitmask & WRAP_ARY_FLAG) {
  6009. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  6010. }
  6011. // Use source `arity` if one is not provided.
  6012. if (data[9] == null) {
  6013. data[9] = source[9];
  6014. }
  6015. // Use source `func` and merge bitmasks.
  6016. data[0] = source[0];
  6017. data[1] = newBitmask;
  6018. return data;
  6019. }
  6020. /**
  6021. * This function is like
  6022. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  6023. * except that it includes inherited enumerable properties.
  6024. *
  6025. * @private
  6026. * @param {Object} object The object to query.
  6027. * @returns {Array} Returns the array of property names.
  6028. */
  6029. function nativeKeysIn(object) {
  6030. var result = [];
  6031. if (object != null) {
  6032. for (var key in Object(object)) {
  6033. result.push(key);
  6034. }
  6035. }
  6036. return result;
  6037. }
  6038. /**
  6039. * Converts `value` to a string using `Object.prototype.toString`.
  6040. *
  6041. * @private
  6042. * @param {*} value The value to convert.
  6043. * @returns {string} Returns the converted string.
  6044. */
  6045. function objectToString(value) {
  6046. return nativeObjectToString.call(value);
  6047. }
  6048. /**
  6049. * A specialized version of `baseRest` which transforms the rest array.
  6050. *
  6051. * @private
  6052. * @param {Function} func The function to apply a rest parameter to.
  6053. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6054. * @param {Function} transform The rest array transform.
  6055. * @returns {Function} Returns the new function.
  6056. */
  6057. function overRest(func, start, transform) {
  6058. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6059. return function() {
  6060. var args = arguments,
  6061. index = -1,
  6062. length = nativeMax(args.length - start, 0),
  6063. array = Array(length);
  6064. while (++index < length) {
  6065. array[index] = args[start + index];
  6066. }
  6067. index = -1;
  6068. var otherArgs = Array(start + 1);
  6069. while (++index < start) {
  6070. otherArgs[index] = args[index];
  6071. }
  6072. otherArgs[start] = transform(array);
  6073. return apply(func, this, otherArgs);
  6074. };
  6075. }
  6076. /**
  6077. * Gets the parent value at `path` of `object`.
  6078. *
  6079. * @private
  6080. * @param {Object} object The object to query.
  6081. * @param {Array} path The path to get the parent value of.
  6082. * @returns {*} Returns the parent value.
  6083. */
  6084. function parent(object, path) {
  6085. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6086. }
  6087. /**
  6088. * Reorder `array` according to the specified indexes where the element at
  6089. * the first index is assigned as the first element, the element at
  6090. * the second index is assigned as the second element, and so on.
  6091. *
  6092. * @private
  6093. * @param {Array} array The array to reorder.
  6094. * @param {Array} indexes The arranged array indexes.
  6095. * @returns {Array} Returns `array`.
  6096. */
  6097. function reorder(array, indexes) {
  6098. var arrLength = array.length,
  6099. length = nativeMin(indexes.length, arrLength),
  6100. oldArray = copyArray(array);
  6101. while (length--) {
  6102. var index = indexes[length];
  6103. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6104. }
  6105. return array;
  6106. }
  6107. /**
  6108. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6109. *
  6110. * @private
  6111. * @param {Object} object The object to query.
  6112. * @param {string} key The key of the property to get.
  6113. * @returns {*} Returns the property value.
  6114. */
  6115. function safeGet(object, key) {
  6116. if (key === 'constructor' && typeof object[key] === 'function') {
  6117. return;
  6118. }
  6119. if (key == '__proto__') {
  6120. return;
  6121. }
  6122. return object[key];
  6123. }
  6124. /**
  6125. * Sets metadata for `func`.
  6126. *
  6127. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6128. * period of time, it will trip its breaker and transition to an identity
  6129. * function to avoid garbage collection pauses in V8. See
  6130. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6131. * for more details.
  6132. *
  6133. * @private
  6134. * @param {Function} func The function to associate metadata with.
  6135. * @param {*} data The metadata.
  6136. * @returns {Function} Returns `func`.
  6137. */
  6138. var setData = shortOut(baseSetData);
  6139. /**
  6140. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6141. *
  6142. * @private
  6143. * @param {Function} func The function to delay.
  6144. * @param {number} wait The number of milliseconds to delay invocation.
  6145. * @returns {number|Object} Returns the timer id or timeout object.
  6146. */
  6147. var setTimeout = ctxSetTimeout || function(func, wait) {
  6148. return root.setTimeout(func, wait);
  6149. };
  6150. /**
  6151. * Sets the `toString` method of `func` to return `string`.
  6152. *
  6153. * @private
  6154. * @param {Function} func The function to modify.
  6155. * @param {Function} string The `toString` result.
  6156. * @returns {Function} Returns `func`.
  6157. */
  6158. var setToString = shortOut(baseSetToString);
  6159. /**
  6160. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6161. * with wrapper details in a comment at the top of the source body.
  6162. *
  6163. * @private
  6164. * @param {Function} wrapper The function to modify.
  6165. * @param {Function} reference The reference function.
  6166. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6167. * @returns {Function} Returns `wrapper`.
  6168. */
  6169. function setWrapToString(wrapper, reference, bitmask) {
  6170. var source = (reference + '');
  6171. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6172. }
  6173. /**
  6174. * Creates a function that'll short out and invoke `identity` instead
  6175. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6176. * milliseconds.
  6177. *
  6178. * @private
  6179. * @param {Function} func The function to restrict.
  6180. * @returns {Function} Returns the new shortable function.
  6181. */
  6182. function shortOut(func) {
  6183. var count = 0,
  6184. lastCalled = 0;
  6185. return function() {
  6186. var stamp = nativeNow(),
  6187. remaining = HOT_SPAN - (stamp - lastCalled);
  6188. lastCalled = stamp;
  6189. if (remaining > 0) {
  6190. if (++count >= HOT_COUNT) {
  6191. return arguments[0];
  6192. }
  6193. } else {
  6194. count = 0;
  6195. }
  6196. return func.apply(undefined, arguments);
  6197. };
  6198. }
  6199. /**
  6200. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6201. *
  6202. * @private
  6203. * @param {Array} array The array to shuffle.
  6204. * @param {number} [size=array.length] The size of `array`.
  6205. * @returns {Array} Returns `array`.
  6206. */
  6207. function shuffleSelf(array, size) {
  6208. var index = -1,
  6209. length = array.length,
  6210. lastIndex = length - 1;
  6211. size = size === undefined ? length : size;
  6212. while (++index < size) {
  6213. var rand = baseRandom(index, lastIndex),
  6214. value = array[rand];
  6215. array[rand] = array[index];
  6216. array[index] = value;
  6217. }
  6218. array.length = size;
  6219. return array;
  6220. }
  6221. /**
  6222. * Converts `string` to a property path array.
  6223. *
  6224. * @private
  6225. * @param {string} string The string to convert.
  6226. * @returns {Array} Returns the property path array.
  6227. */
  6228. var stringToPath = memoizeCapped(function(string) {
  6229. var result = [];
  6230. if (string.charCodeAt(0) === 46 /* . */) {
  6231. result.push('');
  6232. }
  6233. string.replace(rePropName, function(match, number, quote, subString) {
  6234. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6235. });
  6236. return result;
  6237. });
  6238. /**
  6239. * Converts `value` to a string key if it's not a string or symbol.
  6240. *
  6241. * @private
  6242. * @param {*} value The value to inspect.
  6243. * @returns {string|symbol} Returns the key.
  6244. */
  6245. function toKey(value) {
  6246. if (typeof value == 'string' || isSymbol(value)) {
  6247. return value;
  6248. }
  6249. var result = (value + '');
  6250. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6251. }
  6252. /**
  6253. * Converts `func` to its source code.
  6254. *
  6255. * @private
  6256. * @param {Function} func The function to convert.
  6257. * @returns {string} Returns the source code.
  6258. */
  6259. function toSource(func) {
  6260. if (func != null) {
  6261. try {
  6262. return funcToString.call(func);
  6263. } catch (e) {}
  6264. try {
  6265. return (func + '');
  6266. } catch (e) {}
  6267. }
  6268. return '';
  6269. }
  6270. /**
  6271. * Updates wrapper `details` based on `bitmask` flags.
  6272. *
  6273. * @private
  6274. * @returns {Array} details The details to modify.
  6275. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6276. * @returns {Array} Returns `details`.
  6277. */
  6278. function updateWrapDetails(details, bitmask) {
  6279. arrayEach(wrapFlags, function(pair) {
  6280. var value = '_.' + pair[0];
  6281. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6282. details.push(value);
  6283. }
  6284. });
  6285. return details.sort();
  6286. }
  6287. /**
  6288. * Creates a clone of `wrapper`.
  6289. *
  6290. * @private
  6291. * @param {Object} wrapper The wrapper to clone.
  6292. * @returns {Object} Returns the cloned wrapper.
  6293. */
  6294. function wrapperClone(wrapper) {
  6295. if (wrapper instanceof LazyWrapper) {
  6296. return wrapper.clone();
  6297. }
  6298. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6299. result.__actions__ = copyArray(wrapper.__actions__);
  6300. result.__index__ = wrapper.__index__;
  6301. result.__values__ = wrapper.__values__;
  6302. return result;
  6303. }
  6304. /*------------------------------------------------------------------------*/
  6305. /**
  6306. * Creates an array of elements split into groups the length of `size`.
  6307. * If `array` can't be split evenly, the final chunk will be the remaining
  6308. * elements.
  6309. *
  6310. * @static
  6311. * @memberOf _
  6312. * @since 3.0.0
  6313. * @category Array
  6314. * @param {Array} array The array to process.
  6315. * @param {number} [size=1] The length of each chunk
  6316. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6317. * @returns {Array} Returns the new array of chunks.
  6318. * @example
  6319. *
  6320. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6321. * // => [['a', 'b'], ['c', 'd']]
  6322. *
  6323. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6324. * // => [['a', 'b', 'c'], ['d']]
  6325. */
  6326. function chunk(array, size, guard) {
  6327. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6328. size = 1;
  6329. } else {
  6330. size = nativeMax(toInteger(size), 0);
  6331. }
  6332. var length = array == null ? 0 : array.length;
  6333. if (!length || size < 1) {
  6334. return [];
  6335. }
  6336. var index = 0,
  6337. resIndex = 0,
  6338. result = Array(nativeCeil(length / size));
  6339. while (index < length) {
  6340. result[resIndex++] = baseSlice(array, index, (index += size));
  6341. }
  6342. return result;
  6343. }
  6344. /**
  6345. * Creates an array with all falsey values removed. The values `false`, `null`,
  6346. * `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy.
  6347. *
  6348. * @static
  6349. * @memberOf _
  6350. * @since 0.1.0
  6351. * @category Array
  6352. * @param {Array} array The array to compact.
  6353. * @returns {Array} Returns the new array of filtered values.
  6354. * @example
  6355. *
  6356. * _.compact([0, 1, false, 2, '', 3]);
  6357. * // => [1, 2, 3]
  6358. */
  6359. function compact(array) {
  6360. var index = -1,
  6361. length = array == null ? 0 : array.length,
  6362. resIndex = 0,
  6363. result = [];
  6364. while (++index < length) {
  6365. var value = array[index];
  6366. if (value) {
  6367. result[resIndex++] = value;
  6368. }
  6369. }
  6370. return result;
  6371. }
  6372. /**
  6373. * Creates a new array concatenating `array` with any additional arrays
  6374. * and/or values.
  6375. *
  6376. * @static
  6377. * @memberOf _
  6378. * @since 4.0.0
  6379. * @category Array
  6380. * @param {Array} array The array to concatenate.
  6381. * @param {...*} [values] The values to concatenate.
  6382. * @returns {Array} Returns the new concatenated array.
  6383. * @example
  6384. *
  6385. * var array = [1];
  6386. * var other = _.concat(array, 2, [3], [[4]]);
  6387. *
  6388. * console.log(other);
  6389. * // => [1, 2, 3, [4]]
  6390. *
  6391. * console.log(array);
  6392. * // => [1]
  6393. */
  6394. function concat() {
  6395. var length = arguments.length;
  6396. if (!length) {
  6397. return [];
  6398. }
  6399. var args = Array(length - 1),
  6400. array = arguments[0],
  6401. index = length;
  6402. while (index--) {
  6403. args[index - 1] = arguments[index];
  6404. }
  6405. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6406. }
  6407. /**
  6408. * Creates an array of `array` values not included in the other given arrays
  6409. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6410. * for equality comparisons. The order and references of result values are
  6411. * determined by the first array.
  6412. *
  6413. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6414. *
  6415. * @static
  6416. * @memberOf _
  6417. * @since 0.1.0
  6418. * @category Array
  6419. * @param {Array} array The array to inspect.
  6420. * @param {...Array} [values] The values to exclude.
  6421. * @returns {Array} Returns the new array of filtered values.
  6422. * @see _.without, _.xor
  6423. * @example
  6424. *
  6425. * _.difference([2, 1], [2, 3]);
  6426. * // => [1]
  6427. */
  6428. var difference = baseRest(function(array, values) {
  6429. return isArrayLikeObject(array)
  6430. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6431. : [];
  6432. });
  6433. /**
  6434. * This method is like `_.difference` except that it accepts `iteratee` which
  6435. * is invoked for each element of `array` and `values` to generate the criterion
  6436. * by which they're compared. The order and references of result values are
  6437. * determined by the first array. The iteratee is invoked with one argument:
  6438. * (value).
  6439. *
  6440. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6441. *
  6442. * @static
  6443. * @memberOf _
  6444. * @since 4.0.0
  6445. * @category Array
  6446. * @param {Array} array The array to inspect.
  6447. * @param {...Array} [values] The values to exclude.
  6448. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6449. * @returns {Array} Returns the new array of filtered values.
  6450. * @example
  6451. *
  6452. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6453. * // => [1.2]
  6454. *
  6455. * // The `_.property` iteratee shorthand.
  6456. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6457. * // => [{ 'x': 2 }]
  6458. */
  6459. var differenceBy = baseRest(function(array, values) {
  6460. var iteratee = last(values);
  6461. if (isArrayLikeObject(iteratee)) {
  6462. iteratee = undefined;
  6463. }
  6464. return isArrayLikeObject(array)
  6465. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6466. : [];
  6467. });
  6468. /**
  6469. * This method is like `_.difference` except that it accepts `comparator`
  6470. * which is invoked to compare elements of `array` to `values`. The order and
  6471. * references of result values are determined by the first array. The comparator
  6472. * is invoked with two arguments: (arrVal, othVal).
  6473. *
  6474. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6475. *
  6476. * @static
  6477. * @memberOf _
  6478. * @since 4.0.0
  6479. * @category Array
  6480. * @param {Array} array The array to inspect.
  6481. * @param {...Array} [values] The values to exclude.
  6482. * @param {Function} [comparator] The comparator invoked per element.
  6483. * @returns {Array} Returns the new array of filtered values.
  6484. * @example
  6485. *
  6486. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6487. *
  6488. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6489. * // => [{ 'x': 2, 'y': 1 }]
  6490. */
  6491. var differenceWith = baseRest(function(array, values) {
  6492. var comparator = last(values);
  6493. if (isArrayLikeObject(comparator)) {
  6494. comparator = undefined;
  6495. }
  6496. return isArrayLikeObject(array)
  6497. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6498. : [];
  6499. });
  6500. /**
  6501. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6502. *
  6503. * @static
  6504. * @memberOf _
  6505. * @since 0.5.0
  6506. * @category Array
  6507. * @param {Array} array The array to query.
  6508. * @param {number} [n=1] The number of elements to drop.
  6509. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6510. * @returns {Array} Returns the slice of `array`.
  6511. * @example
  6512. *
  6513. * _.drop([1, 2, 3]);
  6514. * // => [2, 3]
  6515. *
  6516. * _.drop([1, 2, 3], 2);
  6517. * // => [3]
  6518. *
  6519. * _.drop([1, 2, 3], 5);
  6520. * // => []
  6521. *
  6522. * _.drop([1, 2, 3], 0);
  6523. * // => [1, 2, 3]
  6524. */
  6525. function drop(array, n, guard) {
  6526. var length = array == null ? 0 : array.length;
  6527. if (!length) {
  6528. return [];
  6529. }
  6530. n = (guard || n === undefined) ? 1 : toInteger(n);
  6531. return baseSlice(array, n < 0 ? 0 : n, length);
  6532. }
  6533. /**
  6534. * Creates a slice of `array` with `n` elements dropped from the end.
  6535. *
  6536. * @static
  6537. * @memberOf _
  6538. * @since 3.0.0
  6539. * @category Array
  6540. * @param {Array} array The array to query.
  6541. * @param {number} [n=1] The number of elements to drop.
  6542. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6543. * @returns {Array} Returns the slice of `array`.
  6544. * @example
  6545. *
  6546. * _.dropRight([1, 2, 3]);
  6547. * // => [1, 2]
  6548. *
  6549. * _.dropRight([1, 2, 3], 2);
  6550. * // => [1]
  6551. *
  6552. * _.dropRight([1, 2, 3], 5);
  6553. * // => []
  6554. *
  6555. * _.dropRight([1, 2, 3], 0);
  6556. * // => [1, 2, 3]
  6557. */
  6558. function dropRight(array, n, guard) {
  6559. var length = array == null ? 0 : array.length;
  6560. if (!length) {
  6561. return [];
  6562. }
  6563. n = (guard || n === undefined) ? 1 : toInteger(n);
  6564. n = length - n;
  6565. return baseSlice(array, 0, n < 0 ? 0 : n);
  6566. }
  6567. /**
  6568. * Creates a slice of `array` excluding elements dropped from the end.
  6569. * Elements are dropped until `predicate` returns falsey. The predicate is
  6570. * invoked with three arguments: (value, index, array).
  6571. *
  6572. * @static
  6573. * @memberOf _
  6574. * @since 3.0.0
  6575. * @category Array
  6576. * @param {Array} array The array to query.
  6577. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6578. * @returns {Array} Returns the slice of `array`.
  6579. * @example
  6580. *
  6581. * var users = [
  6582. * { 'user': 'barney', 'active': true },
  6583. * { 'user': 'fred', 'active': false },
  6584. * { 'user': 'pebbles', 'active': false }
  6585. * ];
  6586. *
  6587. * _.dropRightWhile(users, function(o) { return !o.active; });
  6588. * // => objects for ['barney']
  6589. *
  6590. * // The `_.matches` iteratee shorthand.
  6591. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6592. * // => objects for ['barney', 'fred']
  6593. *
  6594. * // The `_.matchesProperty` iteratee shorthand.
  6595. * _.dropRightWhile(users, ['active', false]);
  6596. * // => objects for ['barney']
  6597. *
  6598. * // The `_.property` iteratee shorthand.
  6599. * _.dropRightWhile(users, 'active');
  6600. * // => objects for ['barney', 'fred', 'pebbles']
  6601. */
  6602. function dropRightWhile(array, predicate) {
  6603. return (array && array.length)
  6604. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6605. : [];
  6606. }
  6607. /**
  6608. * Creates a slice of `array` excluding elements dropped from the beginning.
  6609. * Elements are dropped until `predicate` returns falsey. The predicate is
  6610. * invoked with three arguments: (value, index, array).
  6611. *
  6612. * @static
  6613. * @memberOf _
  6614. * @since 3.0.0
  6615. * @category Array
  6616. * @param {Array} array The array to query.
  6617. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6618. * @returns {Array} Returns the slice of `array`.
  6619. * @example
  6620. *
  6621. * var users = [
  6622. * { 'user': 'barney', 'active': false },
  6623. * { 'user': 'fred', 'active': false },
  6624. * { 'user': 'pebbles', 'active': true }
  6625. * ];
  6626. *
  6627. * _.dropWhile(users, function(o) { return !o.active; });
  6628. * // => objects for ['pebbles']
  6629. *
  6630. * // The `_.matches` iteratee shorthand.
  6631. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6632. * // => objects for ['fred', 'pebbles']
  6633. *
  6634. * // The `_.matchesProperty` iteratee shorthand.
  6635. * _.dropWhile(users, ['active', false]);
  6636. * // => objects for ['pebbles']
  6637. *
  6638. * // The `_.property` iteratee shorthand.
  6639. * _.dropWhile(users, 'active');
  6640. * // => objects for ['barney', 'fred', 'pebbles']
  6641. */
  6642. function dropWhile(array, predicate) {
  6643. return (array && array.length)
  6644. ? baseWhile(array, getIteratee(predicate, 3), true)
  6645. : [];
  6646. }
  6647. /**
  6648. * Fills elements of `array` with `value` from `start` up to, but not
  6649. * including, `end`.
  6650. *
  6651. * **Note:** This method mutates `array`.
  6652. *
  6653. * @static
  6654. * @memberOf _
  6655. * @since 3.2.0
  6656. * @category Array
  6657. * @param {Array} array The array to fill.
  6658. * @param {*} value The value to fill `array` with.
  6659. * @param {number} [start=0] The start position.
  6660. * @param {number} [end=array.length] The end position.
  6661. * @returns {Array} Returns `array`.
  6662. * @example
  6663. *
  6664. * var array = [1, 2, 3];
  6665. *
  6666. * _.fill(array, 'a');
  6667. * console.log(array);
  6668. * // => ['a', 'a', 'a']
  6669. *
  6670. * _.fill(Array(3), 2);
  6671. * // => [2, 2, 2]
  6672. *
  6673. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6674. * // => [4, '*', '*', 10]
  6675. */
  6676. function fill(array, value, start, end) {
  6677. var length = array == null ? 0 : array.length;
  6678. if (!length) {
  6679. return [];
  6680. }
  6681. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6682. start = 0;
  6683. end = length;
  6684. }
  6685. return baseFill(array, value, start, end);
  6686. }
  6687. /**
  6688. * This method is like `_.find` except that it returns the index of the first
  6689. * element `predicate` returns truthy for instead of the element itself.
  6690. *
  6691. * @static
  6692. * @memberOf _
  6693. * @since 1.1.0
  6694. * @category Array
  6695. * @param {Array} array The array to inspect.
  6696. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6697. * @param {number} [fromIndex=0] The index to search from.
  6698. * @returns {number} Returns the index of the found element, else `-1`.
  6699. * @example
  6700. *
  6701. * var users = [
  6702. * { 'user': 'barney', 'active': false },
  6703. * { 'user': 'fred', 'active': false },
  6704. * { 'user': 'pebbles', 'active': true }
  6705. * ];
  6706. *
  6707. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6708. * // => 0
  6709. *
  6710. * // The `_.matches` iteratee shorthand.
  6711. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6712. * // => 1
  6713. *
  6714. * // The `_.matchesProperty` iteratee shorthand.
  6715. * _.findIndex(users, ['active', false]);
  6716. * // => 0
  6717. *
  6718. * // The `_.property` iteratee shorthand.
  6719. * _.findIndex(users, 'active');
  6720. * // => 2
  6721. */
  6722. function findIndex(array, predicate, fromIndex) {
  6723. var length = array == null ? 0 : array.length;
  6724. if (!length) {
  6725. return -1;
  6726. }
  6727. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6728. if (index < 0) {
  6729. index = nativeMax(length + index, 0);
  6730. }
  6731. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6732. }
  6733. /**
  6734. * This method is like `_.findIndex` except that it iterates over elements
  6735. * of `collection` from right to left.
  6736. *
  6737. * @static
  6738. * @memberOf _
  6739. * @since 2.0.0
  6740. * @category Array
  6741. * @param {Array} array The array to inspect.
  6742. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6743. * @param {number} [fromIndex=array.length-1] The index to search from.
  6744. * @returns {number} Returns the index of the found element, else `-1`.
  6745. * @example
  6746. *
  6747. * var users = [
  6748. * { 'user': 'barney', 'active': true },
  6749. * { 'user': 'fred', 'active': false },
  6750. * { 'user': 'pebbles', 'active': false }
  6751. * ];
  6752. *
  6753. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6754. * // => 2
  6755. *
  6756. * // The `_.matches` iteratee shorthand.
  6757. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6758. * // => 0
  6759. *
  6760. * // The `_.matchesProperty` iteratee shorthand.
  6761. * _.findLastIndex(users, ['active', false]);
  6762. * // => 2
  6763. *
  6764. * // The `_.property` iteratee shorthand.
  6765. * _.findLastIndex(users, 'active');
  6766. * // => 0
  6767. */
  6768. function findLastIndex(array, predicate, fromIndex) {
  6769. var length = array == null ? 0 : array.length;
  6770. if (!length) {
  6771. return -1;
  6772. }
  6773. var index = length - 1;
  6774. if (fromIndex !== undefined) {
  6775. index = toInteger(fromIndex);
  6776. index = fromIndex < 0
  6777. ? nativeMax(length + index, 0)
  6778. : nativeMin(index, length - 1);
  6779. }
  6780. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6781. }
  6782. /**
  6783. * Flattens `array` a single level deep.
  6784. *
  6785. * @static
  6786. * @memberOf _
  6787. * @since 0.1.0
  6788. * @category Array
  6789. * @param {Array} array The array to flatten.
  6790. * @returns {Array} Returns the new flattened array.
  6791. * @example
  6792. *
  6793. * _.flatten([1, [2, [3, [4]], 5]]);
  6794. * // => [1, 2, [3, [4]], 5]
  6795. */
  6796. function flatten(array) {
  6797. var length = array == null ? 0 : array.length;
  6798. return length ? baseFlatten(array, 1) : [];
  6799. }
  6800. /**
  6801. * Recursively flattens `array`.
  6802. *
  6803. * @static
  6804. * @memberOf _
  6805. * @since 3.0.0
  6806. * @category Array
  6807. * @param {Array} array The array to flatten.
  6808. * @returns {Array} Returns the new flattened array.
  6809. * @example
  6810. *
  6811. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6812. * // => [1, 2, 3, 4, 5]
  6813. */
  6814. function flattenDeep(array) {
  6815. var length = array == null ? 0 : array.length;
  6816. return length ? baseFlatten(array, INFINITY) : [];
  6817. }
  6818. /**
  6819. * Recursively flatten `array` up to `depth` times.
  6820. *
  6821. * @static
  6822. * @memberOf _
  6823. * @since 4.4.0
  6824. * @category Array
  6825. * @param {Array} array The array to flatten.
  6826. * @param {number} [depth=1] The maximum recursion depth.
  6827. * @returns {Array} Returns the new flattened array.
  6828. * @example
  6829. *
  6830. * var array = [1, [2, [3, [4]], 5]];
  6831. *
  6832. * _.flattenDepth(array, 1);
  6833. * // => [1, 2, [3, [4]], 5]
  6834. *
  6835. * _.flattenDepth(array, 2);
  6836. * // => [1, 2, 3, [4], 5]
  6837. */
  6838. function flattenDepth(array, depth) {
  6839. var length = array == null ? 0 : array.length;
  6840. if (!length) {
  6841. return [];
  6842. }
  6843. depth = depth === undefined ? 1 : toInteger(depth);
  6844. return baseFlatten(array, depth);
  6845. }
  6846. /**
  6847. * The inverse of `_.toPairs`; this method returns an object composed
  6848. * from key-value `pairs`.
  6849. *
  6850. * @static
  6851. * @memberOf _
  6852. * @since 4.0.0
  6853. * @category Array
  6854. * @param {Array} pairs The key-value pairs.
  6855. * @returns {Object} Returns the new object.
  6856. * @example
  6857. *
  6858. * _.fromPairs([['a', 1], ['b', 2]]);
  6859. * // => { 'a': 1, 'b': 2 }
  6860. */
  6861. function fromPairs(pairs) {
  6862. var index = -1,
  6863. length = pairs == null ? 0 : pairs.length,
  6864. result = {};
  6865. while (++index < length) {
  6866. var pair = pairs[index];
  6867. baseAssignValue(result, pair[0], pair[1]);
  6868. }
  6869. return result;
  6870. }
  6871. /**
  6872. * Gets the first element of `array`.
  6873. *
  6874. * @static
  6875. * @memberOf _
  6876. * @since 0.1.0
  6877. * @alias first
  6878. * @category Array
  6879. * @param {Array} array The array to query.
  6880. * @returns {*} Returns the first element of `array`.
  6881. * @example
  6882. *
  6883. * _.head([1, 2, 3]);
  6884. * // => 1
  6885. *
  6886. * _.head([]);
  6887. * // => undefined
  6888. */
  6889. function head(array) {
  6890. return (array && array.length) ? array[0] : undefined;
  6891. }
  6892. /**
  6893. * Gets the index at which the first occurrence of `value` is found in `array`
  6894. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6895. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6896. * offset from the end of `array`.
  6897. *
  6898. * @static
  6899. * @memberOf _
  6900. * @since 0.1.0
  6901. * @category Array
  6902. * @param {Array} array The array to inspect.
  6903. * @param {*} value The value to search for.
  6904. * @param {number} [fromIndex=0] The index to search from.
  6905. * @returns {number} Returns the index of the matched value, else `-1`.
  6906. * @example
  6907. *
  6908. * _.indexOf([1, 2, 1, 2], 2);
  6909. * // => 1
  6910. *
  6911. * // Search from the `fromIndex`.
  6912. * _.indexOf([1, 2, 1, 2], 2, 2);
  6913. * // => 3
  6914. */
  6915. function indexOf(array, value, fromIndex) {
  6916. var length = array == null ? 0 : array.length;
  6917. if (!length) {
  6918. return -1;
  6919. }
  6920. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6921. if (index < 0) {
  6922. index = nativeMax(length + index, 0);
  6923. }
  6924. return baseIndexOf(array, value, index);
  6925. }
  6926. /**
  6927. * Gets all but the last element of `array`.
  6928. *
  6929. * @static
  6930. * @memberOf _
  6931. * @since 0.1.0
  6932. * @category Array
  6933. * @param {Array} array The array to query.
  6934. * @returns {Array} Returns the slice of `array`.
  6935. * @example
  6936. *
  6937. * _.initial([1, 2, 3]);
  6938. * // => [1, 2]
  6939. */
  6940. function initial(array) {
  6941. var length = array == null ? 0 : array.length;
  6942. return length ? baseSlice(array, 0, -1) : [];
  6943. }
  6944. /**
  6945. * Creates an array of unique values that are included in all given arrays
  6946. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6947. * for equality comparisons. The order and references of result values are
  6948. * determined by the first array.
  6949. *
  6950. * @static
  6951. * @memberOf _
  6952. * @since 0.1.0
  6953. * @category Array
  6954. * @param {...Array} [arrays] The arrays to inspect.
  6955. * @returns {Array} Returns the new array of intersecting values.
  6956. * @example
  6957. *
  6958. * _.intersection([2, 1], [2, 3]);
  6959. * // => [2]
  6960. */
  6961. var intersection = baseRest(function(arrays) {
  6962. var mapped = arrayMap(arrays, castArrayLikeObject);
  6963. return (mapped.length && mapped[0] === arrays[0])
  6964. ? baseIntersection(mapped)
  6965. : [];
  6966. });
  6967. /**
  6968. * This method is like `_.intersection` except that it accepts `iteratee`
  6969. * which is invoked for each element of each `arrays` to generate the criterion
  6970. * by which they're compared. The order and references of result values are
  6971. * determined by the first array. The iteratee is invoked with one argument:
  6972. * (value).
  6973. *
  6974. * @static
  6975. * @memberOf _
  6976. * @since 4.0.0
  6977. * @category Array
  6978. * @param {...Array} [arrays] The arrays to inspect.
  6979. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6980. * @returns {Array} Returns the new array of intersecting values.
  6981. * @example
  6982. *
  6983. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6984. * // => [2.1]
  6985. *
  6986. * // The `_.property` iteratee shorthand.
  6987. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6988. * // => [{ 'x': 1 }]
  6989. */
  6990. var intersectionBy = baseRest(function(arrays) {
  6991. var iteratee = last(arrays),
  6992. mapped = arrayMap(arrays, castArrayLikeObject);
  6993. if (iteratee === last(mapped)) {
  6994. iteratee = undefined;
  6995. } else {
  6996. mapped.pop();
  6997. }
  6998. return (mapped.length && mapped[0] === arrays[0])
  6999. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  7000. : [];
  7001. });
  7002. /**
  7003. * This method is like `_.intersection` except that it accepts `comparator`
  7004. * which is invoked to compare elements of `arrays`. The order and references
  7005. * of result values are determined by the first array. The comparator is
  7006. * invoked with two arguments: (arrVal, othVal).
  7007. *
  7008. * @static
  7009. * @memberOf _
  7010. * @since 4.0.0
  7011. * @category Array
  7012. * @param {...Array} [arrays] The arrays to inspect.
  7013. * @param {Function} [comparator] The comparator invoked per element.
  7014. * @returns {Array} Returns the new array of intersecting values.
  7015. * @example
  7016. *
  7017. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7018. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7019. *
  7020. * _.intersectionWith(objects, others, _.isEqual);
  7021. * // => [{ 'x': 1, 'y': 2 }]
  7022. */
  7023. var intersectionWith = baseRest(function(arrays) {
  7024. var comparator = last(arrays),
  7025. mapped = arrayMap(arrays, castArrayLikeObject);
  7026. comparator = typeof comparator == 'function' ? comparator : undefined;
  7027. if (comparator) {
  7028. mapped.pop();
  7029. }
  7030. return (mapped.length && mapped[0] === arrays[0])
  7031. ? baseIntersection(mapped, undefined, comparator)
  7032. : [];
  7033. });
  7034. /**
  7035. * Converts all elements in `array` into a string separated by `separator`.
  7036. *
  7037. * @static
  7038. * @memberOf _
  7039. * @since 4.0.0
  7040. * @category Array
  7041. * @param {Array} array The array to convert.
  7042. * @param {string} [separator=','] The element separator.
  7043. * @returns {string} Returns the joined string.
  7044. * @example
  7045. *
  7046. * _.join(['a', 'b', 'c'], '~');
  7047. * // => 'a~b~c'
  7048. */
  7049. function join(array, separator) {
  7050. return array == null ? '' : nativeJoin.call(array, separator);
  7051. }
  7052. /**
  7053. * Gets the last element of `array`.
  7054. *
  7055. * @static
  7056. * @memberOf _
  7057. * @since 0.1.0
  7058. * @category Array
  7059. * @param {Array} array The array to query.
  7060. * @returns {*} Returns the last element of `array`.
  7061. * @example
  7062. *
  7063. * _.last([1, 2, 3]);
  7064. * // => 3
  7065. */
  7066. function last(array) {
  7067. var length = array == null ? 0 : array.length;
  7068. return length ? array[length - 1] : undefined;
  7069. }
  7070. /**
  7071. * This method is like `_.indexOf` except that it iterates over elements of
  7072. * `array` from right to left.
  7073. *
  7074. * @static
  7075. * @memberOf _
  7076. * @since 0.1.0
  7077. * @category Array
  7078. * @param {Array} array The array to inspect.
  7079. * @param {*} value The value to search for.
  7080. * @param {number} [fromIndex=array.length-1] The index to search from.
  7081. * @returns {number} Returns the index of the matched value, else `-1`.
  7082. * @example
  7083. *
  7084. * _.lastIndexOf([1, 2, 1, 2], 2);
  7085. * // => 3
  7086. *
  7087. * // Search from the `fromIndex`.
  7088. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7089. * // => 1
  7090. */
  7091. function lastIndexOf(array, value, fromIndex) {
  7092. var length = array == null ? 0 : array.length;
  7093. if (!length) {
  7094. return -1;
  7095. }
  7096. var index = length;
  7097. if (fromIndex !== undefined) {
  7098. index = toInteger(fromIndex);
  7099. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7100. }
  7101. return value === value
  7102. ? strictLastIndexOf(array, value, index)
  7103. : baseFindIndex(array, baseIsNaN, index, true);
  7104. }
  7105. /**
  7106. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7107. * element from the end is returned.
  7108. *
  7109. * @static
  7110. * @memberOf _
  7111. * @since 4.11.0
  7112. * @category Array
  7113. * @param {Array} array The array to query.
  7114. * @param {number} [n=0] The index of the element to return.
  7115. * @returns {*} Returns the nth element of `array`.
  7116. * @example
  7117. *
  7118. * var array = ['a', 'b', 'c', 'd'];
  7119. *
  7120. * _.nth(array, 1);
  7121. * // => 'b'
  7122. *
  7123. * _.nth(array, -2);
  7124. * // => 'c';
  7125. */
  7126. function nth(array, n) {
  7127. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7128. }
  7129. /**
  7130. * Removes all given values from `array` using
  7131. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7132. * for equality comparisons.
  7133. *
  7134. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7135. * to remove elements from an array by predicate.
  7136. *
  7137. * @static
  7138. * @memberOf _
  7139. * @since 2.0.0
  7140. * @category Array
  7141. * @param {Array} array The array to modify.
  7142. * @param {...*} [values] The values to remove.
  7143. * @returns {Array} Returns `array`.
  7144. * @example
  7145. *
  7146. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7147. *
  7148. * _.pull(array, 'a', 'c');
  7149. * console.log(array);
  7150. * // => ['b', 'b']
  7151. */
  7152. var pull = baseRest(pullAll);
  7153. /**
  7154. * This method is like `_.pull` except that it accepts an array of values to remove.
  7155. *
  7156. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7157. *
  7158. * @static
  7159. * @memberOf _
  7160. * @since 4.0.0
  7161. * @category Array
  7162. * @param {Array} array The array to modify.
  7163. * @param {Array} values The values to remove.
  7164. * @returns {Array} Returns `array`.
  7165. * @example
  7166. *
  7167. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7168. *
  7169. * _.pullAll(array, ['a', 'c']);
  7170. * console.log(array);
  7171. * // => ['b', 'b']
  7172. */
  7173. function pullAll(array, values) {
  7174. return (array && array.length && values && values.length)
  7175. ? basePullAll(array, values)
  7176. : array;
  7177. }
  7178. /**
  7179. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7180. * invoked for each element of `array` and `values` to generate the criterion
  7181. * by which they're compared. The iteratee is invoked with one argument: (value).
  7182. *
  7183. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7184. *
  7185. * @static
  7186. * @memberOf _
  7187. * @since 4.0.0
  7188. * @category Array
  7189. * @param {Array} array The array to modify.
  7190. * @param {Array} values The values to remove.
  7191. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7192. * @returns {Array} Returns `array`.
  7193. * @example
  7194. *
  7195. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7196. *
  7197. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7198. * console.log(array);
  7199. * // => [{ 'x': 2 }]
  7200. */
  7201. function pullAllBy(array, values, iteratee) {
  7202. return (array && array.length && values && values.length)
  7203. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7204. : array;
  7205. }
  7206. /**
  7207. * This method is like `_.pullAll` except that it accepts `comparator` which
  7208. * is invoked to compare elements of `array` to `values`. The comparator is
  7209. * invoked with two arguments: (arrVal, othVal).
  7210. *
  7211. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7212. *
  7213. * @static
  7214. * @memberOf _
  7215. * @since 4.6.0
  7216. * @category Array
  7217. * @param {Array} array The array to modify.
  7218. * @param {Array} values The values to remove.
  7219. * @param {Function} [comparator] The comparator invoked per element.
  7220. * @returns {Array} Returns `array`.
  7221. * @example
  7222. *
  7223. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7224. *
  7225. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7226. * console.log(array);
  7227. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7228. */
  7229. function pullAllWith(array, values, comparator) {
  7230. return (array && array.length && values && values.length)
  7231. ? basePullAll(array, values, undefined, comparator)
  7232. : array;
  7233. }
  7234. /**
  7235. * Removes elements from `array` corresponding to `indexes` and returns an
  7236. * array of removed elements.
  7237. *
  7238. * **Note:** Unlike `_.at`, this method mutates `array`.
  7239. *
  7240. * @static
  7241. * @memberOf _
  7242. * @since 3.0.0
  7243. * @category Array
  7244. * @param {Array} array The array to modify.
  7245. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7246. * @returns {Array} Returns the new array of removed elements.
  7247. * @example
  7248. *
  7249. * var array = ['a', 'b', 'c', 'd'];
  7250. * var pulled = _.pullAt(array, [1, 3]);
  7251. *
  7252. * console.log(array);
  7253. * // => ['a', 'c']
  7254. *
  7255. * console.log(pulled);
  7256. * // => ['b', 'd']
  7257. */
  7258. var pullAt = flatRest(function(array, indexes) {
  7259. var length = array == null ? 0 : array.length,
  7260. result = baseAt(array, indexes);
  7261. basePullAt(array, arrayMap(indexes, function(index) {
  7262. return isIndex(index, length) ? +index : index;
  7263. }).sort(compareAscending));
  7264. return result;
  7265. });
  7266. /**
  7267. * Removes all elements from `array` that `predicate` returns truthy for
  7268. * and returns an array of the removed elements. The predicate is invoked
  7269. * with three arguments: (value, index, array).
  7270. *
  7271. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7272. * to pull elements from an array by value.
  7273. *
  7274. * @static
  7275. * @memberOf _
  7276. * @since 2.0.0
  7277. * @category Array
  7278. * @param {Array} array The array to modify.
  7279. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7280. * @returns {Array} Returns the new array of removed elements.
  7281. * @example
  7282. *
  7283. * var array = [1, 2, 3, 4];
  7284. * var evens = _.remove(array, function(n) {
  7285. * return n % 2 == 0;
  7286. * });
  7287. *
  7288. * console.log(array);
  7289. * // => [1, 3]
  7290. *
  7291. * console.log(evens);
  7292. * // => [2, 4]
  7293. */
  7294. function remove(array, predicate) {
  7295. var result = [];
  7296. if (!(array && array.length)) {
  7297. return result;
  7298. }
  7299. var index = -1,
  7300. indexes = [],
  7301. length = array.length;
  7302. predicate = getIteratee(predicate, 3);
  7303. while (++index < length) {
  7304. var value = array[index];
  7305. if (predicate(value, index, array)) {
  7306. result.push(value);
  7307. indexes.push(index);
  7308. }
  7309. }
  7310. basePullAt(array, indexes);
  7311. return result;
  7312. }
  7313. /**
  7314. * Reverses `array` so that the first element becomes the last, the second
  7315. * element becomes the second to last, and so on.
  7316. *
  7317. * **Note:** This method mutates `array` and is based on
  7318. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7319. *
  7320. * @static
  7321. * @memberOf _
  7322. * @since 4.0.0
  7323. * @category Array
  7324. * @param {Array} array The array to modify.
  7325. * @returns {Array} Returns `array`.
  7326. * @example
  7327. *
  7328. * var array = [1, 2, 3];
  7329. *
  7330. * _.reverse(array);
  7331. * // => [3, 2, 1]
  7332. *
  7333. * console.log(array);
  7334. * // => [3, 2, 1]
  7335. */
  7336. function reverse(array) {
  7337. return array == null ? array : nativeReverse.call(array);
  7338. }
  7339. /**
  7340. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7341. *
  7342. * **Note:** This method is used instead of
  7343. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7344. * returned.
  7345. *
  7346. * @static
  7347. * @memberOf _
  7348. * @since 3.0.0
  7349. * @category Array
  7350. * @param {Array} array The array to slice.
  7351. * @param {number} [start=0] The start position.
  7352. * @param {number} [end=array.length] The end position.
  7353. * @returns {Array} Returns the slice of `array`.
  7354. */
  7355. function slice(array, start, end) {
  7356. var length = array == null ? 0 : array.length;
  7357. if (!length) {
  7358. return [];
  7359. }
  7360. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7361. start = 0;
  7362. end = length;
  7363. }
  7364. else {
  7365. start = start == null ? 0 : toInteger(start);
  7366. end = end === undefined ? length : toInteger(end);
  7367. }
  7368. return baseSlice(array, start, end);
  7369. }
  7370. /**
  7371. * Uses a binary search to determine the lowest index at which `value`
  7372. * should be inserted into `array` in order to maintain its sort order.
  7373. *
  7374. * @static
  7375. * @memberOf _
  7376. * @since 0.1.0
  7377. * @category Array
  7378. * @param {Array} array The sorted array to inspect.
  7379. * @param {*} value The value to evaluate.
  7380. * @returns {number} Returns the index at which `value` should be inserted
  7381. * into `array`.
  7382. * @example
  7383. *
  7384. * _.sortedIndex([30, 50], 40);
  7385. * // => 1
  7386. */
  7387. function sortedIndex(array, value) {
  7388. return baseSortedIndex(array, value);
  7389. }
  7390. /**
  7391. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7392. * which is invoked for `value` and each element of `array` to compute their
  7393. * sort ranking. The iteratee is invoked with one argument: (value).
  7394. *
  7395. * @static
  7396. * @memberOf _
  7397. * @since 4.0.0
  7398. * @category Array
  7399. * @param {Array} array The sorted array to inspect.
  7400. * @param {*} value The value to evaluate.
  7401. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7402. * @returns {number} Returns the index at which `value` should be inserted
  7403. * into `array`.
  7404. * @example
  7405. *
  7406. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7407. *
  7408. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7409. * // => 0
  7410. *
  7411. * // The `_.property` iteratee shorthand.
  7412. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7413. * // => 0
  7414. */
  7415. function sortedIndexBy(array, value, iteratee) {
  7416. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7417. }
  7418. /**
  7419. * This method is like `_.indexOf` except that it performs a binary
  7420. * search on a sorted `array`.
  7421. *
  7422. * @static
  7423. * @memberOf _
  7424. * @since 4.0.0
  7425. * @category Array
  7426. * @param {Array} array The array to inspect.
  7427. * @param {*} value The value to search for.
  7428. * @returns {number} Returns the index of the matched value, else `-1`.
  7429. * @example
  7430. *
  7431. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7432. * // => 1
  7433. */
  7434. function sortedIndexOf(array, value) {
  7435. var length = array == null ? 0 : array.length;
  7436. if (length) {
  7437. var index = baseSortedIndex(array, value);
  7438. if (index < length && eq(array[index], value)) {
  7439. return index;
  7440. }
  7441. }
  7442. return -1;
  7443. }
  7444. /**
  7445. * This method is like `_.sortedIndex` except that it returns the highest
  7446. * index at which `value` should be inserted into `array` in order to
  7447. * maintain its sort order.
  7448. *
  7449. * @static
  7450. * @memberOf _
  7451. * @since 3.0.0
  7452. * @category Array
  7453. * @param {Array} array The sorted array to inspect.
  7454. * @param {*} value The value to evaluate.
  7455. * @returns {number} Returns the index at which `value` should be inserted
  7456. * into `array`.
  7457. * @example
  7458. *
  7459. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7460. * // => 4
  7461. */
  7462. function sortedLastIndex(array, value) {
  7463. return baseSortedIndex(array, value, true);
  7464. }
  7465. /**
  7466. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7467. * which is invoked for `value` and each element of `array` to compute their
  7468. * sort ranking. The iteratee is invoked with one argument: (value).
  7469. *
  7470. * @static
  7471. * @memberOf _
  7472. * @since 4.0.0
  7473. * @category Array
  7474. * @param {Array} array The sorted array to inspect.
  7475. * @param {*} value The value to evaluate.
  7476. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7477. * @returns {number} Returns the index at which `value` should be inserted
  7478. * into `array`.
  7479. * @example
  7480. *
  7481. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7482. *
  7483. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7484. * // => 1
  7485. *
  7486. * // The `_.property` iteratee shorthand.
  7487. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7488. * // => 1
  7489. */
  7490. function sortedLastIndexBy(array, value, iteratee) {
  7491. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7492. }
  7493. /**
  7494. * This method is like `_.lastIndexOf` except that it performs a binary
  7495. * search on a sorted `array`.
  7496. *
  7497. * @static
  7498. * @memberOf _
  7499. * @since 4.0.0
  7500. * @category Array
  7501. * @param {Array} array The array to inspect.
  7502. * @param {*} value The value to search for.
  7503. * @returns {number} Returns the index of the matched value, else `-1`.
  7504. * @example
  7505. *
  7506. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7507. * // => 3
  7508. */
  7509. function sortedLastIndexOf(array, value) {
  7510. var length = array == null ? 0 : array.length;
  7511. if (length) {
  7512. var index = baseSortedIndex(array, value, true) - 1;
  7513. if (eq(array[index], value)) {
  7514. return index;
  7515. }
  7516. }
  7517. return -1;
  7518. }
  7519. /**
  7520. * This method is like `_.uniq` except that it's designed and optimized
  7521. * for sorted arrays.
  7522. *
  7523. * @static
  7524. * @memberOf _
  7525. * @since 4.0.0
  7526. * @category Array
  7527. * @param {Array} array The array to inspect.
  7528. * @returns {Array} Returns the new duplicate free array.
  7529. * @example
  7530. *
  7531. * _.sortedUniq([1, 1, 2]);
  7532. * // => [1, 2]
  7533. */
  7534. function sortedUniq(array) {
  7535. return (array && array.length)
  7536. ? baseSortedUniq(array)
  7537. : [];
  7538. }
  7539. /**
  7540. * This method is like `_.uniqBy` except that it's designed and optimized
  7541. * for sorted arrays.
  7542. *
  7543. * @static
  7544. * @memberOf _
  7545. * @since 4.0.0
  7546. * @category Array
  7547. * @param {Array} array The array to inspect.
  7548. * @param {Function} [iteratee] The iteratee invoked per element.
  7549. * @returns {Array} Returns the new duplicate free array.
  7550. * @example
  7551. *
  7552. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7553. * // => [1.1, 2.3]
  7554. */
  7555. function sortedUniqBy(array, iteratee) {
  7556. return (array && array.length)
  7557. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7558. : [];
  7559. }
  7560. /**
  7561. * Gets all but the first element of `array`.
  7562. *
  7563. * @static
  7564. * @memberOf _
  7565. * @since 4.0.0
  7566. * @category Array
  7567. * @param {Array} array The array to query.
  7568. * @returns {Array} Returns the slice of `array`.
  7569. * @example
  7570. *
  7571. * _.tail([1, 2, 3]);
  7572. * // => [2, 3]
  7573. */
  7574. function tail(array) {
  7575. var length = array == null ? 0 : array.length;
  7576. return length ? baseSlice(array, 1, length) : [];
  7577. }
  7578. /**
  7579. * Creates a slice of `array` with `n` elements taken from the beginning.
  7580. *
  7581. * @static
  7582. * @memberOf _
  7583. * @since 0.1.0
  7584. * @category Array
  7585. * @param {Array} array The array to query.
  7586. * @param {number} [n=1] The number of elements to take.
  7587. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7588. * @returns {Array} Returns the slice of `array`.
  7589. * @example
  7590. *
  7591. * _.take([1, 2, 3]);
  7592. * // => [1]
  7593. *
  7594. * _.take([1, 2, 3], 2);
  7595. * // => [1, 2]
  7596. *
  7597. * _.take([1, 2, 3], 5);
  7598. * // => [1, 2, 3]
  7599. *
  7600. * _.take([1, 2, 3], 0);
  7601. * // => []
  7602. */
  7603. function take(array, n, guard) {
  7604. if (!(array && array.length)) {
  7605. return [];
  7606. }
  7607. n = (guard || n === undefined) ? 1 : toInteger(n);
  7608. return baseSlice(array, 0, n < 0 ? 0 : n);
  7609. }
  7610. /**
  7611. * Creates a slice of `array` with `n` elements taken from the end.
  7612. *
  7613. * @static
  7614. * @memberOf _
  7615. * @since 3.0.0
  7616. * @category Array
  7617. * @param {Array} array The array to query.
  7618. * @param {number} [n=1] The number of elements to take.
  7619. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7620. * @returns {Array} Returns the slice of `array`.
  7621. * @example
  7622. *
  7623. * _.takeRight([1, 2, 3]);
  7624. * // => [3]
  7625. *
  7626. * _.takeRight([1, 2, 3], 2);
  7627. * // => [2, 3]
  7628. *
  7629. * _.takeRight([1, 2, 3], 5);
  7630. * // => [1, 2, 3]
  7631. *
  7632. * _.takeRight([1, 2, 3], 0);
  7633. * // => []
  7634. */
  7635. function takeRight(array, n, guard) {
  7636. var length = array == null ? 0 : array.length;
  7637. if (!length) {
  7638. return [];
  7639. }
  7640. n = (guard || n === undefined) ? 1 : toInteger(n);
  7641. n = length - n;
  7642. return baseSlice(array, n < 0 ? 0 : n, length);
  7643. }
  7644. /**
  7645. * Creates a slice of `array` with elements taken from the end. Elements are
  7646. * taken until `predicate` returns falsey. The predicate is invoked with
  7647. * three arguments: (value, index, array).
  7648. *
  7649. * @static
  7650. * @memberOf _
  7651. * @since 3.0.0
  7652. * @category Array
  7653. * @param {Array} array The array to query.
  7654. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7655. * @returns {Array} Returns the slice of `array`.
  7656. * @example
  7657. *
  7658. * var users = [
  7659. * { 'user': 'barney', 'active': true },
  7660. * { 'user': 'fred', 'active': false },
  7661. * { 'user': 'pebbles', 'active': false }
  7662. * ];
  7663. *
  7664. * _.takeRightWhile(users, function(o) { return !o.active; });
  7665. * // => objects for ['fred', 'pebbles']
  7666. *
  7667. * // The `_.matches` iteratee shorthand.
  7668. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7669. * // => objects for ['pebbles']
  7670. *
  7671. * // The `_.matchesProperty` iteratee shorthand.
  7672. * _.takeRightWhile(users, ['active', false]);
  7673. * // => objects for ['fred', 'pebbles']
  7674. *
  7675. * // The `_.property` iteratee shorthand.
  7676. * _.takeRightWhile(users, 'active');
  7677. * // => []
  7678. */
  7679. function takeRightWhile(array, predicate) {
  7680. return (array && array.length)
  7681. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7682. : [];
  7683. }
  7684. /**
  7685. * Creates a slice of `array` with elements taken from the beginning. Elements
  7686. * are taken until `predicate` returns falsey. The predicate is invoked with
  7687. * three arguments: (value, index, array).
  7688. *
  7689. * @static
  7690. * @memberOf _
  7691. * @since 3.0.0
  7692. * @category Array
  7693. * @param {Array} array The array to query.
  7694. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7695. * @returns {Array} Returns the slice of `array`.
  7696. * @example
  7697. *
  7698. * var users = [
  7699. * { 'user': 'barney', 'active': false },
  7700. * { 'user': 'fred', 'active': false },
  7701. * { 'user': 'pebbles', 'active': true }
  7702. * ];
  7703. *
  7704. * _.takeWhile(users, function(o) { return !o.active; });
  7705. * // => objects for ['barney', 'fred']
  7706. *
  7707. * // The `_.matches` iteratee shorthand.
  7708. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7709. * // => objects for ['barney']
  7710. *
  7711. * // The `_.matchesProperty` iteratee shorthand.
  7712. * _.takeWhile(users, ['active', false]);
  7713. * // => objects for ['barney', 'fred']
  7714. *
  7715. * // The `_.property` iteratee shorthand.
  7716. * _.takeWhile(users, 'active');
  7717. * // => []
  7718. */
  7719. function takeWhile(array, predicate) {
  7720. return (array && array.length)
  7721. ? baseWhile(array, getIteratee(predicate, 3))
  7722. : [];
  7723. }
  7724. /**
  7725. * Creates an array of unique values, in order, from all given arrays using
  7726. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7727. * for equality comparisons.
  7728. *
  7729. * @static
  7730. * @memberOf _
  7731. * @since 0.1.0
  7732. * @category Array
  7733. * @param {...Array} [arrays] The arrays to inspect.
  7734. * @returns {Array} Returns the new array of combined values.
  7735. * @example
  7736. *
  7737. * _.union([2], [1, 2]);
  7738. * // => [2, 1]
  7739. */
  7740. var union = baseRest(function(arrays) {
  7741. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7742. });
  7743. /**
  7744. * This method is like `_.union` except that it accepts `iteratee` which is
  7745. * invoked for each element of each `arrays` to generate the criterion by
  7746. * which uniqueness is computed. Result values are chosen from the first
  7747. * array in which the value occurs. The iteratee is invoked with one argument:
  7748. * (value).
  7749. *
  7750. * @static
  7751. * @memberOf _
  7752. * @since 4.0.0
  7753. * @category Array
  7754. * @param {...Array} [arrays] The arrays to inspect.
  7755. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7756. * @returns {Array} Returns the new array of combined values.
  7757. * @example
  7758. *
  7759. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7760. * // => [2.1, 1.2]
  7761. *
  7762. * // The `_.property` iteratee shorthand.
  7763. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7764. * // => [{ 'x': 1 }, { 'x': 2 }]
  7765. */
  7766. var unionBy = baseRest(function(arrays) {
  7767. var iteratee = last(arrays);
  7768. if (isArrayLikeObject(iteratee)) {
  7769. iteratee = undefined;
  7770. }
  7771. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7772. });
  7773. /**
  7774. * This method is like `_.union` except that it accepts `comparator` which
  7775. * is invoked to compare elements of `arrays`. Result values are chosen from
  7776. * the first array in which the value occurs. The comparator is invoked
  7777. * with two arguments: (arrVal, othVal).
  7778. *
  7779. * @static
  7780. * @memberOf _
  7781. * @since 4.0.0
  7782. * @category Array
  7783. * @param {...Array} [arrays] The arrays to inspect.
  7784. * @param {Function} [comparator] The comparator invoked per element.
  7785. * @returns {Array} Returns the new array of combined values.
  7786. * @example
  7787. *
  7788. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7789. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7790. *
  7791. * _.unionWith(objects, others, _.isEqual);
  7792. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7793. */
  7794. var unionWith = baseRest(function(arrays) {
  7795. var comparator = last(arrays);
  7796. comparator = typeof comparator == 'function' ? comparator : undefined;
  7797. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7798. });
  7799. /**
  7800. * Creates a duplicate-free version of an array, using
  7801. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7802. * for equality comparisons, in which only the first occurrence of each element
  7803. * is kept. The order of result values is determined by the order they occur
  7804. * in the array.
  7805. *
  7806. * @static
  7807. * @memberOf _
  7808. * @since 0.1.0
  7809. * @category Array
  7810. * @param {Array} array The array to inspect.
  7811. * @returns {Array} Returns the new duplicate free array.
  7812. * @example
  7813. *
  7814. * _.uniq([2, 1, 2]);
  7815. * // => [2, 1]
  7816. */
  7817. function uniq(array) {
  7818. return (array && array.length) ? baseUniq(array) : [];
  7819. }
  7820. /**
  7821. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7822. * invoked for each element in `array` to generate the criterion by which
  7823. * uniqueness is computed. The order of result values is determined by the
  7824. * order they occur in the array. The iteratee is invoked with one argument:
  7825. * (value).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 4.0.0
  7830. * @category Array
  7831. * @param {Array} array The array to inspect.
  7832. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7833. * @returns {Array} Returns the new duplicate free array.
  7834. * @example
  7835. *
  7836. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7837. * // => [2.1, 1.2]
  7838. *
  7839. * // The `_.property` iteratee shorthand.
  7840. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7841. * // => [{ 'x': 1 }, { 'x': 2 }]
  7842. */
  7843. function uniqBy(array, iteratee) {
  7844. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7845. }
  7846. /**
  7847. * This method is like `_.uniq` except that it accepts `comparator` which
  7848. * is invoked to compare elements of `array`. The order of result values is
  7849. * determined by the order they occur in the array.The comparator is invoked
  7850. * with two arguments: (arrVal, othVal).
  7851. *
  7852. * @static
  7853. * @memberOf _
  7854. * @since 4.0.0
  7855. * @category Array
  7856. * @param {Array} array The array to inspect.
  7857. * @param {Function} [comparator] The comparator invoked per element.
  7858. * @returns {Array} Returns the new duplicate free array.
  7859. * @example
  7860. *
  7861. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7862. *
  7863. * _.uniqWith(objects, _.isEqual);
  7864. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7865. */
  7866. function uniqWith(array, comparator) {
  7867. comparator = typeof comparator == 'function' ? comparator : undefined;
  7868. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7869. }
  7870. /**
  7871. * This method is like `_.zip` except that it accepts an array of grouped
  7872. * elements and creates an array regrouping the elements to their pre-zip
  7873. * configuration.
  7874. *
  7875. * @static
  7876. * @memberOf _
  7877. * @since 1.2.0
  7878. * @category Array
  7879. * @param {Array} array The array of grouped elements to process.
  7880. * @returns {Array} Returns the new array of regrouped elements.
  7881. * @example
  7882. *
  7883. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7884. * // => [['a', 1, true], ['b', 2, false]]
  7885. *
  7886. * _.unzip(zipped);
  7887. * // => [['a', 'b'], [1, 2], [true, false]]
  7888. */
  7889. function unzip(array) {
  7890. if (!(array && array.length)) {
  7891. return [];
  7892. }
  7893. var length = 0;
  7894. array = arrayFilter(array, function(group) {
  7895. if (isArrayLikeObject(group)) {
  7896. length = nativeMax(group.length, length);
  7897. return true;
  7898. }
  7899. });
  7900. return baseTimes(length, function(index) {
  7901. return arrayMap(array, baseProperty(index));
  7902. });
  7903. }
  7904. /**
  7905. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7906. * how regrouped values should be combined. The iteratee is invoked with the
  7907. * elements of each group: (...group).
  7908. *
  7909. * @static
  7910. * @memberOf _
  7911. * @since 3.8.0
  7912. * @category Array
  7913. * @param {Array} array The array of grouped elements to process.
  7914. * @param {Function} [iteratee=_.identity] The function to combine
  7915. * regrouped values.
  7916. * @returns {Array} Returns the new array of regrouped elements.
  7917. * @example
  7918. *
  7919. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7920. * // => [[1, 10, 100], [2, 20, 200]]
  7921. *
  7922. * _.unzipWith(zipped, _.add);
  7923. * // => [3, 30, 300]
  7924. */
  7925. function unzipWith(array, iteratee) {
  7926. if (!(array && array.length)) {
  7927. return [];
  7928. }
  7929. var result = unzip(array);
  7930. if (iteratee == null) {
  7931. return result;
  7932. }
  7933. return arrayMap(result, function(group) {
  7934. return apply(iteratee, undefined, group);
  7935. });
  7936. }
  7937. /**
  7938. * Creates an array excluding all given values using
  7939. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7940. * for equality comparisons.
  7941. *
  7942. * **Note:** Unlike `_.pull`, this method returns a new array.
  7943. *
  7944. * @static
  7945. * @memberOf _
  7946. * @since 0.1.0
  7947. * @category Array
  7948. * @param {Array} array The array to inspect.
  7949. * @param {...*} [values] The values to exclude.
  7950. * @returns {Array} Returns the new array of filtered values.
  7951. * @see _.difference, _.xor
  7952. * @example
  7953. *
  7954. * _.without([2, 1, 2, 3], 1, 2);
  7955. * // => [3]
  7956. */
  7957. var without = baseRest(function(array, values) {
  7958. return isArrayLikeObject(array)
  7959. ? baseDifference(array, values)
  7960. : [];
  7961. });
  7962. /**
  7963. * Creates an array of unique values that is the
  7964. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7965. * of the given arrays. The order of result values is determined by the order
  7966. * they occur in the arrays.
  7967. *
  7968. * @static
  7969. * @memberOf _
  7970. * @since 2.4.0
  7971. * @category Array
  7972. * @param {...Array} [arrays] The arrays to inspect.
  7973. * @returns {Array} Returns the new array of filtered values.
  7974. * @see _.difference, _.without
  7975. * @example
  7976. *
  7977. * _.xor([2, 1], [2, 3]);
  7978. * // => [1, 3]
  7979. */
  7980. var xor = baseRest(function(arrays) {
  7981. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7982. });
  7983. /**
  7984. * This method is like `_.xor` except that it accepts `iteratee` which is
  7985. * invoked for each element of each `arrays` to generate the criterion by
  7986. * which by which they're compared. The order of result values is determined
  7987. * by the order they occur in the arrays. The iteratee is invoked with one
  7988. * argument: (value).
  7989. *
  7990. * @static
  7991. * @memberOf _
  7992. * @since 4.0.0
  7993. * @category Array
  7994. * @param {...Array} [arrays] The arrays to inspect.
  7995. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7996. * @returns {Array} Returns the new array of filtered values.
  7997. * @example
  7998. *
  7999. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  8000. * // => [1.2, 3.4]
  8001. *
  8002. * // The `_.property` iteratee shorthand.
  8003. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  8004. * // => [{ 'x': 2 }]
  8005. */
  8006. var xorBy = baseRest(function(arrays) {
  8007. var iteratee = last(arrays);
  8008. if (isArrayLikeObject(iteratee)) {
  8009. iteratee = undefined;
  8010. }
  8011. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  8012. });
  8013. /**
  8014. * This method is like `_.xor` except that it accepts `comparator` which is
  8015. * invoked to compare elements of `arrays`. The order of result values is
  8016. * determined by the order they occur in the arrays. The comparator is invoked
  8017. * with two arguments: (arrVal, othVal).
  8018. *
  8019. * @static
  8020. * @memberOf _
  8021. * @since 4.0.0
  8022. * @category Array
  8023. * @param {...Array} [arrays] The arrays to inspect.
  8024. * @param {Function} [comparator] The comparator invoked per element.
  8025. * @returns {Array} Returns the new array of filtered values.
  8026. * @example
  8027. *
  8028. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8029. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8030. *
  8031. * _.xorWith(objects, others, _.isEqual);
  8032. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8033. */
  8034. var xorWith = baseRest(function(arrays) {
  8035. var comparator = last(arrays);
  8036. comparator = typeof comparator == 'function' ? comparator : undefined;
  8037. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  8038. });
  8039. /**
  8040. * Creates an array of grouped elements, the first of which contains the
  8041. * first elements of the given arrays, the second of which contains the
  8042. * second elements of the given arrays, and so on.
  8043. *
  8044. * @static
  8045. * @memberOf _
  8046. * @since 0.1.0
  8047. * @category Array
  8048. * @param {...Array} [arrays] The arrays to process.
  8049. * @returns {Array} Returns the new array of grouped elements.
  8050. * @example
  8051. *
  8052. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8053. * // => [['a', 1, true], ['b', 2, false]]
  8054. */
  8055. var zip = baseRest(unzip);
  8056. /**
  8057. * This method is like `_.fromPairs` except that it accepts two arrays,
  8058. * one of property identifiers and one of corresponding values.
  8059. *
  8060. * @static
  8061. * @memberOf _
  8062. * @since 0.4.0
  8063. * @category Array
  8064. * @param {Array} [props=[]] The property identifiers.
  8065. * @param {Array} [values=[]] The property values.
  8066. * @returns {Object} Returns the new object.
  8067. * @example
  8068. *
  8069. * _.zipObject(['a', 'b'], [1, 2]);
  8070. * // => { 'a': 1, 'b': 2 }
  8071. */
  8072. function zipObject(props, values) {
  8073. return baseZipObject(props || [], values || [], assignValue);
  8074. }
  8075. /**
  8076. * This method is like `_.zipObject` except that it supports property paths.
  8077. *
  8078. * @static
  8079. * @memberOf _
  8080. * @since 4.1.0
  8081. * @category Array
  8082. * @param {Array} [props=[]] The property identifiers.
  8083. * @param {Array} [values=[]] The property values.
  8084. * @returns {Object} Returns the new object.
  8085. * @example
  8086. *
  8087. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8088. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8089. */
  8090. function zipObjectDeep(props, values) {
  8091. return baseZipObject(props || [], values || [], baseSet);
  8092. }
  8093. /**
  8094. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8095. * how grouped values should be combined. The iteratee is invoked with the
  8096. * elements of each group: (...group).
  8097. *
  8098. * @static
  8099. * @memberOf _
  8100. * @since 3.8.0
  8101. * @category Array
  8102. * @param {...Array} [arrays] The arrays to process.
  8103. * @param {Function} [iteratee=_.identity] The function to combine
  8104. * grouped values.
  8105. * @returns {Array} Returns the new array of grouped elements.
  8106. * @example
  8107. *
  8108. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8109. * return a + b + c;
  8110. * });
  8111. * // => [111, 222]
  8112. */
  8113. var zipWith = baseRest(function(arrays) {
  8114. var length = arrays.length,
  8115. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8116. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8117. return unzipWith(arrays, iteratee);
  8118. });
  8119. /*------------------------------------------------------------------------*/
  8120. /**
  8121. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8122. * chain sequences enabled. The result of such sequences must be unwrapped
  8123. * with `_#value`.
  8124. *
  8125. * @static
  8126. * @memberOf _
  8127. * @since 1.3.0
  8128. * @category Seq
  8129. * @param {*} value The value to wrap.
  8130. * @returns {Object} Returns the new `lodash` wrapper instance.
  8131. * @example
  8132. *
  8133. * var users = [
  8134. * { 'user': 'barney', 'age': 36 },
  8135. * { 'user': 'fred', 'age': 40 },
  8136. * { 'user': 'pebbles', 'age': 1 }
  8137. * ];
  8138. *
  8139. * var youngest = _
  8140. * .chain(users)
  8141. * .sortBy('age')
  8142. * .map(function(o) {
  8143. * return o.user + ' is ' + o.age;
  8144. * })
  8145. * .head()
  8146. * .value();
  8147. * // => 'pebbles is 1'
  8148. */
  8149. function chain(value) {
  8150. var result = lodash(value);
  8151. result.__chain__ = true;
  8152. return result;
  8153. }
  8154. /**
  8155. * This method invokes `interceptor` and returns `value`. The interceptor
  8156. * is invoked with one argument; (value). The purpose of this method is to
  8157. * "tap into" a method chain sequence in order to modify intermediate results.
  8158. *
  8159. * @static
  8160. * @memberOf _
  8161. * @since 0.1.0
  8162. * @category Seq
  8163. * @param {*} value The value to provide to `interceptor`.
  8164. * @param {Function} interceptor The function to invoke.
  8165. * @returns {*} Returns `value`.
  8166. * @example
  8167. *
  8168. * _([1, 2, 3])
  8169. * .tap(function(array) {
  8170. * // Mutate input array.
  8171. * array.pop();
  8172. * })
  8173. * .reverse()
  8174. * .value();
  8175. * // => [2, 1]
  8176. */
  8177. function tap(value, interceptor) {
  8178. interceptor(value);
  8179. return value;
  8180. }
  8181. /**
  8182. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8183. * The purpose of this method is to "pass thru" values replacing intermediate
  8184. * results in a method chain sequence.
  8185. *
  8186. * @static
  8187. * @memberOf _
  8188. * @since 3.0.0
  8189. * @category Seq
  8190. * @param {*} value The value to provide to `interceptor`.
  8191. * @param {Function} interceptor The function to invoke.
  8192. * @returns {*} Returns the result of `interceptor`.
  8193. * @example
  8194. *
  8195. * _(' abc ')
  8196. * .chain()
  8197. * .trim()
  8198. * .thru(function(value) {
  8199. * return [value];
  8200. * })
  8201. * .value();
  8202. * // => ['abc']
  8203. */
  8204. function thru(value, interceptor) {
  8205. return interceptor(value);
  8206. }
  8207. /**
  8208. * This method is the wrapper version of `_.at`.
  8209. *
  8210. * @name at
  8211. * @memberOf _
  8212. * @since 1.0.0
  8213. * @category Seq
  8214. * @param {...(string|string[])} [paths] The property paths to pick.
  8215. * @returns {Object} Returns the new `lodash` wrapper instance.
  8216. * @example
  8217. *
  8218. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8219. *
  8220. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8221. * // => [3, 4]
  8222. */
  8223. var wrapperAt = flatRest(function(paths) {
  8224. var length = paths.length,
  8225. start = length ? paths[0] : 0,
  8226. value = this.__wrapped__,
  8227. interceptor = function(object) { return baseAt(object, paths); };
  8228. if (length > 1 || this.__actions__.length ||
  8229. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8230. return this.thru(interceptor);
  8231. }
  8232. value = value.slice(start, +start + (length ? 1 : 0));
  8233. value.__actions__.push({
  8234. 'func': thru,
  8235. 'args': [interceptor],
  8236. 'thisArg': undefined
  8237. });
  8238. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8239. if (length && !array.length) {
  8240. array.push(undefined);
  8241. }
  8242. return array;
  8243. });
  8244. });
  8245. /**
  8246. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8247. *
  8248. * @name chain
  8249. * @memberOf _
  8250. * @since 0.1.0
  8251. * @category Seq
  8252. * @returns {Object} Returns the new `lodash` wrapper instance.
  8253. * @example
  8254. *
  8255. * var users = [
  8256. * { 'user': 'barney', 'age': 36 },
  8257. * { 'user': 'fred', 'age': 40 }
  8258. * ];
  8259. *
  8260. * // A sequence without explicit chaining.
  8261. * _(users).head();
  8262. * // => { 'user': 'barney', 'age': 36 }
  8263. *
  8264. * // A sequence with explicit chaining.
  8265. * _(users)
  8266. * .chain()
  8267. * .head()
  8268. * .pick('user')
  8269. * .value();
  8270. * // => { 'user': 'barney' }
  8271. */
  8272. function wrapperChain() {
  8273. return chain(this);
  8274. }
  8275. /**
  8276. * Executes the chain sequence and returns the wrapped result.
  8277. *
  8278. * @name commit
  8279. * @memberOf _
  8280. * @since 3.2.0
  8281. * @category Seq
  8282. * @returns {Object} Returns the new `lodash` wrapper instance.
  8283. * @example
  8284. *
  8285. * var array = [1, 2];
  8286. * var wrapped = _(array).push(3);
  8287. *
  8288. * console.log(array);
  8289. * // => [1, 2]
  8290. *
  8291. * wrapped = wrapped.commit();
  8292. * console.log(array);
  8293. * // => [1, 2, 3]
  8294. *
  8295. * wrapped.last();
  8296. * // => 3
  8297. *
  8298. * console.log(array);
  8299. * // => [1, 2, 3]
  8300. */
  8301. function wrapperCommit() {
  8302. return new LodashWrapper(this.value(), this.__chain__);
  8303. }
  8304. /**
  8305. * Gets the next value on a wrapped object following the
  8306. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8307. *
  8308. * @name next
  8309. * @memberOf _
  8310. * @since 4.0.0
  8311. * @category Seq
  8312. * @returns {Object} Returns the next iterator value.
  8313. * @example
  8314. *
  8315. * var wrapped = _([1, 2]);
  8316. *
  8317. * wrapped.next();
  8318. * // => { 'done': false, 'value': 1 }
  8319. *
  8320. * wrapped.next();
  8321. * // => { 'done': false, 'value': 2 }
  8322. *
  8323. * wrapped.next();
  8324. * // => { 'done': true, 'value': undefined }
  8325. */
  8326. function wrapperNext() {
  8327. if (this.__values__ === undefined) {
  8328. this.__values__ = toArray(this.value());
  8329. }
  8330. var done = this.__index__ >= this.__values__.length,
  8331. value = done ? undefined : this.__values__[this.__index__++];
  8332. return { 'done': done, 'value': value };
  8333. }
  8334. /**
  8335. * Enables the wrapper to be iterable.
  8336. *
  8337. * @name Symbol.iterator
  8338. * @memberOf _
  8339. * @since 4.0.0
  8340. * @category Seq
  8341. * @returns {Object} Returns the wrapper object.
  8342. * @example
  8343. *
  8344. * var wrapped = _([1, 2]);
  8345. *
  8346. * wrapped[Symbol.iterator]() === wrapped;
  8347. * // => true
  8348. *
  8349. * Array.from(wrapped);
  8350. * // => [1, 2]
  8351. */
  8352. function wrapperToIterator() {
  8353. return this;
  8354. }
  8355. /**
  8356. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8357. *
  8358. * @name plant
  8359. * @memberOf _
  8360. * @since 3.2.0
  8361. * @category Seq
  8362. * @param {*} value The value to plant.
  8363. * @returns {Object} Returns the new `lodash` wrapper instance.
  8364. * @example
  8365. *
  8366. * function square(n) {
  8367. * return n * n;
  8368. * }
  8369. *
  8370. * var wrapped = _([1, 2]).map(square);
  8371. * var other = wrapped.plant([3, 4]);
  8372. *
  8373. * other.value();
  8374. * // => [9, 16]
  8375. *
  8376. * wrapped.value();
  8377. * // => [1, 4]
  8378. */
  8379. function wrapperPlant(value) {
  8380. var result,
  8381. parent = this;
  8382. while (parent instanceof baseLodash) {
  8383. var clone = wrapperClone(parent);
  8384. clone.__index__ = 0;
  8385. clone.__values__ = undefined;
  8386. if (result) {
  8387. previous.__wrapped__ = clone;
  8388. } else {
  8389. result = clone;
  8390. }
  8391. var previous = clone;
  8392. parent = parent.__wrapped__;
  8393. }
  8394. previous.__wrapped__ = value;
  8395. return result;
  8396. }
  8397. /**
  8398. * This method is the wrapper version of `_.reverse`.
  8399. *
  8400. * **Note:** This method mutates the wrapped array.
  8401. *
  8402. * @name reverse
  8403. * @memberOf _
  8404. * @since 0.1.0
  8405. * @category Seq
  8406. * @returns {Object} Returns the new `lodash` wrapper instance.
  8407. * @example
  8408. *
  8409. * var array = [1, 2, 3];
  8410. *
  8411. * _(array).reverse().value()
  8412. * // => [3, 2, 1]
  8413. *
  8414. * console.log(array);
  8415. * // => [3, 2, 1]
  8416. */
  8417. function wrapperReverse() {
  8418. var value = this.__wrapped__;
  8419. if (value instanceof LazyWrapper) {
  8420. var wrapped = value;
  8421. if (this.__actions__.length) {
  8422. wrapped = new LazyWrapper(this);
  8423. }
  8424. wrapped = wrapped.reverse();
  8425. wrapped.__actions__.push({
  8426. 'func': thru,
  8427. 'args': [reverse],
  8428. 'thisArg': undefined
  8429. });
  8430. return new LodashWrapper(wrapped, this.__chain__);
  8431. }
  8432. return this.thru(reverse);
  8433. }
  8434. /**
  8435. * Executes the chain sequence to resolve the unwrapped value.
  8436. *
  8437. * @name value
  8438. * @memberOf _
  8439. * @since 0.1.0
  8440. * @alias toJSON, valueOf
  8441. * @category Seq
  8442. * @returns {*} Returns the resolved unwrapped value.
  8443. * @example
  8444. *
  8445. * _([1, 2, 3]).value();
  8446. * // => [1, 2, 3]
  8447. */
  8448. function wrapperValue() {
  8449. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8450. }
  8451. /*------------------------------------------------------------------------*/
  8452. /**
  8453. * Creates an object composed of keys generated from the results of running
  8454. * each element of `collection` thru `iteratee`. The corresponding value of
  8455. * each key is the number of times the key was returned by `iteratee`. The
  8456. * iteratee is invoked with one argument: (value).
  8457. *
  8458. * @static
  8459. * @memberOf _
  8460. * @since 0.5.0
  8461. * @category Collection
  8462. * @param {Array|Object} collection The collection to iterate over.
  8463. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8464. * @returns {Object} Returns the composed aggregate object.
  8465. * @example
  8466. *
  8467. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8468. * // => { '4': 1, '6': 2 }
  8469. *
  8470. * // The `_.property` iteratee shorthand.
  8471. * _.countBy(['one', 'two', 'three'], 'length');
  8472. * // => { '3': 2, '5': 1 }
  8473. */
  8474. var countBy = createAggregator(function(result, value, key) {
  8475. if (hasOwnProperty.call(result, key)) {
  8476. ++result[key];
  8477. } else {
  8478. baseAssignValue(result, key, 1);
  8479. }
  8480. });
  8481. /**
  8482. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8483. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8484. * invoked with three arguments: (value, index|key, collection).
  8485. *
  8486. * **Note:** This method returns `true` for
  8487. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8488. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8489. * elements of empty collections.
  8490. *
  8491. * @static
  8492. * @memberOf _
  8493. * @since 0.1.0
  8494. * @category Collection
  8495. * @param {Array|Object} collection The collection to iterate over.
  8496. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8497. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8498. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8499. * else `false`.
  8500. * @example
  8501. *
  8502. * _.every([true, 1, null, 'yes'], Boolean);
  8503. * // => false
  8504. *
  8505. * var users = [
  8506. * { 'user': 'barney', 'age': 36, 'active': false },
  8507. * { 'user': 'fred', 'age': 40, 'active': false }
  8508. * ];
  8509. *
  8510. * // The `_.matches` iteratee shorthand.
  8511. * _.every(users, { 'user': 'barney', 'active': false });
  8512. * // => false
  8513. *
  8514. * // The `_.matchesProperty` iteratee shorthand.
  8515. * _.every(users, ['active', false]);
  8516. * // => true
  8517. *
  8518. * // The `_.property` iteratee shorthand.
  8519. * _.every(users, 'active');
  8520. * // => false
  8521. */
  8522. function every(collection, predicate, guard) {
  8523. var func = isArray(collection) ? arrayEvery : baseEvery;
  8524. if (guard && isIterateeCall(collection, predicate, guard)) {
  8525. predicate = undefined;
  8526. }
  8527. return func(collection, getIteratee(predicate, 3));
  8528. }
  8529. /**
  8530. * Iterates over elements of `collection`, returning an array of all elements
  8531. * `predicate` returns truthy for. The predicate is invoked with three
  8532. * arguments: (value, index|key, collection).
  8533. *
  8534. * **Note:** Unlike `_.remove`, this method returns a new array.
  8535. *
  8536. * @static
  8537. * @memberOf _
  8538. * @since 0.1.0
  8539. * @category Collection
  8540. * @param {Array|Object} collection The collection to iterate over.
  8541. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8542. * @returns {Array} Returns the new filtered array.
  8543. * @see _.reject
  8544. * @example
  8545. *
  8546. * var users = [
  8547. * { 'user': 'barney', 'age': 36, 'active': true },
  8548. * { 'user': 'fred', 'age': 40, 'active': false }
  8549. * ];
  8550. *
  8551. * _.filter(users, function(o) { return !o.active; });
  8552. * // => objects for ['fred']
  8553. *
  8554. * // The `_.matches` iteratee shorthand.
  8555. * _.filter(users, { 'age': 36, 'active': true });
  8556. * // => objects for ['barney']
  8557. *
  8558. * // The `_.matchesProperty` iteratee shorthand.
  8559. * _.filter(users, ['active', false]);
  8560. * // => objects for ['fred']
  8561. *
  8562. * // The `_.property` iteratee shorthand.
  8563. * _.filter(users, 'active');
  8564. * // => objects for ['barney']
  8565. *
  8566. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  8567. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  8568. * // => objects for ['fred', 'barney']
  8569. */
  8570. function filter(collection, predicate) {
  8571. var func = isArray(collection) ? arrayFilter : baseFilter;
  8572. return func(collection, getIteratee(predicate, 3));
  8573. }
  8574. /**
  8575. * Iterates over elements of `collection`, returning the first element
  8576. * `predicate` returns truthy for. The predicate is invoked with three
  8577. * arguments: (value, index|key, collection).
  8578. *
  8579. * @static
  8580. * @memberOf _
  8581. * @since 0.1.0
  8582. * @category Collection
  8583. * @param {Array|Object} collection The collection to inspect.
  8584. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8585. * @param {number} [fromIndex=0] The index to search from.
  8586. * @returns {*} Returns the matched element, else `undefined`.
  8587. * @example
  8588. *
  8589. * var users = [
  8590. * { 'user': 'barney', 'age': 36, 'active': true },
  8591. * { 'user': 'fred', 'age': 40, 'active': false },
  8592. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8593. * ];
  8594. *
  8595. * _.find(users, function(o) { return o.age < 40; });
  8596. * // => object for 'barney'
  8597. *
  8598. * // The `_.matches` iteratee shorthand.
  8599. * _.find(users, { 'age': 1, 'active': true });
  8600. * // => object for 'pebbles'
  8601. *
  8602. * // The `_.matchesProperty` iteratee shorthand.
  8603. * _.find(users, ['active', false]);
  8604. * // => object for 'fred'
  8605. *
  8606. * // The `_.property` iteratee shorthand.
  8607. * _.find(users, 'active');
  8608. * // => object for 'barney'
  8609. */
  8610. var find = createFind(findIndex);
  8611. /**
  8612. * This method is like `_.find` except that it iterates over elements of
  8613. * `collection` from right to left.
  8614. *
  8615. * @static
  8616. * @memberOf _
  8617. * @since 2.0.0
  8618. * @category Collection
  8619. * @param {Array|Object} collection The collection to inspect.
  8620. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8621. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8622. * @returns {*} Returns the matched element, else `undefined`.
  8623. * @example
  8624. *
  8625. * _.findLast([1, 2, 3, 4], function(n) {
  8626. * return n % 2 == 1;
  8627. * });
  8628. * // => 3
  8629. */
  8630. var findLast = createFind(findLastIndex);
  8631. /**
  8632. * Creates a flattened array of values by running each element in `collection`
  8633. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8634. * with three arguments: (value, index|key, collection).
  8635. *
  8636. * @static
  8637. * @memberOf _
  8638. * @since 4.0.0
  8639. * @category Collection
  8640. * @param {Array|Object} collection The collection to iterate over.
  8641. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8642. * @returns {Array} Returns the new flattened array.
  8643. * @example
  8644. *
  8645. * function duplicate(n) {
  8646. * return [n, n];
  8647. * }
  8648. *
  8649. * _.flatMap([1, 2], duplicate);
  8650. * // => [1, 1, 2, 2]
  8651. */
  8652. function flatMap(collection, iteratee) {
  8653. return baseFlatten(map(collection, iteratee), 1);
  8654. }
  8655. /**
  8656. * This method is like `_.flatMap` except that it recursively flattens the
  8657. * mapped results.
  8658. *
  8659. * @static
  8660. * @memberOf _
  8661. * @since 4.7.0
  8662. * @category Collection
  8663. * @param {Array|Object} collection The collection to iterate over.
  8664. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8665. * @returns {Array} Returns the new flattened array.
  8666. * @example
  8667. *
  8668. * function duplicate(n) {
  8669. * return [[[n, n]]];
  8670. * }
  8671. *
  8672. * _.flatMapDeep([1, 2], duplicate);
  8673. * // => [1, 1, 2, 2]
  8674. */
  8675. function flatMapDeep(collection, iteratee) {
  8676. return baseFlatten(map(collection, iteratee), INFINITY);
  8677. }
  8678. /**
  8679. * This method is like `_.flatMap` except that it recursively flattens the
  8680. * mapped results up to `depth` times.
  8681. *
  8682. * @static
  8683. * @memberOf _
  8684. * @since 4.7.0
  8685. * @category Collection
  8686. * @param {Array|Object} collection The collection to iterate over.
  8687. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8688. * @param {number} [depth=1] The maximum recursion depth.
  8689. * @returns {Array} Returns the new flattened array.
  8690. * @example
  8691. *
  8692. * function duplicate(n) {
  8693. * return [[[n, n]]];
  8694. * }
  8695. *
  8696. * _.flatMapDepth([1, 2], duplicate, 2);
  8697. * // => [[1, 1], [2, 2]]
  8698. */
  8699. function flatMapDepth(collection, iteratee, depth) {
  8700. depth = depth === undefined ? 1 : toInteger(depth);
  8701. return baseFlatten(map(collection, iteratee), depth);
  8702. }
  8703. /**
  8704. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8705. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8706. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8707. *
  8708. * **Note:** As with other "Collections" methods, objects with a "length"
  8709. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8710. * or `_.forOwn` for object iteration.
  8711. *
  8712. * @static
  8713. * @memberOf _
  8714. * @since 0.1.0
  8715. * @alias each
  8716. * @category Collection
  8717. * @param {Array|Object} collection The collection to iterate over.
  8718. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8719. * @returns {Array|Object} Returns `collection`.
  8720. * @see _.forEachRight
  8721. * @example
  8722. *
  8723. * _.forEach([1, 2], function(value) {
  8724. * console.log(value);
  8725. * });
  8726. * // => Logs `1` then `2`.
  8727. *
  8728. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8729. * console.log(key);
  8730. * });
  8731. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8732. */
  8733. function forEach(collection, iteratee) {
  8734. var func = isArray(collection) ? arrayEach : baseEach;
  8735. return func(collection, getIteratee(iteratee, 3));
  8736. }
  8737. /**
  8738. * This method is like `_.forEach` except that it iterates over elements of
  8739. * `collection` from right to left.
  8740. *
  8741. * @static
  8742. * @memberOf _
  8743. * @since 2.0.0
  8744. * @alias eachRight
  8745. * @category Collection
  8746. * @param {Array|Object} collection The collection to iterate over.
  8747. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8748. * @returns {Array|Object} Returns `collection`.
  8749. * @see _.forEach
  8750. * @example
  8751. *
  8752. * _.forEachRight([1, 2], function(value) {
  8753. * console.log(value);
  8754. * });
  8755. * // => Logs `2` then `1`.
  8756. */
  8757. function forEachRight(collection, iteratee) {
  8758. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8759. return func(collection, getIteratee(iteratee, 3));
  8760. }
  8761. /**
  8762. * Creates an object composed of keys generated from the results of running
  8763. * each element of `collection` thru `iteratee`. The order of grouped values
  8764. * is determined by the order they occur in `collection`. The corresponding
  8765. * value of each key is an array of elements responsible for generating the
  8766. * key. The iteratee is invoked with one argument: (value).
  8767. *
  8768. * @static
  8769. * @memberOf _
  8770. * @since 0.1.0
  8771. * @category Collection
  8772. * @param {Array|Object} collection The collection to iterate over.
  8773. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8774. * @returns {Object} Returns the composed aggregate object.
  8775. * @example
  8776. *
  8777. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8778. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8779. *
  8780. * // The `_.property` iteratee shorthand.
  8781. * _.groupBy(['one', 'two', 'three'], 'length');
  8782. * // => { '3': ['one', 'two'], '5': ['three'] }
  8783. */
  8784. var groupBy = createAggregator(function(result, value, key) {
  8785. if (hasOwnProperty.call(result, key)) {
  8786. result[key].push(value);
  8787. } else {
  8788. baseAssignValue(result, key, [value]);
  8789. }
  8790. });
  8791. /**
  8792. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8793. * checked for a substring of `value`, otherwise
  8794. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8795. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8796. * the offset from the end of `collection`.
  8797. *
  8798. * @static
  8799. * @memberOf _
  8800. * @since 0.1.0
  8801. * @category Collection
  8802. * @param {Array|Object|string} collection The collection to inspect.
  8803. * @param {*} value The value to search for.
  8804. * @param {number} [fromIndex=0] The index to search from.
  8805. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8806. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8807. * @example
  8808. *
  8809. * _.includes([1, 2, 3], 1);
  8810. * // => true
  8811. *
  8812. * _.includes([1, 2, 3], 1, 2);
  8813. * // => false
  8814. *
  8815. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8816. * // => true
  8817. *
  8818. * _.includes('abcd', 'bc');
  8819. * // => true
  8820. */
  8821. function includes(collection, value, fromIndex, guard) {
  8822. collection = isArrayLike(collection) ? collection : values(collection);
  8823. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8824. var length = collection.length;
  8825. if (fromIndex < 0) {
  8826. fromIndex = nativeMax(length + fromIndex, 0);
  8827. }
  8828. return isString(collection)
  8829. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8830. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8831. }
  8832. /**
  8833. * Invokes the method at `path` of each element in `collection`, returning
  8834. * an array of the results of each invoked method. Any additional arguments
  8835. * are provided to each invoked method. If `path` is a function, it's invoked
  8836. * for, and `this` bound to, each element in `collection`.
  8837. *
  8838. * @static
  8839. * @memberOf _
  8840. * @since 4.0.0
  8841. * @category Collection
  8842. * @param {Array|Object} collection The collection to iterate over.
  8843. * @param {Array|Function|string} path The path of the method to invoke or
  8844. * the function invoked per iteration.
  8845. * @param {...*} [args] The arguments to invoke each method with.
  8846. * @returns {Array} Returns the array of results.
  8847. * @example
  8848. *
  8849. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8850. * // => [[1, 5, 7], [1, 2, 3]]
  8851. *
  8852. * _.invokeMap([123, 456], String.prototype.split, '');
  8853. * // => [['1', '2', '3'], ['4', '5', '6']]
  8854. */
  8855. var invokeMap = baseRest(function(collection, path, args) {
  8856. var index = -1,
  8857. isFunc = typeof path == 'function',
  8858. result = isArrayLike(collection) ? Array(collection.length) : [];
  8859. baseEach(collection, function(value) {
  8860. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8861. });
  8862. return result;
  8863. });
  8864. /**
  8865. * Creates an object composed of keys generated from the results of running
  8866. * each element of `collection` thru `iteratee`. The corresponding value of
  8867. * each key is the last element responsible for generating the key. The
  8868. * iteratee is invoked with one argument: (value).
  8869. *
  8870. * @static
  8871. * @memberOf _
  8872. * @since 4.0.0
  8873. * @category Collection
  8874. * @param {Array|Object} collection The collection to iterate over.
  8875. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8876. * @returns {Object} Returns the composed aggregate object.
  8877. * @example
  8878. *
  8879. * var array = [
  8880. * { 'dir': 'left', 'code': 97 },
  8881. * { 'dir': 'right', 'code': 100 }
  8882. * ];
  8883. *
  8884. * _.keyBy(array, function(o) {
  8885. * return String.fromCharCode(o.code);
  8886. * });
  8887. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8888. *
  8889. * _.keyBy(array, 'dir');
  8890. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8891. */
  8892. var keyBy = createAggregator(function(result, value, key) {
  8893. baseAssignValue(result, key, value);
  8894. });
  8895. /**
  8896. * Creates an array of values by running each element in `collection` thru
  8897. * `iteratee`. The iteratee is invoked with three arguments:
  8898. * (value, index|key, collection).
  8899. *
  8900. * Many lodash methods are guarded to work as iteratees for methods like
  8901. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8902. *
  8903. * The guarded methods are:
  8904. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8905. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8906. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8907. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8908. *
  8909. * @static
  8910. * @memberOf _
  8911. * @since 0.1.0
  8912. * @category Collection
  8913. * @param {Array|Object} collection The collection to iterate over.
  8914. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8915. * @returns {Array} Returns the new mapped array.
  8916. * @example
  8917. *
  8918. * function square(n) {
  8919. * return n * n;
  8920. * }
  8921. *
  8922. * _.map([4, 8], square);
  8923. * // => [16, 64]
  8924. *
  8925. * _.map({ 'a': 4, 'b': 8 }, square);
  8926. * // => [16, 64] (iteration order is not guaranteed)
  8927. *
  8928. * var users = [
  8929. * { 'user': 'barney' },
  8930. * { 'user': 'fred' }
  8931. * ];
  8932. *
  8933. * // The `_.property` iteratee shorthand.
  8934. * _.map(users, 'user');
  8935. * // => ['barney', 'fred']
  8936. */
  8937. function map(collection, iteratee) {
  8938. var func = isArray(collection) ? arrayMap : baseMap;
  8939. return func(collection, getIteratee(iteratee, 3));
  8940. }
  8941. /**
  8942. * This method is like `_.sortBy` except that it allows specifying the sort
  8943. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8944. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8945. * descending or "asc" for ascending sort order of corresponding values.
  8946. *
  8947. * @static
  8948. * @memberOf _
  8949. * @since 4.0.0
  8950. * @category Collection
  8951. * @param {Array|Object} collection The collection to iterate over.
  8952. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8953. * The iteratees to sort by.
  8954. * @param {string[]} [orders] The sort orders of `iteratees`.
  8955. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8956. * @returns {Array} Returns the new sorted array.
  8957. * @example
  8958. *
  8959. * var users = [
  8960. * { 'user': 'fred', 'age': 48 },
  8961. * { 'user': 'barney', 'age': 34 },
  8962. * { 'user': 'fred', 'age': 40 },
  8963. * { 'user': 'barney', 'age': 36 }
  8964. * ];
  8965. *
  8966. * // Sort by `user` in ascending order and by `age` in descending order.
  8967. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8968. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8969. */
  8970. function orderBy(collection, iteratees, orders, guard) {
  8971. if (collection == null) {
  8972. return [];
  8973. }
  8974. if (!isArray(iteratees)) {
  8975. iteratees = iteratees == null ? [] : [iteratees];
  8976. }
  8977. orders = guard ? undefined : orders;
  8978. if (!isArray(orders)) {
  8979. orders = orders == null ? [] : [orders];
  8980. }
  8981. return baseOrderBy(collection, iteratees, orders);
  8982. }
  8983. /**
  8984. * Creates an array of elements split into two groups, the first of which
  8985. * contains elements `predicate` returns truthy for, the second of which
  8986. * contains elements `predicate` returns falsey for. The predicate is
  8987. * invoked with one argument: (value).
  8988. *
  8989. * @static
  8990. * @memberOf _
  8991. * @since 3.0.0
  8992. * @category Collection
  8993. * @param {Array|Object} collection The collection to iterate over.
  8994. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8995. * @returns {Array} Returns the array of grouped elements.
  8996. * @example
  8997. *
  8998. * var users = [
  8999. * { 'user': 'barney', 'age': 36, 'active': false },
  9000. * { 'user': 'fred', 'age': 40, 'active': true },
  9001. * { 'user': 'pebbles', 'age': 1, 'active': false }
  9002. * ];
  9003. *
  9004. * _.partition(users, function(o) { return o.active; });
  9005. * // => objects for [['fred'], ['barney', 'pebbles']]
  9006. *
  9007. * // The `_.matches` iteratee shorthand.
  9008. * _.partition(users, { 'age': 1, 'active': false });
  9009. * // => objects for [['pebbles'], ['barney', 'fred']]
  9010. *
  9011. * // The `_.matchesProperty` iteratee shorthand.
  9012. * _.partition(users, ['active', false]);
  9013. * // => objects for [['barney', 'pebbles'], ['fred']]
  9014. *
  9015. * // The `_.property` iteratee shorthand.
  9016. * _.partition(users, 'active');
  9017. * // => objects for [['fred'], ['barney', 'pebbles']]
  9018. */
  9019. var partition = createAggregator(function(result, value, key) {
  9020. result[key ? 0 : 1].push(value);
  9021. }, function() { return [[], []]; });
  9022. /**
  9023. * Reduces `collection` to a value which is the accumulated result of running
  9024. * each element in `collection` thru `iteratee`, where each successive
  9025. * invocation is supplied the return value of the previous. If `accumulator`
  9026. * is not given, the first element of `collection` is used as the initial
  9027. * value. The iteratee is invoked with four arguments:
  9028. * (accumulator, value, index|key, collection).
  9029. *
  9030. * Many lodash methods are guarded to work as iteratees for methods like
  9031. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9032. *
  9033. * The guarded methods are:
  9034. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9035. * and `sortBy`
  9036. *
  9037. * @static
  9038. * @memberOf _
  9039. * @since 0.1.0
  9040. * @category Collection
  9041. * @param {Array|Object} collection The collection to iterate over.
  9042. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9043. * @param {*} [accumulator] The initial value.
  9044. * @returns {*} Returns the accumulated value.
  9045. * @see _.reduceRight
  9046. * @example
  9047. *
  9048. * _.reduce([1, 2], function(sum, n) {
  9049. * return sum + n;
  9050. * }, 0);
  9051. * // => 3
  9052. *
  9053. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9054. * (result[value] || (result[value] = [])).push(key);
  9055. * return result;
  9056. * }, {});
  9057. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9058. */
  9059. function reduce(collection, iteratee, accumulator) {
  9060. var func = isArray(collection) ? arrayReduce : baseReduce,
  9061. initAccum = arguments.length < 3;
  9062. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9063. }
  9064. /**
  9065. * This method is like `_.reduce` except that it iterates over elements of
  9066. * `collection` from right to left.
  9067. *
  9068. * @static
  9069. * @memberOf _
  9070. * @since 0.1.0
  9071. * @category Collection
  9072. * @param {Array|Object} collection The collection to iterate over.
  9073. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9074. * @param {*} [accumulator] The initial value.
  9075. * @returns {*} Returns the accumulated value.
  9076. * @see _.reduce
  9077. * @example
  9078. *
  9079. * var array = [[0, 1], [2, 3], [4, 5]];
  9080. *
  9081. * _.reduceRight(array, function(flattened, other) {
  9082. * return flattened.concat(other);
  9083. * }, []);
  9084. * // => [4, 5, 2, 3, 0, 1]
  9085. */
  9086. function reduceRight(collection, iteratee, accumulator) {
  9087. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9088. initAccum = arguments.length < 3;
  9089. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9090. }
  9091. /**
  9092. * The opposite of `_.filter`; this method returns the elements of `collection`
  9093. * that `predicate` does **not** return truthy for.
  9094. *
  9095. * @static
  9096. * @memberOf _
  9097. * @since 0.1.0
  9098. * @category Collection
  9099. * @param {Array|Object} collection The collection to iterate over.
  9100. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9101. * @returns {Array} Returns the new filtered array.
  9102. * @see _.filter
  9103. * @example
  9104. *
  9105. * var users = [
  9106. * { 'user': 'barney', 'age': 36, 'active': false },
  9107. * { 'user': 'fred', 'age': 40, 'active': true }
  9108. * ];
  9109. *
  9110. * _.reject(users, function(o) { return !o.active; });
  9111. * // => objects for ['fred']
  9112. *
  9113. * // The `_.matches` iteratee shorthand.
  9114. * _.reject(users, { 'age': 40, 'active': true });
  9115. * // => objects for ['barney']
  9116. *
  9117. * // The `_.matchesProperty` iteratee shorthand.
  9118. * _.reject(users, ['active', false]);
  9119. * // => objects for ['fred']
  9120. *
  9121. * // The `_.property` iteratee shorthand.
  9122. * _.reject(users, 'active');
  9123. * // => objects for ['barney']
  9124. */
  9125. function reject(collection, predicate) {
  9126. var func = isArray(collection) ? arrayFilter : baseFilter;
  9127. return func(collection, negate(getIteratee(predicate, 3)));
  9128. }
  9129. /**
  9130. * Gets a random element from `collection`.
  9131. *
  9132. * @static
  9133. * @memberOf _
  9134. * @since 2.0.0
  9135. * @category Collection
  9136. * @param {Array|Object} collection The collection to sample.
  9137. * @returns {*} Returns the random element.
  9138. * @example
  9139. *
  9140. * _.sample([1, 2, 3, 4]);
  9141. * // => 2
  9142. */
  9143. function sample(collection) {
  9144. var func = isArray(collection) ? arraySample : baseSample;
  9145. return func(collection);
  9146. }
  9147. /**
  9148. * Gets `n` random elements at unique keys from `collection` up to the
  9149. * size of `collection`.
  9150. *
  9151. * @static
  9152. * @memberOf _
  9153. * @since 4.0.0
  9154. * @category Collection
  9155. * @param {Array|Object} collection The collection to sample.
  9156. * @param {number} [n=1] The number of elements to sample.
  9157. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9158. * @returns {Array} Returns the random elements.
  9159. * @example
  9160. *
  9161. * _.sampleSize([1, 2, 3], 2);
  9162. * // => [3, 1]
  9163. *
  9164. * _.sampleSize([1, 2, 3], 4);
  9165. * // => [2, 3, 1]
  9166. */
  9167. function sampleSize(collection, n, guard) {
  9168. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9169. n = 1;
  9170. } else {
  9171. n = toInteger(n);
  9172. }
  9173. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9174. return func(collection, n);
  9175. }
  9176. /**
  9177. * Creates an array of shuffled values, using a version of the
  9178. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9179. *
  9180. * @static
  9181. * @memberOf _
  9182. * @since 0.1.0
  9183. * @category Collection
  9184. * @param {Array|Object} collection The collection to shuffle.
  9185. * @returns {Array} Returns the new shuffled array.
  9186. * @example
  9187. *
  9188. * _.shuffle([1, 2, 3, 4]);
  9189. * // => [4, 1, 3, 2]
  9190. */
  9191. function shuffle(collection) {
  9192. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9193. return func(collection);
  9194. }
  9195. /**
  9196. * Gets the size of `collection` by returning its length for array-like
  9197. * values or the number of own enumerable string keyed properties for objects.
  9198. *
  9199. * @static
  9200. * @memberOf _
  9201. * @since 0.1.0
  9202. * @category Collection
  9203. * @param {Array|Object|string} collection The collection to inspect.
  9204. * @returns {number} Returns the collection size.
  9205. * @example
  9206. *
  9207. * _.size([1, 2, 3]);
  9208. * // => 3
  9209. *
  9210. * _.size({ 'a': 1, 'b': 2 });
  9211. * // => 2
  9212. *
  9213. * _.size('pebbles');
  9214. * // => 7
  9215. */
  9216. function size(collection) {
  9217. if (collection == null) {
  9218. return 0;
  9219. }
  9220. if (isArrayLike(collection)) {
  9221. return isString(collection) ? stringSize(collection) : collection.length;
  9222. }
  9223. var tag = getTag(collection);
  9224. if (tag == mapTag || tag == setTag) {
  9225. return collection.size;
  9226. }
  9227. return baseKeys(collection).length;
  9228. }
  9229. /**
  9230. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9231. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9232. * invoked with three arguments: (value, index|key, collection).
  9233. *
  9234. * @static
  9235. * @memberOf _
  9236. * @since 0.1.0
  9237. * @category Collection
  9238. * @param {Array|Object} collection The collection to iterate over.
  9239. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9240. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9241. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9242. * else `false`.
  9243. * @example
  9244. *
  9245. * _.some([null, 0, 'yes', false], Boolean);
  9246. * // => true
  9247. *
  9248. * var users = [
  9249. * { 'user': 'barney', 'active': true },
  9250. * { 'user': 'fred', 'active': false }
  9251. * ];
  9252. *
  9253. * // The `_.matches` iteratee shorthand.
  9254. * _.some(users, { 'user': 'barney', 'active': false });
  9255. * // => false
  9256. *
  9257. * // The `_.matchesProperty` iteratee shorthand.
  9258. * _.some(users, ['active', false]);
  9259. * // => true
  9260. *
  9261. * // The `_.property` iteratee shorthand.
  9262. * _.some(users, 'active');
  9263. * // => true
  9264. */
  9265. function some(collection, predicate, guard) {
  9266. var func = isArray(collection) ? arraySome : baseSome;
  9267. if (guard && isIterateeCall(collection, predicate, guard)) {
  9268. predicate = undefined;
  9269. }
  9270. return func(collection, getIteratee(predicate, 3));
  9271. }
  9272. /**
  9273. * Creates an array of elements, sorted in ascending order by the results of
  9274. * running each element in a collection thru each iteratee. This method
  9275. * performs a stable sort, that is, it preserves the original sort order of
  9276. * equal elements. The iteratees are invoked with one argument: (value).
  9277. *
  9278. * @static
  9279. * @memberOf _
  9280. * @since 0.1.0
  9281. * @category Collection
  9282. * @param {Array|Object} collection The collection to iterate over.
  9283. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9284. * The iteratees to sort by.
  9285. * @returns {Array} Returns the new sorted array.
  9286. * @example
  9287. *
  9288. * var users = [
  9289. * { 'user': 'fred', 'age': 48 },
  9290. * { 'user': 'barney', 'age': 36 },
  9291. * { 'user': 'fred', 'age': 30 },
  9292. * { 'user': 'barney', 'age': 34 }
  9293. * ];
  9294. *
  9295. * _.sortBy(users, [function(o) { return o.user; }]);
  9296. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  9297. *
  9298. * _.sortBy(users, ['user', 'age']);
  9299. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  9300. */
  9301. var sortBy = baseRest(function(collection, iteratees) {
  9302. if (collection == null) {
  9303. return [];
  9304. }
  9305. var length = iteratees.length;
  9306. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9307. iteratees = [];
  9308. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9309. iteratees = [iteratees[0]];
  9310. }
  9311. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9312. });
  9313. /*------------------------------------------------------------------------*/
  9314. /**
  9315. * Gets the timestamp of the number of milliseconds that have elapsed since
  9316. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9317. *
  9318. * @static
  9319. * @memberOf _
  9320. * @since 2.4.0
  9321. * @category Date
  9322. * @returns {number} Returns the timestamp.
  9323. * @example
  9324. *
  9325. * _.defer(function(stamp) {
  9326. * console.log(_.now() - stamp);
  9327. * }, _.now());
  9328. * // => Logs the number of milliseconds it took for the deferred invocation.
  9329. */
  9330. var now = ctxNow || function() {
  9331. return root.Date.now();
  9332. };
  9333. /*------------------------------------------------------------------------*/
  9334. /**
  9335. * The opposite of `_.before`; this method creates a function that invokes
  9336. * `func` once it's called `n` or more times.
  9337. *
  9338. * @static
  9339. * @memberOf _
  9340. * @since 0.1.0
  9341. * @category Function
  9342. * @param {number} n The number of calls before `func` is invoked.
  9343. * @param {Function} func The function to restrict.
  9344. * @returns {Function} Returns the new restricted function.
  9345. * @example
  9346. *
  9347. * var saves = ['profile', 'settings'];
  9348. *
  9349. * var done = _.after(saves.length, function() {
  9350. * console.log('done saving!');
  9351. * });
  9352. *
  9353. * _.forEach(saves, function(type) {
  9354. * asyncSave({ 'type': type, 'complete': done });
  9355. * });
  9356. * // => Logs 'done saving!' after the two async saves have completed.
  9357. */
  9358. function after(n, func) {
  9359. if (typeof func != 'function') {
  9360. throw new TypeError(FUNC_ERROR_TEXT);
  9361. }
  9362. n = toInteger(n);
  9363. return function() {
  9364. if (--n < 1) {
  9365. return func.apply(this, arguments);
  9366. }
  9367. };
  9368. }
  9369. /**
  9370. * Creates a function that invokes `func`, with up to `n` arguments,
  9371. * ignoring any additional arguments.
  9372. *
  9373. * @static
  9374. * @memberOf _
  9375. * @since 3.0.0
  9376. * @category Function
  9377. * @param {Function} func The function to cap arguments for.
  9378. * @param {number} [n=func.length] The arity cap.
  9379. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9380. * @returns {Function} Returns the new capped function.
  9381. * @example
  9382. *
  9383. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9384. * // => [6, 8, 10]
  9385. */
  9386. function ary(func, n, guard) {
  9387. n = guard ? undefined : n;
  9388. n = (func && n == null) ? func.length : n;
  9389. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9390. }
  9391. /**
  9392. * Creates a function that invokes `func`, with the `this` binding and arguments
  9393. * of the created function, while it's called less than `n` times. Subsequent
  9394. * calls to the created function return the result of the last `func` invocation.
  9395. *
  9396. * @static
  9397. * @memberOf _
  9398. * @since 3.0.0
  9399. * @category Function
  9400. * @param {number} n The number of calls at which `func` is no longer invoked.
  9401. * @param {Function} func The function to restrict.
  9402. * @returns {Function} Returns the new restricted function.
  9403. * @example
  9404. *
  9405. * jQuery(element).on('click', _.before(5, addContactToList));
  9406. * // => Allows adding up to 4 contacts to the list.
  9407. */
  9408. function before(n, func) {
  9409. var result;
  9410. if (typeof func != 'function') {
  9411. throw new TypeError(FUNC_ERROR_TEXT);
  9412. }
  9413. n = toInteger(n);
  9414. return function() {
  9415. if (--n > 0) {
  9416. result = func.apply(this, arguments);
  9417. }
  9418. if (n <= 1) {
  9419. func = undefined;
  9420. }
  9421. return result;
  9422. };
  9423. }
  9424. /**
  9425. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9426. * and `partials` prepended to the arguments it receives.
  9427. *
  9428. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9429. * may be used as a placeholder for partially applied arguments.
  9430. *
  9431. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9432. * property of bound functions.
  9433. *
  9434. * @static
  9435. * @memberOf _
  9436. * @since 0.1.0
  9437. * @category Function
  9438. * @param {Function} func The function to bind.
  9439. * @param {*} thisArg The `this` binding of `func`.
  9440. * @param {...*} [partials] The arguments to be partially applied.
  9441. * @returns {Function} Returns the new bound function.
  9442. * @example
  9443. *
  9444. * function greet(greeting, punctuation) {
  9445. * return greeting + ' ' + this.user + punctuation;
  9446. * }
  9447. *
  9448. * var object = { 'user': 'fred' };
  9449. *
  9450. * var bound = _.bind(greet, object, 'hi');
  9451. * bound('!');
  9452. * // => 'hi fred!'
  9453. *
  9454. * // Bound with placeholders.
  9455. * var bound = _.bind(greet, object, _, '!');
  9456. * bound('hi');
  9457. * // => 'hi fred!'
  9458. */
  9459. var bind = baseRest(function(func, thisArg, partials) {
  9460. var bitmask = WRAP_BIND_FLAG;
  9461. if (partials.length) {
  9462. var holders = replaceHolders(partials, getHolder(bind));
  9463. bitmask |= WRAP_PARTIAL_FLAG;
  9464. }
  9465. return createWrap(func, bitmask, thisArg, partials, holders);
  9466. });
  9467. /**
  9468. * Creates a function that invokes the method at `object[key]` with `partials`
  9469. * prepended to the arguments it receives.
  9470. *
  9471. * This method differs from `_.bind` by allowing bound functions to reference
  9472. * methods that may be redefined or don't yet exist. See
  9473. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9474. * for more details.
  9475. *
  9476. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9477. * builds, may be used as a placeholder for partially applied arguments.
  9478. *
  9479. * @static
  9480. * @memberOf _
  9481. * @since 0.10.0
  9482. * @category Function
  9483. * @param {Object} object The object to invoke the method on.
  9484. * @param {string} key The key of the method.
  9485. * @param {...*} [partials] The arguments to be partially applied.
  9486. * @returns {Function} Returns the new bound function.
  9487. * @example
  9488. *
  9489. * var object = {
  9490. * 'user': 'fred',
  9491. * 'greet': function(greeting, punctuation) {
  9492. * return greeting + ' ' + this.user + punctuation;
  9493. * }
  9494. * };
  9495. *
  9496. * var bound = _.bindKey(object, 'greet', 'hi');
  9497. * bound('!');
  9498. * // => 'hi fred!'
  9499. *
  9500. * object.greet = function(greeting, punctuation) {
  9501. * return greeting + 'ya ' + this.user + punctuation;
  9502. * };
  9503. *
  9504. * bound('!');
  9505. * // => 'hiya fred!'
  9506. *
  9507. * // Bound with placeholders.
  9508. * var bound = _.bindKey(object, 'greet', _, '!');
  9509. * bound('hi');
  9510. * // => 'hiya fred!'
  9511. */
  9512. var bindKey = baseRest(function(object, key, partials) {
  9513. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9514. if (partials.length) {
  9515. var holders = replaceHolders(partials, getHolder(bindKey));
  9516. bitmask |= WRAP_PARTIAL_FLAG;
  9517. }
  9518. return createWrap(key, bitmask, object, partials, holders);
  9519. });
  9520. /**
  9521. * Creates a function that accepts arguments of `func` and either invokes
  9522. * `func` returning its result, if at least `arity` number of arguments have
  9523. * been provided, or returns a function that accepts the remaining `func`
  9524. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9525. * is not sufficient.
  9526. *
  9527. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9528. * may be used as a placeholder for provided arguments.
  9529. *
  9530. * **Note:** This method doesn't set the "length" property of curried functions.
  9531. *
  9532. * @static
  9533. * @memberOf _
  9534. * @since 2.0.0
  9535. * @category Function
  9536. * @param {Function} func The function to curry.
  9537. * @param {number} [arity=func.length] The arity of `func`.
  9538. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9539. * @returns {Function} Returns the new curried function.
  9540. * @example
  9541. *
  9542. * var abc = function(a, b, c) {
  9543. * return [a, b, c];
  9544. * };
  9545. *
  9546. * var curried = _.curry(abc);
  9547. *
  9548. * curried(1)(2)(3);
  9549. * // => [1, 2, 3]
  9550. *
  9551. * curried(1, 2)(3);
  9552. * // => [1, 2, 3]
  9553. *
  9554. * curried(1, 2, 3);
  9555. * // => [1, 2, 3]
  9556. *
  9557. * // Curried with placeholders.
  9558. * curried(1)(_, 3)(2);
  9559. * // => [1, 2, 3]
  9560. */
  9561. function curry(func, arity, guard) {
  9562. arity = guard ? undefined : arity;
  9563. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9564. result.placeholder = curry.placeholder;
  9565. return result;
  9566. }
  9567. /**
  9568. * This method is like `_.curry` except that arguments are applied to `func`
  9569. * in the manner of `_.partialRight` instead of `_.partial`.
  9570. *
  9571. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9572. * builds, may be used as a placeholder for provided arguments.
  9573. *
  9574. * **Note:** This method doesn't set the "length" property of curried functions.
  9575. *
  9576. * @static
  9577. * @memberOf _
  9578. * @since 3.0.0
  9579. * @category Function
  9580. * @param {Function} func The function to curry.
  9581. * @param {number} [arity=func.length] The arity of `func`.
  9582. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9583. * @returns {Function} Returns the new curried function.
  9584. * @example
  9585. *
  9586. * var abc = function(a, b, c) {
  9587. * return [a, b, c];
  9588. * };
  9589. *
  9590. * var curried = _.curryRight(abc);
  9591. *
  9592. * curried(3)(2)(1);
  9593. * // => [1, 2, 3]
  9594. *
  9595. * curried(2, 3)(1);
  9596. * // => [1, 2, 3]
  9597. *
  9598. * curried(1, 2, 3);
  9599. * // => [1, 2, 3]
  9600. *
  9601. * // Curried with placeholders.
  9602. * curried(3)(1, _)(2);
  9603. * // => [1, 2, 3]
  9604. */
  9605. function curryRight(func, arity, guard) {
  9606. arity = guard ? undefined : arity;
  9607. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9608. result.placeholder = curryRight.placeholder;
  9609. return result;
  9610. }
  9611. /**
  9612. * Creates a debounced function that delays invoking `func` until after `wait`
  9613. * milliseconds have elapsed since the last time the debounced function was
  9614. * invoked. The debounced function comes with a `cancel` method to cancel
  9615. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9616. * Provide `options` to indicate whether `func` should be invoked on the
  9617. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9618. * with the last arguments provided to the debounced function. Subsequent
  9619. * calls to the debounced function return the result of the last `func`
  9620. * invocation.
  9621. *
  9622. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9623. * invoked on the trailing edge of the timeout only if the debounced function
  9624. * is invoked more than once during the `wait` timeout.
  9625. *
  9626. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9627. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9628. *
  9629. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9630. * for details over the differences between `_.debounce` and `_.throttle`.
  9631. *
  9632. * @static
  9633. * @memberOf _
  9634. * @since 0.1.0
  9635. * @category Function
  9636. * @param {Function} func The function to debounce.
  9637. * @param {number} [wait=0] The number of milliseconds to delay.
  9638. * @param {Object} [options={}] The options object.
  9639. * @param {boolean} [options.leading=false]
  9640. * Specify invoking on the leading edge of the timeout.
  9641. * @param {number} [options.maxWait]
  9642. * The maximum time `func` is allowed to be delayed before it's invoked.
  9643. * @param {boolean} [options.trailing=true]
  9644. * Specify invoking on the trailing edge of the timeout.
  9645. * @returns {Function} Returns the new debounced function.
  9646. * @example
  9647. *
  9648. * // Avoid costly calculations while the window size is in flux.
  9649. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9650. *
  9651. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9652. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9653. * 'leading': true,
  9654. * 'trailing': false
  9655. * }));
  9656. *
  9657. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9658. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9659. * var source = new EventSource('/stream');
  9660. * jQuery(source).on('message', debounced);
  9661. *
  9662. * // Cancel the trailing debounced invocation.
  9663. * jQuery(window).on('popstate', debounced.cancel);
  9664. */
  9665. function debounce(func, wait, options) {
  9666. var lastArgs,
  9667. lastThis,
  9668. maxWait,
  9669. result,
  9670. timerId,
  9671. lastCallTime,
  9672. lastInvokeTime = 0,
  9673. leading = false,
  9674. maxing = false,
  9675. trailing = true;
  9676. if (typeof func != 'function') {
  9677. throw new TypeError(FUNC_ERROR_TEXT);
  9678. }
  9679. wait = toNumber(wait) || 0;
  9680. if (isObject(options)) {
  9681. leading = !!options.leading;
  9682. maxing = 'maxWait' in options;
  9683. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9684. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9685. }
  9686. function invokeFunc(time) {
  9687. var args = lastArgs,
  9688. thisArg = lastThis;
  9689. lastArgs = lastThis = undefined;
  9690. lastInvokeTime = time;
  9691. result = func.apply(thisArg, args);
  9692. return result;
  9693. }
  9694. function leadingEdge(time) {
  9695. // Reset any `maxWait` timer.
  9696. lastInvokeTime = time;
  9697. // Start the timer for the trailing edge.
  9698. timerId = setTimeout(timerExpired, wait);
  9699. // Invoke the leading edge.
  9700. return leading ? invokeFunc(time) : result;
  9701. }
  9702. function remainingWait(time) {
  9703. var timeSinceLastCall = time - lastCallTime,
  9704. timeSinceLastInvoke = time - lastInvokeTime,
  9705. timeWaiting = wait - timeSinceLastCall;
  9706. return maxing
  9707. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9708. : timeWaiting;
  9709. }
  9710. function shouldInvoke(time) {
  9711. var timeSinceLastCall = time - lastCallTime,
  9712. timeSinceLastInvoke = time - lastInvokeTime;
  9713. // Either this is the first call, activity has stopped and we're at the
  9714. // trailing edge, the system time has gone backwards and we're treating
  9715. // it as the trailing edge, or we've hit the `maxWait` limit.
  9716. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9717. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9718. }
  9719. function timerExpired() {
  9720. var time = now();
  9721. if (shouldInvoke(time)) {
  9722. return trailingEdge(time);
  9723. }
  9724. // Restart the timer.
  9725. timerId = setTimeout(timerExpired, remainingWait(time));
  9726. }
  9727. function trailingEdge(time) {
  9728. timerId = undefined;
  9729. // Only invoke if we have `lastArgs` which means `func` has been
  9730. // debounced at least once.
  9731. if (trailing && lastArgs) {
  9732. return invokeFunc(time);
  9733. }
  9734. lastArgs = lastThis = undefined;
  9735. return result;
  9736. }
  9737. function cancel() {
  9738. if (timerId !== undefined) {
  9739. clearTimeout(timerId);
  9740. }
  9741. lastInvokeTime = 0;
  9742. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9743. }
  9744. function flush() {
  9745. return timerId === undefined ? result : trailingEdge(now());
  9746. }
  9747. function debounced() {
  9748. var time = now(),
  9749. isInvoking = shouldInvoke(time);
  9750. lastArgs = arguments;
  9751. lastThis = this;
  9752. lastCallTime = time;
  9753. if (isInvoking) {
  9754. if (timerId === undefined) {
  9755. return leadingEdge(lastCallTime);
  9756. }
  9757. if (maxing) {
  9758. // Handle invocations in a tight loop.
  9759. clearTimeout(timerId);
  9760. timerId = setTimeout(timerExpired, wait);
  9761. return invokeFunc(lastCallTime);
  9762. }
  9763. }
  9764. if (timerId === undefined) {
  9765. timerId = setTimeout(timerExpired, wait);
  9766. }
  9767. return result;
  9768. }
  9769. debounced.cancel = cancel;
  9770. debounced.flush = flush;
  9771. return debounced;
  9772. }
  9773. /**
  9774. * Defers invoking the `func` until the current call stack has cleared. Any
  9775. * additional arguments are provided to `func` when it's invoked.
  9776. *
  9777. * @static
  9778. * @memberOf _
  9779. * @since 0.1.0
  9780. * @category Function
  9781. * @param {Function} func The function to defer.
  9782. * @param {...*} [args] The arguments to invoke `func` with.
  9783. * @returns {number} Returns the timer id.
  9784. * @example
  9785. *
  9786. * _.defer(function(text) {
  9787. * console.log(text);
  9788. * }, 'deferred');
  9789. * // => Logs 'deferred' after one millisecond.
  9790. */
  9791. var defer = baseRest(function(func, args) {
  9792. return baseDelay(func, 1, args);
  9793. });
  9794. /**
  9795. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9796. * provided to `func` when it's invoked.
  9797. *
  9798. * @static
  9799. * @memberOf _
  9800. * @since 0.1.0
  9801. * @category Function
  9802. * @param {Function} func The function to delay.
  9803. * @param {number} wait The number of milliseconds to delay invocation.
  9804. * @param {...*} [args] The arguments to invoke `func` with.
  9805. * @returns {number} Returns the timer id.
  9806. * @example
  9807. *
  9808. * _.delay(function(text) {
  9809. * console.log(text);
  9810. * }, 1000, 'later');
  9811. * // => Logs 'later' after one second.
  9812. */
  9813. var delay = baseRest(function(func, wait, args) {
  9814. return baseDelay(func, toNumber(wait) || 0, args);
  9815. });
  9816. /**
  9817. * Creates a function that invokes `func` with arguments reversed.
  9818. *
  9819. * @static
  9820. * @memberOf _
  9821. * @since 4.0.0
  9822. * @category Function
  9823. * @param {Function} func The function to flip arguments for.
  9824. * @returns {Function} Returns the new flipped function.
  9825. * @example
  9826. *
  9827. * var flipped = _.flip(function() {
  9828. * return _.toArray(arguments);
  9829. * });
  9830. *
  9831. * flipped('a', 'b', 'c', 'd');
  9832. * // => ['d', 'c', 'b', 'a']
  9833. */
  9834. function flip(func) {
  9835. return createWrap(func, WRAP_FLIP_FLAG);
  9836. }
  9837. /**
  9838. * Creates a function that memoizes the result of `func`. If `resolver` is
  9839. * provided, it determines the cache key for storing the result based on the
  9840. * arguments provided to the memoized function. By default, the first argument
  9841. * provided to the memoized function is used as the map cache key. The `func`
  9842. * is invoked with the `this` binding of the memoized function.
  9843. *
  9844. * **Note:** The cache is exposed as the `cache` property on the memoized
  9845. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9846. * constructor with one whose instances implement the
  9847. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9848. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9849. *
  9850. * @static
  9851. * @memberOf _
  9852. * @since 0.1.0
  9853. * @category Function
  9854. * @param {Function} func The function to have its output memoized.
  9855. * @param {Function} [resolver] The function to resolve the cache key.
  9856. * @returns {Function} Returns the new memoized function.
  9857. * @example
  9858. *
  9859. * var object = { 'a': 1, 'b': 2 };
  9860. * var other = { 'c': 3, 'd': 4 };
  9861. *
  9862. * var values = _.memoize(_.values);
  9863. * values(object);
  9864. * // => [1, 2]
  9865. *
  9866. * values(other);
  9867. * // => [3, 4]
  9868. *
  9869. * object.a = 2;
  9870. * values(object);
  9871. * // => [1, 2]
  9872. *
  9873. * // Modify the result cache.
  9874. * values.cache.set(object, ['a', 'b']);
  9875. * values(object);
  9876. * // => ['a', 'b']
  9877. *
  9878. * // Replace `_.memoize.Cache`.
  9879. * _.memoize.Cache = WeakMap;
  9880. */
  9881. function memoize(func, resolver) {
  9882. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9883. throw new TypeError(FUNC_ERROR_TEXT);
  9884. }
  9885. var memoized = function() {
  9886. var args = arguments,
  9887. key = resolver ? resolver.apply(this, args) : args[0],
  9888. cache = memoized.cache;
  9889. if (cache.has(key)) {
  9890. return cache.get(key);
  9891. }
  9892. var result = func.apply(this, args);
  9893. memoized.cache = cache.set(key, result) || cache;
  9894. return result;
  9895. };
  9896. memoized.cache = new (memoize.Cache || MapCache);
  9897. return memoized;
  9898. }
  9899. // Expose `MapCache`.
  9900. memoize.Cache = MapCache;
  9901. /**
  9902. * Creates a function that negates the result of the predicate `func`. The
  9903. * `func` predicate is invoked with the `this` binding and arguments of the
  9904. * created function.
  9905. *
  9906. * @static
  9907. * @memberOf _
  9908. * @since 3.0.0
  9909. * @category Function
  9910. * @param {Function} predicate The predicate to negate.
  9911. * @returns {Function} Returns the new negated function.
  9912. * @example
  9913. *
  9914. * function isEven(n) {
  9915. * return n % 2 == 0;
  9916. * }
  9917. *
  9918. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9919. * // => [1, 3, 5]
  9920. */
  9921. function negate(predicate) {
  9922. if (typeof predicate != 'function') {
  9923. throw new TypeError(FUNC_ERROR_TEXT);
  9924. }
  9925. return function() {
  9926. var args = arguments;
  9927. switch (args.length) {
  9928. case 0: return !predicate.call(this);
  9929. case 1: return !predicate.call(this, args[0]);
  9930. case 2: return !predicate.call(this, args[0], args[1]);
  9931. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9932. }
  9933. return !predicate.apply(this, args);
  9934. };
  9935. }
  9936. /**
  9937. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9938. * to the function return the value of the first invocation. The `func` is
  9939. * invoked with the `this` binding and arguments of the created function.
  9940. *
  9941. * @static
  9942. * @memberOf _
  9943. * @since 0.1.0
  9944. * @category Function
  9945. * @param {Function} func The function to restrict.
  9946. * @returns {Function} Returns the new restricted function.
  9947. * @example
  9948. *
  9949. * var initialize = _.once(createApplication);
  9950. * initialize();
  9951. * initialize();
  9952. * // => `createApplication` is invoked once
  9953. */
  9954. function once(func) {
  9955. return before(2, func);
  9956. }
  9957. /**
  9958. * Creates a function that invokes `func` with its arguments transformed.
  9959. *
  9960. * @static
  9961. * @since 4.0.0
  9962. * @memberOf _
  9963. * @category Function
  9964. * @param {Function} func The function to wrap.
  9965. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9966. * The argument transforms.
  9967. * @returns {Function} Returns the new function.
  9968. * @example
  9969. *
  9970. * function doubled(n) {
  9971. * return n * 2;
  9972. * }
  9973. *
  9974. * function square(n) {
  9975. * return n * n;
  9976. * }
  9977. *
  9978. * var func = _.overArgs(function(x, y) {
  9979. * return [x, y];
  9980. * }, [square, doubled]);
  9981. *
  9982. * func(9, 3);
  9983. * // => [81, 6]
  9984. *
  9985. * func(10, 5);
  9986. * // => [100, 10]
  9987. */
  9988. var overArgs = castRest(function(func, transforms) {
  9989. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9990. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9991. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9992. var funcsLength = transforms.length;
  9993. return baseRest(function(args) {
  9994. var index = -1,
  9995. length = nativeMin(args.length, funcsLength);
  9996. while (++index < length) {
  9997. args[index] = transforms[index].call(this, args[index]);
  9998. }
  9999. return apply(func, this, args);
  10000. });
  10001. });
  10002. /**
  10003. * Creates a function that invokes `func` with `partials` prepended to the
  10004. * arguments it receives. This method is like `_.bind` except it does **not**
  10005. * alter the `this` binding.
  10006. *
  10007. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  10008. * builds, may be used as a placeholder for partially applied arguments.
  10009. *
  10010. * **Note:** This method doesn't set the "length" property of partially
  10011. * applied functions.
  10012. *
  10013. * @static
  10014. * @memberOf _
  10015. * @since 0.2.0
  10016. * @category Function
  10017. * @param {Function} func The function to partially apply arguments to.
  10018. * @param {...*} [partials] The arguments to be partially applied.
  10019. * @returns {Function} Returns the new partially applied function.
  10020. * @example
  10021. *
  10022. * function greet(greeting, name) {
  10023. * return greeting + ' ' + name;
  10024. * }
  10025. *
  10026. * var sayHelloTo = _.partial(greet, 'hello');
  10027. * sayHelloTo('fred');
  10028. * // => 'hello fred'
  10029. *
  10030. * // Partially applied with placeholders.
  10031. * var greetFred = _.partial(greet, _, 'fred');
  10032. * greetFred('hi');
  10033. * // => 'hi fred'
  10034. */
  10035. var partial = baseRest(function(func, partials) {
  10036. var holders = replaceHolders(partials, getHolder(partial));
  10037. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10038. });
  10039. /**
  10040. * This method is like `_.partial` except that partially applied arguments
  10041. * are appended to the arguments it receives.
  10042. *
  10043. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10044. * builds, may be used as a placeholder for partially applied arguments.
  10045. *
  10046. * **Note:** This method doesn't set the "length" property of partially
  10047. * applied functions.
  10048. *
  10049. * @static
  10050. * @memberOf _
  10051. * @since 1.0.0
  10052. * @category Function
  10053. * @param {Function} func The function to partially apply arguments to.
  10054. * @param {...*} [partials] The arguments to be partially applied.
  10055. * @returns {Function} Returns the new partially applied function.
  10056. * @example
  10057. *
  10058. * function greet(greeting, name) {
  10059. * return greeting + ' ' + name;
  10060. * }
  10061. *
  10062. * var greetFred = _.partialRight(greet, 'fred');
  10063. * greetFred('hi');
  10064. * // => 'hi fred'
  10065. *
  10066. * // Partially applied with placeholders.
  10067. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10068. * sayHelloTo('fred');
  10069. * // => 'hello fred'
  10070. */
  10071. var partialRight = baseRest(function(func, partials) {
  10072. var holders = replaceHolders(partials, getHolder(partialRight));
  10073. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10074. });
  10075. /**
  10076. * Creates a function that invokes `func` with arguments arranged according
  10077. * to the specified `indexes` where the argument value at the first index is
  10078. * provided as the first argument, the argument value at the second index is
  10079. * provided as the second argument, and so on.
  10080. *
  10081. * @static
  10082. * @memberOf _
  10083. * @since 3.0.0
  10084. * @category Function
  10085. * @param {Function} func The function to rearrange arguments for.
  10086. * @param {...(number|number[])} indexes The arranged argument indexes.
  10087. * @returns {Function} Returns the new function.
  10088. * @example
  10089. *
  10090. * var rearged = _.rearg(function(a, b, c) {
  10091. * return [a, b, c];
  10092. * }, [2, 0, 1]);
  10093. *
  10094. * rearged('b', 'c', 'a')
  10095. * // => ['a', 'b', 'c']
  10096. */
  10097. var rearg = flatRest(function(func, indexes) {
  10098. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10099. });
  10100. /**
  10101. * Creates a function that invokes `func` with the `this` binding of the
  10102. * created function and arguments from `start` and beyond provided as
  10103. * an array.
  10104. *
  10105. * **Note:** This method is based on the
  10106. * [rest parameter](https://mdn.io/rest_parameters).
  10107. *
  10108. * @static
  10109. * @memberOf _
  10110. * @since 4.0.0
  10111. * @category Function
  10112. * @param {Function} func The function to apply a rest parameter to.
  10113. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10114. * @returns {Function} Returns the new function.
  10115. * @example
  10116. *
  10117. * var say = _.rest(function(what, names) {
  10118. * return what + ' ' + _.initial(names).join(', ') +
  10119. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10120. * });
  10121. *
  10122. * say('hello', 'fred', 'barney', 'pebbles');
  10123. * // => 'hello fred, barney, & pebbles'
  10124. */
  10125. function rest(func, start) {
  10126. if (typeof func != 'function') {
  10127. throw new TypeError(FUNC_ERROR_TEXT);
  10128. }
  10129. start = start === undefined ? start : toInteger(start);
  10130. return baseRest(func, start);
  10131. }
  10132. /**
  10133. * Creates a function that invokes `func` with the `this` binding of the
  10134. * create function and an array of arguments much like
  10135. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10136. *
  10137. * **Note:** This method is based on the
  10138. * [spread operator](https://mdn.io/spread_operator).
  10139. *
  10140. * @static
  10141. * @memberOf _
  10142. * @since 3.2.0
  10143. * @category Function
  10144. * @param {Function} func The function to spread arguments over.
  10145. * @param {number} [start=0] The start position of the spread.
  10146. * @returns {Function} Returns the new function.
  10147. * @example
  10148. *
  10149. * var say = _.spread(function(who, what) {
  10150. * return who + ' says ' + what;
  10151. * });
  10152. *
  10153. * say(['fred', 'hello']);
  10154. * // => 'fred says hello'
  10155. *
  10156. * var numbers = Promise.all([
  10157. * Promise.resolve(40),
  10158. * Promise.resolve(36)
  10159. * ]);
  10160. *
  10161. * numbers.then(_.spread(function(x, y) {
  10162. * return x + y;
  10163. * }));
  10164. * // => a Promise of 76
  10165. */
  10166. function spread(func, start) {
  10167. if (typeof func != 'function') {
  10168. throw new TypeError(FUNC_ERROR_TEXT);
  10169. }
  10170. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10171. return baseRest(function(args) {
  10172. var array = args[start],
  10173. otherArgs = castSlice(args, 0, start);
  10174. if (array) {
  10175. arrayPush(otherArgs, array);
  10176. }
  10177. return apply(func, this, otherArgs);
  10178. });
  10179. }
  10180. /**
  10181. * Creates a throttled function that only invokes `func` at most once per
  10182. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10183. * method to cancel delayed `func` invocations and a `flush` method to
  10184. * immediately invoke them. Provide `options` to indicate whether `func`
  10185. * should be invoked on the leading and/or trailing edge of the `wait`
  10186. * timeout. The `func` is invoked with the last arguments provided to the
  10187. * throttled function. Subsequent calls to the throttled function return the
  10188. * result of the last `func` invocation.
  10189. *
  10190. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10191. * invoked on the trailing edge of the timeout only if the throttled function
  10192. * is invoked more than once during the `wait` timeout.
  10193. *
  10194. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10195. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10196. *
  10197. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10198. * for details over the differences between `_.throttle` and `_.debounce`.
  10199. *
  10200. * @static
  10201. * @memberOf _
  10202. * @since 0.1.0
  10203. * @category Function
  10204. * @param {Function} func The function to throttle.
  10205. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10206. * @param {Object} [options={}] The options object.
  10207. * @param {boolean} [options.leading=true]
  10208. * Specify invoking on the leading edge of the timeout.
  10209. * @param {boolean} [options.trailing=true]
  10210. * Specify invoking on the trailing edge of the timeout.
  10211. * @returns {Function} Returns the new throttled function.
  10212. * @example
  10213. *
  10214. * // Avoid excessively updating the position while scrolling.
  10215. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10216. *
  10217. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10218. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10219. * jQuery(element).on('click', throttled);
  10220. *
  10221. * // Cancel the trailing throttled invocation.
  10222. * jQuery(window).on('popstate', throttled.cancel);
  10223. */
  10224. function throttle(func, wait, options) {
  10225. var leading = true,
  10226. trailing = true;
  10227. if (typeof func != 'function') {
  10228. throw new TypeError(FUNC_ERROR_TEXT);
  10229. }
  10230. if (isObject(options)) {
  10231. leading = 'leading' in options ? !!options.leading : leading;
  10232. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10233. }
  10234. return debounce(func, wait, {
  10235. 'leading': leading,
  10236. 'maxWait': wait,
  10237. 'trailing': trailing
  10238. });
  10239. }
  10240. /**
  10241. * Creates a function that accepts up to one argument, ignoring any
  10242. * additional arguments.
  10243. *
  10244. * @static
  10245. * @memberOf _
  10246. * @since 4.0.0
  10247. * @category Function
  10248. * @param {Function} func The function to cap arguments for.
  10249. * @returns {Function} Returns the new capped function.
  10250. * @example
  10251. *
  10252. * _.map(['6', '8', '10'], _.unary(parseInt));
  10253. * // => [6, 8, 10]
  10254. */
  10255. function unary(func) {
  10256. return ary(func, 1);
  10257. }
  10258. /**
  10259. * Creates a function that provides `value` to `wrapper` as its first
  10260. * argument. Any additional arguments provided to the function are appended
  10261. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10262. * binding of the created function.
  10263. *
  10264. * @static
  10265. * @memberOf _
  10266. * @since 0.1.0
  10267. * @category Function
  10268. * @param {*} value The value to wrap.
  10269. * @param {Function} [wrapper=identity] The wrapper function.
  10270. * @returns {Function} Returns the new function.
  10271. * @example
  10272. *
  10273. * var p = _.wrap(_.escape, function(func, text) {
  10274. * return '<p>' + func(text) + '</p>';
  10275. * });
  10276. *
  10277. * p('fred, barney, & pebbles');
  10278. * // => '<p>fred, barney, &amp; pebbles</p>'
  10279. */
  10280. function wrap(value, wrapper) {
  10281. return partial(castFunction(wrapper), value);
  10282. }
  10283. /*------------------------------------------------------------------------*/
  10284. /**
  10285. * Casts `value` as an array if it's not one.
  10286. *
  10287. * @static
  10288. * @memberOf _
  10289. * @since 4.4.0
  10290. * @category Lang
  10291. * @param {*} value The value to inspect.
  10292. * @returns {Array} Returns the cast array.
  10293. * @example
  10294. *
  10295. * _.castArray(1);
  10296. * // => [1]
  10297. *
  10298. * _.castArray({ 'a': 1 });
  10299. * // => [{ 'a': 1 }]
  10300. *
  10301. * _.castArray('abc');
  10302. * // => ['abc']
  10303. *
  10304. * _.castArray(null);
  10305. * // => [null]
  10306. *
  10307. * _.castArray(undefined);
  10308. * // => [undefined]
  10309. *
  10310. * _.castArray();
  10311. * // => []
  10312. *
  10313. * var array = [1, 2, 3];
  10314. * console.log(_.castArray(array) === array);
  10315. * // => true
  10316. */
  10317. function castArray() {
  10318. if (!arguments.length) {
  10319. return [];
  10320. }
  10321. var value = arguments[0];
  10322. return isArray(value) ? value : [value];
  10323. }
  10324. /**
  10325. * Creates a shallow clone of `value`.
  10326. *
  10327. * **Note:** This method is loosely based on the
  10328. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10329. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10330. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10331. * arrays. The own enumerable properties of `arguments` objects are cloned
  10332. * as plain objects. An empty object is returned for uncloneable values such
  10333. * as error objects, functions, DOM nodes, and WeakMaps.
  10334. *
  10335. * @static
  10336. * @memberOf _
  10337. * @since 0.1.0
  10338. * @category Lang
  10339. * @param {*} value The value to clone.
  10340. * @returns {*} Returns the cloned value.
  10341. * @see _.cloneDeep
  10342. * @example
  10343. *
  10344. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10345. *
  10346. * var shallow = _.clone(objects);
  10347. * console.log(shallow[0] === objects[0]);
  10348. * // => true
  10349. */
  10350. function clone(value) {
  10351. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10352. }
  10353. /**
  10354. * This method is like `_.clone` except that it accepts `customizer` which
  10355. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10356. * cloning is handled by the method instead. The `customizer` is invoked with
  10357. * up to four arguments; (value [, index|key, object, stack]).
  10358. *
  10359. * @static
  10360. * @memberOf _
  10361. * @since 4.0.0
  10362. * @category Lang
  10363. * @param {*} value The value to clone.
  10364. * @param {Function} [customizer] The function to customize cloning.
  10365. * @returns {*} Returns the cloned value.
  10366. * @see _.cloneDeepWith
  10367. * @example
  10368. *
  10369. * function customizer(value) {
  10370. * if (_.isElement(value)) {
  10371. * return value.cloneNode(false);
  10372. * }
  10373. * }
  10374. *
  10375. * var el = _.cloneWith(document.body, customizer);
  10376. *
  10377. * console.log(el === document.body);
  10378. * // => false
  10379. * console.log(el.nodeName);
  10380. * // => 'BODY'
  10381. * console.log(el.childNodes.length);
  10382. * // => 0
  10383. */
  10384. function cloneWith(value, customizer) {
  10385. customizer = typeof customizer == 'function' ? customizer : undefined;
  10386. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10387. }
  10388. /**
  10389. * This method is like `_.clone` except that it recursively clones `value`.
  10390. *
  10391. * @static
  10392. * @memberOf _
  10393. * @since 1.0.0
  10394. * @category Lang
  10395. * @param {*} value The value to recursively clone.
  10396. * @returns {*} Returns the deep cloned value.
  10397. * @see _.clone
  10398. * @example
  10399. *
  10400. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10401. *
  10402. * var deep = _.cloneDeep(objects);
  10403. * console.log(deep[0] === objects[0]);
  10404. * // => false
  10405. */
  10406. function cloneDeep(value) {
  10407. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10408. }
  10409. /**
  10410. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10411. *
  10412. * @static
  10413. * @memberOf _
  10414. * @since 4.0.0
  10415. * @category Lang
  10416. * @param {*} value The value to recursively clone.
  10417. * @param {Function} [customizer] The function to customize cloning.
  10418. * @returns {*} Returns the deep cloned value.
  10419. * @see _.cloneWith
  10420. * @example
  10421. *
  10422. * function customizer(value) {
  10423. * if (_.isElement(value)) {
  10424. * return value.cloneNode(true);
  10425. * }
  10426. * }
  10427. *
  10428. * var el = _.cloneDeepWith(document.body, customizer);
  10429. *
  10430. * console.log(el === document.body);
  10431. * // => false
  10432. * console.log(el.nodeName);
  10433. * // => 'BODY'
  10434. * console.log(el.childNodes.length);
  10435. * // => 20
  10436. */
  10437. function cloneDeepWith(value, customizer) {
  10438. customizer = typeof customizer == 'function' ? customizer : undefined;
  10439. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10440. }
  10441. /**
  10442. * Checks if `object` conforms to `source` by invoking the predicate
  10443. * properties of `source` with the corresponding property values of `object`.
  10444. *
  10445. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10446. * partially applied.
  10447. *
  10448. * @static
  10449. * @memberOf _
  10450. * @since 4.14.0
  10451. * @category Lang
  10452. * @param {Object} object The object to inspect.
  10453. * @param {Object} source The object of property predicates to conform to.
  10454. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10455. * @example
  10456. *
  10457. * var object = { 'a': 1, 'b': 2 };
  10458. *
  10459. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10460. * // => true
  10461. *
  10462. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10463. * // => false
  10464. */
  10465. function conformsTo(object, source) {
  10466. return source == null || baseConformsTo(object, source, keys(source));
  10467. }
  10468. /**
  10469. * Performs a
  10470. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10471. * comparison between two values to determine if they are equivalent.
  10472. *
  10473. * @static
  10474. * @memberOf _
  10475. * @since 4.0.0
  10476. * @category Lang
  10477. * @param {*} value The value to compare.
  10478. * @param {*} other The other value to compare.
  10479. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10480. * @example
  10481. *
  10482. * var object = { 'a': 1 };
  10483. * var other = { 'a': 1 };
  10484. *
  10485. * _.eq(object, object);
  10486. * // => true
  10487. *
  10488. * _.eq(object, other);
  10489. * // => false
  10490. *
  10491. * _.eq('a', 'a');
  10492. * // => true
  10493. *
  10494. * _.eq('a', Object('a'));
  10495. * // => false
  10496. *
  10497. * _.eq(NaN, NaN);
  10498. * // => true
  10499. */
  10500. function eq(value, other) {
  10501. return value === other || (value !== value && other !== other);
  10502. }
  10503. /**
  10504. * Checks if `value` is greater than `other`.
  10505. *
  10506. * @static
  10507. * @memberOf _
  10508. * @since 3.9.0
  10509. * @category Lang
  10510. * @param {*} value The value to compare.
  10511. * @param {*} other The other value to compare.
  10512. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10513. * else `false`.
  10514. * @see _.lt
  10515. * @example
  10516. *
  10517. * _.gt(3, 1);
  10518. * // => true
  10519. *
  10520. * _.gt(3, 3);
  10521. * // => false
  10522. *
  10523. * _.gt(1, 3);
  10524. * // => false
  10525. */
  10526. var gt = createRelationalOperation(baseGt);
  10527. /**
  10528. * Checks if `value` is greater than or equal to `other`.
  10529. *
  10530. * @static
  10531. * @memberOf _
  10532. * @since 3.9.0
  10533. * @category Lang
  10534. * @param {*} value The value to compare.
  10535. * @param {*} other The other value to compare.
  10536. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10537. * `other`, else `false`.
  10538. * @see _.lte
  10539. * @example
  10540. *
  10541. * _.gte(3, 1);
  10542. * // => true
  10543. *
  10544. * _.gte(3, 3);
  10545. * // => true
  10546. *
  10547. * _.gte(1, 3);
  10548. * // => false
  10549. */
  10550. var gte = createRelationalOperation(function(value, other) {
  10551. return value >= other;
  10552. });
  10553. /**
  10554. * Checks if `value` is likely an `arguments` object.
  10555. *
  10556. * @static
  10557. * @memberOf _
  10558. * @since 0.1.0
  10559. * @category Lang
  10560. * @param {*} value The value to check.
  10561. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10562. * else `false`.
  10563. * @example
  10564. *
  10565. * _.isArguments(function() { return arguments; }());
  10566. * // => true
  10567. *
  10568. * _.isArguments([1, 2, 3]);
  10569. * // => false
  10570. */
  10571. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10572. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10573. !propertyIsEnumerable.call(value, 'callee');
  10574. };
  10575. /**
  10576. * Checks if `value` is classified as an `Array` object.
  10577. *
  10578. * @static
  10579. * @memberOf _
  10580. * @since 0.1.0
  10581. * @category Lang
  10582. * @param {*} value The value to check.
  10583. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10584. * @example
  10585. *
  10586. * _.isArray([1, 2, 3]);
  10587. * // => true
  10588. *
  10589. * _.isArray(document.body.children);
  10590. * // => false
  10591. *
  10592. * _.isArray('abc');
  10593. * // => false
  10594. *
  10595. * _.isArray(_.noop);
  10596. * // => false
  10597. */
  10598. var isArray = Array.isArray;
  10599. /**
  10600. * Checks if `value` is classified as an `ArrayBuffer` object.
  10601. *
  10602. * @static
  10603. * @memberOf _
  10604. * @since 4.3.0
  10605. * @category Lang
  10606. * @param {*} value The value to check.
  10607. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10608. * @example
  10609. *
  10610. * _.isArrayBuffer(new ArrayBuffer(2));
  10611. * // => true
  10612. *
  10613. * _.isArrayBuffer(new Array(2));
  10614. * // => false
  10615. */
  10616. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10617. /**
  10618. * Checks if `value` is array-like. A value is considered array-like if it's
  10619. * not a function and has a `value.length` that's an integer greater than or
  10620. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10621. *
  10622. * @static
  10623. * @memberOf _
  10624. * @since 4.0.0
  10625. * @category Lang
  10626. * @param {*} value The value to check.
  10627. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10628. * @example
  10629. *
  10630. * _.isArrayLike([1, 2, 3]);
  10631. * // => true
  10632. *
  10633. * _.isArrayLike(document.body.children);
  10634. * // => true
  10635. *
  10636. * _.isArrayLike('abc');
  10637. * // => true
  10638. *
  10639. * _.isArrayLike(_.noop);
  10640. * // => false
  10641. */
  10642. function isArrayLike(value) {
  10643. return value != null && isLength(value.length) && !isFunction(value);
  10644. }
  10645. /**
  10646. * This method is like `_.isArrayLike` except that it also checks if `value`
  10647. * is an object.
  10648. *
  10649. * @static
  10650. * @memberOf _
  10651. * @since 4.0.0
  10652. * @category Lang
  10653. * @param {*} value The value to check.
  10654. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10655. * else `false`.
  10656. * @example
  10657. *
  10658. * _.isArrayLikeObject([1, 2, 3]);
  10659. * // => true
  10660. *
  10661. * _.isArrayLikeObject(document.body.children);
  10662. * // => true
  10663. *
  10664. * _.isArrayLikeObject('abc');
  10665. * // => false
  10666. *
  10667. * _.isArrayLikeObject(_.noop);
  10668. * // => false
  10669. */
  10670. function isArrayLikeObject(value) {
  10671. return isObjectLike(value) && isArrayLike(value);
  10672. }
  10673. /**
  10674. * Checks if `value` is classified as a boolean primitive or object.
  10675. *
  10676. * @static
  10677. * @memberOf _
  10678. * @since 0.1.0
  10679. * @category Lang
  10680. * @param {*} value The value to check.
  10681. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10682. * @example
  10683. *
  10684. * _.isBoolean(false);
  10685. * // => true
  10686. *
  10687. * _.isBoolean(null);
  10688. * // => false
  10689. */
  10690. function isBoolean(value) {
  10691. return value === true || value === false ||
  10692. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10693. }
  10694. /**
  10695. * Checks if `value` is a buffer.
  10696. *
  10697. * @static
  10698. * @memberOf _
  10699. * @since 4.3.0
  10700. * @category Lang
  10701. * @param {*} value The value to check.
  10702. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10703. * @example
  10704. *
  10705. * _.isBuffer(new Buffer(2));
  10706. * // => true
  10707. *
  10708. * _.isBuffer(new Uint8Array(2));
  10709. * // => false
  10710. */
  10711. var isBuffer = nativeIsBuffer || stubFalse;
  10712. /**
  10713. * Checks if `value` is classified as a `Date` object.
  10714. *
  10715. * @static
  10716. * @memberOf _
  10717. * @since 0.1.0
  10718. * @category Lang
  10719. * @param {*} value The value to check.
  10720. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10721. * @example
  10722. *
  10723. * _.isDate(new Date);
  10724. * // => true
  10725. *
  10726. * _.isDate('Mon April 23 2012');
  10727. * // => false
  10728. */
  10729. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10730. /**
  10731. * Checks if `value` is likely a DOM element.
  10732. *
  10733. * @static
  10734. * @memberOf _
  10735. * @since 0.1.0
  10736. * @category Lang
  10737. * @param {*} value The value to check.
  10738. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10739. * @example
  10740. *
  10741. * _.isElement(document.body);
  10742. * // => true
  10743. *
  10744. * _.isElement('<body>');
  10745. * // => false
  10746. */
  10747. function isElement(value) {
  10748. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10749. }
  10750. /**
  10751. * Checks if `value` is an empty object, collection, map, or set.
  10752. *
  10753. * Objects are considered empty if they have no own enumerable string keyed
  10754. * properties.
  10755. *
  10756. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10757. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10758. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10759. *
  10760. * @static
  10761. * @memberOf _
  10762. * @since 0.1.0
  10763. * @category Lang
  10764. * @param {*} value The value to check.
  10765. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10766. * @example
  10767. *
  10768. * _.isEmpty(null);
  10769. * // => true
  10770. *
  10771. * _.isEmpty(true);
  10772. * // => true
  10773. *
  10774. * _.isEmpty(1);
  10775. * // => true
  10776. *
  10777. * _.isEmpty([1, 2, 3]);
  10778. * // => false
  10779. *
  10780. * _.isEmpty({ 'a': 1 });
  10781. * // => false
  10782. */
  10783. function isEmpty(value) {
  10784. if (value == null) {
  10785. return true;
  10786. }
  10787. if (isArrayLike(value) &&
  10788. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10789. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10790. return !value.length;
  10791. }
  10792. var tag = getTag(value);
  10793. if (tag == mapTag || tag == setTag) {
  10794. return !value.size;
  10795. }
  10796. if (isPrototype(value)) {
  10797. return !baseKeys(value).length;
  10798. }
  10799. for (var key in value) {
  10800. if (hasOwnProperty.call(value, key)) {
  10801. return false;
  10802. }
  10803. }
  10804. return true;
  10805. }
  10806. /**
  10807. * Performs a deep comparison between two values to determine if they are
  10808. * equivalent.
  10809. *
  10810. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10811. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10812. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10813. * by their own, not inherited, enumerable properties. Functions and DOM
  10814. * nodes are compared by strict equality, i.e. `===`.
  10815. *
  10816. * @static
  10817. * @memberOf _
  10818. * @since 0.1.0
  10819. * @category Lang
  10820. * @param {*} value The value to compare.
  10821. * @param {*} other The other value to compare.
  10822. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10823. * @example
  10824. *
  10825. * var object = { 'a': 1 };
  10826. * var other = { 'a': 1 };
  10827. *
  10828. * _.isEqual(object, other);
  10829. * // => true
  10830. *
  10831. * object === other;
  10832. * // => false
  10833. */
  10834. function isEqual(value, other) {
  10835. return baseIsEqual(value, other);
  10836. }
  10837. /**
  10838. * This method is like `_.isEqual` except that it accepts `customizer` which
  10839. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10840. * are handled by the method instead. The `customizer` is invoked with up to
  10841. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10842. *
  10843. * @static
  10844. * @memberOf _
  10845. * @since 4.0.0
  10846. * @category Lang
  10847. * @param {*} value The value to compare.
  10848. * @param {*} other The other value to compare.
  10849. * @param {Function} [customizer] The function to customize comparisons.
  10850. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10851. * @example
  10852. *
  10853. * function isGreeting(value) {
  10854. * return /^h(?:i|ello)$/.test(value);
  10855. * }
  10856. *
  10857. * function customizer(objValue, othValue) {
  10858. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10859. * return true;
  10860. * }
  10861. * }
  10862. *
  10863. * var array = ['hello', 'goodbye'];
  10864. * var other = ['hi', 'goodbye'];
  10865. *
  10866. * _.isEqualWith(array, other, customizer);
  10867. * // => true
  10868. */
  10869. function isEqualWith(value, other, customizer) {
  10870. customizer = typeof customizer == 'function' ? customizer : undefined;
  10871. var result = customizer ? customizer(value, other) : undefined;
  10872. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10873. }
  10874. /**
  10875. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10876. * `SyntaxError`, `TypeError`, or `URIError` object.
  10877. *
  10878. * @static
  10879. * @memberOf _
  10880. * @since 3.0.0
  10881. * @category Lang
  10882. * @param {*} value The value to check.
  10883. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10884. * @example
  10885. *
  10886. * _.isError(new Error);
  10887. * // => true
  10888. *
  10889. * _.isError(Error);
  10890. * // => false
  10891. */
  10892. function isError(value) {
  10893. if (!isObjectLike(value)) {
  10894. return false;
  10895. }
  10896. var tag = baseGetTag(value);
  10897. return tag == errorTag || tag == domExcTag ||
  10898. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10899. }
  10900. /**
  10901. * Checks if `value` is a finite primitive number.
  10902. *
  10903. * **Note:** This method is based on
  10904. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10905. *
  10906. * @static
  10907. * @memberOf _
  10908. * @since 0.1.0
  10909. * @category Lang
  10910. * @param {*} value The value to check.
  10911. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10912. * @example
  10913. *
  10914. * _.isFinite(3);
  10915. * // => true
  10916. *
  10917. * _.isFinite(Number.MIN_VALUE);
  10918. * // => true
  10919. *
  10920. * _.isFinite(Infinity);
  10921. * // => false
  10922. *
  10923. * _.isFinite('3');
  10924. * // => false
  10925. */
  10926. function isFinite(value) {
  10927. return typeof value == 'number' && nativeIsFinite(value);
  10928. }
  10929. /**
  10930. * Checks if `value` is classified as a `Function` object.
  10931. *
  10932. * @static
  10933. * @memberOf _
  10934. * @since 0.1.0
  10935. * @category Lang
  10936. * @param {*} value The value to check.
  10937. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10938. * @example
  10939. *
  10940. * _.isFunction(_);
  10941. * // => true
  10942. *
  10943. * _.isFunction(/abc/);
  10944. * // => false
  10945. */
  10946. function isFunction(value) {
  10947. if (!isObject(value)) {
  10948. return false;
  10949. }
  10950. // The use of `Object#toString` avoids issues with the `typeof` operator
  10951. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10952. var tag = baseGetTag(value);
  10953. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10954. }
  10955. /**
  10956. * Checks if `value` is an integer.
  10957. *
  10958. * **Note:** This method is based on
  10959. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10960. *
  10961. * @static
  10962. * @memberOf _
  10963. * @since 4.0.0
  10964. * @category Lang
  10965. * @param {*} value The value to check.
  10966. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10967. * @example
  10968. *
  10969. * _.isInteger(3);
  10970. * // => true
  10971. *
  10972. * _.isInteger(Number.MIN_VALUE);
  10973. * // => false
  10974. *
  10975. * _.isInteger(Infinity);
  10976. * // => false
  10977. *
  10978. * _.isInteger('3');
  10979. * // => false
  10980. */
  10981. function isInteger(value) {
  10982. return typeof value == 'number' && value == toInteger(value);
  10983. }
  10984. /**
  10985. * Checks if `value` is a valid array-like length.
  10986. *
  10987. * **Note:** This method is loosely based on
  10988. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10989. *
  10990. * @static
  10991. * @memberOf _
  10992. * @since 4.0.0
  10993. * @category Lang
  10994. * @param {*} value The value to check.
  10995. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10996. * @example
  10997. *
  10998. * _.isLength(3);
  10999. * // => true
  11000. *
  11001. * _.isLength(Number.MIN_VALUE);
  11002. * // => false
  11003. *
  11004. * _.isLength(Infinity);
  11005. * // => false
  11006. *
  11007. * _.isLength('3');
  11008. * // => false
  11009. */
  11010. function isLength(value) {
  11011. return typeof value == 'number' &&
  11012. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11013. }
  11014. /**
  11015. * Checks if `value` is the
  11016. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  11017. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11018. *
  11019. * @static
  11020. * @memberOf _
  11021. * @since 0.1.0
  11022. * @category Lang
  11023. * @param {*} value The value to check.
  11024. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11025. * @example
  11026. *
  11027. * _.isObject({});
  11028. * // => true
  11029. *
  11030. * _.isObject([1, 2, 3]);
  11031. * // => true
  11032. *
  11033. * _.isObject(_.noop);
  11034. * // => true
  11035. *
  11036. * _.isObject(null);
  11037. * // => false
  11038. */
  11039. function isObject(value) {
  11040. var type = typeof value;
  11041. return value != null && (type == 'object' || type == 'function');
  11042. }
  11043. /**
  11044. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11045. * and has a `typeof` result of "object".
  11046. *
  11047. * @static
  11048. * @memberOf _
  11049. * @since 4.0.0
  11050. * @category Lang
  11051. * @param {*} value The value to check.
  11052. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11053. * @example
  11054. *
  11055. * _.isObjectLike({});
  11056. * // => true
  11057. *
  11058. * _.isObjectLike([1, 2, 3]);
  11059. * // => true
  11060. *
  11061. * _.isObjectLike(_.noop);
  11062. * // => false
  11063. *
  11064. * _.isObjectLike(null);
  11065. * // => false
  11066. */
  11067. function isObjectLike(value) {
  11068. return value != null && typeof value == 'object';
  11069. }
  11070. /**
  11071. * Checks if `value` is classified as a `Map` object.
  11072. *
  11073. * @static
  11074. * @memberOf _
  11075. * @since 4.3.0
  11076. * @category Lang
  11077. * @param {*} value The value to check.
  11078. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11079. * @example
  11080. *
  11081. * _.isMap(new Map);
  11082. * // => true
  11083. *
  11084. * _.isMap(new WeakMap);
  11085. * // => false
  11086. */
  11087. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11088. /**
  11089. * Performs a partial deep comparison between `object` and `source` to
  11090. * determine if `object` contains equivalent property values.
  11091. *
  11092. * **Note:** This method is equivalent to `_.matches` when `source` is
  11093. * partially applied.
  11094. *
  11095. * Partial comparisons will match empty array and empty object `source`
  11096. * values against any array or object value, respectively. See `_.isEqual`
  11097. * for a list of supported value comparisons.
  11098. *
  11099. * @static
  11100. * @memberOf _
  11101. * @since 3.0.0
  11102. * @category Lang
  11103. * @param {Object} object The object to inspect.
  11104. * @param {Object} source The object of property values to match.
  11105. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11106. * @example
  11107. *
  11108. * var object = { 'a': 1, 'b': 2 };
  11109. *
  11110. * _.isMatch(object, { 'b': 2 });
  11111. * // => true
  11112. *
  11113. * _.isMatch(object, { 'b': 1 });
  11114. * // => false
  11115. */
  11116. function isMatch(object, source) {
  11117. return object === source || baseIsMatch(object, source, getMatchData(source));
  11118. }
  11119. /**
  11120. * This method is like `_.isMatch` except that it accepts `customizer` which
  11121. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11122. * are handled by the method instead. The `customizer` is invoked with five
  11123. * arguments: (objValue, srcValue, index|key, object, source).
  11124. *
  11125. * @static
  11126. * @memberOf _
  11127. * @since 4.0.0
  11128. * @category Lang
  11129. * @param {Object} object The object to inspect.
  11130. * @param {Object} source The object of property values to match.
  11131. * @param {Function} [customizer] The function to customize comparisons.
  11132. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11133. * @example
  11134. *
  11135. * function isGreeting(value) {
  11136. * return /^h(?:i|ello)$/.test(value);
  11137. * }
  11138. *
  11139. * function customizer(objValue, srcValue) {
  11140. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11141. * return true;
  11142. * }
  11143. * }
  11144. *
  11145. * var object = { 'greeting': 'hello' };
  11146. * var source = { 'greeting': 'hi' };
  11147. *
  11148. * _.isMatchWith(object, source, customizer);
  11149. * // => true
  11150. */
  11151. function isMatchWith(object, source, customizer) {
  11152. customizer = typeof customizer == 'function' ? customizer : undefined;
  11153. return baseIsMatch(object, source, getMatchData(source), customizer);
  11154. }
  11155. /**
  11156. * Checks if `value` is `NaN`.
  11157. *
  11158. * **Note:** This method is based on
  11159. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11160. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11161. * `undefined` and other non-number values.
  11162. *
  11163. * @static
  11164. * @memberOf _
  11165. * @since 0.1.0
  11166. * @category Lang
  11167. * @param {*} value The value to check.
  11168. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11169. * @example
  11170. *
  11171. * _.isNaN(NaN);
  11172. * // => true
  11173. *
  11174. * _.isNaN(new Number(NaN));
  11175. * // => true
  11176. *
  11177. * isNaN(undefined);
  11178. * // => true
  11179. *
  11180. * _.isNaN(undefined);
  11181. * // => false
  11182. */
  11183. function isNaN(value) {
  11184. // An `NaN` primitive is the only value that is not equal to itself.
  11185. // Perform the `toStringTag` check first to avoid errors with some
  11186. // ActiveX objects in IE.
  11187. return isNumber(value) && value != +value;
  11188. }
  11189. /**
  11190. * Checks if `value` is a pristine native function.
  11191. *
  11192. * **Note:** This method can't reliably detect native functions in the presence
  11193. * of the core-js package because core-js circumvents this kind of detection.
  11194. * Despite multiple requests, the core-js maintainer has made it clear: any
  11195. * attempt to fix the detection will be obstructed. As a result, we're left
  11196. * with little choice but to throw an error. Unfortunately, this also affects
  11197. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11198. * which rely on core-js.
  11199. *
  11200. * @static
  11201. * @memberOf _
  11202. * @since 3.0.0
  11203. * @category Lang
  11204. * @param {*} value The value to check.
  11205. * @returns {boolean} Returns `true` if `value` is a native function,
  11206. * else `false`.
  11207. * @example
  11208. *
  11209. * _.isNative(Array.prototype.push);
  11210. * // => true
  11211. *
  11212. * _.isNative(_);
  11213. * // => false
  11214. */
  11215. function isNative(value) {
  11216. if (isMaskable(value)) {
  11217. throw new Error(CORE_ERROR_TEXT);
  11218. }
  11219. return baseIsNative(value);
  11220. }
  11221. /**
  11222. * Checks if `value` is `null`.
  11223. *
  11224. * @static
  11225. * @memberOf _
  11226. * @since 0.1.0
  11227. * @category Lang
  11228. * @param {*} value The value to check.
  11229. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11230. * @example
  11231. *
  11232. * _.isNull(null);
  11233. * // => true
  11234. *
  11235. * _.isNull(void 0);
  11236. * // => false
  11237. */
  11238. function isNull(value) {
  11239. return value === null;
  11240. }
  11241. /**
  11242. * Checks if `value` is `null` or `undefined`.
  11243. *
  11244. * @static
  11245. * @memberOf _
  11246. * @since 4.0.0
  11247. * @category Lang
  11248. * @param {*} value The value to check.
  11249. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11250. * @example
  11251. *
  11252. * _.isNil(null);
  11253. * // => true
  11254. *
  11255. * _.isNil(void 0);
  11256. * // => true
  11257. *
  11258. * _.isNil(NaN);
  11259. * // => false
  11260. */
  11261. function isNil(value) {
  11262. return value == null;
  11263. }
  11264. /**
  11265. * Checks if `value` is classified as a `Number` primitive or object.
  11266. *
  11267. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11268. * classified as numbers, use the `_.isFinite` method.
  11269. *
  11270. * @static
  11271. * @memberOf _
  11272. * @since 0.1.0
  11273. * @category Lang
  11274. * @param {*} value The value to check.
  11275. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11276. * @example
  11277. *
  11278. * _.isNumber(3);
  11279. * // => true
  11280. *
  11281. * _.isNumber(Number.MIN_VALUE);
  11282. * // => true
  11283. *
  11284. * _.isNumber(Infinity);
  11285. * // => true
  11286. *
  11287. * _.isNumber('3');
  11288. * // => false
  11289. */
  11290. function isNumber(value) {
  11291. return typeof value == 'number' ||
  11292. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11293. }
  11294. /**
  11295. * Checks if `value` is a plain object, that is, an object created by the
  11296. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11297. *
  11298. * @static
  11299. * @memberOf _
  11300. * @since 0.8.0
  11301. * @category Lang
  11302. * @param {*} value The value to check.
  11303. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11304. * @example
  11305. *
  11306. * function Foo() {
  11307. * this.a = 1;
  11308. * }
  11309. *
  11310. * _.isPlainObject(new Foo);
  11311. * // => false
  11312. *
  11313. * _.isPlainObject([1, 2, 3]);
  11314. * // => false
  11315. *
  11316. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11317. * // => true
  11318. *
  11319. * _.isPlainObject(Object.create(null));
  11320. * // => true
  11321. */
  11322. function isPlainObject(value) {
  11323. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11324. return false;
  11325. }
  11326. var proto = getPrototype(value);
  11327. if (proto === null) {
  11328. return true;
  11329. }
  11330. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11331. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11332. funcToString.call(Ctor) == objectCtorString;
  11333. }
  11334. /**
  11335. * Checks if `value` is classified as a `RegExp` object.
  11336. *
  11337. * @static
  11338. * @memberOf _
  11339. * @since 0.1.0
  11340. * @category Lang
  11341. * @param {*} value The value to check.
  11342. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11343. * @example
  11344. *
  11345. * _.isRegExp(/abc/);
  11346. * // => true
  11347. *
  11348. * _.isRegExp('/abc/');
  11349. * // => false
  11350. */
  11351. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11352. /**
  11353. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11354. * double precision number which isn't the result of a rounded unsafe integer.
  11355. *
  11356. * **Note:** This method is based on
  11357. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11358. *
  11359. * @static
  11360. * @memberOf _
  11361. * @since 4.0.0
  11362. * @category Lang
  11363. * @param {*} value The value to check.
  11364. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11365. * @example
  11366. *
  11367. * _.isSafeInteger(3);
  11368. * // => true
  11369. *
  11370. * _.isSafeInteger(Number.MIN_VALUE);
  11371. * // => false
  11372. *
  11373. * _.isSafeInteger(Infinity);
  11374. * // => false
  11375. *
  11376. * _.isSafeInteger('3');
  11377. * // => false
  11378. */
  11379. function isSafeInteger(value) {
  11380. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11381. }
  11382. /**
  11383. * Checks if `value` is classified as a `Set` object.
  11384. *
  11385. * @static
  11386. * @memberOf _
  11387. * @since 4.3.0
  11388. * @category Lang
  11389. * @param {*} value The value to check.
  11390. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11391. * @example
  11392. *
  11393. * _.isSet(new Set);
  11394. * // => true
  11395. *
  11396. * _.isSet(new WeakSet);
  11397. * // => false
  11398. */
  11399. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11400. /**
  11401. * Checks if `value` is classified as a `String` primitive or object.
  11402. *
  11403. * @static
  11404. * @since 0.1.0
  11405. * @memberOf _
  11406. * @category Lang
  11407. * @param {*} value The value to check.
  11408. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11409. * @example
  11410. *
  11411. * _.isString('abc');
  11412. * // => true
  11413. *
  11414. * _.isString(1);
  11415. * // => false
  11416. */
  11417. function isString(value) {
  11418. return typeof value == 'string' ||
  11419. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11420. }
  11421. /**
  11422. * Checks if `value` is classified as a `Symbol` primitive or object.
  11423. *
  11424. * @static
  11425. * @memberOf _
  11426. * @since 4.0.0
  11427. * @category Lang
  11428. * @param {*} value The value to check.
  11429. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11430. * @example
  11431. *
  11432. * _.isSymbol(Symbol.iterator);
  11433. * // => true
  11434. *
  11435. * _.isSymbol('abc');
  11436. * // => false
  11437. */
  11438. function isSymbol(value) {
  11439. return typeof value == 'symbol' ||
  11440. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11441. }
  11442. /**
  11443. * Checks if `value` is classified as a typed array.
  11444. *
  11445. * @static
  11446. * @memberOf _
  11447. * @since 3.0.0
  11448. * @category Lang
  11449. * @param {*} value The value to check.
  11450. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11451. * @example
  11452. *
  11453. * _.isTypedArray(new Uint8Array);
  11454. * // => true
  11455. *
  11456. * _.isTypedArray([]);
  11457. * // => false
  11458. */
  11459. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11460. /**
  11461. * Checks if `value` is `undefined`.
  11462. *
  11463. * @static
  11464. * @since 0.1.0
  11465. * @memberOf _
  11466. * @category Lang
  11467. * @param {*} value The value to check.
  11468. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11469. * @example
  11470. *
  11471. * _.isUndefined(void 0);
  11472. * // => true
  11473. *
  11474. * _.isUndefined(null);
  11475. * // => false
  11476. */
  11477. function isUndefined(value) {
  11478. return value === undefined;
  11479. }
  11480. /**
  11481. * Checks if `value` is classified as a `WeakMap` object.
  11482. *
  11483. * @static
  11484. * @memberOf _
  11485. * @since 4.3.0
  11486. * @category Lang
  11487. * @param {*} value The value to check.
  11488. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11489. * @example
  11490. *
  11491. * _.isWeakMap(new WeakMap);
  11492. * // => true
  11493. *
  11494. * _.isWeakMap(new Map);
  11495. * // => false
  11496. */
  11497. function isWeakMap(value) {
  11498. return isObjectLike(value) && getTag(value) == weakMapTag;
  11499. }
  11500. /**
  11501. * Checks if `value` is classified as a `WeakSet` object.
  11502. *
  11503. * @static
  11504. * @memberOf _
  11505. * @since 4.3.0
  11506. * @category Lang
  11507. * @param {*} value The value to check.
  11508. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11509. * @example
  11510. *
  11511. * _.isWeakSet(new WeakSet);
  11512. * // => true
  11513. *
  11514. * _.isWeakSet(new Set);
  11515. * // => false
  11516. */
  11517. function isWeakSet(value) {
  11518. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11519. }
  11520. /**
  11521. * Checks if `value` is less than `other`.
  11522. *
  11523. * @static
  11524. * @memberOf _
  11525. * @since 3.9.0
  11526. * @category Lang
  11527. * @param {*} value The value to compare.
  11528. * @param {*} other The other value to compare.
  11529. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11530. * else `false`.
  11531. * @see _.gt
  11532. * @example
  11533. *
  11534. * _.lt(1, 3);
  11535. * // => true
  11536. *
  11537. * _.lt(3, 3);
  11538. * // => false
  11539. *
  11540. * _.lt(3, 1);
  11541. * // => false
  11542. */
  11543. var lt = createRelationalOperation(baseLt);
  11544. /**
  11545. * Checks if `value` is less than or equal to `other`.
  11546. *
  11547. * @static
  11548. * @memberOf _
  11549. * @since 3.9.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 `value` is less than or equal to
  11554. * `other`, else `false`.
  11555. * @see _.gte
  11556. * @example
  11557. *
  11558. * _.lte(1, 3);
  11559. * // => true
  11560. *
  11561. * _.lte(3, 3);
  11562. * // => true
  11563. *
  11564. * _.lte(3, 1);
  11565. * // => false
  11566. */
  11567. var lte = createRelationalOperation(function(value, other) {
  11568. return value <= other;
  11569. });
  11570. /**
  11571. * Converts `value` to an array.
  11572. *
  11573. * @static
  11574. * @since 0.1.0
  11575. * @memberOf _
  11576. * @category Lang
  11577. * @param {*} value The value to convert.
  11578. * @returns {Array} Returns the converted array.
  11579. * @example
  11580. *
  11581. * _.toArray({ 'a': 1, 'b': 2 });
  11582. * // => [1, 2]
  11583. *
  11584. * _.toArray('abc');
  11585. * // => ['a', 'b', 'c']
  11586. *
  11587. * _.toArray(1);
  11588. * // => []
  11589. *
  11590. * _.toArray(null);
  11591. * // => []
  11592. */
  11593. function toArray(value) {
  11594. if (!value) {
  11595. return [];
  11596. }
  11597. if (isArrayLike(value)) {
  11598. return isString(value) ? stringToArray(value) : copyArray(value);
  11599. }
  11600. if (symIterator && value[symIterator]) {
  11601. return iteratorToArray(value[symIterator]());
  11602. }
  11603. var tag = getTag(value),
  11604. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11605. return func(value);
  11606. }
  11607. /**
  11608. * Converts `value` to a finite number.
  11609. *
  11610. * @static
  11611. * @memberOf _
  11612. * @since 4.12.0
  11613. * @category Lang
  11614. * @param {*} value The value to convert.
  11615. * @returns {number} Returns the converted number.
  11616. * @example
  11617. *
  11618. * _.toFinite(3.2);
  11619. * // => 3.2
  11620. *
  11621. * _.toFinite(Number.MIN_VALUE);
  11622. * // => 5e-324
  11623. *
  11624. * _.toFinite(Infinity);
  11625. * // => 1.7976931348623157e+308
  11626. *
  11627. * _.toFinite('3.2');
  11628. * // => 3.2
  11629. */
  11630. function toFinite(value) {
  11631. if (!value) {
  11632. return value === 0 ? value : 0;
  11633. }
  11634. value = toNumber(value);
  11635. if (value === INFINITY || value === -INFINITY) {
  11636. var sign = (value < 0 ? -1 : 1);
  11637. return sign * MAX_INTEGER;
  11638. }
  11639. return value === value ? value : 0;
  11640. }
  11641. /**
  11642. * Converts `value` to an integer.
  11643. *
  11644. * **Note:** This method is loosely based on
  11645. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11646. *
  11647. * @static
  11648. * @memberOf _
  11649. * @since 4.0.0
  11650. * @category Lang
  11651. * @param {*} value The value to convert.
  11652. * @returns {number} Returns the converted integer.
  11653. * @example
  11654. *
  11655. * _.toInteger(3.2);
  11656. * // => 3
  11657. *
  11658. * _.toInteger(Number.MIN_VALUE);
  11659. * // => 0
  11660. *
  11661. * _.toInteger(Infinity);
  11662. * // => 1.7976931348623157e+308
  11663. *
  11664. * _.toInteger('3.2');
  11665. * // => 3
  11666. */
  11667. function toInteger(value) {
  11668. var result = toFinite(value),
  11669. remainder = result % 1;
  11670. return result === result ? (remainder ? result - remainder : result) : 0;
  11671. }
  11672. /**
  11673. * Converts `value` to an integer suitable for use as the length of an
  11674. * array-like object.
  11675. *
  11676. * **Note:** This method is based on
  11677. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11678. *
  11679. * @static
  11680. * @memberOf _
  11681. * @since 4.0.0
  11682. * @category Lang
  11683. * @param {*} value The value to convert.
  11684. * @returns {number} Returns the converted integer.
  11685. * @example
  11686. *
  11687. * _.toLength(3.2);
  11688. * // => 3
  11689. *
  11690. * _.toLength(Number.MIN_VALUE);
  11691. * // => 0
  11692. *
  11693. * _.toLength(Infinity);
  11694. * // => 4294967295
  11695. *
  11696. * _.toLength('3.2');
  11697. * // => 3
  11698. */
  11699. function toLength(value) {
  11700. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11701. }
  11702. /**
  11703. * Converts `value` to a number.
  11704. *
  11705. * @static
  11706. * @memberOf _
  11707. * @since 4.0.0
  11708. * @category Lang
  11709. * @param {*} value The value to process.
  11710. * @returns {number} Returns the number.
  11711. * @example
  11712. *
  11713. * _.toNumber(3.2);
  11714. * // => 3.2
  11715. *
  11716. * _.toNumber(Number.MIN_VALUE);
  11717. * // => 5e-324
  11718. *
  11719. * _.toNumber(Infinity);
  11720. * // => Infinity
  11721. *
  11722. * _.toNumber('3.2');
  11723. * // => 3.2
  11724. */
  11725. function toNumber(value) {
  11726. if (typeof value == 'number') {
  11727. return value;
  11728. }
  11729. if (isSymbol(value)) {
  11730. return NAN;
  11731. }
  11732. if (isObject(value)) {
  11733. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11734. value = isObject(other) ? (other + '') : other;
  11735. }
  11736. if (typeof value != 'string') {
  11737. return value === 0 ? value : +value;
  11738. }
  11739. value = baseTrim(value);
  11740. var isBinary = reIsBinary.test(value);
  11741. return (isBinary || reIsOctal.test(value))
  11742. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11743. : (reIsBadHex.test(value) ? NAN : +value);
  11744. }
  11745. /**
  11746. * Converts `value` to a plain object flattening inherited enumerable string
  11747. * keyed properties of `value` to own properties of the plain object.
  11748. *
  11749. * @static
  11750. * @memberOf _
  11751. * @since 3.0.0
  11752. * @category Lang
  11753. * @param {*} value The value to convert.
  11754. * @returns {Object} Returns the converted plain object.
  11755. * @example
  11756. *
  11757. * function Foo() {
  11758. * this.b = 2;
  11759. * }
  11760. *
  11761. * Foo.prototype.c = 3;
  11762. *
  11763. * _.assign({ 'a': 1 }, new Foo);
  11764. * // => { 'a': 1, 'b': 2 }
  11765. *
  11766. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11767. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11768. */
  11769. function toPlainObject(value) {
  11770. return copyObject(value, keysIn(value));
  11771. }
  11772. /**
  11773. * Converts `value` to a safe integer. A safe integer can be compared and
  11774. * represented correctly.
  11775. *
  11776. * @static
  11777. * @memberOf _
  11778. * @since 4.0.0
  11779. * @category Lang
  11780. * @param {*} value The value to convert.
  11781. * @returns {number} Returns the converted integer.
  11782. * @example
  11783. *
  11784. * _.toSafeInteger(3.2);
  11785. * // => 3
  11786. *
  11787. * _.toSafeInteger(Number.MIN_VALUE);
  11788. * // => 0
  11789. *
  11790. * _.toSafeInteger(Infinity);
  11791. * // => 9007199254740991
  11792. *
  11793. * _.toSafeInteger('3.2');
  11794. * // => 3
  11795. */
  11796. function toSafeInteger(value) {
  11797. return value
  11798. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11799. : (value === 0 ? value : 0);
  11800. }
  11801. /**
  11802. * Converts `value` to a string. An empty string is returned for `null`
  11803. * and `undefined` values. The sign of `-0` is preserved.
  11804. *
  11805. * @static
  11806. * @memberOf _
  11807. * @since 4.0.0
  11808. * @category Lang
  11809. * @param {*} value The value to convert.
  11810. * @returns {string} Returns the converted string.
  11811. * @example
  11812. *
  11813. * _.toString(null);
  11814. * // => ''
  11815. *
  11816. * _.toString(-0);
  11817. * // => '-0'
  11818. *
  11819. * _.toString([1, 2, 3]);
  11820. * // => '1,2,3'
  11821. */
  11822. function toString(value) {
  11823. return value == null ? '' : baseToString(value);
  11824. }
  11825. /*------------------------------------------------------------------------*/
  11826. /**
  11827. * Assigns own enumerable string keyed properties of source objects to the
  11828. * destination object. Source objects are applied from left to right.
  11829. * Subsequent sources overwrite property assignments of previous sources.
  11830. *
  11831. * **Note:** This method mutates `object` and is loosely based on
  11832. * [`Object.assign`](https://mdn.io/Object/assign).
  11833. *
  11834. * @static
  11835. * @memberOf _
  11836. * @since 0.10.0
  11837. * @category Object
  11838. * @param {Object} object The destination object.
  11839. * @param {...Object} [sources] The source objects.
  11840. * @returns {Object} Returns `object`.
  11841. * @see _.assignIn
  11842. * @example
  11843. *
  11844. * function Foo() {
  11845. * this.a = 1;
  11846. * }
  11847. *
  11848. * function Bar() {
  11849. * this.c = 3;
  11850. * }
  11851. *
  11852. * Foo.prototype.b = 2;
  11853. * Bar.prototype.d = 4;
  11854. *
  11855. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11856. * // => { 'a': 1, 'c': 3 }
  11857. */
  11858. var assign = createAssigner(function(object, source) {
  11859. if (isPrototype(source) || isArrayLike(source)) {
  11860. copyObject(source, keys(source), object);
  11861. return;
  11862. }
  11863. for (var key in source) {
  11864. if (hasOwnProperty.call(source, key)) {
  11865. assignValue(object, key, source[key]);
  11866. }
  11867. }
  11868. });
  11869. /**
  11870. * This method is like `_.assign` except that it iterates over own and
  11871. * inherited source properties.
  11872. *
  11873. * **Note:** This method mutates `object`.
  11874. *
  11875. * @static
  11876. * @memberOf _
  11877. * @since 4.0.0
  11878. * @alias extend
  11879. * @category Object
  11880. * @param {Object} object The destination object.
  11881. * @param {...Object} [sources] The source objects.
  11882. * @returns {Object} Returns `object`.
  11883. * @see _.assign
  11884. * @example
  11885. *
  11886. * function Foo() {
  11887. * this.a = 1;
  11888. * }
  11889. *
  11890. * function Bar() {
  11891. * this.c = 3;
  11892. * }
  11893. *
  11894. * Foo.prototype.b = 2;
  11895. * Bar.prototype.d = 4;
  11896. *
  11897. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11898. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11899. */
  11900. var assignIn = createAssigner(function(object, source) {
  11901. copyObject(source, keysIn(source), object);
  11902. });
  11903. /**
  11904. * This method is like `_.assignIn` except that it accepts `customizer`
  11905. * which is invoked to produce the assigned values. If `customizer` returns
  11906. * `undefined`, assignment is handled by the method instead. The `customizer`
  11907. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11908. *
  11909. * **Note:** This method mutates `object`.
  11910. *
  11911. * @static
  11912. * @memberOf _
  11913. * @since 4.0.0
  11914. * @alias extendWith
  11915. * @category Object
  11916. * @param {Object} object The destination object.
  11917. * @param {...Object} sources The source objects.
  11918. * @param {Function} [customizer] The function to customize assigned values.
  11919. * @returns {Object} Returns `object`.
  11920. * @see _.assignWith
  11921. * @example
  11922. *
  11923. * function customizer(objValue, srcValue) {
  11924. * return _.isUndefined(objValue) ? srcValue : objValue;
  11925. * }
  11926. *
  11927. * var defaults = _.partialRight(_.assignInWith, customizer);
  11928. *
  11929. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11930. * // => { 'a': 1, 'b': 2 }
  11931. */
  11932. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11933. copyObject(source, keysIn(source), object, customizer);
  11934. });
  11935. /**
  11936. * This method is like `_.assign` except that it accepts `customizer`
  11937. * which is invoked to produce the assigned values. If `customizer` returns
  11938. * `undefined`, assignment is handled by the method instead. The `customizer`
  11939. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11940. *
  11941. * **Note:** This method mutates `object`.
  11942. *
  11943. * @static
  11944. * @memberOf _
  11945. * @since 4.0.0
  11946. * @category Object
  11947. * @param {Object} object The destination object.
  11948. * @param {...Object} sources The source objects.
  11949. * @param {Function} [customizer] The function to customize assigned values.
  11950. * @returns {Object} Returns `object`.
  11951. * @see _.assignInWith
  11952. * @example
  11953. *
  11954. * function customizer(objValue, srcValue) {
  11955. * return _.isUndefined(objValue) ? srcValue : objValue;
  11956. * }
  11957. *
  11958. * var defaults = _.partialRight(_.assignWith, customizer);
  11959. *
  11960. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11961. * // => { 'a': 1, 'b': 2 }
  11962. */
  11963. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11964. copyObject(source, keys(source), object, customizer);
  11965. });
  11966. /**
  11967. * Creates an array of values corresponding to `paths` of `object`.
  11968. *
  11969. * @static
  11970. * @memberOf _
  11971. * @since 1.0.0
  11972. * @category Object
  11973. * @param {Object} object The object to iterate over.
  11974. * @param {...(string|string[])} [paths] The property paths to pick.
  11975. * @returns {Array} Returns the picked values.
  11976. * @example
  11977. *
  11978. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11979. *
  11980. * _.at(object, ['a[0].b.c', 'a[1]']);
  11981. * // => [3, 4]
  11982. */
  11983. var at = flatRest(baseAt);
  11984. /**
  11985. * Creates an object that inherits from the `prototype` object. If a
  11986. * `properties` object is given, its own enumerable string keyed properties
  11987. * are assigned to the created object.
  11988. *
  11989. * @static
  11990. * @memberOf _
  11991. * @since 2.3.0
  11992. * @category Object
  11993. * @param {Object} prototype The object to inherit from.
  11994. * @param {Object} [properties] The properties to assign to the object.
  11995. * @returns {Object} Returns the new object.
  11996. * @example
  11997. *
  11998. * function Shape() {
  11999. * this.x = 0;
  12000. * this.y = 0;
  12001. * }
  12002. *
  12003. * function Circle() {
  12004. * Shape.call(this);
  12005. * }
  12006. *
  12007. * Circle.prototype = _.create(Shape.prototype, {
  12008. * 'constructor': Circle
  12009. * });
  12010. *
  12011. * var circle = new Circle;
  12012. * circle instanceof Circle;
  12013. * // => true
  12014. *
  12015. * circle instanceof Shape;
  12016. * // => true
  12017. */
  12018. function create(prototype, properties) {
  12019. var result = baseCreate(prototype);
  12020. return properties == null ? result : baseAssign(result, properties);
  12021. }
  12022. /**
  12023. * Assigns own and inherited enumerable string keyed properties of source
  12024. * objects to the destination object for all destination properties that
  12025. * resolve to `undefined`. Source objects are applied from left to right.
  12026. * Once a property is set, additional values of the same property are ignored.
  12027. *
  12028. * **Note:** This method mutates `object`.
  12029. *
  12030. * @static
  12031. * @since 0.1.0
  12032. * @memberOf _
  12033. * @category Object
  12034. * @param {Object} object The destination object.
  12035. * @param {...Object} [sources] The source objects.
  12036. * @returns {Object} Returns `object`.
  12037. * @see _.defaultsDeep
  12038. * @example
  12039. *
  12040. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12041. * // => { 'a': 1, 'b': 2 }
  12042. */
  12043. var defaults = baseRest(function(object, sources) {
  12044. object = Object(object);
  12045. var index = -1;
  12046. var length = sources.length;
  12047. var guard = length > 2 ? sources[2] : undefined;
  12048. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  12049. length = 1;
  12050. }
  12051. while (++index < length) {
  12052. var source = sources[index];
  12053. var props = keysIn(source);
  12054. var propsIndex = -1;
  12055. var propsLength = props.length;
  12056. while (++propsIndex < propsLength) {
  12057. var key = props[propsIndex];
  12058. var value = object[key];
  12059. if (value === undefined ||
  12060. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  12061. object[key] = source[key];
  12062. }
  12063. }
  12064. }
  12065. return object;
  12066. });
  12067. /**
  12068. * This method is like `_.defaults` except that it recursively assigns
  12069. * default properties.
  12070. *
  12071. * **Note:** This method mutates `object`.
  12072. *
  12073. * @static
  12074. * @memberOf _
  12075. * @since 3.10.0
  12076. * @category Object
  12077. * @param {Object} object The destination object.
  12078. * @param {...Object} [sources] The source objects.
  12079. * @returns {Object} Returns `object`.
  12080. * @see _.defaults
  12081. * @example
  12082. *
  12083. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12084. * // => { 'a': { 'b': 2, 'c': 3 } }
  12085. */
  12086. var defaultsDeep = baseRest(function(args) {
  12087. args.push(undefined, customDefaultsMerge);
  12088. return apply(mergeWith, undefined, args);
  12089. });
  12090. /**
  12091. * This method is like `_.find` except that it returns the key of the first
  12092. * element `predicate` returns truthy for instead of the element itself.
  12093. *
  12094. * @static
  12095. * @memberOf _
  12096. * @since 1.1.0
  12097. * @category Object
  12098. * @param {Object} object The object to inspect.
  12099. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12100. * @returns {string|undefined} Returns the key of the matched element,
  12101. * else `undefined`.
  12102. * @example
  12103. *
  12104. * var users = {
  12105. * 'barney': { 'age': 36, 'active': true },
  12106. * 'fred': { 'age': 40, 'active': false },
  12107. * 'pebbles': { 'age': 1, 'active': true }
  12108. * };
  12109. *
  12110. * _.findKey(users, function(o) { return o.age < 40; });
  12111. * // => 'barney' (iteration order is not guaranteed)
  12112. *
  12113. * // The `_.matches` iteratee shorthand.
  12114. * _.findKey(users, { 'age': 1, 'active': true });
  12115. * // => 'pebbles'
  12116. *
  12117. * // The `_.matchesProperty` iteratee shorthand.
  12118. * _.findKey(users, ['active', false]);
  12119. * // => 'fred'
  12120. *
  12121. * // The `_.property` iteratee shorthand.
  12122. * _.findKey(users, 'active');
  12123. * // => 'barney'
  12124. */
  12125. function findKey(object, predicate) {
  12126. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12127. }
  12128. /**
  12129. * This method is like `_.findKey` except that it iterates over elements of
  12130. * a collection in the opposite order.
  12131. *
  12132. * @static
  12133. * @memberOf _
  12134. * @since 2.0.0
  12135. * @category Object
  12136. * @param {Object} object The object to inspect.
  12137. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12138. * @returns {string|undefined} Returns the key of the matched element,
  12139. * else `undefined`.
  12140. * @example
  12141. *
  12142. * var users = {
  12143. * 'barney': { 'age': 36, 'active': true },
  12144. * 'fred': { 'age': 40, 'active': false },
  12145. * 'pebbles': { 'age': 1, 'active': true }
  12146. * };
  12147. *
  12148. * _.findLastKey(users, function(o) { return o.age < 40; });
  12149. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12150. *
  12151. * // The `_.matches` iteratee shorthand.
  12152. * _.findLastKey(users, { 'age': 36, 'active': true });
  12153. * // => 'barney'
  12154. *
  12155. * // The `_.matchesProperty` iteratee shorthand.
  12156. * _.findLastKey(users, ['active', false]);
  12157. * // => 'fred'
  12158. *
  12159. * // The `_.property` iteratee shorthand.
  12160. * _.findLastKey(users, 'active');
  12161. * // => 'pebbles'
  12162. */
  12163. function findLastKey(object, predicate) {
  12164. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12165. }
  12166. /**
  12167. * Iterates over own and inherited enumerable string keyed properties of an
  12168. * object and invokes `iteratee` for each property. The iteratee is invoked
  12169. * with three arguments: (value, key, object). Iteratee functions may exit
  12170. * iteration early by explicitly returning `false`.
  12171. *
  12172. * @static
  12173. * @memberOf _
  12174. * @since 0.3.0
  12175. * @category Object
  12176. * @param {Object} object The object to iterate over.
  12177. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12178. * @returns {Object} Returns `object`.
  12179. * @see _.forInRight
  12180. * @example
  12181. *
  12182. * function Foo() {
  12183. * this.a = 1;
  12184. * this.b = 2;
  12185. * }
  12186. *
  12187. * Foo.prototype.c = 3;
  12188. *
  12189. * _.forIn(new Foo, function(value, key) {
  12190. * console.log(key);
  12191. * });
  12192. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12193. */
  12194. function forIn(object, iteratee) {
  12195. return object == null
  12196. ? object
  12197. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12198. }
  12199. /**
  12200. * This method is like `_.forIn` except that it iterates over properties of
  12201. * `object` in the opposite order.
  12202. *
  12203. * @static
  12204. * @memberOf _
  12205. * @since 2.0.0
  12206. * @category Object
  12207. * @param {Object} object The object to iterate over.
  12208. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12209. * @returns {Object} Returns `object`.
  12210. * @see _.forIn
  12211. * @example
  12212. *
  12213. * function Foo() {
  12214. * this.a = 1;
  12215. * this.b = 2;
  12216. * }
  12217. *
  12218. * Foo.prototype.c = 3;
  12219. *
  12220. * _.forInRight(new Foo, function(value, key) {
  12221. * console.log(key);
  12222. * });
  12223. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12224. */
  12225. function forInRight(object, iteratee) {
  12226. return object == null
  12227. ? object
  12228. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12229. }
  12230. /**
  12231. * Iterates over own enumerable string keyed properties of an object and
  12232. * invokes `iteratee` for each property. The iteratee is invoked with three
  12233. * arguments: (value, key, object). Iteratee functions may exit iteration
  12234. * early by explicitly returning `false`.
  12235. *
  12236. * @static
  12237. * @memberOf _
  12238. * @since 0.3.0
  12239. * @category Object
  12240. * @param {Object} object The object to iterate over.
  12241. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12242. * @returns {Object} Returns `object`.
  12243. * @see _.forOwnRight
  12244. * @example
  12245. *
  12246. * function Foo() {
  12247. * this.a = 1;
  12248. * this.b = 2;
  12249. * }
  12250. *
  12251. * Foo.prototype.c = 3;
  12252. *
  12253. * _.forOwn(new Foo, function(value, key) {
  12254. * console.log(key);
  12255. * });
  12256. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12257. */
  12258. function forOwn(object, iteratee) {
  12259. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12260. }
  12261. /**
  12262. * This method is like `_.forOwn` except that it iterates over properties of
  12263. * `object` in the opposite order.
  12264. *
  12265. * @static
  12266. * @memberOf _
  12267. * @since 2.0.0
  12268. * @category Object
  12269. * @param {Object} object The object to iterate over.
  12270. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12271. * @returns {Object} Returns `object`.
  12272. * @see _.forOwn
  12273. * @example
  12274. *
  12275. * function Foo() {
  12276. * this.a = 1;
  12277. * this.b = 2;
  12278. * }
  12279. *
  12280. * Foo.prototype.c = 3;
  12281. *
  12282. * _.forOwnRight(new Foo, function(value, key) {
  12283. * console.log(key);
  12284. * });
  12285. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12286. */
  12287. function forOwnRight(object, iteratee) {
  12288. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12289. }
  12290. /**
  12291. * Creates an array of function property names from own enumerable properties
  12292. * of `object`.
  12293. *
  12294. * @static
  12295. * @since 0.1.0
  12296. * @memberOf _
  12297. * @category Object
  12298. * @param {Object} object The object to inspect.
  12299. * @returns {Array} Returns the function names.
  12300. * @see _.functionsIn
  12301. * @example
  12302. *
  12303. * function Foo() {
  12304. * this.a = _.constant('a');
  12305. * this.b = _.constant('b');
  12306. * }
  12307. *
  12308. * Foo.prototype.c = _.constant('c');
  12309. *
  12310. * _.functions(new Foo);
  12311. * // => ['a', 'b']
  12312. */
  12313. function functions(object) {
  12314. return object == null ? [] : baseFunctions(object, keys(object));
  12315. }
  12316. /**
  12317. * Creates an array of function property names from own and inherited
  12318. * enumerable properties of `object`.
  12319. *
  12320. * @static
  12321. * @memberOf _
  12322. * @since 4.0.0
  12323. * @category Object
  12324. * @param {Object} object The object to inspect.
  12325. * @returns {Array} Returns the function names.
  12326. * @see _.functions
  12327. * @example
  12328. *
  12329. * function Foo() {
  12330. * this.a = _.constant('a');
  12331. * this.b = _.constant('b');
  12332. * }
  12333. *
  12334. * Foo.prototype.c = _.constant('c');
  12335. *
  12336. * _.functionsIn(new Foo);
  12337. * // => ['a', 'b', 'c']
  12338. */
  12339. function functionsIn(object) {
  12340. return object == null ? [] : baseFunctions(object, keysIn(object));
  12341. }
  12342. /**
  12343. * Gets the value at `path` of `object`. If the resolved value is
  12344. * `undefined`, the `defaultValue` is returned in its place.
  12345. *
  12346. * @static
  12347. * @memberOf _
  12348. * @since 3.7.0
  12349. * @category Object
  12350. * @param {Object} object The object to query.
  12351. * @param {Array|string} path The path of the property to get.
  12352. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12353. * @returns {*} Returns the resolved value.
  12354. * @example
  12355. *
  12356. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12357. *
  12358. * _.get(object, 'a[0].b.c');
  12359. * // => 3
  12360. *
  12361. * _.get(object, ['a', '0', 'b', 'c']);
  12362. * // => 3
  12363. *
  12364. * _.get(object, 'a.b.c', 'default');
  12365. * // => 'default'
  12366. */
  12367. function get(object, path, defaultValue) {
  12368. var result = object == null ? undefined : baseGet(object, path);
  12369. return result === undefined ? defaultValue : result;
  12370. }
  12371. /**
  12372. * Checks if `path` is a direct property of `object`.
  12373. *
  12374. * @static
  12375. * @since 0.1.0
  12376. * @memberOf _
  12377. * @category Object
  12378. * @param {Object} object The object to query.
  12379. * @param {Array|string} path The path to check.
  12380. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12381. * @example
  12382. *
  12383. * var object = { 'a': { 'b': 2 } };
  12384. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12385. *
  12386. * _.has(object, 'a');
  12387. * // => true
  12388. *
  12389. * _.has(object, 'a.b');
  12390. * // => true
  12391. *
  12392. * _.has(object, ['a', 'b']);
  12393. * // => true
  12394. *
  12395. * _.has(other, 'a');
  12396. * // => false
  12397. */
  12398. function has(object, path) {
  12399. return object != null && hasPath(object, path, baseHas);
  12400. }
  12401. /**
  12402. * Checks if `path` is a direct or inherited property of `object`.
  12403. *
  12404. * @static
  12405. * @memberOf _
  12406. * @since 4.0.0
  12407. * @category Object
  12408. * @param {Object} object The object to query.
  12409. * @param {Array|string} path The path to check.
  12410. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12411. * @example
  12412. *
  12413. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12414. *
  12415. * _.hasIn(object, 'a');
  12416. * // => true
  12417. *
  12418. * _.hasIn(object, 'a.b');
  12419. * // => true
  12420. *
  12421. * _.hasIn(object, ['a', 'b']);
  12422. * // => true
  12423. *
  12424. * _.hasIn(object, 'b');
  12425. * // => false
  12426. */
  12427. function hasIn(object, path) {
  12428. return object != null && hasPath(object, path, baseHasIn);
  12429. }
  12430. /**
  12431. * Creates an object composed of the inverted keys and values of `object`.
  12432. * If `object` contains duplicate values, subsequent values overwrite
  12433. * property assignments of previous values.
  12434. *
  12435. * @static
  12436. * @memberOf _
  12437. * @since 0.7.0
  12438. * @category Object
  12439. * @param {Object} object The object to invert.
  12440. * @returns {Object} Returns the new inverted object.
  12441. * @example
  12442. *
  12443. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12444. *
  12445. * _.invert(object);
  12446. * // => { '1': 'c', '2': 'b' }
  12447. */
  12448. var invert = createInverter(function(result, value, key) {
  12449. if (value != null &&
  12450. typeof value.toString != 'function') {
  12451. value = nativeObjectToString.call(value);
  12452. }
  12453. result[value] = key;
  12454. }, constant(identity));
  12455. /**
  12456. * This method is like `_.invert` except that the inverted object is generated
  12457. * from the results of running each element of `object` thru `iteratee`. The
  12458. * corresponding inverted value of each inverted key is an array of keys
  12459. * responsible for generating the inverted value. The iteratee is invoked
  12460. * with one argument: (value).
  12461. *
  12462. * @static
  12463. * @memberOf _
  12464. * @since 4.1.0
  12465. * @category Object
  12466. * @param {Object} object The object to invert.
  12467. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12468. * @returns {Object} Returns the new inverted object.
  12469. * @example
  12470. *
  12471. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12472. *
  12473. * _.invertBy(object);
  12474. * // => { '1': ['a', 'c'], '2': ['b'] }
  12475. *
  12476. * _.invertBy(object, function(value) {
  12477. * return 'group' + value;
  12478. * });
  12479. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12480. */
  12481. var invertBy = createInverter(function(result, value, key) {
  12482. if (value != null &&
  12483. typeof value.toString != 'function') {
  12484. value = nativeObjectToString.call(value);
  12485. }
  12486. if (hasOwnProperty.call(result, value)) {
  12487. result[value].push(key);
  12488. } else {
  12489. result[value] = [key];
  12490. }
  12491. }, getIteratee);
  12492. /**
  12493. * Invokes the method at `path` of `object`.
  12494. *
  12495. * @static
  12496. * @memberOf _
  12497. * @since 4.0.0
  12498. * @category Object
  12499. * @param {Object} object The object to query.
  12500. * @param {Array|string} path The path of the method to invoke.
  12501. * @param {...*} [args] The arguments to invoke the method with.
  12502. * @returns {*} Returns the result of the invoked method.
  12503. * @example
  12504. *
  12505. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12506. *
  12507. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12508. * // => [2, 3]
  12509. */
  12510. var invoke = baseRest(baseInvoke);
  12511. /**
  12512. * Creates an array of the own enumerable property names of `object`.
  12513. *
  12514. * **Note:** Non-object values are coerced to objects. See the
  12515. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12516. * for more details.
  12517. *
  12518. * @static
  12519. * @since 0.1.0
  12520. * @memberOf _
  12521. * @category Object
  12522. * @param {Object} object The object to query.
  12523. * @returns {Array} Returns the array of property names.
  12524. * @example
  12525. *
  12526. * function Foo() {
  12527. * this.a = 1;
  12528. * this.b = 2;
  12529. * }
  12530. *
  12531. * Foo.prototype.c = 3;
  12532. *
  12533. * _.keys(new Foo);
  12534. * // => ['a', 'b'] (iteration order is not guaranteed)
  12535. *
  12536. * _.keys('hi');
  12537. * // => ['0', '1']
  12538. */
  12539. function keys(object) {
  12540. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12541. }
  12542. /**
  12543. * Creates an array of the own and inherited enumerable property names of `object`.
  12544. *
  12545. * **Note:** Non-object values are coerced to objects.
  12546. *
  12547. * @static
  12548. * @memberOf _
  12549. * @since 3.0.0
  12550. * @category Object
  12551. * @param {Object} object The object to query.
  12552. * @returns {Array} Returns the array of property names.
  12553. * @example
  12554. *
  12555. * function Foo() {
  12556. * this.a = 1;
  12557. * this.b = 2;
  12558. * }
  12559. *
  12560. * Foo.prototype.c = 3;
  12561. *
  12562. * _.keysIn(new Foo);
  12563. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12564. */
  12565. function keysIn(object) {
  12566. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12567. }
  12568. /**
  12569. * The opposite of `_.mapValues`; this method creates an object with the
  12570. * same values as `object` and keys generated by running each own enumerable
  12571. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12572. * with three arguments: (value, key, object).
  12573. *
  12574. * @static
  12575. * @memberOf _
  12576. * @since 3.8.0
  12577. * @category Object
  12578. * @param {Object} object The object to iterate over.
  12579. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12580. * @returns {Object} Returns the new mapped object.
  12581. * @see _.mapValues
  12582. * @example
  12583. *
  12584. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12585. * return key + value;
  12586. * });
  12587. * // => { 'a1': 1, 'b2': 2 }
  12588. */
  12589. function mapKeys(object, iteratee) {
  12590. var result = {};
  12591. iteratee = getIteratee(iteratee, 3);
  12592. baseForOwn(object, function(value, key, object) {
  12593. baseAssignValue(result, iteratee(value, key, object), value);
  12594. });
  12595. return result;
  12596. }
  12597. /**
  12598. * Creates an object with the same keys as `object` and values generated
  12599. * by running each own enumerable string keyed property of `object` thru
  12600. * `iteratee`. The iteratee is invoked with three arguments:
  12601. * (value, key, object).
  12602. *
  12603. * @static
  12604. * @memberOf _
  12605. * @since 2.4.0
  12606. * @category Object
  12607. * @param {Object} object The object to iterate over.
  12608. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12609. * @returns {Object} Returns the new mapped object.
  12610. * @see _.mapKeys
  12611. * @example
  12612. *
  12613. * var users = {
  12614. * 'fred': { 'user': 'fred', 'age': 40 },
  12615. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12616. * };
  12617. *
  12618. * _.mapValues(users, function(o) { return o.age; });
  12619. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12620. *
  12621. * // The `_.property` iteratee shorthand.
  12622. * _.mapValues(users, 'age');
  12623. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12624. */
  12625. function mapValues(object, iteratee) {
  12626. var result = {};
  12627. iteratee = getIteratee(iteratee, 3);
  12628. baseForOwn(object, function(value, key, object) {
  12629. baseAssignValue(result, key, iteratee(value, key, object));
  12630. });
  12631. return result;
  12632. }
  12633. /**
  12634. * This method is like `_.assign` except that it recursively merges own and
  12635. * inherited enumerable string keyed properties of source objects into the
  12636. * destination object. Source properties that resolve to `undefined` are
  12637. * skipped if a destination value exists. Array and plain object properties
  12638. * are merged recursively. Other objects and value types are overridden by
  12639. * assignment. Source objects are applied from left to right. Subsequent
  12640. * sources overwrite property assignments of previous sources.
  12641. *
  12642. * **Note:** This method mutates `object`.
  12643. *
  12644. * @static
  12645. * @memberOf _
  12646. * @since 0.5.0
  12647. * @category Object
  12648. * @param {Object} object The destination object.
  12649. * @param {...Object} [sources] The source objects.
  12650. * @returns {Object} Returns `object`.
  12651. * @example
  12652. *
  12653. * var object = {
  12654. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12655. * };
  12656. *
  12657. * var other = {
  12658. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12659. * };
  12660. *
  12661. * _.merge(object, other);
  12662. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12663. */
  12664. var merge = createAssigner(function(object, source, srcIndex) {
  12665. baseMerge(object, source, srcIndex);
  12666. });
  12667. /**
  12668. * This method is like `_.merge` except that it accepts `customizer` which
  12669. * is invoked to produce the merged values of the destination and source
  12670. * properties. If `customizer` returns `undefined`, merging is handled by the
  12671. * method instead. The `customizer` is invoked with six arguments:
  12672. * (objValue, srcValue, key, object, source, stack).
  12673. *
  12674. * **Note:** This method mutates `object`.
  12675. *
  12676. * @static
  12677. * @memberOf _
  12678. * @since 4.0.0
  12679. * @category Object
  12680. * @param {Object} object The destination object.
  12681. * @param {...Object} sources The source objects.
  12682. * @param {Function} customizer The function to customize assigned values.
  12683. * @returns {Object} Returns `object`.
  12684. * @example
  12685. *
  12686. * function customizer(objValue, srcValue) {
  12687. * if (_.isArray(objValue)) {
  12688. * return objValue.concat(srcValue);
  12689. * }
  12690. * }
  12691. *
  12692. * var object = { 'a': [1], 'b': [2] };
  12693. * var other = { 'a': [3], 'b': [4] };
  12694. *
  12695. * _.mergeWith(object, other, customizer);
  12696. * // => { 'a': [1, 3], 'b': [2, 4] }
  12697. */
  12698. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12699. baseMerge(object, source, srcIndex, customizer);
  12700. });
  12701. /**
  12702. * The opposite of `_.pick`; this method creates an object composed of the
  12703. * own and inherited enumerable property paths of `object` that are not omitted.
  12704. *
  12705. * **Note:** This method is considerably slower than `_.pick`.
  12706. *
  12707. * @static
  12708. * @since 0.1.0
  12709. * @memberOf _
  12710. * @category Object
  12711. * @param {Object} object The source object.
  12712. * @param {...(string|string[])} [paths] The property paths to omit.
  12713. * @returns {Object} Returns the new object.
  12714. * @example
  12715. *
  12716. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12717. *
  12718. * _.omit(object, ['a', 'c']);
  12719. * // => { 'b': '2' }
  12720. */
  12721. var omit = flatRest(function(object, paths) {
  12722. var result = {};
  12723. if (object == null) {
  12724. return result;
  12725. }
  12726. var isDeep = false;
  12727. paths = arrayMap(paths, function(path) {
  12728. path = castPath(path, object);
  12729. isDeep || (isDeep = path.length > 1);
  12730. return path;
  12731. });
  12732. copyObject(object, getAllKeysIn(object), result);
  12733. if (isDeep) {
  12734. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12735. }
  12736. var length = paths.length;
  12737. while (length--) {
  12738. baseUnset(result, paths[length]);
  12739. }
  12740. return result;
  12741. });
  12742. /**
  12743. * The opposite of `_.pickBy`; this method creates an object composed of
  12744. * the own and inherited enumerable string keyed properties of `object` that
  12745. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12746. * arguments: (value, key).
  12747. *
  12748. * @static
  12749. * @memberOf _
  12750. * @since 4.0.0
  12751. * @category Object
  12752. * @param {Object} object The source object.
  12753. * @param {Function} [predicate=_.identity] The function invoked per property.
  12754. * @returns {Object} Returns the new object.
  12755. * @example
  12756. *
  12757. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12758. *
  12759. * _.omitBy(object, _.isNumber);
  12760. * // => { 'b': '2' }
  12761. */
  12762. function omitBy(object, predicate) {
  12763. return pickBy(object, negate(getIteratee(predicate)));
  12764. }
  12765. /**
  12766. * Creates an object composed of the picked `object` properties.
  12767. *
  12768. * @static
  12769. * @since 0.1.0
  12770. * @memberOf _
  12771. * @category Object
  12772. * @param {Object} object The source object.
  12773. * @param {...(string|string[])} [paths] The property paths to pick.
  12774. * @returns {Object} Returns the new object.
  12775. * @example
  12776. *
  12777. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12778. *
  12779. * _.pick(object, ['a', 'c']);
  12780. * // => { 'a': 1, 'c': 3 }
  12781. */
  12782. var pick = flatRest(function(object, paths) {
  12783. return object == null ? {} : basePick(object, paths);
  12784. });
  12785. /**
  12786. * Creates an object composed of the `object` properties `predicate` returns
  12787. * truthy for. The predicate is invoked with two arguments: (value, key).
  12788. *
  12789. * @static
  12790. * @memberOf _
  12791. * @since 4.0.0
  12792. * @category Object
  12793. * @param {Object} object The source object.
  12794. * @param {Function} [predicate=_.identity] The function invoked per property.
  12795. * @returns {Object} Returns the new object.
  12796. * @example
  12797. *
  12798. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12799. *
  12800. * _.pickBy(object, _.isNumber);
  12801. * // => { 'a': 1, 'c': 3 }
  12802. */
  12803. function pickBy(object, predicate) {
  12804. if (object == null) {
  12805. return {};
  12806. }
  12807. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12808. return [prop];
  12809. });
  12810. predicate = getIteratee(predicate);
  12811. return basePickBy(object, props, function(value, path) {
  12812. return predicate(value, path[0]);
  12813. });
  12814. }
  12815. /**
  12816. * This method is like `_.get` except that if the resolved value is a
  12817. * function it's invoked with the `this` binding of its parent object and
  12818. * its result is returned.
  12819. *
  12820. * @static
  12821. * @since 0.1.0
  12822. * @memberOf _
  12823. * @category Object
  12824. * @param {Object} object The object to query.
  12825. * @param {Array|string} path The path of the property to resolve.
  12826. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12827. * @returns {*} Returns the resolved value.
  12828. * @example
  12829. *
  12830. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12831. *
  12832. * _.result(object, 'a[0].b.c1');
  12833. * // => 3
  12834. *
  12835. * _.result(object, 'a[0].b.c2');
  12836. * // => 4
  12837. *
  12838. * _.result(object, 'a[0].b.c3', 'default');
  12839. * // => 'default'
  12840. *
  12841. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12842. * // => 'default'
  12843. */
  12844. function result(object, path, defaultValue) {
  12845. path = castPath(path, object);
  12846. var index = -1,
  12847. length = path.length;
  12848. // Ensure the loop is entered when path is empty.
  12849. if (!length) {
  12850. length = 1;
  12851. object = undefined;
  12852. }
  12853. while (++index < length) {
  12854. var value = object == null ? undefined : object[toKey(path[index])];
  12855. if (value === undefined) {
  12856. index = length;
  12857. value = defaultValue;
  12858. }
  12859. object = isFunction(value) ? value.call(object) : value;
  12860. }
  12861. return object;
  12862. }
  12863. /**
  12864. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12865. * it's created. Arrays are created for missing index properties while objects
  12866. * are created for all other missing properties. Use `_.setWith` to customize
  12867. * `path` creation.
  12868. *
  12869. * **Note:** This method mutates `object`.
  12870. *
  12871. * @static
  12872. * @memberOf _
  12873. * @since 3.7.0
  12874. * @category Object
  12875. * @param {Object} object The object to modify.
  12876. * @param {Array|string} path The path of the property to set.
  12877. * @param {*} value The value to set.
  12878. * @returns {Object} Returns `object`.
  12879. * @example
  12880. *
  12881. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12882. *
  12883. * _.set(object, 'a[0].b.c', 4);
  12884. * console.log(object.a[0].b.c);
  12885. * // => 4
  12886. *
  12887. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12888. * console.log(object.x[0].y.z);
  12889. * // => 5
  12890. */
  12891. function set(object, path, value) {
  12892. return object == null ? object : baseSet(object, path, value);
  12893. }
  12894. /**
  12895. * This method is like `_.set` except that it accepts `customizer` which is
  12896. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12897. * path creation is handled by the method instead. The `customizer` is invoked
  12898. * with three arguments: (nsValue, key, nsObject).
  12899. *
  12900. * **Note:** This method mutates `object`.
  12901. *
  12902. * @static
  12903. * @memberOf _
  12904. * @since 4.0.0
  12905. * @category Object
  12906. * @param {Object} object The object to modify.
  12907. * @param {Array|string} path The path of the property to set.
  12908. * @param {*} value The value to set.
  12909. * @param {Function} [customizer] The function to customize assigned values.
  12910. * @returns {Object} Returns `object`.
  12911. * @example
  12912. *
  12913. * var object = {};
  12914. *
  12915. * _.setWith(object, '[0][1]', 'a', Object);
  12916. * // => { '0': { '1': 'a' } }
  12917. */
  12918. function setWith(object, path, value, customizer) {
  12919. customizer = typeof customizer == 'function' ? customizer : undefined;
  12920. return object == null ? object : baseSet(object, path, value, customizer);
  12921. }
  12922. /**
  12923. * Creates an array of own enumerable string keyed-value pairs for `object`
  12924. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12925. * entries are returned.
  12926. *
  12927. * @static
  12928. * @memberOf _
  12929. * @since 4.0.0
  12930. * @alias entries
  12931. * @category Object
  12932. * @param {Object} object The object to query.
  12933. * @returns {Array} Returns the key-value pairs.
  12934. * @example
  12935. *
  12936. * function Foo() {
  12937. * this.a = 1;
  12938. * this.b = 2;
  12939. * }
  12940. *
  12941. * Foo.prototype.c = 3;
  12942. *
  12943. * _.toPairs(new Foo);
  12944. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12945. */
  12946. var toPairs = createToPairs(keys);
  12947. /**
  12948. * Creates an array of own and inherited enumerable string keyed-value pairs
  12949. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12950. * or set, its entries are returned.
  12951. *
  12952. * @static
  12953. * @memberOf _
  12954. * @since 4.0.0
  12955. * @alias entriesIn
  12956. * @category Object
  12957. * @param {Object} object The object to query.
  12958. * @returns {Array} Returns the key-value pairs.
  12959. * @example
  12960. *
  12961. * function Foo() {
  12962. * this.a = 1;
  12963. * this.b = 2;
  12964. * }
  12965. *
  12966. * Foo.prototype.c = 3;
  12967. *
  12968. * _.toPairsIn(new Foo);
  12969. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12970. */
  12971. var toPairsIn = createToPairs(keysIn);
  12972. /**
  12973. * An alternative to `_.reduce`; this method transforms `object` to a new
  12974. * `accumulator` object which is the result of running each of its own
  12975. * enumerable string keyed properties thru `iteratee`, with each invocation
  12976. * potentially mutating the `accumulator` object. If `accumulator` is not
  12977. * provided, a new object with the same `[[Prototype]]` will be used. The
  12978. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12979. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12980. *
  12981. * @static
  12982. * @memberOf _
  12983. * @since 1.3.0
  12984. * @category Object
  12985. * @param {Object} object The object to iterate over.
  12986. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12987. * @param {*} [accumulator] The custom accumulator value.
  12988. * @returns {*} Returns the accumulated value.
  12989. * @example
  12990. *
  12991. * _.transform([2, 3, 4], function(result, n) {
  12992. * result.push(n *= n);
  12993. * return n % 2 == 0;
  12994. * }, []);
  12995. * // => [4, 9]
  12996. *
  12997. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12998. * (result[value] || (result[value] = [])).push(key);
  12999. * }, {});
  13000. * // => { '1': ['a', 'c'], '2': ['b'] }
  13001. */
  13002. function transform(object, iteratee, accumulator) {
  13003. var isArr = isArray(object),
  13004. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  13005. iteratee = getIteratee(iteratee, 4);
  13006. if (accumulator == null) {
  13007. var Ctor = object && object.constructor;
  13008. if (isArrLike) {
  13009. accumulator = isArr ? new Ctor : [];
  13010. }
  13011. else if (isObject(object)) {
  13012. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  13013. }
  13014. else {
  13015. accumulator = {};
  13016. }
  13017. }
  13018. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  13019. return iteratee(accumulator, value, index, object);
  13020. });
  13021. return accumulator;
  13022. }
  13023. /**
  13024. * Removes the property at `path` of `object`.
  13025. *
  13026. * **Note:** This method mutates `object`.
  13027. *
  13028. * @static
  13029. * @memberOf _
  13030. * @since 4.0.0
  13031. * @category Object
  13032. * @param {Object} object The object to modify.
  13033. * @param {Array|string} path The path of the property to unset.
  13034. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13035. * @example
  13036. *
  13037. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13038. * _.unset(object, 'a[0].b.c');
  13039. * // => true
  13040. *
  13041. * console.log(object);
  13042. * // => { 'a': [{ 'b': {} }] };
  13043. *
  13044. * _.unset(object, ['a', '0', 'b', 'c']);
  13045. * // => true
  13046. *
  13047. * console.log(object);
  13048. * // => { 'a': [{ 'b': {} }] };
  13049. */
  13050. function unset(object, path) {
  13051. return object == null ? true : baseUnset(object, path);
  13052. }
  13053. /**
  13054. * This method is like `_.set` except that accepts `updater` to produce the
  13055. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13056. * is invoked with one argument: (value).
  13057. *
  13058. * **Note:** This method mutates `object`.
  13059. *
  13060. * @static
  13061. * @memberOf _
  13062. * @since 4.6.0
  13063. * @category Object
  13064. * @param {Object} object The object to modify.
  13065. * @param {Array|string} path The path of the property to set.
  13066. * @param {Function} updater The function to produce the updated value.
  13067. * @returns {Object} Returns `object`.
  13068. * @example
  13069. *
  13070. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13071. *
  13072. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13073. * console.log(object.a[0].b.c);
  13074. * // => 9
  13075. *
  13076. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13077. * console.log(object.x[0].y.z);
  13078. * // => 0
  13079. */
  13080. function update(object, path, updater) {
  13081. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13082. }
  13083. /**
  13084. * This method is like `_.update` except that it accepts `customizer` which is
  13085. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13086. * path creation is handled by the method instead. The `customizer` is invoked
  13087. * with three arguments: (nsValue, key, nsObject).
  13088. *
  13089. * **Note:** This method mutates `object`.
  13090. *
  13091. * @static
  13092. * @memberOf _
  13093. * @since 4.6.0
  13094. * @category Object
  13095. * @param {Object} object The object to modify.
  13096. * @param {Array|string} path The path of the property to set.
  13097. * @param {Function} updater The function to produce the updated value.
  13098. * @param {Function} [customizer] The function to customize assigned values.
  13099. * @returns {Object} Returns `object`.
  13100. * @example
  13101. *
  13102. * var object = {};
  13103. *
  13104. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13105. * // => { '0': { '1': 'a' } }
  13106. */
  13107. function updateWith(object, path, updater, customizer) {
  13108. customizer = typeof customizer == 'function' ? customizer : undefined;
  13109. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13110. }
  13111. /**
  13112. * Creates an array of the own enumerable string keyed property values of `object`.
  13113. *
  13114. * **Note:** Non-object values are coerced to objects.
  13115. *
  13116. * @static
  13117. * @since 0.1.0
  13118. * @memberOf _
  13119. * @category Object
  13120. * @param {Object} object The object to query.
  13121. * @returns {Array} Returns the array of property values.
  13122. * @example
  13123. *
  13124. * function Foo() {
  13125. * this.a = 1;
  13126. * this.b = 2;
  13127. * }
  13128. *
  13129. * Foo.prototype.c = 3;
  13130. *
  13131. * _.values(new Foo);
  13132. * // => [1, 2] (iteration order is not guaranteed)
  13133. *
  13134. * _.values('hi');
  13135. * // => ['h', 'i']
  13136. */
  13137. function values(object) {
  13138. return object == null ? [] : baseValues(object, keys(object));
  13139. }
  13140. /**
  13141. * Creates an array of the own and inherited enumerable string keyed property
  13142. * values of `object`.
  13143. *
  13144. * **Note:** Non-object values are coerced to objects.
  13145. *
  13146. * @static
  13147. * @memberOf _
  13148. * @since 3.0.0
  13149. * @category Object
  13150. * @param {Object} object The object to query.
  13151. * @returns {Array} Returns the array of property values.
  13152. * @example
  13153. *
  13154. * function Foo() {
  13155. * this.a = 1;
  13156. * this.b = 2;
  13157. * }
  13158. *
  13159. * Foo.prototype.c = 3;
  13160. *
  13161. * _.valuesIn(new Foo);
  13162. * // => [1, 2, 3] (iteration order is not guaranteed)
  13163. */
  13164. function valuesIn(object) {
  13165. return object == null ? [] : baseValues(object, keysIn(object));
  13166. }
  13167. /*------------------------------------------------------------------------*/
  13168. /**
  13169. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13170. *
  13171. * @static
  13172. * @memberOf _
  13173. * @since 4.0.0
  13174. * @category Number
  13175. * @param {number} number The number to clamp.
  13176. * @param {number} [lower] The lower bound.
  13177. * @param {number} upper The upper bound.
  13178. * @returns {number} Returns the clamped number.
  13179. * @example
  13180. *
  13181. * _.clamp(-10, -5, 5);
  13182. * // => -5
  13183. *
  13184. * _.clamp(10, -5, 5);
  13185. * // => 5
  13186. */
  13187. function clamp(number, lower, upper) {
  13188. if (upper === undefined) {
  13189. upper = lower;
  13190. lower = undefined;
  13191. }
  13192. if (upper !== undefined) {
  13193. upper = toNumber(upper);
  13194. upper = upper === upper ? upper : 0;
  13195. }
  13196. if (lower !== undefined) {
  13197. lower = toNumber(lower);
  13198. lower = lower === lower ? lower : 0;
  13199. }
  13200. return baseClamp(toNumber(number), lower, upper);
  13201. }
  13202. /**
  13203. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13204. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13205. * If `start` is greater than `end` the params are swapped to support
  13206. * negative ranges.
  13207. *
  13208. * @static
  13209. * @memberOf _
  13210. * @since 3.3.0
  13211. * @category Number
  13212. * @param {number} number The number to check.
  13213. * @param {number} [start=0] The start of the range.
  13214. * @param {number} end The end of the range.
  13215. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13216. * @see _.range, _.rangeRight
  13217. * @example
  13218. *
  13219. * _.inRange(3, 2, 4);
  13220. * // => true
  13221. *
  13222. * _.inRange(4, 8);
  13223. * // => true
  13224. *
  13225. * _.inRange(4, 2);
  13226. * // => false
  13227. *
  13228. * _.inRange(2, 2);
  13229. * // => false
  13230. *
  13231. * _.inRange(1.2, 2);
  13232. * // => true
  13233. *
  13234. * _.inRange(5.2, 4);
  13235. * // => false
  13236. *
  13237. * _.inRange(-3, -2, -6);
  13238. * // => true
  13239. */
  13240. function inRange(number, start, end) {
  13241. start = toFinite(start);
  13242. if (end === undefined) {
  13243. end = start;
  13244. start = 0;
  13245. } else {
  13246. end = toFinite(end);
  13247. }
  13248. number = toNumber(number);
  13249. return baseInRange(number, start, end);
  13250. }
  13251. /**
  13252. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13253. * If only one argument is provided a number between `0` and the given number
  13254. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13255. * floats, a floating-point number is returned instead of an integer.
  13256. *
  13257. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13258. * floating-point values which can produce unexpected results.
  13259. *
  13260. * **Note:** If `lower` is greater than `upper`, the values are swapped.
  13261. *
  13262. * @static
  13263. * @memberOf _
  13264. * @since 0.7.0
  13265. * @category Number
  13266. * @param {number} [lower=0] The lower bound.
  13267. * @param {number} [upper=1] The upper bound.
  13268. * @param {boolean} [floating] Specify returning a floating-point number.
  13269. * @returns {number} Returns the random number.
  13270. * @example
  13271. *
  13272. * _.random(0, 5);
  13273. * // => an integer between 0 and 5
  13274. *
  13275. * // when lower is greater than upper the values are swapped
  13276. * _.random(5, 0);
  13277. * // => an integer between 0 and 5
  13278. *
  13279. * _.random(5);
  13280. * // => also an integer between 0 and 5
  13281. *
  13282. * _.random(-5);
  13283. * // => an integer between -5 and 0
  13284. *
  13285. * _.random(5, true);
  13286. * // => a floating-point number between 0 and 5
  13287. *
  13288. * _.random(1.2, 5.2);
  13289. * // => a floating-point number between 1.2 and 5.2
  13290. */
  13291. function random(lower, upper, floating) {
  13292. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13293. upper = floating = undefined;
  13294. }
  13295. if (floating === undefined) {
  13296. if (typeof upper == 'boolean') {
  13297. floating = upper;
  13298. upper = undefined;
  13299. }
  13300. else if (typeof lower == 'boolean') {
  13301. floating = lower;
  13302. lower = undefined;
  13303. }
  13304. }
  13305. if (lower === undefined && upper === undefined) {
  13306. lower = 0;
  13307. upper = 1;
  13308. }
  13309. else {
  13310. lower = toFinite(lower);
  13311. if (upper === undefined) {
  13312. upper = lower;
  13313. lower = 0;
  13314. } else {
  13315. upper = toFinite(upper);
  13316. }
  13317. }
  13318. if (lower > upper) {
  13319. var temp = lower;
  13320. lower = upper;
  13321. upper = temp;
  13322. }
  13323. if (floating || lower % 1 || upper % 1) {
  13324. var rand = nativeRandom();
  13325. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13326. }
  13327. return baseRandom(lower, upper);
  13328. }
  13329. /*------------------------------------------------------------------------*/
  13330. /**
  13331. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13332. *
  13333. * @static
  13334. * @memberOf _
  13335. * @since 3.0.0
  13336. * @category String
  13337. * @param {string} [string=''] The string to convert.
  13338. * @returns {string} Returns the camel cased string.
  13339. * @example
  13340. *
  13341. * _.camelCase('Foo Bar');
  13342. * // => 'fooBar'
  13343. *
  13344. * _.camelCase('--foo-bar--');
  13345. * // => 'fooBar'
  13346. *
  13347. * _.camelCase('__FOO_BAR__');
  13348. * // => 'fooBar'
  13349. */
  13350. var camelCase = createCompounder(function(result, word, index) {
  13351. word = word.toLowerCase();
  13352. return result + (index ? capitalize(word) : word);
  13353. });
  13354. /**
  13355. * Converts the first character of `string` to upper case and the remaining
  13356. * to lower case.
  13357. *
  13358. * @static
  13359. * @memberOf _
  13360. * @since 3.0.0
  13361. * @category String
  13362. * @param {string} [string=''] The string to capitalize.
  13363. * @returns {string} Returns the capitalized string.
  13364. * @example
  13365. *
  13366. * _.capitalize('FRED');
  13367. * // => 'Fred'
  13368. */
  13369. function capitalize(string) {
  13370. return upperFirst(toString(string).toLowerCase());
  13371. }
  13372. /**
  13373. * Deburrs `string` by converting
  13374. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13375. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13376. * letters to basic Latin letters and removing
  13377. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13378. *
  13379. * @static
  13380. * @memberOf _
  13381. * @since 3.0.0
  13382. * @category String
  13383. * @param {string} [string=''] The string to deburr.
  13384. * @returns {string} Returns the deburred string.
  13385. * @example
  13386. *
  13387. * _.deburr('déjà vu');
  13388. * // => 'deja vu'
  13389. */
  13390. function deburr(string) {
  13391. string = toString(string);
  13392. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13393. }
  13394. /**
  13395. * Checks if `string` ends with the given target string.
  13396. *
  13397. * @static
  13398. * @memberOf _
  13399. * @since 3.0.0
  13400. * @category String
  13401. * @param {string} [string=''] The string to inspect.
  13402. * @param {string} [target] The string to search for.
  13403. * @param {number} [position=string.length] The position to search up to.
  13404. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13405. * else `false`.
  13406. * @example
  13407. *
  13408. * _.endsWith('abc', 'c');
  13409. * // => true
  13410. *
  13411. * _.endsWith('abc', 'b');
  13412. * // => false
  13413. *
  13414. * _.endsWith('abc', 'b', 2);
  13415. * // => true
  13416. */
  13417. function endsWith(string, target, position) {
  13418. string = toString(string);
  13419. target = baseToString(target);
  13420. var length = string.length;
  13421. position = position === undefined
  13422. ? length
  13423. : baseClamp(toInteger(position), 0, length);
  13424. var end = position;
  13425. position -= target.length;
  13426. return position >= 0 && string.slice(position, end) == target;
  13427. }
  13428. /**
  13429. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13430. * corresponding HTML entities.
  13431. *
  13432. * **Note:** No other characters are escaped. To escape additional
  13433. * characters use a third-party library like [_he_](https://mths.be/he).
  13434. *
  13435. * Though the ">" character is escaped for symmetry, characters like
  13436. * ">" and "/" don't need escaping in HTML and have no special meaning
  13437. * unless they're part of a tag or unquoted attribute value. See
  13438. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13439. * (under "semi-related fun fact") for more details.
  13440. *
  13441. * When working with HTML you should always
  13442. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13443. * XSS vectors.
  13444. *
  13445. * @static
  13446. * @since 0.1.0
  13447. * @memberOf _
  13448. * @category String
  13449. * @param {string} [string=''] The string to escape.
  13450. * @returns {string} Returns the escaped string.
  13451. * @example
  13452. *
  13453. * _.escape('fred, barney, & pebbles');
  13454. * // => 'fred, barney, &amp; pebbles'
  13455. */
  13456. function escape(string) {
  13457. string = toString(string);
  13458. return (string && reHasUnescapedHtml.test(string))
  13459. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13460. : string;
  13461. }
  13462. /**
  13463. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13464. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13465. *
  13466. * @static
  13467. * @memberOf _
  13468. * @since 3.0.0
  13469. * @category String
  13470. * @param {string} [string=''] The string to escape.
  13471. * @returns {string} Returns the escaped string.
  13472. * @example
  13473. *
  13474. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13475. * // => '\[lodash\]\(https://lodash\.com/\)'
  13476. */
  13477. function escapeRegExp(string) {
  13478. string = toString(string);
  13479. return (string && reHasRegExpChar.test(string))
  13480. ? string.replace(reRegExpChar, '\\$&')
  13481. : string;
  13482. }
  13483. /**
  13484. * Converts `string` to
  13485. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13486. *
  13487. * @static
  13488. * @memberOf _
  13489. * @since 3.0.0
  13490. * @category String
  13491. * @param {string} [string=''] The string to convert.
  13492. * @returns {string} Returns the kebab cased string.
  13493. * @example
  13494. *
  13495. * _.kebabCase('Foo Bar');
  13496. * // => 'foo-bar'
  13497. *
  13498. * _.kebabCase('fooBar');
  13499. * // => 'foo-bar'
  13500. *
  13501. * _.kebabCase('__FOO_BAR__');
  13502. * // => 'foo-bar'
  13503. */
  13504. var kebabCase = createCompounder(function(result, word, index) {
  13505. return result + (index ? '-' : '') + word.toLowerCase();
  13506. });
  13507. /**
  13508. * Converts `string`, as space separated words, to lower case.
  13509. *
  13510. * @static
  13511. * @memberOf _
  13512. * @since 4.0.0
  13513. * @category String
  13514. * @param {string} [string=''] The string to convert.
  13515. * @returns {string} Returns the lower cased string.
  13516. * @example
  13517. *
  13518. * _.lowerCase('--Foo-Bar--');
  13519. * // => 'foo bar'
  13520. *
  13521. * _.lowerCase('fooBar');
  13522. * // => 'foo bar'
  13523. *
  13524. * _.lowerCase('__FOO_BAR__');
  13525. * // => 'foo bar'
  13526. */
  13527. var lowerCase = createCompounder(function(result, word, index) {
  13528. return result + (index ? ' ' : '') + word.toLowerCase();
  13529. });
  13530. /**
  13531. * Converts the first character of `string` to lower case.
  13532. *
  13533. * @static
  13534. * @memberOf _
  13535. * @since 4.0.0
  13536. * @category String
  13537. * @param {string} [string=''] The string to convert.
  13538. * @returns {string} Returns the converted string.
  13539. * @example
  13540. *
  13541. * _.lowerFirst('Fred');
  13542. * // => 'fred'
  13543. *
  13544. * _.lowerFirst('FRED');
  13545. * // => 'fRED'
  13546. */
  13547. var lowerFirst = createCaseFirst('toLowerCase');
  13548. /**
  13549. * Pads `string` on the left and right sides if it's shorter than `length`.
  13550. * Padding characters are truncated if they can't be evenly divided by `length`.
  13551. *
  13552. * @static
  13553. * @memberOf _
  13554. * @since 3.0.0
  13555. * @category String
  13556. * @param {string} [string=''] The string to pad.
  13557. * @param {number} [length=0] The padding length.
  13558. * @param {string} [chars=' '] The string used as padding.
  13559. * @returns {string} Returns the padded string.
  13560. * @example
  13561. *
  13562. * _.pad('abc', 8);
  13563. * // => ' abc '
  13564. *
  13565. * _.pad('abc', 8, '_-');
  13566. * // => '_-abc_-_'
  13567. *
  13568. * _.pad('abc', 3);
  13569. * // => 'abc'
  13570. */
  13571. function pad(string, length, chars) {
  13572. string = toString(string);
  13573. length = toInteger(length);
  13574. var strLength = length ? stringSize(string) : 0;
  13575. if (!length || strLength >= length) {
  13576. return string;
  13577. }
  13578. var mid = (length - strLength) / 2;
  13579. return (
  13580. createPadding(nativeFloor(mid), chars) +
  13581. string +
  13582. createPadding(nativeCeil(mid), chars)
  13583. );
  13584. }
  13585. /**
  13586. * Pads `string` on the right side if it's shorter than `length`. Padding
  13587. * characters are truncated if they exceed `length`.
  13588. *
  13589. * @static
  13590. * @memberOf _
  13591. * @since 4.0.0
  13592. * @category String
  13593. * @param {string} [string=''] The string to pad.
  13594. * @param {number} [length=0] The padding length.
  13595. * @param {string} [chars=' '] The string used as padding.
  13596. * @returns {string} Returns the padded string.
  13597. * @example
  13598. *
  13599. * _.padEnd('abc', 6);
  13600. * // => 'abc '
  13601. *
  13602. * _.padEnd('abc', 6, '_-');
  13603. * // => 'abc_-_'
  13604. *
  13605. * _.padEnd('abc', 3);
  13606. * // => 'abc'
  13607. */
  13608. function padEnd(string, length, chars) {
  13609. string = toString(string);
  13610. length = toInteger(length);
  13611. var strLength = length ? stringSize(string) : 0;
  13612. return (length && strLength < length)
  13613. ? (string + createPadding(length - strLength, chars))
  13614. : string;
  13615. }
  13616. /**
  13617. * Pads `string` on the left side if it's shorter than `length`. Padding
  13618. * characters are truncated if they exceed `length`.
  13619. *
  13620. * @static
  13621. * @memberOf _
  13622. * @since 4.0.0
  13623. * @category String
  13624. * @param {string} [string=''] The string to pad.
  13625. * @param {number} [length=0] The padding length.
  13626. * @param {string} [chars=' '] The string used as padding.
  13627. * @returns {string} Returns the padded string.
  13628. * @example
  13629. *
  13630. * _.padStart('abc', 6);
  13631. * // => ' abc'
  13632. *
  13633. * _.padStart('abc', 6, '_-');
  13634. * // => '_-_abc'
  13635. *
  13636. * _.padStart('abc', 3);
  13637. * // => 'abc'
  13638. */
  13639. function padStart(string, length, chars) {
  13640. string = toString(string);
  13641. length = toInteger(length);
  13642. var strLength = length ? stringSize(string) : 0;
  13643. return (length && strLength < length)
  13644. ? (createPadding(length - strLength, chars) + string)
  13645. : string;
  13646. }
  13647. /**
  13648. * Converts `string` to an integer of the specified radix. If `radix` is
  13649. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13650. * hexadecimal, in which case a `radix` of `16` is used.
  13651. *
  13652. * **Note:** This method aligns with the
  13653. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13654. *
  13655. * @static
  13656. * @memberOf _
  13657. * @since 1.1.0
  13658. * @category String
  13659. * @param {string} string The string to convert.
  13660. * @param {number} [radix=10] The radix to interpret `value` by.
  13661. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13662. * @returns {number} Returns the converted integer.
  13663. * @example
  13664. *
  13665. * _.parseInt('08');
  13666. * // => 8
  13667. *
  13668. * _.map(['6', '08', '10'], _.parseInt);
  13669. * // => [6, 8, 10]
  13670. */
  13671. function parseInt(string, radix, guard) {
  13672. if (guard || radix == null) {
  13673. radix = 0;
  13674. } else if (radix) {
  13675. radix = +radix;
  13676. }
  13677. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13678. }
  13679. /**
  13680. * Repeats the given string `n` times.
  13681. *
  13682. * @static
  13683. * @memberOf _
  13684. * @since 3.0.0
  13685. * @category String
  13686. * @param {string} [string=''] The string to repeat.
  13687. * @param {number} [n=1] The number of times to repeat the string.
  13688. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13689. * @returns {string} Returns the repeated string.
  13690. * @example
  13691. *
  13692. * _.repeat('*', 3);
  13693. * // => '***'
  13694. *
  13695. * _.repeat('abc', 2);
  13696. * // => 'abcabc'
  13697. *
  13698. * _.repeat('abc', 0);
  13699. * // => ''
  13700. */
  13701. function repeat(string, n, guard) {
  13702. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13703. n = 1;
  13704. } else {
  13705. n = toInteger(n);
  13706. }
  13707. return baseRepeat(toString(string), n);
  13708. }
  13709. /**
  13710. * Replaces matches for `pattern` in `string` with `replacement`.
  13711. *
  13712. * **Note:** This method is based on
  13713. * [`String#replace`](https://mdn.io/String/replace).
  13714. *
  13715. * @static
  13716. * @memberOf _
  13717. * @since 4.0.0
  13718. * @category String
  13719. * @param {string} [string=''] The string to modify.
  13720. * @param {RegExp|string} pattern The pattern to replace.
  13721. * @param {Function|string} replacement The match replacement.
  13722. * @returns {string} Returns the modified string.
  13723. * @example
  13724. *
  13725. * _.replace('Hi Fred', 'Fred', 'Barney');
  13726. * // => 'Hi Barney'
  13727. */
  13728. function replace() {
  13729. var args = arguments,
  13730. string = toString(args[0]);
  13731. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13732. }
  13733. /**
  13734. * Converts `string` to
  13735. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13736. *
  13737. * @static
  13738. * @memberOf _
  13739. * @since 3.0.0
  13740. * @category String
  13741. * @param {string} [string=''] The string to convert.
  13742. * @returns {string} Returns the snake cased string.
  13743. * @example
  13744. *
  13745. * _.snakeCase('Foo Bar');
  13746. * // => 'foo_bar'
  13747. *
  13748. * _.snakeCase('fooBar');
  13749. * // => 'foo_bar'
  13750. *
  13751. * _.snakeCase('--FOO-BAR--');
  13752. * // => 'foo_bar'
  13753. */
  13754. var snakeCase = createCompounder(function(result, word, index) {
  13755. return result + (index ? '_' : '') + word.toLowerCase();
  13756. });
  13757. /**
  13758. * Splits `string` by `separator`.
  13759. *
  13760. * **Note:** This method is based on
  13761. * [`String#split`](https://mdn.io/String/split).
  13762. *
  13763. * @static
  13764. * @memberOf _
  13765. * @since 4.0.0
  13766. * @category String
  13767. * @param {string} [string=''] The string to split.
  13768. * @param {RegExp|string} separator The separator pattern to split by.
  13769. * @param {number} [limit] The length to truncate results to.
  13770. * @returns {Array} Returns the string segments.
  13771. * @example
  13772. *
  13773. * _.split('a-b-c', '-', 2);
  13774. * // => ['a', 'b']
  13775. */
  13776. function split(string, separator, limit) {
  13777. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13778. separator = limit = undefined;
  13779. }
  13780. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13781. if (!limit) {
  13782. return [];
  13783. }
  13784. string = toString(string);
  13785. if (string && (
  13786. typeof separator == 'string' ||
  13787. (separator != null && !isRegExp(separator))
  13788. )) {
  13789. separator = baseToString(separator);
  13790. if (!separator && hasUnicode(string)) {
  13791. return castSlice(stringToArray(string), 0, limit);
  13792. }
  13793. }
  13794. return string.split(separator, limit);
  13795. }
  13796. /**
  13797. * Converts `string` to
  13798. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13799. *
  13800. * @static
  13801. * @memberOf _
  13802. * @since 3.1.0
  13803. * @category String
  13804. * @param {string} [string=''] The string to convert.
  13805. * @returns {string} Returns the start cased string.
  13806. * @example
  13807. *
  13808. * _.startCase('--foo-bar--');
  13809. * // => 'Foo Bar'
  13810. *
  13811. * _.startCase('fooBar');
  13812. * // => 'Foo Bar'
  13813. *
  13814. * _.startCase('__FOO_BAR__');
  13815. * // => 'FOO BAR'
  13816. */
  13817. var startCase = createCompounder(function(result, word, index) {
  13818. return result + (index ? ' ' : '') + upperFirst(word);
  13819. });
  13820. /**
  13821. * Checks if `string` starts with the given target string.
  13822. *
  13823. * @static
  13824. * @memberOf _
  13825. * @since 3.0.0
  13826. * @category String
  13827. * @param {string} [string=''] The string to inspect.
  13828. * @param {string} [target] The string to search for.
  13829. * @param {number} [position=0] The position to search from.
  13830. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13831. * else `false`.
  13832. * @example
  13833. *
  13834. * _.startsWith('abc', 'a');
  13835. * // => true
  13836. *
  13837. * _.startsWith('abc', 'b');
  13838. * // => false
  13839. *
  13840. * _.startsWith('abc', 'b', 1);
  13841. * // => true
  13842. */
  13843. function startsWith(string, target, position) {
  13844. string = toString(string);
  13845. position = position == null
  13846. ? 0
  13847. : baseClamp(toInteger(position), 0, string.length);
  13848. target = baseToString(target);
  13849. return string.slice(position, position + target.length) == target;
  13850. }
  13851. /**
  13852. * Creates a compiled template function that can interpolate data properties
  13853. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13854. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13855. * properties may be accessed as free variables in the template. If a setting
  13856. * object is given, it takes precedence over `_.templateSettings` values.
  13857. *
  13858. * **Security:** `_.template` is insecure and should not be used. It will be
  13859. * removed in Lodash v5. Avoid untrusted input. See
  13860. * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md).
  13861. *
  13862. * **Note:** In the development build `_.template` utilizes
  13863. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13864. * for easier debugging.
  13865. *
  13866. * For more information on precompiling templates see
  13867. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13868. *
  13869. * For more information on Chrome extension sandboxes see
  13870. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13871. *
  13872. * @static
  13873. * @since 0.1.0
  13874. * @memberOf _
  13875. * @category String
  13876. * @param {string} [string=''] The template string.
  13877. * @param {Object} [options={}] The options object.
  13878. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13879. * The HTML "escape" delimiter.
  13880. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13881. * The "evaluate" delimiter.
  13882. * @param {Object} [options.imports=_.templateSettings.imports]
  13883. * An object to import into the template as free variables.
  13884. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13885. * The "interpolate" delimiter.
  13886. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13887. * The sourceURL of the compiled template.
  13888. * @param {string} [options.variable='obj']
  13889. * The data object variable name.
  13890. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13891. * @returns {Function} Returns the compiled template function.
  13892. * @example
  13893. *
  13894. * // Use the "interpolate" delimiter to create a compiled template.
  13895. * var compiled = _.template('hello <%= user %>!');
  13896. * compiled({ 'user': 'fred' });
  13897. * // => 'hello fred!'
  13898. *
  13899. * // Use the HTML "escape" delimiter to escape data property values.
  13900. * var compiled = _.template('<b><%- value %></b>');
  13901. * compiled({ 'value': '<script>' });
  13902. * // => '<b>&lt;script&gt;</b>'
  13903. *
  13904. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13905. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13906. * compiled({ 'users': ['fred', 'barney'] });
  13907. * // => '<li>fred</li><li>barney</li>'
  13908. *
  13909. * // Use the internal `print` function in "evaluate" delimiters.
  13910. * var compiled = _.template('<% print("hello " + user); %>!');
  13911. * compiled({ 'user': 'barney' });
  13912. * // => 'hello barney!'
  13913. *
  13914. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13915. * // Disable support by replacing the "interpolate" delimiter.
  13916. * var compiled = _.template('hello ${ user }!');
  13917. * compiled({ 'user': 'pebbles' });
  13918. * // => 'hello pebbles!'
  13919. *
  13920. * // Use backslashes to treat delimiters as plain text.
  13921. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13922. * compiled({ 'value': 'ignored' });
  13923. * // => '<%- value %>'
  13924. *
  13925. * // Use the `imports` option to import `jQuery` as `jq`.
  13926. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13927. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13928. * compiled({ 'users': ['fred', 'barney'] });
  13929. * // => '<li>fred</li><li>barney</li>'
  13930. *
  13931. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13932. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13933. * compiled(data);
  13934. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13935. *
  13936. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13937. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13938. * compiled.source;
  13939. * // => function(data) {
  13940. * // var __t, __p = '';
  13941. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13942. * // return __p;
  13943. * // }
  13944. *
  13945. * // Use custom template delimiters.
  13946. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13947. * var compiled = _.template('hello {{ user }}!');
  13948. * compiled({ 'user': 'mustache' });
  13949. * // => 'hello mustache!'
  13950. *
  13951. * // Use the `source` property to inline compiled templates for meaningful
  13952. * // line numbers in error messages and stack traces.
  13953. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13954. * var JST = {\
  13955. * "main": ' + _.template(mainText).source + '\
  13956. * };\
  13957. * ');
  13958. */
  13959. function template(string, options, guard) {
  13960. // Based on John Resig's `tmpl` implementation
  13961. // (http://ejohn.org/blog/javascript-micro-templating/)
  13962. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13963. var settings = lodash.templateSettings;
  13964. if (guard && isIterateeCall(string, options, guard)) {
  13965. options = undefined;
  13966. }
  13967. string = toString(string);
  13968. options = assignWith({}, options, settings, customDefaultsAssignIn);
  13969. var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13970. importsKeys = keys(imports),
  13971. importsValues = baseValues(imports, importsKeys);
  13972. arrayEach(importsKeys, function(key) {
  13973. if (reForbiddenIdentifierChars.test(key)) {
  13974. throw new Error(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
  13975. }
  13976. });
  13977. var isEscaping,
  13978. isEvaluating,
  13979. index = 0,
  13980. interpolate = options.interpolate || reNoMatch,
  13981. source = "__p += '";
  13982. // Compile the regexp to match each delimiter.
  13983. var reDelimiters = RegExp(
  13984. (options.escape || reNoMatch).source + '|' +
  13985. interpolate.source + '|' +
  13986. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13987. (options.evaluate || reNoMatch).source + '|$'
  13988. , 'g');
  13989. // Use a sourceURL for easier debugging.
  13990. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13991. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  13992. // and escape the comment, thus injecting code that gets evaled.
  13993. var sourceURL = '//# sourceURL=' +
  13994. (hasOwnProperty.call(options, 'sourceURL')
  13995. ? (options.sourceURL + '').replace(/\s/g, ' ')
  13996. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13997. ) + '\n';
  13998. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13999. interpolateValue || (interpolateValue = esTemplateValue);
  14000. // Escape characters that can't be included in string literals.
  14001. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  14002. // Replace delimiters with snippets.
  14003. if (escapeValue) {
  14004. isEscaping = true;
  14005. source += "' +\n__e(" + escapeValue + ") +\n'";
  14006. }
  14007. if (evaluateValue) {
  14008. isEvaluating = true;
  14009. source += "';\n" + evaluateValue + ";\n__p += '";
  14010. }
  14011. if (interpolateValue) {
  14012. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  14013. }
  14014. index = offset + match.length;
  14015. // The JS engine embedded in Adobe products needs `match` returned in
  14016. // order to produce the correct `offset` value.
  14017. return match;
  14018. });
  14019. source += "';\n";
  14020. // If `variable` is not specified wrap a with-statement around the generated
  14021. // code to add the data object to the top of the scope chain.
  14022. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  14023. if (!variable) {
  14024. source = 'with (obj) {\n' + source + '\n}\n';
  14025. }
  14026. // Throw an error if a forbidden character was found in `variable`, to prevent
  14027. // potential command injection attacks.
  14028. else if (reForbiddenIdentifierChars.test(variable)) {
  14029. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  14030. }
  14031. // Cleanup code by stripping empty strings.
  14032. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  14033. .replace(reEmptyStringMiddle, '$1')
  14034. .replace(reEmptyStringTrailing, '$1;');
  14035. // Frame code as the function body.
  14036. source = 'function(' + (variable || 'obj') + ') {\n' +
  14037. (variable
  14038. ? ''
  14039. : 'obj || (obj = {});\n'
  14040. ) +
  14041. "var __t, __p = ''" +
  14042. (isEscaping
  14043. ? ', __e = _.escape'
  14044. : ''
  14045. ) +
  14046. (isEvaluating
  14047. ? ', __j = Array.prototype.join;\n' +
  14048. "function print() { __p += __j.call(arguments, '') }\n"
  14049. : ';\n'
  14050. ) +
  14051. source +
  14052. 'return __p\n}';
  14053. var result = attempt(function() {
  14054. return Function(importsKeys, sourceURL + 'return ' + source)
  14055. .apply(undefined, importsValues);
  14056. });
  14057. // Provide the compiled function's source by its `toString` method or
  14058. // the `source` property as a convenience for inlining compiled templates.
  14059. result.source = source;
  14060. if (isError(result)) {
  14061. throw result;
  14062. }
  14063. return result;
  14064. }
  14065. /**
  14066. * Converts `string`, as a whole, to lower case just like
  14067. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14068. *
  14069. * @static
  14070. * @memberOf _
  14071. * @since 4.0.0
  14072. * @category String
  14073. * @param {string} [string=''] The string to convert.
  14074. * @returns {string} Returns the lower cased string.
  14075. * @example
  14076. *
  14077. * _.toLower('--Foo-Bar--');
  14078. * // => '--foo-bar--'
  14079. *
  14080. * _.toLower('fooBar');
  14081. * // => 'foobar'
  14082. *
  14083. * _.toLower('__FOO_BAR__');
  14084. * // => '__foo_bar__'
  14085. */
  14086. function toLower(value) {
  14087. return toString(value).toLowerCase();
  14088. }
  14089. /**
  14090. * Converts `string`, as a whole, to upper case just like
  14091. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14092. *
  14093. * @static
  14094. * @memberOf _
  14095. * @since 4.0.0
  14096. * @category String
  14097. * @param {string} [string=''] The string to convert.
  14098. * @returns {string} Returns the upper cased string.
  14099. * @example
  14100. *
  14101. * _.toUpper('--foo-bar--');
  14102. * // => '--FOO-BAR--'
  14103. *
  14104. * _.toUpper('fooBar');
  14105. * // => 'FOOBAR'
  14106. *
  14107. * _.toUpper('__foo_bar__');
  14108. * // => '__FOO_BAR__'
  14109. */
  14110. function toUpper(value) {
  14111. return toString(value).toUpperCase();
  14112. }
  14113. /**
  14114. * Removes leading and trailing whitespace or specified characters from `string`.
  14115. *
  14116. * @static
  14117. * @memberOf _
  14118. * @since 3.0.0
  14119. * @category String
  14120. * @param {string} [string=''] The string to trim.
  14121. * @param {string} [chars=whitespace] The characters to trim.
  14122. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14123. * @returns {string} Returns the trimmed string.
  14124. * @example
  14125. *
  14126. * _.trim(' abc ');
  14127. * // => 'abc'
  14128. *
  14129. * _.trim('-_-abc-_-', '_-');
  14130. * // => 'abc'
  14131. *
  14132. * _.map([' foo ', ' bar '], _.trim);
  14133. * // => ['foo', 'bar']
  14134. */
  14135. function trim(string, chars, guard) {
  14136. string = toString(string);
  14137. if (string && (guard || chars === undefined)) {
  14138. return baseTrim(string);
  14139. }
  14140. if (!string || !(chars = baseToString(chars))) {
  14141. return string;
  14142. }
  14143. var strSymbols = stringToArray(string),
  14144. chrSymbols = stringToArray(chars),
  14145. start = charsStartIndex(strSymbols, chrSymbols),
  14146. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14147. return castSlice(strSymbols, start, end).join('');
  14148. }
  14149. /**
  14150. * Removes trailing whitespace or specified characters from `string`.
  14151. *
  14152. * @static
  14153. * @memberOf _
  14154. * @since 4.0.0
  14155. * @category String
  14156. * @param {string} [string=''] The string to trim.
  14157. * @param {string} [chars=whitespace] The characters to trim.
  14158. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14159. * @returns {string} Returns the trimmed string.
  14160. * @example
  14161. *
  14162. * _.trimEnd(' abc ');
  14163. * // => ' abc'
  14164. *
  14165. * _.trimEnd('-_-abc-_-', '_-');
  14166. * // => '-_-abc'
  14167. */
  14168. function trimEnd(string, chars, guard) {
  14169. string = toString(string);
  14170. if (string && (guard || chars === undefined)) {
  14171. return string.slice(0, trimmedEndIndex(string) + 1);
  14172. }
  14173. if (!string || !(chars = baseToString(chars))) {
  14174. return string;
  14175. }
  14176. var strSymbols = stringToArray(string),
  14177. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14178. return castSlice(strSymbols, 0, end).join('');
  14179. }
  14180. /**
  14181. * Removes leading whitespace or specified characters from `string`.
  14182. *
  14183. * @static
  14184. * @memberOf _
  14185. * @since 4.0.0
  14186. * @category String
  14187. * @param {string} [string=''] The string to trim.
  14188. * @param {string} [chars=whitespace] The characters to trim.
  14189. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14190. * @returns {string} Returns the trimmed string.
  14191. * @example
  14192. *
  14193. * _.trimStart(' abc ');
  14194. * // => 'abc '
  14195. *
  14196. * _.trimStart('-_-abc-_-', '_-');
  14197. * // => 'abc-_-'
  14198. */
  14199. function trimStart(string, chars, guard) {
  14200. string = toString(string);
  14201. if (string && (guard || chars === undefined)) {
  14202. return string.replace(reTrimStart, '');
  14203. }
  14204. if (!string || !(chars = baseToString(chars))) {
  14205. return string;
  14206. }
  14207. var strSymbols = stringToArray(string),
  14208. start = charsStartIndex(strSymbols, stringToArray(chars));
  14209. return castSlice(strSymbols, start).join('');
  14210. }
  14211. /**
  14212. * Truncates `string` if it's longer than the given maximum string length.
  14213. * The last characters of the truncated string are replaced with the omission
  14214. * string which defaults to "...".
  14215. *
  14216. * @static
  14217. * @memberOf _
  14218. * @since 4.0.0
  14219. * @category String
  14220. * @param {string} [string=''] The string to truncate.
  14221. * @param {Object} [options={}] The options object.
  14222. * @param {number} [options.length=30] The maximum string length.
  14223. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14224. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14225. * @returns {string} Returns the truncated string.
  14226. * @example
  14227. *
  14228. * _.truncate('hi-diddly-ho there, neighborino');
  14229. * // => 'hi-diddly-ho there, neighbo...'
  14230. *
  14231. * _.truncate('hi-diddly-ho there, neighborino', {
  14232. * 'length': 24,
  14233. * 'separator': ' '
  14234. * });
  14235. * // => 'hi-diddly-ho there,...'
  14236. *
  14237. * _.truncate('hi-diddly-ho there, neighborino', {
  14238. * 'length': 24,
  14239. * 'separator': /,? +/
  14240. * });
  14241. * // => 'hi-diddly-ho there...'
  14242. *
  14243. * _.truncate('hi-diddly-ho there, neighborino', {
  14244. * 'omission': ' [...]'
  14245. * });
  14246. * // => 'hi-diddly-ho there, neig [...]'
  14247. */
  14248. function truncate(string, options) {
  14249. var length = DEFAULT_TRUNC_LENGTH,
  14250. omission = DEFAULT_TRUNC_OMISSION;
  14251. if (isObject(options)) {
  14252. var separator = 'separator' in options ? options.separator : separator;
  14253. length = 'length' in options ? toInteger(options.length) : length;
  14254. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14255. }
  14256. string = toString(string);
  14257. var strLength = string.length;
  14258. if (hasUnicode(string)) {
  14259. var strSymbols = stringToArray(string);
  14260. strLength = strSymbols.length;
  14261. }
  14262. if (length >= strLength) {
  14263. return string;
  14264. }
  14265. var end = length - stringSize(omission);
  14266. if (end < 1) {
  14267. return omission;
  14268. }
  14269. var result = strSymbols
  14270. ? castSlice(strSymbols, 0, end).join('')
  14271. : string.slice(0, end);
  14272. if (separator === undefined) {
  14273. return result + omission;
  14274. }
  14275. if (strSymbols) {
  14276. end += (result.length - end);
  14277. }
  14278. if (isRegExp(separator)) {
  14279. if (string.slice(end).search(separator)) {
  14280. var match,
  14281. substring = result;
  14282. if (!separator.global) {
  14283. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14284. }
  14285. separator.lastIndex = 0;
  14286. while ((match = separator.exec(substring))) {
  14287. var newEnd = match.index;
  14288. }
  14289. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14290. }
  14291. } else if (string.indexOf(baseToString(separator), end) != end) {
  14292. var index = result.lastIndexOf(separator);
  14293. if (index > -1) {
  14294. result = result.slice(0, index);
  14295. }
  14296. }
  14297. return result + omission;
  14298. }
  14299. /**
  14300. * The inverse of `_.escape`; this method converts the HTML entities
  14301. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14302. * their corresponding characters.
  14303. *
  14304. * **Note:** No other HTML entities are unescaped. To unescape additional
  14305. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14306. *
  14307. * @static
  14308. * @memberOf _
  14309. * @since 0.6.0
  14310. * @category String
  14311. * @param {string} [string=''] The string to unescape.
  14312. * @returns {string} Returns the unescaped string.
  14313. * @example
  14314. *
  14315. * _.unescape('fred, barney, &amp; pebbles');
  14316. * // => 'fred, barney, & pebbles'
  14317. */
  14318. function unescape(string) {
  14319. string = toString(string);
  14320. return (string && reHasEscapedHtml.test(string))
  14321. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14322. : string;
  14323. }
  14324. /**
  14325. * Converts `string`, as space separated words, to upper case.
  14326. *
  14327. * @static
  14328. * @memberOf _
  14329. * @since 4.0.0
  14330. * @category String
  14331. * @param {string} [string=''] The string to convert.
  14332. * @returns {string} Returns the upper cased string.
  14333. * @example
  14334. *
  14335. * _.upperCase('--foo-bar');
  14336. * // => 'FOO BAR'
  14337. *
  14338. * _.upperCase('fooBar');
  14339. * // => 'FOO BAR'
  14340. *
  14341. * _.upperCase('__foo_bar__');
  14342. * // => 'FOO BAR'
  14343. */
  14344. var upperCase = createCompounder(function(result, word, index) {
  14345. return result + (index ? ' ' : '') + word.toUpperCase();
  14346. });
  14347. /**
  14348. * Converts the first character of `string` to upper case.
  14349. *
  14350. * @static
  14351. * @memberOf _
  14352. * @since 4.0.0
  14353. * @category String
  14354. * @param {string} [string=''] The string to convert.
  14355. * @returns {string} Returns the converted string.
  14356. * @example
  14357. *
  14358. * _.upperFirst('fred');
  14359. * // => 'Fred'
  14360. *
  14361. * _.upperFirst('FRED');
  14362. * // => 'FRED'
  14363. */
  14364. var upperFirst = createCaseFirst('toUpperCase');
  14365. /**
  14366. * Splits `string` into an array of its words.
  14367. *
  14368. * @static
  14369. * @memberOf _
  14370. * @since 3.0.0
  14371. * @category String
  14372. * @param {string} [string=''] The string to inspect.
  14373. * @param {RegExp|string} [pattern] The pattern to match words.
  14374. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14375. * @returns {Array} Returns the words of `string`.
  14376. * @example
  14377. *
  14378. * _.words('fred, barney, & pebbles');
  14379. * // => ['fred', 'barney', 'pebbles']
  14380. *
  14381. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14382. * // => ['fred', 'barney', '&', 'pebbles']
  14383. */
  14384. function words(string, pattern, guard) {
  14385. string = toString(string);
  14386. pattern = guard ? undefined : pattern;
  14387. if (pattern === undefined) {
  14388. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14389. }
  14390. return string.match(pattern) || [];
  14391. }
  14392. /*------------------------------------------------------------------------*/
  14393. /**
  14394. * Attempts to invoke `func`, returning either the result or the caught error
  14395. * object. Any additional arguments are provided to `func` when it's invoked.
  14396. *
  14397. * @static
  14398. * @memberOf _
  14399. * @since 3.0.0
  14400. * @category Util
  14401. * @param {Function} func The function to attempt.
  14402. * @param {...*} [args] The arguments to invoke `func` with.
  14403. * @returns {*} Returns the `func` result or error object.
  14404. * @example
  14405. *
  14406. * // Avoid throwing errors for invalid selectors.
  14407. * var elements = _.attempt(function(selector) {
  14408. * return document.querySelectorAll(selector);
  14409. * }, '>_>');
  14410. *
  14411. * if (_.isError(elements)) {
  14412. * elements = [];
  14413. * }
  14414. */
  14415. var attempt = baseRest(function(func, args) {
  14416. try {
  14417. return apply(func, undefined, args);
  14418. } catch (e) {
  14419. return isError(e) ? e : new Error(e);
  14420. }
  14421. });
  14422. /**
  14423. * Binds methods of an object to the object itself, overwriting the existing
  14424. * method.
  14425. *
  14426. * **Note:** This method doesn't set the "length" property of bound functions.
  14427. *
  14428. * @static
  14429. * @since 0.1.0
  14430. * @memberOf _
  14431. * @category Util
  14432. * @param {Object} object The object to bind and assign the bound methods to.
  14433. * @param {...(string|string[])} methodNames The object method names to bind.
  14434. * @returns {Object} Returns `object`.
  14435. * @example
  14436. *
  14437. * var view = {
  14438. * 'label': 'docs',
  14439. * 'click': function() {
  14440. * console.log('clicked ' + this.label);
  14441. * }
  14442. * };
  14443. *
  14444. * _.bindAll(view, ['click']);
  14445. * jQuery(element).on('click', view.click);
  14446. * // => Logs 'clicked docs' when clicked.
  14447. */
  14448. var bindAll = flatRest(function(object, methodNames) {
  14449. arrayEach(methodNames, function(key) {
  14450. key = toKey(key);
  14451. baseAssignValue(object, key, bind(object[key], object));
  14452. });
  14453. return object;
  14454. });
  14455. /**
  14456. * Creates a function that iterates over `pairs` and invokes the corresponding
  14457. * function of the first predicate to return truthy. The predicate-function
  14458. * pairs are invoked with the `this` binding and arguments of the created
  14459. * function.
  14460. *
  14461. * @static
  14462. * @memberOf _
  14463. * @since 4.0.0
  14464. * @category Util
  14465. * @param {Array} pairs The predicate-function pairs.
  14466. * @returns {Function} Returns the new composite function.
  14467. * @example
  14468. *
  14469. * var func = _.cond([
  14470. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14471. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14472. * [_.stubTrue, _.constant('no match')]
  14473. * ]);
  14474. *
  14475. * func({ 'a': 1, 'b': 2 });
  14476. * // => 'matches A'
  14477. *
  14478. * func({ 'a': 0, 'b': 1 });
  14479. * // => 'matches B'
  14480. *
  14481. * func({ 'a': '1', 'b': '2' });
  14482. * // => 'no match'
  14483. */
  14484. function cond(pairs) {
  14485. var length = pairs == null ? 0 : pairs.length,
  14486. toIteratee = getIteratee();
  14487. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14488. if (typeof pair[1] != 'function') {
  14489. throw new TypeError(FUNC_ERROR_TEXT);
  14490. }
  14491. return [toIteratee(pair[0]), pair[1]];
  14492. });
  14493. return baseRest(function(args) {
  14494. var index = -1;
  14495. while (++index < length) {
  14496. var pair = pairs[index];
  14497. if (apply(pair[0], this, args)) {
  14498. return apply(pair[1], this, args);
  14499. }
  14500. }
  14501. });
  14502. }
  14503. /**
  14504. * Creates a function that invokes the predicate properties of `source` with
  14505. * the corresponding property values of a given object, returning `true` if
  14506. * all predicates return truthy, else `false`.
  14507. *
  14508. * **Note:** The created function is equivalent to `_.conformsTo` with
  14509. * `source` partially applied.
  14510. *
  14511. * @static
  14512. * @memberOf _
  14513. * @since 4.0.0
  14514. * @category Util
  14515. * @param {Object} source The object of property predicates to conform to.
  14516. * @returns {Function} Returns the new spec function.
  14517. * @example
  14518. *
  14519. * var objects = [
  14520. * { 'a': 2, 'b': 1 },
  14521. * { 'a': 1, 'b': 2 }
  14522. * ];
  14523. *
  14524. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14525. * // => [{ 'a': 1, 'b': 2 }]
  14526. */
  14527. function conforms(source) {
  14528. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14529. }
  14530. /**
  14531. * Creates a function that returns `value`.
  14532. *
  14533. * @static
  14534. * @memberOf _
  14535. * @since 2.4.0
  14536. * @category Util
  14537. * @param {*} value The value to return from the new function.
  14538. * @returns {Function} Returns the new constant function.
  14539. * @example
  14540. *
  14541. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14542. *
  14543. * console.log(objects);
  14544. * // => [{ 'a': 1 }, { 'a': 1 }]
  14545. *
  14546. * console.log(objects[0] === objects[1]);
  14547. * // => true
  14548. */
  14549. function constant(value) {
  14550. return function() {
  14551. return value;
  14552. };
  14553. }
  14554. /**
  14555. * Checks `value` to determine whether a default value should be returned in
  14556. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14557. * or `undefined`.
  14558. *
  14559. * @static
  14560. * @memberOf _
  14561. * @since 4.14.0
  14562. * @category Util
  14563. * @param {*} value The value to check.
  14564. * @param {*} defaultValue The default value.
  14565. * @returns {*} Returns the resolved value.
  14566. * @example
  14567. *
  14568. * _.defaultTo(1, 10);
  14569. * // => 1
  14570. *
  14571. * _.defaultTo(undefined, 10);
  14572. * // => 10
  14573. */
  14574. function defaultTo(value, defaultValue) {
  14575. return (value == null || value !== value) ? defaultValue : value;
  14576. }
  14577. /**
  14578. * Creates a function that returns the result of invoking the given functions
  14579. * with the `this` binding of the created function, where each successive
  14580. * invocation is supplied the return value of the previous.
  14581. *
  14582. * @static
  14583. * @memberOf _
  14584. * @since 3.0.0
  14585. * @category Util
  14586. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14587. * @returns {Function} Returns the new composite function.
  14588. * @see _.flowRight
  14589. * @example
  14590. *
  14591. * function square(n) {
  14592. * return n * n;
  14593. * }
  14594. *
  14595. * var addSquare = _.flow([_.add, square]);
  14596. * addSquare(1, 2);
  14597. * // => 9
  14598. */
  14599. var flow = createFlow();
  14600. /**
  14601. * This method is like `_.flow` except that it creates a function that
  14602. * invokes the given functions from right to left.
  14603. *
  14604. * @static
  14605. * @since 3.0.0
  14606. * @memberOf _
  14607. * @category Util
  14608. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14609. * @returns {Function} Returns the new composite function.
  14610. * @see _.flow
  14611. * @example
  14612. *
  14613. * function square(n) {
  14614. * return n * n;
  14615. * }
  14616. *
  14617. * var addSquare = _.flowRight([square, _.add]);
  14618. * addSquare(1, 2);
  14619. * // => 9
  14620. */
  14621. var flowRight = createFlow(true);
  14622. /**
  14623. * This method returns the first argument it receives.
  14624. *
  14625. * @static
  14626. * @since 0.1.0
  14627. * @memberOf _
  14628. * @category Util
  14629. * @param {*} value Any value.
  14630. * @returns {*} Returns `value`.
  14631. * @example
  14632. *
  14633. * var object = { 'a': 1 };
  14634. *
  14635. * console.log(_.identity(object) === object);
  14636. * // => true
  14637. */
  14638. function identity(value) {
  14639. return value;
  14640. }
  14641. /**
  14642. * Creates a function that invokes `func` with the arguments of the created
  14643. * function. If `func` is a property name, the created function returns the
  14644. * property value for a given element. If `func` is an array or object, the
  14645. * created function returns `true` for elements that contain the equivalent
  14646. * source properties, otherwise it returns `false`.
  14647. *
  14648. * @static
  14649. * @since 4.0.0
  14650. * @memberOf _
  14651. * @category Util
  14652. * @param {*} [func=_.identity] The value to convert to a callback.
  14653. * @returns {Function} Returns the callback.
  14654. * @example
  14655. *
  14656. * var users = [
  14657. * { 'user': 'barney', 'age': 36, 'active': true },
  14658. * { 'user': 'fred', 'age': 40, 'active': false }
  14659. * ];
  14660. *
  14661. * // The `_.matches` iteratee shorthand.
  14662. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14663. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14664. *
  14665. * // The `_.matchesProperty` iteratee shorthand.
  14666. * _.filter(users, _.iteratee(['user', 'fred']));
  14667. * // => [{ 'user': 'fred', 'age': 40 }]
  14668. *
  14669. * // The `_.property` iteratee shorthand.
  14670. * _.map(users, _.iteratee('user'));
  14671. * // => ['barney', 'fred']
  14672. *
  14673. * // Create custom iteratee shorthands.
  14674. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14675. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14676. * return func.test(string);
  14677. * };
  14678. * });
  14679. *
  14680. * _.filter(['abc', 'def'], /ef/);
  14681. * // => ['def']
  14682. */
  14683. function iteratee(func) {
  14684. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14685. }
  14686. /**
  14687. * Creates a function that performs a partial deep comparison between a given
  14688. * object and `source`, returning `true` if the given object has equivalent
  14689. * property values, else `false`.
  14690. *
  14691. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14692. * partially applied.
  14693. *
  14694. * Partial comparisons will match empty array and empty object `source`
  14695. * values against any array or object value, respectively. See `_.isEqual`
  14696. * for a list of supported value comparisons.
  14697. *
  14698. * **Note:** Multiple values can be checked by combining several matchers
  14699. * using `_.overSome`
  14700. *
  14701. * @static
  14702. * @memberOf _
  14703. * @since 3.0.0
  14704. * @category Util
  14705. * @param {Object} source The object of property values to match.
  14706. * @returns {Function} Returns the new spec function.
  14707. * @example
  14708. *
  14709. * var objects = [
  14710. * { 'a': 1, 'b': 2, 'c': 3 },
  14711. * { 'a': 4, 'b': 5, 'c': 6 }
  14712. * ];
  14713. *
  14714. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14715. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14716. *
  14717. * // Checking for several possible values
  14718. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  14719. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14720. */
  14721. function matches(source) {
  14722. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14723. }
  14724. /**
  14725. * Creates a function that performs a partial deep comparison between the
  14726. * value at `path` of a given object to `srcValue`, returning `true` if the
  14727. * object value is equivalent, else `false`.
  14728. *
  14729. * **Note:** Partial comparisons will match empty array and empty object
  14730. * `srcValue` values against any array or object value, respectively. See
  14731. * `_.isEqual` for a list of supported value comparisons.
  14732. *
  14733. * **Note:** Multiple values can be checked by combining several matchers
  14734. * using `_.overSome`
  14735. *
  14736. * @static
  14737. * @memberOf _
  14738. * @since 3.2.0
  14739. * @category Util
  14740. * @param {Array|string} path The path of the property to get.
  14741. * @param {*} srcValue The value to match.
  14742. * @returns {Function} Returns the new spec function.
  14743. * @example
  14744. *
  14745. * var objects = [
  14746. * { 'a': 1, 'b': 2, 'c': 3 },
  14747. * { 'a': 4, 'b': 5, 'c': 6 }
  14748. * ];
  14749. *
  14750. * _.find(objects, _.matchesProperty('a', 4));
  14751. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14752. *
  14753. * // Checking for several possible values
  14754. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  14755. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14756. */
  14757. function matchesProperty(path, srcValue) {
  14758. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14759. }
  14760. /**
  14761. * Creates a function that invokes the method at `path` of a given object.
  14762. * Any additional arguments are provided to the invoked method.
  14763. *
  14764. * @static
  14765. * @memberOf _
  14766. * @since 3.7.0
  14767. * @category Util
  14768. * @param {Array|string} path The path of the method to invoke.
  14769. * @param {...*} [args] The arguments to invoke the method with.
  14770. * @returns {Function} Returns the new invoker function.
  14771. * @example
  14772. *
  14773. * var objects = [
  14774. * { 'a': { 'b': _.constant(2) } },
  14775. * { 'a': { 'b': _.constant(1) } }
  14776. * ];
  14777. *
  14778. * _.map(objects, _.method('a.b'));
  14779. * // => [2, 1]
  14780. *
  14781. * _.map(objects, _.method(['a', 'b']));
  14782. * // => [2, 1]
  14783. */
  14784. var method = baseRest(function(path, args) {
  14785. return function(object) {
  14786. return baseInvoke(object, path, args);
  14787. };
  14788. });
  14789. /**
  14790. * The opposite of `_.method`; this method creates a function that invokes
  14791. * the method at a given path of `object`. Any additional arguments are
  14792. * provided to the invoked method.
  14793. *
  14794. * @static
  14795. * @memberOf _
  14796. * @since 3.7.0
  14797. * @category Util
  14798. * @param {Object} object The object to query.
  14799. * @param {...*} [args] The arguments to invoke the method with.
  14800. * @returns {Function} Returns the new invoker function.
  14801. * @example
  14802. *
  14803. * var array = _.times(3, _.constant),
  14804. * object = { 'a': array, 'b': array, 'c': array };
  14805. *
  14806. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14807. * // => [2, 0]
  14808. *
  14809. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14810. * // => [2, 0]
  14811. */
  14812. var methodOf = baseRest(function(object, args) {
  14813. return function(path) {
  14814. return baseInvoke(object, path, args);
  14815. };
  14816. });
  14817. /**
  14818. * Adds all own enumerable string keyed function properties of a source
  14819. * object to the destination object. If `object` is a function, then methods
  14820. * are added to its prototype as well.
  14821. *
  14822. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14823. * avoid conflicts caused by modifying the original.
  14824. *
  14825. * @static
  14826. * @since 0.1.0
  14827. * @memberOf _
  14828. * @category Util
  14829. * @param {Function|Object} [object=lodash] The destination object.
  14830. * @param {Object} source The object of functions to add.
  14831. * @param {Object} [options={}] The options object.
  14832. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14833. * @returns {Function|Object} Returns `object`.
  14834. * @example
  14835. *
  14836. * function vowels(string) {
  14837. * return _.filter(string, function(v) {
  14838. * return /[aeiou]/i.test(v);
  14839. * });
  14840. * }
  14841. *
  14842. * _.mixin({ 'vowels': vowels });
  14843. * _.vowels('fred');
  14844. * // => ['e']
  14845. *
  14846. * _('fred').vowels().value();
  14847. * // => ['e']
  14848. *
  14849. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14850. * _('fred').vowels();
  14851. * // => ['e']
  14852. */
  14853. function mixin(object, source, options) {
  14854. var props = keys(source),
  14855. methodNames = baseFunctions(source, props);
  14856. if (options == null &&
  14857. !(isObject(source) && (methodNames.length || !props.length))) {
  14858. options = source;
  14859. source = object;
  14860. object = this;
  14861. methodNames = baseFunctions(source, keys(source));
  14862. }
  14863. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14864. isFunc = isFunction(object);
  14865. arrayEach(methodNames, function(methodName) {
  14866. var func = source[methodName];
  14867. object[methodName] = func;
  14868. if (isFunc) {
  14869. object.prototype[methodName] = function() {
  14870. var chainAll = this.__chain__;
  14871. if (chain || chainAll) {
  14872. var result = object(this.__wrapped__),
  14873. actions = result.__actions__ = copyArray(this.__actions__);
  14874. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14875. result.__chain__ = chainAll;
  14876. return result;
  14877. }
  14878. return func.apply(object, arrayPush([this.value()], arguments));
  14879. };
  14880. }
  14881. });
  14882. return object;
  14883. }
  14884. /**
  14885. * Reverts the `_` variable to its previous value and returns a reference to
  14886. * the `lodash` function.
  14887. *
  14888. * @static
  14889. * @since 0.1.0
  14890. * @memberOf _
  14891. * @category Util
  14892. * @returns {Function} Returns the `lodash` function.
  14893. * @example
  14894. *
  14895. * var lodash = _.noConflict();
  14896. */
  14897. function noConflict() {
  14898. if (root._ === this) {
  14899. root._ = oldDash;
  14900. }
  14901. return this;
  14902. }
  14903. /**
  14904. * This method returns `undefined`.
  14905. *
  14906. * @static
  14907. * @memberOf _
  14908. * @since 2.3.0
  14909. * @category Util
  14910. * @example
  14911. *
  14912. * _.times(2, _.noop);
  14913. * // => [undefined, undefined]
  14914. */
  14915. function noop() {
  14916. // No operation performed.
  14917. }
  14918. /**
  14919. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14920. * the nth argument from the end is returned.
  14921. *
  14922. * @static
  14923. * @memberOf _
  14924. * @since 4.0.0
  14925. * @category Util
  14926. * @param {number} [n=0] The index of the argument to return.
  14927. * @returns {Function} Returns the new pass-thru function.
  14928. * @example
  14929. *
  14930. * var func = _.nthArg(1);
  14931. * func('a', 'b', 'c', 'd');
  14932. * // => 'b'
  14933. *
  14934. * var func = _.nthArg(-2);
  14935. * func('a', 'b', 'c', 'd');
  14936. * // => 'c'
  14937. */
  14938. function nthArg(n) {
  14939. n = toInteger(n);
  14940. return baseRest(function(args) {
  14941. return baseNth(args, n);
  14942. });
  14943. }
  14944. /**
  14945. * Creates a function that invokes `iteratees` with the arguments it receives
  14946. * and returns their results.
  14947. *
  14948. * @static
  14949. * @memberOf _
  14950. * @since 4.0.0
  14951. * @category Util
  14952. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14953. * The iteratees to invoke.
  14954. * @returns {Function} Returns the new function.
  14955. * @example
  14956. *
  14957. * var func = _.over([Math.max, Math.min]);
  14958. *
  14959. * func(1, 2, 3, 4);
  14960. * // => [4, 1]
  14961. */
  14962. var over = createOver(arrayMap);
  14963. /**
  14964. * Creates a function that checks if **all** of the `predicates` return
  14965. * truthy when invoked with the arguments it receives.
  14966. *
  14967. * Following shorthands are possible for providing predicates.
  14968. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14969. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14970. *
  14971. * @static
  14972. * @memberOf _
  14973. * @since 4.0.0
  14974. * @category Util
  14975. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14976. * The predicates to check.
  14977. * @returns {Function} Returns the new function.
  14978. * @example
  14979. *
  14980. * var func = _.overEvery([Boolean, isFinite]);
  14981. *
  14982. * func('1');
  14983. * // => true
  14984. *
  14985. * func(null);
  14986. * // => false
  14987. *
  14988. * func(NaN);
  14989. * // => false
  14990. */
  14991. var overEvery = createOver(arrayEvery);
  14992. /**
  14993. * Creates a function that checks if **any** of the `predicates` return
  14994. * truthy when invoked with the arguments it receives.
  14995. *
  14996. * Following shorthands are possible for providing predicates.
  14997. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14998. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14999. *
  15000. * @static
  15001. * @memberOf _
  15002. * @since 4.0.0
  15003. * @category Util
  15004. * @param {...(Function|Function[])} [predicates=[_.identity]]
  15005. * The predicates to check.
  15006. * @returns {Function} Returns the new function.
  15007. * @example
  15008. *
  15009. * var func = _.overSome([Boolean, isFinite]);
  15010. *
  15011. * func('1');
  15012. * // => true
  15013. *
  15014. * func(null);
  15015. * // => true
  15016. *
  15017. * func(NaN);
  15018. * // => false
  15019. *
  15020. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  15021. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  15022. */
  15023. var overSome = createOver(arraySome);
  15024. /**
  15025. * Creates a function that returns the value at `path` of a given object.
  15026. *
  15027. * @static
  15028. * @memberOf _
  15029. * @since 2.4.0
  15030. * @category Util
  15031. * @param {Array|string} path The path of the property to get.
  15032. * @returns {Function} Returns the new accessor function.
  15033. * @example
  15034. *
  15035. * var objects = [
  15036. * { 'a': { 'b': 2 } },
  15037. * { 'a': { 'b': 1 } }
  15038. * ];
  15039. *
  15040. * _.map(objects, _.property('a.b'));
  15041. * // => [2, 1]
  15042. *
  15043. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  15044. * // => [1, 2]
  15045. */
  15046. function property(path) {
  15047. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  15048. }
  15049. /**
  15050. * The opposite of `_.property`; this method creates a function that returns
  15051. * the value at a given path of `object`.
  15052. *
  15053. * @static
  15054. * @memberOf _
  15055. * @since 3.0.0
  15056. * @category Util
  15057. * @param {Object} object The object to query.
  15058. * @returns {Function} Returns the new accessor function.
  15059. * @example
  15060. *
  15061. * var array = [0, 1, 2],
  15062. * object = { 'a': array, 'b': array, 'c': array };
  15063. *
  15064. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15065. * // => [2, 0]
  15066. *
  15067. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15068. * // => [2, 0]
  15069. */
  15070. function propertyOf(object) {
  15071. return function(path) {
  15072. return object == null ? undefined : baseGet(object, path);
  15073. };
  15074. }
  15075. /**
  15076. * Creates an array of numbers (positive and/or negative) progressing from
  15077. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15078. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15079. * it's set to `start` with `start` then set to `0`.
  15080. *
  15081. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15082. * floating-point values which can produce unexpected results.
  15083. *
  15084. * @static
  15085. * @since 0.1.0
  15086. * @memberOf _
  15087. * @category Util
  15088. * @param {number} [start=0] The start of the range.
  15089. * @param {number} end The end of the range.
  15090. * @param {number} [step=1] The value to increment or decrement by.
  15091. * @returns {Array} Returns the range of numbers.
  15092. * @see _.inRange, _.rangeRight
  15093. * @example
  15094. *
  15095. * _.range(4);
  15096. * // => [0, 1, 2, 3]
  15097. *
  15098. * _.range(-4);
  15099. * // => [0, -1, -2, -3]
  15100. *
  15101. * _.range(1, 5);
  15102. * // => [1, 2, 3, 4]
  15103. *
  15104. * _.range(0, 20, 5);
  15105. * // => [0, 5, 10, 15]
  15106. *
  15107. * _.range(0, -4, -1);
  15108. * // => [0, -1, -2, -3]
  15109. *
  15110. * _.range(1, 4, 0);
  15111. * // => [1, 1, 1]
  15112. *
  15113. * _.range(0);
  15114. * // => []
  15115. */
  15116. var range = createRange();
  15117. /**
  15118. * This method is like `_.range` except that it populates values in
  15119. * descending order.
  15120. *
  15121. * @static
  15122. * @memberOf _
  15123. * @since 4.0.0
  15124. * @category Util
  15125. * @param {number} [start=0] The start of the range.
  15126. * @param {number} end The end of the range.
  15127. * @param {number} [step=1] The value to increment or decrement by.
  15128. * @returns {Array} Returns the range of numbers.
  15129. * @see _.inRange, _.range
  15130. * @example
  15131. *
  15132. * _.rangeRight(4);
  15133. * // => [3, 2, 1, 0]
  15134. *
  15135. * _.rangeRight(-4);
  15136. * // => [-3, -2, -1, 0]
  15137. *
  15138. * _.rangeRight(1, 5);
  15139. * // => [4, 3, 2, 1]
  15140. *
  15141. * _.rangeRight(0, 20, 5);
  15142. * // => [15, 10, 5, 0]
  15143. *
  15144. * _.rangeRight(0, -4, -1);
  15145. * // => [-3, -2, -1, 0]
  15146. *
  15147. * _.rangeRight(1, 4, 0);
  15148. * // => [1, 1, 1]
  15149. *
  15150. * _.rangeRight(0);
  15151. * // => []
  15152. */
  15153. var rangeRight = createRange(true);
  15154. /**
  15155. * This method returns a new empty array.
  15156. *
  15157. * @static
  15158. * @memberOf _
  15159. * @since 4.13.0
  15160. * @category Util
  15161. * @returns {Array} Returns the new empty array.
  15162. * @example
  15163. *
  15164. * var arrays = _.times(2, _.stubArray);
  15165. *
  15166. * console.log(arrays);
  15167. * // => [[], []]
  15168. *
  15169. * console.log(arrays[0] === arrays[1]);
  15170. * // => false
  15171. */
  15172. function stubArray() {
  15173. return [];
  15174. }
  15175. /**
  15176. * This method returns `false`.
  15177. *
  15178. * @static
  15179. * @memberOf _
  15180. * @since 4.13.0
  15181. * @category Util
  15182. * @returns {boolean} Returns `false`.
  15183. * @example
  15184. *
  15185. * _.times(2, _.stubFalse);
  15186. * // => [false, false]
  15187. */
  15188. function stubFalse() {
  15189. return false;
  15190. }
  15191. /**
  15192. * This method returns a new empty object.
  15193. *
  15194. * @static
  15195. * @memberOf _
  15196. * @since 4.13.0
  15197. * @category Util
  15198. * @returns {Object} Returns the new empty object.
  15199. * @example
  15200. *
  15201. * var objects = _.times(2, _.stubObject);
  15202. *
  15203. * console.log(objects);
  15204. * // => [{}, {}]
  15205. *
  15206. * console.log(objects[0] === objects[1]);
  15207. * // => false
  15208. */
  15209. function stubObject() {
  15210. return {};
  15211. }
  15212. /**
  15213. * This method returns an empty string.
  15214. *
  15215. * @static
  15216. * @memberOf _
  15217. * @since 4.13.0
  15218. * @category Util
  15219. * @returns {string} Returns the empty string.
  15220. * @example
  15221. *
  15222. * _.times(2, _.stubString);
  15223. * // => ['', '']
  15224. */
  15225. function stubString() {
  15226. return '';
  15227. }
  15228. /**
  15229. * This method returns `true`.
  15230. *
  15231. * @static
  15232. * @memberOf _
  15233. * @since 4.13.0
  15234. * @category Util
  15235. * @returns {boolean} Returns `true`.
  15236. * @example
  15237. *
  15238. * _.times(2, _.stubTrue);
  15239. * // => [true, true]
  15240. */
  15241. function stubTrue() {
  15242. return true;
  15243. }
  15244. /**
  15245. * Invokes the iteratee `n` times, returning an array of the results of
  15246. * each invocation. The iteratee is invoked with one argument; (index).
  15247. *
  15248. * @static
  15249. * @since 0.1.0
  15250. * @memberOf _
  15251. * @category Util
  15252. * @param {number} n The number of times to invoke `iteratee`.
  15253. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15254. * @returns {Array} Returns the array of results.
  15255. * @example
  15256. *
  15257. * _.times(3, String);
  15258. * // => ['0', '1', '2']
  15259. *
  15260. * _.times(4, _.constant(0));
  15261. * // => [0, 0, 0, 0]
  15262. */
  15263. function times(n, iteratee) {
  15264. n = toInteger(n);
  15265. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15266. return [];
  15267. }
  15268. var index = MAX_ARRAY_LENGTH,
  15269. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15270. iteratee = getIteratee(iteratee);
  15271. n -= MAX_ARRAY_LENGTH;
  15272. var result = baseTimes(length, iteratee);
  15273. while (++index < n) {
  15274. iteratee(index);
  15275. }
  15276. return result;
  15277. }
  15278. /**
  15279. * Converts `value` to a property path array.
  15280. *
  15281. * @static
  15282. * @memberOf _
  15283. * @since 4.0.0
  15284. * @category Util
  15285. * @param {*} value The value to convert.
  15286. * @returns {Array} Returns the new property path array.
  15287. * @example
  15288. *
  15289. * _.toPath('a.b.c');
  15290. * // => ['a', 'b', 'c']
  15291. *
  15292. * _.toPath('a[0].b.c');
  15293. * // => ['a', '0', 'b', 'c']
  15294. */
  15295. function toPath(value) {
  15296. if (isArray(value)) {
  15297. return arrayMap(value, toKey);
  15298. }
  15299. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15300. }
  15301. /**
  15302. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15303. *
  15304. * @static
  15305. * @since 0.1.0
  15306. * @memberOf _
  15307. * @category Util
  15308. * @param {string} [prefix=''] The value to prefix the ID with.
  15309. * @returns {string} Returns the unique ID.
  15310. * @example
  15311. *
  15312. * _.uniqueId('contact_');
  15313. * // => 'contact_104'
  15314. *
  15315. * _.uniqueId();
  15316. * // => '105'
  15317. */
  15318. function uniqueId(prefix) {
  15319. var id = ++idCounter;
  15320. return toString(prefix) + id;
  15321. }
  15322. /*------------------------------------------------------------------------*/
  15323. /**
  15324. * Adds two numbers.
  15325. *
  15326. * @static
  15327. * @memberOf _
  15328. * @since 3.4.0
  15329. * @category Math
  15330. * @param {number} augend The first number in an addition.
  15331. * @param {number} addend The second number in an addition.
  15332. * @returns {number} Returns the total.
  15333. * @example
  15334. *
  15335. * _.add(6, 4);
  15336. * // => 10
  15337. */
  15338. var add = createMathOperation(function(augend, addend) {
  15339. return augend + addend;
  15340. }, 0);
  15341. /**
  15342. * Computes `number` rounded up to `precision`.
  15343. *
  15344. * @static
  15345. * @memberOf _
  15346. * @since 3.10.0
  15347. * @category Math
  15348. * @param {number} number The number to round up.
  15349. * @param {number} [precision=0] The precision to round up to.
  15350. * @returns {number} Returns the rounded up number.
  15351. * @example
  15352. *
  15353. * _.ceil(4.006);
  15354. * // => 5
  15355. *
  15356. * _.ceil(6.004, 2);
  15357. * // => 6.01
  15358. *
  15359. * _.ceil(6040, -2);
  15360. * // => 6100
  15361. */
  15362. var ceil = createRound('ceil');
  15363. /**
  15364. * Divide two numbers.
  15365. *
  15366. * @static
  15367. * @memberOf _
  15368. * @since 4.7.0
  15369. * @category Math
  15370. * @param {number} dividend The first number in a division.
  15371. * @param {number} divisor The second number in a division.
  15372. * @returns {number} Returns the quotient.
  15373. * @example
  15374. *
  15375. * _.divide(6, 4);
  15376. * // => 1.5
  15377. */
  15378. var divide = createMathOperation(function(dividend, divisor) {
  15379. return dividend / divisor;
  15380. }, 1);
  15381. /**
  15382. * Computes `number` rounded down to `precision`.
  15383. *
  15384. * @static
  15385. * @memberOf _
  15386. * @since 3.10.0
  15387. * @category Math
  15388. * @param {number} number The number to round down.
  15389. * @param {number} [precision=0] The precision to round down to.
  15390. * @returns {number} Returns the rounded down number.
  15391. * @example
  15392. *
  15393. * _.floor(4.006);
  15394. * // => 4
  15395. *
  15396. * _.floor(0.046, 2);
  15397. * // => 0.04
  15398. *
  15399. * _.floor(4060, -2);
  15400. * // => 4000
  15401. */
  15402. var floor = createRound('floor');
  15403. /**
  15404. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15405. * `undefined` is returned.
  15406. *
  15407. * @static
  15408. * @since 0.1.0
  15409. * @memberOf _
  15410. * @category Math
  15411. * @param {Array} array The array to iterate over.
  15412. * @returns {*} Returns the maximum value.
  15413. * @example
  15414. *
  15415. * _.max([4, 2, 8, 6]);
  15416. * // => 8
  15417. *
  15418. * _.max([]);
  15419. * // => undefined
  15420. */
  15421. function max(array) {
  15422. return (array && array.length)
  15423. ? baseExtremum(array, identity, baseGt)
  15424. : undefined;
  15425. }
  15426. /**
  15427. * This method is like `_.max` except that it accepts `iteratee` which is
  15428. * invoked for each element in `array` to generate the criterion by which
  15429. * the value is ranked. The iteratee is invoked with one argument: (value).
  15430. *
  15431. * @static
  15432. * @memberOf _
  15433. * @since 4.0.0
  15434. * @category Math
  15435. * @param {Array} array The array to iterate over.
  15436. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15437. * @returns {*} Returns the maximum value.
  15438. * @example
  15439. *
  15440. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15441. *
  15442. * _.maxBy(objects, function(o) { return o.n; });
  15443. * // => { 'n': 2 }
  15444. *
  15445. * // The `_.property` iteratee shorthand.
  15446. * _.maxBy(objects, 'n');
  15447. * // => { 'n': 2 }
  15448. */
  15449. function maxBy(array, iteratee) {
  15450. return (array && array.length)
  15451. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15452. : undefined;
  15453. }
  15454. /**
  15455. * Computes the mean of the values in `array`.
  15456. *
  15457. * @static
  15458. * @memberOf _
  15459. * @since 4.0.0
  15460. * @category Math
  15461. * @param {Array} array The array to iterate over.
  15462. * @returns {number} Returns the mean.
  15463. * @example
  15464. *
  15465. * _.mean([4, 2, 8, 6]);
  15466. * // => 5
  15467. */
  15468. function mean(array) {
  15469. return baseMean(array, identity);
  15470. }
  15471. /**
  15472. * This method is like `_.mean` except that it accepts `iteratee` which is
  15473. * invoked for each element in `array` to generate the value to be averaged.
  15474. * The iteratee is invoked with one argument: (value).
  15475. *
  15476. * @static
  15477. * @memberOf _
  15478. * @since 4.7.0
  15479. * @category Math
  15480. * @param {Array} array The array to iterate over.
  15481. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15482. * @returns {number} Returns the mean.
  15483. * @example
  15484. *
  15485. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15486. *
  15487. * _.meanBy(objects, function(o) { return o.n; });
  15488. * // => 5
  15489. *
  15490. * // The `_.property` iteratee shorthand.
  15491. * _.meanBy(objects, 'n');
  15492. * // => 5
  15493. */
  15494. function meanBy(array, iteratee) {
  15495. return baseMean(array, getIteratee(iteratee, 2));
  15496. }
  15497. /**
  15498. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15499. * `undefined` is returned.
  15500. *
  15501. * @static
  15502. * @since 0.1.0
  15503. * @memberOf _
  15504. * @category Math
  15505. * @param {Array} array The array to iterate over.
  15506. * @returns {*} Returns the minimum value.
  15507. * @example
  15508. *
  15509. * _.min([4, 2, 8, 6]);
  15510. * // => 2
  15511. *
  15512. * _.min([]);
  15513. * // => undefined
  15514. */
  15515. function min(array) {
  15516. return (array && array.length)
  15517. ? baseExtremum(array, identity, baseLt)
  15518. : undefined;
  15519. }
  15520. /**
  15521. * This method is like `_.min` except that it accepts `iteratee` which is
  15522. * invoked for each element in `array` to generate the criterion by which
  15523. * the value is ranked. The iteratee is invoked with one argument: (value).
  15524. *
  15525. * @static
  15526. * @memberOf _
  15527. * @since 4.0.0
  15528. * @category Math
  15529. * @param {Array} array The array to iterate over.
  15530. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15531. * @returns {*} Returns the minimum value.
  15532. * @example
  15533. *
  15534. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15535. *
  15536. * _.minBy(objects, function(o) { return o.n; });
  15537. * // => { 'n': 1 }
  15538. *
  15539. * // The `_.property` iteratee shorthand.
  15540. * _.minBy(objects, 'n');
  15541. * // => { 'n': 1 }
  15542. */
  15543. function minBy(array, iteratee) {
  15544. return (array && array.length)
  15545. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15546. : undefined;
  15547. }
  15548. /**
  15549. * Multiply two numbers.
  15550. *
  15551. * @static
  15552. * @memberOf _
  15553. * @since 4.7.0
  15554. * @category Math
  15555. * @param {number} multiplier The first number in a multiplication.
  15556. * @param {number} multiplicand The second number in a multiplication.
  15557. * @returns {number} Returns the product.
  15558. * @example
  15559. *
  15560. * _.multiply(6, 4);
  15561. * // => 24
  15562. */
  15563. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15564. return multiplier * multiplicand;
  15565. }, 1);
  15566. /**
  15567. * Computes `number` rounded to `precision`.
  15568. *
  15569. * @static
  15570. * @memberOf _
  15571. * @since 3.10.0
  15572. * @category Math
  15573. * @param {number} number The number to round.
  15574. * @param {number} [precision=0] The precision to round to.
  15575. * @returns {number} Returns the rounded number.
  15576. * @example
  15577. *
  15578. * _.round(4.006);
  15579. * // => 4
  15580. *
  15581. * _.round(4.006, 2);
  15582. * // => 4.01
  15583. *
  15584. * _.round(4060, -2);
  15585. * // => 4100
  15586. */
  15587. var round = createRound('round');
  15588. /**
  15589. * Subtract two numbers.
  15590. *
  15591. * @static
  15592. * @memberOf _
  15593. * @since 4.0.0
  15594. * @category Math
  15595. * @param {number} minuend The first number in a subtraction.
  15596. * @param {number} subtrahend The second number in a subtraction.
  15597. * @returns {number} Returns the difference.
  15598. * @example
  15599. *
  15600. * _.subtract(6, 4);
  15601. * // => 2
  15602. */
  15603. var subtract = createMathOperation(function(minuend, subtrahend) {
  15604. return minuend - subtrahend;
  15605. }, 0);
  15606. /**
  15607. * Computes the sum of the values in `array`.
  15608. *
  15609. * @static
  15610. * @memberOf _
  15611. * @since 3.4.0
  15612. * @category Math
  15613. * @param {Array} array The array to iterate over.
  15614. * @returns {number} Returns the sum.
  15615. * @example
  15616. *
  15617. * _.sum([4, 2, 8, 6]);
  15618. * // => 20
  15619. */
  15620. function sum(array) {
  15621. return (array && array.length)
  15622. ? baseSum(array, identity)
  15623. : 0;
  15624. }
  15625. /**
  15626. * This method is like `_.sum` except that it accepts `iteratee` which is
  15627. * invoked for each element in `array` to generate the value to be summed.
  15628. * The iteratee is invoked with one argument: (value).
  15629. *
  15630. * @static
  15631. * @memberOf _
  15632. * @since 4.0.0
  15633. * @category Math
  15634. * @param {Array} array The array to iterate over.
  15635. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15636. * @returns {number} Returns the sum.
  15637. * @example
  15638. *
  15639. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15640. *
  15641. * _.sumBy(objects, function(o) { return o.n; });
  15642. * // => 20
  15643. *
  15644. * // The `_.property` iteratee shorthand.
  15645. * _.sumBy(objects, 'n');
  15646. * // => 20
  15647. */
  15648. function sumBy(array, iteratee) {
  15649. return (array && array.length)
  15650. ? baseSum(array, getIteratee(iteratee, 2))
  15651. : 0;
  15652. }
  15653. /*------------------------------------------------------------------------*/
  15654. // Add methods that return wrapped values in chain sequences.
  15655. lodash.after = after;
  15656. lodash.ary = ary;
  15657. lodash.assign = assign;
  15658. lodash.assignIn = assignIn;
  15659. lodash.assignInWith = assignInWith;
  15660. lodash.assignWith = assignWith;
  15661. lodash.at = at;
  15662. lodash.before = before;
  15663. lodash.bind = bind;
  15664. lodash.bindAll = bindAll;
  15665. lodash.bindKey = bindKey;
  15666. lodash.castArray = castArray;
  15667. lodash.chain = chain;
  15668. lodash.chunk = chunk;
  15669. lodash.compact = compact;
  15670. lodash.concat = concat;
  15671. lodash.cond = cond;
  15672. lodash.conforms = conforms;
  15673. lodash.constant = constant;
  15674. lodash.countBy = countBy;
  15675. lodash.create = create;
  15676. lodash.curry = curry;
  15677. lodash.curryRight = curryRight;
  15678. lodash.debounce = debounce;
  15679. lodash.defaults = defaults;
  15680. lodash.defaultsDeep = defaultsDeep;
  15681. lodash.defer = defer;
  15682. lodash.delay = delay;
  15683. lodash.difference = difference;
  15684. lodash.differenceBy = differenceBy;
  15685. lodash.differenceWith = differenceWith;
  15686. lodash.drop = drop;
  15687. lodash.dropRight = dropRight;
  15688. lodash.dropRightWhile = dropRightWhile;
  15689. lodash.dropWhile = dropWhile;
  15690. lodash.fill = fill;
  15691. lodash.filter = filter;
  15692. lodash.flatMap = flatMap;
  15693. lodash.flatMapDeep = flatMapDeep;
  15694. lodash.flatMapDepth = flatMapDepth;
  15695. lodash.flatten = flatten;
  15696. lodash.flattenDeep = flattenDeep;
  15697. lodash.flattenDepth = flattenDepth;
  15698. lodash.flip = flip;
  15699. lodash.flow = flow;
  15700. lodash.flowRight = flowRight;
  15701. lodash.fromPairs = fromPairs;
  15702. lodash.functions = functions;
  15703. lodash.functionsIn = functionsIn;
  15704. lodash.groupBy = groupBy;
  15705. lodash.initial = initial;
  15706. lodash.intersection = intersection;
  15707. lodash.intersectionBy = intersectionBy;
  15708. lodash.intersectionWith = intersectionWith;
  15709. lodash.invert = invert;
  15710. lodash.invertBy = invertBy;
  15711. lodash.invokeMap = invokeMap;
  15712. lodash.iteratee = iteratee;
  15713. lodash.keyBy = keyBy;
  15714. lodash.keys = keys;
  15715. lodash.keysIn = keysIn;
  15716. lodash.map = map;
  15717. lodash.mapKeys = mapKeys;
  15718. lodash.mapValues = mapValues;
  15719. lodash.matches = matches;
  15720. lodash.matchesProperty = matchesProperty;
  15721. lodash.memoize = memoize;
  15722. lodash.merge = merge;
  15723. lodash.mergeWith = mergeWith;
  15724. lodash.method = method;
  15725. lodash.methodOf = methodOf;
  15726. lodash.mixin = mixin;
  15727. lodash.negate = negate;
  15728. lodash.nthArg = nthArg;
  15729. lodash.omit = omit;
  15730. lodash.omitBy = omitBy;
  15731. lodash.once = once;
  15732. lodash.orderBy = orderBy;
  15733. lodash.over = over;
  15734. lodash.overArgs = overArgs;
  15735. lodash.overEvery = overEvery;
  15736. lodash.overSome = overSome;
  15737. lodash.partial = partial;
  15738. lodash.partialRight = partialRight;
  15739. lodash.partition = partition;
  15740. lodash.pick = pick;
  15741. lodash.pickBy = pickBy;
  15742. lodash.property = property;
  15743. lodash.propertyOf = propertyOf;
  15744. lodash.pull = pull;
  15745. lodash.pullAll = pullAll;
  15746. lodash.pullAllBy = pullAllBy;
  15747. lodash.pullAllWith = pullAllWith;
  15748. lodash.pullAt = pullAt;
  15749. lodash.range = range;
  15750. lodash.rangeRight = rangeRight;
  15751. lodash.rearg = rearg;
  15752. lodash.reject = reject;
  15753. lodash.remove = remove;
  15754. lodash.rest = rest;
  15755. lodash.reverse = reverse;
  15756. lodash.sampleSize = sampleSize;
  15757. lodash.set = set;
  15758. lodash.setWith = setWith;
  15759. lodash.shuffle = shuffle;
  15760. lodash.slice = slice;
  15761. lodash.sortBy = sortBy;
  15762. lodash.sortedUniq = sortedUniq;
  15763. lodash.sortedUniqBy = sortedUniqBy;
  15764. lodash.split = split;
  15765. lodash.spread = spread;
  15766. lodash.tail = tail;
  15767. lodash.take = take;
  15768. lodash.takeRight = takeRight;
  15769. lodash.takeRightWhile = takeRightWhile;
  15770. lodash.takeWhile = takeWhile;
  15771. lodash.tap = tap;
  15772. lodash.throttle = throttle;
  15773. lodash.thru = thru;
  15774. lodash.toArray = toArray;
  15775. lodash.toPairs = toPairs;
  15776. lodash.toPairsIn = toPairsIn;
  15777. lodash.toPath = toPath;
  15778. lodash.toPlainObject = toPlainObject;
  15779. lodash.transform = transform;
  15780. lodash.unary = unary;
  15781. lodash.union = union;
  15782. lodash.unionBy = unionBy;
  15783. lodash.unionWith = unionWith;
  15784. lodash.uniq = uniq;
  15785. lodash.uniqBy = uniqBy;
  15786. lodash.uniqWith = uniqWith;
  15787. lodash.unset = unset;
  15788. lodash.unzip = unzip;
  15789. lodash.unzipWith = unzipWith;
  15790. lodash.update = update;
  15791. lodash.updateWith = updateWith;
  15792. lodash.values = values;
  15793. lodash.valuesIn = valuesIn;
  15794. lodash.without = without;
  15795. lodash.words = words;
  15796. lodash.wrap = wrap;
  15797. lodash.xor = xor;
  15798. lodash.xorBy = xorBy;
  15799. lodash.xorWith = xorWith;
  15800. lodash.zip = zip;
  15801. lodash.zipObject = zipObject;
  15802. lodash.zipObjectDeep = zipObjectDeep;
  15803. lodash.zipWith = zipWith;
  15804. // Add aliases.
  15805. lodash.entries = toPairs;
  15806. lodash.entriesIn = toPairsIn;
  15807. lodash.extend = assignIn;
  15808. lodash.extendWith = assignInWith;
  15809. // Add methods to `lodash.prototype`.
  15810. mixin(lodash, lodash);
  15811. /*------------------------------------------------------------------------*/
  15812. // Add methods that return unwrapped values in chain sequences.
  15813. lodash.add = add;
  15814. lodash.attempt = attempt;
  15815. lodash.camelCase = camelCase;
  15816. lodash.capitalize = capitalize;
  15817. lodash.ceil = ceil;
  15818. lodash.clamp = clamp;
  15819. lodash.clone = clone;
  15820. lodash.cloneDeep = cloneDeep;
  15821. lodash.cloneDeepWith = cloneDeepWith;
  15822. lodash.cloneWith = cloneWith;
  15823. lodash.conformsTo = conformsTo;
  15824. lodash.deburr = deburr;
  15825. lodash.defaultTo = defaultTo;
  15826. lodash.divide = divide;
  15827. lodash.endsWith = endsWith;
  15828. lodash.eq = eq;
  15829. lodash.escape = escape;
  15830. lodash.escapeRegExp = escapeRegExp;
  15831. lodash.every = every;
  15832. lodash.find = find;
  15833. lodash.findIndex = findIndex;
  15834. lodash.findKey = findKey;
  15835. lodash.findLast = findLast;
  15836. lodash.findLastIndex = findLastIndex;
  15837. lodash.findLastKey = findLastKey;
  15838. lodash.floor = floor;
  15839. lodash.forEach = forEach;
  15840. lodash.forEachRight = forEachRight;
  15841. lodash.forIn = forIn;
  15842. lodash.forInRight = forInRight;
  15843. lodash.forOwn = forOwn;
  15844. lodash.forOwnRight = forOwnRight;
  15845. lodash.get = get;
  15846. lodash.gt = gt;
  15847. lodash.gte = gte;
  15848. lodash.has = has;
  15849. lodash.hasIn = hasIn;
  15850. lodash.head = head;
  15851. lodash.identity = identity;
  15852. lodash.includes = includes;
  15853. lodash.indexOf = indexOf;
  15854. lodash.inRange = inRange;
  15855. lodash.invoke = invoke;
  15856. lodash.isArguments = isArguments;
  15857. lodash.isArray = isArray;
  15858. lodash.isArrayBuffer = isArrayBuffer;
  15859. lodash.isArrayLike = isArrayLike;
  15860. lodash.isArrayLikeObject = isArrayLikeObject;
  15861. lodash.isBoolean = isBoolean;
  15862. lodash.isBuffer = isBuffer;
  15863. lodash.isDate = isDate;
  15864. lodash.isElement = isElement;
  15865. lodash.isEmpty = isEmpty;
  15866. lodash.isEqual = isEqual;
  15867. lodash.isEqualWith = isEqualWith;
  15868. lodash.isError = isError;
  15869. lodash.isFinite = isFinite;
  15870. lodash.isFunction = isFunction;
  15871. lodash.isInteger = isInteger;
  15872. lodash.isLength = isLength;
  15873. lodash.isMap = isMap;
  15874. lodash.isMatch = isMatch;
  15875. lodash.isMatchWith = isMatchWith;
  15876. lodash.isNaN = isNaN;
  15877. lodash.isNative = isNative;
  15878. lodash.isNil = isNil;
  15879. lodash.isNull = isNull;
  15880. lodash.isNumber = isNumber;
  15881. lodash.isObject = isObject;
  15882. lodash.isObjectLike = isObjectLike;
  15883. lodash.isPlainObject = isPlainObject;
  15884. lodash.isRegExp = isRegExp;
  15885. lodash.isSafeInteger = isSafeInteger;
  15886. lodash.isSet = isSet;
  15887. lodash.isString = isString;
  15888. lodash.isSymbol = isSymbol;
  15889. lodash.isTypedArray = isTypedArray;
  15890. lodash.isUndefined = isUndefined;
  15891. lodash.isWeakMap = isWeakMap;
  15892. lodash.isWeakSet = isWeakSet;
  15893. lodash.join = join;
  15894. lodash.kebabCase = kebabCase;
  15895. lodash.last = last;
  15896. lodash.lastIndexOf = lastIndexOf;
  15897. lodash.lowerCase = lowerCase;
  15898. lodash.lowerFirst = lowerFirst;
  15899. lodash.lt = lt;
  15900. lodash.lte = lte;
  15901. lodash.max = max;
  15902. lodash.maxBy = maxBy;
  15903. lodash.mean = mean;
  15904. lodash.meanBy = meanBy;
  15905. lodash.min = min;
  15906. lodash.minBy = minBy;
  15907. lodash.stubArray = stubArray;
  15908. lodash.stubFalse = stubFalse;
  15909. lodash.stubObject = stubObject;
  15910. lodash.stubString = stubString;
  15911. lodash.stubTrue = stubTrue;
  15912. lodash.multiply = multiply;
  15913. lodash.nth = nth;
  15914. lodash.noConflict = noConflict;
  15915. lodash.noop = noop;
  15916. lodash.now = now;
  15917. lodash.pad = pad;
  15918. lodash.padEnd = padEnd;
  15919. lodash.padStart = padStart;
  15920. lodash.parseInt = parseInt;
  15921. lodash.random = random;
  15922. lodash.reduce = reduce;
  15923. lodash.reduceRight = reduceRight;
  15924. lodash.repeat = repeat;
  15925. lodash.replace = replace;
  15926. lodash.result = result;
  15927. lodash.round = round;
  15928. lodash.runInContext = runInContext;
  15929. lodash.sample = sample;
  15930. lodash.size = size;
  15931. lodash.snakeCase = snakeCase;
  15932. lodash.some = some;
  15933. lodash.sortedIndex = sortedIndex;
  15934. lodash.sortedIndexBy = sortedIndexBy;
  15935. lodash.sortedIndexOf = sortedIndexOf;
  15936. lodash.sortedLastIndex = sortedLastIndex;
  15937. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15938. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15939. lodash.startCase = startCase;
  15940. lodash.startsWith = startsWith;
  15941. lodash.subtract = subtract;
  15942. lodash.sum = sum;
  15943. lodash.sumBy = sumBy;
  15944. lodash.template = template;
  15945. lodash.times = times;
  15946. lodash.toFinite = toFinite;
  15947. lodash.toInteger = toInteger;
  15948. lodash.toLength = toLength;
  15949. lodash.toLower = toLower;
  15950. lodash.toNumber = toNumber;
  15951. lodash.toSafeInteger = toSafeInteger;
  15952. lodash.toString = toString;
  15953. lodash.toUpper = toUpper;
  15954. lodash.trim = trim;
  15955. lodash.trimEnd = trimEnd;
  15956. lodash.trimStart = trimStart;
  15957. lodash.truncate = truncate;
  15958. lodash.unescape = unescape;
  15959. lodash.uniqueId = uniqueId;
  15960. lodash.upperCase = upperCase;
  15961. lodash.upperFirst = upperFirst;
  15962. // Add aliases.
  15963. lodash.each = forEach;
  15964. lodash.eachRight = forEachRight;
  15965. lodash.first = head;
  15966. mixin(lodash, (function() {
  15967. var source = {};
  15968. baseForOwn(lodash, function(func, methodName) {
  15969. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15970. source[methodName] = func;
  15971. }
  15972. });
  15973. return source;
  15974. }()), { 'chain': false });
  15975. /*------------------------------------------------------------------------*/
  15976. /**
  15977. * The semantic version number.
  15978. *
  15979. * @static
  15980. * @memberOf _
  15981. * @type {string}
  15982. */
  15983. lodash.VERSION = VERSION;
  15984. // Assign default placeholders.
  15985. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15986. lodash[methodName].placeholder = lodash;
  15987. });
  15988. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15989. arrayEach(['drop', 'take'], function(methodName, index) {
  15990. LazyWrapper.prototype[methodName] = function(n) {
  15991. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15992. var result = (this.__filtered__ && !index)
  15993. ? new LazyWrapper(this)
  15994. : this.clone();
  15995. if (result.__filtered__) {
  15996. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15997. } else {
  15998. result.__views__.push({
  15999. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  16000. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  16001. });
  16002. }
  16003. return result;
  16004. };
  16005. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  16006. return this.reverse()[methodName](n).reverse();
  16007. };
  16008. });
  16009. // Add `LazyWrapper` methods that accept an `iteratee` value.
  16010. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  16011. var type = index + 1,
  16012. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  16013. LazyWrapper.prototype[methodName] = function(iteratee) {
  16014. var result = this.clone();
  16015. result.__iteratees__.push({
  16016. 'iteratee': getIteratee(iteratee, 3),
  16017. 'type': type
  16018. });
  16019. result.__filtered__ = result.__filtered__ || isFilter;
  16020. return result;
  16021. };
  16022. });
  16023. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  16024. arrayEach(['head', 'last'], function(methodName, index) {
  16025. var takeName = 'take' + (index ? 'Right' : '');
  16026. LazyWrapper.prototype[methodName] = function() {
  16027. return this[takeName](1).value()[0];
  16028. };
  16029. });
  16030. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  16031. arrayEach(['initial', 'tail'], function(methodName, index) {
  16032. var dropName = 'drop' + (index ? '' : 'Right');
  16033. LazyWrapper.prototype[methodName] = function() {
  16034. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  16035. };
  16036. });
  16037. LazyWrapper.prototype.compact = function() {
  16038. return this.filter(identity);
  16039. };
  16040. LazyWrapper.prototype.find = function(predicate) {
  16041. return this.filter(predicate).head();
  16042. };
  16043. LazyWrapper.prototype.findLast = function(predicate) {
  16044. return this.reverse().find(predicate);
  16045. };
  16046. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  16047. if (typeof path == 'function') {
  16048. return new LazyWrapper(this);
  16049. }
  16050. return this.map(function(value) {
  16051. return baseInvoke(value, path, args);
  16052. });
  16053. });
  16054. LazyWrapper.prototype.reject = function(predicate) {
  16055. return this.filter(negate(getIteratee(predicate)));
  16056. };
  16057. LazyWrapper.prototype.slice = function(start, end) {
  16058. start = toInteger(start);
  16059. var result = this;
  16060. if (result.__filtered__ && (start > 0 || end < 0)) {
  16061. return new LazyWrapper(result);
  16062. }
  16063. if (start < 0) {
  16064. result = result.takeRight(-start);
  16065. } else if (start) {
  16066. result = result.drop(start);
  16067. }
  16068. if (end !== undefined) {
  16069. end = toInteger(end);
  16070. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16071. }
  16072. return result;
  16073. };
  16074. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16075. return this.reverse().takeWhile(predicate).reverse();
  16076. };
  16077. LazyWrapper.prototype.toArray = function() {
  16078. return this.take(MAX_ARRAY_LENGTH);
  16079. };
  16080. // Add `LazyWrapper` methods to `lodash.prototype`.
  16081. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16082. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16083. isTaker = /^(?:head|last)$/.test(methodName),
  16084. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16085. retUnwrapped = isTaker || /^find/.test(methodName);
  16086. if (!lodashFunc) {
  16087. return;
  16088. }
  16089. lodash.prototype[methodName] = function() {
  16090. var value = this.__wrapped__,
  16091. args = isTaker ? [1] : arguments,
  16092. isLazy = value instanceof LazyWrapper,
  16093. iteratee = args[0],
  16094. useLazy = isLazy || isArray(value);
  16095. var interceptor = function(value) {
  16096. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16097. return (isTaker && chainAll) ? result[0] : result;
  16098. };
  16099. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16100. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16101. isLazy = useLazy = false;
  16102. }
  16103. var chainAll = this.__chain__,
  16104. isHybrid = !!this.__actions__.length,
  16105. isUnwrapped = retUnwrapped && !chainAll,
  16106. onlyLazy = isLazy && !isHybrid;
  16107. if (!retUnwrapped && useLazy) {
  16108. value = onlyLazy ? value : new LazyWrapper(this);
  16109. var result = func.apply(value, args);
  16110. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16111. return new LodashWrapper(result, chainAll);
  16112. }
  16113. if (isUnwrapped && onlyLazy) {
  16114. return func.apply(this, args);
  16115. }
  16116. result = this.thru(interceptor);
  16117. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16118. };
  16119. });
  16120. // Add `Array` methods to `lodash.prototype`.
  16121. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16122. var func = arrayProto[methodName],
  16123. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16124. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16125. lodash.prototype[methodName] = function() {
  16126. var args = arguments;
  16127. if (retUnwrapped && !this.__chain__) {
  16128. var value = this.value();
  16129. return func.apply(isArray(value) ? value : [], args);
  16130. }
  16131. return this[chainName](function(value) {
  16132. return func.apply(isArray(value) ? value : [], args);
  16133. });
  16134. };
  16135. });
  16136. // Map minified method names to their real names.
  16137. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16138. var lodashFunc = lodash[methodName];
  16139. if (lodashFunc) {
  16140. var key = lodashFunc.name + '';
  16141. if (!hasOwnProperty.call(realNames, key)) {
  16142. realNames[key] = [];
  16143. }
  16144. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16145. }
  16146. });
  16147. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16148. 'name': 'wrapper',
  16149. 'func': undefined
  16150. }];
  16151. // Add methods to `LazyWrapper`.
  16152. LazyWrapper.prototype.clone = lazyClone;
  16153. LazyWrapper.prototype.reverse = lazyReverse;
  16154. LazyWrapper.prototype.value = lazyValue;
  16155. // Add chain sequence methods to the `lodash` wrapper.
  16156. lodash.prototype.at = wrapperAt;
  16157. lodash.prototype.chain = wrapperChain;
  16158. lodash.prototype.commit = wrapperCommit;
  16159. lodash.prototype.next = wrapperNext;
  16160. lodash.prototype.plant = wrapperPlant;
  16161. lodash.prototype.reverse = wrapperReverse;
  16162. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16163. // Add lazy aliases.
  16164. lodash.prototype.first = lodash.prototype.head;
  16165. if (symIterator) {
  16166. lodash.prototype[symIterator] = wrapperToIterator;
  16167. }
  16168. return lodash;
  16169. });
  16170. /*--------------------------------------------------------------------------*/
  16171. // Export lodash.
  16172. var _ = runInContext();
  16173. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16174. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16175. // Expose Lodash on the global object to prevent errors when Lodash is
  16176. // loaded by a script tag in the presence of an AMD loader.
  16177. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16178. // Use `_.noConflict` to remove Lodash from the global object.
  16179. root._ = _;
  16180. // Define as an anonymous module so, through path mapping, it can be
  16181. // referenced as the "underscore" module.
  16182. define(function() {
  16183. return _;
  16184. });
  16185. }
  16186. // Check for `exports` after `define` in case a build optimizer adds it.
  16187. else if (freeModule) {
  16188. // Export for Node.js.
  16189. (freeModule.exports = _)._ = _;
  16190. // Export for CommonJS support.
  16191. freeExports._ = _;
  16192. }
  16193. else {
  16194. // Export to the global object.
  16195. root._ = _;
  16196. }
  16197. }.call(this));