lodash.js 531 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210
  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.17.21';
  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. /** Used to stand-in for `undefined` hash values. */
  21. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  22. /** Used as the maximum memoize cache size. */
  23. var MAX_MEMOIZE_SIZE = 500;
  24. /** Used as the internal argument placeholder. */
  25. var PLACEHOLDER = '__lodash_placeholder__';
  26. /** Used to compose bitmasks for cloning. */
  27. var CLONE_DEEP_FLAG = 1,
  28. CLONE_FLAT_FLAG = 2,
  29. CLONE_SYMBOLS_FLAG = 4;
  30. /** Used to compose bitmasks for value comparisons. */
  31. var COMPARE_PARTIAL_FLAG = 1,
  32. COMPARE_UNORDERED_FLAG = 2;
  33. /** Used to compose bitmasks for function metadata. */
  34. var WRAP_BIND_FLAG = 1,
  35. WRAP_BIND_KEY_FLAG = 2,
  36. WRAP_CURRY_BOUND_FLAG = 4,
  37. WRAP_CURRY_FLAG = 8,
  38. WRAP_CURRY_RIGHT_FLAG = 16,
  39. WRAP_PARTIAL_FLAG = 32,
  40. WRAP_PARTIAL_RIGHT_FLAG = 64,
  41. WRAP_ARY_FLAG = 128,
  42. WRAP_REARG_FLAG = 256,
  43. WRAP_FLIP_FLAG = 512;
  44. /** Used as default options for `_.truncate`. */
  45. var DEFAULT_TRUNC_LENGTH = 30,
  46. DEFAULT_TRUNC_OMISSION = '...';
  47. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  48. var HOT_COUNT = 800,
  49. HOT_SPAN = 16;
  50. /** Used to indicate the type of lazy iteratees. */
  51. var LAZY_FILTER_FLAG = 1,
  52. LAZY_MAP_FLAG = 2,
  53. LAZY_WHILE_FLAG = 3;
  54. /** Used as references for various `Number` constants. */
  55. var INFINITY = 1 / 0,
  56. MAX_SAFE_INTEGER = 9007199254740991,
  57. MAX_INTEGER = 1.7976931348623157e+308,
  58. NAN = 0 / 0;
  59. /** Used as references for the maximum length and index of an array. */
  60. var MAX_ARRAY_LENGTH = 4294967295,
  61. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  62. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  63. /** Used to associate wrap methods with their bit flags. */
  64. var wrapFlags = [
  65. ['ary', WRAP_ARY_FLAG],
  66. ['bind', WRAP_BIND_FLAG],
  67. ['bindKey', WRAP_BIND_KEY_FLAG],
  68. ['curry', WRAP_CURRY_FLAG],
  69. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  70. ['flip', WRAP_FLIP_FLAG],
  71. ['partial', WRAP_PARTIAL_FLAG],
  72. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  73. ['rearg', WRAP_REARG_FLAG]
  74. ];
  75. /** `Object#toString` result references. */
  76. var argsTag = '[object Arguments]',
  77. arrayTag = '[object Array]',
  78. asyncTag = '[object AsyncFunction]',
  79. boolTag = '[object Boolean]',
  80. dateTag = '[object Date]',
  81. domExcTag = '[object DOMException]',
  82. errorTag = '[object Error]',
  83. funcTag = '[object Function]',
  84. genTag = '[object GeneratorFunction]',
  85. mapTag = '[object Map]',
  86. numberTag = '[object Number]',
  87. nullTag = '[object Null]',
  88. objectTag = '[object Object]',
  89. promiseTag = '[object Promise]',
  90. proxyTag = '[object Proxy]',
  91. regexpTag = '[object RegExp]',
  92. setTag = '[object Set]',
  93. stringTag = '[object String]',
  94. symbolTag = '[object Symbol]',
  95. undefinedTag = '[object Undefined]',
  96. weakMapTag = '[object WeakMap]',
  97. weakSetTag = '[object WeakSet]';
  98. var arrayBufferTag = '[object ArrayBuffer]',
  99. dataViewTag = '[object DataView]',
  100. float32Tag = '[object Float32Array]',
  101. float64Tag = '[object Float64Array]',
  102. int8Tag = '[object Int8Array]',
  103. int16Tag = '[object Int16Array]',
  104. int32Tag = '[object Int32Array]',
  105. uint8Tag = '[object Uint8Array]',
  106. uint8ClampedTag = '[object Uint8ClampedArray]',
  107. uint16Tag = '[object Uint16Array]',
  108. uint32Tag = '[object Uint32Array]';
  109. /** Used to match empty string literals in compiled template source. */
  110. var reEmptyStringLeading = /\b__p \+= '';/g,
  111. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  112. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  113. /** Used to match HTML entities and HTML characters. */
  114. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  115. reUnescapedHtml = /[&<>"']/g,
  116. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  117. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  118. /** Used to match template delimiters. */
  119. var reEscape = /<%-([\s\S]+?)%>/g,
  120. reEvaluate = /<%([\s\S]+?)%>/g,
  121. reInterpolate = /<%=([\s\S]+?)%>/g;
  122. /** Used to match property names within property paths. */
  123. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  124. reIsPlainProp = /^\w*$/,
  125. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  126. /**
  127. * Used to match `RegExp`
  128. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  129. */
  130. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  131. reHasRegExpChar = RegExp(reRegExpChar.source);
  132. /** Used to match leading whitespace. */
  133. var reTrimStart = /^\s+/;
  134. /** Used to match a single whitespace character. */
  135. var reWhitespace = /\s/;
  136. /** Used to match wrap detail comments. */
  137. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  138. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  139. reSplitDetails = /,? & /;
  140. /** Used to match words composed of alphanumeric characters. */
  141. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  142. /**
  143. * Used to validate the `validate` option in `_.template` variable.
  144. *
  145. * Forbids characters which could potentially change the meaning of the function argument definition:
  146. * - "()," (modification of function parameters)
  147. * - "=" (default value)
  148. * - "[]{}" (destructuring of function parameters)
  149. * - "/" (beginning of a comment)
  150. * - whitespace
  151. */
  152. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  153. /** Used to match backslashes in property paths. */
  154. var reEscapeChar = /\\(\\)?/g;
  155. /**
  156. * Used to match
  157. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  158. */
  159. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  160. /** Used to match `RegExp` flags from their coerced string values. */
  161. var reFlags = /\w*$/;
  162. /** Used to detect bad signed hexadecimal string values. */
  163. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  164. /** Used to detect binary string values. */
  165. var reIsBinary = /^0b[01]+$/i;
  166. /** Used to detect host constructors (Safari). */
  167. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  168. /** Used to detect octal string values. */
  169. var reIsOctal = /^0o[0-7]+$/i;
  170. /** Used to detect unsigned integer values. */
  171. var reIsUint = /^(?:0|[1-9]\d*)$/;
  172. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  173. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  174. /** Used to ensure capturing order of template delimiters. */
  175. var reNoMatch = /($^)/;
  176. /** Used to match unescaped characters in compiled string literals. */
  177. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  178. /** Used to compose unicode character classes. */
  179. var rsAstralRange = '\\ud800-\\udfff',
  180. rsComboMarksRange = '\\u0300-\\u036f',
  181. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  182. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  183. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  184. rsDingbatRange = '\\u2700-\\u27bf',
  185. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  186. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  187. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  188. rsPunctuationRange = '\\u2000-\\u206f',
  189. 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',
  190. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  191. rsVarRange = '\\ufe0e\\ufe0f',
  192. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  193. /** Used to compose unicode capture groups. */
  194. var rsApos = "['\u2019]",
  195. rsAstral = '[' + rsAstralRange + ']',
  196. rsBreak = '[' + rsBreakRange + ']',
  197. rsCombo = '[' + rsComboRange + ']',
  198. rsDigits = '\\d+',
  199. rsDingbat = '[' + rsDingbatRange + ']',
  200. rsLower = '[' + rsLowerRange + ']',
  201. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  202. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  203. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  204. rsNonAstral = '[^' + rsAstralRange + ']',
  205. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  206. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  207. rsUpper = '[' + rsUpperRange + ']',
  208. rsZWJ = '\\u200d';
  209. /** Used to compose unicode regexes. */
  210. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  211. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  212. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  213. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  214. reOptMod = rsModifier + '?',
  215. rsOptVar = '[' + rsVarRange + ']?',
  216. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  217. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  218. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  219. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  220. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  221. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  222. /** Used to match apostrophes. */
  223. var reApos = RegExp(rsApos, 'g');
  224. /**
  225. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  226. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  227. */
  228. var reComboMark = RegExp(rsCombo, 'g');
  229. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  230. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  231. /** Used to match complex or compound words. */
  232. var reUnicodeWord = RegExp([
  233. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  234. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  235. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  236. rsUpper + '+' + rsOptContrUpper,
  237. rsOrdUpper,
  238. rsOrdLower,
  239. rsDigits,
  240. rsEmoji
  241. ].join('|'), 'g');
  242. /** 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/). */
  243. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  244. /** Used to detect strings that need a more robust regexp to match words. */
  245. 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 ]/;
  246. /** Used to assign default `context` object properties. */
  247. var contextProps = [
  248. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  249. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  250. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  251. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  252. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  253. ];
  254. /** Used to make template sourceURLs easier to identify. */
  255. var templateCounter = -1;
  256. /** Used to identify `toStringTag` values of typed arrays. */
  257. var typedArrayTags = {};
  258. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  259. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  260. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  261. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  262. typedArrayTags[uint32Tag] = true;
  263. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  264. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  265. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  266. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  267. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  268. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  269. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  270. typedArrayTags[weakMapTag] = false;
  271. /** Used to identify `toStringTag` values supported by `_.clone`. */
  272. var cloneableTags = {};
  273. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  274. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  275. cloneableTags[boolTag] = cloneableTags[dateTag] =
  276. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  277. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  278. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  279. cloneableTags[numberTag] = cloneableTags[objectTag] =
  280. cloneableTags[regexpTag] = cloneableTags[setTag] =
  281. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  282. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  283. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  284. cloneableTags[errorTag] = cloneableTags[funcTag] =
  285. cloneableTags[weakMapTag] = false;
  286. /** Used to map Latin Unicode letters to basic Latin letters. */
  287. var deburredLetters = {
  288. // Latin-1 Supplement block.
  289. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  290. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  291. '\xc7': 'C', '\xe7': 'c',
  292. '\xd0': 'D', '\xf0': 'd',
  293. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  294. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  295. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  296. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  297. '\xd1': 'N', '\xf1': 'n',
  298. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  299. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  300. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  301. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  302. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  303. '\xc6': 'Ae', '\xe6': 'ae',
  304. '\xde': 'Th', '\xfe': 'th',
  305. '\xdf': 'ss',
  306. // Latin Extended-A block.
  307. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  308. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  309. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  310. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  311. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  312. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  313. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  314. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  315. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  316. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  317. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  318. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  319. '\u0134': 'J', '\u0135': 'j',
  320. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  321. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  322. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  323. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  324. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  325. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  326. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  327. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  328. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  329. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  330. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  331. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  332. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  333. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  334. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  335. '\u0174': 'W', '\u0175': 'w',
  336. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  337. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  338. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  339. '\u0132': 'IJ', '\u0133': 'ij',
  340. '\u0152': 'Oe', '\u0153': 'oe',
  341. '\u0149': "'n", '\u017f': 's'
  342. };
  343. /** Used to map characters to HTML entities. */
  344. var htmlEscapes = {
  345. '&': '&amp;',
  346. '<': '&lt;',
  347. '>': '&gt;',
  348. '"': '&quot;',
  349. "'": '&#39;'
  350. };
  351. /** Used to map HTML entities to characters. */
  352. var htmlUnescapes = {
  353. '&amp;': '&',
  354. '&lt;': '<',
  355. '&gt;': '>',
  356. '&quot;': '"',
  357. '&#39;': "'"
  358. };
  359. /** Used to escape characters for inclusion in compiled string literals. */
  360. var stringEscapes = {
  361. '\\': '\\',
  362. "'": "'",
  363. '\n': 'n',
  364. '\r': 'r',
  365. '\u2028': 'u2028',
  366. '\u2029': 'u2029'
  367. };
  368. /** Built-in method references without a dependency on `root`. */
  369. var freeParseFloat = parseFloat,
  370. freeParseInt = parseInt;
  371. /** Detect free variable `global` from Node.js. */
  372. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  373. /** Detect free variable `self`. */
  374. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  375. /** Used as a reference to the global object. */
  376. var root = freeGlobal || freeSelf || Function('return this')();
  377. /** Detect free variable `exports`. */
  378. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  379. /** Detect free variable `module`. */
  380. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  381. /** Detect the popular CommonJS extension `module.exports`. */
  382. var moduleExports = freeModule && freeModule.exports === freeExports;
  383. /** Detect free variable `process` from Node.js. */
  384. var freeProcess = moduleExports && freeGlobal.process;
  385. /** Used to access faster Node.js helpers. */
  386. var nodeUtil = (function() {
  387. try {
  388. // Use `util.types` for Node.js 10+.
  389. var types = freeModule && freeModule.require && freeModule.require('util').types;
  390. if (types) {
  391. return types;
  392. }
  393. // Legacy `process.binding('util')` for Node.js < 10.
  394. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  395. } catch (e) {}
  396. }());
  397. /* Node.js helper references. */
  398. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  399. nodeIsDate = nodeUtil && nodeUtil.isDate,
  400. nodeIsMap = nodeUtil && nodeUtil.isMap,
  401. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  402. nodeIsSet = nodeUtil && nodeUtil.isSet,
  403. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  404. /*--------------------------------------------------------------------------*/
  405. /**
  406. * A faster alternative to `Function#apply`, this function invokes `func`
  407. * with the `this` binding of `thisArg` and the arguments of `args`.
  408. *
  409. * @private
  410. * @param {Function} func The function to invoke.
  411. * @param {*} thisArg The `this` binding of `func`.
  412. * @param {Array} args The arguments to invoke `func` with.
  413. * @returns {*} Returns the result of `func`.
  414. */
  415. function apply(func, thisArg, args) {
  416. switch (args.length) {
  417. case 0: return func.call(thisArg);
  418. case 1: return func.call(thisArg, args[0]);
  419. case 2: return func.call(thisArg, args[0], args[1]);
  420. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  421. }
  422. return func.apply(thisArg, args);
  423. }
  424. /**
  425. * A specialized version of `baseAggregator` for arrays.
  426. *
  427. * @private
  428. * @param {Array} [array] The array to iterate over.
  429. * @param {Function} setter The function to set `accumulator` values.
  430. * @param {Function} iteratee The iteratee to transform keys.
  431. * @param {Object} accumulator The initial aggregated object.
  432. * @returns {Function} Returns `accumulator`.
  433. */
  434. function arrayAggregator(array, setter, iteratee, accumulator) {
  435. var index = -1,
  436. length = array == null ? 0 : array.length;
  437. while (++index < length) {
  438. var value = array[index];
  439. setter(accumulator, value, iteratee(value), array);
  440. }
  441. return accumulator;
  442. }
  443. /**
  444. * A specialized version of `_.forEach` for arrays without support for
  445. * iteratee shorthands.
  446. *
  447. * @private
  448. * @param {Array} [array] The array to iterate over.
  449. * @param {Function} iteratee The function invoked per iteration.
  450. * @returns {Array} Returns `array`.
  451. */
  452. function arrayEach(array, iteratee) {
  453. var index = -1,
  454. length = array == null ? 0 : array.length;
  455. while (++index < length) {
  456. if (iteratee(array[index], index, array) === false) {
  457. break;
  458. }
  459. }
  460. return array;
  461. }
  462. /**
  463. * A specialized version of `_.forEachRight` for arrays without support for
  464. * iteratee shorthands.
  465. *
  466. * @private
  467. * @param {Array} [array] The array to iterate over.
  468. * @param {Function} iteratee The function invoked per iteration.
  469. * @returns {Array} Returns `array`.
  470. */
  471. function arrayEachRight(array, iteratee) {
  472. var length = array == null ? 0 : array.length;
  473. while (length--) {
  474. if (iteratee(array[length], length, array) === false) {
  475. break;
  476. }
  477. }
  478. return array;
  479. }
  480. /**
  481. * A specialized version of `_.every` for arrays without support for
  482. * iteratee shorthands.
  483. *
  484. * @private
  485. * @param {Array} [array] The array to iterate over.
  486. * @param {Function} predicate The function invoked per iteration.
  487. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  488. * else `false`.
  489. */
  490. function arrayEvery(array, predicate) {
  491. var index = -1,
  492. length = array == null ? 0 : array.length;
  493. while (++index < length) {
  494. if (!predicate(array[index], index, array)) {
  495. return false;
  496. }
  497. }
  498. return true;
  499. }
  500. /**
  501. * A specialized version of `_.filter` for arrays without support for
  502. * iteratee shorthands.
  503. *
  504. * @private
  505. * @param {Array} [array] The array to iterate over.
  506. * @param {Function} predicate The function invoked per iteration.
  507. * @returns {Array} Returns the new filtered array.
  508. */
  509. function arrayFilter(array, predicate) {
  510. var index = -1,
  511. length = array == null ? 0 : array.length,
  512. resIndex = 0,
  513. result = [];
  514. while (++index < length) {
  515. var value = array[index];
  516. if (predicate(value, index, array)) {
  517. result[resIndex++] = value;
  518. }
  519. }
  520. return result;
  521. }
  522. /**
  523. * A specialized version of `_.includes` for arrays without support for
  524. * specifying an index to search from.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  530. */
  531. function arrayIncludes(array, value) {
  532. var length = array == null ? 0 : array.length;
  533. return !!length && baseIndexOf(array, value, 0) > -1;
  534. }
  535. /**
  536. * This function is like `arrayIncludes` except that it accepts a comparator.
  537. *
  538. * @private
  539. * @param {Array} [array] The array to inspect.
  540. * @param {*} target The value to search for.
  541. * @param {Function} comparator The comparator invoked per element.
  542. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  543. */
  544. function arrayIncludesWith(array, value, comparator) {
  545. var index = -1,
  546. length = array == null ? 0 : array.length;
  547. while (++index < length) {
  548. if (comparator(value, array[index])) {
  549. return true;
  550. }
  551. }
  552. return false;
  553. }
  554. /**
  555. * A specialized version of `_.map` for arrays without support for iteratee
  556. * shorthands.
  557. *
  558. * @private
  559. * @param {Array} [array] The array to iterate over.
  560. * @param {Function} iteratee The function invoked per iteration.
  561. * @returns {Array} Returns the new mapped array.
  562. */
  563. function arrayMap(array, iteratee) {
  564. var index = -1,
  565. length = array == null ? 0 : array.length,
  566. result = Array(length);
  567. while (++index < length) {
  568. result[index] = iteratee(array[index], index, array);
  569. }
  570. return result;
  571. }
  572. /**
  573. * Appends the elements of `values` to `array`.
  574. *
  575. * @private
  576. * @param {Array} array The array to modify.
  577. * @param {Array} values The values to append.
  578. * @returns {Array} Returns `array`.
  579. */
  580. function arrayPush(array, values) {
  581. var index = -1,
  582. length = values.length,
  583. offset = array.length;
  584. while (++index < length) {
  585. array[offset + index] = values[index];
  586. }
  587. return array;
  588. }
  589. /**
  590. * A specialized version of `_.reduce` for arrays without support for
  591. * iteratee shorthands.
  592. *
  593. * @private
  594. * @param {Array} [array] The array to iterate over.
  595. * @param {Function} iteratee The function invoked per iteration.
  596. * @param {*} [accumulator] The initial value.
  597. * @param {boolean} [initAccum] Specify using the first element of `array` as
  598. * the initial value.
  599. * @returns {*} Returns the accumulated value.
  600. */
  601. function arrayReduce(array, iteratee, accumulator, initAccum) {
  602. var index = -1,
  603. length = array == null ? 0 : array.length;
  604. if (initAccum && length) {
  605. accumulator = array[++index];
  606. }
  607. while (++index < length) {
  608. accumulator = iteratee(accumulator, array[index], index, array);
  609. }
  610. return accumulator;
  611. }
  612. /**
  613. * A specialized version of `_.reduceRight` for arrays without support for
  614. * iteratee shorthands.
  615. *
  616. * @private
  617. * @param {Array} [array] The array to iterate over.
  618. * @param {Function} iteratee The function invoked per iteration.
  619. * @param {*} [accumulator] The initial value.
  620. * @param {boolean} [initAccum] Specify using the last element of `array` as
  621. * the initial value.
  622. * @returns {*} Returns the accumulated value.
  623. */
  624. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  625. var length = array == null ? 0 : array.length;
  626. if (initAccum && length) {
  627. accumulator = array[--length];
  628. }
  629. while (length--) {
  630. accumulator = iteratee(accumulator, array[length], length, array);
  631. }
  632. return accumulator;
  633. }
  634. /**
  635. * A specialized version of `_.some` for arrays without support for iteratee
  636. * shorthands.
  637. *
  638. * @private
  639. * @param {Array} [array] The array to iterate over.
  640. * @param {Function} predicate The function invoked per iteration.
  641. * @returns {boolean} Returns `true` if any element passes the predicate check,
  642. * else `false`.
  643. */
  644. function arraySome(array, predicate) {
  645. var index = -1,
  646. length = array == null ? 0 : array.length;
  647. while (++index < length) {
  648. if (predicate(array[index], index, array)) {
  649. return true;
  650. }
  651. }
  652. return false;
  653. }
  654. /**
  655. * Gets the size of an ASCII `string`.
  656. *
  657. * @private
  658. * @param {string} string The string inspect.
  659. * @returns {number} Returns the string size.
  660. */
  661. var asciiSize = baseProperty('length');
  662. /**
  663. * Converts an ASCII `string` to an array.
  664. *
  665. * @private
  666. * @param {string} string The string to convert.
  667. * @returns {Array} Returns the converted array.
  668. */
  669. function asciiToArray(string) {
  670. return string.split('');
  671. }
  672. /**
  673. * Splits an ASCII `string` into an array of its words.
  674. *
  675. * @private
  676. * @param {string} The string to inspect.
  677. * @returns {Array} Returns the words of `string`.
  678. */
  679. function asciiWords(string) {
  680. return string.match(reAsciiWord) || [];
  681. }
  682. /**
  683. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  684. * without support for iteratee shorthands, which iterates over `collection`
  685. * using `eachFunc`.
  686. *
  687. * @private
  688. * @param {Array|Object} collection The collection to inspect.
  689. * @param {Function} predicate The function invoked per iteration.
  690. * @param {Function} eachFunc The function to iterate over `collection`.
  691. * @returns {*} Returns the found element or its key, else `undefined`.
  692. */
  693. function baseFindKey(collection, predicate, eachFunc) {
  694. var result;
  695. eachFunc(collection, function(value, key, collection) {
  696. if (predicate(value, key, collection)) {
  697. result = key;
  698. return false;
  699. }
  700. });
  701. return result;
  702. }
  703. /**
  704. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  705. * support for iteratee shorthands.
  706. *
  707. * @private
  708. * @param {Array} array The array to inspect.
  709. * @param {Function} predicate The function invoked per iteration.
  710. * @param {number} fromIndex The index to search from.
  711. * @param {boolean} [fromRight] Specify iterating from right to left.
  712. * @returns {number} Returns the index of the matched value, else `-1`.
  713. */
  714. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  715. var length = array.length,
  716. index = fromIndex + (fromRight ? 1 : -1);
  717. while ((fromRight ? index-- : ++index < length)) {
  718. if (predicate(array[index], index, array)) {
  719. return index;
  720. }
  721. }
  722. return -1;
  723. }
  724. /**
  725. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  726. *
  727. * @private
  728. * @param {Array} array The array to inspect.
  729. * @param {*} value The value to search for.
  730. * @param {number} fromIndex The index to search from.
  731. * @returns {number} Returns the index of the matched value, else `-1`.
  732. */
  733. function baseIndexOf(array, value, fromIndex) {
  734. return value === value
  735. ? strictIndexOf(array, value, fromIndex)
  736. : baseFindIndex(array, baseIsNaN, fromIndex);
  737. }
  738. /**
  739. * This function is like `baseIndexOf` except that it accepts a comparator.
  740. *
  741. * @private
  742. * @param {Array} array The array to inspect.
  743. * @param {*} value The value to search for.
  744. * @param {number} fromIndex The index to search from.
  745. * @param {Function} comparator The comparator invoked per element.
  746. * @returns {number} Returns the index of the matched value, else `-1`.
  747. */
  748. function baseIndexOfWith(array, value, fromIndex, comparator) {
  749. var index = fromIndex - 1,
  750. length = array.length;
  751. while (++index < length) {
  752. if (comparator(array[index], value)) {
  753. return index;
  754. }
  755. }
  756. return -1;
  757. }
  758. /**
  759. * The base implementation of `_.isNaN` without support for number objects.
  760. *
  761. * @private
  762. * @param {*} value The value to check.
  763. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  764. */
  765. function baseIsNaN(value) {
  766. return value !== value;
  767. }
  768. /**
  769. * The base implementation of `_.mean` and `_.meanBy` without support for
  770. * iteratee shorthands.
  771. *
  772. * @private
  773. * @param {Array} array The array to iterate over.
  774. * @param {Function} iteratee The function invoked per iteration.
  775. * @returns {number} Returns the mean.
  776. */
  777. function baseMean(array, iteratee) {
  778. var length = array == null ? 0 : array.length;
  779. return length ? (baseSum(array, iteratee) / length) : NAN;
  780. }
  781. /**
  782. * The base implementation of `_.property` without support for deep paths.
  783. *
  784. * @private
  785. * @param {string} key The key of the property to get.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function baseProperty(key) {
  789. return function(object) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.propertyOf` without support for deep paths.
  795. *
  796. * @private
  797. * @param {Object} object The object to query.
  798. * @returns {Function} Returns the new accessor function.
  799. */
  800. function basePropertyOf(object) {
  801. return function(key) {
  802. return object == null ? undefined : object[key];
  803. };
  804. }
  805. /**
  806. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  807. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  808. *
  809. * @private
  810. * @param {Array|Object} collection The collection to iterate over.
  811. * @param {Function} iteratee The function invoked per iteration.
  812. * @param {*} accumulator The initial value.
  813. * @param {boolean} initAccum Specify using the first or last element of
  814. * `collection` as the initial value.
  815. * @param {Function} eachFunc The function to iterate over `collection`.
  816. * @returns {*} Returns the accumulated value.
  817. */
  818. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  819. eachFunc(collection, function(value, index, collection) {
  820. accumulator = initAccum
  821. ? (initAccum = false, value)
  822. : iteratee(accumulator, value, index, collection);
  823. });
  824. return accumulator;
  825. }
  826. /**
  827. * The base implementation of `_.sortBy` which uses `comparer` to define the
  828. * sort order of `array` and replaces criteria objects with their corresponding
  829. * values.
  830. *
  831. * @private
  832. * @param {Array} array The array to sort.
  833. * @param {Function} comparer The function to define sort order.
  834. * @returns {Array} Returns `array`.
  835. */
  836. function baseSortBy(array, comparer) {
  837. var length = array.length;
  838. array.sort(comparer);
  839. while (length--) {
  840. array[length] = array[length].value;
  841. }
  842. return array;
  843. }
  844. /**
  845. * The base implementation of `_.sum` and `_.sumBy` without support for
  846. * iteratee shorthands.
  847. *
  848. * @private
  849. * @param {Array} array The array to iterate over.
  850. * @param {Function} iteratee The function invoked per iteration.
  851. * @returns {number} Returns the sum.
  852. */
  853. function baseSum(array, iteratee) {
  854. var result,
  855. index = -1,
  856. length = array.length;
  857. while (++index < length) {
  858. var current = iteratee(array[index]);
  859. if (current !== undefined) {
  860. result = result === undefined ? current : (result + current);
  861. }
  862. }
  863. return result;
  864. }
  865. /**
  866. * The base implementation of `_.times` without support for iteratee shorthands
  867. * or max array length checks.
  868. *
  869. * @private
  870. * @param {number} n The number of times to invoke `iteratee`.
  871. * @param {Function} iteratee The function invoked per iteration.
  872. * @returns {Array} Returns the array of results.
  873. */
  874. function baseTimes(n, iteratee) {
  875. var index = -1,
  876. result = Array(n);
  877. while (++index < n) {
  878. result[index] = iteratee(index);
  879. }
  880. return result;
  881. }
  882. /**
  883. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  884. * of key-value pairs for `object` corresponding to the property names of `props`.
  885. *
  886. * @private
  887. * @param {Object} object The object to query.
  888. * @param {Array} props The property names to get values for.
  889. * @returns {Object} Returns the key-value pairs.
  890. */
  891. function baseToPairs(object, props) {
  892. return arrayMap(props, function(key) {
  893. return [key, object[key]];
  894. });
  895. }
  896. /**
  897. * The base implementation of `_.trim`.
  898. *
  899. * @private
  900. * @param {string} string The string to trim.
  901. * @returns {string} Returns the trimmed string.
  902. */
  903. function baseTrim(string) {
  904. return string
  905. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  906. : string;
  907. }
  908. /**
  909. * The base implementation of `_.unary` without support for storing metadata.
  910. *
  911. * @private
  912. * @param {Function} func The function to cap arguments for.
  913. * @returns {Function} Returns the new capped function.
  914. */
  915. function baseUnary(func) {
  916. return function(value) {
  917. return func(value);
  918. };
  919. }
  920. /**
  921. * The base implementation of `_.values` and `_.valuesIn` which creates an
  922. * array of `object` property values corresponding to the property names
  923. * of `props`.
  924. *
  925. * @private
  926. * @param {Object} object The object to query.
  927. * @param {Array} props The property names to get values for.
  928. * @returns {Object} Returns the array of property values.
  929. */
  930. function baseValues(object, props) {
  931. return arrayMap(props, function(key) {
  932. return object[key];
  933. });
  934. }
  935. /**
  936. * Checks if a `cache` value for `key` exists.
  937. *
  938. * @private
  939. * @param {Object} cache The cache to query.
  940. * @param {string} key The key of the entry to check.
  941. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  942. */
  943. function cacheHas(cache, key) {
  944. return cache.has(key);
  945. }
  946. /**
  947. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  948. * that is not found in the character symbols.
  949. *
  950. * @private
  951. * @param {Array} strSymbols The string symbols to inspect.
  952. * @param {Array} chrSymbols The character symbols to find.
  953. * @returns {number} Returns the index of the first unmatched string symbol.
  954. */
  955. function charsStartIndex(strSymbols, chrSymbols) {
  956. var index = -1,
  957. length = strSymbols.length;
  958. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  959. return index;
  960. }
  961. /**
  962. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  963. * that is not found in the character symbols.
  964. *
  965. * @private
  966. * @param {Array} strSymbols The string symbols to inspect.
  967. * @param {Array} chrSymbols The character symbols to find.
  968. * @returns {number} Returns the index of the last unmatched string symbol.
  969. */
  970. function charsEndIndex(strSymbols, chrSymbols) {
  971. var index = strSymbols.length;
  972. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  973. return index;
  974. }
  975. /**
  976. * Gets the number of `placeholder` occurrences in `array`.
  977. *
  978. * @private
  979. * @param {Array} array The array to inspect.
  980. * @param {*} placeholder The placeholder to search for.
  981. * @returns {number} Returns the placeholder count.
  982. */
  983. function countHolders(array, placeholder) {
  984. var length = array.length,
  985. result = 0;
  986. while (length--) {
  987. if (array[length] === placeholder) {
  988. ++result;
  989. }
  990. }
  991. return result;
  992. }
  993. /**
  994. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  995. * letters to basic Latin letters.
  996. *
  997. * @private
  998. * @param {string} letter The matched letter to deburr.
  999. * @returns {string} Returns the deburred letter.
  1000. */
  1001. var deburrLetter = basePropertyOf(deburredLetters);
  1002. /**
  1003. * Used by `_.escape` to convert characters to HTML entities.
  1004. *
  1005. * @private
  1006. * @param {string} chr The matched character to escape.
  1007. * @returns {string} Returns the escaped character.
  1008. */
  1009. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1010. /**
  1011. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1012. *
  1013. * @private
  1014. * @param {string} chr The matched character to escape.
  1015. * @returns {string} Returns the escaped character.
  1016. */
  1017. function escapeStringChar(chr) {
  1018. return '\\' + stringEscapes[chr];
  1019. }
  1020. /**
  1021. * Gets the value at `key` of `object`.
  1022. *
  1023. * @private
  1024. * @param {Object} [object] The object to query.
  1025. * @param {string} key The key of the property to get.
  1026. * @returns {*} Returns the property value.
  1027. */
  1028. function getValue(object, key) {
  1029. return object == null ? undefined : object[key];
  1030. }
  1031. /**
  1032. * Checks if `string` contains Unicode symbols.
  1033. *
  1034. * @private
  1035. * @param {string} string The string to inspect.
  1036. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1037. */
  1038. function hasUnicode(string) {
  1039. return reHasUnicode.test(string);
  1040. }
  1041. /**
  1042. * Checks if `string` contains a word composed of Unicode symbols.
  1043. *
  1044. * @private
  1045. * @param {string} string The string to inspect.
  1046. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1047. */
  1048. function hasUnicodeWord(string) {
  1049. return reHasUnicodeWord.test(string);
  1050. }
  1051. /**
  1052. * Converts `iterator` to an array.
  1053. *
  1054. * @private
  1055. * @param {Object} iterator The iterator to convert.
  1056. * @returns {Array} Returns the converted array.
  1057. */
  1058. function iteratorToArray(iterator) {
  1059. var data,
  1060. result = [];
  1061. while (!(data = iterator.next()).done) {
  1062. result.push(data.value);
  1063. }
  1064. return result;
  1065. }
  1066. /**
  1067. * Converts `map` to its key-value pairs.
  1068. *
  1069. * @private
  1070. * @param {Object} map The map to convert.
  1071. * @returns {Array} Returns the key-value pairs.
  1072. */
  1073. function mapToArray(map) {
  1074. var index = -1,
  1075. result = Array(map.size);
  1076. map.forEach(function(value, key) {
  1077. result[++index] = [key, value];
  1078. });
  1079. return result;
  1080. }
  1081. /**
  1082. * Creates a unary function that invokes `func` with its argument transformed.
  1083. *
  1084. * @private
  1085. * @param {Function} func The function to wrap.
  1086. * @param {Function} transform The argument transform.
  1087. * @returns {Function} Returns the new function.
  1088. */
  1089. function overArg(func, transform) {
  1090. return function(arg) {
  1091. return func(transform(arg));
  1092. };
  1093. }
  1094. /**
  1095. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1096. * and returns an array of their indexes.
  1097. *
  1098. * @private
  1099. * @param {Array} array The array to modify.
  1100. * @param {*} placeholder The placeholder to replace.
  1101. * @returns {Array} Returns the new array of placeholder indexes.
  1102. */
  1103. function replaceHolders(array, placeholder) {
  1104. var index = -1,
  1105. length = array.length,
  1106. resIndex = 0,
  1107. result = [];
  1108. while (++index < length) {
  1109. var value = array[index];
  1110. if (value === placeholder || value === PLACEHOLDER) {
  1111. array[index] = PLACEHOLDER;
  1112. result[resIndex++] = index;
  1113. }
  1114. }
  1115. return result;
  1116. }
  1117. /**
  1118. * Converts `set` to an array of its values.
  1119. *
  1120. * @private
  1121. * @param {Object} set The set to convert.
  1122. * @returns {Array} Returns the values.
  1123. */
  1124. function setToArray(set) {
  1125. var index = -1,
  1126. result = Array(set.size);
  1127. set.forEach(function(value) {
  1128. result[++index] = value;
  1129. });
  1130. return result;
  1131. }
  1132. /**
  1133. * Converts `set` to its value-value pairs.
  1134. *
  1135. * @private
  1136. * @param {Object} set The set to convert.
  1137. * @returns {Array} Returns the value-value pairs.
  1138. */
  1139. function setToPairs(set) {
  1140. var index = -1,
  1141. result = Array(set.size);
  1142. set.forEach(function(value) {
  1143. result[++index] = [value, value];
  1144. });
  1145. return result;
  1146. }
  1147. /**
  1148. * A specialized version of `_.indexOf` which performs strict equality
  1149. * comparisons of values, i.e. `===`.
  1150. *
  1151. * @private
  1152. * @param {Array} array The array to inspect.
  1153. * @param {*} value The value to search for.
  1154. * @param {number} fromIndex The index to search from.
  1155. * @returns {number} Returns the index of the matched value, else `-1`.
  1156. */
  1157. function strictIndexOf(array, value, fromIndex) {
  1158. var index = fromIndex - 1,
  1159. length = array.length;
  1160. while (++index < length) {
  1161. if (array[index] === value) {
  1162. return index;
  1163. }
  1164. }
  1165. return -1;
  1166. }
  1167. /**
  1168. * A specialized version of `_.lastIndexOf` which performs strict equality
  1169. * comparisons of values, i.e. `===`.
  1170. *
  1171. * @private
  1172. * @param {Array} array The array to inspect.
  1173. * @param {*} value The value to search for.
  1174. * @param {number} fromIndex The index to search from.
  1175. * @returns {number} Returns the index of the matched value, else `-1`.
  1176. */
  1177. function strictLastIndexOf(array, value, fromIndex) {
  1178. var index = fromIndex + 1;
  1179. while (index--) {
  1180. if (array[index] === value) {
  1181. return index;
  1182. }
  1183. }
  1184. return index;
  1185. }
  1186. /**
  1187. * Gets the number of symbols in `string`.
  1188. *
  1189. * @private
  1190. * @param {string} string The string to inspect.
  1191. * @returns {number} Returns the string size.
  1192. */
  1193. function stringSize(string) {
  1194. return hasUnicode(string)
  1195. ? unicodeSize(string)
  1196. : asciiSize(string);
  1197. }
  1198. /**
  1199. * Converts `string` to an array.
  1200. *
  1201. * @private
  1202. * @param {string} string The string to convert.
  1203. * @returns {Array} Returns the converted array.
  1204. */
  1205. function stringToArray(string) {
  1206. return hasUnicode(string)
  1207. ? unicodeToArray(string)
  1208. : asciiToArray(string);
  1209. }
  1210. /**
  1211. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  1212. * character of `string`.
  1213. *
  1214. * @private
  1215. * @param {string} string The string to inspect.
  1216. * @returns {number} Returns the index of the last non-whitespace character.
  1217. */
  1218. function trimmedEndIndex(string) {
  1219. var index = string.length;
  1220. while (index-- && reWhitespace.test(string.charAt(index))) {}
  1221. return index;
  1222. }
  1223. /**
  1224. * Used by `_.unescape` to convert HTML entities to characters.
  1225. *
  1226. * @private
  1227. * @param {string} chr The matched character to unescape.
  1228. * @returns {string} Returns the unescaped character.
  1229. */
  1230. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1231. /**
  1232. * Gets the size of a Unicode `string`.
  1233. *
  1234. * @private
  1235. * @param {string} string The string inspect.
  1236. * @returns {number} Returns the string size.
  1237. */
  1238. function unicodeSize(string) {
  1239. var result = reUnicode.lastIndex = 0;
  1240. while (reUnicode.test(string)) {
  1241. ++result;
  1242. }
  1243. return result;
  1244. }
  1245. /**
  1246. * Converts a Unicode `string` to an array.
  1247. *
  1248. * @private
  1249. * @param {string} string The string to convert.
  1250. * @returns {Array} Returns the converted array.
  1251. */
  1252. function unicodeToArray(string) {
  1253. return string.match(reUnicode) || [];
  1254. }
  1255. /**
  1256. * Splits a Unicode `string` into an array of its words.
  1257. *
  1258. * @private
  1259. * @param {string} The string to inspect.
  1260. * @returns {Array} Returns the words of `string`.
  1261. */
  1262. function unicodeWords(string) {
  1263. return string.match(reUnicodeWord) || [];
  1264. }
  1265. /*--------------------------------------------------------------------------*/
  1266. /**
  1267. * Create a new pristine `lodash` function using the `context` object.
  1268. *
  1269. * @static
  1270. * @memberOf _
  1271. * @since 1.1.0
  1272. * @category Util
  1273. * @param {Object} [context=root] The context object.
  1274. * @returns {Function} Returns a new `lodash` function.
  1275. * @example
  1276. *
  1277. * _.mixin({ 'foo': _.constant('foo') });
  1278. *
  1279. * var lodash = _.runInContext();
  1280. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1281. *
  1282. * _.isFunction(_.foo);
  1283. * // => true
  1284. * _.isFunction(_.bar);
  1285. * // => false
  1286. *
  1287. * lodash.isFunction(lodash.foo);
  1288. * // => false
  1289. * lodash.isFunction(lodash.bar);
  1290. * // => true
  1291. *
  1292. * // Create a suped-up `defer` in Node.js.
  1293. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1294. */
  1295. var runInContext = (function runInContext(context) {
  1296. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1297. /** Built-in constructor references. */
  1298. var Array = context.Array,
  1299. Date = context.Date,
  1300. Error = context.Error,
  1301. Function = context.Function,
  1302. Math = context.Math,
  1303. Object = context.Object,
  1304. RegExp = context.RegExp,
  1305. String = context.String,
  1306. TypeError = context.TypeError;
  1307. /** Used for built-in method references. */
  1308. var arrayProto = Array.prototype,
  1309. funcProto = Function.prototype,
  1310. objectProto = Object.prototype;
  1311. /** Used to detect overreaching core-js shims. */
  1312. var coreJsData = context['__core-js_shared__'];
  1313. /** Used to resolve the decompiled source of functions. */
  1314. var funcToString = funcProto.toString;
  1315. /** Used to check objects for own properties. */
  1316. var hasOwnProperty = objectProto.hasOwnProperty;
  1317. /** Used to generate unique IDs. */
  1318. var idCounter = 0;
  1319. /** Used to detect methods masquerading as native. */
  1320. var maskSrcKey = (function() {
  1321. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1322. return uid ? ('Symbol(src)_1.' + uid) : '';
  1323. }());
  1324. /**
  1325. * Used to resolve the
  1326. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1327. * of values.
  1328. */
  1329. var nativeObjectToString = objectProto.toString;
  1330. /** Used to infer the `Object` constructor. */
  1331. var objectCtorString = funcToString.call(Object);
  1332. /** Used to restore the original `_` reference in `_.noConflict`. */
  1333. var oldDash = root._;
  1334. /** Used to detect if a method is native. */
  1335. var reIsNative = RegExp('^' +
  1336. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1337. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1338. );
  1339. /** Built-in value references. */
  1340. var Buffer = moduleExports ? context.Buffer : undefined,
  1341. Symbol = context.Symbol,
  1342. Uint8Array = context.Uint8Array,
  1343. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1344. getPrototype = overArg(Object.getPrototypeOf, Object),
  1345. objectCreate = Object.create,
  1346. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1347. splice = arrayProto.splice,
  1348. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1349. symIterator = Symbol ? Symbol.iterator : undefined,
  1350. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1351. var defineProperty = (function() {
  1352. try {
  1353. var func = getNative(Object, 'defineProperty');
  1354. func({}, '', {});
  1355. return func;
  1356. } catch (e) {}
  1357. }());
  1358. /** Mocked built-ins. */
  1359. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1360. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1361. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1362. /* Built-in method references for those with the same name as other `lodash` methods. */
  1363. var nativeCeil = Math.ceil,
  1364. nativeFloor = Math.floor,
  1365. nativeGetSymbols = Object.getOwnPropertySymbols,
  1366. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1367. nativeIsFinite = context.isFinite,
  1368. nativeJoin = arrayProto.join,
  1369. nativeKeys = overArg(Object.keys, Object),
  1370. nativeMax = Math.max,
  1371. nativeMin = Math.min,
  1372. nativeNow = Date.now,
  1373. nativeParseInt = context.parseInt,
  1374. nativeRandom = Math.random,
  1375. nativeReverse = arrayProto.reverse;
  1376. /* Built-in method references that are verified to be native. */
  1377. var DataView = getNative(context, 'DataView'),
  1378. Map = getNative(context, 'Map'),
  1379. Promise = getNative(context, 'Promise'),
  1380. Set = getNative(context, 'Set'),
  1381. WeakMap = getNative(context, 'WeakMap'),
  1382. nativeCreate = getNative(Object, 'create');
  1383. /** Used to store function metadata. */
  1384. var metaMap = WeakMap && new WeakMap;
  1385. /** Used to lookup unminified function names. */
  1386. var realNames = {};
  1387. /** Used to detect maps, sets, and weakmaps. */
  1388. var dataViewCtorString = toSource(DataView),
  1389. mapCtorString = toSource(Map),
  1390. promiseCtorString = toSource(Promise),
  1391. setCtorString = toSource(Set),
  1392. weakMapCtorString = toSource(WeakMap);
  1393. /** Used to convert symbols to primitives and strings. */
  1394. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1395. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1396. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1397. /*------------------------------------------------------------------------*/
  1398. /**
  1399. * Creates a `lodash` object which wraps `value` to enable implicit method
  1400. * chain sequences. Methods that operate on and return arrays, collections,
  1401. * and functions can be chained together. Methods that retrieve a single value
  1402. * or may return a primitive value will automatically end the chain sequence
  1403. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1404. * with `_#value`.
  1405. *
  1406. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1407. * enabled using `_.chain`.
  1408. *
  1409. * The execution of chained methods is lazy, that is, it's deferred until
  1410. * `_#value` is implicitly or explicitly called.
  1411. *
  1412. * Lazy evaluation allows several methods to support shortcut fusion.
  1413. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1414. * the creation of intermediate arrays and can greatly reduce the number of
  1415. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1416. * fusion if the section is applied to an array and iteratees accept only
  1417. * one argument. The heuristic for whether a section qualifies for shortcut
  1418. * fusion is subject to change.
  1419. *
  1420. * Chaining is supported in custom builds as long as the `_#value` method is
  1421. * directly or indirectly included in the build.
  1422. *
  1423. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1424. *
  1425. * The wrapper `Array` methods are:
  1426. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1427. *
  1428. * The wrapper `String` methods are:
  1429. * `replace` and `split`
  1430. *
  1431. * The wrapper methods that support shortcut fusion are:
  1432. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1433. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1434. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1435. *
  1436. * The chainable wrapper methods are:
  1437. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1438. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1439. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1440. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1441. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1442. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1443. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1444. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1445. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1446. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1447. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1448. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1449. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1450. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1451. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1452. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1453. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1454. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1455. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1456. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1457. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1458. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1459. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1460. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1461. *
  1462. * The wrapper methods that are **not** chainable by default are:
  1463. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1464. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1465. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1466. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1467. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1468. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1469. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1470. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1471. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1472. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1473. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1474. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1475. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1476. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1477. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1478. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1479. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1480. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1481. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1482. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1483. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1484. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1485. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1486. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1487. * `upperFirst`, `value`, and `words`
  1488. *
  1489. * @name _
  1490. * @constructor
  1491. * @category Seq
  1492. * @param {*} value The value to wrap in a `lodash` instance.
  1493. * @returns {Object} Returns the new `lodash` wrapper instance.
  1494. * @example
  1495. *
  1496. * function square(n) {
  1497. * return n * n;
  1498. * }
  1499. *
  1500. * var wrapped = _([1, 2, 3]);
  1501. *
  1502. * // Returns an unwrapped value.
  1503. * wrapped.reduce(_.add);
  1504. * // => 6
  1505. *
  1506. * // Returns a wrapped value.
  1507. * var squares = wrapped.map(square);
  1508. *
  1509. * _.isArray(squares);
  1510. * // => false
  1511. *
  1512. * _.isArray(squares.value());
  1513. * // => true
  1514. */
  1515. function lodash(value) {
  1516. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1517. if (value instanceof LodashWrapper) {
  1518. return value;
  1519. }
  1520. if (hasOwnProperty.call(value, '__wrapped__')) {
  1521. return wrapperClone(value);
  1522. }
  1523. }
  1524. return new LodashWrapper(value);
  1525. }
  1526. /**
  1527. * The base implementation of `_.create` without support for assigning
  1528. * properties to the created object.
  1529. *
  1530. * @private
  1531. * @param {Object} proto The object to inherit from.
  1532. * @returns {Object} Returns the new object.
  1533. */
  1534. var baseCreate = (function() {
  1535. function object() {}
  1536. return function(proto) {
  1537. if (!isObject(proto)) {
  1538. return {};
  1539. }
  1540. if (objectCreate) {
  1541. return objectCreate(proto);
  1542. }
  1543. object.prototype = proto;
  1544. var result = new object;
  1545. object.prototype = undefined;
  1546. return result;
  1547. };
  1548. }());
  1549. /**
  1550. * The function whose prototype chain sequence wrappers inherit from.
  1551. *
  1552. * @private
  1553. */
  1554. function baseLodash() {
  1555. // No operation performed.
  1556. }
  1557. /**
  1558. * The base constructor for creating `lodash` wrapper objects.
  1559. *
  1560. * @private
  1561. * @param {*} value The value to wrap.
  1562. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1563. */
  1564. function LodashWrapper(value, chainAll) {
  1565. this.__wrapped__ = value;
  1566. this.__actions__ = [];
  1567. this.__chain__ = !!chainAll;
  1568. this.__index__ = 0;
  1569. this.__values__ = undefined;
  1570. }
  1571. /**
  1572. * By default, the template delimiters used by lodash are like those in
  1573. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1574. * following template settings to use alternative delimiters.
  1575. *
  1576. * @static
  1577. * @memberOf _
  1578. * @type {Object}
  1579. */
  1580. lodash.templateSettings = {
  1581. /**
  1582. * Used to detect `data` property values to be HTML-escaped.
  1583. *
  1584. * @memberOf _.templateSettings
  1585. * @type {RegExp}
  1586. */
  1587. 'escape': reEscape,
  1588. /**
  1589. * Used to detect code to be evaluated.
  1590. *
  1591. * @memberOf _.templateSettings
  1592. * @type {RegExp}
  1593. */
  1594. 'evaluate': reEvaluate,
  1595. /**
  1596. * Used to detect `data` property values to inject.
  1597. *
  1598. * @memberOf _.templateSettings
  1599. * @type {RegExp}
  1600. */
  1601. 'interpolate': reInterpolate,
  1602. /**
  1603. * Used to reference the data object in the template text.
  1604. *
  1605. * @memberOf _.templateSettings
  1606. * @type {string}
  1607. */
  1608. 'variable': '',
  1609. /**
  1610. * Used to import variables into the compiled template.
  1611. *
  1612. * @memberOf _.templateSettings
  1613. * @type {Object}
  1614. */
  1615. 'imports': {
  1616. /**
  1617. * A reference to the `lodash` function.
  1618. *
  1619. * @memberOf _.templateSettings.imports
  1620. * @type {Function}
  1621. */
  1622. '_': lodash
  1623. }
  1624. };
  1625. // Ensure wrappers are instances of `baseLodash`.
  1626. lodash.prototype = baseLodash.prototype;
  1627. lodash.prototype.constructor = lodash;
  1628. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1629. LodashWrapper.prototype.constructor = LodashWrapper;
  1630. /*------------------------------------------------------------------------*/
  1631. /**
  1632. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1633. *
  1634. * @private
  1635. * @constructor
  1636. * @param {*} value The value to wrap.
  1637. */
  1638. function LazyWrapper(value) {
  1639. this.__wrapped__ = value;
  1640. this.__actions__ = [];
  1641. this.__dir__ = 1;
  1642. this.__filtered__ = false;
  1643. this.__iteratees__ = [];
  1644. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1645. this.__views__ = [];
  1646. }
  1647. /**
  1648. * Creates a clone of the lazy wrapper object.
  1649. *
  1650. * @private
  1651. * @name clone
  1652. * @memberOf LazyWrapper
  1653. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1654. */
  1655. function lazyClone() {
  1656. var result = new LazyWrapper(this.__wrapped__);
  1657. result.__actions__ = copyArray(this.__actions__);
  1658. result.__dir__ = this.__dir__;
  1659. result.__filtered__ = this.__filtered__;
  1660. result.__iteratees__ = copyArray(this.__iteratees__);
  1661. result.__takeCount__ = this.__takeCount__;
  1662. result.__views__ = copyArray(this.__views__);
  1663. return result;
  1664. }
  1665. /**
  1666. * Reverses the direction of lazy iteration.
  1667. *
  1668. * @private
  1669. * @name reverse
  1670. * @memberOf LazyWrapper
  1671. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1672. */
  1673. function lazyReverse() {
  1674. if (this.__filtered__) {
  1675. var result = new LazyWrapper(this);
  1676. result.__dir__ = -1;
  1677. result.__filtered__ = true;
  1678. } else {
  1679. result = this.clone();
  1680. result.__dir__ *= -1;
  1681. }
  1682. return result;
  1683. }
  1684. /**
  1685. * Extracts the unwrapped value from its lazy wrapper.
  1686. *
  1687. * @private
  1688. * @name value
  1689. * @memberOf LazyWrapper
  1690. * @returns {*} Returns the unwrapped value.
  1691. */
  1692. function lazyValue() {
  1693. var array = this.__wrapped__.value(),
  1694. dir = this.__dir__,
  1695. isArr = isArray(array),
  1696. isRight = dir < 0,
  1697. arrLength = isArr ? array.length : 0,
  1698. view = getView(0, arrLength, this.__views__),
  1699. start = view.start,
  1700. end = view.end,
  1701. length = end - start,
  1702. index = isRight ? end : (start - 1),
  1703. iteratees = this.__iteratees__,
  1704. iterLength = iteratees.length,
  1705. resIndex = 0,
  1706. takeCount = nativeMin(length, this.__takeCount__);
  1707. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1708. return baseWrapperValue(array, this.__actions__);
  1709. }
  1710. var result = [];
  1711. outer:
  1712. while (length-- && resIndex < takeCount) {
  1713. index += dir;
  1714. var iterIndex = -1,
  1715. value = array[index];
  1716. while (++iterIndex < iterLength) {
  1717. var data = iteratees[iterIndex],
  1718. iteratee = data.iteratee,
  1719. type = data.type,
  1720. computed = iteratee(value);
  1721. if (type == LAZY_MAP_FLAG) {
  1722. value = computed;
  1723. } else if (!computed) {
  1724. if (type == LAZY_FILTER_FLAG) {
  1725. continue outer;
  1726. } else {
  1727. break outer;
  1728. }
  1729. }
  1730. }
  1731. result[resIndex++] = value;
  1732. }
  1733. return result;
  1734. }
  1735. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1736. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1737. LazyWrapper.prototype.constructor = LazyWrapper;
  1738. /*------------------------------------------------------------------------*/
  1739. /**
  1740. * Creates a hash object.
  1741. *
  1742. * @private
  1743. * @constructor
  1744. * @param {Array} [entries] The key-value pairs to cache.
  1745. */
  1746. function Hash(entries) {
  1747. var index = -1,
  1748. length = entries == null ? 0 : entries.length;
  1749. this.clear();
  1750. while (++index < length) {
  1751. var entry = entries[index];
  1752. this.set(entry[0], entry[1]);
  1753. }
  1754. }
  1755. /**
  1756. * Removes all key-value entries from the hash.
  1757. *
  1758. * @private
  1759. * @name clear
  1760. * @memberOf Hash
  1761. */
  1762. function hashClear() {
  1763. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1764. this.size = 0;
  1765. }
  1766. /**
  1767. * Removes `key` and its value from the hash.
  1768. *
  1769. * @private
  1770. * @name delete
  1771. * @memberOf Hash
  1772. * @param {Object} hash The hash to modify.
  1773. * @param {string} key The key of the value to remove.
  1774. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1775. */
  1776. function hashDelete(key) {
  1777. var result = this.has(key) && delete this.__data__[key];
  1778. this.size -= result ? 1 : 0;
  1779. return result;
  1780. }
  1781. /**
  1782. * Gets the hash value for `key`.
  1783. *
  1784. * @private
  1785. * @name get
  1786. * @memberOf Hash
  1787. * @param {string} key The key of the value to get.
  1788. * @returns {*} Returns the entry value.
  1789. */
  1790. function hashGet(key) {
  1791. var data = this.__data__;
  1792. if (nativeCreate) {
  1793. var result = data[key];
  1794. return result === HASH_UNDEFINED ? undefined : result;
  1795. }
  1796. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1797. }
  1798. /**
  1799. * Checks if a hash value for `key` exists.
  1800. *
  1801. * @private
  1802. * @name has
  1803. * @memberOf Hash
  1804. * @param {string} key The key of the entry to check.
  1805. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1806. */
  1807. function hashHas(key) {
  1808. var data = this.__data__;
  1809. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1810. }
  1811. /**
  1812. * Sets the hash `key` to `value`.
  1813. *
  1814. * @private
  1815. * @name set
  1816. * @memberOf Hash
  1817. * @param {string} key The key of the value to set.
  1818. * @param {*} value The value to set.
  1819. * @returns {Object} Returns the hash instance.
  1820. */
  1821. function hashSet(key, value) {
  1822. var data = this.__data__;
  1823. this.size += this.has(key) ? 0 : 1;
  1824. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1825. return this;
  1826. }
  1827. // Add methods to `Hash`.
  1828. Hash.prototype.clear = hashClear;
  1829. Hash.prototype['delete'] = hashDelete;
  1830. Hash.prototype.get = hashGet;
  1831. Hash.prototype.has = hashHas;
  1832. Hash.prototype.set = hashSet;
  1833. /*------------------------------------------------------------------------*/
  1834. /**
  1835. * Creates an list cache object.
  1836. *
  1837. * @private
  1838. * @constructor
  1839. * @param {Array} [entries] The key-value pairs to cache.
  1840. */
  1841. function ListCache(entries) {
  1842. var index = -1,
  1843. length = entries == null ? 0 : entries.length;
  1844. this.clear();
  1845. while (++index < length) {
  1846. var entry = entries[index];
  1847. this.set(entry[0], entry[1]);
  1848. }
  1849. }
  1850. /**
  1851. * Removes all key-value entries from the list cache.
  1852. *
  1853. * @private
  1854. * @name clear
  1855. * @memberOf ListCache
  1856. */
  1857. function listCacheClear() {
  1858. this.__data__ = [];
  1859. this.size = 0;
  1860. }
  1861. /**
  1862. * Removes `key` and its value from the list cache.
  1863. *
  1864. * @private
  1865. * @name delete
  1866. * @memberOf ListCache
  1867. * @param {string} key The key of the value to remove.
  1868. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1869. */
  1870. function listCacheDelete(key) {
  1871. var data = this.__data__,
  1872. index = assocIndexOf(data, key);
  1873. if (index < 0) {
  1874. return false;
  1875. }
  1876. var lastIndex = data.length - 1;
  1877. if (index == lastIndex) {
  1878. data.pop();
  1879. } else {
  1880. splice.call(data, index, 1);
  1881. }
  1882. --this.size;
  1883. return true;
  1884. }
  1885. /**
  1886. * Gets the list cache value for `key`.
  1887. *
  1888. * @private
  1889. * @name get
  1890. * @memberOf ListCache
  1891. * @param {string} key The key of the value to get.
  1892. * @returns {*} Returns the entry value.
  1893. */
  1894. function listCacheGet(key) {
  1895. var data = this.__data__,
  1896. index = assocIndexOf(data, key);
  1897. return index < 0 ? undefined : data[index][1];
  1898. }
  1899. /**
  1900. * Checks if a list cache value for `key` exists.
  1901. *
  1902. * @private
  1903. * @name has
  1904. * @memberOf ListCache
  1905. * @param {string} key The key of the entry to check.
  1906. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1907. */
  1908. function listCacheHas(key) {
  1909. return assocIndexOf(this.__data__, key) > -1;
  1910. }
  1911. /**
  1912. * Sets the list cache `key` to `value`.
  1913. *
  1914. * @private
  1915. * @name set
  1916. * @memberOf ListCache
  1917. * @param {string} key The key of the value to set.
  1918. * @param {*} value The value to set.
  1919. * @returns {Object} Returns the list cache instance.
  1920. */
  1921. function listCacheSet(key, value) {
  1922. var data = this.__data__,
  1923. index = assocIndexOf(data, key);
  1924. if (index < 0) {
  1925. ++this.size;
  1926. data.push([key, value]);
  1927. } else {
  1928. data[index][1] = value;
  1929. }
  1930. return this;
  1931. }
  1932. // Add methods to `ListCache`.
  1933. ListCache.prototype.clear = listCacheClear;
  1934. ListCache.prototype['delete'] = listCacheDelete;
  1935. ListCache.prototype.get = listCacheGet;
  1936. ListCache.prototype.has = listCacheHas;
  1937. ListCache.prototype.set = listCacheSet;
  1938. /*------------------------------------------------------------------------*/
  1939. /**
  1940. * Creates a map cache object to store key-value pairs.
  1941. *
  1942. * @private
  1943. * @constructor
  1944. * @param {Array} [entries] The key-value pairs to cache.
  1945. */
  1946. function MapCache(entries) {
  1947. var index = -1,
  1948. length = entries == null ? 0 : entries.length;
  1949. this.clear();
  1950. while (++index < length) {
  1951. var entry = entries[index];
  1952. this.set(entry[0], entry[1]);
  1953. }
  1954. }
  1955. /**
  1956. * Removes all key-value entries from the map.
  1957. *
  1958. * @private
  1959. * @name clear
  1960. * @memberOf MapCache
  1961. */
  1962. function mapCacheClear() {
  1963. this.size = 0;
  1964. this.__data__ = {
  1965. 'hash': new Hash,
  1966. 'map': new (Map || ListCache),
  1967. 'string': new Hash
  1968. };
  1969. }
  1970. /**
  1971. * Removes `key` and its value from the map.
  1972. *
  1973. * @private
  1974. * @name delete
  1975. * @memberOf MapCache
  1976. * @param {string} key The key of the value to remove.
  1977. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1978. */
  1979. function mapCacheDelete(key) {
  1980. var result = getMapData(this, key)['delete'](key);
  1981. this.size -= result ? 1 : 0;
  1982. return result;
  1983. }
  1984. /**
  1985. * Gets the map value for `key`.
  1986. *
  1987. * @private
  1988. * @name get
  1989. * @memberOf MapCache
  1990. * @param {string} key The key of the value to get.
  1991. * @returns {*} Returns the entry value.
  1992. */
  1993. function mapCacheGet(key) {
  1994. return getMapData(this, key).get(key);
  1995. }
  1996. /**
  1997. * Checks if a map value for `key` exists.
  1998. *
  1999. * @private
  2000. * @name has
  2001. * @memberOf MapCache
  2002. * @param {string} key The key of the entry to check.
  2003. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2004. */
  2005. function mapCacheHas(key) {
  2006. return getMapData(this, key).has(key);
  2007. }
  2008. /**
  2009. * Sets the map `key` to `value`.
  2010. *
  2011. * @private
  2012. * @name set
  2013. * @memberOf MapCache
  2014. * @param {string} key The key of the value to set.
  2015. * @param {*} value The value to set.
  2016. * @returns {Object} Returns the map cache instance.
  2017. */
  2018. function mapCacheSet(key, value) {
  2019. var data = getMapData(this, key),
  2020. size = data.size;
  2021. data.set(key, value);
  2022. this.size += data.size == size ? 0 : 1;
  2023. return this;
  2024. }
  2025. // Add methods to `MapCache`.
  2026. MapCache.prototype.clear = mapCacheClear;
  2027. MapCache.prototype['delete'] = mapCacheDelete;
  2028. MapCache.prototype.get = mapCacheGet;
  2029. MapCache.prototype.has = mapCacheHas;
  2030. MapCache.prototype.set = mapCacheSet;
  2031. /*------------------------------------------------------------------------*/
  2032. /**
  2033. *
  2034. * Creates an array cache object to store unique values.
  2035. *
  2036. * @private
  2037. * @constructor
  2038. * @param {Array} [values] The values to cache.
  2039. */
  2040. function SetCache(values) {
  2041. var index = -1,
  2042. length = values == null ? 0 : values.length;
  2043. this.__data__ = new MapCache;
  2044. while (++index < length) {
  2045. this.add(values[index]);
  2046. }
  2047. }
  2048. /**
  2049. * Adds `value` to the array cache.
  2050. *
  2051. * @private
  2052. * @name add
  2053. * @memberOf SetCache
  2054. * @alias push
  2055. * @param {*} value The value to cache.
  2056. * @returns {Object} Returns the cache instance.
  2057. */
  2058. function setCacheAdd(value) {
  2059. this.__data__.set(value, HASH_UNDEFINED);
  2060. return this;
  2061. }
  2062. /**
  2063. * Checks if `value` is in the array cache.
  2064. *
  2065. * @private
  2066. * @name has
  2067. * @memberOf SetCache
  2068. * @param {*} value The value to search for.
  2069. * @returns {number} Returns `true` if `value` is found, else `false`.
  2070. */
  2071. function setCacheHas(value) {
  2072. return this.__data__.has(value);
  2073. }
  2074. // Add methods to `SetCache`.
  2075. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2076. SetCache.prototype.has = setCacheHas;
  2077. /*------------------------------------------------------------------------*/
  2078. /**
  2079. * Creates a stack cache object to store key-value pairs.
  2080. *
  2081. * @private
  2082. * @constructor
  2083. * @param {Array} [entries] The key-value pairs to cache.
  2084. */
  2085. function Stack(entries) {
  2086. var data = this.__data__ = new ListCache(entries);
  2087. this.size = data.size;
  2088. }
  2089. /**
  2090. * Removes all key-value entries from the stack.
  2091. *
  2092. * @private
  2093. * @name clear
  2094. * @memberOf Stack
  2095. */
  2096. function stackClear() {
  2097. this.__data__ = new ListCache;
  2098. this.size = 0;
  2099. }
  2100. /**
  2101. * Removes `key` and its value from the stack.
  2102. *
  2103. * @private
  2104. * @name delete
  2105. * @memberOf Stack
  2106. * @param {string} key The key of the value to remove.
  2107. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2108. */
  2109. function stackDelete(key) {
  2110. var data = this.__data__,
  2111. result = data['delete'](key);
  2112. this.size = data.size;
  2113. return result;
  2114. }
  2115. /**
  2116. * Gets the stack value for `key`.
  2117. *
  2118. * @private
  2119. * @name get
  2120. * @memberOf Stack
  2121. * @param {string} key The key of the value to get.
  2122. * @returns {*} Returns the entry value.
  2123. */
  2124. function stackGet(key) {
  2125. return this.__data__.get(key);
  2126. }
  2127. /**
  2128. * Checks if a stack value for `key` exists.
  2129. *
  2130. * @private
  2131. * @name has
  2132. * @memberOf Stack
  2133. * @param {string} key The key of the entry to check.
  2134. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2135. */
  2136. function stackHas(key) {
  2137. return this.__data__.has(key);
  2138. }
  2139. /**
  2140. * Sets the stack `key` to `value`.
  2141. *
  2142. * @private
  2143. * @name set
  2144. * @memberOf Stack
  2145. * @param {string} key The key of the value to set.
  2146. * @param {*} value The value to set.
  2147. * @returns {Object} Returns the stack cache instance.
  2148. */
  2149. function stackSet(key, value) {
  2150. var data = this.__data__;
  2151. if (data instanceof ListCache) {
  2152. var pairs = data.__data__;
  2153. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2154. pairs.push([key, value]);
  2155. this.size = ++data.size;
  2156. return this;
  2157. }
  2158. data = this.__data__ = new MapCache(pairs);
  2159. }
  2160. data.set(key, value);
  2161. this.size = data.size;
  2162. return this;
  2163. }
  2164. // Add methods to `Stack`.
  2165. Stack.prototype.clear = stackClear;
  2166. Stack.prototype['delete'] = stackDelete;
  2167. Stack.prototype.get = stackGet;
  2168. Stack.prototype.has = stackHas;
  2169. Stack.prototype.set = stackSet;
  2170. /*------------------------------------------------------------------------*/
  2171. /**
  2172. * Creates an array of the enumerable property names of the array-like `value`.
  2173. *
  2174. * @private
  2175. * @param {*} value The value to query.
  2176. * @param {boolean} inherited Specify returning inherited property names.
  2177. * @returns {Array} Returns the array of property names.
  2178. */
  2179. function arrayLikeKeys(value, inherited) {
  2180. var isArr = isArray(value),
  2181. isArg = !isArr && isArguments(value),
  2182. isBuff = !isArr && !isArg && isBuffer(value),
  2183. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2184. skipIndexes = isArr || isArg || isBuff || isType,
  2185. result = skipIndexes ? baseTimes(value.length, String) : [],
  2186. length = result.length;
  2187. for (var key in value) {
  2188. if ((inherited || hasOwnProperty.call(value, key)) &&
  2189. !(skipIndexes && (
  2190. // Safari 9 has enumerable `arguments.length` in strict mode.
  2191. key == 'length' ||
  2192. // Node.js 0.10 has enumerable non-index properties on buffers.
  2193. (isBuff && (key == 'offset' || key == 'parent')) ||
  2194. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2195. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2196. // Skip index properties.
  2197. isIndex(key, length)
  2198. ))) {
  2199. result.push(key);
  2200. }
  2201. }
  2202. return result;
  2203. }
  2204. /**
  2205. * A specialized version of `_.sample` for arrays.
  2206. *
  2207. * @private
  2208. * @param {Array} array The array to sample.
  2209. * @returns {*} Returns the random element.
  2210. */
  2211. function arraySample(array) {
  2212. var length = array.length;
  2213. return length ? array[baseRandom(0, length - 1)] : undefined;
  2214. }
  2215. /**
  2216. * A specialized version of `_.sampleSize` for arrays.
  2217. *
  2218. * @private
  2219. * @param {Array} array The array to sample.
  2220. * @param {number} n The number of elements to sample.
  2221. * @returns {Array} Returns the random elements.
  2222. */
  2223. function arraySampleSize(array, n) {
  2224. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2225. }
  2226. /**
  2227. * A specialized version of `_.shuffle` for arrays.
  2228. *
  2229. * @private
  2230. * @param {Array} array The array to shuffle.
  2231. * @returns {Array} Returns the new shuffled array.
  2232. */
  2233. function arrayShuffle(array) {
  2234. return shuffleSelf(copyArray(array));
  2235. }
  2236. /**
  2237. * This function is like `assignValue` except that it doesn't assign
  2238. * `undefined` values.
  2239. *
  2240. * @private
  2241. * @param {Object} object The object to modify.
  2242. * @param {string} key The key of the property to assign.
  2243. * @param {*} value The value to assign.
  2244. */
  2245. function assignMergeValue(object, key, value) {
  2246. if ((value !== undefined && !eq(object[key], value)) ||
  2247. (value === undefined && !(key in object))) {
  2248. baseAssignValue(object, key, value);
  2249. }
  2250. }
  2251. /**
  2252. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2253. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2254. * for equality comparisons.
  2255. *
  2256. * @private
  2257. * @param {Object} object The object to modify.
  2258. * @param {string} key The key of the property to assign.
  2259. * @param {*} value The value to assign.
  2260. */
  2261. function assignValue(object, key, value) {
  2262. var objValue = object[key];
  2263. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2264. (value === undefined && !(key in object))) {
  2265. baseAssignValue(object, key, value);
  2266. }
  2267. }
  2268. /**
  2269. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2270. *
  2271. * @private
  2272. * @param {Array} array The array to inspect.
  2273. * @param {*} key The key to search for.
  2274. * @returns {number} Returns the index of the matched value, else `-1`.
  2275. */
  2276. function assocIndexOf(array, key) {
  2277. var length = array.length;
  2278. while (length--) {
  2279. if (eq(array[length][0], key)) {
  2280. return length;
  2281. }
  2282. }
  2283. return -1;
  2284. }
  2285. /**
  2286. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2287. * by `iteratee` and values set by `setter`.
  2288. *
  2289. * @private
  2290. * @param {Array|Object} collection The collection to iterate over.
  2291. * @param {Function} setter The function to set `accumulator` values.
  2292. * @param {Function} iteratee The iteratee to transform keys.
  2293. * @param {Object} accumulator The initial aggregated object.
  2294. * @returns {Function} Returns `accumulator`.
  2295. */
  2296. function baseAggregator(collection, setter, iteratee, accumulator) {
  2297. baseEach(collection, function(value, key, collection) {
  2298. setter(accumulator, value, iteratee(value), collection);
  2299. });
  2300. return accumulator;
  2301. }
  2302. /**
  2303. * The base implementation of `_.assign` without support for multiple sources
  2304. * or `customizer` functions.
  2305. *
  2306. * @private
  2307. * @param {Object} object The destination object.
  2308. * @param {Object} source The source object.
  2309. * @returns {Object} Returns `object`.
  2310. */
  2311. function baseAssign(object, source) {
  2312. return object && copyObject(source, keys(source), object);
  2313. }
  2314. /**
  2315. * The base implementation of `_.assignIn` without support for multiple sources
  2316. * or `customizer` functions.
  2317. *
  2318. * @private
  2319. * @param {Object} object The destination object.
  2320. * @param {Object} source The source object.
  2321. * @returns {Object} Returns `object`.
  2322. */
  2323. function baseAssignIn(object, source) {
  2324. return object && copyObject(source, keysIn(source), object);
  2325. }
  2326. /**
  2327. * The base implementation of `assignValue` and `assignMergeValue` without
  2328. * value checks.
  2329. *
  2330. * @private
  2331. * @param {Object} object The object to modify.
  2332. * @param {string} key The key of the property to assign.
  2333. * @param {*} value The value to assign.
  2334. */
  2335. function baseAssignValue(object, key, value) {
  2336. if (key == '__proto__' && defineProperty) {
  2337. defineProperty(object, key, {
  2338. 'configurable': true,
  2339. 'enumerable': true,
  2340. 'value': value,
  2341. 'writable': true
  2342. });
  2343. } else {
  2344. object[key] = value;
  2345. }
  2346. }
  2347. /**
  2348. * The base implementation of `_.at` without support for individual paths.
  2349. *
  2350. * @private
  2351. * @param {Object} object The object to iterate over.
  2352. * @param {string[]} paths The property paths to pick.
  2353. * @returns {Array} Returns the picked elements.
  2354. */
  2355. function baseAt(object, paths) {
  2356. var index = -1,
  2357. length = paths.length,
  2358. result = Array(length),
  2359. skip = object == null;
  2360. while (++index < length) {
  2361. result[index] = skip ? undefined : get(object, paths[index]);
  2362. }
  2363. return result;
  2364. }
  2365. /**
  2366. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2367. *
  2368. * @private
  2369. * @param {number} number The number to clamp.
  2370. * @param {number} [lower] The lower bound.
  2371. * @param {number} upper The upper bound.
  2372. * @returns {number} Returns the clamped number.
  2373. */
  2374. function baseClamp(number, lower, upper) {
  2375. if (number === number) {
  2376. if (upper !== undefined) {
  2377. number = number <= upper ? number : upper;
  2378. }
  2379. if (lower !== undefined) {
  2380. number = number >= lower ? number : lower;
  2381. }
  2382. }
  2383. return number;
  2384. }
  2385. /**
  2386. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2387. * traversed objects.
  2388. *
  2389. * @private
  2390. * @param {*} value The value to clone.
  2391. * @param {boolean} bitmask The bitmask flags.
  2392. * 1 - Deep clone
  2393. * 2 - Flatten inherited properties
  2394. * 4 - Clone symbols
  2395. * @param {Function} [customizer] The function to customize cloning.
  2396. * @param {string} [key] The key of `value`.
  2397. * @param {Object} [object] The parent object of `value`.
  2398. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2399. * @returns {*} Returns the cloned value.
  2400. */
  2401. function baseClone(value, bitmask, customizer, key, object, stack) {
  2402. var result,
  2403. isDeep = bitmask & CLONE_DEEP_FLAG,
  2404. isFlat = bitmask & CLONE_FLAT_FLAG,
  2405. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2406. if (customizer) {
  2407. result = object ? customizer(value, key, object, stack) : customizer(value);
  2408. }
  2409. if (result !== undefined) {
  2410. return result;
  2411. }
  2412. if (!isObject(value)) {
  2413. return value;
  2414. }
  2415. var isArr = isArray(value);
  2416. if (isArr) {
  2417. result = initCloneArray(value);
  2418. if (!isDeep) {
  2419. return copyArray(value, result);
  2420. }
  2421. } else {
  2422. var tag = getTag(value),
  2423. isFunc = tag == funcTag || tag == genTag;
  2424. if (isBuffer(value)) {
  2425. return cloneBuffer(value, isDeep);
  2426. }
  2427. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2428. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2429. if (!isDeep) {
  2430. return isFlat
  2431. ? copySymbolsIn(value, baseAssignIn(result, value))
  2432. : copySymbols(value, baseAssign(result, value));
  2433. }
  2434. } else {
  2435. if (!cloneableTags[tag]) {
  2436. return object ? value : {};
  2437. }
  2438. result = initCloneByTag(value, tag, isDeep);
  2439. }
  2440. }
  2441. // Check for circular references and return its corresponding clone.
  2442. stack || (stack = new Stack);
  2443. var stacked = stack.get(value);
  2444. if (stacked) {
  2445. return stacked;
  2446. }
  2447. stack.set(value, result);
  2448. if (isSet(value)) {
  2449. value.forEach(function(subValue) {
  2450. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2451. });
  2452. } else if (isMap(value)) {
  2453. value.forEach(function(subValue, key) {
  2454. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2455. });
  2456. }
  2457. var keysFunc = isFull
  2458. ? (isFlat ? getAllKeysIn : getAllKeys)
  2459. : (isFlat ? keysIn : keys);
  2460. var props = isArr ? undefined : keysFunc(value);
  2461. arrayEach(props || value, function(subValue, key) {
  2462. if (props) {
  2463. key = subValue;
  2464. subValue = value[key];
  2465. }
  2466. // Recursively populate clone (susceptible to call stack limits).
  2467. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2468. });
  2469. return result;
  2470. }
  2471. /**
  2472. * The base implementation of `_.conforms` which doesn't clone `source`.
  2473. *
  2474. * @private
  2475. * @param {Object} source The object of property predicates to conform to.
  2476. * @returns {Function} Returns the new spec function.
  2477. */
  2478. function baseConforms(source) {
  2479. var props = keys(source);
  2480. return function(object) {
  2481. return baseConformsTo(object, source, props);
  2482. };
  2483. }
  2484. /**
  2485. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2486. *
  2487. * @private
  2488. * @param {Object} object The object to inspect.
  2489. * @param {Object} source The object of property predicates to conform to.
  2490. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2491. */
  2492. function baseConformsTo(object, source, props) {
  2493. var length = props.length;
  2494. if (object == null) {
  2495. return !length;
  2496. }
  2497. object = Object(object);
  2498. while (length--) {
  2499. var key = props[length],
  2500. predicate = source[key],
  2501. value = object[key];
  2502. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2503. return false;
  2504. }
  2505. }
  2506. return true;
  2507. }
  2508. /**
  2509. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2510. * to provide to `func`.
  2511. *
  2512. * @private
  2513. * @param {Function} func The function to delay.
  2514. * @param {number} wait The number of milliseconds to delay invocation.
  2515. * @param {Array} args The arguments to provide to `func`.
  2516. * @returns {number|Object} Returns the timer id or timeout object.
  2517. */
  2518. function baseDelay(func, wait, args) {
  2519. if (typeof func != 'function') {
  2520. throw new TypeError(FUNC_ERROR_TEXT);
  2521. }
  2522. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2523. }
  2524. /**
  2525. * The base implementation of methods like `_.difference` without support
  2526. * for excluding multiple arrays or iteratee shorthands.
  2527. *
  2528. * @private
  2529. * @param {Array} array The array to inspect.
  2530. * @param {Array} values The values to exclude.
  2531. * @param {Function} [iteratee] The iteratee invoked per element.
  2532. * @param {Function} [comparator] The comparator invoked per element.
  2533. * @returns {Array} Returns the new array of filtered values.
  2534. */
  2535. function baseDifference(array, values, iteratee, comparator) {
  2536. var index = -1,
  2537. includes = arrayIncludes,
  2538. isCommon = true,
  2539. length = array.length,
  2540. result = [],
  2541. valuesLength = values.length;
  2542. if (!length) {
  2543. return result;
  2544. }
  2545. if (iteratee) {
  2546. values = arrayMap(values, baseUnary(iteratee));
  2547. }
  2548. if (comparator) {
  2549. includes = arrayIncludesWith;
  2550. isCommon = false;
  2551. }
  2552. else if (values.length >= LARGE_ARRAY_SIZE) {
  2553. includes = cacheHas;
  2554. isCommon = false;
  2555. values = new SetCache(values);
  2556. }
  2557. outer:
  2558. while (++index < length) {
  2559. var value = array[index],
  2560. computed = iteratee == null ? value : iteratee(value);
  2561. value = (comparator || value !== 0) ? value : 0;
  2562. if (isCommon && computed === computed) {
  2563. var valuesIndex = valuesLength;
  2564. while (valuesIndex--) {
  2565. if (values[valuesIndex] === computed) {
  2566. continue outer;
  2567. }
  2568. }
  2569. result.push(value);
  2570. }
  2571. else if (!includes(values, computed, comparator)) {
  2572. result.push(value);
  2573. }
  2574. }
  2575. return result;
  2576. }
  2577. /**
  2578. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2579. *
  2580. * @private
  2581. * @param {Array|Object} collection The collection to iterate over.
  2582. * @param {Function} iteratee The function invoked per iteration.
  2583. * @returns {Array|Object} Returns `collection`.
  2584. */
  2585. var baseEach = createBaseEach(baseForOwn);
  2586. /**
  2587. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2588. *
  2589. * @private
  2590. * @param {Array|Object} collection The collection to iterate over.
  2591. * @param {Function} iteratee The function invoked per iteration.
  2592. * @returns {Array|Object} Returns `collection`.
  2593. */
  2594. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2595. /**
  2596. * The base implementation of `_.every` without support for iteratee shorthands.
  2597. *
  2598. * @private
  2599. * @param {Array|Object} collection The collection to iterate over.
  2600. * @param {Function} predicate The function invoked per iteration.
  2601. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2602. * else `false`
  2603. */
  2604. function baseEvery(collection, predicate) {
  2605. var result = true;
  2606. baseEach(collection, function(value, index, collection) {
  2607. result = !!predicate(value, index, collection);
  2608. return result;
  2609. });
  2610. return result;
  2611. }
  2612. /**
  2613. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2614. * `comparator` to determine the extremum value.
  2615. *
  2616. * @private
  2617. * @param {Array} array The array to iterate over.
  2618. * @param {Function} iteratee The iteratee invoked per iteration.
  2619. * @param {Function} comparator The comparator used to compare values.
  2620. * @returns {*} Returns the extremum value.
  2621. */
  2622. function baseExtremum(array, iteratee, comparator) {
  2623. var index = -1,
  2624. length = array.length;
  2625. while (++index < length) {
  2626. var value = array[index],
  2627. current = iteratee(value);
  2628. if (current != null && (computed === undefined
  2629. ? (current === current && !isSymbol(current))
  2630. : comparator(current, computed)
  2631. )) {
  2632. var computed = current,
  2633. result = value;
  2634. }
  2635. }
  2636. return result;
  2637. }
  2638. /**
  2639. * The base implementation of `_.fill` without an iteratee call guard.
  2640. *
  2641. * @private
  2642. * @param {Array} array The array to fill.
  2643. * @param {*} value The value to fill `array` with.
  2644. * @param {number} [start=0] The start position.
  2645. * @param {number} [end=array.length] The end position.
  2646. * @returns {Array} Returns `array`.
  2647. */
  2648. function baseFill(array, value, start, end) {
  2649. var length = array.length;
  2650. start = toInteger(start);
  2651. if (start < 0) {
  2652. start = -start > length ? 0 : (length + start);
  2653. }
  2654. end = (end === undefined || end > length) ? length : toInteger(end);
  2655. if (end < 0) {
  2656. end += length;
  2657. }
  2658. end = start > end ? 0 : toLength(end);
  2659. while (start < end) {
  2660. array[start++] = value;
  2661. }
  2662. return array;
  2663. }
  2664. /**
  2665. * The base implementation of `_.filter` without support for iteratee shorthands.
  2666. *
  2667. * @private
  2668. * @param {Array|Object} collection The collection to iterate over.
  2669. * @param {Function} predicate The function invoked per iteration.
  2670. * @returns {Array} Returns the new filtered array.
  2671. */
  2672. function baseFilter(collection, predicate) {
  2673. var result = [];
  2674. baseEach(collection, function(value, index, collection) {
  2675. if (predicate(value, index, collection)) {
  2676. result.push(value);
  2677. }
  2678. });
  2679. return result;
  2680. }
  2681. /**
  2682. * The base implementation of `_.flatten` with support for restricting flattening.
  2683. *
  2684. * @private
  2685. * @param {Array} array The array to flatten.
  2686. * @param {number} depth The maximum recursion depth.
  2687. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2688. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2689. * @param {Array} [result=[]] The initial result value.
  2690. * @returns {Array} Returns the new flattened array.
  2691. */
  2692. function baseFlatten(array, depth, predicate, isStrict, result) {
  2693. var index = -1,
  2694. length = array.length;
  2695. predicate || (predicate = isFlattenable);
  2696. result || (result = []);
  2697. while (++index < length) {
  2698. var value = array[index];
  2699. if (depth > 0 && predicate(value)) {
  2700. if (depth > 1) {
  2701. // Recursively flatten arrays (susceptible to call stack limits).
  2702. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2703. } else {
  2704. arrayPush(result, value);
  2705. }
  2706. } else if (!isStrict) {
  2707. result[result.length] = value;
  2708. }
  2709. }
  2710. return result;
  2711. }
  2712. /**
  2713. * The base implementation of `baseForOwn` which iterates over `object`
  2714. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2715. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2716. *
  2717. * @private
  2718. * @param {Object} object The object to iterate over.
  2719. * @param {Function} iteratee The function invoked per iteration.
  2720. * @param {Function} keysFunc The function to get the keys of `object`.
  2721. * @returns {Object} Returns `object`.
  2722. */
  2723. var baseFor = createBaseFor();
  2724. /**
  2725. * This function is like `baseFor` except that it iterates over properties
  2726. * in the opposite order.
  2727. *
  2728. * @private
  2729. * @param {Object} object The object to iterate over.
  2730. * @param {Function} iteratee The function invoked per iteration.
  2731. * @param {Function} keysFunc The function to get the keys of `object`.
  2732. * @returns {Object} Returns `object`.
  2733. */
  2734. var baseForRight = createBaseFor(true);
  2735. /**
  2736. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2737. *
  2738. * @private
  2739. * @param {Object} object The object to iterate over.
  2740. * @param {Function} iteratee The function invoked per iteration.
  2741. * @returns {Object} Returns `object`.
  2742. */
  2743. function baseForOwn(object, iteratee) {
  2744. return object && baseFor(object, iteratee, keys);
  2745. }
  2746. /**
  2747. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2748. *
  2749. * @private
  2750. * @param {Object} object The object to iterate over.
  2751. * @param {Function} iteratee The function invoked per iteration.
  2752. * @returns {Object} Returns `object`.
  2753. */
  2754. function baseForOwnRight(object, iteratee) {
  2755. return object && baseForRight(object, iteratee, keys);
  2756. }
  2757. /**
  2758. * The base implementation of `_.functions` which creates an array of
  2759. * `object` function property names filtered from `props`.
  2760. *
  2761. * @private
  2762. * @param {Object} object The object to inspect.
  2763. * @param {Array} props The property names to filter.
  2764. * @returns {Array} Returns the function names.
  2765. */
  2766. function baseFunctions(object, props) {
  2767. return arrayFilter(props, function(key) {
  2768. return isFunction(object[key]);
  2769. });
  2770. }
  2771. /**
  2772. * The base implementation of `_.get` without support for default values.
  2773. *
  2774. * @private
  2775. * @param {Object} object The object to query.
  2776. * @param {Array|string} path The path of the property to get.
  2777. * @returns {*} Returns the resolved value.
  2778. */
  2779. function baseGet(object, path) {
  2780. path = castPath(path, object);
  2781. var index = 0,
  2782. length = path.length;
  2783. while (object != null && index < length) {
  2784. object = object[toKey(path[index++])];
  2785. }
  2786. return (index && index == length) ? object : undefined;
  2787. }
  2788. /**
  2789. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2790. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2791. * symbols of `object`.
  2792. *
  2793. * @private
  2794. * @param {Object} object The object to query.
  2795. * @param {Function} keysFunc The function to get the keys of `object`.
  2796. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2797. * @returns {Array} Returns the array of property names and symbols.
  2798. */
  2799. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2800. var result = keysFunc(object);
  2801. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2802. }
  2803. /**
  2804. * The base implementation of `getTag` without fallbacks for buggy environments.
  2805. *
  2806. * @private
  2807. * @param {*} value The value to query.
  2808. * @returns {string} Returns the `toStringTag`.
  2809. */
  2810. function baseGetTag(value) {
  2811. if (value == null) {
  2812. return value === undefined ? undefinedTag : nullTag;
  2813. }
  2814. return (symToStringTag && symToStringTag in Object(value))
  2815. ? getRawTag(value)
  2816. : objectToString(value);
  2817. }
  2818. /**
  2819. * The base implementation of `_.gt` which doesn't coerce arguments.
  2820. *
  2821. * @private
  2822. * @param {*} value The value to compare.
  2823. * @param {*} other The other value to compare.
  2824. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2825. * else `false`.
  2826. */
  2827. function baseGt(value, other) {
  2828. return value > other;
  2829. }
  2830. /**
  2831. * The base implementation of `_.has` without support for deep paths.
  2832. *
  2833. * @private
  2834. * @param {Object} [object] The object to query.
  2835. * @param {Array|string} key The key to check.
  2836. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2837. */
  2838. function baseHas(object, key) {
  2839. return object != null && hasOwnProperty.call(object, key);
  2840. }
  2841. /**
  2842. * The base implementation of `_.hasIn` without support for deep paths.
  2843. *
  2844. * @private
  2845. * @param {Object} [object] The object to query.
  2846. * @param {Array|string} key The key to check.
  2847. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2848. */
  2849. function baseHasIn(object, key) {
  2850. return object != null && key in Object(object);
  2851. }
  2852. /**
  2853. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2854. *
  2855. * @private
  2856. * @param {number} number The number to check.
  2857. * @param {number} start The start of the range.
  2858. * @param {number} end The end of the range.
  2859. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2860. */
  2861. function baseInRange(number, start, end) {
  2862. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2863. }
  2864. /**
  2865. * The base implementation of methods like `_.intersection`, without support
  2866. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2867. *
  2868. * @private
  2869. * @param {Array} arrays The arrays to inspect.
  2870. * @param {Function} [iteratee] The iteratee invoked per element.
  2871. * @param {Function} [comparator] The comparator invoked per element.
  2872. * @returns {Array} Returns the new array of shared values.
  2873. */
  2874. function baseIntersection(arrays, iteratee, comparator) {
  2875. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2876. length = arrays[0].length,
  2877. othLength = arrays.length,
  2878. othIndex = othLength,
  2879. caches = Array(othLength),
  2880. maxLength = Infinity,
  2881. result = [];
  2882. while (othIndex--) {
  2883. var array = arrays[othIndex];
  2884. if (othIndex && iteratee) {
  2885. array = arrayMap(array, baseUnary(iteratee));
  2886. }
  2887. maxLength = nativeMin(array.length, maxLength);
  2888. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2889. ? new SetCache(othIndex && array)
  2890. : undefined;
  2891. }
  2892. array = arrays[0];
  2893. var index = -1,
  2894. seen = caches[0];
  2895. outer:
  2896. while (++index < length && result.length < maxLength) {
  2897. var value = array[index],
  2898. computed = iteratee ? iteratee(value) : value;
  2899. value = (comparator || value !== 0) ? value : 0;
  2900. if (!(seen
  2901. ? cacheHas(seen, computed)
  2902. : includes(result, computed, comparator)
  2903. )) {
  2904. othIndex = othLength;
  2905. while (--othIndex) {
  2906. var cache = caches[othIndex];
  2907. if (!(cache
  2908. ? cacheHas(cache, computed)
  2909. : includes(arrays[othIndex], computed, comparator))
  2910. ) {
  2911. continue outer;
  2912. }
  2913. }
  2914. if (seen) {
  2915. seen.push(computed);
  2916. }
  2917. result.push(value);
  2918. }
  2919. }
  2920. return result;
  2921. }
  2922. /**
  2923. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2924. * `object` with values transformed by `iteratee` and set by `setter`.
  2925. *
  2926. * @private
  2927. * @param {Object} object The object to iterate over.
  2928. * @param {Function} setter The function to set `accumulator` values.
  2929. * @param {Function} iteratee The iteratee to transform values.
  2930. * @param {Object} accumulator The initial inverted object.
  2931. * @returns {Function} Returns `accumulator`.
  2932. */
  2933. function baseInverter(object, setter, iteratee, accumulator) {
  2934. baseForOwn(object, function(value, key, object) {
  2935. setter(accumulator, iteratee(value), key, object);
  2936. });
  2937. return accumulator;
  2938. }
  2939. /**
  2940. * The base implementation of `_.invoke` without support for individual
  2941. * method arguments.
  2942. *
  2943. * @private
  2944. * @param {Object} object The object to query.
  2945. * @param {Array|string} path The path of the method to invoke.
  2946. * @param {Array} args The arguments to invoke the method with.
  2947. * @returns {*} Returns the result of the invoked method.
  2948. */
  2949. function baseInvoke(object, path, args) {
  2950. path = castPath(path, object);
  2951. object = parent(object, path);
  2952. var func = object == null ? object : object[toKey(last(path))];
  2953. return func == null ? undefined : apply(func, object, args);
  2954. }
  2955. /**
  2956. * The base implementation of `_.isArguments`.
  2957. *
  2958. * @private
  2959. * @param {*} value The value to check.
  2960. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2961. */
  2962. function baseIsArguments(value) {
  2963. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2964. }
  2965. /**
  2966. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2967. *
  2968. * @private
  2969. * @param {*} value The value to check.
  2970. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2971. */
  2972. function baseIsArrayBuffer(value) {
  2973. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2974. }
  2975. /**
  2976. * The base implementation of `_.isDate` without Node.js optimizations.
  2977. *
  2978. * @private
  2979. * @param {*} value The value to check.
  2980. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2981. */
  2982. function baseIsDate(value) {
  2983. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2984. }
  2985. /**
  2986. * The base implementation of `_.isEqual` which supports partial comparisons
  2987. * and tracks traversed objects.
  2988. *
  2989. * @private
  2990. * @param {*} value The value to compare.
  2991. * @param {*} other The other value to compare.
  2992. * @param {boolean} bitmask The bitmask flags.
  2993. * 1 - Unordered comparison
  2994. * 2 - Partial comparison
  2995. * @param {Function} [customizer] The function to customize comparisons.
  2996. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2997. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2998. */
  2999. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3000. if (value === other) {
  3001. return true;
  3002. }
  3003. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  3004. return value !== value && other !== other;
  3005. }
  3006. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  3007. }
  3008. /**
  3009. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3010. * deep comparisons and tracks traversed objects enabling objects with circular
  3011. * references to be compared.
  3012. *
  3013. * @private
  3014. * @param {Object} object The object to compare.
  3015. * @param {Object} other The other object to compare.
  3016. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3017. * @param {Function} customizer The function to customize comparisons.
  3018. * @param {Function} equalFunc The function to determine equivalents of values.
  3019. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3020. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3021. */
  3022. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3023. var objIsArr = isArray(object),
  3024. othIsArr = isArray(other),
  3025. objTag = objIsArr ? arrayTag : getTag(object),
  3026. othTag = othIsArr ? arrayTag : getTag(other);
  3027. objTag = objTag == argsTag ? objectTag : objTag;
  3028. othTag = othTag == argsTag ? objectTag : othTag;
  3029. var objIsObj = objTag == objectTag,
  3030. othIsObj = othTag == objectTag,
  3031. isSameTag = objTag == othTag;
  3032. if (isSameTag && isBuffer(object)) {
  3033. if (!isBuffer(other)) {
  3034. return false;
  3035. }
  3036. objIsArr = true;
  3037. objIsObj = false;
  3038. }
  3039. if (isSameTag && !objIsObj) {
  3040. stack || (stack = new Stack);
  3041. return (objIsArr || isTypedArray(object))
  3042. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3043. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3044. }
  3045. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3046. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3047. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3048. if (objIsWrapped || othIsWrapped) {
  3049. var objUnwrapped = objIsWrapped ? object.value() : object,
  3050. othUnwrapped = othIsWrapped ? other.value() : other;
  3051. stack || (stack = new Stack);
  3052. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3053. }
  3054. }
  3055. if (!isSameTag) {
  3056. return false;
  3057. }
  3058. stack || (stack = new Stack);
  3059. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3060. }
  3061. /**
  3062. * The base implementation of `_.isMap` without Node.js optimizations.
  3063. *
  3064. * @private
  3065. * @param {*} value The value to check.
  3066. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3067. */
  3068. function baseIsMap(value) {
  3069. return isObjectLike(value) && getTag(value) == mapTag;
  3070. }
  3071. /**
  3072. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3073. *
  3074. * @private
  3075. * @param {Object} object The object to inspect.
  3076. * @param {Object} source The object of property values to match.
  3077. * @param {Array} matchData The property names, values, and compare flags to match.
  3078. * @param {Function} [customizer] The function to customize comparisons.
  3079. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3080. */
  3081. function baseIsMatch(object, source, matchData, customizer) {
  3082. var index = matchData.length,
  3083. length = index,
  3084. noCustomizer = !customizer;
  3085. if (object == null) {
  3086. return !length;
  3087. }
  3088. object = Object(object);
  3089. while (index--) {
  3090. var data = matchData[index];
  3091. if ((noCustomizer && data[2])
  3092. ? data[1] !== object[data[0]]
  3093. : !(data[0] in object)
  3094. ) {
  3095. return false;
  3096. }
  3097. }
  3098. while (++index < length) {
  3099. data = matchData[index];
  3100. var key = data[0],
  3101. objValue = object[key],
  3102. srcValue = data[1];
  3103. if (noCustomizer && data[2]) {
  3104. if (objValue === undefined && !(key in object)) {
  3105. return false;
  3106. }
  3107. } else {
  3108. var stack = new Stack;
  3109. if (customizer) {
  3110. var result = customizer(objValue, srcValue, key, object, source, stack);
  3111. }
  3112. if (!(result === undefined
  3113. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3114. : result
  3115. )) {
  3116. return false;
  3117. }
  3118. }
  3119. }
  3120. return true;
  3121. }
  3122. /**
  3123. * The base implementation of `_.isNative` without bad shim checks.
  3124. *
  3125. * @private
  3126. * @param {*} value The value to check.
  3127. * @returns {boolean} Returns `true` if `value` is a native function,
  3128. * else `false`.
  3129. */
  3130. function baseIsNative(value) {
  3131. if (!isObject(value) || isMasked(value)) {
  3132. return false;
  3133. }
  3134. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3135. return pattern.test(toSource(value));
  3136. }
  3137. /**
  3138. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3139. *
  3140. * @private
  3141. * @param {*} value The value to check.
  3142. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3143. */
  3144. function baseIsRegExp(value) {
  3145. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3146. }
  3147. /**
  3148. * The base implementation of `_.isSet` without Node.js optimizations.
  3149. *
  3150. * @private
  3151. * @param {*} value The value to check.
  3152. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3153. */
  3154. function baseIsSet(value) {
  3155. return isObjectLike(value) && getTag(value) == setTag;
  3156. }
  3157. /**
  3158. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3159. *
  3160. * @private
  3161. * @param {*} value The value to check.
  3162. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3163. */
  3164. function baseIsTypedArray(value) {
  3165. return isObjectLike(value) &&
  3166. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3167. }
  3168. /**
  3169. * The base implementation of `_.iteratee`.
  3170. *
  3171. * @private
  3172. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3173. * @returns {Function} Returns the iteratee.
  3174. */
  3175. function baseIteratee(value) {
  3176. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3177. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3178. if (typeof value == 'function') {
  3179. return value;
  3180. }
  3181. if (value == null) {
  3182. return identity;
  3183. }
  3184. if (typeof value == 'object') {
  3185. return isArray(value)
  3186. ? baseMatchesProperty(value[0], value[1])
  3187. : baseMatches(value);
  3188. }
  3189. return property(value);
  3190. }
  3191. /**
  3192. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3193. *
  3194. * @private
  3195. * @param {Object} object The object to query.
  3196. * @returns {Array} Returns the array of property names.
  3197. */
  3198. function baseKeys(object) {
  3199. if (!isPrototype(object)) {
  3200. return nativeKeys(object);
  3201. }
  3202. var result = [];
  3203. for (var key in Object(object)) {
  3204. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3205. result.push(key);
  3206. }
  3207. }
  3208. return result;
  3209. }
  3210. /**
  3211. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3212. *
  3213. * @private
  3214. * @param {Object} object The object to query.
  3215. * @returns {Array} Returns the array of property names.
  3216. */
  3217. function baseKeysIn(object) {
  3218. if (!isObject(object)) {
  3219. return nativeKeysIn(object);
  3220. }
  3221. var isProto = isPrototype(object),
  3222. result = [];
  3223. for (var key in object) {
  3224. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3225. result.push(key);
  3226. }
  3227. }
  3228. return result;
  3229. }
  3230. /**
  3231. * The base implementation of `_.lt` which doesn't coerce arguments.
  3232. *
  3233. * @private
  3234. * @param {*} value The value to compare.
  3235. * @param {*} other The other value to compare.
  3236. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3237. * else `false`.
  3238. */
  3239. function baseLt(value, other) {
  3240. return value < other;
  3241. }
  3242. /**
  3243. * The base implementation of `_.map` without support for iteratee shorthands.
  3244. *
  3245. * @private
  3246. * @param {Array|Object} collection The collection to iterate over.
  3247. * @param {Function} iteratee The function invoked per iteration.
  3248. * @returns {Array} Returns the new mapped array.
  3249. */
  3250. function baseMap(collection, iteratee) {
  3251. var index = -1,
  3252. result = isArrayLike(collection) ? Array(collection.length) : [];
  3253. baseEach(collection, function(value, key, collection) {
  3254. result[++index] = iteratee(value, key, collection);
  3255. });
  3256. return result;
  3257. }
  3258. /**
  3259. * The base implementation of `_.matches` which doesn't clone `source`.
  3260. *
  3261. * @private
  3262. * @param {Object} source The object of property values to match.
  3263. * @returns {Function} Returns the new spec function.
  3264. */
  3265. function baseMatches(source) {
  3266. var matchData = getMatchData(source);
  3267. if (matchData.length == 1 && matchData[0][2]) {
  3268. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3269. }
  3270. return function(object) {
  3271. return object === source || baseIsMatch(object, source, matchData);
  3272. };
  3273. }
  3274. /**
  3275. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3276. *
  3277. * @private
  3278. * @param {string} path The path of the property to get.
  3279. * @param {*} srcValue The value to match.
  3280. * @returns {Function} Returns the new spec function.
  3281. */
  3282. function baseMatchesProperty(path, srcValue) {
  3283. if (isKey(path) && isStrictComparable(srcValue)) {
  3284. return matchesStrictComparable(toKey(path), srcValue);
  3285. }
  3286. return function(object) {
  3287. var objValue = get(object, path);
  3288. return (objValue === undefined && objValue === srcValue)
  3289. ? hasIn(object, path)
  3290. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3291. };
  3292. }
  3293. /**
  3294. * The base implementation of `_.merge` without support for multiple sources.
  3295. *
  3296. * @private
  3297. * @param {Object} object The destination object.
  3298. * @param {Object} source The source object.
  3299. * @param {number} srcIndex The index of `source`.
  3300. * @param {Function} [customizer] The function to customize merged values.
  3301. * @param {Object} [stack] Tracks traversed source values and their merged
  3302. * counterparts.
  3303. */
  3304. function baseMerge(object, source, srcIndex, customizer, stack) {
  3305. if (object === source) {
  3306. return;
  3307. }
  3308. baseFor(source, function(srcValue, key) {
  3309. stack || (stack = new Stack);
  3310. if (isObject(srcValue)) {
  3311. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3312. }
  3313. else {
  3314. var newValue = customizer
  3315. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3316. : undefined;
  3317. if (newValue === undefined) {
  3318. newValue = srcValue;
  3319. }
  3320. assignMergeValue(object, key, newValue);
  3321. }
  3322. }, keysIn);
  3323. }
  3324. /**
  3325. * A specialized version of `baseMerge` for arrays and objects which performs
  3326. * deep merges and tracks traversed objects enabling objects with circular
  3327. * references to be merged.
  3328. *
  3329. * @private
  3330. * @param {Object} object The destination object.
  3331. * @param {Object} source The source object.
  3332. * @param {string} key The key of the value to merge.
  3333. * @param {number} srcIndex The index of `source`.
  3334. * @param {Function} mergeFunc The function to merge values.
  3335. * @param {Function} [customizer] The function to customize assigned values.
  3336. * @param {Object} [stack] Tracks traversed source values and their merged
  3337. * counterparts.
  3338. */
  3339. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3340. var objValue = safeGet(object, key),
  3341. srcValue = safeGet(source, key),
  3342. stacked = stack.get(srcValue);
  3343. if (stacked) {
  3344. assignMergeValue(object, key, stacked);
  3345. return;
  3346. }
  3347. var newValue = customizer
  3348. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3349. : undefined;
  3350. var isCommon = newValue === undefined;
  3351. if (isCommon) {
  3352. var isArr = isArray(srcValue),
  3353. isBuff = !isArr && isBuffer(srcValue),
  3354. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3355. newValue = srcValue;
  3356. if (isArr || isBuff || isTyped) {
  3357. if (isArray(objValue)) {
  3358. newValue = objValue;
  3359. }
  3360. else if (isArrayLikeObject(objValue)) {
  3361. newValue = copyArray(objValue);
  3362. }
  3363. else if (isBuff) {
  3364. isCommon = false;
  3365. newValue = cloneBuffer(srcValue, true);
  3366. }
  3367. else if (isTyped) {
  3368. isCommon = false;
  3369. newValue = cloneTypedArray(srcValue, true);
  3370. }
  3371. else {
  3372. newValue = [];
  3373. }
  3374. }
  3375. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3376. newValue = objValue;
  3377. if (isArguments(objValue)) {
  3378. newValue = toPlainObject(objValue);
  3379. }
  3380. else if (!isObject(objValue) || isFunction(objValue)) {
  3381. newValue = initCloneObject(srcValue);
  3382. }
  3383. }
  3384. else {
  3385. isCommon = false;
  3386. }
  3387. }
  3388. if (isCommon) {
  3389. // Recursively merge objects and arrays (susceptible to call stack limits).
  3390. stack.set(srcValue, newValue);
  3391. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3392. stack['delete'](srcValue);
  3393. }
  3394. assignMergeValue(object, key, newValue);
  3395. }
  3396. /**
  3397. * The base implementation of `_.nth` which doesn't coerce arguments.
  3398. *
  3399. * @private
  3400. * @param {Array} array The array to query.
  3401. * @param {number} n The index of the element to return.
  3402. * @returns {*} Returns the nth element of `array`.
  3403. */
  3404. function baseNth(array, n) {
  3405. var length = array.length;
  3406. if (!length) {
  3407. return;
  3408. }
  3409. n += n < 0 ? length : 0;
  3410. return isIndex(n, length) ? array[n] : undefined;
  3411. }
  3412. /**
  3413. * The base implementation of `_.orderBy` without param guards.
  3414. *
  3415. * @private
  3416. * @param {Array|Object} collection The collection to iterate over.
  3417. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3418. * @param {string[]} orders The sort orders of `iteratees`.
  3419. * @returns {Array} Returns the new sorted array.
  3420. */
  3421. function baseOrderBy(collection, iteratees, orders) {
  3422. if (iteratees.length) {
  3423. iteratees = arrayMap(iteratees, function(iteratee) {
  3424. if (isArray(iteratee)) {
  3425. return function(value) {
  3426. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  3427. }
  3428. }
  3429. return iteratee;
  3430. });
  3431. } else {
  3432. iteratees = [identity];
  3433. }
  3434. var index = -1;
  3435. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  3436. var result = baseMap(collection, function(value, key, collection) {
  3437. var criteria = arrayMap(iteratees, function(iteratee) {
  3438. return iteratee(value);
  3439. });
  3440. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3441. });
  3442. return baseSortBy(result, function(object, other) {
  3443. return compareMultiple(object, other, orders);
  3444. });
  3445. }
  3446. /**
  3447. * The base implementation of `_.pick` without support for individual
  3448. * property identifiers.
  3449. *
  3450. * @private
  3451. * @param {Object} object The source object.
  3452. * @param {string[]} paths The property paths to pick.
  3453. * @returns {Object} Returns the new object.
  3454. */
  3455. function basePick(object, paths) {
  3456. return basePickBy(object, paths, function(value, path) {
  3457. return hasIn(object, path);
  3458. });
  3459. }
  3460. /**
  3461. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3462. *
  3463. * @private
  3464. * @param {Object} object The source object.
  3465. * @param {string[]} paths The property paths to pick.
  3466. * @param {Function} predicate The function invoked per property.
  3467. * @returns {Object} Returns the new object.
  3468. */
  3469. function basePickBy(object, paths, predicate) {
  3470. var index = -1,
  3471. length = paths.length,
  3472. result = {};
  3473. while (++index < length) {
  3474. var path = paths[index],
  3475. value = baseGet(object, path);
  3476. if (predicate(value, path)) {
  3477. baseSet(result, castPath(path, object), value);
  3478. }
  3479. }
  3480. return result;
  3481. }
  3482. /**
  3483. * A specialized version of `baseProperty` which supports deep paths.
  3484. *
  3485. * @private
  3486. * @param {Array|string} path The path of the property to get.
  3487. * @returns {Function} Returns the new accessor function.
  3488. */
  3489. function basePropertyDeep(path) {
  3490. return function(object) {
  3491. return baseGet(object, path);
  3492. };
  3493. }
  3494. /**
  3495. * The base implementation of `_.pullAllBy` without support for iteratee
  3496. * shorthands.
  3497. *
  3498. * @private
  3499. * @param {Array} array The array to modify.
  3500. * @param {Array} values The values to remove.
  3501. * @param {Function} [iteratee] The iteratee invoked per element.
  3502. * @param {Function} [comparator] The comparator invoked per element.
  3503. * @returns {Array} Returns `array`.
  3504. */
  3505. function basePullAll(array, values, iteratee, comparator) {
  3506. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3507. index = -1,
  3508. length = values.length,
  3509. seen = array;
  3510. if (array === values) {
  3511. values = copyArray(values);
  3512. }
  3513. if (iteratee) {
  3514. seen = arrayMap(array, baseUnary(iteratee));
  3515. }
  3516. while (++index < length) {
  3517. var fromIndex = 0,
  3518. value = values[index],
  3519. computed = iteratee ? iteratee(value) : value;
  3520. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3521. if (seen !== array) {
  3522. splice.call(seen, fromIndex, 1);
  3523. }
  3524. splice.call(array, fromIndex, 1);
  3525. }
  3526. }
  3527. return array;
  3528. }
  3529. /**
  3530. * The base implementation of `_.pullAt` without support for individual
  3531. * indexes or capturing the removed elements.
  3532. *
  3533. * @private
  3534. * @param {Array} array The array to modify.
  3535. * @param {number[]} indexes The indexes of elements to remove.
  3536. * @returns {Array} Returns `array`.
  3537. */
  3538. function basePullAt(array, indexes) {
  3539. var length = array ? indexes.length : 0,
  3540. lastIndex = length - 1;
  3541. while (length--) {
  3542. var index = indexes[length];
  3543. if (length == lastIndex || index !== previous) {
  3544. var previous = index;
  3545. if (isIndex(index)) {
  3546. splice.call(array, index, 1);
  3547. } else {
  3548. baseUnset(array, index);
  3549. }
  3550. }
  3551. }
  3552. return array;
  3553. }
  3554. /**
  3555. * The base implementation of `_.random` without support for returning
  3556. * floating-point numbers.
  3557. *
  3558. * @private
  3559. * @param {number} lower The lower bound.
  3560. * @param {number} upper The upper bound.
  3561. * @returns {number} Returns the random number.
  3562. */
  3563. function baseRandom(lower, upper) {
  3564. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3565. }
  3566. /**
  3567. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3568. * coerce arguments.
  3569. *
  3570. * @private
  3571. * @param {number} start The start of the range.
  3572. * @param {number} end The end of the range.
  3573. * @param {number} step The value to increment or decrement by.
  3574. * @param {boolean} [fromRight] Specify iterating from right to left.
  3575. * @returns {Array} Returns the range of numbers.
  3576. */
  3577. function baseRange(start, end, step, fromRight) {
  3578. var index = -1,
  3579. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3580. result = Array(length);
  3581. while (length--) {
  3582. result[fromRight ? length : ++index] = start;
  3583. start += step;
  3584. }
  3585. return result;
  3586. }
  3587. /**
  3588. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3589. *
  3590. * @private
  3591. * @param {string} string The string to repeat.
  3592. * @param {number} n The number of times to repeat the string.
  3593. * @returns {string} Returns the repeated string.
  3594. */
  3595. function baseRepeat(string, n) {
  3596. var result = '';
  3597. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3598. return result;
  3599. }
  3600. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3601. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3602. do {
  3603. if (n % 2) {
  3604. result += string;
  3605. }
  3606. n = nativeFloor(n / 2);
  3607. if (n) {
  3608. string += string;
  3609. }
  3610. } while (n);
  3611. return result;
  3612. }
  3613. /**
  3614. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3615. *
  3616. * @private
  3617. * @param {Function} func The function to apply a rest parameter to.
  3618. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3619. * @returns {Function} Returns the new function.
  3620. */
  3621. function baseRest(func, start) {
  3622. return setToString(overRest(func, start, identity), func + '');
  3623. }
  3624. /**
  3625. * The base implementation of `_.sample`.
  3626. *
  3627. * @private
  3628. * @param {Array|Object} collection The collection to sample.
  3629. * @returns {*} Returns the random element.
  3630. */
  3631. function baseSample(collection) {
  3632. return arraySample(values(collection));
  3633. }
  3634. /**
  3635. * The base implementation of `_.sampleSize` without param guards.
  3636. *
  3637. * @private
  3638. * @param {Array|Object} collection The collection to sample.
  3639. * @param {number} n The number of elements to sample.
  3640. * @returns {Array} Returns the random elements.
  3641. */
  3642. function baseSampleSize(collection, n) {
  3643. var array = values(collection);
  3644. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3645. }
  3646. /**
  3647. * The base implementation of `_.set`.
  3648. *
  3649. * @private
  3650. * @param {Object} object The object to modify.
  3651. * @param {Array|string} path The path of the property to set.
  3652. * @param {*} value The value to set.
  3653. * @param {Function} [customizer] The function to customize path creation.
  3654. * @returns {Object} Returns `object`.
  3655. */
  3656. function baseSet(object, path, value, customizer) {
  3657. if (!isObject(object)) {
  3658. return object;
  3659. }
  3660. path = castPath(path, object);
  3661. var index = -1,
  3662. length = path.length,
  3663. lastIndex = length - 1,
  3664. nested = object;
  3665. while (nested != null && ++index < length) {
  3666. var key = toKey(path[index]),
  3667. newValue = value;
  3668. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  3669. return object;
  3670. }
  3671. if (index != lastIndex) {
  3672. var objValue = nested[key];
  3673. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3674. if (newValue === undefined) {
  3675. newValue = isObject(objValue)
  3676. ? objValue
  3677. : (isIndex(path[index + 1]) ? [] : {});
  3678. }
  3679. }
  3680. assignValue(nested, key, newValue);
  3681. nested = nested[key];
  3682. }
  3683. return object;
  3684. }
  3685. /**
  3686. * The base implementation of `setData` without support for hot loop shorting.
  3687. *
  3688. * @private
  3689. * @param {Function} func The function to associate metadata with.
  3690. * @param {*} data The metadata.
  3691. * @returns {Function} Returns `func`.
  3692. */
  3693. var baseSetData = !metaMap ? identity : function(func, data) {
  3694. metaMap.set(func, data);
  3695. return func;
  3696. };
  3697. /**
  3698. * The base implementation of `setToString` without support for hot loop shorting.
  3699. *
  3700. * @private
  3701. * @param {Function} func The function to modify.
  3702. * @param {Function} string The `toString` result.
  3703. * @returns {Function} Returns `func`.
  3704. */
  3705. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3706. return defineProperty(func, 'toString', {
  3707. 'configurable': true,
  3708. 'enumerable': false,
  3709. 'value': constant(string),
  3710. 'writable': true
  3711. });
  3712. };
  3713. /**
  3714. * The base implementation of `_.shuffle`.
  3715. *
  3716. * @private
  3717. * @param {Array|Object} collection The collection to shuffle.
  3718. * @returns {Array} Returns the new shuffled array.
  3719. */
  3720. function baseShuffle(collection) {
  3721. return shuffleSelf(values(collection));
  3722. }
  3723. /**
  3724. * The base implementation of `_.slice` without an iteratee call guard.
  3725. *
  3726. * @private
  3727. * @param {Array} array The array to slice.
  3728. * @param {number} [start=0] The start position.
  3729. * @param {number} [end=array.length] The end position.
  3730. * @returns {Array} Returns the slice of `array`.
  3731. */
  3732. function baseSlice(array, start, end) {
  3733. var index = -1,
  3734. length = array.length;
  3735. if (start < 0) {
  3736. start = -start > length ? 0 : (length + start);
  3737. }
  3738. end = end > length ? length : end;
  3739. if (end < 0) {
  3740. end += length;
  3741. }
  3742. length = start > end ? 0 : ((end - start) >>> 0);
  3743. start >>>= 0;
  3744. var result = Array(length);
  3745. while (++index < length) {
  3746. result[index] = array[index + start];
  3747. }
  3748. return result;
  3749. }
  3750. /**
  3751. * The base implementation of `_.some` without support for iteratee shorthands.
  3752. *
  3753. * @private
  3754. * @param {Array|Object} collection The collection to iterate over.
  3755. * @param {Function} predicate The function invoked per iteration.
  3756. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3757. * else `false`.
  3758. */
  3759. function baseSome(collection, predicate) {
  3760. var result;
  3761. baseEach(collection, function(value, index, collection) {
  3762. result = predicate(value, index, collection);
  3763. return !result;
  3764. });
  3765. return !!result;
  3766. }
  3767. /**
  3768. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3769. * performs a binary search of `array` to determine the index at which `value`
  3770. * should be inserted into `array` in order to maintain its sort order.
  3771. *
  3772. * @private
  3773. * @param {Array} array The sorted array to inspect.
  3774. * @param {*} value The value to evaluate.
  3775. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3776. * @returns {number} Returns the index at which `value` should be inserted
  3777. * into `array`.
  3778. */
  3779. function baseSortedIndex(array, value, retHighest) {
  3780. var low = 0,
  3781. high = array == null ? low : array.length;
  3782. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3783. while (low < high) {
  3784. var mid = (low + high) >>> 1,
  3785. computed = array[mid];
  3786. if (computed !== null && !isSymbol(computed) &&
  3787. (retHighest ? (computed <= value) : (computed < value))) {
  3788. low = mid + 1;
  3789. } else {
  3790. high = mid;
  3791. }
  3792. }
  3793. return high;
  3794. }
  3795. return baseSortedIndexBy(array, value, identity, retHighest);
  3796. }
  3797. /**
  3798. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3799. * which invokes `iteratee` for `value` and each element of `array` to compute
  3800. * their sort ranking. The iteratee is invoked with one argument; (value).
  3801. *
  3802. * @private
  3803. * @param {Array} array The sorted array to inspect.
  3804. * @param {*} value The value to evaluate.
  3805. * @param {Function} iteratee The iteratee invoked per element.
  3806. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3807. * @returns {number} Returns the index at which `value` should be inserted
  3808. * into `array`.
  3809. */
  3810. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3811. var low = 0,
  3812. high = array == null ? 0 : array.length;
  3813. if (high === 0) {
  3814. return 0;
  3815. }
  3816. value = iteratee(value);
  3817. var valIsNaN = value !== value,
  3818. valIsNull = value === null,
  3819. valIsSymbol = isSymbol(value),
  3820. valIsUndefined = value === undefined;
  3821. while (low < high) {
  3822. var mid = nativeFloor((low + high) / 2),
  3823. computed = iteratee(array[mid]),
  3824. othIsDefined = computed !== undefined,
  3825. othIsNull = computed === null,
  3826. othIsReflexive = computed === computed,
  3827. othIsSymbol = isSymbol(computed);
  3828. if (valIsNaN) {
  3829. var setLow = retHighest || othIsReflexive;
  3830. } else if (valIsUndefined) {
  3831. setLow = othIsReflexive && (retHighest || othIsDefined);
  3832. } else if (valIsNull) {
  3833. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3834. } else if (valIsSymbol) {
  3835. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3836. } else if (othIsNull || othIsSymbol) {
  3837. setLow = false;
  3838. } else {
  3839. setLow = retHighest ? (computed <= value) : (computed < value);
  3840. }
  3841. if (setLow) {
  3842. low = mid + 1;
  3843. } else {
  3844. high = mid;
  3845. }
  3846. }
  3847. return nativeMin(high, MAX_ARRAY_INDEX);
  3848. }
  3849. /**
  3850. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3851. * support for iteratee shorthands.
  3852. *
  3853. * @private
  3854. * @param {Array} array The array to inspect.
  3855. * @param {Function} [iteratee] The iteratee invoked per element.
  3856. * @returns {Array} Returns the new duplicate free array.
  3857. */
  3858. function baseSortedUniq(array, iteratee) {
  3859. var index = -1,
  3860. length = array.length,
  3861. resIndex = 0,
  3862. result = [];
  3863. while (++index < length) {
  3864. var value = array[index],
  3865. computed = iteratee ? iteratee(value) : value;
  3866. if (!index || !eq(computed, seen)) {
  3867. var seen = computed;
  3868. result[resIndex++] = value === 0 ? 0 : value;
  3869. }
  3870. }
  3871. return result;
  3872. }
  3873. /**
  3874. * The base implementation of `_.toNumber` which doesn't ensure correct
  3875. * conversions of binary, hexadecimal, or octal string values.
  3876. *
  3877. * @private
  3878. * @param {*} value The value to process.
  3879. * @returns {number} Returns the number.
  3880. */
  3881. function baseToNumber(value) {
  3882. if (typeof value == 'number') {
  3883. return value;
  3884. }
  3885. if (isSymbol(value)) {
  3886. return NAN;
  3887. }
  3888. return +value;
  3889. }
  3890. /**
  3891. * The base implementation of `_.toString` which doesn't convert nullish
  3892. * values to empty strings.
  3893. *
  3894. * @private
  3895. * @param {*} value The value to process.
  3896. * @returns {string} Returns the string.
  3897. */
  3898. function baseToString(value) {
  3899. // Exit early for strings to avoid a performance hit in some environments.
  3900. if (typeof value == 'string') {
  3901. return value;
  3902. }
  3903. if (isArray(value)) {
  3904. // Recursively convert values (susceptible to call stack limits).
  3905. return arrayMap(value, baseToString) + '';
  3906. }
  3907. if (isSymbol(value)) {
  3908. return symbolToString ? symbolToString.call(value) : '';
  3909. }
  3910. var result = (value + '');
  3911. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3912. }
  3913. /**
  3914. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3915. *
  3916. * @private
  3917. * @param {Array} array The array to inspect.
  3918. * @param {Function} [iteratee] The iteratee invoked per element.
  3919. * @param {Function} [comparator] The comparator invoked per element.
  3920. * @returns {Array} Returns the new duplicate free array.
  3921. */
  3922. function baseUniq(array, iteratee, comparator) {
  3923. var index = -1,
  3924. includes = arrayIncludes,
  3925. length = array.length,
  3926. isCommon = true,
  3927. result = [],
  3928. seen = result;
  3929. if (comparator) {
  3930. isCommon = false;
  3931. includes = arrayIncludesWith;
  3932. }
  3933. else if (length >= LARGE_ARRAY_SIZE) {
  3934. var set = iteratee ? null : createSet(array);
  3935. if (set) {
  3936. return setToArray(set);
  3937. }
  3938. isCommon = false;
  3939. includes = cacheHas;
  3940. seen = new SetCache;
  3941. }
  3942. else {
  3943. seen = iteratee ? [] : result;
  3944. }
  3945. outer:
  3946. while (++index < length) {
  3947. var value = array[index],
  3948. computed = iteratee ? iteratee(value) : value;
  3949. value = (comparator || value !== 0) ? value : 0;
  3950. if (isCommon && computed === computed) {
  3951. var seenIndex = seen.length;
  3952. while (seenIndex--) {
  3953. if (seen[seenIndex] === computed) {
  3954. continue outer;
  3955. }
  3956. }
  3957. if (iteratee) {
  3958. seen.push(computed);
  3959. }
  3960. result.push(value);
  3961. }
  3962. else if (!includes(seen, computed, comparator)) {
  3963. if (seen !== result) {
  3964. seen.push(computed);
  3965. }
  3966. result.push(value);
  3967. }
  3968. }
  3969. return result;
  3970. }
  3971. /**
  3972. * The base implementation of `_.unset`.
  3973. *
  3974. * @private
  3975. * @param {Object} object The object to modify.
  3976. * @param {Array|string} path The property path to unset.
  3977. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3978. */
  3979. function baseUnset(object, path) {
  3980. path = castPath(path, object);
  3981. object = parent(object, path);
  3982. return object == null || delete object[toKey(last(path))];
  3983. }
  3984. /**
  3985. * The base implementation of `_.update`.
  3986. *
  3987. * @private
  3988. * @param {Object} object The object to modify.
  3989. * @param {Array|string} path The path of the property to update.
  3990. * @param {Function} updater The function to produce the updated value.
  3991. * @param {Function} [customizer] The function to customize path creation.
  3992. * @returns {Object} Returns `object`.
  3993. */
  3994. function baseUpdate(object, path, updater, customizer) {
  3995. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3996. }
  3997. /**
  3998. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3999. * without support for iteratee shorthands.
  4000. *
  4001. * @private
  4002. * @param {Array} array The array to query.
  4003. * @param {Function} predicate The function invoked per iteration.
  4004. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4005. * @param {boolean} [fromRight] Specify iterating from right to left.
  4006. * @returns {Array} Returns the slice of `array`.
  4007. */
  4008. function baseWhile(array, predicate, isDrop, fromRight) {
  4009. var length = array.length,
  4010. index = fromRight ? length : -1;
  4011. while ((fromRight ? index-- : ++index < length) &&
  4012. predicate(array[index], index, array)) {}
  4013. return isDrop
  4014. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4015. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4016. }
  4017. /**
  4018. * The base implementation of `wrapperValue` which returns the result of
  4019. * performing a sequence of actions on the unwrapped `value`, where each
  4020. * successive action is supplied the return value of the previous.
  4021. *
  4022. * @private
  4023. * @param {*} value The unwrapped value.
  4024. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4025. * @returns {*} Returns the resolved value.
  4026. */
  4027. function baseWrapperValue(value, actions) {
  4028. var result = value;
  4029. if (result instanceof LazyWrapper) {
  4030. result = result.value();
  4031. }
  4032. return arrayReduce(actions, function(result, action) {
  4033. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  4034. }, result);
  4035. }
  4036. /**
  4037. * The base implementation of methods like `_.xor`, without support for
  4038. * iteratee shorthands, that accepts an array of arrays to inspect.
  4039. *
  4040. * @private
  4041. * @param {Array} arrays The arrays to inspect.
  4042. * @param {Function} [iteratee] The iteratee invoked per element.
  4043. * @param {Function} [comparator] The comparator invoked per element.
  4044. * @returns {Array} Returns the new array of values.
  4045. */
  4046. function baseXor(arrays, iteratee, comparator) {
  4047. var length = arrays.length;
  4048. if (length < 2) {
  4049. return length ? baseUniq(arrays[0]) : [];
  4050. }
  4051. var index = -1,
  4052. result = Array(length);
  4053. while (++index < length) {
  4054. var array = arrays[index],
  4055. othIndex = -1;
  4056. while (++othIndex < length) {
  4057. if (othIndex != index) {
  4058. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4059. }
  4060. }
  4061. }
  4062. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4063. }
  4064. /**
  4065. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4066. *
  4067. * @private
  4068. * @param {Array} props The property identifiers.
  4069. * @param {Array} values The property values.
  4070. * @param {Function} assignFunc The function to assign values.
  4071. * @returns {Object} Returns the new object.
  4072. */
  4073. function baseZipObject(props, values, assignFunc) {
  4074. var index = -1,
  4075. length = props.length,
  4076. valsLength = values.length,
  4077. result = {};
  4078. while (++index < length) {
  4079. var value = index < valsLength ? values[index] : undefined;
  4080. assignFunc(result, props[index], value);
  4081. }
  4082. return result;
  4083. }
  4084. /**
  4085. * Casts `value` to an empty array if it's not an array like object.
  4086. *
  4087. * @private
  4088. * @param {*} value The value to inspect.
  4089. * @returns {Array|Object} Returns the cast array-like object.
  4090. */
  4091. function castArrayLikeObject(value) {
  4092. return isArrayLikeObject(value) ? value : [];
  4093. }
  4094. /**
  4095. * Casts `value` to `identity` if it's not a function.
  4096. *
  4097. * @private
  4098. * @param {*} value The value to inspect.
  4099. * @returns {Function} Returns cast function.
  4100. */
  4101. function castFunction(value) {
  4102. return typeof value == 'function' ? value : identity;
  4103. }
  4104. /**
  4105. * Casts `value` to a path array if it's not one.
  4106. *
  4107. * @private
  4108. * @param {*} value The value to inspect.
  4109. * @param {Object} [object] The object to query keys on.
  4110. * @returns {Array} Returns the cast property path array.
  4111. */
  4112. function castPath(value, object) {
  4113. if (isArray(value)) {
  4114. return value;
  4115. }
  4116. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4117. }
  4118. /**
  4119. * A `baseRest` alias which can be replaced with `identity` by module
  4120. * replacement plugins.
  4121. *
  4122. * @private
  4123. * @type {Function}
  4124. * @param {Function} func The function to apply a rest parameter to.
  4125. * @returns {Function} Returns the new function.
  4126. */
  4127. var castRest = baseRest;
  4128. /**
  4129. * Casts `array` to a slice if it's needed.
  4130. *
  4131. * @private
  4132. * @param {Array} array The array to inspect.
  4133. * @param {number} start The start position.
  4134. * @param {number} [end=array.length] The end position.
  4135. * @returns {Array} Returns the cast slice.
  4136. */
  4137. function castSlice(array, start, end) {
  4138. var length = array.length;
  4139. end = end === undefined ? length : end;
  4140. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4141. }
  4142. /**
  4143. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4144. *
  4145. * @private
  4146. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4147. */
  4148. var clearTimeout = ctxClearTimeout || function(id) {
  4149. return root.clearTimeout(id);
  4150. };
  4151. /**
  4152. * Creates a clone of `buffer`.
  4153. *
  4154. * @private
  4155. * @param {Buffer} buffer The buffer to clone.
  4156. * @param {boolean} [isDeep] Specify a deep clone.
  4157. * @returns {Buffer} Returns the cloned buffer.
  4158. */
  4159. function cloneBuffer(buffer, isDeep) {
  4160. if (isDeep) {
  4161. return buffer.slice();
  4162. }
  4163. var length = buffer.length,
  4164. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4165. buffer.copy(result);
  4166. return result;
  4167. }
  4168. /**
  4169. * Creates a clone of `arrayBuffer`.
  4170. *
  4171. * @private
  4172. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4173. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4174. */
  4175. function cloneArrayBuffer(arrayBuffer) {
  4176. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4177. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4178. return result;
  4179. }
  4180. /**
  4181. * Creates a clone of `dataView`.
  4182. *
  4183. * @private
  4184. * @param {Object} dataView The data view to clone.
  4185. * @param {boolean} [isDeep] Specify a deep clone.
  4186. * @returns {Object} Returns the cloned data view.
  4187. */
  4188. function cloneDataView(dataView, isDeep) {
  4189. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4190. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4191. }
  4192. /**
  4193. * Creates a clone of `regexp`.
  4194. *
  4195. * @private
  4196. * @param {Object} regexp The regexp to clone.
  4197. * @returns {Object} Returns the cloned regexp.
  4198. */
  4199. function cloneRegExp(regexp) {
  4200. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4201. result.lastIndex = regexp.lastIndex;
  4202. return result;
  4203. }
  4204. /**
  4205. * Creates a clone of the `symbol` object.
  4206. *
  4207. * @private
  4208. * @param {Object} symbol The symbol object to clone.
  4209. * @returns {Object} Returns the cloned symbol object.
  4210. */
  4211. function cloneSymbol(symbol) {
  4212. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4213. }
  4214. /**
  4215. * Creates a clone of `typedArray`.
  4216. *
  4217. * @private
  4218. * @param {Object} typedArray The typed array to clone.
  4219. * @param {boolean} [isDeep] Specify a deep clone.
  4220. * @returns {Object} Returns the cloned typed array.
  4221. */
  4222. function cloneTypedArray(typedArray, isDeep) {
  4223. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4224. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4225. }
  4226. /**
  4227. * Compares values to sort them in ascending order.
  4228. *
  4229. * @private
  4230. * @param {*} value The value to compare.
  4231. * @param {*} other The other value to compare.
  4232. * @returns {number} Returns the sort order indicator for `value`.
  4233. */
  4234. function compareAscending(value, other) {
  4235. if (value !== other) {
  4236. var valIsDefined = value !== undefined,
  4237. valIsNull = value === null,
  4238. valIsReflexive = value === value,
  4239. valIsSymbol = isSymbol(value);
  4240. var othIsDefined = other !== undefined,
  4241. othIsNull = other === null,
  4242. othIsReflexive = other === other,
  4243. othIsSymbol = isSymbol(other);
  4244. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4245. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4246. (valIsNull && othIsDefined && othIsReflexive) ||
  4247. (!valIsDefined && othIsReflexive) ||
  4248. !valIsReflexive) {
  4249. return 1;
  4250. }
  4251. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4252. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4253. (othIsNull && valIsDefined && valIsReflexive) ||
  4254. (!othIsDefined && valIsReflexive) ||
  4255. !othIsReflexive) {
  4256. return -1;
  4257. }
  4258. }
  4259. return 0;
  4260. }
  4261. /**
  4262. * Used by `_.orderBy` to compare multiple properties of a value to another
  4263. * and stable sort them.
  4264. *
  4265. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4266. * specify an order of "desc" for descending or "asc" for ascending sort order
  4267. * of corresponding values.
  4268. *
  4269. * @private
  4270. * @param {Object} object The object to compare.
  4271. * @param {Object} other The other object to compare.
  4272. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4273. * @returns {number} Returns the sort order indicator for `object`.
  4274. */
  4275. function compareMultiple(object, other, orders) {
  4276. var index = -1,
  4277. objCriteria = object.criteria,
  4278. othCriteria = other.criteria,
  4279. length = objCriteria.length,
  4280. ordersLength = orders.length;
  4281. while (++index < length) {
  4282. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4283. if (result) {
  4284. if (index >= ordersLength) {
  4285. return result;
  4286. }
  4287. var order = orders[index];
  4288. return result * (order == 'desc' ? -1 : 1);
  4289. }
  4290. }
  4291. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4292. // that causes it, under certain circumstances, to provide the same value for
  4293. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4294. // for more details.
  4295. //
  4296. // This also ensures a stable sort in V8 and other engines.
  4297. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4298. return object.index - other.index;
  4299. }
  4300. /**
  4301. * Creates an array that is the composition of partially applied arguments,
  4302. * placeholders, and provided arguments into a single array of arguments.
  4303. *
  4304. * @private
  4305. * @param {Array} args The provided arguments.
  4306. * @param {Array} partials The arguments to prepend to those provided.
  4307. * @param {Array} holders The `partials` placeholder indexes.
  4308. * @params {boolean} [isCurried] Specify composing for a curried function.
  4309. * @returns {Array} Returns the new array of composed arguments.
  4310. */
  4311. function composeArgs(args, partials, holders, isCurried) {
  4312. var argsIndex = -1,
  4313. argsLength = args.length,
  4314. holdersLength = holders.length,
  4315. leftIndex = -1,
  4316. leftLength = partials.length,
  4317. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4318. result = Array(leftLength + rangeLength),
  4319. isUncurried = !isCurried;
  4320. while (++leftIndex < leftLength) {
  4321. result[leftIndex] = partials[leftIndex];
  4322. }
  4323. while (++argsIndex < holdersLength) {
  4324. if (isUncurried || argsIndex < argsLength) {
  4325. result[holders[argsIndex]] = args[argsIndex];
  4326. }
  4327. }
  4328. while (rangeLength--) {
  4329. result[leftIndex++] = args[argsIndex++];
  4330. }
  4331. return result;
  4332. }
  4333. /**
  4334. * This function is like `composeArgs` except that the arguments composition
  4335. * is tailored for `_.partialRight`.
  4336. *
  4337. * @private
  4338. * @param {Array} args The provided arguments.
  4339. * @param {Array} partials The arguments to append to those provided.
  4340. * @param {Array} holders The `partials` placeholder indexes.
  4341. * @params {boolean} [isCurried] Specify composing for a curried function.
  4342. * @returns {Array} Returns the new array of composed arguments.
  4343. */
  4344. function composeArgsRight(args, partials, holders, isCurried) {
  4345. var argsIndex = -1,
  4346. argsLength = args.length,
  4347. holdersIndex = -1,
  4348. holdersLength = holders.length,
  4349. rightIndex = -1,
  4350. rightLength = partials.length,
  4351. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4352. result = Array(rangeLength + rightLength),
  4353. isUncurried = !isCurried;
  4354. while (++argsIndex < rangeLength) {
  4355. result[argsIndex] = args[argsIndex];
  4356. }
  4357. var offset = argsIndex;
  4358. while (++rightIndex < rightLength) {
  4359. result[offset + rightIndex] = partials[rightIndex];
  4360. }
  4361. while (++holdersIndex < holdersLength) {
  4362. if (isUncurried || argsIndex < argsLength) {
  4363. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4364. }
  4365. }
  4366. return result;
  4367. }
  4368. /**
  4369. * Copies the values of `source` to `array`.
  4370. *
  4371. * @private
  4372. * @param {Array} source The array to copy values from.
  4373. * @param {Array} [array=[]] The array to copy values to.
  4374. * @returns {Array} Returns `array`.
  4375. */
  4376. function copyArray(source, array) {
  4377. var index = -1,
  4378. length = source.length;
  4379. array || (array = Array(length));
  4380. while (++index < length) {
  4381. array[index] = source[index];
  4382. }
  4383. return array;
  4384. }
  4385. /**
  4386. * Copies properties of `source` to `object`.
  4387. *
  4388. * @private
  4389. * @param {Object} source The object to copy properties from.
  4390. * @param {Array} props The property identifiers to copy.
  4391. * @param {Object} [object={}] The object to copy properties to.
  4392. * @param {Function} [customizer] The function to customize copied values.
  4393. * @returns {Object} Returns `object`.
  4394. */
  4395. function copyObject(source, props, object, customizer) {
  4396. var isNew = !object;
  4397. object || (object = {});
  4398. var index = -1,
  4399. length = props.length;
  4400. while (++index < length) {
  4401. var key = props[index];
  4402. var newValue = customizer
  4403. ? customizer(object[key], source[key], key, object, source)
  4404. : undefined;
  4405. if (newValue === undefined) {
  4406. newValue = source[key];
  4407. }
  4408. if (isNew) {
  4409. baseAssignValue(object, key, newValue);
  4410. } else {
  4411. assignValue(object, key, newValue);
  4412. }
  4413. }
  4414. return object;
  4415. }
  4416. /**
  4417. * Copies own symbols of `source` to `object`.
  4418. *
  4419. * @private
  4420. * @param {Object} source The object to copy symbols from.
  4421. * @param {Object} [object={}] The object to copy symbols to.
  4422. * @returns {Object} Returns `object`.
  4423. */
  4424. function copySymbols(source, object) {
  4425. return copyObject(source, getSymbols(source), object);
  4426. }
  4427. /**
  4428. * Copies own and inherited symbols of `source` to `object`.
  4429. *
  4430. * @private
  4431. * @param {Object} source The object to copy symbols from.
  4432. * @param {Object} [object={}] The object to copy symbols to.
  4433. * @returns {Object} Returns `object`.
  4434. */
  4435. function copySymbolsIn(source, object) {
  4436. return copyObject(source, getSymbolsIn(source), object);
  4437. }
  4438. /**
  4439. * Creates a function like `_.groupBy`.
  4440. *
  4441. * @private
  4442. * @param {Function} setter The function to set accumulator values.
  4443. * @param {Function} [initializer] The accumulator object initializer.
  4444. * @returns {Function} Returns the new aggregator function.
  4445. */
  4446. function createAggregator(setter, initializer) {
  4447. return function(collection, iteratee) {
  4448. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4449. accumulator = initializer ? initializer() : {};
  4450. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4451. };
  4452. }
  4453. /**
  4454. * Creates a function like `_.assign`.
  4455. *
  4456. * @private
  4457. * @param {Function} assigner The function to assign values.
  4458. * @returns {Function} Returns the new assigner function.
  4459. */
  4460. function createAssigner(assigner) {
  4461. return baseRest(function(object, sources) {
  4462. var index = -1,
  4463. length = sources.length,
  4464. customizer = length > 1 ? sources[length - 1] : undefined,
  4465. guard = length > 2 ? sources[2] : undefined;
  4466. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4467. ? (length--, customizer)
  4468. : undefined;
  4469. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4470. customizer = length < 3 ? undefined : customizer;
  4471. length = 1;
  4472. }
  4473. object = Object(object);
  4474. while (++index < length) {
  4475. var source = sources[index];
  4476. if (source) {
  4477. assigner(object, source, index, customizer);
  4478. }
  4479. }
  4480. return object;
  4481. });
  4482. }
  4483. /**
  4484. * Creates a `baseEach` or `baseEachRight` function.
  4485. *
  4486. * @private
  4487. * @param {Function} eachFunc The function to iterate over a collection.
  4488. * @param {boolean} [fromRight] Specify iterating from right to left.
  4489. * @returns {Function} Returns the new base function.
  4490. */
  4491. function createBaseEach(eachFunc, fromRight) {
  4492. return function(collection, iteratee) {
  4493. if (collection == null) {
  4494. return collection;
  4495. }
  4496. if (!isArrayLike(collection)) {
  4497. return eachFunc(collection, iteratee);
  4498. }
  4499. var length = collection.length,
  4500. index = fromRight ? length : -1,
  4501. iterable = Object(collection);
  4502. while ((fromRight ? index-- : ++index < length)) {
  4503. if (iteratee(iterable[index], index, iterable) === false) {
  4504. break;
  4505. }
  4506. }
  4507. return collection;
  4508. };
  4509. }
  4510. /**
  4511. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4512. *
  4513. * @private
  4514. * @param {boolean} [fromRight] Specify iterating from right to left.
  4515. * @returns {Function} Returns the new base function.
  4516. */
  4517. function createBaseFor(fromRight) {
  4518. return function(object, iteratee, keysFunc) {
  4519. var index = -1,
  4520. iterable = Object(object),
  4521. props = keysFunc(object),
  4522. length = props.length;
  4523. while (length--) {
  4524. var key = props[fromRight ? length : ++index];
  4525. if (iteratee(iterable[key], key, iterable) === false) {
  4526. break;
  4527. }
  4528. }
  4529. return object;
  4530. };
  4531. }
  4532. /**
  4533. * Creates a function that wraps `func` to invoke it with the optional `this`
  4534. * binding of `thisArg`.
  4535. *
  4536. * @private
  4537. * @param {Function} func The function to wrap.
  4538. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4539. * @param {*} [thisArg] The `this` binding of `func`.
  4540. * @returns {Function} Returns the new wrapped function.
  4541. */
  4542. function createBind(func, bitmask, thisArg) {
  4543. var isBind = bitmask & WRAP_BIND_FLAG,
  4544. Ctor = createCtor(func);
  4545. function wrapper() {
  4546. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4547. return fn.apply(isBind ? thisArg : this, arguments);
  4548. }
  4549. return wrapper;
  4550. }
  4551. /**
  4552. * Creates a function like `_.lowerFirst`.
  4553. *
  4554. * @private
  4555. * @param {string} methodName The name of the `String` case method to use.
  4556. * @returns {Function} Returns the new case function.
  4557. */
  4558. function createCaseFirst(methodName) {
  4559. return function(string) {
  4560. string = toString(string);
  4561. var strSymbols = hasUnicode(string)
  4562. ? stringToArray(string)
  4563. : undefined;
  4564. var chr = strSymbols
  4565. ? strSymbols[0]
  4566. : string.charAt(0);
  4567. var trailing = strSymbols
  4568. ? castSlice(strSymbols, 1).join('')
  4569. : string.slice(1);
  4570. return chr[methodName]() + trailing;
  4571. };
  4572. }
  4573. /**
  4574. * Creates a function like `_.camelCase`.
  4575. *
  4576. * @private
  4577. * @param {Function} callback The function to combine each word.
  4578. * @returns {Function} Returns the new compounder function.
  4579. */
  4580. function createCompounder(callback) {
  4581. return function(string) {
  4582. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4583. };
  4584. }
  4585. /**
  4586. * Creates a function that produces an instance of `Ctor` regardless of
  4587. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4588. *
  4589. * @private
  4590. * @param {Function} Ctor The constructor to wrap.
  4591. * @returns {Function} Returns the new wrapped function.
  4592. */
  4593. function createCtor(Ctor) {
  4594. return function() {
  4595. // Use a `switch` statement to work with class constructors. See
  4596. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4597. // for more details.
  4598. var args = arguments;
  4599. switch (args.length) {
  4600. case 0: return new Ctor;
  4601. case 1: return new Ctor(args[0]);
  4602. case 2: return new Ctor(args[0], args[1]);
  4603. case 3: return new Ctor(args[0], args[1], args[2]);
  4604. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4605. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4606. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4607. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4608. }
  4609. var thisBinding = baseCreate(Ctor.prototype),
  4610. result = Ctor.apply(thisBinding, args);
  4611. // Mimic the constructor's `return` behavior.
  4612. // See https://es5.github.io/#x13.2.2 for more details.
  4613. return isObject(result) ? result : thisBinding;
  4614. };
  4615. }
  4616. /**
  4617. * Creates a function that wraps `func` to enable currying.
  4618. *
  4619. * @private
  4620. * @param {Function} func The function to wrap.
  4621. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4622. * @param {number} arity The arity of `func`.
  4623. * @returns {Function} Returns the new wrapped function.
  4624. */
  4625. function createCurry(func, bitmask, arity) {
  4626. var Ctor = createCtor(func);
  4627. function wrapper() {
  4628. var length = arguments.length,
  4629. args = Array(length),
  4630. index = length,
  4631. placeholder = getHolder(wrapper);
  4632. while (index--) {
  4633. args[index] = arguments[index];
  4634. }
  4635. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4636. ? []
  4637. : replaceHolders(args, placeholder);
  4638. length -= holders.length;
  4639. if (length < arity) {
  4640. return createRecurry(
  4641. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4642. args, holders, undefined, undefined, arity - length);
  4643. }
  4644. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4645. return apply(fn, this, args);
  4646. }
  4647. return wrapper;
  4648. }
  4649. /**
  4650. * Creates a `_.find` or `_.findLast` function.
  4651. *
  4652. * @private
  4653. * @param {Function} findIndexFunc The function to find the collection index.
  4654. * @returns {Function} Returns the new find function.
  4655. */
  4656. function createFind(findIndexFunc) {
  4657. return function(collection, predicate, fromIndex) {
  4658. var iterable = Object(collection);
  4659. if (!isArrayLike(collection)) {
  4660. var iteratee = getIteratee(predicate, 3);
  4661. collection = keys(collection);
  4662. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4663. }
  4664. var index = findIndexFunc(collection, predicate, fromIndex);
  4665. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4666. };
  4667. }
  4668. /**
  4669. * Creates a `_.flow` or `_.flowRight` function.
  4670. *
  4671. * @private
  4672. * @param {boolean} [fromRight] Specify iterating from right to left.
  4673. * @returns {Function} Returns the new flow function.
  4674. */
  4675. function createFlow(fromRight) {
  4676. return flatRest(function(funcs) {
  4677. var length = funcs.length,
  4678. index = length,
  4679. prereq = LodashWrapper.prototype.thru;
  4680. if (fromRight) {
  4681. funcs.reverse();
  4682. }
  4683. while (index--) {
  4684. var func = funcs[index];
  4685. if (typeof func != 'function') {
  4686. throw new TypeError(FUNC_ERROR_TEXT);
  4687. }
  4688. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4689. var wrapper = new LodashWrapper([], true);
  4690. }
  4691. }
  4692. index = wrapper ? index : length;
  4693. while (++index < length) {
  4694. func = funcs[index];
  4695. var funcName = getFuncName(func),
  4696. data = funcName == 'wrapper' ? getData(func) : undefined;
  4697. if (data && isLaziable(data[0]) &&
  4698. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4699. !data[4].length && data[9] == 1
  4700. ) {
  4701. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4702. } else {
  4703. wrapper = (func.length == 1 && isLaziable(func))
  4704. ? wrapper[funcName]()
  4705. : wrapper.thru(func);
  4706. }
  4707. }
  4708. return function() {
  4709. var args = arguments,
  4710. value = args[0];
  4711. if (wrapper && args.length == 1 && isArray(value)) {
  4712. return wrapper.plant(value).value();
  4713. }
  4714. var index = 0,
  4715. result = length ? funcs[index].apply(this, args) : value;
  4716. while (++index < length) {
  4717. result = funcs[index].call(this, result);
  4718. }
  4719. return result;
  4720. };
  4721. });
  4722. }
  4723. /**
  4724. * Creates a function that wraps `func` to invoke it with optional `this`
  4725. * binding of `thisArg`, partial application, and currying.
  4726. *
  4727. * @private
  4728. * @param {Function|string} func The function or method name to wrap.
  4729. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4730. * @param {*} [thisArg] The `this` binding of `func`.
  4731. * @param {Array} [partials] The arguments to prepend to those provided to
  4732. * the new function.
  4733. * @param {Array} [holders] The `partials` placeholder indexes.
  4734. * @param {Array} [partialsRight] The arguments to append to those provided
  4735. * to the new function.
  4736. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4737. * @param {Array} [argPos] The argument positions of the new function.
  4738. * @param {number} [ary] The arity cap of `func`.
  4739. * @param {number} [arity] The arity of `func`.
  4740. * @returns {Function} Returns the new wrapped function.
  4741. */
  4742. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4743. var isAry = bitmask & WRAP_ARY_FLAG,
  4744. isBind = bitmask & WRAP_BIND_FLAG,
  4745. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4746. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4747. isFlip = bitmask & WRAP_FLIP_FLAG,
  4748. Ctor = isBindKey ? undefined : createCtor(func);
  4749. function wrapper() {
  4750. var length = arguments.length,
  4751. args = Array(length),
  4752. index = length;
  4753. while (index--) {
  4754. args[index] = arguments[index];
  4755. }
  4756. if (isCurried) {
  4757. var placeholder = getHolder(wrapper),
  4758. holdersCount = countHolders(args, placeholder);
  4759. }
  4760. if (partials) {
  4761. args = composeArgs(args, partials, holders, isCurried);
  4762. }
  4763. if (partialsRight) {
  4764. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4765. }
  4766. length -= holdersCount;
  4767. if (isCurried && length < arity) {
  4768. var newHolders = replaceHolders(args, placeholder);
  4769. return createRecurry(
  4770. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4771. args, newHolders, argPos, ary, arity - length
  4772. );
  4773. }
  4774. var thisBinding = isBind ? thisArg : this,
  4775. fn = isBindKey ? thisBinding[func] : func;
  4776. length = args.length;
  4777. if (argPos) {
  4778. args = reorder(args, argPos);
  4779. } else if (isFlip && length > 1) {
  4780. args.reverse();
  4781. }
  4782. if (isAry && ary < length) {
  4783. args.length = ary;
  4784. }
  4785. if (this && this !== root && this instanceof wrapper) {
  4786. fn = Ctor || createCtor(fn);
  4787. }
  4788. return fn.apply(thisBinding, args);
  4789. }
  4790. return wrapper;
  4791. }
  4792. /**
  4793. * Creates a function like `_.invertBy`.
  4794. *
  4795. * @private
  4796. * @param {Function} setter The function to set accumulator values.
  4797. * @param {Function} toIteratee The function to resolve iteratees.
  4798. * @returns {Function} Returns the new inverter function.
  4799. */
  4800. function createInverter(setter, toIteratee) {
  4801. return function(object, iteratee) {
  4802. return baseInverter(object, setter, toIteratee(iteratee), {});
  4803. };
  4804. }
  4805. /**
  4806. * Creates a function that performs a mathematical operation on two values.
  4807. *
  4808. * @private
  4809. * @param {Function} operator The function to perform the operation.
  4810. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4811. * @returns {Function} Returns the new mathematical operation function.
  4812. */
  4813. function createMathOperation(operator, defaultValue) {
  4814. return function(value, other) {
  4815. var result;
  4816. if (value === undefined && other === undefined) {
  4817. return defaultValue;
  4818. }
  4819. if (value !== undefined) {
  4820. result = value;
  4821. }
  4822. if (other !== undefined) {
  4823. if (result === undefined) {
  4824. return other;
  4825. }
  4826. if (typeof value == 'string' || typeof other == 'string') {
  4827. value = baseToString(value);
  4828. other = baseToString(other);
  4829. } else {
  4830. value = baseToNumber(value);
  4831. other = baseToNumber(other);
  4832. }
  4833. result = operator(value, other);
  4834. }
  4835. return result;
  4836. };
  4837. }
  4838. /**
  4839. * Creates a function like `_.over`.
  4840. *
  4841. * @private
  4842. * @param {Function} arrayFunc The function to iterate over iteratees.
  4843. * @returns {Function} Returns the new over function.
  4844. */
  4845. function createOver(arrayFunc) {
  4846. return flatRest(function(iteratees) {
  4847. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4848. return baseRest(function(args) {
  4849. var thisArg = this;
  4850. return arrayFunc(iteratees, function(iteratee) {
  4851. return apply(iteratee, thisArg, args);
  4852. });
  4853. });
  4854. });
  4855. }
  4856. /**
  4857. * Creates the padding for `string` based on `length`. The `chars` string
  4858. * is truncated if the number of characters exceeds `length`.
  4859. *
  4860. * @private
  4861. * @param {number} length The padding length.
  4862. * @param {string} [chars=' '] The string used as padding.
  4863. * @returns {string} Returns the padding for `string`.
  4864. */
  4865. function createPadding(length, chars) {
  4866. chars = chars === undefined ? ' ' : baseToString(chars);
  4867. var charsLength = chars.length;
  4868. if (charsLength < 2) {
  4869. return charsLength ? baseRepeat(chars, length) : chars;
  4870. }
  4871. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4872. return hasUnicode(chars)
  4873. ? castSlice(stringToArray(result), 0, length).join('')
  4874. : result.slice(0, length);
  4875. }
  4876. /**
  4877. * Creates a function that wraps `func` to invoke it with the `this` binding
  4878. * of `thisArg` and `partials` prepended to the arguments it receives.
  4879. *
  4880. * @private
  4881. * @param {Function} func The function to wrap.
  4882. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4883. * @param {*} thisArg The `this` binding of `func`.
  4884. * @param {Array} partials The arguments to prepend to those provided to
  4885. * the new function.
  4886. * @returns {Function} Returns the new wrapped function.
  4887. */
  4888. function createPartial(func, bitmask, thisArg, partials) {
  4889. var isBind = bitmask & WRAP_BIND_FLAG,
  4890. Ctor = createCtor(func);
  4891. function wrapper() {
  4892. var argsIndex = -1,
  4893. argsLength = arguments.length,
  4894. leftIndex = -1,
  4895. leftLength = partials.length,
  4896. args = Array(leftLength + argsLength),
  4897. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4898. while (++leftIndex < leftLength) {
  4899. args[leftIndex] = partials[leftIndex];
  4900. }
  4901. while (argsLength--) {
  4902. args[leftIndex++] = arguments[++argsIndex];
  4903. }
  4904. return apply(fn, isBind ? thisArg : this, args);
  4905. }
  4906. return wrapper;
  4907. }
  4908. /**
  4909. * Creates a `_.range` or `_.rangeRight` function.
  4910. *
  4911. * @private
  4912. * @param {boolean} [fromRight] Specify iterating from right to left.
  4913. * @returns {Function} Returns the new range function.
  4914. */
  4915. function createRange(fromRight) {
  4916. return function(start, end, step) {
  4917. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4918. end = step = undefined;
  4919. }
  4920. // Ensure the sign of `-0` is preserved.
  4921. start = toFinite(start);
  4922. if (end === undefined) {
  4923. end = start;
  4924. start = 0;
  4925. } else {
  4926. end = toFinite(end);
  4927. }
  4928. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4929. return baseRange(start, end, step, fromRight);
  4930. };
  4931. }
  4932. /**
  4933. * Creates a function that performs a relational operation on two values.
  4934. *
  4935. * @private
  4936. * @param {Function} operator The function to perform the operation.
  4937. * @returns {Function} Returns the new relational operation function.
  4938. */
  4939. function createRelationalOperation(operator) {
  4940. return function(value, other) {
  4941. if (!(typeof value == 'string' && typeof other == 'string')) {
  4942. value = toNumber(value);
  4943. other = toNumber(other);
  4944. }
  4945. return operator(value, other);
  4946. };
  4947. }
  4948. /**
  4949. * Creates a function that wraps `func` to continue currying.
  4950. *
  4951. * @private
  4952. * @param {Function} func The function to wrap.
  4953. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4954. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4955. * @param {*} placeholder The placeholder value.
  4956. * @param {*} [thisArg] The `this` binding of `func`.
  4957. * @param {Array} [partials] The arguments to prepend to those provided to
  4958. * the new function.
  4959. * @param {Array} [holders] The `partials` placeholder indexes.
  4960. * @param {Array} [argPos] The argument positions of the new function.
  4961. * @param {number} [ary] The arity cap of `func`.
  4962. * @param {number} [arity] The arity of `func`.
  4963. * @returns {Function} Returns the new wrapped function.
  4964. */
  4965. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4966. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4967. newHolders = isCurry ? holders : undefined,
  4968. newHoldersRight = isCurry ? undefined : holders,
  4969. newPartials = isCurry ? partials : undefined,
  4970. newPartialsRight = isCurry ? undefined : partials;
  4971. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4972. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4973. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4974. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4975. }
  4976. var newData = [
  4977. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4978. newHoldersRight, argPos, ary, arity
  4979. ];
  4980. var result = wrapFunc.apply(undefined, newData);
  4981. if (isLaziable(func)) {
  4982. setData(result, newData);
  4983. }
  4984. result.placeholder = placeholder;
  4985. return setWrapToString(result, func, bitmask);
  4986. }
  4987. /**
  4988. * Creates a function like `_.round`.
  4989. *
  4990. * @private
  4991. * @param {string} methodName The name of the `Math` method to use when rounding.
  4992. * @returns {Function} Returns the new round function.
  4993. */
  4994. function createRound(methodName) {
  4995. var func = Math[methodName];
  4996. return function(number, precision) {
  4997. number = toNumber(number);
  4998. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4999. if (precision && nativeIsFinite(number)) {
  5000. // Shift with exponential notation to avoid floating-point issues.
  5001. // See [MDN](https://mdn.io/round#Examples) for more details.
  5002. var pair = (toString(number) + 'e').split('e'),
  5003. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5004. pair = (toString(value) + 'e').split('e');
  5005. return +(pair[0] + 'e' + (+pair[1] - precision));
  5006. }
  5007. return func(number);
  5008. };
  5009. }
  5010. /**
  5011. * Creates a set object of `values`.
  5012. *
  5013. * @private
  5014. * @param {Array} values The values to add to the set.
  5015. * @returns {Object} Returns the new set.
  5016. */
  5017. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5018. return new Set(values);
  5019. };
  5020. /**
  5021. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5022. *
  5023. * @private
  5024. * @param {Function} keysFunc The function to get the keys of a given object.
  5025. * @returns {Function} Returns the new pairs function.
  5026. */
  5027. function createToPairs(keysFunc) {
  5028. return function(object) {
  5029. var tag = getTag(object);
  5030. if (tag == mapTag) {
  5031. return mapToArray(object);
  5032. }
  5033. if (tag == setTag) {
  5034. return setToPairs(object);
  5035. }
  5036. return baseToPairs(object, keysFunc(object));
  5037. };
  5038. }
  5039. /**
  5040. * Creates a function that either curries or invokes `func` with optional
  5041. * `this` binding and partially applied arguments.
  5042. *
  5043. * @private
  5044. * @param {Function|string} func The function or method name to wrap.
  5045. * @param {number} bitmask The bitmask flags.
  5046. * 1 - `_.bind`
  5047. * 2 - `_.bindKey`
  5048. * 4 - `_.curry` or `_.curryRight` of a bound function
  5049. * 8 - `_.curry`
  5050. * 16 - `_.curryRight`
  5051. * 32 - `_.partial`
  5052. * 64 - `_.partialRight`
  5053. * 128 - `_.rearg`
  5054. * 256 - `_.ary`
  5055. * 512 - `_.flip`
  5056. * @param {*} [thisArg] The `this` binding of `func`.
  5057. * @param {Array} [partials] The arguments to be partially applied.
  5058. * @param {Array} [holders] The `partials` placeholder indexes.
  5059. * @param {Array} [argPos] The argument positions of the new function.
  5060. * @param {number} [ary] The arity cap of `func`.
  5061. * @param {number} [arity] The arity of `func`.
  5062. * @returns {Function} Returns the new wrapped function.
  5063. */
  5064. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5065. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5066. if (!isBindKey && typeof func != 'function') {
  5067. throw new TypeError(FUNC_ERROR_TEXT);
  5068. }
  5069. var length = partials ? partials.length : 0;
  5070. if (!length) {
  5071. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5072. partials = holders = undefined;
  5073. }
  5074. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5075. arity = arity === undefined ? arity : toInteger(arity);
  5076. length -= holders ? holders.length : 0;
  5077. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5078. var partialsRight = partials,
  5079. holdersRight = holders;
  5080. partials = holders = undefined;
  5081. }
  5082. var data = isBindKey ? undefined : getData(func);
  5083. var newData = [
  5084. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5085. argPos, ary, arity
  5086. ];
  5087. if (data) {
  5088. mergeData(newData, data);
  5089. }
  5090. func = newData[0];
  5091. bitmask = newData[1];
  5092. thisArg = newData[2];
  5093. partials = newData[3];
  5094. holders = newData[4];
  5095. arity = newData[9] = newData[9] === undefined
  5096. ? (isBindKey ? 0 : func.length)
  5097. : nativeMax(newData[9] - length, 0);
  5098. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5099. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5100. }
  5101. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5102. var result = createBind(func, bitmask, thisArg);
  5103. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5104. result = createCurry(func, bitmask, arity);
  5105. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5106. result = createPartial(func, bitmask, thisArg, partials);
  5107. } else {
  5108. result = createHybrid.apply(undefined, newData);
  5109. }
  5110. var setter = data ? baseSetData : setData;
  5111. return setWrapToString(setter(result, newData), func, bitmask);
  5112. }
  5113. /**
  5114. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5115. * of source objects to the destination object for all destination properties
  5116. * that resolve to `undefined`.
  5117. *
  5118. * @private
  5119. * @param {*} objValue The destination value.
  5120. * @param {*} srcValue The source value.
  5121. * @param {string} key The key of the property to assign.
  5122. * @param {Object} object The parent object of `objValue`.
  5123. * @returns {*} Returns the value to assign.
  5124. */
  5125. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5126. if (objValue === undefined ||
  5127. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5128. return srcValue;
  5129. }
  5130. return objValue;
  5131. }
  5132. /**
  5133. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5134. * objects into destination objects that are passed thru.
  5135. *
  5136. * @private
  5137. * @param {*} objValue The destination value.
  5138. * @param {*} srcValue The source value.
  5139. * @param {string} key The key of the property to merge.
  5140. * @param {Object} object The parent object of `objValue`.
  5141. * @param {Object} source The parent object of `srcValue`.
  5142. * @param {Object} [stack] Tracks traversed source values and their merged
  5143. * counterparts.
  5144. * @returns {*} Returns the value to assign.
  5145. */
  5146. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5147. if (isObject(objValue) && isObject(srcValue)) {
  5148. // Recursively merge objects and arrays (susceptible to call stack limits).
  5149. stack.set(srcValue, objValue);
  5150. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5151. stack['delete'](srcValue);
  5152. }
  5153. return objValue;
  5154. }
  5155. /**
  5156. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5157. * objects.
  5158. *
  5159. * @private
  5160. * @param {*} value The value to inspect.
  5161. * @param {string} key The key of the property to inspect.
  5162. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5163. */
  5164. function customOmitClone(value) {
  5165. return isPlainObject(value) ? undefined : value;
  5166. }
  5167. /**
  5168. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5169. * partial deep comparisons.
  5170. *
  5171. * @private
  5172. * @param {Array} array The array to compare.
  5173. * @param {Array} other The other array to compare.
  5174. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5175. * @param {Function} customizer The function to customize comparisons.
  5176. * @param {Function} equalFunc The function to determine equivalents of values.
  5177. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5178. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5179. */
  5180. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5181. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5182. arrLength = array.length,
  5183. othLength = other.length;
  5184. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5185. return false;
  5186. }
  5187. // Check that cyclic values are equal.
  5188. var arrStacked = stack.get(array);
  5189. var othStacked = stack.get(other);
  5190. if (arrStacked && othStacked) {
  5191. return arrStacked == other && othStacked == array;
  5192. }
  5193. var index = -1,
  5194. result = true,
  5195. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5196. stack.set(array, other);
  5197. stack.set(other, array);
  5198. // Ignore non-index properties.
  5199. while (++index < arrLength) {
  5200. var arrValue = array[index],
  5201. othValue = other[index];
  5202. if (customizer) {
  5203. var compared = isPartial
  5204. ? customizer(othValue, arrValue, index, other, array, stack)
  5205. : customizer(arrValue, othValue, index, array, other, stack);
  5206. }
  5207. if (compared !== undefined) {
  5208. if (compared) {
  5209. continue;
  5210. }
  5211. result = false;
  5212. break;
  5213. }
  5214. // Recursively compare arrays (susceptible to call stack limits).
  5215. if (seen) {
  5216. if (!arraySome(other, function(othValue, othIndex) {
  5217. if (!cacheHas(seen, othIndex) &&
  5218. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5219. return seen.push(othIndex);
  5220. }
  5221. })) {
  5222. result = false;
  5223. break;
  5224. }
  5225. } else if (!(
  5226. arrValue === othValue ||
  5227. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5228. )) {
  5229. result = false;
  5230. break;
  5231. }
  5232. }
  5233. stack['delete'](array);
  5234. stack['delete'](other);
  5235. return result;
  5236. }
  5237. /**
  5238. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5239. * the same `toStringTag`.
  5240. *
  5241. * **Note:** This function only supports comparing values with tags of
  5242. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5243. *
  5244. * @private
  5245. * @param {Object} object The object to compare.
  5246. * @param {Object} other The other object to compare.
  5247. * @param {string} tag The `toStringTag` of the objects to compare.
  5248. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5249. * @param {Function} customizer The function to customize comparisons.
  5250. * @param {Function} equalFunc The function to determine equivalents of values.
  5251. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5252. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5253. */
  5254. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5255. switch (tag) {
  5256. case dataViewTag:
  5257. if ((object.byteLength != other.byteLength) ||
  5258. (object.byteOffset != other.byteOffset)) {
  5259. return false;
  5260. }
  5261. object = object.buffer;
  5262. other = other.buffer;
  5263. case arrayBufferTag:
  5264. if ((object.byteLength != other.byteLength) ||
  5265. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5266. return false;
  5267. }
  5268. return true;
  5269. case boolTag:
  5270. case dateTag:
  5271. case numberTag:
  5272. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5273. // Invalid dates are coerced to `NaN`.
  5274. return eq(+object, +other);
  5275. case errorTag:
  5276. return object.name == other.name && object.message == other.message;
  5277. case regexpTag:
  5278. case stringTag:
  5279. // Coerce regexes to strings and treat strings, primitives and objects,
  5280. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5281. // for more details.
  5282. return object == (other + '');
  5283. case mapTag:
  5284. var convert = mapToArray;
  5285. case setTag:
  5286. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5287. convert || (convert = setToArray);
  5288. if (object.size != other.size && !isPartial) {
  5289. return false;
  5290. }
  5291. // Assume cyclic values are equal.
  5292. var stacked = stack.get(object);
  5293. if (stacked) {
  5294. return stacked == other;
  5295. }
  5296. bitmask |= COMPARE_UNORDERED_FLAG;
  5297. // Recursively compare objects (susceptible to call stack limits).
  5298. stack.set(object, other);
  5299. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5300. stack['delete'](object);
  5301. return result;
  5302. case symbolTag:
  5303. if (symbolValueOf) {
  5304. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5305. }
  5306. }
  5307. return false;
  5308. }
  5309. /**
  5310. * A specialized version of `baseIsEqualDeep` for objects with support for
  5311. * partial deep comparisons.
  5312. *
  5313. * @private
  5314. * @param {Object} object The object to compare.
  5315. * @param {Object} other The other object to compare.
  5316. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5317. * @param {Function} customizer The function to customize comparisons.
  5318. * @param {Function} equalFunc The function to determine equivalents of values.
  5319. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5320. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5321. */
  5322. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5323. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5324. objProps = getAllKeys(object),
  5325. objLength = objProps.length,
  5326. othProps = getAllKeys(other),
  5327. othLength = othProps.length;
  5328. if (objLength != othLength && !isPartial) {
  5329. return false;
  5330. }
  5331. var index = objLength;
  5332. while (index--) {
  5333. var key = objProps[index];
  5334. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5335. return false;
  5336. }
  5337. }
  5338. // Check that cyclic values are equal.
  5339. var objStacked = stack.get(object);
  5340. var othStacked = stack.get(other);
  5341. if (objStacked && othStacked) {
  5342. return objStacked == other && othStacked == object;
  5343. }
  5344. var result = true;
  5345. stack.set(object, other);
  5346. stack.set(other, object);
  5347. var skipCtor = isPartial;
  5348. while (++index < objLength) {
  5349. key = objProps[index];
  5350. var objValue = object[key],
  5351. othValue = other[key];
  5352. if (customizer) {
  5353. var compared = isPartial
  5354. ? customizer(othValue, objValue, key, other, object, stack)
  5355. : customizer(objValue, othValue, key, object, other, stack);
  5356. }
  5357. // Recursively compare objects (susceptible to call stack limits).
  5358. if (!(compared === undefined
  5359. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5360. : compared
  5361. )) {
  5362. result = false;
  5363. break;
  5364. }
  5365. skipCtor || (skipCtor = key == 'constructor');
  5366. }
  5367. if (result && !skipCtor) {
  5368. var objCtor = object.constructor,
  5369. othCtor = other.constructor;
  5370. // Non `Object` object instances with different constructors are not equal.
  5371. if (objCtor != othCtor &&
  5372. ('constructor' in object && 'constructor' in other) &&
  5373. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5374. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5375. result = false;
  5376. }
  5377. }
  5378. stack['delete'](object);
  5379. stack['delete'](other);
  5380. return result;
  5381. }
  5382. /**
  5383. * A specialized version of `baseRest` which flattens the rest array.
  5384. *
  5385. * @private
  5386. * @param {Function} func The function to apply a rest parameter to.
  5387. * @returns {Function} Returns the new function.
  5388. */
  5389. function flatRest(func) {
  5390. return setToString(overRest(func, undefined, flatten), func + '');
  5391. }
  5392. /**
  5393. * Creates an array of own enumerable property names and symbols of `object`.
  5394. *
  5395. * @private
  5396. * @param {Object} object The object to query.
  5397. * @returns {Array} Returns the array of property names and symbols.
  5398. */
  5399. function getAllKeys(object) {
  5400. return baseGetAllKeys(object, keys, getSymbols);
  5401. }
  5402. /**
  5403. * Creates an array of own and inherited enumerable property names and
  5404. * symbols of `object`.
  5405. *
  5406. * @private
  5407. * @param {Object} object The object to query.
  5408. * @returns {Array} Returns the array of property names and symbols.
  5409. */
  5410. function getAllKeysIn(object) {
  5411. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5412. }
  5413. /**
  5414. * Gets metadata for `func`.
  5415. *
  5416. * @private
  5417. * @param {Function} func The function to query.
  5418. * @returns {*} Returns the metadata for `func`.
  5419. */
  5420. var getData = !metaMap ? noop : function(func) {
  5421. return metaMap.get(func);
  5422. };
  5423. /**
  5424. * Gets the name of `func`.
  5425. *
  5426. * @private
  5427. * @param {Function} func The function to query.
  5428. * @returns {string} Returns the function name.
  5429. */
  5430. function getFuncName(func) {
  5431. var result = (func.name + ''),
  5432. array = realNames[result],
  5433. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5434. while (length--) {
  5435. var data = array[length],
  5436. otherFunc = data.func;
  5437. if (otherFunc == null || otherFunc == func) {
  5438. return data.name;
  5439. }
  5440. }
  5441. return result;
  5442. }
  5443. /**
  5444. * Gets the argument placeholder value for `func`.
  5445. *
  5446. * @private
  5447. * @param {Function} func The function to inspect.
  5448. * @returns {*} Returns the placeholder value.
  5449. */
  5450. function getHolder(func) {
  5451. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5452. return object.placeholder;
  5453. }
  5454. /**
  5455. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5456. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5457. * If arguments are provided, the chosen function is invoked with them and
  5458. * its result is returned.
  5459. *
  5460. * @private
  5461. * @param {*} [value] The value to convert to an iteratee.
  5462. * @param {number} [arity] The arity of the created iteratee.
  5463. * @returns {Function} Returns the chosen function or its result.
  5464. */
  5465. function getIteratee() {
  5466. var result = lodash.iteratee || iteratee;
  5467. result = result === iteratee ? baseIteratee : result;
  5468. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5469. }
  5470. /**
  5471. * Gets the data for `map`.
  5472. *
  5473. * @private
  5474. * @param {Object} map The map to query.
  5475. * @param {string} key The reference key.
  5476. * @returns {*} Returns the map data.
  5477. */
  5478. function getMapData(map, key) {
  5479. var data = map.__data__;
  5480. return isKeyable(key)
  5481. ? data[typeof key == 'string' ? 'string' : 'hash']
  5482. : data.map;
  5483. }
  5484. /**
  5485. * Gets the property names, values, and compare flags of `object`.
  5486. *
  5487. * @private
  5488. * @param {Object} object The object to query.
  5489. * @returns {Array} Returns the match data of `object`.
  5490. */
  5491. function getMatchData(object) {
  5492. var result = keys(object),
  5493. length = result.length;
  5494. while (length--) {
  5495. var key = result[length],
  5496. value = object[key];
  5497. result[length] = [key, value, isStrictComparable(value)];
  5498. }
  5499. return result;
  5500. }
  5501. /**
  5502. * Gets the native function at `key` of `object`.
  5503. *
  5504. * @private
  5505. * @param {Object} object The object to query.
  5506. * @param {string} key The key of the method to get.
  5507. * @returns {*} Returns the function if it's native, else `undefined`.
  5508. */
  5509. function getNative(object, key) {
  5510. var value = getValue(object, key);
  5511. return baseIsNative(value) ? value : undefined;
  5512. }
  5513. /**
  5514. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5515. *
  5516. * @private
  5517. * @param {*} value The value to query.
  5518. * @returns {string} Returns the raw `toStringTag`.
  5519. */
  5520. function getRawTag(value) {
  5521. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5522. tag = value[symToStringTag];
  5523. try {
  5524. value[symToStringTag] = undefined;
  5525. var unmasked = true;
  5526. } catch (e) {}
  5527. var result = nativeObjectToString.call(value);
  5528. if (unmasked) {
  5529. if (isOwn) {
  5530. value[symToStringTag] = tag;
  5531. } else {
  5532. delete value[symToStringTag];
  5533. }
  5534. }
  5535. return result;
  5536. }
  5537. /**
  5538. * Creates an array of the own enumerable symbols of `object`.
  5539. *
  5540. * @private
  5541. * @param {Object} object The object to query.
  5542. * @returns {Array} Returns the array of symbols.
  5543. */
  5544. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5545. if (object == null) {
  5546. return [];
  5547. }
  5548. object = Object(object);
  5549. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5550. return propertyIsEnumerable.call(object, symbol);
  5551. });
  5552. };
  5553. /**
  5554. * Creates an array of the own and inherited enumerable symbols of `object`.
  5555. *
  5556. * @private
  5557. * @param {Object} object The object to query.
  5558. * @returns {Array} Returns the array of symbols.
  5559. */
  5560. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5561. var result = [];
  5562. while (object) {
  5563. arrayPush(result, getSymbols(object));
  5564. object = getPrototype(object);
  5565. }
  5566. return result;
  5567. };
  5568. /**
  5569. * Gets the `toStringTag` of `value`.
  5570. *
  5571. * @private
  5572. * @param {*} value The value to query.
  5573. * @returns {string} Returns the `toStringTag`.
  5574. */
  5575. var getTag = baseGetTag;
  5576. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5577. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5578. (Map && getTag(new Map) != mapTag) ||
  5579. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5580. (Set && getTag(new Set) != setTag) ||
  5581. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5582. getTag = function(value) {
  5583. var result = baseGetTag(value),
  5584. Ctor = result == objectTag ? value.constructor : undefined,
  5585. ctorString = Ctor ? toSource(Ctor) : '';
  5586. if (ctorString) {
  5587. switch (ctorString) {
  5588. case dataViewCtorString: return dataViewTag;
  5589. case mapCtorString: return mapTag;
  5590. case promiseCtorString: return promiseTag;
  5591. case setCtorString: return setTag;
  5592. case weakMapCtorString: return weakMapTag;
  5593. }
  5594. }
  5595. return result;
  5596. };
  5597. }
  5598. /**
  5599. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5600. *
  5601. * @private
  5602. * @param {number} start The start of the view.
  5603. * @param {number} end The end of the view.
  5604. * @param {Array} transforms The transformations to apply to the view.
  5605. * @returns {Object} Returns an object containing the `start` and `end`
  5606. * positions of the view.
  5607. */
  5608. function getView(start, end, transforms) {
  5609. var index = -1,
  5610. length = transforms.length;
  5611. while (++index < length) {
  5612. var data = transforms[index],
  5613. size = data.size;
  5614. switch (data.type) {
  5615. case 'drop': start += size; break;
  5616. case 'dropRight': end -= size; break;
  5617. case 'take': end = nativeMin(end, start + size); break;
  5618. case 'takeRight': start = nativeMax(start, end - size); break;
  5619. }
  5620. }
  5621. return { 'start': start, 'end': end };
  5622. }
  5623. /**
  5624. * Extracts wrapper details from the `source` body comment.
  5625. *
  5626. * @private
  5627. * @param {string} source The source to inspect.
  5628. * @returns {Array} Returns the wrapper details.
  5629. */
  5630. function getWrapDetails(source) {
  5631. var match = source.match(reWrapDetails);
  5632. return match ? match[1].split(reSplitDetails) : [];
  5633. }
  5634. /**
  5635. * Checks if `path` exists on `object`.
  5636. *
  5637. * @private
  5638. * @param {Object} object The object to query.
  5639. * @param {Array|string} path The path to check.
  5640. * @param {Function} hasFunc The function to check properties.
  5641. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5642. */
  5643. function hasPath(object, path, hasFunc) {
  5644. path = castPath(path, object);
  5645. var index = -1,
  5646. length = path.length,
  5647. result = false;
  5648. while (++index < length) {
  5649. var key = toKey(path[index]);
  5650. if (!(result = object != null && hasFunc(object, key))) {
  5651. break;
  5652. }
  5653. object = object[key];
  5654. }
  5655. if (result || ++index != length) {
  5656. return result;
  5657. }
  5658. length = object == null ? 0 : object.length;
  5659. return !!length && isLength(length) && isIndex(key, length) &&
  5660. (isArray(object) || isArguments(object));
  5661. }
  5662. /**
  5663. * Initializes an array clone.
  5664. *
  5665. * @private
  5666. * @param {Array} array The array to clone.
  5667. * @returns {Array} Returns the initialized clone.
  5668. */
  5669. function initCloneArray(array) {
  5670. var length = array.length,
  5671. result = new array.constructor(length);
  5672. // Add properties assigned by `RegExp#exec`.
  5673. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5674. result.index = array.index;
  5675. result.input = array.input;
  5676. }
  5677. return result;
  5678. }
  5679. /**
  5680. * Initializes an object clone.
  5681. *
  5682. * @private
  5683. * @param {Object} object The object to clone.
  5684. * @returns {Object} Returns the initialized clone.
  5685. */
  5686. function initCloneObject(object) {
  5687. return (typeof object.constructor == 'function' && !isPrototype(object))
  5688. ? baseCreate(getPrototype(object))
  5689. : {};
  5690. }
  5691. /**
  5692. * Initializes an object clone based on its `toStringTag`.
  5693. *
  5694. * **Note:** This function only supports cloning values with tags of
  5695. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5696. *
  5697. * @private
  5698. * @param {Object} object The object to clone.
  5699. * @param {string} tag The `toStringTag` of the object to clone.
  5700. * @param {boolean} [isDeep] Specify a deep clone.
  5701. * @returns {Object} Returns the initialized clone.
  5702. */
  5703. function initCloneByTag(object, tag, isDeep) {
  5704. var Ctor = object.constructor;
  5705. switch (tag) {
  5706. case arrayBufferTag:
  5707. return cloneArrayBuffer(object);
  5708. case boolTag:
  5709. case dateTag:
  5710. return new Ctor(+object);
  5711. case dataViewTag:
  5712. return cloneDataView(object, isDeep);
  5713. case float32Tag: case float64Tag:
  5714. case int8Tag: case int16Tag: case int32Tag:
  5715. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5716. return cloneTypedArray(object, isDeep);
  5717. case mapTag:
  5718. return new Ctor;
  5719. case numberTag:
  5720. case stringTag:
  5721. return new Ctor(object);
  5722. case regexpTag:
  5723. return cloneRegExp(object);
  5724. case setTag:
  5725. return new Ctor;
  5726. case symbolTag:
  5727. return cloneSymbol(object);
  5728. }
  5729. }
  5730. /**
  5731. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5732. *
  5733. * @private
  5734. * @param {string} source The source to modify.
  5735. * @returns {Array} details The details to insert.
  5736. * @returns {string} Returns the modified source.
  5737. */
  5738. function insertWrapDetails(source, details) {
  5739. var length = details.length;
  5740. if (!length) {
  5741. return source;
  5742. }
  5743. var lastIndex = length - 1;
  5744. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5745. details = details.join(length > 2 ? ', ' : ' ');
  5746. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5747. }
  5748. /**
  5749. * Checks if `value` is a flattenable `arguments` object or array.
  5750. *
  5751. * @private
  5752. * @param {*} value The value to check.
  5753. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5754. */
  5755. function isFlattenable(value) {
  5756. return isArray(value) || isArguments(value) ||
  5757. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5758. }
  5759. /**
  5760. * Checks if `value` is a valid array-like index.
  5761. *
  5762. * @private
  5763. * @param {*} value The value to check.
  5764. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5765. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5766. */
  5767. function isIndex(value, length) {
  5768. var type = typeof value;
  5769. length = length == null ? MAX_SAFE_INTEGER : length;
  5770. return !!length &&
  5771. (type == 'number' ||
  5772. (type != 'symbol' && reIsUint.test(value))) &&
  5773. (value > -1 && value % 1 == 0 && value < length);
  5774. }
  5775. /**
  5776. * Checks if the given arguments are from an iteratee call.
  5777. *
  5778. * @private
  5779. * @param {*} value The potential iteratee value argument.
  5780. * @param {*} index The potential iteratee index or key argument.
  5781. * @param {*} object The potential iteratee object argument.
  5782. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5783. * else `false`.
  5784. */
  5785. function isIterateeCall(value, index, object) {
  5786. if (!isObject(object)) {
  5787. return false;
  5788. }
  5789. var type = typeof index;
  5790. if (type == 'number'
  5791. ? (isArrayLike(object) && isIndex(index, object.length))
  5792. : (type == 'string' && index in object)
  5793. ) {
  5794. return eq(object[index], value);
  5795. }
  5796. return false;
  5797. }
  5798. /**
  5799. * Checks if `value` is a property name and not a property path.
  5800. *
  5801. * @private
  5802. * @param {*} value The value to check.
  5803. * @param {Object} [object] The object to query keys on.
  5804. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5805. */
  5806. function isKey(value, object) {
  5807. if (isArray(value)) {
  5808. return false;
  5809. }
  5810. var type = typeof value;
  5811. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5812. value == null || isSymbol(value)) {
  5813. return true;
  5814. }
  5815. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5816. (object != null && value in Object(object));
  5817. }
  5818. /**
  5819. * Checks if `value` is suitable for use as unique object key.
  5820. *
  5821. * @private
  5822. * @param {*} value The value to check.
  5823. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5824. */
  5825. function isKeyable(value) {
  5826. var type = typeof value;
  5827. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5828. ? (value !== '__proto__')
  5829. : (value === null);
  5830. }
  5831. /**
  5832. * Checks if `func` has a lazy counterpart.
  5833. *
  5834. * @private
  5835. * @param {Function} func The function to check.
  5836. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5837. * else `false`.
  5838. */
  5839. function isLaziable(func) {
  5840. var funcName = getFuncName(func),
  5841. other = lodash[funcName];
  5842. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5843. return false;
  5844. }
  5845. if (func === other) {
  5846. return true;
  5847. }
  5848. var data = getData(other);
  5849. return !!data && func === data[0];
  5850. }
  5851. /**
  5852. * Checks if `func` has its source masked.
  5853. *
  5854. * @private
  5855. * @param {Function} func The function to check.
  5856. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5857. */
  5858. function isMasked(func) {
  5859. return !!maskSrcKey && (maskSrcKey in func);
  5860. }
  5861. /**
  5862. * Checks if `func` is capable of being masked.
  5863. *
  5864. * @private
  5865. * @param {*} value The value to check.
  5866. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5867. */
  5868. var isMaskable = coreJsData ? isFunction : stubFalse;
  5869. /**
  5870. * Checks if `value` is likely a prototype object.
  5871. *
  5872. * @private
  5873. * @param {*} value The value to check.
  5874. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5875. */
  5876. function isPrototype(value) {
  5877. var Ctor = value && value.constructor,
  5878. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5879. return value === proto;
  5880. }
  5881. /**
  5882. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5883. *
  5884. * @private
  5885. * @param {*} value The value to check.
  5886. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5887. * equality comparisons, else `false`.
  5888. */
  5889. function isStrictComparable(value) {
  5890. return value === value && !isObject(value);
  5891. }
  5892. /**
  5893. * A specialized version of `matchesProperty` for source values suitable
  5894. * for strict equality comparisons, i.e. `===`.
  5895. *
  5896. * @private
  5897. * @param {string} key The key of the property to get.
  5898. * @param {*} srcValue The value to match.
  5899. * @returns {Function} Returns the new spec function.
  5900. */
  5901. function matchesStrictComparable(key, srcValue) {
  5902. return function(object) {
  5903. if (object == null) {
  5904. return false;
  5905. }
  5906. return object[key] === srcValue &&
  5907. (srcValue !== undefined || (key in Object(object)));
  5908. };
  5909. }
  5910. /**
  5911. * A specialized version of `_.memoize` which clears the memoized function's
  5912. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5913. *
  5914. * @private
  5915. * @param {Function} func The function to have its output memoized.
  5916. * @returns {Function} Returns the new memoized function.
  5917. */
  5918. function memoizeCapped(func) {
  5919. var result = memoize(func, function(key) {
  5920. if (cache.size === MAX_MEMOIZE_SIZE) {
  5921. cache.clear();
  5922. }
  5923. return key;
  5924. });
  5925. var cache = result.cache;
  5926. return result;
  5927. }
  5928. /**
  5929. * Merges the function metadata of `source` into `data`.
  5930. *
  5931. * Merging metadata reduces the number of wrappers used to invoke a function.
  5932. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5933. * may be applied regardless of execution order. Methods like `_.ary` and
  5934. * `_.rearg` modify function arguments, making the order in which they are
  5935. * executed important, preventing the merging of metadata. However, we make
  5936. * an exception for a safe combined case where curried functions have `_.ary`
  5937. * and or `_.rearg` applied.
  5938. *
  5939. * @private
  5940. * @param {Array} data The destination metadata.
  5941. * @param {Array} source The source metadata.
  5942. * @returns {Array} Returns `data`.
  5943. */
  5944. function mergeData(data, source) {
  5945. var bitmask = data[1],
  5946. srcBitmask = source[1],
  5947. newBitmask = bitmask | srcBitmask,
  5948. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5949. var isCombo =
  5950. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5951. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5952. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5953. // Exit early if metadata can't be merged.
  5954. if (!(isCommon || isCombo)) {
  5955. return data;
  5956. }
  5957. // Use source `thisArg` if available.
  5958. if (srcBitmask & WRAP_BIND_FLAG) {
  5959. data[2] = source[2];
  5960. // Set when currying a bound function.
  5961. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5962. }
  5963. // Compose partial arguments.
  5964. var value = source[3];
  5965. if (value) {
  5966. var partials = data[3];
  5967. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5968. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5969. }
  5970. // Compose partial right arguments.
  5971. value = source[5];
  5972. if (value) {
  5973. partials = data[5];
  5974. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5975. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5976. }
  5977. // Use source `argPos` if available.
  5978. value = source[7];
  5979. if (value) {
  5980. data[7] = value;
  5981. }
  5982. // Use source `ary` if it's smaller.
  5983. if (srcBitmask & WRAP_ARY_FLAG) {
  5984. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5985. }
  5986. // Use source `arity` if one is not provided.
  5987. if (data[9] == null) {
  5988. data[9] = source[9];
  5989. }
  5990. // Use source `func` and merge bitmasks.
  5991. data[0] = source[0];
  5992. data[1] = newBitmask;
  5993. return data;
  5994. }
  5995. /**
  5996. * This function is like
  5997. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5998. * except that it includes inherited enumerable properties.
  5999. *
  6000. * @private
  6001. * @param {Object} object The object to query.
  6002. * @returns {Array} Returns the array of property names.
  6003. */
  6004. function nativeKeysIn(object) {
  6005. var result = [];
  6006. if (object != null) {
  6007. for (var key in Object(object)) {
  6008. result.push(key);
  6009. }
  6010. }
  6011. return result;
  6012. }
  6013. /**
  6014. * Converts `value` to a string using `Object.prototype.toString`.
  6015. *
  6016. * @private
  6017. * @param {*} value The value to convert.
  6018. * @returns {string} Returns the converted string.
  6019. */
  6020. function objectToString(value) {
  6021. return nativeObjectToString.call(value);
  6022. }
  6023. /**
  6024. * A specialized version of `baseRest` which transforms the rest array.
  6025. *
  6026. * @private
  6027. * @param {Function} func The function to apply a rest parameter to.
  6028. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6029. * @param {Function} transform The rest array transform.
  6030. * @returns {Function} Returns the new function.
  6031. */
  6032. function overRest(func, start, transform) {
  6033. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6034. return function() {
  6035. var args = arguments,
  6036. index = -1,
  6037. length = nativeMax(args.length - start, 0),
  6038. array = Array(length);
  6039. while (++index < length) {
  6040. array[index] = args[start + index];
  6041. }
  6042. index = -1;
  6043. var otherArgs = Array(start + 1);
  6044. while (++index < start) {
  6045. otherArgs[index] = args[index];
  6046. }
  6047. otherArgs[start] = transform(array);
  6048. return apply(func, this, otherArgs);
  6049. };
  6050. }
  6051. /**
  6052. * Gets the parent value at `path` of `object`.
  6053. *
  6054. * @private
  6055. * @param {Object} object The object to query.
  6056. * @param {Array} path The path to get the parent value of.
  6057. * @returns {*} Returns the parent value.
  6058. */
  6059. function parent(object, path) {
  6060. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6061. }
  6062. /**
  6063. * Reorder `array` according to the specified indexes where the element at
  6064. * the first index is assigned as the first element, the element at
  6065. * the second index is assigned as the second element, and so on.
  6066. *
  6067. * @private
  6068. * @param {Array} array The array to reorder.
  6069. * @param {Array} indexes The arranged array indexes.
  6070. * @returns {Array} Returns `array`.
  6071. */
  6072. function reorder(array, indexes) {
  6073. var arrLength = array.length,
  6074. length = nativeMin(indexes.length, arrLength),
  6075. oldArray = copyArray(array);
  6076. while (length--) {
  6077. var index = indexes[length];
  6078. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6079. }
  6080. return array;
  6081. }
  6082. /**
  6083. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6084. *
  6085. * @private
  6086. * @param {Object} object The object to query.
  6087. * @param {string} key The key of the property to get.
  6088. * @returns {*} Returns the property value.
  6089. */
  6090. function safeGet(object, key) {
  6091. if (key === 'constructor' && typeof object[key] === 'function') {
  6092. return;
  6093. }
  6094. if (key == '__proto__') {
  6095. return;
  6096. }
  6097. return object[key];
  6098. }
  6099. /**
  6100. * Sets metadata for `func`.
  6101. *
  6102. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6103. * period of time, it will trip its breaker and transition to an identity
  6104. * function to avoid garbage collection pauses in V8. See
  6105. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6106. * for more details.
  6107. *
  6108. * @private
  6109. * @param {Function} func The function to associate metadata with.
  6110. * @param {*} data The metadata.
  6111. * @returns {Function} Returns `func`.
  6112. */
  6113. var setData = shortOut(baseSetData);
  6114. /**
  6115. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6116. *
  6117. * @private
  6118. * @param {Function} func The function to delay.
  6119. * @param {number} wait The number of milliseconds to delay invocation.
  6120. * @returns {number|Object} Returns the timer id or timeout object.
  6121. */
  6122. var setTimeout = ctxSetTimeout || function(func, wait) {
  6123. return root.setTimeout(func, wait);
  6124. };
  6125. /**
  6126. * Sets the `toString` method of `func` to return `string`.
  6127. *
  6128. * @private
  6129. * @param {Function} func The function to modify.
  6130. * @param {Function} string The `toString` result.
  6131. * @returns {Function} Returns `func`.
  6132. */
  6133. var setToString = shortOut(baseSetToString);
  6134. /**
  6135. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6136. * with wrapper details in a comment at the top of the source body.
  6137. *
  6138. * @private
  6139. * @param {Function} wrapper The function to modify.
  6140. * @param {Function} reference The reference function.
  6141. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6142. * @returns {Function} Returns `wrapper`.
  6143. */
  6144. function setWrapToString(wrapper, reference, bitmask) {
  6145. var source = (reference + '');
  6146. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6147. }
  6148. /**
  6149. * Creates a function that'll short out and invoke `identity` instead
  6150. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6151. * milliseconds.
  6152. *
  6153. * @private
  6154. * @param {Function} func The function to restrict.
  6155. * @returns {Function} Returns the new shortable function.
  6156. */
  6157. function shortOut(func) {
  6158. var count = 0,
  6159. lastCalled = 0;
  6160. return function() {
  6161. var stamp = nativeNow(),
  6162. remaining = HOT_SPAN - (stamp - lastCalled);
  6163. lastCalled = stamp;
  6164. if (remaining > 0) {
  6165. if (++count >= HOT_COUNT) {
  6166. return arguments[0];
  6167. }
  6168. } else {
  6169. count = 0;
  6170. }
  6171. return func.apply(undefined, arguments);
  6172. };
  6173. }
  6174. /**
  6175. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6176. *
  6177. * @private
  6178. * @param {Array} array The array to shuffle.
  6179. * @param {number} [size=array.length] The size of `array`.
  6180. * @returns {Array} Returns `array`.
  6181. */
  6182. function shuffleSelf(array, size) {
  6183. var index = -1,
  6184. length = array.length,
  6185. lastIndex = length - 1;
  6186. size = size === undefined ? length : size;
  6187. while (++index < size) {
  6188. var rand = baseRandom(index, lastIndex),
  6189. value = array[rand];
  6190. array[rand] = array[index];
  6191. array[index] = value;
  6192. }
  6193. array.length = size;
  6194. return array;
  6195. }
  6196. /**
  6197. * Converts `string` to a property path array.
  6198. *
  6199. * @private
  6200. * @param {string} string The string to convert.
  6201. * @returns {Array} Returns the property path array.
  6202. */
  6203. var stringToPath = memoizeCapped(function(string) {
  6204. var result = [];
  6205. if (string.charCodeAt(0) === 46 /* . */) {
  6206. result.push('');
  6207. }
  6208. string.replace(rePropName, function(match, number, quote, subString) {
  6209. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6210. });
  6211. return result;
  6212. });
  6213. /**
  6214. * Converts `value` to a string key if it's not a string or symbol.
  6215. *
  6216. * @private
  6217. * @param {*} value The value to inspect.
  6218. * @returns {string|symbol} Returns the key.
  6219. */
  6220. function toKey(value) {
  6221. if (typeof value == 'string' || isSymbol(value)) {
  6222. return value;
  6223. }
  6224. var result = (value + '');
  6225. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6226. }
  6227. /**
  6228. * Converts `func` to its source code.
  6229. *
  6230. * @private
  6231. * @param {Function} func The function to convert.
  6232. * @returns {string} Returns the source code.
  6233. */
  6234. function toSource(func) {
  6235. if (func != null) {
  6236. try {
  6237. return funcToString.call(func);
  6238. } catch (e) {}
  6239. try {
  6240. return (func + '');
  6241. } catch (e) {}
  6242. }
  6243. return '';
  6244. }
  6245. /**
  6246. * Updates wrapper `details` based on `bitmask` flags.
  6247. *
  6248. * @private
  6249. * @returns {Array} details The details to modify.
  6250. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6251. * @returns {Array} Returns `details`.
  6252. */
  6253. function updateWrapDetails(details, bitmask) {
  6254. arrayEach(wrapFlags, function(pair) {
  6255. var value = '_.' + pair[0];
  6256. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6257. details.push(value);
  6258. }
  6259. });
  6260. return details.sort();
  6261. }
  6262. /**
  6263. * Creates a clone of `wrapper`.
  6264. *
  6265. * @private
  6266. * @param {Object} wrapper The wrapper to clone.
  6267. * @returns {Object} Returns the cloned wrapper.
  6268. */
  6269. function wrapperClone(wrapper) {
  6270. if (wrapper instanceof LazyWrapper) {
  6271. return wrapper.clone();
  6272. }
  6273. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6274. result.__actions__ = copyArray(wrapper.__actions__);
  6275. result.__index__ = wrapper.__index__;
  6276. result.__values__ = wrapper.__values__;
  6277. return result;
  6278. }
  6279. /*------------------------------------------------------------------------*/
  6280. /**
  6281. * Creates an array of elements split into groups the length of `size`.
  6282. * If `array` can't be split evenly, the final chunk will be the remaining
  6283. * elements.
  6284. *
  6285. * @static
  6286. * @memberOf _
  6287. * @since 3.0.0
  6288. * @category Array
  6289. * @param {Array} array The array to process.
  6290. * @param {number} [size=1] The length of each chunk
  6291. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6292. * @returns {Array} Returns the new array of chunks.
  6293. * @example
  6294. *
  6295. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6296. * // => [['a', 'b'], ['c', 'd']]
  6297. *
  6298. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6299. * // => [['a', 'b', 'c'], ['d']]
  6300. */
  6301. function chunk(array, size, guard) {
  6302. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6303. size = 1;
  6304. } else {
  6305. size = nativeMax(toInteger(size), 0);
  6306. }
  6307. var length = array == null ? 0 : array.length;
  6308. if (!length || size < 1) {
  6309. return [];
  6310. }
  6311. var index = 0,
  6312. resIndex = 0,
  6313. result = Array(nativeCeil(length / size));
  6314. while (index < length) {
  6315. result[resIndex++] = baseSlice(array, index, (index += size));
  6316. }
  6317. return result;
  6318. }
  6319. /**
  6320. * Creates an array with all falsey values removed. The values `false`, `null`,
  6321. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6322. *
  6323. * @static
  6324. * @memberOf _
  6325. * @since 0.1.0
  6326. * @category Array
  6327. * @param {Array} array The array to compact.
  6328. * @returns {Array} Returns the new array of filtered values.
  6329. * @example
  6330. *
  6331. * _.compact([0, 1, false, 2, '', 3]);
  6332. * // => [1, 2, 3]
  6333. */
  6334. function compact(array) {
  6335. var index = -1,
  6336. length = array == null ? 0 : array.length,
  6337. resIndex = 0,
  6338. result = [];
  6339. while (++index < length) {
  6340. var value = array[index];
  6341. if (value) {
  6342. result[resIndex++] = value;
  6343. }
  6344. }
  6345. return result;
  6346. }
  6347. /**
  6348. * Creates a new array concatenating `array` with any additional arrays
  6349. * and/or values.
  6350. *
  6351. * @static
  6352. * @memberOf _
  6353. * @since 4.0.0
  6354. * @category Array
  6355. * @param {Array} array The array to concatenate.
  6356. * @param {...*} [values] The values to concatenate.
  6357. * @returns {Array} Returns the new concatenated array.
  6358. * @example
  6359. *
  6360. * var array = [1];
  6361. * var other = _.concat(array, 2, [3], [[4]]);
  6362. *
  6363. * console.log(other);
  6364. * // => [1, 2, 3, [4]]
  6365. *
  6366. * console.log(array);
  6367. * // => [1]
  6368. */
  6369. function concat() {
  6370. var length = arguments.length;
  6371. if (!length) {
  6372. return [];
  6373. }
  6374. var args = Array(length - 1),
  6375. array = arguments[0],
  6376. index = length;
  6377. while (index--) {
  6378. args[index - 1] = arguments[index];
  6379. }
  6380. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6381. }
  6382. /**
  6383. * Creates an array of `array` values not included in the other given arrays
  6384. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6385. * for equality comparisons. The order and references of result values are
  6386. * determined by the first array.
  6387. *
  6388. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6389. *
  6390. * @static
  6391. * @memberOf _
  6392. * @since 0.1.0
  6393. * @category Array
  6394. * @param {Array} array The array to inspect.
  6395. * @param {...Array} [values] The values to exclude.
  6396. * @returns {Array} Returns the new array of filtered values.
  6397. * @see _.without, _.xor
  6398. * @example
  6399. *
  6400. * _.difference([2, 1], [2, 3]);
  6401. * // => [1]
  6402. */
  6403. var difference = baseRest(function(array, values) {
  6404. return isArrayLikeObject(array)
  6405. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6406. : [];
  6407. });
  6408. /**
  6409. * This method is like `_.difference` except that it accepts `iteratee` which
  6410. * is invoked for each element of `array` and `values` to generate the criterion
  6411. * by which they're compared. The order and references of result values are
  6412. * determined by the first array. The iteratee is invoked with one argument:
  6413. * (value).
  6414. *
  6415. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6416. *
  6417. * @static
  6418. * @memberOf _
  6419. * @since 4.0.0
  6420. * @category Array
  6421. * @param {Array} array The array to inspect.
  6422. * @param {...Array} [values] The values to exclude.
  6423. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6424. * @returns {Array} Returns the new array of filtered values.
  6425. * @example
  6426. *
  6427. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6428. * // => [1.2]
  6429. *
  6430. * // The `_.property` iteratee shorthand.
  6431. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6432. * // => [{ 'x': 2 }]
  6433. */
  6434. var differenceBy = baseRest(function(array, values) {
  6435. var iteratee = last(values);
  6436. if (isArrayLikeObject(iteratee)) {
  6437. iteratee = undefined;
  6438. }
  6439. return isArrayLikeObject(array)
  6440. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6441. : [];
  6442. });
  6443. /**
  6444. * This method is like `_.difference` except that it accepts `comparator`
  6445. * which is invoked to compare elements of `array` to `values`. The order and
  6446. * references of result values are determined by the first array. The comparator
  6447. * is invoked with two arguments: (arrVal, othVal).
  6448. *
  6449. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6450. *
  6451. * @static
  6452. * @memberOf _
  6453. * @since 4.0.0
  6454. * @category Array
  6455. * @param {Array} array The array to inspect.
  6456. * @param {...Array} [values] The values to exclude.
  6457. * @param {Function} [comparator] The comparator invoked per element.
  6458. * @returns {Array} Returns the new array of filtered values.
  6459. * @example
  6460. *
  6461. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6462. *
  6463. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6464. * // => [{ 'x': 2, 'y': 1 }]
  6465. */
  6466. var differenceWith = baseRest(function(array, values) {
  6467. var comparator = last(values);
  6468. if (isArrayLikeObject(comparator)) {
  6469. comparator = undefined;
  6470. }
  6471. return isArrayLikeObject(array)
  6472. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6473. : [];
  6474. });
  6475. /**
  6476. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6477. *
  6478. * @static
  6479. * @memberOf _
  6480. * @since 0.5.0
  6481. * @category Array
  6482. * @param {Array} array The array to query.
  6483. * @param {number} [n=1] The number of elements to drop.
  6484. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6485. * @returns {Array} Returns the slice of `array`.
  6486. * @example
  6487. *
  6488. * _.drop([1, 2, 3]);
  6489. * // => [2, 3]
  6490. *
  6491. * _.drop([1, 2, 3], 2);
  6492. * // => [3]
  6493. *
  6494. * _.drop([1, 2, 3], 5);
  6495. * // => []
  6496. *
  6497. * _.drop([1, 2, 3], 0);
  6498. * // => [1, 2, 3]
  6499. */
  6500. function drop(array, n, guard) {
  6501. var length = array == null ? 0 : array.length;
  6502. if (!length) {
  6503. return [];
  6504. }
  6505. n = (guard || n === undefined) ? 1 : toInteger(n);
  6506. return baseSlice(array, n < 0 ? 0 : n, length);
  6507. }
  6508. /**
  6509. * Creates a slice of `array` with `n` elements dropped from the end.
  6510. *
  6511. * @static
  6512. * @memberOf _
  6513. * @since 3.0.0
  6514. * @category Array
  6515. * @param {Array} array The array to query.
  6516. * @param {number} [n=1] The number of elements to drop.
  6517. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6518. * @returns {Array} Returns the slice of `array`.
  6519. * @example
  6520. *
  6521. * _.dropRight([1, 2, 3]);
  6522. * // => [1, 2]
  6523. *
  6524. * _.dropRight([1, 2, 3], 2);
  6525. * // => [1]
  6526. *
  6527. * _.dropRight([1, 2, 3], 5);
  6528. * // => []
  6529. *
  6530. * _.dropRight([1, 2, 3], 0);
  6531. * // => [1, 2, 3]
  6532. */
  6533. function dropRight(array, n, guard) {
  6534. var length = array == null ? 0 : array.length;
  6535. if (!length) {
  6536. return [];
  6537. }
  6538. n = (guard || n === undefined) ? 1 : toInteger(n);
  6539. n = length - n;
  6540. return baseSlice(array, 0, n < 0 ? 0 : n);
  6541. }
  6542. /**
  6543. * Creates a slice of `array` excluding elements dropped from the end.
  6544. * Elements are dropped until `predicate` returns falsey. The predicate is
  6545. * invoked with three arguments: (value, index, array).
  6546. *
  6547. * @static
  6548. * @memberOf _
  6549. * @since 3.0.0
  6550. * @category Array
  6551. * @param {Array} array The array to query.
  6552. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6553. * @returns {Array} Returns the slice of `array`.
  6554. * @example
  6555. *
  6556. * var users = [
  6557. * { 'user': 'barney', 'active': true },
  6558. * { 'user': 'fred', 'active': false },
  6559. * { 'user': 'pebbles', 'active': false }
  6560. * ];
  6561. *
  6562. * _.dropRightWhile(users, function(o) { return !o.active; });
  6563. * // => objects for ['barney']
  6564. *
  6565. * // The `_.matches` iteratee shorthand.
  6566. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6567. * // => objects for ['barney', 'fred']
  6568. *
  6569. * // The `_.matchesProperty` iteratee shorthand.
  6570. * _.dropRightWhile(users, ['active', false]);
  6571. * // => objects for ['barney']
  6572. *
  6573. * // The `_.property` iteratee shorthand.
  6574. * _.dropRightWhile(users, 'active');
  6575. * // => objects for ['barney', 'fred', 'pebbles']
  6576. */
  6577. function dropRightWhile(array, predicate) {
  6578. return (array && array.length)
  6579. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6580. : [];
  6581. }
  6582. /**
  6583. * Creates a slice of `array` excluding elements dropped from the beginning.
  6584. * Elements are dropped until `predicate` returns falsey. The predicate is
  6585. * invoked with three arguments: (value, index, array).
  6586. *
  6587. * @static
  6588. * @memberOf _
  6589. * @since 3.0.0
  6590. * @category Array
  6591. * @param {Array} array The array to query.
  6592. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6593. * @returns {Array} Returns the slice of `array`.
  6594. * @example
  6595. *
  6596. * var users = [
  6597. * { 'user': 'barney', 'active': false },
  6598. * { 'user': 'fred', 'active': false },
  6599. * { 'user': 'pebbles', 'active': true }
  6600. * ];
  6601. *
  6602. * _.dropWhile(users, function(o) { return !o.active; });
  6603. * // => objects for ['pebbles']
  6604. *
  6605. * // The `_.matches` iteratee shorthand.
  6606. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6607. * // => objects for ['fred', 'pebbles']
  6608. *
  6609. * // The `_.matchesProperty` iteratee shorthand.
  6610. * _.dropWhile(users, ['active', false]);
  6611. * // => objects for ['pebbles']
  6612. *
  6613. * // The `_.property` iteratee shorthand.
  6614. * _.dropWhile(users, 'active');
  6615. * // => objects for ['barney', 'fred', 'pebbles']
  6616. */
  6617. function dropWhile(array, predicate) {
  6618. return (array && array.length)
  6619. ? baseWhile(array, getIteratee(predicate, 3), true)
  6620. : [];
  6621. }
  6622. /**
  6623. * Fills elements of `array` with `value` from `start` up to, but not
  6624. * including, `end`.
  6625. *
  6626. * **Note:** This method mutates `array`.
  6627. *
  6628. * @static
  6629. * @memberOf _
  6630. * @since 3.2.0
  6631. * @category Array
  6632. * @param {Array} array The array to fill.
  6633. * @param {*} value The value to fill `array` with.
  6634. * @param {number} [start=0] The start position.
  6635. * @param {number} [end=array.length] The end position.
  6636. * @returns {Array} Returns `array`.
  6637. * @example
  6638. *
  6639. * var array = [1, 2, 3];
  6640. *
  6641. * _.fill(array, 'a');
  6642. * console.log(array);
  6643. * // => ['a', 'a', 'a']
  6644. *
  6645. * _.fill(Array(3), 2);
  6646. * // => [2, 2, 2]
  6647. *
  6648. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6649. * // => [4, '*', '*', 10]
  6650. */
  6651. function fill(array, value, start, end) {
  6652. var length = array == null ? 0 : array.length;
  6653. if (!length) {
  6654. return [];
  6655. }
  6656. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6657. start = 0;
  6658. end = length;
  6659. }
  6660. return baseFill(array, value, start, end);
  6661. }
  6662. /**
  6663. * This method is like `_.find` except that it returns the index of the first
  6664. * element `predicate` returns truthy for instead of the element itself.
  6665. *
  6666. * @static
  6667. * @memberOf _
  6668. * @since 1.1.0
  6669. * @category Array
  6670. * @param {Array} array The array to inspect.
  6671. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6672. * @param {number} [fromIndex=0] The index to search from.
  6673. * @returns {number} Returns the index of the found element, else `-1`.
  6674. * @example
  6675. *
  6676. * var users = [
  6677. * { 'user': 'barney', 'active': false },
  6678. * { 'user': 'fred', 'active': false },
  6679. * { 'user': 'pebbles', 'active': true }
  6680. * ];
  6681. *
  6682. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6683. * // => 0
  6684. *
  6685. * // The `_.matches` iteratee shorthand.
  6686. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6687. * // => 1
  6688. *
  6689. * // The `_.matchesProperty` iteratee shorthand.
  6690. * _.findIndex(users, ['active', false]);
  6691. * // => 0
  6692. *
  6693. * // The `_.property` iteratee shorthand.
  6694. * _.findIndex(users, 'active');
  6695. * // => 2
  6696. */
  6697. function findIndex(array, predicate, fromIndex) {
  6698. var length = array == null ? 0 : array.length;
  6699. if (!length) {
  6700. return -1;
  6701. }
  6702. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6703. if (index < 0) {
  6704. index = nativeMax(length + index, 0);
  6705. }
  6706. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6707. }
  6708. /**
  6709. * This method is like `_.findIndex` except that it iterates over elements
  6710. * of `collection` from right to left.
  6711. *
  6712. * @static
  6713. * @memberOf _
  6714. * @since 2.0.0
  6715. * @category Array
  6716. * @param {Array} array The array to inspect.
  6717. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6718. * @param {number} [fromIndex=array.length-1] The index to search from.
  6719. * @returns {number} Returns the index of the found element, else `-1`.
  6720. * @example
  6721. *
  6722. * var users = [
  6723. * { 'user': 'barney', 'active': true },
  6724. * { 'user': 'fred', 'active': false },
  6725. * { 'user': 'pebbles', 'active': false }
  6726. * ];
  6727. *
  6728. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6729. * // => 2
  6730. *
  6731. * // The `_.matches` iteratee shorthand.
  6732. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6733. * // => 0
  6734. *
  6735. * // The `_.matchesProperty` iteratee shorthand.
  6736. * _.findLastIndex(users, ['active', false]);
  6737. * // => 2
  6738. *
  6739. * // The `_.property` iteratee shorthand.
  6740. * _.findLastIndex(users, 'active');
  6741. * // => 0
  6742. */
  6743. function findLastIndex(array, predicate, fromIndex) {
  6744. var length = array == null ? 0 : array.length;
  6745. if (!length) {
  6746. return -1;
  6747. }
  6748. var index = length - 1;
  6749. if (fromIndex !== undefined) {
  6750. index = toInteger(fromIndex);
  6751. index = fromIndex < 0
  6752. ? nativeMax(length + index, 0)
  6753. : nativeMin(index, length - 1);
  6754. }
  6755. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6756. }
  6757. /**
  6758. * Flattens `array` a single level deep.
  6759. *
  6760. * @static
  6761. * @memberOf _
  6762. * @since 0.1.0
  6763. * @category Array
  6764. * @param {Array} array The array to flatten.
  6765. * @returns {Array} Returns the new flattened array.
  6766. * @example
  6767. *
  6768. * _.flatten([1, [2, [3, [4]], 5]]);
  6769. * // => [1, 2, [3, [4]], 5]
  6770. */
  6771. function flatten(array) {
  6772. var length = array == null ? 0 : array.length;
  6773. return length ? baseFlatten(array, 1) : [];
  6774. }
  6775. /**
  6776. * Recursively flattens `array`.
  6777. *
  6778. * @static
  6779. * @memberOf _
  6780. * @since 3.0.0
  6781. * @category Array
  6782. * @param {Array} array The array to flatten.
  6783. * @returns {Array} Returns the new flattened array.
  6784. * @example
  6785. *
  6786. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6787. * // => [1, 2, 3, 4, 5]
  6788. */
  6789. function flattenDeep(array) {
  6790. var length = array == null ? 0 : array.length;
  6791. return length ? baseFlatten(array, INFINITY) : [];
  6792. }
  6793. /**
  6794. * Recursively flatten `array` up to `depth` times.
  6795. *
  6796. * @static
  6797. * @memberOf _
  6798. * @since 4.4.0
  6799. * @category Array
  6800. * @param {Array} array The array to flatten.
  6801. * @param {number} [depth=1] The maximum recursion depth.
  6802. * @returns {Array} Returns the new flattened array.
  6803. * @example
  6804. *
  6805. * var array = [1, [2, [3, [4]], 5]];
  6806. *
  6807. * _.flattenDepth(array, 1);
  6808. * // => [1, 2, [3, [4]], 5]
  6809. *
  6810. * _.flattenDepth(array, 2);
  6811. * // => [1, 2, 3, [4], 5]
  6812. */
  6813. function flattenDepth(array, depth) {
  6814. var length = array == null ? 0 : array.length;
  6815. if (!length) {
  6816. return [];
  6817. }
  6818. depth = depth === undefined ? 1 : toInteger(depth);
  6819. return baseFlatten(array, depth);
  6820. }
  6821. /**
  6822. * The inverse of `_.toPairs`; this method returns an object composed
  6823. * from key-value `pairs`.
  6824. *
  6825. * @static
  6826. * @memberOf _
  6827. * @since 4.0.0
  6828. * @category Array
  6829. * @param {Array} pairs The key-value pairs.
  6830. * @returns {Object} Returns the new object.
  6831. * @example
  6832. *
  6833. * _.fromPairs([['a', 1], ['b', 2]]);
  6834. * // => { 'a': 1, 'b': 2 }
  6835. */
  6836. function fromPairs(pairs) {
  6837. var index = -1,
  6838. length = pairs == null ? 0 : pairs.length,
  6839. result = {};
  6840. while (++index < length) {
  6841. var pair = pairs[index];
  6842. result[pair[0]] = pair[1];
  6843. }
  6844. return result;
  6845. }
  6846. /**
  6847. * Gets the first element of `array`.
  6848. *
  6849. * @static
  6850. * @memberOf _
  6851. * @since 0.1.0
  6852. * @alias first
  6853. * @category Array
  6854. * @param {Array} array The array to query.
  6855. * @returns {*} Returns the first element of `array`.
  6856. * @example
  6857. *
  6858. * _.head([1, 2, 3]);
  6859. * // => 1
  6860. *
  6861. * _.head([]);
  6862. * // => undefined
  6863. */
  6864. function head(array) {
  6865. return (array && array.length) ? array[0] : undefined;
  6866. }
  6867. /**
  6868. * Gets the index at which the first occurrence of `value` is found in `array`
  6869. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6870. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6871. * offset from the end of `array`.
  6872. *
  6873. * @static
  6874. * @memberOf _
  6875. * @since 0.1.0
  6876. * @category Array
  6877. * @param {Array} array The array to inspect.
  6878. * @param {*} value The value to search for.
  6879. * @param {number} [fromIndex=0] The index to search from.
  6880. * @returns {number} Returns the index of the matched value, else `-1`.
  6881. * @example
  6882. *
  6883. * _.indexOf([1, 2, 1, 2], 2);
  6884. * // => 1
  6885. *
  6886. * // Search from the `fromIndex`.
  6887. * _.indexOf([1, 2, 1, 2], 2, 2);
  6888. * // => 3
  6889. */
  6890. function indexOf(array, value, fromIndex) {
  6891. var length = array == null ? 0 : array.length;
  6892. if (!length) {
  6893. return -1;
  6894. }
  6895. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6896. if (index < 0) {
  6897. index = nativeMax(length + index, 0);
  6898. }
  6899. return baseIndexOf(array, value, index);
  6900. }
  6901. /**
  6902. * Gets all but the last element of `array`.
  6903. *
  6904. * @static
  6905. * @memberOf _
  6906. * @since 0.1.0
  6907. * @category Array
  6908. * @param {Array} array The array to query.
  6909. * @returns {Array} Returns the slice of `array`.
  6910. * @example
  6911. *
  6912. * _.initial([1, 2, 3]);
  6913. * // => [1, 2]
  6914. */
  6915. function initial(array) {
  6916. var length = array == null ? 0 : array.length;
  6917. return length ? baseSlice(array, 0, -1) : [];
  6918. }
  6919. /**
  6920. * Creates an array of unique values that are included in all given arrays
  6921. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6922. * for equality comparisons. The order and references of result values are
  6923. * determined by the first array.
  6924. *
  6925. * @static
  6926. * @memberOf _
  6927. * @since 0.1.0
  6928. * @category Array
  6929. * @param {...Array} [arrays] The arrays to inspect.
  6930. * @returns {Array} Returns the new array of intersecting values.
  6931. * @example
  6932. *
  6933. * _.intersection([2, 1], [2, 3]);
  6934. * // => [2]
  6935. */
  6936. var intersection = baseRest(function(arrays) {
  6937. var mapped = arrayMap(arrays, castArrayLikeObject);
  6938. return (mapped.length && mapped[0] === arrays[0])
  6939. ? baseIntersection(mapped)
  6940. : [];
  6941. });
  6942. /**
  6943. * This method is like `_.intersection` except that it accepts `iteratee`
  6944. * which is invoked for each element of each `arrays` to generate the criterion
  6945. * by which they're compared. The order and references of result values are
  6946. * determined by the first array. The iteratee is invoked with one argument:
  6947. * (value).
  6948. *
  6949. * @static
  6950. * @memberOf _
  6951. * @since 4.0.0
  6952. * @category Array
  6953. * @param {...Array} [arrays] The arrays to inspect.
  6954. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6955. * @returns {Array} Returns the new array of intersecting values.
  6956. * @example
  6957. *
  6958. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6959. * // => [2.1]
  6960. *
  6961. * // The `_.property` iteratee shorthand.
  6962. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6963. * // => [{ 'x': 1 }]
  6964. */
  6965. var intersectionBy = baseRest(function(arrays) {
  6966. var iteratee = last(arrays),
  6967. mapped = arrayMap(arrays, castArrayLikeObject);
  6968. if (iteratee === last(mapped)) {
  6969. iteratee = undefined;
  6970. } else {
  6971. mapped.pop();
  6972. }
  6973. return (mapped.length && mapped[0] === arrays[0])
  6974. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6975. : [];
  6976. });
  6977. /**
  6978. * This method is like `_.intersection` except that it accepts `comparator`
  6979. * which is invoked to compare elements of `arrays`. The order and references
  6980. * of result values are determined by the first array. The comparator is
  6981. * invoked with two arguments: (arrVal, othVal).
  6982. *
  6983. * @static
  6984. * @memberOf _
  6985. * @since 4.0.0
  6986. * @category Array
  6987. * @param {...Array} [arrays] The arrays to inspect.
  6988. * @param {Function} [comparator] The comparator invoked per element.
  6989. * @returns {Array} Returns the new array of intersecting values.
  6990. * @example
  6991. *
  6992. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6993. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6994. *
  6995. * _.intersectionWith(objects, others, _.isEqual);
  6996. * // => [{ 'x': 1, 'y': 2 }]
  6997. */
  6998. var intersectionWith = baseRest(function(arrays) {
  6999. var comparator = last(arrays),
  7000. mapped = arrayMap(arrays, castArrayLikeObject);
  7001. comparator = typeof comparator == 'function' ? comparator : undefined;
  7002. if (comparator) {
  7003. mapped.pop();
  7004. }
  7005. return (mapped.length && mapped[0] === arrays[0])
  7006. ? baseIntersection(mapped, undefined, comparator)
  7007. : [];
  7008. });
  7009. /**
  7010. * Converts all elements in `array` into a string separated by `separator`.
  7011. *
  7012. * @static
  7013. * @memberOf _
  7014. * @since 4.0.0
  7015. * @category Array
  7016. * @param {Array} array The array to convert.
  7017. * @param {string} [separator=','] The element separator.
  7018. * @returns {string} Returns the joined string.
  7019. * @example
  7020. *
  7021. * _.join(['a', 'b', 'c'], '~');
  7022. * // => 'a~b~c'
  7023. */
  7024. function join(array, separator) {
  7025. return array == null ? '' : nativeJoin.call(array, separator);
  7026. }
  7027. /**
  7028. * Gets the last element of `array`.
  7029. *
  7030. * @static
  7031. * @memberOf _
  7032. * @since 0.1.0
  7033. * @category Array
  7034. * @param {Array} array The array to query.
  7035. * @returns {*} Returns the last element of `array`.
  7036. * @example
  7037. *
  7038. * _.last([1, 2, 3]);
  7039. * // => 3
  7040. */
  7041. function last(array) {
  7042. var length = array == null ? 0 : array.length;
  7043. return length ? array[length - 1] : undefined;
  7044. }
  7045. /**
  7046. * This method is like `_.indexOf` except that it iterates over elements of
  7047. * `array` from right to left.
  7048. *
  7049. * @static
  7050. * @memberOf _
  7051. * @since 0.1.0
  7052. * @category Array
  7053. * @param {Array} array The array to inspect.
  7054. * @param {*} value The value to search for.
  7055. * @param {number} [fromIndex=array.length-1] The index to search from.
  7056. * @returns {number} Returns the index of the matched value, else `-1`.
  7057. * @example
  7058. *
  7059. * _.lastIndexOf([1, 2, 1, 2], 2);
  7060. * // => 3
  7061. *
  7062. * // Search from the `fromIndex`.
  7063. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7064. * // => 1
  7065. */
  7066. function lastIndexOf(array, value, fromIndex) {
  7067. var length = array == null ? 0 : array.length;
  7068. if (!length) {
  7069. return -1;
  7070. }
  7071. var index = length;
  7072. if (fromIndex !== undefined) {
  7073. index = toInteger(fromIndex);
  7074. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7075. }
  7076. return value === value
  7077. ? strictLastIndexOf(array, value, index)
  7078. : baseFindIndex(array, baseIsNaN, index, true);
  7079. }
  7080. /**
  7081. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7082. * element from the end is returned.
  7083. *
  7084. * @static
  7085. * @memberOf _
  7086. * @since 4.11.0
  7087. * @category Array
  7088. * @param {Array} array The array to query.
  7089. * @param {number} [n=0] The index of the element to return.
  7090. * @returns {*} Returns the nth element of `array`.
  7091. * @example
  7092. *
  7093. * var array = ['a', 'b', 'c', 'd'];
  7094. *
  7095. * _.nth(array, 1);
  7096. * // => 'b'
  7097. *
  7098. * _.nth(array, -2);
  7099. * // => 'c';
  7100. */
  7101. function nth(array, n) {
  7102. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7103. }
  7104. /**
  7105. * Removes all given values from `array` using
  7106. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7107. * for equality comparisons.
  7108. *
  7109. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7110. * to remove elements from an array by predicate.
  7111. *
  7112. * @static
  7113. * @memberOf _
  7114. * @since 2.0.0
  7115. * @category Array
  7116. * @param {Array} array The array to modify.
  7117. * @param {...*} [values] The values to remove.
  7118. * @returns {Array} Returns `array`.
  7119. * @example
  7120. *
  7121. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7122. *
  7123. * _.pull(array, 'a', 'c');
  7124. * console.log(array);
  7125. * // => ['b', 'b']
  7126. */
  7127. var pull = baseRest(pullAll);
  7128. /**
  7129. * This method is like `_.pull` except that it accepts an array of values to remove.
  7130. *
  7131. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7132. *
  7133. * @static
  7134. * @memberOf _
  7135. * @since 4.0.0
  7136. * @category Array
  7137. * @param {Array} array The array to modify.
  7138. * @param {Array} values The values to remove.
  7139. * @returns {Array} Returns `array`.
  7140. * @example
  7141. *
  7142. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7143. *
  7144. * _.pullAll(array, ['a', 'c']);
  7145. * console.log(array);
  7146. * // => ['b', 'b']
  7147. */
  7148. function pullAll(array, values) {
  7149. return (array && array.length && values && values.length)
  7150. ? basePullAll(array, values)
  7151. : array;
  7152. }
  7153. /**
  7154. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7155. * invoked for each element of `array` and `values` to generate the criterion
  7156. * by which they're compared. The iteratee is invoked with one argument: (value).
  7157. *
  7158. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7159. *
  7160. * @static
  7161. * @memberOf _
  7162. * @since 4.0.0
  7163. * @category Array
  7164. * @param {Array} array The array to modify.
  7165. * @param {Array} values The values to remove.
  7166. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7167. * @returns {Array} Returns `array`.
  7168. * @example
  7169. *
  7170. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7171. *
  7172. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7173. * console.log(array);
  7174. * // => [{ 'x': 2 }]
  7175. */
  7176. function pullAllBy(array, values, iteratee) {
  7177. return (array && array.length && values && values.length)
  7178. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7179. : array;
  7180. }
  7181. /**
  7182. * This method is like `_.pullAll` except that it accepts `comparator` which
  7183. * is invoked to compare elements of `array` to `values`. The comparator is
  7184. * invoked with two arguments: (arrVal, othVal).
  7185. *
  7186. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7187. *
  7188. * @static
  7189. * @memberOf _
  7190. * @since 4.6.0
  7191. * @category Array
  7192. * @param {Array} array The array to modify.
  7193. * @param {Array} values The values to remove.
  7194. * @param {Function} [comparator] The comparator invoked per element.
  7195. * @returns {Array} Returns `array`.
  7196. * @example
  7197. *
  7198. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7199. *
  7200. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7201. * console.log(array);
  7202. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7203. */
  7204. function pullAllWith(array, values, comparator) {
  7205. return (array && array.length && values && values.length)
  7206. ? basePullAll(array, values, undefined, comparator)
  7207. : array;
  7208. }
  7209. /**
  7210. * Removes elements from `array` corresponding to `indexes` and returns an
  7211. * array of removed elements.
  7212. *
  7213. * **Note:** Unlike `_.at`, this method mutates `array`.
  7214. *
  7215. * @static
  7216. * @memberOf _
  7217. * @since 3.0.0
  7218. * @category Array
  7219. * @param {Array} array The array to modify.
  7220. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7221. * @returns {Array} Returns the new array of removed elements.
  7222. * @example
  7223. *
  7224. * var array = ['a', 'b', 'c', 'd'];
  7225. * var pulled = _.pullAt(array, [1, 3]);
  7226. *
  7227. * console.log(array);
  7228. * // => ['a', 'c']
  7229. *
  7230. * console.log(pulled);
  7231. * // => ['b', 'd']
  7232. */
  7233. var pullAt = flatRest(function(array, indexes) {
  7234. var length = array == null ? 0 : array.length,
  7235. result = baseAt(array, indexes);
  7236. basePullAt(array, arrayMap(indexes, function(index) {
  7237. return isIndex(index, length) ? +index : index;
  7238. }).sort(compareAscending));
  7239. return result;
  7240. });
  7241. /**
  7242. * Removes all elements from `array` that `predicate` returns truthy for
  7243. * and returns an array of the removed elements. The predicate is invoked
  7244. * with three arguments: (value, index, array).
  7245. *
  7246. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7247. * to pull elements from an array by value.
  7248. *
  7249. * @static
  7250. * @memberOf _
  7251. * @since 2.0.0
  7252. * @category Array
  7253. * @param {Array} array The array to modify.
  7254. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7255. * @returns {Array} Returns the new array of removed elements.
  7256. * @example
  7257. *
  7258. * var array = [1, 2, 3, 4];
  7259. * var evens = _.remove(array, function(n) {
  7260. * return n % 2 == 0;
  7261. * });
  7262. *
  7263. * console.log(array);
  7264. * // => [1, 3]
  7265. *
  7266. * console.log(evens);
  7267. * // => [2, 4]
  7268. */
  7269. function remove(array, predicate) {
  7270. var result = [];
  7271. if (!(array && array.length)) {
  7272. return result;
  7273. }
  7274. var index = -1,
  7275. indexes = [],
  7276. length = array.length;
  7277. predicate = getIteratee(predicate, 3);
  7278. while (++index < length) {
  7279. var value = array[index];
  7280. if (predicate(value, index, array)) {
  7281. result.push(value);
  7282. indexes.push(index);
  7283. }
  7284. }
  7285. basePullAt(array, indexes);
  7286. return result;
  7287. }
  7288. /**
  7289. * Reverses `array` so that the first element becomes the last, the second
  7290. * element becomes the second to last, and so on.
  7291. *
  7292. * **Note:** This method mutates `array` and is based on
  7293. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7294. *
  7295. * @static
  7296. * @memberOf _
  7297. * @since 4.0.0
  7298. * @category Array
  7299. * @param {Array} array The array to modify.
  7300. * @returns {Array} Returns `array`.
  7301. * @example
  7302. *
  7303. * var array = [1, 2, 3];
  7304. *
  7305. * _.reverse(array);
  7306. * // => [3, 2, 1]
  7307. *
  7308. * console.log(array);
  7309. * // => [3, 2, 1]
  7310. */
  7311. function reverse(array) {
  7312. return array == null ? array : nativeReverse.call(array);
  7313. }
  7314. /**
  7315. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7316. *
  7317. * **Note:** This method is used instead of
  7318. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7319. * returned.
  7320. *
  7321. * @static
  7322. * @memberOf _
  7323. * @since 3.0.0
  7324. * @category Array
  7325. * @param {Array} array The array to slice.
  7326. * @param {number} [start=0] The start position.
  7327. * @param {number} [end=array.length] The end position.
  7328. * @returns {Array} Returns the slice of `array`.
  7329. */
  7330. function slice(array, start, end) {
  7331. var length = array == null ? 0 : array.length;
  7332. if (!length) {
  7333. return [];
  7334. }
  7335. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7336. start = 0;
  7337. end = length;
  7338. }
  7339. else {
  7340. start = start == null ? 0 : toInteger(start);
  7341. end = end === undefined ? length : toInteger(end);
  7342. }
  7343. return baseSlice(array, start, end);
  7344. }
  7345. /**
  7346. * Uses a binary search to determine the lowest index at which `value`
  7347. * should be inserted into `array` in order to maintain its sort order.
  7348. *
  7349. * @static
  7350. * @memberOf _
  7351. * @since 0.1.0
  7352. * @category Array
  7353. * @param {Array} array The sorted array to inspect.
  7354. * @param {*} value The value to evaluate.
  7355. * @returns {number} Returns the index at which `value` should be inserted
  7356. * into `array`.
  7357. * @example
  7358. *
  7359. * _.sortedIndex([30, 50], 40);
  7360. * // => 1
  7361. */
  7362. function sortedIndex(array, value) {
  7363. return baseSortedIndex(array, value);
  7364. }
  7365. /**
  7366. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7367. * which is invoked for `value` and each element of `array` to compute their
  7368. * sort ranking. The iteratee is invoked with one argument: (value).
  7369. *
  7370. * @static
  7371. * @memberOf _
  7372. * @since 4.0.0
  7373. * @category Array
  7374. * @param {Array} array The sorted array to inspect.
  7375. * @param {*} value The value to evaluate.
  7376. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7377. * @returns {number} Returns the index at which `value` should be inserted
  7378. * into `array`.
  7379. * @example
  7380. *
  7381. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7382. *
  7383. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7384. * // => 0
  7385. *
  7386. * // The `_.property` iteratee shorthand.
  7387. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7388. * // => 0
  7389. */
  7390. function sortedIndexBy(array, value, iteratee) {
  7391. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7392. }
  7393. /**
  7394. * This method is like `_.indexOf` except that it performs a binary
  7395. * search on a sorted `array`.
  7396. *
  7397. * @static
  7398. * @memberOf _
  7399. * @since 4.0.0
  7400. * @category Array
  7401. * @param {Array} array The array to inspect.
  7402. * @param {*} value The value to search for.
  7403. * @returns {number} Returns the index of the matched value, else `-1`.
  7404. * @example
  7405. *
  7406. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7407. * // => 1
  7408. */
  7409. function sortedIndexOf(array, value) {
  7410. var length = array == null ? 0 : array.length;
  7411. if (length) {
  7412. var index = baseSortedIndex(array, value);
  7413. if (index < length && eq(array[index], value)) {
  7414. return index;
  7415. }
  7416. }
  7417. return -1;
  7418. }
  7419. /**
  7420. * This method is like `_.sortedIndex` except that it returns the highest
  7421. * index at which `value` should be inserted into `array` in order to
  7422. * maintain its sort order.
  7423. *
  7424. * @static
  7425. * @memberOf _
  7426. * @since 3.0.0
  7427. * @category Array
  7428. * @param {Array} array The sorted array to inspect.
  7429. * @param {*} value The value to evaluate.
  7430. * @returns {number} Returns the index at which `value` should be inserted
  7431. * into `array`.
  7432. * @example
  7433. *
  7434. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7435. * // => 4
  7436. */
  7437. function sortedLastIndex(array, value) {
  7438. return baseSortedIndex(array, value, true);
  7439. }
  7440. /**
  7441. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7442. * which is invoked for `value` and each element of `array` to compute their
  7443. * sort ranking. The iteratee is invoked with one argument: (value).
  7444. *
  7445. * @static
  7446. * @memberOf _
  7447. * @since 4.0.0
  7448. * @category Array
  7449. * @param {Array} array The sorted array to inspect.
  7450. * @param {*} value The value to evaluate.
  7451. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7452. * @returns {number} Returns the index at which `value` should be inserted
  7453. * into `array`.
  7454. * @example
  7455. *
  7456. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7457. *
  7458. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7459. * // => 1
  7460. *
  7461. * // The `_.property` iteratee shorthand.
  7462. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7463. * // => 1
  7464. */
  7465. function sortedLastIndexBy(array, value, iteratee) {
  7466. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7467. }
  7468. /**
  7469. * This method is like `_.lastIndexOf` except that it performs a binary
  7470. * search on a sorted `array`.
  7471. *
  7472. * @static
  7473. * @memberOf _
  7474. * @since 4.0.0
  7475. * @category Array
  7476. * @param {Array} array The array to inspect.
  7477. * @param {*} value The value to search for.
  7478. * @returns {number} Returns the index of the matched value, else `-1`.
  7479. * @example
  7480. *
  7481. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7482. * // => 3
  7483. */
  7484. function sortedLastIndexOf(array, value) {
  7485. var length = array == null ? 0 : array.length;
  7486. if (length) {
  7487. var index = baseSortedIndex(array, value, true) - 1;
  7488. if (eq(array[index], value)) {
  7489. return index;
  7490. }
  7491. }
  7492. return -1;
  7493. }
  7494. /**
  7495. * This method is like `_.uniq` except that it's designed and optimized
  7496. * for sorted arrays.
  7497. *
  7498. * @static
  7499. * @memberOf _
  7500. * @since 4.0.0
  7501. * @category Array
  7502. * @param {Array} array The array to inspect.
  7503. * @returns {Array} Returns the new duplicate free array.
  7504. * @example
  7505. *
  7506. * _.sortedUniq([1, 1, 2]);
  7507. * // => [1, 2]
  7508. */
  7509. function sortedUniq(array) {
  7510. return (array && array.length)
  7511. ? baseSortedUniq(array)
  7512. : [];
  7513. }
  7514. /**
  7515. * This method is like `_.uniqBy` except that it's designed and optimized
  7516. * for sorted arrays.
  7517. *
  7518. * @static
  7519. * @memberOf _
  7520. * @since 4.0.0
  7521. * @category Array
  7522. * @param {Array} array The array to inspect.
  7523. * @param {Function} [iteratee] The iteratee invoked per element.
  7524. * @returns {Array} Returns the new duplicate free array.
  7525. * @example
  7526. *
  7527. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7528. * // => [1.1, 2.3]
  7529. */
  7530. function sortedUniqBy(array, iteratee) {
  7531. return (array && array.length)
  7532. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7533. : [];
  7534. }
  7535. /**
  7536. * Gets all but the first element of `array`.
  7537. *
  7538. * @static
  7539. * @memberOf _
  7540. * @since 4.0.0
  7541. * @category Array
  7542. * @param {Array} array The array to query.
  7543. * @returns {Array} Returns the slice of `array`.
  7544. * @example
  7545. *
  7546. * _.tail([1, 2, 3]);
  7547. * // => [2, 3]
  7548. */
  7549. function tail(array) {
  7550. var length = array == null ? 0 : array.length;
  7551. return length ? baseSlice(array, 1, length) : [];
  7552. }
  7553. /**
  7554. * Creates a slice of `array` with `n` elements taken from the beginning.
  7555. *
  7556. * @static
  7557. * @memberOf _
  7558. * @since 0.1.0
  7559. * @category Array
  7560. * @param {Array} array The array to query.
  7561. * @param {number} [n=1] The number of elements to take.
  7562. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7563. * @returns {Array} Returns the slice of `array`.
  7564. * @example
  7565. *
  7566. * _.take([1, 2, 3]);
  7567. * // => [1]
  7568. *
  7569. * _.take([1, 2, 3], 2);
  7570. * // => [1, 2]
  7571. *
  7572. * _.take([1, 2, 3], 5);
  7573. * // => [1, 2, 3]
  7574. *
  7575. * _.take([1, 2, 3], 0);
  7576. * // => []
  7577. */
  7578. function take(array, n, guard) {
  7579. if (!(array && array.length)) {
  7580. return [];
  7581. }
  7582. n = (guard || n === undefined) ? 1 : toInteger(n);
  7583. return baseSlice(array, 0, n < 0 ? 0 : n);
  7584. }
  7585. /**
  7586. * Creates a slice of `array` with `n` elements taken from the end.
  7587. *
  7588. * @static
  7589. * @memberOf _
  7590. * @since 3.0.0
  7591. * @category Array
  7592. * @param {Array} array The array to query.
  7593. * @param {number} [n=1] The number of elements to take.
  7594. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7595. * @returns {Array} Returns the slice of `array`.
  7596. * @example
  7597. *
  7598. * _.takeRight([1, 2, 3]);
  7599. * // => [3]
  7600. *
  7601. * _.takeRight([1, 2, 3], 2);
  7602. * // => [2, 3]
  7603. *
  7604. * _.takeRight([1, 2, 3], 5);
  7605. * // => [1, 2, 3]
  7606. *
  7607. * _.takeRight([1, 2, 3], 0);
  7608. * // => []
  7609. */
  7610. function takeRight(array, n, guard) {
  7611. var length = array == null ? 0 : array.length;
  7612. if (!length) {
  7613. return [];
  7614. }
  7615. n = (guard || n === undefined) ? 1 : toInteger(n);
  7616. n = length - n;
  7617. return baseSlice(array, n < 0 ? 0 : n, length);
  7618. }
  7619. /**
  7620. * Creates a slice of `array` with elements taken from the end. Elements are
  7621. * taken until `predicate` returns falsey. The predicate is invoked with
  7622. * three arguments: (value, index, array).
  7623. *
  7624. * @static
  7625. * @memberOf _
  7626. * @since 3.0.0
  7627. * @category Array
  7628. * @param {Array} array The array to query.
  7629. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7630. * @returns {Array} Returns the slice of `array`.
  7631. * @example
  7632. *
  7633. * var users = [
  7634. * { 'user': 'barney', 'active': true },
  7635. * { 'user': 'fred', 'active': false },
  7636. * { 'user': 'pebbles', 'active': false }
  7637. * ];
  7638. *
  7639. * _.takeRightWhile(users, function(o) { return !o.active; });
  7640. * // => objects for ['fred', 'pebbles']
  7641. *
  7642. * // The `_.matches` iteratee shorthand.
  7643. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7644. * // => objects for ['pebbles']
  7645. *
  7646. * // The `_.matchesProperty` iteratee shorthand.
  7647. * _.takeRightWhile(users, ['active', false]);
  7648. * // => objects for ['fred', 'pebbles']
  7649. *
  7650. * // The `_.property` iteratee shorthand.
  7651. * _.takeRightWhile(users, 'active');
  7652. * // => []
  7653. */
  7654. function takeRightWhile(array, predicate) {
  7655. return (array && array.length)
  7656. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7657. : [];
  7658. }
  7659. /**
  7660. * Creates a slice of `array` with elements taken from the beginning. Elements
  7661. * are taken until `predicate` returns falsey. The predicate is invoked with
  7662. * three arguments: (value, index, array).
  7663. *
  7664. * @static
  7665. * @memberOf _
  7666. * @since 3.0.0
  7667. * @category Array
  7668. * @param {Array} array The array to query.
  7669. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7670. * @returns {Array} Returns the slice of `array`.
  7671. * @example
  7672. *
  7673. * var users = [
  7674. * { 'user': 'barney', 'active': false },
  7675. * { 'user': 'fred', 'active': false },
  7676. * { 'user': 'pebbles', 'active': true }
  7677. * ];
  7678. *
  7679. * _.takeWhile(users, function(o) { return !o.active; });
  7680. * // => objects for ['barney', 'fred']
  7681. *
  7682. * // The `_.matches` iteratee shorthand.
  7683. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7684. * // => objects for ['barney']
  7685. *
  7686. * // The `_.matchesProperty` iteratee shorthand.
  7687. * _.takeWhile(users, ['active', false]);
  7688. * // => objects for ['barney', 'fred']
  7689. *
  7690. * // The `_.property` iteratee shorthand.
  7691. * _.takeWhile(users, 'active');
  7692. * // => []
  7693. */
  7694. function takeWhile(array, predicate) {
  7695. return (array && array.length)
  7696. ? baseWhile(array, getIteratee(predicate, 3))
  7697. : [];
  7698. }
  7699. /**
  7700. * Creates an array of unique values, in order, from all given arrays using
  7701. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7702. * for equality comparisons.
  7703. *
  7704. * @static
  7705. * @memberOf _
  7706. * @since 0.1.0
  7707. * @category Array
  7708. * @param {...Array} [arrays] The arrays to inspect.
  7709. * @returns {Array} Returns the new array of combined values.
  7710. * @example
  7711. *
  7712. * _.union([2], [1, 2]);
  7713. * // => [2, 1]
  7714. */
  7715. var union = baseRest(function(arrays) {
  7716. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7717. });
  7718. /**
  7719. * This method is like `_.union` except that it accepts `iteratee` which is
  7720. * invoked for each element of each `arrays` to generate the criterion by
  7721. * which uniqueness is computed. Result values are chosen from the first
  7722. * array in which the value occurs. The iteratee is invoked with one argument:
  7723. * (value).
  7724. *
  7725. * @static
  7726. * @memberOf _
  7727. * @since 4.0.0
  7728. * @category Array
  7729. * @param {...Array} [arrays] The arrays to inspect.
  7730. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7731. * @returns {Array} Returns the new array of combined values.
  7732. * @example
  7733. *
  7734. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7735. * // => [2.1, 1.2]
  7736. *
  7737. * // The `_.property` iteratee shorthand.
  7738. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7739. * // => [{ 'x': 1 }, { 'x': 2 }]
  7740. */
  7741. var unionBy = baseRest(function(arrays) {
  7742. var iteratee = last(arrays);
  7743. if (isArrayLikeObject(iteratee)) {
  7744. iteratee = undefined;
  7745. }
  7746. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7747. });
  7748. /**
  7749. * This method is like `_.union` except that it accepts `comparator` which
  7750. * is invoked to compare elements of `arrays`. Result values are chosen from
  7751. * the first array in which the value occurs. The comparator is invoked
  7752. * with two arguments: (arrVal, othVal).
  7753. *
  7754. * @static
  7755. * @memberOf _
  7756. * @since 4.0.0
  7757. * @category Array
  7758. * @param {...Array} [arrays] The arrays to inspect.
  7759. * @param {Function} [comparator] The comparator invoked per element.
  7760. * @returns {Array} Returns the new array of combined values.
  7761. * @example
  7762. *
  7763. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7764. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7765. *
  7766. * _.unionWith(objects, others, _.isEqual);
  7767. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7768. */
  7769. var unionWith = baseRest(function(arrays) {
  7770. var comparator = last(arrays);
  7771. comparator = typeof comparator == 'function' ? comparator : undefined;
  7772. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7773. });
  7774. /**
  7775. * Creates a duplicate-free version of an array, using
  7776. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7777. * for equality comparisons, in which only the first occurrence of each element
  7778. * is kept. The order of result values is determined by the order they occur
  7779. * in the array.
  7780. *
  7781. * @static
  7782. * @memberOf _
  7783. * @since 0.1.0
  7784. * @category Array
  7785. * @param {Array} array The array to inspect.
  7786. * @returns {Array} Returns the new duplicate free array.
  7787. * @example
  7788. *
  7789. * _.uniq([2, 1, 2]);
  7790. * // => [2, 1]
  7791. */
  7792. function uniq(array) {
  7793. return (array && array.length) ? baseUniq(array) : [];
  7794. }
  7795. /**
  7796. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7797. * invoked for each element in `array` to generate the criterion by which
  7798. * uniqueness is computed. The order of result values is determined by the
  7799. * order they occur in the array. The iteratee is invoked with one argument:
  7800. * (value).
  7801. *
  7802. * @static
  7803. * @memberOf _
  7804. * @since 4.0.0
  7805. * @category Array
  7806. * @param {Array} array The array to inspect.
  7807. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7808. * @returns {Array} Returns the new duplicate free array.
  7809. * @example
  7810. *
  7811. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7812. * // => [2.1, 1.2]
  7813. *
  7814. * // The `_.property` iteratee shorthand.
  7815. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7816. * // => [{ 'x': 1 }, { 'x': 2 }]
  7817. */
  7818. function uniqBy(array, iteratee) {
  7819. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7820. }
  7821. /**
  7822. * This method is like `_.uniq` except that it accepts `comparator` which
  7823. * is invoked to compare elements of `array`. The order of result values is
  7824. * determined by the order they occur in the array.The comparator is invoked
  7825. * with two arguments: (arrVal, othVal).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 4.0.0
  7830. * @category Array
  7831. * @param {Array} array The array to inspect.
  7832. * @param {Function} [comparator] The comparator invoked per element.
  7833. * @returns {Array} Returns the new duplicate free array.
  7834. * @example
  7835. *
  7836. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7837. *
  7838. * _.uniqWith(objects, _.isEqual);
  7839. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7840. */
  7841. function uniqWith(array, comparator) {
  7842. comparator = typeof comparator == 'function' ? comparator : undefined;
  7843. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7844. }
  7845. /**
  7846. * This method is like `_.zip` except that it accepts an array of grouped
  7847. * elements and creates an array regrouping the elements to their pre-zip
  7848. * configuration.
  7849. *
  7850. * @static
  7851. * @memberOf _
  7852. * @since 1.2.0
  7853. * @category Array
  7854. * @param {Array} array The array of grouped elements to process.
  7855. * @returns {Array} Returns the new array of regrouped elements.
  7856. * @example
  7857. *
  7858. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7859. * // => [['a', 1, true], ['b', 2, false]]
  7860. *
  7861. * _.unzip(zipped);
  7862. * // => [['a', 'b'], [1, 2], [true, false]]
  7863. */
  7864. function unzip(array) {
  7865. if (!(array && array.length)) {
  7866. return [];
  7867. }
  7868. var length = 0;
  7869. array = arrayFilter(array, function(group) {
  7870. if (isArrayLikeObject(group)) {
  7871. length = nativeMax(group.length, length);
  7872. return true;
  7873. }
  7874. });
  7875. return baseTimes(length, function(index) {
  7876. return arrayMap(array, baseProperty(index));
  7877. });
  7878. }
  7879. /**
  7880. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7881. * how regrouped values should be combined. The iteratee is invoked with the
  7882. * elements of each group: (...group).
  7883. *
  7884. * @static
  7885. * @memberOf _
  7886. * @since 3.8.0
  7887. * @category Array
  7888. * @param {Array} array The array of grouped elements to process.
  7889. * @param {Function} [iteratee=_.identity] The function to combine
  7890. * regrouped values.
  7891. * @returns {Array} Returns the new array of regrouped elements.
  7892. * @example
  7893. *
  7894. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7895. * // => [[1, 10, 100], [2, 20, 200]]
  7896. *
  7897. * _.unzipWith(zipped, _.add);
  7898. * // => [3, 30, 300]
  7899. */
  7900. function unzipWith(array, iteratee) {
  7901. if (!(array && array.length)) {
  7902. return [];
  7903. }
  7904. var result = unzip(array);
  7905. if (iteratee == null) {
  7906. return result;
  7907. }
  7908. return arrayMap(result, function(group) {
  7909. return apply(iteratee, undefined, group);
  7910. });
  7911. }
  7912. /**
  7913. * Creates an array excluding all given values using
  7914. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7915. * for equality comparisons.
  7916. *
  7917. * **Note:** Unlike `_.pull`, this method returns a new array.
  7918. *
  7919. * @static
  7920. * @memberOf _
  7921. * @since 0.1.0
  7922. * @category Array
  7923. * @param {Array} array The array to inspect.
  7924. * @param {...*} [values] The values to exclude.
  7925. * @returns {Array} Returns the new array of filtered values.
  7926. * @see _.difference, _.xor
  7927. * @example
  7928. *
  7929. * _.without([2, 1, 2, 3], 1, 2);
  7930. * // => [3]
  7931. */
  7932. var without = baseRest(function(array, values) {
  7933. return isArrayLikeObject(array)
  7934. ? baseDifference(array, values)
  7935. : [];
  7936. });
  7937. /**
  7938. * Creates an array of unique values that is the
  7939. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7940. * of the given arrays. The order of result values is determined by the order
  7941. * they occur in the arrays.
  7942. *
  7943. * @static
  7944. * @memberOf _
  7945. * @since 2.4.0
  7946. * @category Array
  7947. * @param {...Array} [arrays] The arrays to inspect.
  7948. * @returns {Array} Returns the new array of filtered values.
  7949. * @see _.difference, _.without
  7950. * @example
  7951. *
  7952. * _.xor([2, 1], [2, 3]);
  7953. * // => [1, 3]
  7954. */
  7955. var xor = baseRest(function(arrays) {
  7956. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7957. });
  7958. /**
  7959. * This method is like `_.xor` except that it accepts `iteratee` which is
  7960. * invoked for each element of each `arrays` to generate the criterion by
  7961. * which by which they're compared. The order of result values is determined
  7962. * by the order they occur in the arrays. The iteratee is invoked with one
  7963. * argument: (value).
  7964. *
  7965. * @static
  7966. * @memberOf _
  7967. * @since 4.0.0
  7968. * @category Array
  7969. * @param {...Array} [arrays] The arrays to inspect.
  7970. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7971. * @returns {Array} Returns the new array of filtered values.
  7972. * @example
  7973. *
  7974. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7975. * // => [1.2, 3.4]
  7976. *
  7977. * // The `_.property` iteratee shorthand.
  7978. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7979. * // => [{ 'x': 2 }]
  7980. */
  7981. var xorBy = baseRest(function(arrays) {
  7982. var iteratee = last(arrays);
  7983. if (isArrayLikeObject(iteratee)) {
  7984. iteratee = undefined;
  7985. }
  7986. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7987. });
  7988. /**
  7989. * This method is like `_.xor` except that it accepts `comparator` which is
  7990. * invoked to compare elements of `arrays`. The order of result values is
  7991. * determined by the order they occur in the arrays. The comparator is invoked
  7992. * with two arguments: (arrVal, othVal).
  7993. *
  7994. * @static
  7995. * @memberOf _
  7996. * @since 4.0.0
  7997. * @category Array
  7998. * @param {...Array} [arrays] The arrays to inspect.
  7999. * @param {Function} [comparator] The comparator invoked per element.
  8000. * @returns {Array} Returns the new array of filtered values.
  8001. * @example
  8002. *
  8003. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8004. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8005. *
  8006. * _.xorWith(objects, others, _.isEqual);
  8007. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8008. */
  8009. var xorWith = baseRest(function(arrays) {
  8010. var comparator = last(arrays);
  8011. comparator = typeof comparator == 'function' ? comparator : undefined;
  8012. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  8013. });
  8014. /**
  8015. * Creates an array of grouped elements, the first of which contains the
  8016. * first elements of the given arrays, the second of which contains the
  8017. * second elements of the given arrays, and so on.
  8018. *
  8019. * @static
  8020. * @memberOf _
  8021. * @since 0.1.0
  8022. * @category Array
  8023. * @param {...Array} [arrays] The arrays to process.
  8024. * @returns {Array} Returns the new array of grouped elements.
  8025. * @example
  8026. *
  8027. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8028. * // => [['a', 1, true], ['b', 2, false]]
  8029. */
  8030. var zip = baseRest(unzip);
  8031. /**
  8032. * This method is like `_.fromPairs` except that it accepts two arrays,
  8033. * one of property identifiers and one of corresponding values.
  8034. *
  8035. * @static
  8036. * @memberOf _
  8037. * @since 0.4.0
  8038. * @category Array
  8039. * @param {Array} [props=[]] The property identifiers.
  8040. * @param {Array} [values=[]] The property values.
  8041. * @returns {Object} Returns the new object.
  8042. * @example
  8043. *
  8044. * _.zipObject(['a', 'b'], [1, 2]);
  8045. * // => { 'a': 1, 'b': 2 }
  8046. */
  8047. function zipObject(props, values) {
  8048. return baseZipObject(props || [], values || [], assignValue);
  8049. }
  8050. /**
  8051. * This method is like `_.zipObject` except that it supports property paths.
  8052. *
  8053. * @static
  8054. * @memberOf _
  8055. * @since 4.1.0
  8056. * @category Array
  8057. * @param {Array} [props=[]] The property identifiers.
  8058. * @param {Array} [values=[]] The property values.
  8059. * @returns {Object} Returns the new object.
  8060. * @example
  8061. *
  8062. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8063. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8064. */
  8065. function zipObjectDeep(props, values) {
  8066. return baseZipObject(props || [], values || [], baseSet);
  8067. }
  8068. /**
  8069. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8070. * how grouped values should be combined. The iteratee is invoked with the
  8071. * elements of each group: (...group).
  8072. *
  8073. * @static
  8074. * @memberOf _
  8075. * @since 3.8.0
  8076. * @category Array
  8077. * @param {...Array} [arrays] The arrays to process.
  8078. * @param {Function} [iteratee=_.identity] The function to combine
  8079. * grouped values.
  8080. * @returns {Array} Returns the new array of grouped elements.
  8081. * @example
  8082. *
  8083. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8084. * return a + b + c;
  8085. * });
  8086. * // => [111, 222]
  8087. */
  8088. var zipWith = baseRest(function(arrays) {
  8089. var length = arrays.length,
  8090. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8091. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8092. return unzipWith(arrays, iteratee);
  8093. });
  8094. /*------------------------------------------------------------------------*/
  8095. /**
  8096. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8097. * chain sequences enabled. The result of such sequences must be unwrapped
  8098. * with `_#value`.
  8099. *
  8100. * @static
  8101. * @memberOf _
  8102. * @since 1.3.0
  8103. * @category Seq
  8104. * @param {*} value The value to wrap.
  8105. * @returns {Object} Returns the new `lodash` wrapper instance.
  8106. * @example
  8107. *
  8108. * var users = [
  8109. * { 'user': 'barney', 'age': 36 },
  8110. * { 'user': 'fred', 'age': 40 },
  8111. * { 'user': 'pebbles', 'age': 1 }
  8112. * ];
  8113. *
  8114. * var youngest = _
  8115. * .chain(users)
  8116. * .sortBy('age')
  8117. * .map(function(o) {
  8118. * return o.user + ' is ' + o.age;
  8119. * })
  8120. * .head()
  8121. * .value();
  8122. * // => 'pebbles is 1'
  8123. */
  8124. function chain(value) {
  8125. var result = lodash(value);
  8126. result.__chain__ = true;
  8127. return result;
  8128. }
  8129. /**
  8130. * This method invokes `interceptor` and returns `value`. The interceptor
  8131. * is invoked with one argument; (value). The purpose of this method is to
  8132. * "tap into" a method chain sequence in order to modify intermediate results.
  8133. *
  8134. * @static
  8135. * @memberOf _
  8136. * @since 0.1.0
  8137. * @category Seq
  8138. * @param {*} value The value to provide to `interceptor`.
  8139. * @param {Function} interceptor The function to invoke.
  8140. * @returns {*} Returns `value`.
  8141. * @example
  8142. *
  8143. * _([1, 2, 3])
  8144. * .tap(function(array) {
  8145. * // Mutate input array.
  8146. * array.pop();
  8147. * })
  8148. * .reverse()
  8149. * .value();
  8150. * // => [2, 1]
  8151. */
  8152. function tap(value, interceptor) {
  8153. interceptor(value);
  8154. return value;
  8155. }
  8156. /**
  8157. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8158. * The purpose of this method is to "pass thru" values replacing intermediate
  8159. * results in a method chain sequence.
  8160. *
  8161. * @static
  8162. * @memberOf _
  8163. * @since 3.0.0
  8164. * @category Seq
  8165. * @param {*} value The value to provide to `interceptor`.
  8166. * @param {Function} interceptor The function to invoke.
  8167. * @returns {*} Returns the result of `interceptor`.
  8168. * @example
  8169. *
  8170. * _(' abc ')
  8171. * .chain()
  8172. * .trim()
  8173. * .thru(function(value) {
  8174. * return [value];
  8175. * })
  8176. * .value();
  8177. * // => ['abc']
  8178. */
  8179. function thru(value, interceptor) {
  8180. return interceptor(value);
  8181. }
  8182. /**
  8183. * This method is the wrapper version of `_.at`.
  8184. *
  8185. * @name at
  8186. * @memberOf _
  8187. * @since 1.0.0
  8188. * @category Seq
  8189. * @param {...(string|string[])} [paths] The property paths to pick.
  8190. * @returns {Object} Returns the new `lodash` wrapper instance.
  8191. * @example
  8192. *
  8193. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8194. *
  8195. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8196. * // => [3, 4]
  8197. */
  8198. var wrapperAt = flatRest(function(paths) {
  8199. var length = paths.length,
  8200. start = length ? paths[0] : 0,
  8201. value = this.__wrapped__,
  8202. interceptor = function(object) { return baseAt(object, paths); };
  8203. if (length > 1 || this.__actions__.length ||
  8204. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8205. return this.thru(interceptor);
  8206. }
  8207. value = value.slice(start, +start + (length ? 1 : 0));
  8208. value.__actions__.push({
  8209. 'func': thru,
  8210. 'args': [interceptor],
  8211. 'thisArg': undefined
  8212. });
  8213. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8214. if (length && !array.length) {
  8215. array.push(undefined);
  8216. }
  8217. return array;
  8218. });
  8219. });
  8220. /**
  8221. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8222. *
  8223. * @name chain
  8224. * @memberOf _
  8225. * @since 0.1.0
  8226. * @category Seq
  8227. * @returns {Object} Returns the new `lodash` wrapper instance.
  8228. * @example
  8229. *
  8230. * var users = [
  8231. * { 'user': 'barney', 'age': 36 },
  8232. * { 'user': 'fred', 'age': 40 }
  8233. * ];
  8234. *
  8235. * // A sequence without explicit chaining.
  8236. * _(users).head();
  8237. * // => { 'user': 'barney', 'age': 36 }
  8238. *
  8239. * // A sequence with explicit chaining.
  8240. * _(users)
  8241. * .chain()
  8242. * .head()
  8243. * .pick('user')
  8244. * .value();
  8245. * // => { 'user': 'barney' }
  8246. */
  8247. function wrapperChain() {
  8248. return chain(this);
  8249. }
  8250. /**
  8251. * Executes the chain sequence and returns the wrapped result.
  8252. *
  8253. * @name commit
  8254. * @memberOf _
  8255. * @since 3.2.0
  8256. * @category Seq
  8257. * @returns {Object} Returns the new `lodash` wrapper instance.
  8258. * @example
  8259. *
  8260. * var array = [1, 2];
  8261. * var wrapped = _(array).push(3);
  8262. *
  8263. * console.log(array);
  8264. * // => [1, 2]
  8265. *
  8266. * wrapped = wrapped.commit();
  8267. * console.log(array);
  8268. * // => [1, 2, 3]
  8269. *
  8270. * wrapped.last();
  8271. * // => 3
  8272. *
  8273. * console.log(array);
  8274. * // => [1, 2, 3]
  8275. */
  8276. function wrapperCommit() {
  8277. return new LodashWrapper(this.value(), this.__chain__);
  8278. }
  8279. /**
  8280. * Gets the next value on a wrapped object following the
  8281. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8282. *
  8283. * @name next
  8284. * @memberOf _
  8285. * @since 4.0.0
  8286. * @category Seq
  8287. * @returns {Object} Returns the next iterator value.
  8288. * @example
  8289. *
  8290. * var wrapped = _([1, 2]);
  8291. *
  8292. * wrapped.next();
  8293. * // => { 'done': false, 'value': 1 }
  8294. *
  8295. * wrapped.next();
  8296. * // => { 'done': false, 'value': 2 }
  8297. *
  8298. * wrapped.next();
  8299. * // => { 'done': true, 'value': undefined }
  8300. */
  8301. function wrapperNext() {
  8302. if (this.__values__ === undefined) {
  8303. this.__values__ = toArray(this.value());
  8304. }
  8305. var done = this.__index__ >= this.__values__.length,
  8306. value = done ? undefined : this.__values__[this.__index__++];
  8307. return { 'done': done, 'value': value };
  8308. }
  8309. /**
  8310. * Enables the wrapper to be iterable.
  8311. *
  8312. * @name Symbol.iterator
  8313. * @memberOf _
  8314. * @since 4.0.0
  8315. * @category Seq
  8316. * @returns {Object} Returns the wrapper object.
  8317. * @example
  8318. *
  8319. * var wrapped = _([1, 2]);
  8320. *
  8321. * wrapped[Symbol.iterator]() === wrapped;
  8322. * // => true
  8323. *
  8324. * Array.from(wrapped);
  8325. * // => [1, 2]
  8326. */
  8327. function wrapperToIterator() {
  8328. return this;
  8329. }
  8330. /**
  8331. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8332. *
  8333. * @name plant
  8334. * @memberOf _
  8335. * @since 3.2.0
  8336. * @category Seq
  8337. * @param {*} value The value to plant.
  8338. * @returns {Object} Returns the new `lodash` wrapper instance.
  8339. * @example
  8340. *
  8341. * function square(n) {
  8342. * return n * n;
  8343. * }
  8344. *
  8345. * var wrapped = _([1, 2]).map(square);
  8346. * var other = wrapped.plant([3, 4]);
  8347. *
  8348. * other.value();
  8349. * // => [9, 16]
  8350. *
  8351. * wrapped.value();
  8352. * // => [1, 4]
  8353. */
  8354. function wrapperPlant(value) {
  8355. var result,
  8356. parent = this;
  8357. while (parent instanceof baseLodash) {
  8358. var clone = wrapperClone(parent);
  8359. clone.__index__ = 0;
  8360. clone.__values__ = undefined;
  8361. if (result) {
  8362. previous.__wrapped__ = clone;
  8363. } else {
  8364. result = clone;
  8365. }
  8366. var previous = clone;
  8367. parent = parent.__wrapped__;
  8368. }
  8369. previous.__wrapped__ = value;
  8370. return result;
  8371. }
  8372. /**
  8373. * This method is the wrapper version of `_.reverse`.
  8374. *
  8375. * **Note:** This method mutates the wrapped array.
  8376. *
  8377. * @name reverse
  8378. * @memberOf _
  8379. * @since 0.1.0
  8380. * @category Seq
  8381. * @returns {Object} Returns the new `lodash` wrapper instance.
  8382. * @example
  8383. *
  8384. * var array = [1, 2, 3];
  8385. *
  8386. * _(array).reverse().value()
  8387. * // => [3, 2, 1]
  8388. *
  8389. * console.log(array);
  8390. * // => [3, 2, 1]
  8391. */
  8392. function wrapperReverse() {
  8393. var value = this.__wrapped__;
  8394. if (value instanceof LazyWrapper) {
  8395. var wrapped = value;
  8396. if (this.__actions__.length) {
  8397. wrapped = new LazyWrapper(this);
  8398. }
  8399. wrapped = wrapped.reverse();
  8400. wrapped.__actions__.push({
  8401. 'func': thru,
  8402. 'args': [reverse],
  8403. 'thisArg': undefined
  8404. });
  8405. return new LodashWrapper(wrapped, this.__chain__);
  8406. }
  8407. return this.thru(reverse);
  8408. }
  8409. /**
  8410. * Executes the chain sequence to resolve the unwrapped value.
  8411. *
  8412. * @name value
  8413. * @memberOf _
  8414. * @since 0.1.0
  8415. * @alias toJSON, valueOf
  8416. * @category Seq
  8417. * @returns {*} Returns the resolved unwrapped value.
  8418. * @example
  8419. *
  8420. * _([1, 2, 3]).value();
  8421. * // => [1, 2, 3]
  8422. */
  8423. function wrapperValue() {
  8424. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8425. }
  8426. /*------------------------------------------------------------------------*/
  8427. /**
  8428. * Creates an object composed of keys generated from the results of running
  8429. * each element of `collection` thru `iteratee`. The corresponding value of
  8430. * each key is the number of times the key was returned by `iteratee`. The
  8431. * iteratee is invoked with one argument: (value).
  8432. *
  8433. * @static
  8434. * @memberOf _
  8435. * @since 0.5.0
  8436. * @category Collection
  8437. * @param {Array|Object} collection The collection to iterate over.
  8438. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8439. * @returns {Object} Returns the composed aggregate object.
  8440. * @example
  8441. *
  8442. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8443. * // => { '4': 1, '6': 2 }
  8444. *
  8445. * // The `_.property` iteratee shorthand.
  8446. * _.countBy(['one', 'two', 'three'], 'length');
  8447. * // => { '3': 2, '5': 1 }
  8448. */
  8449. var countBy = createAggregator(function(result, value, key) {
  8450. if (hasOwnProperty.call(result, key)) {
  8451. ++result[key];
  8452. } else {
  8453. baseAssignValue(result, key, 1);
  8454. }
  8455. });
  8456. /**
  8457. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8458. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8459. * invoked with three arguments: (value, index|key, collection).
  8460. *
  8461. * **Note:** This method returns `true` for
  8462. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8463. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8464. * elements of empty collections.
  8465. *
  8466. * @static
  8467. * @memberOf _
  8468. * @since 0.1.0
  8469. * @category Collection
  8470. * @param {Array|Object} collection The collection to iterate over.
  8471. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8472. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8473. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8474. * else `false`.
  8475. * @example
  8476. *
  8477. * _.every([true, 1, null, 'yes'], Boolean);
  8478. * // => false
  8479. *
  8480. * var users = [
  8481. * { 'user': 'barney', 'age': 36, 'active': false },
  8482. * { 'user': 'fred', 'age': 40, 'active': false }
  8483. * ];
  8484. *
  8485. * // The `_.matches` iteratee shorthand.
  8486. * _.every(users, { 'user': 'barney', 'active': false });
  8487. * // => false
  8488. *
  8489. * // The `_.matchesProperty` iteratee shorthand.
  8490. * _.every(users, ['active', false]);
  8491. * // => true
  8492. *
  8493. * // The `_.property` iteratee shorthand.
  8494. * _.every(users, 'active');
  8495. * // => false
  8496. */
  8497. function every(collection, predicate, guard) {
  8498. var func = isArray(collection) ? arrayEvery : baseEvery;
  8499. if (guard && isIterateeCall(collection, predicate, guard)) {
  8500. predicate = undefined;
  8501. }
  8502. return func(collection, getIteratee(predicate, 3));
  8503. }
  8504. /**
  8505. * Iterates over elements of `collection`, returning an array of all elements
  8506. * `predicate` returns truthy for. The predicate is invoked with three
  8507. * arguments: (value, index|key, collection).
  8508. *
  8509. * **Note:** Unlike `_.remove`, this method returns a new array.
  8510. *
  8511. * @static
  8512. * @memberOf _
  8513. * @since 0.1.0
  8514. * @category Collection
  8515. * @param {Array|Object} collection The collection to iterate over.
  8516. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8517. * @returns {Array} Returns the new filtered array.
  8518. * @see _.reject
  8519. * @example
  8520. *
  8521. * var users = [
  8522. * { 'user': 'barney', 'age': 36, 'active': true },
  8523. * { 'user': 'fred', 'age': 40, 'active': false }
  8524. * ];
  8525. *
  8526. * _.filter(users, function(o) { return !o.active; });
  8527. * // => objects for ['fred']
  8528. *
  8529. * // The `_.matches` iteratee shorthand.
  8530. * _.filter(users, { 'age': 36, 'active': true });
  8531. * // => objects for ['barney']
  8532. *
  8533. * // The `_.matchesProperty` iteratee shorthand.
  8534. * _.filter(users, ['active', false]);
  8535. * // => objects for ['fred']
  8536. *
  8537. * // The `_.property` iteratee shorthand.
  8538. * _.filter(users, 'active');
  8539. * // => objects for ['barney']
  8540. *
  8541. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  8542. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  8543. * // => objects for ['fred', 'barney']
  8544. */
  8545. function filter(collection, predicate) {
  8546. var func = isArray(collection) ? arrayFilter : baseFilter;
  8547. return func(collection, getIteratee(predicate, 3));
  8548. }
  8549. /**
  8550. * Iterates over elements of `collection`, returning the first element
  8551. * `predicate` returns truthy for. The predicate is invoked with three
  8552. * arguments: (value, index|key, collection).
  8553. *
  8554. * @static
  8555. * @memberOf _
  8556. * @since 0.1.0
  8557. * @category Collection
  8558. * @param {Array|Object} collection The collection to inspect.
  8559. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8560. * @param {number} [fromIndex=0] The index to search from.
  8561. * @returns {*} Returns the matched element, else `undefined`.
  8562. * @example
  8563. *
  8564. * var users = [
  8565. * { 'user': 'barney', 'age': 36, 'active': true },
  8566. * { 'user': 'fred', 'age': 40, 'active': false },
  8567. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8568. * ];
  8569. *
  8570. * _.find(users, function(o) { return o.age < 40; });
  8571. * // => object for 'barney'
  8572. *
  8573. * // The `_.matches` iteratee shorthand.
  8574. * _.find(users, { 'age': 1, 'active': true });
  8575. * // => object for 'pebbles'
  8576. *
  8577. * // The `_.matchesProperty` iteratee shorthand.
  8578. * _.find(users, ['active', false]);
  8579. * // => object for 'fred'
  8580. *
  8581. * // The `_.property` iteratee shorthand.
  8582. * _.find(users, 'active');
  8583. * // => object for 'barney'
  8584. */
  8585. var find = createFind(findIndex);
  8586. /**
  8587. * This method is like `_.find` except that it iterates over elements of
  8588. * `collection` from right to left.
  8589. *
  8590. * @static
  8591. * @memberOf _
  8592. * @since 2.0.0
  8593. * @category Collection
  8594. * @param {Array|Object} collection The collection to inspect.
  8595. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8596. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8597. * @returns {*} Returns the matched element, else `undefined`.
  8598. * @example
  8599. *
  8600. * _.findLast([1, 2, 3, 4], function(n) {
  8601. * return n % 2 == 1;
  8602. * });
  8603. * // => 3
  8604. */
  8605. var findLast = createFind(findLastIndex);
  8606. /**
  8607. * Creates a flattened array of values by running each element in `collection`
  8608. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8609. * with three arguments: (value, index|key, collection).
  8610. *
  8611. * @static
  8612. * @memberOf _
  8613. * @since 4.0.0
  8614. * @category Collection
  8615. * @param {Array|Object} collection The collection to iterate over.
  8616. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8617. * @returns {Array} Returns the new flattened array.
  8618. * @example
  8619. *
  8620. * function duplicate(n) {
  8621. * return [n, n];
  8622. * }
  8623. *
  8624. * _.flatMap([1, 2], duplicate);
  8625. * // => [1, 1, 2, 2]
  8626. */
  8627. function flatMap(collection, iteratee) {
  8628. return baseFlatten(map(collection, iteratee), 1);
  8629. }
  8630. /**
  8631. * This method is like `_.flatMap` except that it recursively flattens the
  8632. * mapped results.
  8633. *
  8634. * @static
  8635. * @memberOf _
  8636. * @since 4.7.0
  8637. * @category Collection
  8638. * @param {Array|Object} collection The collection to iterate over.
  8639. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8640. * @returns {Array} Returns the new flattened array.
  8641. * @example
  8642. *
  8643. * function duplicate(n) {
  8644. * return [[[n, n]]];
  8645. * }
  8646. *
  8647. * _.flatMapDeep([1, 2], duplicate);
  8648. * // => [1, 1, 2, 2]
  8649. */
  8650. function flatMapDeep(collection, iteratee) {
  8651. return baseFlatten(map(collection, iteratee), INFINITY);
  8652. }
  8653. /**
  8654. * This method is like `_.flatMap` except that it recursively flattens the
  8655. * mapped results up to `depth` times.
  8656. *
  8657. * @static
  8658. * @memberOf _
  8659. * @since 4.7.0
  8660. * @category Collection
  8661. * @param {Array|Object} collection The collection to iterate over.
  8662. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8663. * @param {number} [depth=1] The maximum recursion depth.
  8664. * @returns {Array} Returns the new flattened array.
  8665. * @example
  8666. *
  8667. * function duplicate(n) {
  8668. * return [[[n, n]]];
  8669. * }
  8670. *
  8671. * _.flatMapDepth([1, 2], duplicate, 2);
  8672. * // => [[1, 1], [2, 2]]
  8673. */
  8674. function flatMapDepth(collection, iteratee, depth) {
  8675. depth = depth === undefined ? 1 : toInteger(depth);
  8676. return baseFlatten(map(collection, iteratee), depth);
  8677. }
  8678. /**
  8679. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8680. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8681. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8682. *
  8683. * **Note:** As with other "Collections" methods, objects with a "length"
  8684. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8685. * or `_.forOwn` for object iteration.
  8686. *
  8687. * @static
  8688. * @memberOf _
  8689. * @since 0.1.0
  8690. * @alias each
  8691. * @category Collection
  8692. * @param {Array|Object} collection The collection to iterate over.
  8693. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8694. * @returns {Array|Object} Returns `collection`.
  8695. * @see _.forEachRight
  8696. * @example
  8697. *
  8698. * _.forEach([1, 2], function(value) {
  8699. * console.log(value);
  8700. * });
  8701. * // => Logs `1` then `2`.
  8702. *
  8703. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8704. * console.log(key);
  8705. * });
  8706. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8707. */
  8708. function forEach(collection, iteratee) {
  8709. var func = isArray(collection) ? arrayEach : baseEach;
  8710. return func(collection, getIteratee(iteratee, 3));
  8711. }
  8712. /**
  8713. * This method is like `_.forEach` except that it iterates over elements of
  8714. * `collection` from right to left.
  8715. *
  8716. * @static
  8717. * @memberOf _
  8718. * @since 2.0.0
  8719. * @alias eachRight
  8720. * @category Collection
  8721. * @param {Array|Object} collection The collection to iterate over.
  8722. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8723. * @returns {Array|Object} Returns `collection`.
  8724. * @see _.forEach
  8725. * @example
  8726. *
  8727. * _.forEachRight([1, 2], function(value) {
  8728. * console.log(value);
  8729. * });
  8730. * // => Logs `2` then `1`.
  8731. */
  8732. function forEachRight(collection, iteratee) {
  8733. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8734. return func(collection, getIteratee(iteratee, 3));
  8735. }
  8736. /**
  8737. * Creates an object composed of keys generated from the results of running
  8738. * each element of `collection` thru `iteratee`. The order of grouped values
  8739. * is determined by the order they occur in `collection`. The corresponding
  8740. * value of each key is an array of elements responsible for generating the
  8741. * key. The iteratee is invoked with one argument: (value).
  8742. *
  8743. * @static
  8744. * @memberOf _
  8745. * @since 0.1.0
  8746. * @category Collection
  8747. * @param {Array|Object} collection The collection to iterate over.
  8748. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8749. * @returns {Object} Returns the composed aggregate object.
  8750. * @example
  8751. *
  8752. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8753. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8754. *
  8755. * // The `_.property` iteratee shorthand.
  8756. * _.groupBy(['one', 'two', 'three'], 'length');
  8757. * // => { '3': ['one', 'two'], '5': ['three'] }
  8758. */
  8759. var groupBy = createAggregator(function(result, value, key) {
  8760. if (hasOwnProperty.call(result, key)) {
  8761. result[key].push(value);
  8762. } else {
  8763. baseAssignValue(result, key, [value]);
  8764. }
  8765. });
  8766. /**
  8767. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8768. * checked for a substring of `value`, otherwise
  8769. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8770. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8771. * the offset from the end of `collection`.
  8772. *
  8773. * @static
  8774. * @memberOf _
  8775. * @since 0.1.0
  8776. * @category Collection
  8777. * @param {Array|Object|string} collection The collection to inspect.
  8778. * @param {*} value The value to search for.
  8779. * @param {number} [fromIndex=0] The index to search from.
  8780. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8781. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8782. * @example
  8783. *
  8784. * _.includes([1, 2, 3], 1);
  8785. * // => true
  8786. *
  8787. * _.includes([1, 2, 3], 1, 2);
  8788. * // => false
  8789. *
  8790. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8791. * // => true
  8792. *
  8793. * _.includes('abcd', 'bc');
  8794. * // => true
  8795. */
  8796. function includes(collection, value, fromIndex, guard) {
  8797. collection = isArrayLike(collection) ? collection : values(collection);
  8798. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8799. var length = collection.length;
  8800. if (fromIndex < 0) {
  8801. fromIndex = nativeMax(length + fromIndex, 0);
  8802. }
  8803. return isString(collection)
  8804. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8805. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8806. }
  8807. /**
  8808. * Invokes the method at `path` of each element in `collection`, returning
  8809. * an array of the results of each invoked method. Any additional arguments
  8810. * are provided to each invoked method. If `path` is a function, it's invoked
  8811. * for, and `this` bound to, each element in `collection`.
  8812. *
  8813. * @static
  8814. * @memberOf _
  8815. * @since 4.0.0
  8816. * @category Collection
  8817. * @param {Array|Object} collection The collection to iterate over.
  8818. * @param {Array|Function|string} path The path of the method to invoke or
  8819. * the function invoked per iteration.
  8820. * @param {...*} [args] The arguments to invoke each method with.
  8821. * @returns {Array} Returns the array of results.
  8822. * @example
  8823. *
  8824. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8825. * // => [[1, 5, 7], [1, 2, 3]]
  8826. *
  8827. * _.invokeMap([123, 456], String.prototype.split, '');
  8828. * // => [['1', '2', '3'], ['4', '5', '6']]
  8829. */
  8830. var invokeMap = baseRest(function(collection, path, args) {
  8831. var index = -1,
  8832. isFunc = typeof path == 'function',
  8833. result = isArrayLike(collection) ? Array(collection.length) : [];
  8834. baseEach(collection, function(value) {
  8835. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8836. });
  8837. return result;
  8838. });
  8839. /**
  8840. * Creates an object composed of keys generated from the results of running
  8841. * each element of `collection` thru `iteratee`. The corresponding value of
  8842. * each key is the last element responsible for generating the key. The
  8843. * iteratee is invoked with one argument: (value).
  8844. *
  8845. * @static
  8846. * @memberOf _
  8847. * @since 4.0.0
  8848. * @category Collection
  8849. * @param {Array|Object} collection The collection to iterate over.
  8850. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8851. * @returns {Object} Returns the composed aggregate object.
  8852. * @example
  8853. *
  8854. * var array = [
  8855. * { 'dir': 'left', 'code': 97 },
  8856. * { 'dir': 'right', 'code': 100 }
  8857. * ];
  8858. *
  8859. * _.keyBy(array, function(o) {
  8860. * return String.fromCharCode(o.code);
  8861. * });
  8862. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8863. *
  8864. * _.keyBy(array, 'dir');
  8865. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8866. */
  8867. var keyBy = createAggregator(function(result, value, key) {
  8868. baseAssignValue(result, key, value);
  8869. });
  8870. /**
  8871. * Creates an array of values by running each element in `collection` thru
  8872. * `iteratee`. The iteratee is invoked with three arguments:
  8873. * (value, index|key, collection).
  8874. *
  8875. * Many lodash methods are guarded to work as iteratees for methods like
  8876. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8877. *
  8878. * The guarded methods are:
  8879. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8880. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8881. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8882. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8883. *
  8884. * @static
  8885. * @memberOf _
  8886. * @since 0.1.0
  8887. * @category Collection
  8888. * @param {Array|Object} collection The collection to iterate over.
  8889. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8890. * @returns {Array} Returns the new mapped array.
  8891. * @example
  8892. *
  8893. * function square(n) {
  8894. * return n * n;
  8895. * }
  8896. *
  8897. * _.map([4, 8], square);
  8898. * // => [16, 64]
  8899. *
  8900. * _.map({ 'a': 4, 'b': 8 }, square);
  8901. * // => [16, 64] (iteration order is not guaranteed)
  8902. *
  8903. * var users = [
  8904. * { 'user': 'barney' },
  8905. * { 'user': 'fred' }
  8906. * ];
  8907. *
  8908. * // The `_.property` iteratee shorthand.
  8909. * _.map(users, 'user');
  8910. * // => ['barney', 'fred']
  8911. */
  8912. function map(collection, iteratee) {
  8913. var func = isArray(collection) ? arrayMap : baseMap;
  8914. return func(collection, getIteratee(iteratee, 3));
  8915. }
  8916. /**
  8917. * This method is like `_.sortBy` except that it allows specifying the sort
  8918. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8919. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8920. * descending or "asc" for ascending sort order of corresponding values.
  8921. *
  8922. * @static
  8923. * @memberOf _
  8924. * @since 4.0.0
  8925. * @category Collection
  8926. * @param {Array|Object} collection The collection to iterate over.
  8927. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8928. * The iteratees to sort by.
  8929. * @param {string[]} [orders] The sort orders of `iteratees`.
  8930. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8931. * @returns {Array} Returns the new sorted array.
  8932. * @example
  8933. *
  8934. * var users = [
  8935. * { 'user': 'fred', 'age': 48 },
  8936. * { 'user': 'barney', 'age': 34 },
  8937. * { 'user': 'fred', 'age': 40 },
  8938. * { 'user': 'barney', 'age': 36 }
  8939. * ];
  8940. *
  8941. * // Sort by `user` in ascending order and by `age` in descending order.
  8942. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8943. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8944. */
  8945. function orderBy(collection, iteratees, orders, guard) {
  8946. if (collection == null) {
  8947. return [];
  8948. }
  8949. if (!isArray(iteratees)) {
  8950. iteratees = iteratees == null ? [] : [iteratees];
  8951. }
  8952. orders = guard ? undefined : orders;
  8953. if (!isArray(orders)) {
  8954. orders = orders == null ? [] : [orders];
  8955. }
  8956. return baseOrderBy(collection, iteratees, orders);
  8957. }
  8958. /**
  8959. * Creates an array of elements split into two groups, the first of which
  8960. * contains elements `predicate` returns truthy for, the second of which
  8961. * contains elements `predicate` returns falsey for. The predicate is
  8962. * invoked with one argument: (value).
  8963. *
  8964. * @static
  8965. * @memberOf _
  8966. * @since 3.0.0
  8967. * @category Collection
  8968. * @param {Array|Object} collection The collection to iterate over.
  8969. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8970. * @returns {Array} Returns the array of grouped elements.
  8971. * @example
  8972. *
  8973. * var users = [
  8974. * { 'user': 'barney', 'age': 36, 'active': false },
  8975. * { 'user': 'fred', 'age': 40, 'active': true },
  8976. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8977. * ];
  8978. *
  8979. * _.partition(users, function(o) { return o.active; });
  8980. * // => objects for [['fred'], ['barney', 'pebbles']]
  8981. *
  8982. * // The `_.matches` iteratee shorthand.
  8983. * _.partition(users, { 'age': 1, 'active': false });
  8984. * // => objects for [['pebbles'], ['barney', 'fred']]
  8985. *
  8986. * // The `_.matchesProperty` iteratee shorthand.
  8987. * _.partition(users, ['active', false]);
  8988. * // => objects for [['barney', 'pebbles'], ['fred']]
  8989. *
  8990. * // The `_.property` iteratee shorthand.
  8991. * _.partition(users, 'active');
  8992. * // => objects for [['fred'], ['barney', 'pebbles']]
  8993. */
  8994. var partition = createAggregator(function(result, value, key) {
  8995. result[key ? 0 : 1].push(value);
  8996. }, function() { return [[], []]; });
  8997. /**
  8998. * Reduces `collection` to a value which is the accumulated result of running
  8999. * each element in `collection` thru `iteratee`, where each successive
  9000. * invocation is supplied the return value of the previous. If `accumulator`
  9001. * is not given, the first element of `collection` is used as the initial
  9002. * value. The iteratee is invoked with four arguments:
  9003. * (accumulator, value, index|key, collection).
  9004. *
  9005. * Many lodash methods are guarded to work as iteratees for methods like
  9006. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9007. *
  9008. * The guarded methods are:
  9009. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9010. * and `sortBy`
  9011. *
  9012. * @static
  9013. * @memberOf _
  9014. * @since 0.1.0
  9015. * @category Collection
  9016. * @param {Array|Object} collection The collection to iterate over.
  9017. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9018. * @param {*} [accumulator] The initial value.
  9019. * @returns {*} Returns the accumulated value.
  9020. * @see _.reduceRight
  9021. * @example
  9022. *
  9023. * _.reduce([1, 2], function(sum, n) {
  9024. * return sum + n;
  9025. * }, 0);
  9026. * // => 3
  9027. *
  9028. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9029. * (result[value] || (result[value] = [])).push(key);
  9030. * return result;
  9031. * }, {});
  9032. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9033. */
  9034. function reduce(collection, iteratee, accumulator) {
  9035. var func = isArray(collection) ? arrayReduce : baseReduce,
  9036. initAccum = arguments.length < 3;
  9037. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9038. }
  9039. /**
  9040. * This method is like `_.reduce` except that it iterates over elements of
  9041. * `collection` from right to left.
  9042. *
  9043. * @static
  9044. * @memberOf _
  9045. * @since 0.1.0
  9046. * @category Collection
  9047. * @param {Array|Object} collection The collection to iterate over.
  9048. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9049. * @param {*} [accumulator] The initial value.
  9050. * @returns {*} Returns the accumulated value.
  9051. * @see _.reduce
  9052. * @example
  9053. *
  9054. * var array = [[0, 1], [2, 3], [4, 5]];
  9055. *
  9056. * _.reduceRight(array, function(flattened, other) {
  9057. * return flattened.concat(other);
  9058. * }, []);
  9059. * // => [4, 5, 2, 3, 0, 1]
  9060. */
  9061. function reduceRight(collection, iteratee, accumulator) {
  9062. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9063. initAccum = arguments.length < 3;
  9064. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9065. }
  9066. /**
  9067. * The opposite of `_.filter`; this method returns the elements of `collection`
  9068. * that `predicate` does **not** return truthy for.
  9069. *
  9070. * @static
  9071. * @memberOf _
  9072. * @since 0.1.0
  9073. * @category Collection
  9074. * @param {Array|Object} collection The collection to iterate over.
  9075. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9076. * @returns {Array} Returns the new filtered array.
  9077. * @see _.filter
  9078. * @example
  9079. *
  9080. * var users = [
  9081. * { 'user': 'barney', 'age': 36, 'active': false },
  9082. * { 'user': 'fred', 'age': 40, 'active': true }
  9083. * ];
  9084. *
  9085. * _.reject(users, function(o) { return !o.active; });
  9086. * // => objects for ['fred']
  9087. *
  9088. * // The `_.matches` iteratee shorthand.
  9089. * _.reject(users, { 'age': 40, 'active': true });
  9090. * // => objects for ['barney']
  9091. *
  9092. * // The `_.matchesProperty` iteratee shorthand.
  9093. * _.reject(users, ['active', false]);
  9094. * // => objects for ['fred']
  9095. *
  9096. * // The `_.property` iteratee shorthand.
  9097. * _.reject(users, 'active');
  9098. * // => objects for ['barney']
  9099. */
  9100. function reject(collection, predicate) {
  9101. var func = isArray(collection) ? arrayFilter : baseFilter;
  9102. return func(collection, negate(getIteratee(predicate, 3)));
  9103. }
  9104. /**
  9105. * Gets a random element from `collection`.
  9106. *
  9107. * @static
  9108. * @memberOf _
  9109. * @since 2.0.0
  9110. * @category Collection
  9111. * @param {Array|Object} collection The collection to sample.
  9112. * @returns {*} Returns the random element.
  9113. * @example
  9114. *
  9115. * _.sample([1, 2, 3, 4]);
  9116. * // => 2
  9117. */
  9118. function sample(collection) {
  9119. var func = isArray(collection) ? arraySample : baseSample;
  9120. return func(collection);
  9121. }
  9122. /**
  9123. * Gets `n` random elements at unique keys from `collection` up to the
  9124. * size of `collection`.
  9125. *
  9126. * @static
  9127. * @memberOf _
  9128. * @since 4.0.0
  9129. * @category Collection
  9130. * @param {Array|Object} collection The collection to sample.
  9131. * @param {number} [n=1] The number of elements to sample.
  9132. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9133. * @returns {Array} Returns the random elements.
  9134. * @example
  9135. *
  9136. * _.sampleSize([1, 2, 3], 2);
  9137. * // => [3, 1]
  9138. *
  9139. * _.sampleSize([1, 2, 3], 4);
  9140. * // => [2, 3, 1]
  9141. */
  9142. function sampleSize(collection, n, guard) {
  9143. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9144. n = 1;
  9145. } else {
  9146. n = toInteger(n);
  9147. }
  9148. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9149. return func(collection, n);
  9150. }
  9151. /**
  9152. * Creates an array of shuffled values, using a version of the
  9153. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9154. *
  9155. * @static
  9156. * @memberOf _
  9157. * @since 0.1.0
  9158. * @category Collection
  9159. * @param {Array|Object} collection The collection to shuffle.
  9160. * @returns {Array} Returns the new shuffled array.
  9161. * @example
  9162. *
  9163. * _.shuffle([1, 2, 3, 4]);
  9164. * // => [4, 1, 3, 2]
  9165. */
  9166. function shuffle(collection) {
  9167. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9168. return func(collection);
  9169. }
  9170. /**
  9171. * Gets the size of `collection` by returning its length for array-like
  9172. * values or the number of own enumerable string keyed properties for objects.
  9173. *
  9174. * @static
  9175. * @memberOf _
  9176. * @since 0.1.0
  9177. * @category Collection
  9178. * @param {Array|Object|string} collection The collection to inspect.
  9179. * @returns {number} Returns the collection size.
  9180. * @example
  9181. *
  9182. * _.size([1, 2, 3]);
  9183. * // => 3
  9184. *
  9185. * _.size({ 'a': 1, 'b': 2 });
  9186. * // => 2
  9187. *
  9188. * _.size('pebbles');
  9189. * // => 7
  9190. */
  9191. function size(collection) {
  9192. if (collection == null) {
  9193. return 0;
  9194. }
  9195. if (isArrayLike(collection)) {
  9196. return isString(collection) ? stringSize(collection) : collection.length;
  9197. }
  9198. var tag = getTag(collection);
  9199. if (tag == mapTag || tag == setTag) {
  9200. return collection.size;
  9201. }
  9202. return baseKeys(collection).length;
  9203. }
  9204. /**
  9205. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9206. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9207. * invoked with three arguments: (value, index|key, collection).
  9208. *
  9209. * @static
  9210. * @memberOf _
  9211. * @since 0.1.0
  9212. * @category Collection
  9213. * @param {Array|Object} collection The collection to iterate over.
  9214. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9215. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9216. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9217. * else `false`.
  9218. * @example
  9219. *
  9220. * _.some([null, 0, 'yes', false], Boolean);
  9221. * // => true
  9222. *
  9223. * var users = [
  9224. * { 'user': 'barney', 'active': true },
  9225. * { 'user': 'fred', 'active': false }
  9226. * ];
  9227. *
  9228. * // The `_.matches` iteratee shorthand.
  9229. * _.some(users, { 'user': 'barney', 'active': false });
  9230. * // => false
  9231. *
  9232. * // The `_.matchesProperty` iteratee shorthand.
  9233. * _.some(users, ['active', false]);
  9234. * // => true
  9235. *
  9236. * // The `_.property` iteratee shorthand.
  9237. * _.some(users, 'active');
  9238. * // => true
  9239. */
  9240. function some(collection, predicate, guard) {
  9241. var func = isArray(collection) ? arraySome : baseSome;
  9242. if (guard && isIterateeCall(collection, predicate, guard)) {
  9243. predicate = undefined;
  9244. }
  9245. return func(collection, getIteratee(predicate, 3));
  9246. }
  9247. /**
  9248. * Creates an array of elements, sorted in ascending order by the results of
  9249. * running each element in a collection thru each iteratee. This method
  9250. * performs a stable sort, that is, it preserves the original sort order of
  9251. * equal elements. The iteratees are invoked with one argument: (value).
  9252. *
  9253. * @static
  9254. * @memberOf _
  9255. * @since 0.1.0
  9256. * @category Collection
  9257. * @param {Array|Object} collection The collection to iterate over.
  9258. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9259. * The iteratees to sort by.
  9260. * @returns {Array} Returns the new sorted array.
  9261. * @example
  9262. *
  9263. * var users = [
  9264. * { 'user': 'fred', 'age': 48 },
  9265. * { 'user': 'barney', 'age': 36 },
  9266. * { 'user': 'fred', 'age': 30 },
  9267. * { 'user': 'barney', 'age': 34 }
  9268. * ];
  9269. *
  9270. * _.sortBy(users, [function(o) { return o.user; }]);
  9271. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  9272. *
  9273. * _.sortBy(users, ['user', 'age']);
  9274. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  9275. */
  9276. var sortBy = baseRest(function(collection, iteratees) {
  9277. if (collection == null) {
  9278. return [];
  9279. }
  9280. var length = iteratees.length;
  9281. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9282. iteratees = [];
  9283. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9284. iteratees = [iteratees[0]];
  9285. }
  9286. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9287. });
  9288. /*------------------------------------------------------------------------*/
  9289. /**
  9290. * Gets the timestamp of the number of milliseconds that have elapsed since
  9291. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9292. *
  9293. * @static
  9294. * @memberOf _
  9295. * @since 2.4.0
  9296. * @category Date
  9297. * @returns {number} Returns the timestamp.
  9298. * @example
  9299. *
  9300. * _.defer(function(stamp) {
  9301. * console.log(_.now() - stamp);
  9302. * }, _.now());
  9303. * // => Logs the number of milliseconds it took for the deferred invocation.
  9304. */
  9305. var now = ctxNow || function() {
  9306. return root.Date.now();
  9307. };
  9308. /*------------------------------------------------------------------------*/
  9309. /**
  9310. * The opposite of `_.before`; this method creates a function that invokes
  9311. * `func` once it's called `n` or more times.
  9312. *
  9313. * @static
  9314. * @memberOf _
  9315. * @since 0.1.0
  9316. * @category Function
  9317. * @param {number} n The number of calls before `func` is invoked.
  9318. * @param {Function} func The function to restrict.
  9319. * @returns {Function} Returns the new restricted function.
  9320. * @example
  9321. *
  9322. * var saves = ['profile', 'settings'];
  9323. *
  9324. * var done = _.after(saves.length, function() {
  9325. * console.log('done saving!');
  9326. * });
  9327. *
  9328. * _.forEach(saves, function(type) {
  9329. * asyncSave({ 'type': type, 'complete': done });
  9330. * });
  9331. * // => Logs 'done saving!' after the two async saves have completed.
  9332. */
  9333. function after(n, func) {
  9334. if (typeof func != 'function') {
  9335. throw new TypeError(FUNC_ERROR_TEXT);
  9336. }
  9337. n = toInteger(n);
  9338. return function() {
  9339. if (--n < 1) {
  9340. return func.apply(this, arguments);
  9341. }
  9342. };
  9343. }
  9344. /**
  9345. * Creates a function that invokes `func`, with up to `n` arguments,
  9346. * ignoring any additional arguments.
  9347. *
  9348. * @static
  9349. * @memberOf _
  9350. * @since 3.0.0
  9351. * @category Function
  9352. * @param {Function} func The function to cap arguments for.
  9353. * @param {number} [n=func.length] The arity cap.
  9354. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9355. * @returns {Function} Returns the new capped function.
  9356. * @example
  9357. *
  9358. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9359. * // => [6, 8, 10]
  9360. */
  9361. function ary(func, n, guard) {
  9362. n = guard ? undefined : n;
  9363. n = (func && n == null) ? func.length : n;
  9364. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9365. }
  9366. /**
  9367. * Creates a function that invokes `func`, with the `this` binding and arguments
  9368. * of the created function, while it's called less than `n` times. Subsequent
  9369. * calls to the created function return the result of the last `func` invocation.
  9370. *
  9371. * @static
  9372. * @memberOf _
  9373. * @since 3.0.0
  9374. * @category Function
  9375. * @param {number} n The number of calls at which `func` is no longer invoked.
  9376. * @param {Function} func The function to restrict.
  9377. * @returns {Function} Returns the new restricted function.
  9378. * @example
  9379. *
  9380. * jQuery(element).on('click', _.before(5, addContactToList));
  9381. * // => Allows adding up to 4 contacts to the list.
  9382. */
  9383. function before(n, func) {
  9384. var result;
  9385. if (typeof func != 'function') {
  9386. throw new TypeError(FUNC_ERROR_TEXT);
  9387. }
  9388. n = toInteger(n);
  9389. return function() {
  9390. if (--n > 0) {
  9391. result = func.apply(this, arguments);
  9392. }
  9393. if (n <= 1) {
  9394. func = undefined;
  9395. }
  9396. return result;
  9397. };
  9398. }
  9399. /**
  9400. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9401. * and `partials` prepended to the arguments it receives.
  9402. *
  9403. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9404. * may be used as a placeholder for partially applied arguments.
  9405. *
  9406. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9407. * property of bound functions.
  9408. *
  9409. * @static
  9410. * @memberOf _
  9411. * @since 0.1.0
  9412. * @category Function
  9413. * @param {Function} func The function to bind.
  9414. * @param {*} thisArg The `this` binding of `func`.
  9415. * @param {...*} [partials] The arguments to be partially applied.
  9416. * @returns {Function} Returns the new bound function.
  9417. * @example
  9418. *
  9419. * function greet(greeting, punctuation) {
  9420. * return greeting + ' ' + this.user + punctuation;
  9421. * }
  9422. *
  9423. * var object = { 'user': 'fred' };
  9424. *
  9425. * var bound = _.bind(greet, object, 'hi');
  9426. * bound('!');
  9427. * // => 'hi fred!'
  9428. *
  9429. * // Bound with placeholders.
  9430. * var bound = _.bind(greet, object, _, '!');
  9431. * bound('hi');
  9432. * // => 'hi fred!'
  9433. */
  9434. var bind = baseRest(function(func, thisArg, partials) {
  9435. var bitmask = WRAP_BIND_FLAG;
  9436. if (partials.length) {
  9437. var holders = replaceHolders(partials, getHolder(bind));
  9438. bitmask |= WRAP_PARTIAL_FLAG;
  9439. }
  9440. return createWrap(func, bitmask, thisArg, partials, holders);
  9441. });
  9442. /**
  9443. * Creates a function that invokes the method at `object[key]` with `partials`
  9444. * prepended to the arguments it receives.
  9445. *
  9446. * This method differs from `_.bind` by allowing bound functions to reference
  9447. * methods that may be redefined or don't yet exist. See
  9448. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9449. * for more details.
  9450. *
  9451. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9452. * builds, may be used as a placeholder for partially applied arguments.
  9453. *
  9454. * @static
  9455. * @memberOf _
  9456. * @since 0.10.0
  9457. * @category Function
  9458. * @param {Object} object The object to invoke the method on.
  9459. * @param {string} key The key of the method.
  9460. * @param {...*} [partials] The arguments to be partially applied.
  9461. * @returns {Function} Returns the new bound function.
  9462. * @example
  9463. *
  9464. * var object = {
  9465. * 'user': 'fred',
  9466. * 'greet': function(greeting, punctuation) {
  9467. * return greeting + ' ' + this.user + punctuation;
  9468. * }
  9469. * };
  9470. *
  9471. * var bound = _.bindKey(object, 'greet', 'hi');
  9472. * bound('!');
  9473. * // => 'hi fred!'
  9474. *
  9475. * object.greet = function(greeting, punctuation) {
  9476. * return greeting + 'ya ' + this.user + punctuation;
  9477. * };
  9478. *
  9479. * bound('!');
  9480. * // => 'hiya fred!'
  9481. *
  9482. * // Bound with placeholders.
  9483. * var bound = _.bindKey(object, 'greet', _, '!');
  9484. * bound('hi');
  9485. * // => 'hiya fred!'
  9486. */
  9487. var bindKey = baseRest(function(object, key, partials) {
  9488. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9489. if (partials.length) {
  9490. var holders = replaceHolders(partials, getHolder(bindKey));
  9491. bitmask |= WRAP_PARTIAL_FLAG;
  9492. }
  9493. return createWrap(key, bitmask, object, partials, holders);
  9494. });
  9495. /**
  9496. * Creates a function that accepts arguments of `func` and either invokes
  9497. * `func` returning its result, if at least `arity` number of arguments have
  9498. * been provided, or returns a function that accepts the remaining `func`
  9499. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9500. * is not sufficient.
  9501. *
  9502. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9503. * may be used as a placeholder for provided arguments.
  9504. *
  9505. * **Note:** This method doesn't set the "length" property of curried functions.
  9506. *
  9507. * @static
  9508. * @memberOf _
  9509. * @since 2.0.0
  9510. * @category Function
  9511. * @param {Function} func The function to curry.
  9512. * @param {number} [arity=func.length] The arity of `func`.
  9513. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9514. * @returns {Function} Returns the new curried function.
  9515. * @example
  9516. *
  9517. * var abc = function(a, b, c) {
  9518. * return [a, b, c];
  9519. * };
  9520. *
  9521. * var curried = _.curry(abc);
  9522. *
  9523. * curried(1)(2)(3);
  9524. * // => [1, 2, 3]
  9525. *
  9526. * curried(1, 2)(3);
  9527. * // => [1, 2, 3]
  9528. *
  9529. * curried(1, 2, 3);
  9530. * // => [1, 2, 3]
  9531. *
  9532. * // Curried with placeholders.
  9533. * curried(1)(_, 3)(2);
  9534. * // => [1, 2, 3]
  9535. */
  9536. function curry(func, arity, guard) {
  9537. arity = guard ? undefined : arity;
  9538. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9539. result.placeholder = curry.placeholder;
  9540. return result;
  9541. }
  9542. /**
  9543. * This method is like `_.curry` except that arguments are applied to `func`
  9544. * in the manner of `_.partialRight` instead of `_.partial`.
  9545. *
  9546. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9547. * builds, may be used as a placeholder for provided arguments.
  9548. *
  9549. * **Note:** This method doesn't set the "length" property of curried functions.
  9550. *
  9551. * @static
  9552. * @memberOf _
  9553. * @since 3.0.0
  9554. * @category Function
  9555. * @param {Function} func The function to curry.
  9556. * @param {number} [arity=func.length] The arity of `func`.
  9557. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9558. * @returns {Function} Returns the new curried function.
  9559. * @example
  9560. *
  9561. * var abc = function(a, b, c) {
  9562. * return [a, b, c];
  9563. * };
  9564. *
  9565. * var curried = _.curryRight(abc);
  9566. *
  9567. * curried(3)(2)(1);
  9568. * // => [1, 2, 3]
  9569. *
  9570. * curried(2, 3)(1);
  9571. * // => [1, 2, 3]
  9572. *
  9573. * curried(1, 2, 3);
  9574. * // => [1, 2, 3]
  9575. *
  9576. * // Curried with placeholders.
  9577. * curried(3)(1, _)(2);
  9578. * // => [1, 2, 3]
  9579. */
  9580. function curryRight(func, arity, guard) {
  9581. arity = guard ? undefined : arity;
  9582. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9583. result.placeholder = curryRight.placeholder;
  9584. return result;
  9585. }
  9586. /**
  9587. * Creates a debounced function that delays invoking `func` until after `wait`
  9588. * milliseconds have elapsed since the last time the debounced function was
  9589. * invoked. The debounced function comes with a `cancel` method to cancel
  9590. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9591. * Provide `options` to indicate whether `func` should be invoked on the
  9592. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9593. * with the last arguments provided to the debounced function. Subsequent
  9594. * calls to the debounced function return the result of the last `func`
  9595. * invocation.
  9596. *
  9597. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9598. * invoked on the trailing edge of the timeout only if the debounced function
  9599. * is invoked more than once during the `wait` timeout.
  9600. *
  9601. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9602. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9603. *
  9604. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9605. * for details over the differences between `_.debounce` and `_.throttle`.
  9606. *
  9607. * @static
  9608. * @memberOf _
  9609. * @since 0.1.0
  9610. * @category Function
  9611. * @param {Function} func The function to debounce.
  9612. * @param {number} [wait=0] The number of milliseconds to delay.
  9613. * @param {Object} [options={}] The options object.
  9614. * @param {boolean} [options.leading=false]
  9615. * Specify invoking on the leading edge of the timeout.
  9616. * @param {number} [options.maxWait]
  9617. * The maximum time `func` is allowed to be delayed before it's invoked.
  9618. * @param {boolean} [options.trailing=true]
  9619. * Specify invoking on the trailing edge of the timeout.
  9620. * @returns {Function} Returns the new debounced function.
  9621. * @example
  9622. *
  9623. * // Avoid costly calculations while the window size is in flux.
  9624. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9625. *
  9626. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9627. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9628. * 'leading': true,
  9629. * 'trailing': false
  9630. * }));
  9631. *
  9632. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9633. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9634. * var source = new EventSource('/stream');
  9635. * jQuery(source).on('message', debounced);
  9636. *
  9637. * // Cancel the trailing debounced invocation.
  9638. * jQuery(window).on('popstate', debounced.cancel);
  9639. */
  9640. function debounce(func, wait, options) {
  9641. var lastArgs,
  9642. lastThis,
  9643. maxWait,
  9644. result,
  9645. timerId,
  9646. lastCallTime,
  9647. lastInvokeTime = 0,
  9648. leading = false,
  9649. maxing = false,
  9650. trailing = true;
  9651. if (typeof func != 'function') {
  9652. throw new TypeError(FUNC_ERROR_TEXT);
  9653. }
  9654. wait = toNumber(wait) || 0;
  9655. if (isObject(options)) {
  9656. leading = !!options.leading;
  9657. maxing = 'maxWait' in options;
  9658. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9659. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9660. }
  9661. function invokeFunc(time) {
  9662. var args = lastArgs,
  9663. thisArg = lastThis;
  9664. lastArgs = lastThis = undefined;
  9665. lastInvokeTime = time;
  9666. result = func.apply(thisArg, args);
  9667. return result;
  9668. }
  9669. function leadingEdge(time) {
  9670. // Reset any `maxWait` timer.
  9671. lastInvokeTime = time;
  9672. // Start the timer for the trailing edge.
  9673. timerId = setTimeout(timerExpired, wait);
  9674. // Invoke the leading edge.
  9675. return leading ? invokeFunc(time) : result;
  9676. }
  9677. function remainingWait(time) {
  9678. var timeSinceLastCall = time - lastCallTime,
  9679. timeSinceLastInvoke = time - lastInvokeTime,
  9680. timeWaiting = wait - timeSinceLastCall;
  9681. return maxing
  9682. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9683. : timeWaiting;
  9684. }
  9685. function shouldInvoke(time) {
  9686. var timeSinceLastCall = time - lastCallTime,
  9687. timeSinceLastInvoke = time - lastInvokeTime;
  9688. // Either this is the first call, activity has stopped and we're at the
  9689. // trailing edge, the system time has gone backwards and we're treating
  9690. // it as the trailing edge, or we've hit the `maxWait` limit.
  9691. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9692. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9693. }
  9694. function timerExpired() {
  9695. var time = now();
  9696. if (shouldInvoke(time)) {
  9697. return trailingEdge(time);
  9698. }
  9699. // Restart the timer.
  9700. timerId = setTimeout(timerExpired, remainingWait(time));
  9701. }
  9702. function trailingEdge(time) {
  9703. timerId = undefined;
  9704. // Only invoke if we have `lastArgs` which means `func` has been
  9705. // debounced at least once.
  9706. if (trailing && lastArgs) {
  9707. return invokeFunc(time);
  9708. }
  9709. lastArgs = lastThis = undefined;
  9710. return result;
  9711. }
  9712. function cancel() {
  9713. if (timerId !== undefined) {
  9714. clearTimeout(timerId);
  9715. }
  9716. lastInvokeTime = 0;
  9717. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9718. }
  9719. function flush() {
  9720. return timerId === undefined ? result : trailingEdge(now());
  9721. }
  9722. function debounced() {
  9723. var time = now(),
  9724. isInvoking = shouldInvoke(time);
  9725. lastArgs = arguments;
  9726. lastThis = this;
  9727. lastCallTime = time;
  9728. if (isInvoking) {
  9729. if (timerId === undefined) {
  9730. return leadingEdge(lastCallTime);
  9731. }
  9732. if (maxing) {
  9733. // Handle invocations in a tight loop.
  9734. clearTimeout(timerId);
  9735. timerId = setTimeout(timerExpired, wait);
  9736. return invokeFunc(lastCallTime);
  9737. }
  9738. }
  9739. if (timerId === undefined) {
  9740. timerId = setTimeout(timerExpired, wait);
  9741. }
  9742. return result;
  9743. }
  9744. debounced.cancel = cancel;
  9745. debounced.flush = flush;
  9746. return debounced;
  9747. }
  9748. /**
  9749. * Defers invoking the `func` until the current call stack has cleared. Any
  9750. * additional arguments are provided to `func` when it's invoked.
  9751. *
  9752. * @static
  9753. * @memberOf _
  9754. * @since 0.1.0
  9755. * @category Function
  9756. * @param {Function} func The function to defer.
  9757. * @param {...*} [args] The arguments to invoke `func` with.
  9758. * @returns {number} Returns the timer id.
  9759. * @example
  9760. *
  9761. * _.defer(function(text) {
  9762. * console.log(text);
  9763. * }, 'deferred');
  9764. * // => Logs 'deferred' after one millisecond.
  9765. */
  9766. var defer = baseRest(function(func, args) {
  9767. return baseDelay(func, 1, args);
  9768. });
  9769. /**
  9770. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9771. * provided to `func` when it's invoked.
  9772. *
  9773. * @static
  9774. * @memberOf _
  9775. * @since 0.1.0
  9776. * @category Function
  9777. * @param {Function} func The function to delay.
  9778. * @param {number} wait The number of milliseconds to delay invocation.
  9779. * @param {...*} [args] The arguments to invoke `func` with.
  9780. * @returns {number} Returns the timer id.
  9781. * @example
  9782. *
  9783. * _.delay(function(text) {
  9784. * console.log(text);
  9785. * }, 1000, 'later');
  9786. * // => Logs 'later' after one second.
  9787. */
  9788. var delay = baseRest(function(func, wait, args) {
  9789. return baseDelay(func, toNumber(wait) || 0, args);
  9790. });
  9791. /**
  9792. * Creates a function that invokes `func` with arguments reversed.
  9793. *
  9794. * @static
  9795. * @memberOf _
  9796. * @since 4.0.0
  9797. * @category Function
  9798. * @param {Function} func The function to flip arguments for.
  9799. * @returns {Function} Returns the new flipped function.
  9800. * @example
  9801. *
  9802. * var flipped = _.flip(function() {
  9803. * return _.toArray(arguments);
  9804. * });
  9805. *
  9806. * flipped('a', 'b', 'c', 'd');
  9807. * // => ['d', 'c', 'b', 'a']
  9808. */
  9809. function flip(func) {
  9810. return createWrap(func, WRAP_FLIP_FLAG);
  9811. }
  9812. /**
  9813. * Creates a function that memoizes the result of `func`. If `resolver` is
  9814. * provided, it determines the cache key for storing the result based on the
  9815. * arguments provided to the memoized function. By default, the first argument
  9816. * provided to the memoized function is used as the map cache key. The `func`
  9817. * is invoked with the `this` binding of the memoized function.
  9818. *
  9819. * **Note:** The cache is exposed as the `cache` property on the memoized
  9820. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9821. * constructor with one whose instances implement the
  9822. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9823. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9824. *
  9825. * @static
  9826. * @memberOf _
  9827. * @since 0.1.0
  9828. * @category Function
  9829. * @param {Function} func The function to have its output memoized.
  9830. * @param {Function} [resolver] The function to resolve the cache key.
  9831. * @returns {Function} Returns the new memoized function.
  9832. * @example
  9833. *
  9834. * var object = { 'a': 1, 'b': 2 };
  9835. * var other = { 'c': 3, 'd': 4 };
  9836. *
  9837. * var values = _.memoize(_.values);
  9838. * values(object);
  9839. * // => [1, 2]
  9840. *
  9841. * values(other);
  9842. * // => [3, 4]
  9843. *
  9844. * object.a = 2;
  9845. * values(object);
  9846. * // => [1, 2]
  9847. *
  9848. * // Modify the result cache.
  9849. * values.cache.set(object, ['a', 'b']);
  9850. * values(object);
  9851. * // => ['a', 'b']
  9852. *
  9853. * // Replace `_.memoize.Cache`.
  9854. * _.memoize.Cache = WeakMap;
  9855. */
  9856. function memoize(func, resolver) {
  9857. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9858. throw new TypeError(FUNC_ERROR_TEXT);
  9859. }
  9860. var memoized = function() {
  9861. var args = arguments,
  9862. key = resolver ? resolver.apply(this, args) : args[0],
  9863. cache = memoized.cache;
  9864. if (cache.has(key)) {
  9865. return cache.get(key);
  9866. }
  9867. var result = func.apply(this, args);
  9868. memoized.cache = cache.set(key, result) || cache;
  9869. return result;
  9870. };
  9871. memoized.cache = new (memoize.Cache || MapCache);
  9872. return memoized;
  9873. }
  9874. // Expose `MapCache`.
  9875. memoize.Cache = MapCache;
  9876. /**
  9877. * Creates a function that negates the result of the predicate `func`. The
  9878. * `func` predicate is invoked with the `this` binding and arguments of the
  9879. * created function.
  9880. *
  9881. * @static
  9882. * @memberOf _
  9883. * @since 3.0.0
  9884. * @category Function
  9885. * @param {Function} predicate The predicate to negate.
  9886. * @returns {Function} Returns the new negated function.
  9887. * @example
  9888. *
  9889. * function isEven(n) {
  9890. * return n % 2 == 0;
  9891. * }
  9892. *
  9893. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9894. * // => [1, 3, 5]
  9895. */
  9896. function negate(predicate) {
  9897. if (typeof predicate != 'function') {
  9898. throw new TypeError(FUNC_ERROR_TEXT);
  9899. }
  9900. return function() {
  9901. var args = arguments;
  9902. switch (args.length) {
  9903. case 0: return !predicate.call(this);
  9904. case 1: return !predicate.call(this, args[0]);
  9905. case 2: return !predicate.call(this, args[0], args[1]);
  9906. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9907. }
  9908. return !predicate.apply(this, args);
  9909. };
  9910. }
  9911. /**
  9912. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9913. * to the function return the value of the first invocation. The `func` is
  9914. * invoked with the `this` binding and arguments of the created function.
  9915. *
  9916. * @static
  9917. * @memberOf _
  9918. * @since 0.1.0
  9919. * @category Function
  9920. * @param {Function} func The function to restrict.
  9921. * @returns {Function} Returns the new restricted function.
  9922. * @example
  9923. *
  9924. * var initialize = _.once(createApplication);
  9925. * initialize();
  9926. * initialize();
  9927. * // => `createApplication` is invoked once
  9928. */
  9929. function once(func) {
  9930. return before(2, func);
  9931. }
  9932. /**
  9933. * Creates a function that invokes `func` with its arguments transformed.
  9934. *
  9935. * @static
  9936. * @since 4.0.0
  9937. * @memberOf _
  9938. * @category Function
  9939. * @param {Function} func The function to wrap.
  9940. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9941. * The argument transforms.
  9942. * @returns {Function} Returns the new function.
  9943. * @example
  9944. *
  9945. * function doubled(n) {
  9946. * return n * 2;
  9947. * }
  9948. *
  9949. * function square(n) {
  9950. * return n * n;
  9951. * }
  9952. *
  9953. * var func = _.overArgs(function(x, y) {
  9954. * return [x, y];
  9955. * }, [square, doubled]);
  9956. *
  9957. * func(9, 3);
  9958. * // => [81, 6]
  9959. *
  9960. * func(10, 5);
  9961. * // => [100, 10]
  9962. */
  9963. var overArgs = castRest(function(func, transforms) {
  9964. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9965. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9966. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9967. var funcsLength = transforms.length;
  9968. return baseRest(function(args) {
  9969. var index = -1,
  9970. length = nativeMin(args.length, funcsLength);
  9971. while (++index < length) {
  9972. args[index] = transforms[index].call(this, args[index]);
  9973. }
  9974. return apply(func, this, args);
  9975. });
  9976. });
  9977. /**
  9978. * Creates a function that invokes `func` with `partials` prepended to the
  9979. * arguments it receives. This method is like `_.bind` except it does **not**
  9980. * alter the `this` binding.
  9981. *
  9982. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9983. * builds, may be used as a placeholder for partially applied arguments.
  9984. *
  9985. * **Note:** This method doesn't set the "length" property of partially
  9986. * applied functions.
  9987. *
  9988. * @static
  9989. * @memberOf _
  9990. * @since 0.2.0
  9991. * @category Function
  9992. * @param {Function} func The function to partially apply arguments to.
  9993. * @param {...*} [partials] The arguments to be partially applied.
  9994. * @returns {Function} Returns the new partially applied function.
  9995. * @example
  9996. *
  9997. * function greet(greeting, name) {
  9998. * return greeting + ' ' + name;
  9999. * }
  10000. *
  10001. * var sayHelloTo = _.partial(greet, 'hello');
  10002. * sayHelloTo('fred');
  10003. * // => 'hello fred'
  10004. *
  10005. * // Partially applied with placeholders.
  10006. * var greetFred = _.partial(greet, _, 'fred');
  10007. * greetFred('hi');
  10008. * // => 'hi fred'
  10009. */
  10010. var partial = baseRest(function(func, partials) {
  10011. var holders = replaceHolders(partials, getHolder(partial));
  10012. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10013. });
  10014. /**
  10015. * This method is like `_.partial` except that partially applied arguments
  10016. * are appended to the arguments it receives.
  10017. *
  10018. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10019. * builds, may be used as a placeholder for partially applied arguments.
  10020. *
  10021. * **Note:** This method doesn't set the "length" property of partially
  10022. * applied functions.
  10023. *
  10024. * @static
  10025. * @memberOf _
  10026. * @since 1.0.0
  10027. * @category Function
  10028. * @param {Function} func The function to partially apply arguments to.
  10029. * @param {...*} [partials] The arguments to be partially applied.
  10030. * @returns {Function} Returns the new partially applied function.
  10031. * @example
  10032. *
  10033. * function greet(greeting, name) {
  10034. * return greeting + ' ' + name;
  10035. * }
  10036. *
  10037. * var greetFred = _.partialRight(greet, 'fred');
  10038. * greetFred('hi');
  10039. * // => 'hi fred'
  10040. *
  10041. * // Partially applied with placeholders.
  10042. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10043. * sayHelloTo('fred');
  10044. * // => 'hello fred'
  10045. */
  10046. var partialRight = baseRest(function(func, partials) {
  10047. var holders = replaceHolders(partials, getHolder(partialRight));
  10048. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10049. });
  10050. /**
  10051. * Creates a function that invokes `func` with arguments arranged according
  10052. * to the specified `indexes` where the argument value at the first index is
  10053. * provided as the first argument, the argument value at the second index is
  10054. * provided as the second argument, and so on.
  10055. *
  10056. * @static
  10057. * @memberOf _
  10058. * @since 3.0.0
  10059. * @category Function
  10060. * @param {Function} func The function to rearrange arguments for.
  10061. * @param {...(number|number[])} indexes The arranged argument indexes.
  10062. * @returns {Function} Returns the new function.
  10063. * @example
  10064. *
  10065. * var rearged = _.rearg(function(a, b, c) {
  10066. * return [a, b, c];
  10067. * }, [2, 0, 1]);
  10068. *
  10069. * rearged('b', 'c', 'a')
  10070. * // => ['a', 'b', 'c']
  10071. */
  10072. var rearg = flatRest(function(func, indexes) {
  10073. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10074. });
  10075. /**
  10076. * Creates a function that invokes `func` with the `this` binding of the
  10077. * created function and arguments from `start` and beyond provided as
  10078. * an array.
  10079. *
  10080. * **Note:** This method is based on the
  10081. * [rest parameter](https://mdn.io/rest_parameters).
  10082. *
  10083. * @static
  10084. * @memberOf _
  10085. * @since 4.0.0
  10086. * @category Function
  10087. * @param {Function} func The function to apply a rest parameter to.
  10088. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10089. * @returns {Function} Returns the new function.
  10090. * @example
  10091. *
  10092. * var say = _.rest(function(what, names) {
  10093. * return what + ' ' + _.initial(names).join(', ') +
  10094. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10095. * });
  10096. *
  10097. * say('hello', 'fred', 'barney', 'pebbles');
  10098. * // => 'hello fred, barney, & pebbles'
  10099. */
  10100. function rest(func, start) {
  10101. if (typeof func != 'function') {
  10102. throw new TypeError(FUNC_ERROR_TEXT);
  10103. }
  10104. start = start === undefined ? start : toInteger(start);
  10105. return baseRest(func, start);
  10106. }
  10107. /**
  10108. * Creates a function that invokes `func` with the `this` binding of the
  10109. * create function and an array of arguments much like
  10110. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10111. *
  10112. * **Note:** This method is based on the
  10113. * [spread operator](https://mdn.io/spread_operator).
  10114. *
  10115. * @static
  10116. * @memberOf _
  10117. * @since 3.2.0
  10118. * @category Function
  10119. * @param {Function} func The function to spread arguments over.
  10120. * @param {number} [start=0] The start position of the spread.
  10121. * @returns {Function} Returns the new function.
  10122. * @example
  10123. *
  10124. * var say = _.spread(function(who, what) {
  10125. * return who + ' says ' + what;
  10126. * });
  10127. *
  10128. * say(['fred', 'hello']);
  10129. * // => 'fred says hello'
  10130. *
  10131. * var numbers = Promise.all([
  10132. * Promise.resolve(40),
  10133. * Promise.resolve(36)
  10134. * ]);
  10135. *
  10136. * numbers.then(_.spread(function(x, y) {
  10137. * return x + y;
  10138. * }));
  10139. * // => a Promise of 76
  10140. */
  10141. function spread(func, start) {
  10142. if (typeof func != 'function') {
  10143. throw new TypeError(FUNC_ERROR_TEXT);
  10144. }
  10145. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10146. return baseRest(function(args) {
  10147. var array = args[start],
  10148. otherArgs = castSlice(args, 0, start);
  10149. if (array) {
  10150. arrayPush(otherArgs, array);
  10151. }
  10152. return apply(func, this, otherArgs);
  10153. });
  10154. }
  10155. /**
  10156. * Creates a throttled function that only invokes `func` at most once per
  10157. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10158. * method to cancel delayed `func` invocations and a `flush` method to
  10159. * immediately invoke them. Provide `options` to indicate whether `func`
  10160. * should be invoked on the leading and/or trailing edge of the `wait`
  10161. * timeout. The `func` is invoked with the last arguments provided to the
  10162. * throttled function. Subsequent calls to the throttled function return the
  10163. * result of the last `func` invocation.
  10164. *
  10165. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10166. * invoked on the trailing edge of the timeout only if the throttled function
  10167. * is invoked more than once during the `wait` timeout.
  10168. *
  10169. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10170. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10171. *
  10172. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10173. * for details over the differences between `_.throttle` and `_.debounce`.
  10174. *
  10175. * @static
  10176. * @memberOf _
  10177. * @since 0.1.0
  10178. * @category Function
  10179. * @param {Function} func The function to throttle.
  10180. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10181. * @param {Object} [options={}] The options object.
  10182. * @param {boolean} [options.leading=true]
  10183. * Specify invoking on the leading edge of the timeout.
  10184. * @param {boolean} [options.trailing=true]
  10185. * Specify invoking on the trailing edge of the timeout.
  10186. * @returns {Function} Returns the new throttled function.
  10187. * @example
  10188. *
  10189. * // Avoid excessively updating the position while scrolling.
  10190. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10191. *
  10192. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10193. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10194. * jQuery(element).on('click', throttled);
  10195. *
  10196. * // Cancel the trailing throttled invocation.
  10197. * jQuery(window).on('popstate', throttled.cancel);
  10198. */
  10199. function throttle(func, wait, options) {
  10200. var leading = true,
  10201. trailing = true;
  10202. if (typeof func != 'function') {
  10203. throw new TypeError(FUNC_ERROR_TEXT);
  10204. }
  10205. if (isObject(options)) {
  10206. leading = 'leading' in options ? !!options.leading : leading;
  10207. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10208. }
  10209. return debounce(func, wait, {
  10210. 'leading': leading,
  10211. 'maxWait': wait,
  10212. 'trailing': trailing
  10213. });
  10214. }
  10215. /**
  10216. * Creates a function that accepts up to one argument, ignoring any
  10217. * additional arguments.
  10218. *
  10219. * @static
  10220. * @memberOf _
  10221. * @since 4.0.0
  10222. * @category Function
  10223. * @param {Function} func The function to cap arguments for.
  10224. * @returns {Function} Returns the new capped function.
  10225. * @example
  10226. *
  10227. * _.map(['6', '8', '10'], _.unary(parseInt));
  10228. * // => [6, 8, 10]
  10229. */
  10230. function unary(func) {
  10231. return ary(func, 1);
  10232. }
  10233. /**
  10234. * Creates a function that provides `value` to `wrapper` as its first
  10235. * argument. Any additional arguments provided to the function are appended
  10236. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10237. * binding of the created function.
  10238. *
  10239. * @static
  10240. * @memberOf _
  10241. * @since 0.1.0
  10242. * @category Function
  10243. * @param {*} value The value to wrap.
  10244. * @param {Function} [wrapper=identity] The wrapper function.
  10245. * @returns {Function} Returns the new function.
  10246. * @example
  10247. *
  10248. * var p = _.wrap(_.escape, function(func, text) {
  10249. * return '<p>' + func(text) + '</p>';
  10250. * });
  10251. *
  10252. * p('fred, barney, & pebbles');
  10253. * // => '<p>fred, barney, &amp; pebbles</p>'
  10254. */
  10255. function wrap(value, wrapper) {
  10256. return partial(castFunction(wrapper), value);
  10257. }
  10258. /*------------------------------------------------------------------------*/
  10259. /**
  10260. * Casts `value` as an array if it's not one.
  10261. *
  10262. * @static
  10263. * @memberOf _
  10264. * @since 4.4.0
  10265. * @category Lang
  10266. * @param {*} value The value to inspect.
  10267. * @returns {Array} Returns the cast array.
  10268. * @example
  10269. *
  10270. * _.castArray(1);
  10271. * // => [1]
  10272. *
  10273. * _.castArray({ 'a': 1 });
  10274. * // => [{ 'a': 1 }]
  10275. *
  10276. * _.castArray('abc');
  10277. * // => ['abc']
  10278. *
  10279. * _.castArray(null);
  10280. * // => [null]
  10281. *
  10282. * _.castArray(undefined);
  10283. * // => [undefined]
  10284. *
  10285. * _.castArray();
  10286. * // => []
  10287. *
  10288. * var array = [1, 2, 3];
  10289. * console.log(_.castArray(array) === array);
  10290. * // => true
  10291. */
  10292. function castArray() {
  10293. if (!arguments.length) {
  10294. return [];
  10295. }
  10296. var value = arguments[0];
  10297. return isArray(value) ? value : [value];
  10298. }
  10299. /**
  10300. * Creates a shallow clone of `value`.
  10301. *
  10302. * **Note:** This method is loosely based on the
  10303. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10304. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10305. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10306. * arrays. The own enumerable properties of `arguments` objects are cloned
  10307. * as plain objects. An empty object is returned for uncloneable values such
  10308. * as error objects, functions, DOM nodes, and WeakMaps.
  10309. *
  10310. * @static
  10311. * @memberOf _
  10312. * @since 0.1.0
  10313. * @category Lang
  10314. * @param {*} value The value to clone.
  10315. * @returns {*} Returns the cloned value.
  10316. * @see _.cloneDeep
  10317. * @example
  10318. *
  10319. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10320. *
  10321. * var shallow = _.clone(objects);
  10322. * console.log(shallow[0] === objects[0]);
  10323. * // => true
  10324. */
  10325. function clone(value) {
  10326. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10327. }
  10328. /**
  10329. * This method is like `_.clone` except that it accepts `customizer` which
  10330. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10331. * cloning is handled by the method instead. The `customizer` is invoked with
  10332. * up to four arguments; (value [, index|key, object, stack]).
  10333. *
  10334. * @static
  10335. * @memberOf _
  10336. * @since 4.0.0
  10337. * @category Lang
  10338. * @param {*} value The value to clone.
  10339. * @param {Function} [customizer] The function to customize cloning.
  10340. * @returns {*} Returns the cloned value.
  10341. * @see _.cloneDeepWith
  10342. * @example
  10343. *
  10344. * function customizer(value) {
  10345. * if (_.isElement(value)) {
  10346. * return value.cloneNode(false);
  10347. * }
  10348. * }
  10349. *
  10350. * var el = _.cloneWith(document.body, customizer);
  10351. *
  10352. * console.log(el === document.body);
  10353. * // => false
  10354. * console.log(el.nodeName);
  10355. * // => 'BODY'
  10356. * console.log(el.childNodes.length);
  10357. * // => 0
  10358. */
  10359. function cloneWith(value, customizer) {
  10360. customizer = typeof customizer == 'function' ? customizer : undefined;
  10361. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10362. }
  10363. /**
  10364. * This method is like `_.clone` except that it recursively clones `value`.
  10365. *
  10366. * @static
  10367. * @memberOf _
  10368. * @since 1.0.0
  10369. * @category Lang
  10370. * @param {*} value The value to recursively clone.
  10371. * @returns {*} Returns the deep cloned value.
  10372. * @see _.clone
  10373. * @example
  10374. *
  10375. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10376. *
  10377. * var deep = _.cloneDeep(objects);
  10378. * console.log(deep[0] === objects[0]);
  10379. * // => false
  10380. */
  10381. function cloneDeep(value) {
  10382. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10383. }
  10384. /**
  10385. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10386. *
  10387. * @static
  10388. * @memberOf _
  10389. * @since 4.0.0
  10390. * @category Lang
  10391. * @param {*} value The value to recursively clone.
  10392. * @param {Function} [customizer] The function to customize cloning.
  10393. * @returns {*} Returns the deep cloned value.
  10394. * @see _.cloneWith
  10395. * @example
  10396. *
  10397. * function customizer(value) {
  10398. * if (_.isElement(value)) {
  10399. * return value.cloneNode(true);
  10400. * }
  10401. * }
  10402. *
  10403. * var el = _.cloneDeepWith(document.body, customizer);
  10404. *
  10405. * console.log(el === document.body);
  10406. * // => false
  10407. * console.log(el.nodeName);
  10408. * // => 'BODY'
  10409. * console.log(el.childNodes.length);
  10410. * // => 20
  10411. */
  10412. function cloneDeepWith(value, customizer) {
  10413. customizer = typeof customizer == 'function' ? customizer : undefined;
  10414. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10415. }
  10416. /**
  10417. * Checks if `object` conforms to `source` by invoking the predicate
  10418. * properties of `source` with the corresponding property values of `object`.
  10419. *
  10420. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10421. * partially applied.
  10422. *
  10423. * @static
  10424. * @memberOf _
  10425. * @since 4.14.0
  10426. * @category Lang
  10427. * @param {Object} object The object to inspect.
  10428. * @param {Object} source The object of property predicates to conform to.
  10429. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10430. * @example
  10431. *
  10432. * var object = { 'a': 1, 'b': 2 };
  10433. *
  10434. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10435. * // => true
  10436. *
  10437. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10438. * // => false
  10439. */
  10440. function conformsTo(object, source) {
  10441. return source == null || baseConformsTo(object, source, keys(source));
  10442. }
  10443. /**
  10444. * Performs a
  10445. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10446. * comparison between two values to determine if they are equivalent.
  10447. *
  10448. * @static
  10449. * @memberOf _
  10450. * @since 4.0.0
  10451. * @category Lang
  10452. * @param {*} value The value to compare.
  10453. * @param {*} other The other value to compare.
  10454. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10455. * @example
  10456. *
  10457. * var object = { 'a': 1 };
  10458. * var other = { 'a': 1 };
  10459. *
  10460. * _.eq(object, object);
  10461. * // => true
  10462. *
  10463. * _.eq(object, other);
  10464. * // => false
  10465. *
  10466. * _.eq('a', 'a');
  10467. * // => true
  10468. *
  10469. * _.eq('a', Object('a'));
  10470. * // => false
  10471. *
  10472. * _.eq(NaN, NaN);
  10473. * // => true
  10474. */
  10475. function eq(value, other) {
  10476. return value === other || (value !== value && other !== other);
  10477. }
  10478. /**
  10479. * Checks if `value` is greater than `other`.
  10480. *
  10481. * @static
  10482. * @memberOf _
  10483. * @since 3.9.0
  10484. * @category Lang
  10485. * @param {*} value The value to compare.
  10486. * @param {*} other The other value to compare.
  10487. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10488. * else `false`.
  10489. * @see _.lt
  10490. * @example
  10491. *
  10492. * _.gt(3, 1);
  10493. * // => true
  10494. *
  10495. * _.gt(3, 3);
  10496. * // => false
  10497. *
  10498. * _.gt(1, 3);
  10499. * // => false
  10500. */
  10501. var gt = createRelationalOperation(baseGt);
  10502. /**
  10503. * Checks if `value` is greater than or equal to `other`.
  10504. *
  10505. * @static
  10506. * @memberOf _
  10507. * @since 3.9.0
  10508. * @category Lang
  10509. * @param {*} value The value to compare.
  10510. * @param {*} other The other value to compare.
  10511. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10512. * `other`, else `false`.
  10513. * @see _.lte
  10514. * @example
  10515. *
  10516. * _.gte(3, 1);
  10517. * // => true
  10518. *
  10519. * _.gte(3, 3);
  10520. * // => true
  10521. *
  10522. * _.gte(1, 3);
  10523. * // => false
  10524. */
  10525. var gte = createRelationalOperation(function(value, other) {
  10526. return value >= other;
  10527. });
  10528. /**
  10529. * Checks if `value` is likely an `arguments` object.
  10530. *
  10531. * @static
  10532. * @memberOf _
  10533. * @since 0.1.0
  10534. * @category Lang
  10535. * @param {*} value The value to check.
  10536. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10537. * else `false`.
  10538. * @example
  10539. *
  10540. * _.isArguments(function() { return arguments; }());
  10541. * // => true
  10542. *
  10543. * _.isArguments([1, 2, 3]);
  10544. * // => false
  10545. */
  10546. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10547. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10548. !propertyIsEnumerable.call(value, 'callee');
  10549. };
  10550. /**
  10551. * Checks if `value` is classified as an `Array` object.
  10552. *
  10553. * @static
  10554. * @memberOf _
  10555. * @since 0.1.0
  10556. * @category Lang
  10557. * @param {*} value The value to check.
  10558. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10559. * @example
  10560. *
  10561. * _.isArray([1, 2, 3]);
  10562. * // => true
  10563. *
  10564. * _.isArray(document.body.children);
  10565. * // => false
  10566. *
  10567. * _.isArray('abc');
  10568. * // => false
  10569. *
  10570. * _.isArray(_.noop);
  10571. * // => false
  10572. */
  10573. var isArray = Array.isArray;
  10574. /**
  10575. * Checks if `value` is classified as an `ArrayBuffer` object.
  10576. *
  10577. * @static
  10578. * @memberOf _
  10579. * @since 4.3.0
  10580. * @category Lang
  10581. * @param {*} value The value to check.
  10582. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10583. * @example
  10584. *
  10585. * _.isArrayBuffer(new ArrayBuffer(2));
  10586. * // => true
  10587. *
  10588. * _.isArrayBuffer(new Array(2));
  10589. * // => false
  10590. */
  10591. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10592. /**
  10593. * Checks if `value` is array-like. A value is considered array-like if it's
  10594. * not a function and has a `value.length` that's an integer greater than or
  10595. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10596. *
  10597. * @static
  10598. * @memberOf _
  10599. * @since 4.0.0
  10600. * @category Lang
  10601. * @param {*} value The value to check.
  10602. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10603. * @example
  10604. *
  10605. * _.isArrayLike([1, 2, 3]);
  10606. * // => true
  10607. *
  10608. * _.isArrayLike(document.body.children);
  10609. * // => true
  10610. *
  10611. * _.isArrayLike('abc');
  10612. * // => true
  10613. *
  10614. * _.isArrayLike(_.noop);
  10615. * // => false
  10616. */
  10617. function isArrayLike(value) {
  10618. return value != null && isLength(value.length) && !isFunction(value);
  10619. }
  10620. /**
  10621. * This method is like `_.isArrayLike` except that it also checks if `value`
  10622. * is an object.
  10623. *
  10624. * @static
  10625. * @memberOf _
  10626. * @since 4.0.0
  10627. * @category Lang
  10628. * @param {*} value The value to check.
  10629. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10630. * else `false`.
  10631. * @example
  10632. *
  10633. * _.isArrayLikeObject([1, 2, 3]);
  10634. * // => true
  10635. *
  10636. * _.isArrayLikeObject(document.body.children);
  10637. * // => true
  10638. *
  10639. * _.isArrayLikeObject('abc');
  10640. * // => false
  10641. *
  10642. * _.isArrayLikeObject(_.noop);
  10643. * // => false
  10644. */
  10645. function isArrayLikeObject(value) {
  10646. return isObjectLike(value) && isArrayLike(value);
  10647. }
  10648. /**
  10649. * Checks if `value` is classified as a boolean primitive or object.
  10650. *
  10651. * @static
  10652. * @memberOf _
  10653. * @since 0.1.0
  10654. * @category Lang
  10655. * @param {*} value The value to check.
  10656. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10657. * @example
  10658. *
  10659. * _.isBoolean(false);
  10660. * // => true
  10661. *
  10662. * _.isBoolean(null);
  10663. * // => false
  10664. */
  10665. function isBoolean(value) {
  10666. return value === true || value === false ||
  10667. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10668. }
  10669. /**
  10670. * Checks if `value` is a buffer.
  10671. *
  10672. * @static
  10673. * @memberOf _
  10674. * @since 4.3.0
  10675. * @category Lang
  10676. * @param {*} value The value to check.
  10677. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10678. * @example
  10679. *
  10680. * _.isBuffer(new Buffer(2));
  10681. * // => true
  10682. *
  10683. * _.isBuffer(new Uint8Array(2));
  10684. * // => false
  10685. */
  10686. var isBuffer = nativeIsBuffer || stubFalse;
  10687. /**
  10688. * Checks if `value` is classified as a `Date` object.
  10689. *
  10690. * @static
  10691. * @memberOf _
  10692. * @since 0.1.0
  10693. * @category Lang
  10694. * @param {*} value The value to check.
  10695. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10696. * @example
  10697. *
  10698. * _.isDate(new Date);
  10699. * // => true
  10700. *
  10701. * _.isDate('Mon April 23 2012');
  10702. * // => false
  10703. */
  10704. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10705. /**
  10706. * Checks if `value` is likely a DOM element.
  10707. *
  10708. * @static
  10709. * @memberOf _
  10710. * @since 0.1.0
  10711. * @category Lang
  10712. * @param {*} value The value to check.
  10713. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10714. * @example
  10715. *
  10716. * _.isElement(document.body);
  10717. * // => true
  10718. *
  10719. * _.isElement('<body>');
  10720. * // => false
  10721. */
  10722. function isElement(value) {
  10723. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10724. }
  10725. /**
  10726. * Checks if `value` is an empty object, collection, map, or set.
  10727. *
  10728. * Objects are considered empty if they have no own enumerable string keyed
  10729. * properties.
  10730. *
  10731. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10732. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10733. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10734. *
  10735. * @static
  10736. * @memberOf _
  10737. * @since 0.1.0
  10738. * @category Lang
  10739. * @param {*} value The value to check.
  10740. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10741. * @example
  10742. *
  10743. * _.isEmpty(null);
  10744. * // => true
  10745. *
  10746. * _.isEmpty(true);
  10747. * // => true
  10748. *
  10749. * _.isEmpty(1);
  10750. * // => true
  10751. *
  10752. * _.isEmpty([1, 2, 3]);
  10753. * // => false
  10754. *
  10755. * _.isEmpty({ 'a': 1 });
  10756. * // => false
  10757. */
  10758. function isEmpty(value) {
  10759. if (value == null) {
  10760. return true;
  10761. }
  10762. if (isArrayLike(value) &&
  10763. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10764. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10765. return !value.length;
  10766. }
  10767. var tag = getTag(value);
  10768. if (tag == mapTag || tag == setTag) {
  10769. return !value.size;
  10770. }
  10771. if (isPrototype(value)) {
  10772. return !baseKeys(value).length;
  10773. }
  10774. for (var key in value) {
  10775. if (hasOwnProperty.call(value, key)) {
  10776. return false;
  10777. }
  10778. }
  10779. return true;
  10780. }
  10781. /**
  10782. * Performs a deep comparison between two values to determine if they are
  10783. * equivalent.
  10784. *
  10785. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10786. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10787. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10788. * by their own, not inherited, enumerable properties. Functions and DOM
  10789. * nodes are compared by strict equality, i.e. `===`.
  10790. *
  10791. * @static
  10792. * @memberOf _
  10793. * @since 0.1.0
  10794. * @category Lang
  10795. * @param {*} value The value to compare.
  10796. * @param {*} other The other value to compare.
  10797. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10798. * @example
  10799. *
  10800. * var object = { 'a': 1 };
  10801. * var other = { 'a': 1 };
  10802. *
  10803. * _.isEqual(object, other);
  10804. * // => true
  10805. *
  10806. * object === other;
  10807. * // => false
  10808. */
  10809. function isEqual(value, other) {
  10810. return baseIsEqual(value, other);
  10811. }
  10812. /**
  10813. * This method is like `_.isEqual` except that it accepts `customizer` which
  10814. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10815. * are handled by the method instead. The `customizer` is invoked with up to
  10816. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10817. *
  10818. * @static
  10819. * @memberOf _
  10820. * @since 4.0.0
  10821. * @category Lang
  10822. * @param {*} value The value to compare.
  10823. * @param {*} other The other value to compare.
  10824. * @param {Function} [customizer] The function to customize comparisons.
  10825. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10826. * @example
  10827. *
  10828. * function isGreeting(value) {
  10829. * return /^h(?:i|ello)$/.test(value);
  10830. * }
  10831. *
  10832. * function customizer(objValue, othValue) {
  10833. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10834. * return true;
  10835. * }
  10836. * }
  10837. *
  10838. * var array = ['hello', 'goodbye'];
  10839. * var other = ['hi', 'goodbye'];
  10840. *
  10841. * _.isEqualWith(array, other, customizer);
  10842. * // => true
  10843. */
  10844. function isEqualWith(value, other, customizer) {
  10845. customizer = typeof customizer == 'function' ? customizer : undefined;
  10846. var result = customizer ? customizer(value, other) : undefined;
  10847. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10848. }
  10849. /**
  10850. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10851. * `SyntaxError`, `TypeError`, or `URIError` object.
  10852. *
  10853. * @static
  10854. * @memberOf _
  10855. * @since 3.0.0
  10856. * @category Lang
  10857. * @param {*} value The value to check.
  10858. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10859. * @example
  10860. *
  10861. * _.isError(new Error);
  10862. * // => true
  10863. *
  10864. * _.isError(Error);
  10865. * // => false
  10866. */
  10867. function isError(value) {
  10868. if (!isObjectLike(value)) {
  10869. return false;
  10870. }
  10871. var tag = baseGetTag(value);
  10872. return tag == errorTag || tag == domExcTag ||
  10873. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10874. }
  10875. /**
  10876. * Checks if `value` is a finite primitive number.
  10877. *
  10878. * **Note:** This method is based on
  10879. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10880. *
  10881. * @static
  10882. * @memberOf _
  10883. * @since 0.1.0
  10884. * @category Lang
  10885. * @param {*} value The value to check.
  10886. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10887. * @example
  10888. *
  10889. * _.isFinite(3);
  10890. * // => true
  10891. *
  10892. * _.isFinite(Number.MIN_VALUE);
  10893. * // => true
  10894. *
  10895. * _.isFinite(Infinity);
  10896. * // => false
  10897. *
  10898. * _.isFinite('3');
  10899. * // => false
  10900. */
  10901. function isFinite(value) {
  10902. return typeof value == 'number' && nativeIsFinite(value);
  10903. }
  10904. /**
  10905. * Checks if `value` is classified as a `Function` object.
  10906. *
  10907. * @static
  10908. * @memberOf _
  10909. * @since 0.1.0
  10910. * @category Lang
  10911. * @param {*} value The value to check.
  10912. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10913. * @example
  10914. *
  10915. * _.isFunction(_);
  10916. * // => true
  10917. *
  10918. * _.isFunction(/abc/);
  10919. * // => false
  10920. */
  10921. function isFunction(value) {
  10922. if (!isObject(value)) {
  10923. return false;
  10924. }
  10925. // The use of `Object#toString` avoids issues with the `typeof` operator
  10926. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10927. var tag = baseGetTag(value);
  10928. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10929. }
  10930. /**
  10931. * Checks if `value` is an integer.
  10932. *
  10933. * **Note:** This method is based on
  10934. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10935. *
  10936. * @static
  10937. * @memberOf _
  10938. * @since 4.0.0
  10939. * @category Lang
  10940. * @param {*} value The value to check.
  10941. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10942. * @example
  10943. *
  10944. * _.isInteger(3);
  10945. * // => true
  10946. *
  10947. * _.isInteger(Number.MIN_VALUE);
  10948. * // => false
  10949. *
  10950. * _.isInteger(Infinity);
  10951. * // => false
  10952. *
  10953. * _.isInteger('3');
  10954. * // => false
  10955. */
  10956. function isInteger(value) {
  10957. return typeof value == 'number' && value == toInteger(value);
  10958. }
  10959. /**
  10960. * Checks if `value` is a valid array-like length.
  10961. *
  10962. * **Note:** This method is loosely based on
  10963. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10964. *
  10965. * @static
  10966. * @memberOf _
  10967. * @since 4.0.0
  10968. * @category Lang
  10969. * @param {*} value The value to check.
  10970. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10971. * @example
  10972. *
  10973. * _.isLength(3);
  10974. * // => true
  10975. *
  10976. * _.isLength(Number.MIN_VALUE);
  10977. * // => false
  10978. *
  10979. * _.isLength(Infinity);
  10980. * // => false
  10981. *
  10982. * _.isLength('3');
  10983. * // => false
  10984. */
  10985. function isLength(value) {
  10986. return typeof value == 'number' &&
  10987. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10988. }
  10989. /**
  10990. * Checks if `value` is the
  10991. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10992. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10993. *
  10994. * @static
  10995. * @memberOf _
  10996. * @since 0.1.0
  10997. * @category Lang
  10998. * @param {*} value The value to check.
  10999. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11000. * @example
  11001. *
  11002. * _.isObject({});
  11003. * // => true
  11004. *
  11005. * _.isObject([1, 2, 3]);
  11006. * // => true
  11007. *
  11008. * _.isObject(_.noop);
  11009. * // => true
  11010. *
  11011. * _.isObject(null);
  11012. * // => false
  11013. */
  11014. function isObject(value) {
  11015. var type = typeof value;
  11016. return value != null && (type == 'object' || type == 'function');
  11017. }
  11018. /**
  11019. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11020. * and has a `typeof` result of "object".
  11021. *
  11022. * @static
  11023. * @memberOf _
  11024. * @since 4.0.0
  11025. * @category Lang
  11026. * @param {*} value The value to check.
  11027. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11028. * @example
  11029. *
  11030. * _.isObjectLike({});
  11031. * // => true
  11032. *
  11033. * _.isObjectLike([1, 2, 3]);
  11034. * // => true
  11035. *
  11036. * _.isObjectLike(_.noop);
  11037. * // => false
  11038. *
  11039. * _.isObjectLike(null);
  11040. * // => false
  11041. */
  11042. function isObjectLike(value) {
  11043. return value != null && typeof value == 'object';
  11044. }
  11045. /**
  11046. * Checks if `value` is classified as a `Map` object.
  11047. *
  11048. * @static
  11049. * @memberOf _
  11050. * @since 4.3.0
  11051. * @category Lang
  11052. * @param {*} value The value to check.
  11053. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11054. * @example
  11055. *
  11056. * _.isMap(new Map);
  11057. * // => true
  11058. *
  11059. * _.isMap(new WeakMap);
  11060. * // => false
  11061. */
  11062. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11063. /**
  11064. * Performs a partial deep comparison between `object` and `source` to
  11065. * determine if `object` contains equivalent property values.
  11066. *
  11067. * **Note:** This method is equivalent to `_.matches` when `source` is
  11068. * partially applied.
  11069. *
  11070. * Partial comparisons will match empty array and empty object `source`
  11071. * values against any array or object value, respectively. See `_.isEqual`
  11072. * for a list of supported value comparisons.
  11073. *
  11074. * @static
  11075. * @memberOf _
  11076. * @since 3.0.0
  11077. * @category Lang
  11078. * @param {Object} object The object to inspect.
  11079. * @param {Object} source The object of property values to match.
  11080. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11081. * @example
  11082. *
  11083. * var object = { 'a': 1, 'b': 2 };
  11084. *
  11085. * _.isMatch(object, { 'b': 2 });
  11086. * // => true
  11087. *
  11088. * _.isMatch(object, { 'b': 1 });
  11089. * // => false
  11090. */
  11091. function isMatch(object, source) {
  11092. return object === source || baseIsMatch(object, source, getMatchData(source));
  11093. }
  11094. /**
  11095. * This method is like `_.isMatch` except that it accepts `customizer` which
  11096. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11097. * are handled by the method instead. The `customizer` is invoked with five
  11098. * arguments: (objValue, srcValue, index|key, object, source).
  11099. *
  11100. * @static
  11101. * @memberOf _
  11102. * @since 4.0.0
  11103. * @category Lang
  11104. * @param {Object} object The object to inspect.
  11105. * @param {Object} source The object of property values to match.
  11106. * @param {Function} [customizer] The function to customize comparisons.
  11107. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11108. * @example
  11109. *
  11110. * function isGreeting(value) {
  11111. * return /^h(?:i|ello)$/.test(value);
  11112. * }
  11113. *
  11114. * function customizer(objValue, srcValue) {
  11115. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11116. * return true;
  11117. * }
  11118. * }
  11119. *
  11120. * var object = { 'greeting': 'hello' };
  11121. * var source = { 'greeting': 'hi' };
  11122. *
  11123. * _.isMatchWith(object, source, customizer);
  11124. * // => true
  11125. */
  11126. function isMatchWith(object, source, customizer) {
  11127. customizer = typeof customizer == 'function' ? customizer : undefined;
  11128. return baseIsMatch(object, source, getMatchData(source), customizer);
  11129. }
  11130. /**
  11131. * Checks if `value` is `NaN`.
  11132. *
  11133. * **Note:** This method is based on
  11134. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11135. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11136. * `undefined` and other non-number values.
  11137. *
  11138. * @static
  11139. * @memberOf _
  11140. * @since 0.1.0
  11141. * @category Lang
  11142. * @param {*} value The value to check.
  11143. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11144. * @example
  11145. *
  11146. * _.isNaN(NaN);
  11147. * // => true
  11148. *
  11149. * _.isNaN(new Number(NaN));
  11150. * // => true
  11151. *
  11152. * isNaN(undefined);
  11153. * // => true
  11154. *
  11155. * _.isNaN(undefined);
  11156. * // => false
  11157. */
  11158. function isNaN(value) {
  11159. // An `NaN` primitive is the only value that is not equal to itself.
  11160. // Perform the `toStringTag` check first to avoid errors with some
  11161. // ActiveX objects in IE.
  11162. return isNumber(value) && value != +value;
  11163. }
  11164. /**
  11165. * Checks if `value` is a pristine native function.
  11166. *
  11167. * **Note:** This method can't reliably detect native functions in the presence
  11168. * of the core-js package because core-js circumvents this kind of detection.
  11169. * Despite multiple requests, the core-js maintainer has made it clear: any
  11170. * attempt to fix the detection will be obstructed. As a result, we're left
  11171. * with little choice but to throw an error. Unfortunately, this also affects
  11172. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11173. * which rely on core-js.
  11174. *
  11175. * @static
  11176. * @memberOf _
  11177. * @since 3.0.0
  11178. * @category Lang
  11179. * @param {*} value The value to check.
  11180. * @returns {boolean} Returns `true` if `value` is a native function,
  11181. * else `false`.
  11182. * @example
  11183. *
  11184. * _.isNative(Array.prototype.push);
  11185. * // => true
  11186. *
  11187. * _.isNative(_);
  11188. * // => false
  11189. */
  11190. function isNative(value) {
  11191. if (isMaskable(value)) {
  11192. throw new Error(CORE_ERROR_TEXT);
  11193. }
  11194. return baseIsNative(value);
  11195. }
  11196. /**
  11197. * Checks if `value` is `null`.
  11198. *
  11199. * @static
  11200. * @memberOf _
  11201. * @since 0.1.0
  11202. * @category Lang
  11203. * @param {*} value The value to check.
  11204. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11205. * @example
  11206. *
  11207. * _.isNull(null);
  11208. * // => true
  11209. *
  11210. * _.isNull(void 0);
  11211. * // => false
  11212. */
  11213. function isNull(value) {
  11214. return value === null;
  11215. }
  11216. /**
  11217. * Checks if `value` is `null` or `undefined`.
  11218. *
  11219. * @static
  11220. * @memberOf _
  11221. * @since 4.0.0
  11222. * @category Lang
  11223. * @param {*} value The value to check.
  11224. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11225. * @example
  11226. *
  11227. * _.isNil(null);
  11228. * // => true
  11229. *
  11230. * _.isNil(void 0);
  11231. * // => true
  11232. *
  11233. * _.isNil(NaN);
  11234. * // => false
  11235. */
  11236. function isNil(value) {
  11237. return value == null;
  11238. }
  11239. /**
  11240. * Checks if `value` is classified as a `Number` primitive or object.
  11241. *
  11242. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11243. * classified as numbers, use the `_.isFinite` method.
  11244. *
  11245. * @static
  11246. * @memberOf _
  11247. * @since 0.1.0
  11248. * @category Lang
  11249. * @param {*} value The value to check.
  11250. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11251. * @example
  11252. *
  11253. * _.isNumber(3);
  11254. * // => true
  11255. *
  11256. * _.isNumber(Number.MIN_VALUE);
  11257. * // => true
  11258. *
  11259. * _.isNumber(Infinity);
  11260. * // => true
  11261. *
  11262. * _.isNumber('3');
  11263. * // => false
  11264. */
  11265. function isNumber(value) {
  11266. return typeof value == 'number' ||
  11267. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11268. }
  11269. /**
  11270. * Checks if `value` is a plain object, that is, an object created by the
  11271. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11272. *
  11273. * @static
  11274. * @memberOf _
  11275. * @since 0.8.0
  11276. * @category Lang
  11277. * @param {*} value The value to check.
  11278. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11279. * @example
  11280. *
  11281. * function Foo() {
  11282. * this.a = 1;
  11283. * }
  11284. *
  11285. * _.isPlainObject(new Foo);
  11286. * // => false
  11287. *
  11288. * _.isPlainObject([1, 2, 3]);
  11289. * // => false
  11290. *
  11291. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11292. * // => true
  11293. *
  11294. * _.isPlainObject(Object.create(null));
  11295. * // => true
  11296. */
  11297. function isPlainObject(value) {
  11298. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11299. return false;
  11300. }
  11301. var proto = getPrototype(value);
  11302. if (proto === null) {
  11303. return true;
  11304. }
  11305. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11306. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11307. funcToString.call(Ctor) == objectCtorString;
  11308. }
  11309. /**
  11310. * Checks if `value` is classified as a `RegExp` object.
  11311. *
  11312. * @static
  11313. * @memberOf _
  11314. * @since 0.1.0
  11315. * @category Lang
  11316. * @param {*} value The value to check.
  11317. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11318. * @example
  11319. *
  11320. * _.isRegExp(/abc/);
  11321. * // => true
  11322. *
  11323. * _.isRegExp('/abc/');
  11324. * // => false
  11325. */
  11326. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11327. /**
  11328. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11329. * double precision number which isn't the result of a rounded unsafe integer.
  11330. *
  11331. * **Note:** This method is based on
  11332. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11333. *
  11334. * @static
  11335. * @memberOf _
  11336. * @since 4.0.0
  11337. * @category Lang
  11338. * @param {*} value The value to check.
  11339. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11340. * @example
  11341. *
  11342. * _.isSafeInteger(3);
  11343. * // => true
  11344. *
  11345. * _.isSafeInteger(Number.MIN_VALUE);
  11346. * // => false
  11347. *
  11348. * _.isSafeInteger(Infinity);
  11349. * // => false
  11350. *
  11351. * _.isSafeInteger('3');
  11352. * // => false
  11353. */
  11354. function isSafeInteger(value) {
  11355. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11356. }
  11357. /**
  11358. * Checks if `value` is classified as a `Set` object.
  11359. *
  11360. * @static
  11361. * @memberOf _
  11362. * @since 4.3.0
  11363. * @category Lang
  11364. * @param {*} value The value to check.
  11365. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11366. * @example
  11367. *
  11368. * _.isSet(new Set);
  11369. * // => true
  11370. *
  11371. * _.isSet(new WeakSet);
  11372. * // => false
  11373. */
  11374. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11375. /**
  11376. * Checks if `value` is classified as a `String` primitive or object.
  11377. *
  11378. * @static
  11379. * @since 0.1.0
  11380. * @memberOf _
  11381. * @category Lang
  11382. * @param {*} value The value to check.
  11383. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11384. * @example
  11385. *
  11386. * _.isString('abc');
  11387. * // => true
  11388. *
  11389. * _.isString(1);
  11390. * // => false
  11391. */
  11392. function isString(value) {
  11393. return typeof value == 'string' ||
  11394. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11395. }
  11396. /**
  11397. * Checks if `value` is classified as a `Symbol` primitive or object.
  11398. *
  11399. * @static
  11400. * @memberOf _
  11401. * @since 4.0.0
  11402. * @category Lang
  11403. * @param {*} value The value to check.
  11404. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11405. * @example
  11406. *
  11407. * _.isSymbol(Symbol.iterator);
  11408. * // => true
  11409. *
  11410. * _.isSymbol('abc');
  11411. * // => false
  11412. */
  11413. function isSymbol(value) {
  11414. return typeof value == 'symbol' ||
  11415. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11416. }
  11417. /**
  11418. * Checks if `value` is classified as a typed array.
  11419. *
  11420. * @static
  11421. * @memberOf _
  11422. * @since 3.0.0
  11423. * @category Lang
  11424. * @param {*} value The value to check.
  11425. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11426. * @example
  11427. *
  11428. * _.isTypedArray(new Uint8Array);
  11429. * // => true
  11430. *
  11431. * _.isTypedArray([]);
  11432. * // => false
  11433. */
  11434. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11435. /**
  11436. * Checks if `value` is `undefined`.
  11437. *
  11438. * @static
  11439. * @since 0.1.0
  11440. * @memberOf _
  11441. * @category Lang
  11442. * @param {*} value The value to check.
  11443. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11444. * @example
  11445. *
  11446. * _.isUndefined(void 0);
  11447. * // => true
  11448. *
  11449. * _.isUndefined(null);
  11450. * // => false
  11451. */
  11452. function isUndefined(value) {
  11453. return value === undefined;
  11454. }
  11455. /**
  11456. * Checks if `value` is classified as a `WeakMap` object.
  11457. *
  11458. * @static
  11459. * @memberOf _
  11460. * @since 4.3.0
  11461. * @category Lang
  11462. * @param {*} value The value to check.
  11463. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11464. * @example
  11465. *
  11466. * _.isWeakMap(new WeakMap);
  11467. * // => true
  11468. *
  11469. * _.isWeakMap(new Map);
  11470. * // => false
  11471. */
  11472. function isWeakMap(value) {
  11473. return isObjectLike(value) && getTag(value) == weakMapTag;
  11474. }
  11475. /**
  11476. * Checks if `value` is classified as a `WeakSet` object.
  11477. *
  11478. * @static
  11479. * @memberOf _
  11480. * @since 4.3.0
  11481. * @category Lang
  11482. * @param {*} value The value to check.
  11483. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11484. * @example
  11485. *
  11486. * _.isWeakSet(new WeakSet);
  11487. * // => true
  11488. *
  11489. * _.isWeakSet(new Set);
  11490. * // => false
  11491. */
  11492. function isWeakSet(value) {
  11493. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11494. }
  11495. /**
  11496. * Checks if `value` is less than `other`.
  11497. *
  11498. * @static
  11499. * @memberOf _
  11500. * @since 3.9.0
  11501. * @category Lang
  11502. * @param {*} value The value to compare.
  11503. * @param {*} other The other value to compare.
  11504. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11505. * else `false`.
  11506. * @see _.gt
  11507. * @example
  11508. *
  11509. * _.lt(1, 3);
  11510. * // => true
  11511. *
  11512. * _.lt(3, 3);
  11513. * // => false
  11514. *
  11515. * _.lt(3, 1);
  11516. * // => false
  11517. */
  11518. var lt = createRelationalOperation(baseLt);
  11519. /**
  11520. * Checks if `value` is less than or equal to `other`.
  11521. *
  11522. * @static
  11523. * @memberOf _
  11524. * @since 3.9.0
  11525. * @category Lang
  11526. * @param {*} value The value to compare.
  11527. * @param {*} other The other value to compare.
  11528. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11529. * `other`, else `false`.
  11530. * @see _.gte
  11531. * @example
  11532. *
  11533. * _.lte(1, 3);
  11534. * // => true
  11535. *
  11536. * _.lte(3, 3);
  11537. * // => true
  11538. *
  11539. * _.lte(3, 1);
  11540. * // => false
  11541. */
  11542. var lte = createRelationalOperation(function(value, other) {
  11543. return value <= other;
  11544. });
  11545. /**
  11546. * Converts `value` to an array.
  11547. *
  11548. * @static
  11549. * @since 0.1.0
  11550. * @memberOf _
  11551. * @category Lang
  11552. * @param {*} value The value to convert.
  11553. * @returns {Array} Returns the converted array.
  11554. * @example
  11555. *
  11556. * _.toArray({ 'a': 1, 'b': 2 });
  11557. * // => [1, 2]
  11558. *
  11559. * _.toArray('abc');
  11560. * // => ['a', 'b', 'c']
  11561. *
  11562. * _.toArray(1);
  11563. * // => []
  11564. *
  11565. * _.toArray(null);
  11566. * // => []
  11567. */
  11568. function toArray(value) {
  11569. if (!value) {
  11570. return [];
  11571. }
  11572. if (isArrayLike(value)) {
  11573. return isString(value) ? stringToArray(value) : copyArray(value);
  11574. }
  11575. if (symIterator && value[symIterator]) {
  11576. return iteratorToArray(value[symIterator]());
  11577. }
  11578. var tag = getTag(value),
  11579. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11580. return func(value);
  11581. }
  11582. /**
  11583. * Converts `value` to a finite number.
  11584. *
  11585. * @static
  11586. * @memberOf _
  11587. * @since 4.12.0
  11588. * @category Lang
  11589. * @param {*} value The value to convert.
  11590. * @returns {number} Returns the converted number.
  11591. * @example
  11592. *
  11593. * _.toFinite(3.2);
  11594. * // => 3.2
  11595. *
  11596. * _.toFinite(Number.MIN_VALUE);
  11597. * // => 5e-324
  11598. *
  11599. * _.toFinite(Infinity);
  11600. * // => 1.7976931348623157e+308
  11601. *
  11602. * _.toFinite('3.2');
  11603. * // => 3.2
  11604. */
  11605. function toFinite(value) {
  11606. if (!value) {
  11607. return value === 0 ? value : 0;
  11608. }
  11609. value = toNumber(value);
  11610. if (value === INFINITY || value === -INFINITY) {
  11611. var sign = (value < 0 ? -1 : 1);
  11612. return sign * MAX_INTEGER;
  11613. }
  11614. return value === value ? value : 0;
  11615. }
  11616. /**
  11617. * Converts `value` to an integer.
  11618. *
  11619. * **Note:** This method is loosely based on
  11620. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11621. *
  11622. * @static
  11623. * @memberOf _
  11624. * @since 4.0.0
  11625. * @category Lang
  11626. * @param {*} value The value to convert.
  11627. * @returns {number} Returns the converted integer.
  11628. * @example
  11629. *
  11630. * _.toInteger(3.2);
  11631. * // => 3
  11632. *
  11633. * _.toInteger(Number.MIN_VALUE);
  11634. * // => 0
  11635. *
  11636. * _.toInteger(Infinity);
  11637. * // => 1.7976931348623157e+308
  11638. *
  11639. * _.toInteger('3.2');
  11640. * // => 3
  11641. */
  11642. function toInteger(value) {
  11643. var result = toFinite(value),
  11644. remainder = result % 1;
  11645. return result === result ? (remainder ? result - remainder : result) : 0;
  11646. }
  11647. /**
  11648. * Converts `value` to an integer suitable for use as the length of an
  11649. * array-like object.
  11650. *
  11651. * **Note:** This method is based on
  11652. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11653. *
  11654. * @static
  11655. * @memberOf _
  11656. * @since 4.0.0
  11657. * @category Lang
  11658. * @param {*} value The value to convert.
  11659. * @returns {number} Returns the converted integer.
  11660. * @example
  11661. *
  11662. * _.toLength(3.2);
  11663. * // => 3
  11664. *
  11665. * _.toLength(Number.MIN_VALUE);
  11666. * // => 0
  11667. *
  11668. * _.toLength(Infinity);
  11669. * // => 4294967295
  11670. *
  11671. * _.toLength('3.2');
  11672. * // => 3
  11673. */
  11674. function toLength(value) {
  11675. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11676. }
  11677. /**
  11678. * Converts `value` to a number.
  11679. *
  11680. * @static
  11681. * @memberOf _
  11682. * @since 4.0.0
  11683. * @category Lang
  11684. * @param {*} value The value to process.
  11685. * @returns {number} Returns the number.
  11686. * @example
  11687. *
  11688. * _.toNumber(3.2);
  11689. * // => 3.2
  11690. *
  11691. * _.toNumber(Number.MIN_VALUE);
  11692. * // => 5e-324
  11693. *
  11694. * _.toNumber(Infinity);
  11695. * // => Infinity
  11696. *
  11697. * _.toNumber('3.2');
  11698. * // => 3.2
  11699. */
  11700. function toNumber(value) {
  11701. if (typeof value == 'number') {
  11702. return value;
  11703. }
  11704. if (isSymbol(value)) {
  11705. return NAN;
  11706. }
  11707. if (isObject(value)) {
  11708. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11709. value = isObject(other) ? (other + '') : other;
  11710. }
  11711. if (typeof value != 'string') {
  11712. return value === 0 ? value : +value;
  11713. }
  11714. value = baseTrim(value);
  11715. var isBinary = reIsBinary.test(value);
  11716. return (isBinary || reIsOctal.test(value))
  11717. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11718. : (reIsBadHex.test(value) ? NAN : +value);
  11719. }
  11720. /**
  11721. * Converts `value` to a plain object flattening inherited enumerable string
  11722. * keyed properties of `value` to own properties of the plain object.
  11723. *
  11724. * @static
  11725. * @memberOf _
  11726. * @since 3.0.0
  11727. * @category Lang
  11728. * @param {*} value The value to convert.
  11729. * @returns {Object} Returns the converted plain object.
  11730. * @example
  11731. *
  11732. * function Foo() {
  11733. * this.b = 2;
  11734. * }
  11735. *
  11736. * Foo.prototype.c = 3;
  11737. *
  11738. * _.assign({ 'a': 1 }, new Foo);
  11739. * // => { 'a': 1, 'b': 2 }
  11740. *
  11741. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11742. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11743. */
  11744. function toPlainObject(value) {
  11745. return copyObject(value, keysIn(value));
  11746. }
  11747. /**
  11748. * Converts `value` to a safe integer. A safe integer can be compared and
  11749. * represented correctly.
  11750. *
  11751. * @static
  11752. * @memberOf _
  11753. * @since 4.0.0
  11754. * @category Lang
  11755. * @param {*} value The value to convert.
  11756. * @returns {number} Returns the converted integer.
  11757. * @example
  11758. *
  11759. * _.toSafeInteger(3.2);
  11760. * // => 3
  11761. *
  11762. * _.toSafeInteger(Number.MIN_VALUE);
  11763. * // => 0
  11764. *
  11765. * _.toSafeInteger(Infinity);
  11766. * // => 9007199254740991
  11767. *
  11768. * _.toSafeInteger('3.2');
  11769. * // => 3
  11770. */
  11771. function toSafeInteger(value) {
  11772. return value
  11773. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11774. : (value === 0 ? value : 0);
  11775. }
  11776. /**
  11777. * Converts `value` to a string. An empty string is returned for `null`
  11778. * and `undefined` values. The sign of `-0` is preserved.
  11779. *
  11780. * @static
  11781. * @memberOf _
  11782. * @since 4.0.0
  11783. * @category Lang
  11784. * @param {*} value The value to convert.
  11785. * @returns {string} Returns the converted string.
  11786. * @example
  11787. *
  11788. * _.toString(null);
  11789. * // => ''
  11790. *
  11791. * _.toString(-0);
  11792. * // => '-0'
  11793. *
  11794. * _.toString([1, 2, 3]);
  11795. * // => '1,2,3'
  11796. */
  11797. function toString(value) {
  11798. return value == null ? '' : baseToString(value);
  11799. }
  11800. /*------------------------------------------------------------------------*/
  11801. /**
  11802. * Assigns own enumerable string keyed properties of source objects to the
  11803. * destination object. Source objects are applied from left to right.
  11804. * Subsequent sources overwrite property assignments of previous sources.
  11805. *
  11806. * **Note:** This method mutates `object` and is loosely based on
  11807. * [`Object.assign`](https://mdn.io/Object/assign).
  11808. *
  11809. * @static
  11810. * @memberOf _
  11811. * @since 0.10.0
  11812. * @category Object
  11813. * @param {Object} object The destination object.
  11814. * @param {...Object} [sources] The source objects.
  11815. * @returns {Object} Returns `object`.
  11816. * @see _.assignIn
  11817. * @example
  11818. *
  11819. * function Foo() {
  11820. * this.a = 1;
  11821. * }
  11822. *
  11823. * function Bar() {
  11824. * this.c = 3;
  11825. * }
  11826. *
  11827. * Foo.prototype.b = 2;
  11828. * Bar.prototype.d = 4;
  11829. *
  11830. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11831. * // => { 'a': 1, 'c': 3 }
  11832. */
  11833. var assign = createAssigner(function(object, source) {
  11834. if (isPrototype(source) || isArrayLike(source)) {
  11835. copyObject(source, keys(source), object);
  11836. return;
  11837. }
  11838. for (var key in source) {
  11839. if (hasOwnProperty.call(source, key)) {
  11840. assignValue(object, key, source[key]);
  11841. }
  11842. }
  11843. });
  11844. /**
  11845. * This method is like `_.assign` except that it iterates over own and
  11846. * inherited source properties.
  11847. *
  11848. * **Note:** This method mutates `object`.
  11849. *
  11850. * @static
  11851. * @memberOf _
  11852. * @since 4.0.0
  11853. * @alias extend
  11854. * @category Object
  11855. * @param {Object} object The destination object.
  11856. * @param {...Object} [sources] The source objects.
  11857. * @returns {Object} Returns `object`.
  11858. * @see _.assign
  11859. * @example
  11860. *
  11861. * function Foo() {
  11862. * this.a = 1;
  11863. * }
  11864. *
  11865. * function Bar() {
  11866. * this.c = 3;
  11867. * }
  11868. *
  11869. * Foo.prototype.b = 2;
  11870. * Bar.prototype.d = 4;
  11871. *
  11872. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11873. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11874. */
  11875. var assignIn = createAssigner(function(object, source) {
  11876. copyObject(source, keysIn(source), object);
  11877. });
  11878. /**
  11879. * This method is like `_.assignIn` except that it accepts `customizer`
  11880. * which is invoked to produce the assigned values. If `customizer` returns
  11881. * `undefined`, assignment is handled by the method instead. The `customizer`
  11882. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11883. *
  11884. * **Note:** This method mutates `object`.
  11885. *
  11886. * @static
  11887. * @memberOf _
  11888. * @since 4.0.0
  11889. * @alias extendWith
  11890. * @category Object
  11891. * @param {Object} object The destination object.
  11892. * @param {...Object} sources The source objects.
  11893. * @param {Function} [customizer] The function to customize assigned values.
  11894. * @returns {Object} Returns `object`.
  11895. * @see _.assignWith
  11896. * @example
  11897. *
  11898. * function customizer(objValue, srcValue) {
  11899. * return _.isUndefined(objValue) ? srcValue : objValue;
  11900. * }
  11901. *
  11902. * var defaults = _.partialRight(_.assignInWith, customizer);
  11903. *
  11904. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11905. * // => { 'a': 1, 'b': 2 }
  11906. */
  11907. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11908. copyObject(source, keysIn(source), object, customizer);
  11909. });
  11910. /**
  11911. * This method is like `_.assign` except that it accepts `customizer`
  11912. * which is invoked to produce the assigned values. If `customizer` returns
  11913. * `undefined`, assignment is handled by the method instead. The `customizer`
  11914. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11915. *
  11916. * **Note:** This method mutates `object`.
  11917. *
  11918. * @static
  11919. * @memberOf _
  11920. * @since 4.0.0
  11921. * @category Object
  11922. * @param {Object} object The destination object.
  11923. * @param {...Object} sources The source objects.
  11924. * @param {Function} [customizer] The function to customize assigned values.
  11925. * @returns {Object} Returns `object`.
  11926. * @see _.assignInWith
  11927. * @example
  11928. *
  11929. * function customizer(objValue, srcValue) {
  11930. * return _.isUndefined(objValue) ? srcValue : objValue;
  11931. * }
  11932. *
  11933. * var defaults = _.partialRight(_.assignWith, customizer);
  11934. *
  11935. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11936. * // => { 'a': 1, 'b': 2 }
  11937. */
  11938. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11939. copyObject(source, keys(source), object, customizer);
  11940. });
  11941. /**
  11942. * Creates an array of values corresponding to `paths` of `object`.
  11943. *
  11944. * @static
  11945. * @memberOf _
  11946. * @since 1.0.0
  11947. * @category Object
  11948. * @param {Object} object The object to iterate over.
  11949. * @param {...(string|string[])} [paths] The property paths to pick.
  11950. * @returns {Array} Returns the picked values.
  11951. * @example
  11952. *
  11953. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11954. *
  11955. * _.at(object, ['a[0].b.c', 'a[1]']);
  11956. * // => [3, 4]
  11957. */
  11958. var at = flatRest(baseAt);
  11959. /**
  11960. * Creates an object that inherits from the `prototype` object. If a
  11961. * `properties` object is given, its own enumerable string keyed properties
  11962. * are assigned to the created object.
  11963. *
  11964. * @static
  11965. * @memberOf _
  11966. * @since 2.3.0
  11967. * @category Object
  11968. * @param {Object} prototype The object to inherit from.
  11969. * @param {Object} [properties] The properties to assign to the object.
  11970. * @returns {Object} Returns the new object.
  11971. * @example
  11972. *
  11973. * function Shape() {
  11974. * this.x = 0;
  11975. * this.y = 0;
  11976. * }
  11977. *
  11978. * function Circle() {
  11979. * Shape.call(this);
  11980. * }
  11981. *
  11982. * Circle.prototype = _.create(Shape.prototype, {
  11983. * 'constructor': Circle
  11984. * });
  11985. *
  11986. * var circle = new Circle;
  11987. * circle instanceof Circle;
  11988. * // => true
  11989. *
  11990. * circle instanceof Shape;
  11991. * // => true
  11992. */
  11993. function create(prototype, properties) {
  11994. var result = baseCreate(prototype);
  11995. return properties == null ? result : baseAssign(result, properties);
  11996. }
  11997. /**
  11998. * Assigns own and inherited enumerable string keyed properties of source
  11999. * objects to the destination object for all destination properties that
  12000. * resolve to `undefined`. Source objects are applied from left to right.
  12001. * Once a property is set, additional values of the same property are ignored.
  12002. *
  12003. * **Note:** This method mutates `object`.
  12004. *
  12005. * @static
  12006. * @since 0.1.0
  12007. * @memberOf _
  12008. * @category Object
  12009. * @param {Object} object The destination object.
  12010. * @param {...Object} [sources] The source objects.
  12011. * @returns {Object} Returns `object`.
  12012. * @see _.defaultsDeep
  12013. * @example
  12014. *
  12015. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12016. * // => { 'a': 1, 'b': 2 }
  12017. */
  12018. var defaults = baseRest(function(object, sources) {
  12019. object = Object(object);
  12020. var index = -1;
  12021. var length = sources.length;
  12022. var guard = length > 2 ? sources[2] : undefined;
  12023. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  12024. length = 1;
  12025. }
  12026. while (++index < length) {
  12027. var source = sources[index];
  12028. var props = keysIn(source);
  12029. var propsIndex = -1;
  12030. var propsLength = props.length;
  12031. while (++propsIndex < propsLength) {
  12032. var key = props[propsIndex];
  12033. var value = object[key];
  12034. if (value === undefined ||
  12035. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  12036. object[key] = source[key];
  12037. }
  12038. }
  12039. }
  12040. return object;
  12041. });
  12042. /**
  12043. * This method is like `_.defaults` except that it recursively assigns
  12044. * default properties.
  12045. *
  12046. * **Note:** This method mutates `object`.
  12047. *
  12048. * @static
  12049. * @memberOf _
  12050. * @since 3.10.0
  12051. * @category Object
  12052. * @param {Object} object The destination object.
  12053. * @param {...Object} [sources] The source objects.
  12054. * @returns {Object} Returns `object`.
  12055. * @see _.defaults
  12056. * @example
  12057. *
  12058. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12059. * // => { 'a': { 'b': 2, 'c': 3 } }
  12060. */
  12061. var defaultsDeep = baseRest(function(args) {
  12062. args.push(undefined, customDefaultsMerge);
  12063. return apply(mergeWith, undefined, args);
  12064. });
  12065. /**
  12066. * This method is like `_.find` except that it returns the key of the first
  12067. * element `predicate` returns truthy for instead of the element itself.
  12068. *
  12069. * @static
  12070. * @memberOf _
  12071. * @since 1.1.0
  12072. * @category Object
  12073. * @param {Object} object The object to inspect.
  12074. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12075. * @returns {string|undefined} Returns the key of the matched element,
  12076. * else `undefined`.
  12077. * @example
  12078. *
  12079. * var users = {
  12080. * 'barney': { 'age': 36, 'active': true },
  12081. * 'fred': { 'age': 40, 'active': false },
  12082. * 'pebbles': { 'age': 1, 'active': true }
  12083. * };
  12084. *
  12085. * _.findKey(users, function(o) { return o.age < 40; });
  12086. * // => 'barney' (iteration order is not guaranteed)
  12087. *
  12088. * // The `_.matches` iteratee shorthand.
  12089. * _.findKey(users, { 'age': 1, 'active': true });
  12090. * // => 'pebbles'
  12091. *
  12092. * // The `_.matchesProperty` iteratee shorthand.
  12093. * _.findKey(users, ['active', false]);
  12094. * // => 'fred'
  12095. *
  12096. * // The `_.property` iteratee shorthand.
  12097. * _.findKey(users, 'active');
  12098. * // => 'barney'
  12099. */
  12100. function findKey(object, predicate) {
  12101. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12102. }
  12103. /**
  12104. * This method is like `_.findKey` except that it iterates over elements of
  12105. * a collection in the opposite order.
  12106. *
  12107. * @static
  12108. * @memberOf _
  12109. * @since 2.0.0
  12110. * @category Object
  12111. * @param {Object} object The object to inspect.
  12112. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12113. * @returns {string|undefined} Returns the key of the matched element,
  12114. * else `undefined`.
  12115. * @example
  12116. *
  12117. * var users = {
  12118. * 'barney': { 'age': 36, 'active': true },
  12119. * 'fred': { 'age': 40, 'active': false },
  12120. * 'pebbles': { 'age': 1, 'active': true }
  12121. * };
  12122. *
  12123. * _.findLastKey(users, function(o) { return o.age < 40; });
  12124. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12125. *
  12126. * // The `_.matches` iteratee shorthand.
  12127. * _.findLastKey(users, { 'age': 36, 'active': true });
  12128. * // => 'barney'
  12129. *
  12130. * // The `_.matchesProperty` iteratee shorthand.
  12131. * _.findLastKey(users, ['active', false]);
  12132. * // => 'fred'
  12133. *
  12134. * // The `_.property` iteratee shorthand.
  12135. * _.findLastKey(users, 'active');
  12136. * // => 'pebbles'
  12137. */
  12138. function findLastKey(object, predicate) {
  12139. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12140. }
  12141. /**
  12142. * Iterates over own and inherited enumerable string keyed properties of an
  12143. * object and invokes `iteratee` for each property. The iteratee is invoked
  12144. * with three arguments: (value, key, object). Iteratee functions may exit
  12145. * iteration early by explicitly returning `false`.
  12146. *
  12147. * @static
  12148. * @memberOf _
  12149. * @since 0.3.0
  12150. * @category Object
  12151. * @param {Object} object The object to iterate over.
  12152. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12153. * @returns {Object} Returns `object`.
  12154. * @see _.forInRight
  12155. * @example
  12156. *
  12157. * function Foo() {
  12158. * this.a = 1;
  12159. * this.b = 2;
  12160. * }
  12161. *
  12162. * Foo.prototype.c = 3;
  12163. *
  12164. * _.forIn(new Foo, function(value, key) {
  12165. * console.log(key);
  12166. * });
  12167. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12168. */
  12169. function forIn(object, iteratee) {
  12170. return object == null
  12171. ? object
  12172. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12173. }
  12174. /**
  12175. * This method is like `_.forIn` except that it iterates over properties of
  12176. * `object` in the opposite order.
  12177. *
  12178. * @static
  12179. * @memberOf _
  12180. * @since 2.0.0
  12181. * @category Object
  12182. * @param {Object} object The object to iterate over.
  12183. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12184. * @returns {Object} Returns `object`.
  12185. * @see _.forIn
  12186. * @example
  12187. *
  12188. * function Foo() {
  12189. * this.a = 1;
  12190. * this.b = 2;
  12191. * }
  12192. *
  12193. * Foo.prototype.c = 3;
  12194. *
  12195. * _.forInRight(new Foo, function(value, key) {
  12196. * console.log(key);
  12197. * });
  12198. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12199. */
  12200. function forInRight(object, iteratee) {
  12201. return object == null
  12202. ? object
  12203. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12204. }
  12205. /**
  12206. * Iterates over own enumerable string keyed properties of an object and
  12207. * invokes `iteratee` for each property. The iteratee is invoked with three
  12208. * arguments: (value, key, object). Iteratee functions may exit iteration
  12209. * early by explicitly returning `false`.
  12210. *
  12211. * @static
  12212. * @memberOf _
  12213. * @since 0.3.0
  12214. * @category Object
  12215. * @param {Object} object The object to iterate over.
  12216. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12217. * @returns {Object} Returns `object`.
  12218. * @see _.forOwnRight
  12219. * @example
  12220. *
  12221. * function Foo() {
  12222. * this.a = 1;
  12223. * this.b = 2;
  12224. * }
  12225. *
  12226. * Foo.prototype.c = 3;
  12227. *
  12228. * _.forOwn(new Foo, function(value, key) {
  12229. * console.log(key);
  12230. * });
  12231. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12232. */
  12233. function forOwn(object, iteratee) {
  12234. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12235. }
  12236. /**
  12237. * This method is like `_.forOwn` except that it iterates over properties of
  12238. * `object` in the opposite order.
  12239. *
  12240. * @static
  12241. * @memberOf _
  12242. * @since 2.0.0
  12243. * @category Object
  12244. * @param {Object} object The object to iterate over.
  12245. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12246. * @returns {Object} Returns `object`.
  12247. * @see _.forOwn
  12248. * @example
  12249. *
  12250. * function Foo() {
  12251. * this.a = 1;
  12252. * this.b = 2;
  12253. * }
  12254. *
  12255. * Foo.prototype.c = 3;
  12256. *
  12257. * _.forOwnRight(new Foo, function(value, key) {
  12258. * console.log(key);
  12259. * });
  12260. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12261. */
  12262. function forOwnRight(object, iteratee) {
  12263. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12264. }
  12265. /**
  12266. * Creates an array of function property names from own enumerable properties
  12267. * of `object`.
  12268. *
  12269. * @static
  12270. * @since 0.1.0
  12271. * @memberOf _
  12272. * @category Object
  12273. * @param {Object} object The object to inspect.
  12274. * @returns {Array} Returns the function names.
  12275. * @see _.functionsIn
  12276. * @example
  12277. *
  12278. * function Foo() {
  12279. * this.a = _.constant('a');
  12280. * this.b = _.constant('b');
  12281. * }
  12282. *
  12283. * Foo.prototype.c = _.constant('c');
  12284. *
  12285. * _.functions(new Foo);
  12286. * // => ['a', 'b']
  12287. */
  12288. function functions(object) {
  12289. return object == null ? [] : baseFunctions(object, keys(object));
  12290. }
  12291. /**
  12292. * Creates an array of function property names from own and inherited
  12293. * enumerable properties of `object`.
  12294. *
  12295. * @static
  12296. * @memberOf _
  12297. * @since 4.0.0
  12298. * @category Object
  12299. * @param {Object} object The object to inspect.
  12300. * @returns {Array} Returns the function names.
  12301. * @see _.functions
  12302. * @example
  12303. *
  12304. * function Foo() {
  12305. * this.a = _.constant('a');
  12306. * this.b = _.constant('b');
  12307. * }
  12308. *
  12309. * Foo.prototype.c = _.constant('c');
  12310. *
  12311. * _.functionsIn(new Foo);
  12312. * // => ['a', 'b', 'c']
  12313. */
  12314. function functionsIn(object) {
  12315. return object == null ? [] : baseFunctions(object, keysIn(object));
  12316. }
  12317. /**
  12318. * Gets the value at `path` of `object`. If the resolved value is
  12319. * `undefined`, the `defaultValue` is returned in its place.
  12320. *
  12321. * @static
  12322. * @memberOf _
  12323. * @since 3.7.0
  12324. * @category Object
  12325. * @param {Object} object The object to query.
  12326. * @param {Array|string} path The path of the property to get.
  12327. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12328. * @returns {*} Returns the resolved value.
  12329. * @example
  12330. *
  12331. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12332. *
  12333. * _.get(object, 'a[0].b.c');
  12334. * // => 3
  12335. *
  12336. * _.get(object, ['a', '0', 'b', 'c']);
  12337. * // => 3
  12338. *
  12339. * _.get(object, 'a.b.c', 'default');
  12340. * // => 'default'
  12341. */
  12342. function get(object, path, defaultValue) {
  12343. var result = object == null ? undefined : baseGet(object, path);
  12344. return result === undefined ? defaultValue : result;
  12345. }
  12346. /**
  12347. * Checks if `path` is a direct property of `object`.
  12348. *
  12349. * @static
  12350. * @since 0.1.0
  12351. * @memberOf _
  12352. * @category Object
  12353. * @param {Object} object The object to query.
  12354. * @param {Array|string} path The path to check.
  12355. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12356. * @example
  12357. *
  12358. * var object = { 'a': { 'b': 2 } };
  12359. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12360. *
  12361. * _.has(object, 'a');
  12362. * // => true
  12363. *
  12364. * _.has(object, 'a.b');
  12365. * // => true
  12366. *
  12367. * _.has(object, ['a', 'b']);
  12368. * // => true
  12369. *
  12370. * _.has(other, 'a');
  12371. * // => false
  12372. */
  12373. function has(object, path) {
  12374. return object != null && hasPath(object, path, baseHas);
  12375. }
  12376. /**
  12377. * Checks if `path` is a direct or inherited property of `object`.
  12378. *
  12379. * @static
  12380. * @memberOf _
  12381. * @since 4.0.0
  12382. * @category Object
  12383. * @param {Object} object The object to query.
  12384. * @param {Array|string} path The path to check.
  12385. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12386. * @example
  12387. *
  12388. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12389. *
  12390. * _.hasIn(object, 'a');
  12391. * // => true
  12392. *
  12393. * _.hasIn(object, 'a.b');
  12394. * // => true
  12395. *
  12396. * _.hasIn(object, ['a', 'b']);
  12397. * // => true
  12398. *
  12399. * _.hasIn(object, 'b');
  12400. * // => false
  12401. */
  12402. function hasIn(object, path) {
  12403. return object != null && hasPath(object, path, baseHasIn);
  12404. }
  12405. /**
  12406. * Creates an object composed of the inverted keys and values of `object`.
  12407. * If `object` contains duplicate values, subsequent values overwrite
  12408. * property assignments of previous values.
  12409. *
  12410. * @static
  12411. * @memberOf _
  12412. * @since 0.7.0
  12413. * @category Object
  12414. * @param {Object} object The object to invert.
  12415. * @returns {Object} Returns the new inverted object.
  12416. * @example
  12417. *
  12418. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12419. *
  12420. * _.invert(object);
  12421. * // => { '1': 'c', '2': 'b' }
  12422. */
  12423. var invert = createInverter(function(result, value, key) {
  12424. if (value != null &&
  12425. typeof value.toString != 'function') {
  12426. value = nativeObjectToString.call(value);
  12427. }
  12428. result[value] = key;
  12429. }, constant(identity));
  12430. /**
  12431. * This method is like `_.invert` except that the inverted object is generated
  12432. * from the results of running each element of `object` thru `iteratee`. The
  12433. * corresponding inverted value of each inverted key is an array of keys
  12434. * responsible for generating the inverted value. The iteratee is invoked
  12435. * with one argument: (value).
  12436. *
  12437. * @static
  12438. * @memberOf _
  12439. * @since 4.1.0
  12440. * @category Object
  12441. * @param {Object} object The object to invert.
  12442. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12443. * @returns {Object} Returns the new inverted object.
  12444. * @example
  12445. *
  12446. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12447. *
  12448. * _.invertBy(object);
  12449. * // => { '1': ['a', 'c'], '2': ['b'] }
  12450. *
  12451. * _.invertBy(object, function(value) {
  12452. * return 'group' + value;
  12453. * });
  12454. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12455. */
  12456. var invertBy = createInverter(function(result, value, key) {
  12457. if (value != null &&
  12458. typeof value.toString != 'function') {
  12459. value = nativeObjectToString.call(value);
  12460. }
  12461. if (hasOwnProperty.call(result, value)) {
  12462. result[value].push(key);
  12463. } else {
  12464. result[value] = [key];
  12465. }
  12466. }, getIteratee);
  12467. /**
  12468. * Invokes the method at `path` of `object`.
  12469. *
  12470. * @static
  12471. * @memberOf _
  12472. * @since 4.0.0
  12473. * @category Object
  12474. * @param {Object} object The object to query.
  12475. * @param {Array|string} path The path of the method to invoke.
  12476. * @param {...*} [args] The arguments to invoke the method with.
  12477. * @returns {*} Returns the result of the invoked method.
  12478. * @example
  12479. *
  12480. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12481. *
  12482. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12483. * // => [2, 3]
  12484. */
  12485. var invoke = baseRest(baseInvoke);
  12486. /**
  12487. * Creates an array of the own enumerable property names of `object`.
  12488. *
  12489. * **Note:** Non-object values are coerced to objects. See the
  12490. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12491. * for more details.
  12492. *
  12493. * @static
  12494. * @since 0.1.0
  12495. * @memberOf _
  12496. * @category Object
  12497. * @param {Object} object The object to query.
  12498. * @returns {Array} Returns the array of property names.
  12499. * @example
  12500. *
  12501. * function Foo() {
  12502. * this.a = 1;
  12503. * this.b = 2;
  12504. * }
  12505. *
  12506. * Foo.prototype.c = 3;
  12507. *
  12508. * _.keys(new Foo);
  12509. * // => ['a', 'b'] (iteration order is not guaranteed)
  12510. *
  12511. * _.keys('hi');
  12512. * // => ['0', '1']
  12513. */
  12514. function keys(object) {
  12515. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12516. }
  12517. /**
  12518. * Creates an array of the own and inherited enumerable property names of `object`.
  12519. *
  12520. * **Note:** Non-object values are coerced to objects.
  12521. *
  12522. * @static
  12523. * @memberOf _
  12524. * @since 3.0.0
  12525. * @category Object
  12526. * @param {Object} object The object to query.
  12527. * @returns {Array} Returns the array of property names.
  12528. * @example
  12529. *
  12530. * function Foo() {
  12531. * this.a = 1;
  12532. * this.b = 2;
  12533. * }
  12534. *
  12535. * Foo.prototype.c = 3;
  12536. *
  12537. * _.keysIn(new Foo);
  12538. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12539. */
  12540. function keysIn(object) {
  12541. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12542. }
  12543. /**
  12544. * The opposite of `_.mapValues`; this method creates an object with the
  12545. * same values as `object` and keys generated by running each own enumerable
  12546. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12547. * with three arguments: (value, key, object).
  12548. *
  12549. * @static
  12550. * @memberOf _
  12551. * @since 3.8.0
  12552. * @category Object
  12553. * @param {Object} object The object to iterate over.
  12554. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12555. * @returns {Object} Returns the new mapped object.
  12556. * @see _.mapValues
  12557. * @example
  12558. *
  12559. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12560. * return key + value;
  12561. * });
  12562. * // => { 'a1': 1, 'b2': 2 }
  12563. */
  12564. function mapKeys(object, iteratee) {
  12565. var result = {};
  12566. iteratee = getIteratee(iteratee, 3);
  12567. baseForOwn(object, function(value, key, object) {
  12568. baseAssignValue(result, iteratee(value, key, object), value);
  12569. });
  12570. return result;
  12571. }
  12572. /**
  12573. * Creates an object with the same keys as `object` and values generated
  12574. * by running each own enumerable string keyed property of `object` thru
  12575. * `iteratee`. The iteratee is invoked with three arguments:
  12576. * (value, key, object).
  12577. *
  12578. * @static
  12579. * @memberOf _
  12580. * @since 2.4.0
  12581. * @category Object
  12582. * @param {Object} object The object to iterate over.
  12583. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12584. * @returns {Object} Returns the new mapped object.
  12585. * @see _.mapKeys
  12586. * @example
  12587. *
  12588. * var users = {
  12589. * 'fred': { 'user': 'fred', 'age': 40 },
  12590. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12591. * };
  12592. *
  12593. * _.mapValues(users, function(o) { return o.age; });
  12594. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12595. *
  12596. * // The `_.property` iteratee shorthand.
  12597. * _.mapValues(users, 'age');
  12598. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12599. */
  12600. function mapValues(object, iteratee) {
  12601. var result = {};
  12602. iteratee = getIteratee(iteratee, 3);
  12603. baseForOwn(object, function(value, key, object) {
  12604. baseAssignValue(result, key, iteratee(value, key, object));
  12605. });
  12606. return result;
  12607. }
  12608. /**
  12609. * This method is like `_.assign` except that it recursively merges own and
  12610. * inherited enumerable string keyed properties of source objects into the
  12611. * destination object. Source properties that resolve to `undefined` are
  12612. * skipped if a destination value exists. Array and plain object properties
  12613. * are merged recursively. Other objects and value types are overridden by
  12614. * assignment. Source objects are applied from left to right. Subsequent
  12615. * sources overwrite property assignments of previous sources.
  12616. *
  12617. * **Note:** This method mutates `object`.
  12618. *
  12619. * @static
  12620. * @memberOf _
  12621. * @since 0.5.0
  12622. * @category Object
  12623. * @param {Object} object The destination object.
  12624. * @param {...Object} [sources] The source objects.
  12625. * @returns {Object} Returns `object`.
  12626. * @example
  12627. *
  12628. * var object = {
  12629. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12630. * };
  12631. *
  12632. * var other = {
  12633. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12634. * };
  12635. *
  12636. * _.merge(object, other);
  12637. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12638. */
  12639. var merge = createAssigner(function(object, source, srcIndex) {
  12640. baseMerge(object, source, srcIndex);
  12641. });
  12642. /**
  12643. * This method is like `_.merge` except that it accepts `customizer` which
  12644. * is invoked to produce the merged values of the destination and source
  12645. * properties. If `customizer` returns `undefined`, merging is handled by the
  12646. * method instead. The `customizer` is invoked with six arguments:
  12647. * (objValue, srcValue, key, object, source, stack).
  12648. *
  12649. * **Note:** This method mutates `object`.
  12650. *
  12651. * @static
  12652. * @memberOf _
  12653. * @since 4.0.0
  12654. * @category Object
  12655. * @param {Object} object The destination object.
  12656. * @param {...Object} sources The source objects.
  12657. * @param {Function} customizer The function to customize assigned values.
  12658. * @returns {Object} Returns `object`.
  12659. * @example
  12660. *
  12661. * function customizer(objValue, srcValue) {
  12662. * if (_.isArray(objValue)) {
  12663. * return objValue.concat(srcValue);
  12664. * }
  12665. * }
  12666. *
  12667. * var object = { 'a': [1], 'b': [2] };
  12668. * var other = { 'a': [3], 'b': [4] };
  12669. *
  12670. * _.mergeWith(object, other, customizer);
  12671. * // => { 'a': [1, 3], 'b': [2, 4] }
  12672. */
  12673. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12674. baseMerge(object, source, srcIndex, customizer);
  12675. });
  12676. /**
  12677. * The opposite of `_.pick`; this method creates an object composed of the
  12678. * own and inherited enumerable property paths of `object` that are not omitted.
  12679. *
  12680. * **Note:** This method is considerably slower than `_.pick`.
  12681. *
  12682. * @static
  12683. * @since 0.1.0
  12684. * @memberOf _
  12685. * @category Object
  12686. * @param {Object} object The source object.
  12687. * @param {...(string|string[])} [paths] The property paths to omit.
  12688. * @returns {Object} Returns the new object.
  12689. * @example
  12690. *
  12691. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12692. *
  12693. * _.omit(object, ['a', 'c']);
  12694. * // => { 'b': '2' }
  12695. */
  12696. var omit = flatRest(function(object, paths) {
  12697. var result = {};
  12698. if (object == null) {
  12699. return result;
  12700. }
  12701. var isDeep = false;
  12702. paths = arrayMap(paths, function(path) {
  12703. path = castPath(path, object);
  12704. isDeep || (isDeep = path.length > 1);
  12705. return path;
  12706. });
  12707. copyObject(object, getAllKeysIn(object), result);
  12708. if (isDeep) {
  12709. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12710. }
  12711. var length = paths.length;
  12712. while (length--) {
  12713. baseUnset(result, paths[length]);
  12714. }
  12715. return result;
  12716. });
  12717. /**
  12718. * The opposite of `_.pickBy`; this method creates an object composed of
  12719. * the own and inherited enumerable string keyed properties of `object` that
  12720. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12721. * arguments: (value, key).
  12722. *
  12723. * @static
  12724. * @memberOf _
  12725. * @since 4.0.0
  12726. * @category Object
  12727. * @param {Object} object The source object.
  12728. * @param {Function} [predicate=_.identity] The function invoked per property.
  12729. * @returns {Object} Returns the new object.
  12730. * @example
  12731. *
  12732. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12733. *
  12734. * _.omitBy(object, _.isNumber);
  12735. * // => { 'b': '2' }
  12736. */
  12737. function omitBy(object, predicate) {
  12738. return pickBy(object, negate(getIteratee(predicate)));
  12739. }
  12740. /**
  12741. * Creates an object composed of the picked `object` properties.
  12742. *
  12743. * @static
  12744. * @since 0.1.0
  12745. * @memberOf _
  12746. * @category Object
  12747. * @param {Object} object The source object.
  12748. * @param {...(string|string[])} [paths] The property paths to pick.
  12749. * @returns {Object} Returns the new object.
  12750. * @example
  12751. *
  12752. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12753. *
  12754. * _.pick(object, ['a', 'c']);
  12755. * // => { 'a': 1, 'c': 3 }
  12756. */
  12757. var pick = flatRest(function(object, paths) {
  12758. return object == null ? {} : basePick(object, paths);
  12759. });
  12760. /**
  12761. * Creates an object composed of the `object` properties `predicate` returns
  12762. * truthy for. The predicate is invoked with two arguments: (value, key).
  12763. *
  12764. * @static
  12765. * @memberOf _
  12766. * @since 4.0.0
  12767. * @category Object
  12768. * @param {Object} object The source object.
  12769. * @param {Function} [predicate=_.identity] The function invoked per property.
  12770. * @returns {Object} Returns the new object.
  12771. * @example
  12772. *
  12773. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12774. *
  12775. * _.pickBy(object, _.isNumber);
  12776. * // => { 'a': 1, 'c': 3 }
  12777. */
  12778. function pickBy(object, predicate) {
  12779. if (object == null) {
  12780. return {};
  12781. }
  12782. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12783. return [prop];
  12784. });
  12785. predicate = getIteratee(predicate);
  12786. return basePickBy(object, props, function(value, path) {
  12787. return predicate(value, path[0]);
  12788. });
  12789. }
  12790. /**
  12791. * This method is like `_.get` except that if the resolved value is a
  12792. * function it's invoked with the `this` binding of its parent object and
  12793. * its result is returned.
  12794. *
  12795. * @static
  12796. * @since 0.1.0
  12797. * @memberOf _
  12798. * @category Object
  12799. * @param {Object} object The object to query.
  12800. * @param {Array|string} path The path of the property to resolve.
  12801. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12802. * @returns {*} Returns the resolved value.
  12803. * @example
  12804. *
  12805. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12806. *
  12807. * _.result(object, 'a[0].b.c1');
  12808. * // => 3
  12809. *
  12810. * _.result(object, 'a[0].b.c2');
  12811. * // => 4
  12812. *
  12813. * _.result(object, 'a[0].b.c3', 'default');
  12814. * // => 'default'
  12815. *
  12816. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12817. * // => 'default'
  12818. */
  12819. function result(object, path, defaultValue) {
  12820. path = castPath(path, object);
  12821. var index = -1,
  12822. length = path.length;
  12823. // Ensure the loop is entered when path is empty.
  12824. if (!length) {
  12825. length = 1;
  12826. object = undefined;
  12827. }
  12828. while (++index < length) {
  12829. var value = object == null ? undefined : object[toKey(path[index])];
  12830. if (value === undefined) {
  12831. index = length;
  12832. value = defaultValue;
  12833. }
  12834. object = isFunction(value) ? value.call(object) : value;
  12835. }
  12836. return object;
  12837. }
  12838. /**
  12839. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12840. * it's created. Arrays are created for missing index properties while objects
  12841. * are created for all other missing properties. Use `_.setWith` to customize
  12842. * `path` creation.
  12843. *
  12844. * **Note:** This method mutates `object`.
  12845. *
  12846. * @static
  12847. * @memberOf _
  12848. * @since 3.7.0
  12849. * @category Object
  12850. * @param {Object} object The object to modify.
  12851. * @param {Array|string} path The path of the property to set.
  12852. * @param {*} value The value to set.
  12853. * @returns {Object} Returns `object`.
  12854. * @example
  12855. *
  12856. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12857. *
  12858. * _.set(object, 'a[0].b.c', 4);
  12859. * console.log(object.a[0].b.c);
  12860. * // => 4
  12861. *
  12862. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12863. * console.log(object.x[0].y.z);
  12864. * // => 5
  12865. */
  12866. function set(object, path, value) {
  12867. return object == null ? object : baseSet(object, path, value);
  12868. }
  12869. /**
  12870. * This method is like `_.set` except that it accepts `customizer` which is
  12871. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12872. * path creation is handled by the method instead. The `customizer` is invoked
  12873. * with three arguments: (nsValue, key, nsObject).
  12874. *
  12875. * **Note:** This method mutates `object`.
  12876. *
  12877. * @static
  12878. * @memberOf _
  12879. * @since 4.0.0
  12880. * @category Object
  12881. * @param {Object} object The object to modify.
  12882. * @param {Array|string} path The path of the property to set.
  12883. * @param {*} value The value to set.
  12884. * @param {Function} [customizer] The function to customize assigned values.
  12885. * @returns {Object} Returns `object`.
  12886. * @example
  12887. *
  12888. * var object = {};
  12889. *
  12890. * _.setWith(object, '[0][1]', 'a', Object);
  12891. * // => { '0': { '1': 'a' } }
  12892. */
  12893. function setWith(object, path, value, customizer) {
  12894. customizer = typeof customizer == 'function' ? customizer : undefined;
  12895. return object == null ? object : baseSet(object, path, value, customizer);
  12896. }
  12897. /**
  12898. * Creates an array of own enumerable string keyed-value pairs for `object`
  12899. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12900. * entries are returned.
  12901. *
  12902. * @static
  12903. * @memberOf _
  12904. * @since 4.0.0
  12905. * @alias entries
  12906. * @category Object
  12907. * @param {Object} object The object to query.
  12908. * @returns {Array} Returns the key-value pairs.
  12909. * @example
  12910. *
  12911. * function Foo() {
  12912. * this.a = 1;
  12913. * this.b = 2;
  12914. * }
  12915. *
  12916. * Foo.prototype.c = 3;
  12917. *
  12918. * _.toPairs(new Foo);
  12919. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12920. */
  12921. var toPairs = createToPairs(keys);
  12922. /**
  12923. * Creates an array of own and inherited enumerable string keyed-value pairs
  12924. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12925. * or set, its entries are returned.
  12926. *
  12927. * @static
  12928. * @memberOf _
  12929. * @since 4.0.0
  12930. * @alias entriesIn
  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. * _.toPairsIn(new Foo);
  12944. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12945. */
  12946. var toPairsIn = createToPairs(keysIn);
  12947. /**
  12948. * An alternative to `_.reduce`; this method transforms `object` to a new
  12949. * `accumulator` object which is the result of running each of its own
  12950. * enumerable string keyed properties thru `iteratee`, with each invocation
  12951. * potentially mutating the `accumulator` object. If `accumulator` is not
  12952. * provided, a new object with the same `[[Prototype]]` will be used. The
  12953. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12954. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12955. *
  12956. * @static
  12957. * @memberOf _
  12958. * @since 1.3.0
  12959. * @category Object
  12960. * @param {Object} object The object to iterate over.
  12961. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12962. * @param {*} [accumulator] The custom accumulator value.
  12963. * @returns {*} Returns the accumulated value.
  12964. * @example
  12965. *
  12966. * _.transform([2, 3, 4], function(result, n) {
  12967. * result.push(n *= n);
  12968. * return n % 2 == 0;
  12969. * }, []);
  12970. * // => [4, 9]
  12971. *
  12972. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12973. * (result[value] || (result[value] = [])).push(key);
  12974. * }, {});
  12975. * // => { '1': ['a', 'c'], '2': ['b'] }
  12976. */
  12977. function transform(object, iteratee, accumulator) {
  12978. var isArr = isArray(object),
  12979. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12980. iteratee = getIteratee(iteratee, 4);
  12981. if (accumulator == null) {
  12982. var Ctor = object && object.constructor;
  12983. if (isArrLike) {
  12984. accumulator = isArr ? new Ctor : [];
  12985. }
  12986. else if (isObject(object)) {
  12987. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12988. }
  12989. else {
  12990. accumulator = {};
  12991. }
  12992. }
  12993. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12994. return iteratee(accumulator, value, index, object);
  12995. });
  12996. return accumulator;
  12997. }
  12998. /**
  12999. * Removes the property at `path` of `object`.
  13000. *
  13001. * **Note:** This method mutates `object`.
  13002. *
  13003. * @static
  13004. * @memberOf _
  13005. * @since 4.0.0
  13006. * @category Object
  13007. * @param {Object} object The object to modify.
  13008. * @param {Array|string} path The path of the property to unset.
  13009. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13010. * @example
  13011. *
  13012. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13013. * _.unset(object, 'a[0].b.c');
  13014. * // => true
  13015. *
  13016. * console.log(object);
  13017. * // => { 'a': [{ 'b': {} }] };
  13018. *
  13019. * _.unset(object, ['a', '0', 'b', 'c']);
  13020. * // => true
  13021. *
  13022. * console.log(object);
  13023. * // => { 'a': [{ 'b': {} }] };
  13024. */
  13025. function unset(object, path) {
  13026. return object == null ? true : baseUnset(object, path);
  13027. }
  13028. /**
  13029. * This method is like `_.set` except that accepts `updater` to produce the
  13030. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13031. * is invoked with one argument: (value).
  13032. *
  13033. * **Note:** This method mutates `object`.
  13034. *
  13035. * @static
  13036. * @memberOf _
  13037. * @since 4.6.0
  13038. * @category Object
  13039. * @param {Object} object The object to modify.
  13040. * @param {Array|string} path The path of the property to set.
  13041. * @param {Function} updater The function to produce the updated value.
  13042. * @returns {Object} Returns `object`.
  13043. * @example
  13044. *
  13045. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13046. *
  13047. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13048. * console.log(object.a[0].b.c);
  13049. * // => 9
  13050. *
  13051. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13052. * console.log(object.x[0].y.z);
  13053. * // => 0
  13054. */
  13055. function update(object, path, updater) {
  13056. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13057. }
  13058. /**
  13059. * This method is like `_.update` except that it accepts `customizer` which is
  13060. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13061. * path creation is handled by the method instead. The `customizer` is invoked
  13062. * with three arguments: (nsValue, key, nsObject).
  13063. *
  13064. * **Note:** This method mutates `object`.
  13065. *
  13066. * @static
  13067. * @memberOf _
  13068. * @since 4.6.0
  13069. * @category Object
  13070. * @param {Object} object The object to modify.
  13071. * @param {Array|string} path The path of the property to set.
  13072. * @param {Function} updater The function to produce the updated value.
  13073. * @param {Function} [customizer] The function to customize assigned values.
  13074. * @returns {Object} Returns `object`.
  13075. * @example
  13076. *
  13077. * var object = {};
  13078. *
  13079. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13080. * // => { '0': { '1': 'a' } }
  13081. */
  13082. function updateWith(object, path, updater, customizer) {
  13083. customizer = typeof customizer == 'function' ? customizer : undefined;
  13084. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13085. }
  13086. /**
  13087. * Creates an array of the own enumerable string keyed property values of `object`.
  13088. *
  13089. * **Note:** Non-object values are coerced to objects.
  13090. *
  13091. * @static
  13092. * @since 0.1.0
  13093. * @memberOf _
  13094. * @category Object
  13095. * @param {Object} object The object to query.
  13096. * @returns {Array} Returns the array of property values.
  13097. * @example
  13098. *
  13099. * function Foo() {
  13100. * this.a = 1;
  13101. * this.b = 2;
  13102. * }
  13103. *
  13104. * Foo.prototype.c = 3;
  13105. *
  13106. * _.values(new Foo);
  13107. * // => [1, 2] (iteration order is not guaranteed)
  13108. *
  13109. * _.values('hi');
  13110. * // => ['h', 'i']
  13111. */
  13112. function values(object) {
  13113. return object == null ? [] : baseValues(object, keys(object));
  13114. }
  13115. /**
  13116. * Creates an array of the own and inherited enumerable string keyed property
  13117. * values of `object`.
  13118. *
  13119. * **Note:** Non-object values are coerced to objects.
  13120. *
  13121. * @static
  13122. * @memberOf _
  13123. * @since 3.0.0
  13124. * @category Object
  13125. * @param {Object} object The object to query.
  13126. * @returns {Array} Returns the array of property values.
  13127. * @example
  13128. *
  13129. * function Foo() {
  13130. * this.a = 1;
  13131. * this.b = 2;
  13132. * }
  13133. *
  13134. * Foo.prototype.c = 3;
  13135. *
  13136. * _.valuesIn(new Foo);
  13137. * // => [1, 2, 3] (iteration order is not guaranteed)
  13138. */
  13139. function valuesIn(object) {
  13140. return object == null ? [] : baseValues(object, keysIn(object));
  13141. }
  13142. /*------------------------------------------------------------------------*/
  13143. /**
  13144. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13145. *
  13146. * @static
  13147. * @memberOf _
  13148. * @since 4.0.0
  13149. * @category Number
  13150. * @param {number} number The number to clamp.
  13151. * @param {number} [lower] The lower bound.
  13152. * @param {number} upper The upper bound.
  13153. * @returns {number} Returns the clamped number.
  13154. * @example
  13155. *
  13156. * _.clamp(-10, -5, 5);
  13157. * // => -5
  13158. *
  13159. * _.clamp(10, -5, 5);
  13160. * // => 5
  13161. */
  13162. function clamp(number, lower, upper) {
  13163. if (upper === undefined) {
  13164. upper = lower;
  13165. lower = undefined;
  13166. }
  13167. if (upper !== undefined) {
  13168. upper = toNumber(upper);
  13169. upper = upper === upper ? upper : 0;
  13170. }
  13171. if (lower !== undefined) {
  13172. lower = toNumber(lower);
  13173. lower = lower === lower ? lower : 0;
  13174. }
  13175. return baseClamp(toNumber(number), lower, upper);
  13176. }
  13177. /**
  13178. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13179. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13180. * If `start` is greater than `end` the params are swapped to support
  13181. * negative ranges.
  13182. *
  13183. * @static
  13184. * @memberOf _
  13185. * @since 3.3.0
  13186. * @category Number
  13187. * @param {number} number The number to check.
  13188. * @param {number} [start=0] The start of the range.
  13189. * @param {number} end The end of the range.
  13190. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13191. * @see _.range, _.rangeRight
  13192. * @example
  13193. *
  13194. * _.inRange(3, 2, 4);
  13195. * // => true
  13196. *
  13197. * _.inRange(4, 8);
  13198. * // => true
  13199. *
  13200. * _.inRange(4, 2);
  13201. * // => false
  13202. *
  13203. * _.inRange(2, 2);
  13204. * // => false
  13205. *
  13206. * _.inRange(1.2, 2);
  13207. * // => true
  13208. *
  13209. * _.inRange(5.2, 4);
  13210. * // => false
  13211. *
  13212. * _.inRange(-3, -2, -6);
  13213. * // => true
  13214. */
  13215. function inRange(number, start, end) {
  13216. start = toFinite(start);
  13217. if (end === undefined) {
  13218. end = start;
  13219. start = 0;
  13220. } else {
  13221. end = toFinite(end);
  13222. }
  13223. number = toNumber(number);
  13224. return baseInRange(number, start, end);
  13225. }
  13226. /**
  13227. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13228. * If only one argument is provided a number between `0` and the given number
  13229. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13230. * floats, a floating-point number is returned instead of an integer.
  13231. *
  13232. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13233. * floating-point values which can produce unexpected results.
  13234. *
  13235. * @static
  13236. * @memberOf _
  13237. * @since 0.7.0
  13238. * @category Number
  13239. * @param {number} [lower=0] The lower bound.
  13240. * @param {number} [upper=1] The upper bound.
  13241. * @param {boolean} [floating] Specify returning a floating-point number.
  13242. * @returns {number} Returns the random number.
  13243. * @example
  13244. *
  13245. * _.random(0, 5);
  13246. * // => an integer between 0 and 5
  13247. *
  13248. * _.random(5);
  13249. * // => also an integer between 0 and 5
  13250. *
  13251. * _.random(5, true);
  13252. * // => a floating-point number between 0 and 5
  13253. *
  13254. * _.random(1.2, 5.2);
  13255. * // => a floating-point number between 1.2 and 5.2
  13256. */
  13257. function random(lower, upper, floating) {
  13258. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13259. upper = floating = undefined;
  13260. }
  13261. if (floating === undefined) {
  13262. if (typeof upper == 'boolean') {
  13263. floating = upper;
  13264. upper = undefined;
  13265. }
  13266. else if (typeof lower == 'boolean') {
  13267. floating = lower;
  13268. lower = undefined;
  13269. }
  13270. }
  13271. if (lower === undefined && upper === undefined) {
  13272. lower = 0;
  13273. upper = 1;
  13274. }
  13275. else {
  13276. lower = toFinite(lower);
  13277. if (upper === undefined) {
  13278. upper = lower;
  13279. lower = 0;
  13280. } else {
  13281. upper = toFinite(upper);
  13282. }
  13283. }
  13284. if (lower > upper) {
  13285. var temp = lower;
  13286. lower = upper;
  13287. upper = temp;
  13288. }
  13289. if (floating || lower % 1 || upper % 1) {
  13290. var rand = nativeRandom();
  13291. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13292. }
  13293. return baseRandom(lower, upper);
  13294. }
  13295. /*------------------------------------------------------------------------*/
  13296. /**
  13297. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13298. *
  13299. * @static
  13300. * @memberOf _
  13301. * @since 3.0.0
  13302. * @category String
  13303. * @param {string} [string=''] The string to convert.
  13304. * @returns {string} Returns the camel cased string.
  13305. * @example
  13306. *
  13307. * _.camelCase('Foo Bar');
  13308. * // => 'fooBar'
  13309. *
  13310. * _.camelCase('--foo-bar--');
  13311. * // => 'fooBar'
  13312. *
  13313. * _.camelCase('__FOO_BAR__');
  13314. * // => 'fooBar'
  13315. */
  13316. var camelCase = createCompounder(function(result, word, index) {
  13317. word = word.toLowerCase();
  13318. return result + (index ? capitalize(word) : word);
  13319. });
  13320. /**
  13321. * Converts the first character of `string` to upper case and the remaining
  13322. * to lower case.
  13323. *
  13324. * @static
  13325. * @memberOf _
  13326. * @since 3.0.0
  13327. * @category String
  13328. * @param {string} [string=''] The string to capitalize.
  13329. * @returns {string} Returns the capitalized string.
  13330. * @example
  13331. *
  13332. * _.capitalize('FRED');
  13333. * // => 'Fred'
  13334. */
  13335. function capitalize(string) {
  13336. return upperFirst(toString(string).toLowerCase());
  13337. }
  13338. /**
  13339. * Deburrs `string` by converting
  13340. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13341. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13342. * letters to basic Latin letters and removing
  13343. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13344. *
  13345. * @static
  13346. * @memberOf _
  13347. * @since 3.0.0
  13348. * @category String
  13349. * @param {string} [string=''] The string to deburr.
  13350. * @returns {string} Returns the deburred string.
  13351. * @example
  13352. *
  13353. * _.deburr('déjà vu');
  13354. * // => 'deja vu'
  13355. */
  13356. function deburr(string) {
  13357. string = toString(string);
  13358. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13359. }
  13360. /**
  13361. * Checks if `string` ends with the given target string.
  13362. *
  13363. * @static
  13364. * @memberOf _
  13365. * @since 3.0.0
  13366. * @category String
  13367. * @param {string} [string=''] The string to inspect.
  13368. * @param {string} [target] The string to search for.
  13369. * @param {number} [position=string.length] The position to search up to.
  13370. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13371. * else `false`.
  13372. * @example
  13373. *
  13374. * _.endsWith('abc', 'c');
  13375. * // => true
  13376. *
  13377. * _.endsWith('abc', 'b');
  13378. * // => false
  13379. *
  13380. * _.endsWith('abc', 'b', 2);
  13381. * // => true
  13382. */
  13383. function endsWith(string, target, position) {
  13384. string = toString(string);
  13385. target = baseToString(target);
  13386. var length = string.length;
  13387. position = position === undefined
  13388. ? length
  13389. : baseClamp(toInteger(position), 0, length);
  13390. var end = position;
  13391. position -= target.length;
  13392. return position >= 0 && string.slice(position, end) == target;
  13393. }
  13394. /**
  13395. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13396. * corresponding HTML entities.
  13397. *
  13398. * **Note:** No other characters are escaped. To escape additional
  13399. * characters use a third-party library like [_he_](https://mths.be/he).
  13400. *
  13401. * Though the ">" character is escaped for symmetry, characters like
  13402. * ">" and "/" don't need escaping in HTML and have no special meaning
  13403. * unless they're part of a tag or unquoted attribute value. See
  13404. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13405. * (under "semi-related fun fact") for more details.
  13406. *
  13407. * When working with HTML you should always
  13408. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13409. * XSS vectors.
  13410. *
  13411. * @static
  13412. * @since 0.1.0
  13413. * @memberOf _
  13414. * @category String
  13415. * @param {string} [string=''] The string to escape.
  13416. * @returns {string} Returns the escaped string.
  13417. * @example
  13418. *
  13419. * _.escape('fred, barney, & pebbles');
  13420. * // => 'fred, barney, &amp; pebbles'
  13421. */
  13422. function escape(string) {
  13423. string = toString(string);
  13424. return (string && reHasUnescapedHtml.test(string))
  13425. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13426. : string;
  13427. }
  13428. /**
  13429. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13430. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13431. *
  13432. * @static
  13433. * @memberOf _
  13434. * @since 3.0.0
  13435. * @category String
  13436. * @param {string} [string=''] The string to escape.
  13437. * @returns {string} Returns the escaped string.
  13438. * @example
  13439. *
  13440. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13441. * // => '\[lodash\]\(https://lodash\.com/\)'
  13442. */
  13443. function escapeRegExp(string) {
  13444. string = toString(string);
  13445. return (string && reHasRegExpChar.test(string))
  13446. ? string.replace(reRegExpChar, '\\$&')
  13447. : string;
  13448. }
  13449. /**
  13450. * Converts `string` to
  13451. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13452. *
  13453. * @static
  13454. * @memberOf _
  13455. * @since 3.0.0
  13456. * @category String
  13457. * @param {string} [string=''] The string to convert.
  13458. * @returns {string} Returns the kebab cased string.
  13459. * @example
  13460. *
  13461. * _.kebabCase('Foo Bar');
  13462. * // => 'foo-bar'
  13463. *
  13464. * _.kebabCase('fooBar');
  13465. * // => 'foo-bar'
  13466. *
  13467. * _.kebabCase('__FOO_BAR__');
  13468. * // => 'foo-bar'
  13469. */
  13470. var kebabCase = createCompounder(function(result, word, index) {
  13471. return result + (index ? '-' : '') + word.toLowerCase();
  13472. });
  13473. /**
  13474. * Converts `string`, as space separated words, to lower case.
  13475. *
  13476. * @static
  13477. * @memberOf _
  13478. * @since 4.0.0
  13479. * @category String
  13480. * @param {string} [string=''] The string to convert.
  13481. * @returns {string} Returns the lower cased string.
  13482. * @example
  13483. *
  13484. * _.lowerCase('--Foo-Bar--');
  13485. * // => 'foo bar'
  13486. *
  13487. * _.lowerCase('fooBar');
  13488. * // => 'foo bar'
  13489. *
  13490. * _.lowerCase('__FOO_BAR__');
  13491. * // => 'foo bar'
  13492. */
  13493. var lowerCase = createCompounder(function(result, word, index) {
  13494. return result + (index ? ' ' : '') + word.toLowerCase();
  13495. });
  13496. /**
  13497. * Converts the first character of `string` to lower case.
  13498. *
  13499. * @static
  13500. * @memberOf _
  13501. * @since 4.0.0
  13502. * @category String
  13503. * @param {string} [string=''] The string to convert.
  13504. * @returns {string} Returns the converted string.
  13505. * @example
  13506. *
  13507. * _.lowerFirst('Fred');
  13508. * // => 'fred'
  13509. *
  13510. * _.lowerFirst('FRED');
  13511. * // => 'fRED'
  13512. */
  13513. var lowerFirst = createCaseFirst('toLowerCase');
  13514. /**
  13515. * Pads `string` on the left and right sides if it's shorter than `length`.
  13516. * Padding characters are truncated if they can't be evenly divided by `length`.
  13517. *
  13518. * @static
  13519. * @memberOf _
  13520. * @since 3.0.0
  13521. * @category String
  13522. * @param {string} [string=''] The string to pad.
  13523. * @param {number} [length=0] The padding length.
  13524. * @param {string} [chars=' '] The string used as padding.
  13525. * @returns {string} Returns the padded string.
  13526. * @example
  13527. *
  13528. * _.pad('abc', 8);
  13529. * // => ' abc '
  13530. *
  13531. * _.pad('abc', 8, '_-');
  13532. * // => '_-abc_-_'
  13533. *
  13534. * _.pad('abc', 3);
  13535. * // => 'abc'
  13536. */
  13537. function pad(string, length, chars) {
  13538. string = toString(string);
  13539. length = toInteger(length);
  13540. var strLength = length ? stringSize(string) : 0;
  13541. if (!length || strLength >= length) {
  13542. return string;
  13543. }
  13544. var mid = (length - strLength) / 2;
  13545. return (
  13546. createPadding(nativeFloor(mid), chars) +
  13547. string +
  13548. createPadding(nativeCeil(mid), chars)
  13549. );
  13550. }
  13551. /**
  13552. * Pads `string` on the right side if it's shorter than `length`. Padding
  13553. * characters are truncated if they exceed `length`.
  13554. *
  13555. * @static
  13556. * @memberOf _
  13557. * @since 4.0.0
  13558. * @category String
  13559. * @param {string} [string=''] The string to pad.
  13560. * @param {number} [length=0] The padding length.
  13561. * @param {string} [chars=' '] The string used as padding.
  13562. * @returns {string} Returns the padded string.
  13563. * @example
  13564. *
  13565. * _.padEnd('abc', 6);
  13566. * // => 'abc '
  13567. *
  13568. * _.padEnd('abc', 6, '_-');
  13569. * // => 'abc_-_'
  13570. *
  13571. * _.padEnd('abc', 3);
  13572. * // => 'abc'
  13573. */
  13574. function padEnd(string, length, chars) {
  13575. string = toString(string);
  13576. length = toInteger(length);
  13577. var strLength = length ? stringSize(string) : 0;
  13578. return (length && strLength < length)
  13579. ? (string + createPadding(length - strLength, chars))
  13580. : string;
  13581. }
  13582. /**
  13583. * Pads `string` on the left side if it's shorter than `length`. Padding
  13584. * characters are truncated if they exceed `length`.
  13585. *
  13586. * @static
  13587. * @memberOf _
  13588. * @since 4.0.0
  13589. * @category String
  13590. * @param {string} [string=''] The string to pad.
  13591. * @param {number} [length=0] The padding length.
  13592. * @param {string} [chars=' '] The string used as padding.
  13593. * @returns {string} Returns the padded string.
  13594. * @example
  13595. *
  13596. * _.padStart('abc', 6);
  13597. * // => ' abc'
  13598. *
  13599. * _.padStart('abc', 6, '_-');
  13600. * // => '_-_abc'
  13601. *
  13602. * _.padStart('abc', 3);
  13603. * // => 'abc'
  13604. */
  13605. function padStart(string, length, chars) {
  13606. string = toString(string);
  13607. length = toInteger(length);
  13608. var strLength = length ? stringSize(string) : 0;
  13609. return (length && strLength < length)
  13610. ? (createPadding(length - strLength, chars) + string)
  13611. : string;
  13612. }
  13613. /**
  13614. * Converts `string` to an integer of the specified radix. If `radix` is
  13615. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13616. * hexadecimal, in which case a `radix` of `16` is used.
  13617. *
  13618. * **Note:** This method aligns with the
  13619. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13620. *
  13621. * @static
  13622. * @memberOf _
  13623. * @since 1.1.0
  13624. * @category String
  13625. * @param {string} string The string to convert.
  13626. * @param {number} [radix=10] The radix to interpret `value` by.
  13627. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13628. * @returns {number} Returns the converted integer.
  13629. * @example
  13630. *
  13631. * _.parseInt('08');
  13632. * // => 8
  13633. *
  13634. * _.map(['6', '08', '10'], _.parseInt);
  13635. * // => [6, 8, 10]
  13636. */
  13637. function parseInt(string, radix, guard) {
  13638. if (guard || radix == null) {
  13639. radix = 0;
  13640. } else if (radix) {
  13641. radix = +radix;
  13642. }
  13643. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13644. }
  13645. /**
  13646. * Repeats the given string `n` times.
  13647. *
  13648. * @static
  13649. * @memberOf _
  13650. * @since 3.0.0
  13651. * @category String
  13652. * @param {string} [string=''] The string to repeat.
  13653. * @param {number} [n=1] The number of times to repeat the string.
  13654. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13655. * @returns {string} Returns the repeated string.
  13656. * @example
  13657. *
  13658. * _.repeat('*', 3);
  13659. * // => '***'
  13660. *
  13661. * _.repeat('abc', 2);
  13662. * // => 'abcabc'
  13663. *
  13664. * _.repeat('abc', 0);
  13665. * // => ''
  13666. */
  13667. function repeat(string, n, guard) {
  13668. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13669. n = 1;
  13670. } else {
  13671. n = toInteger(n);
  13672. }
  13673. return baseRepeat(toString(string), n);
  13674. }
  13675. /**
  13676. * Replaces matches for `pattern` in `string` with `replacement`.
  13677. *
  13678. * **Note:** This method is based on
  13679. * [`String#replace`](https://mdn.io/String/replace).
  13680. *
  13681. * @static
  13682. * @memberOf _
  13683. * @since 4.0.0
  13684. * @category String
  13685. * @param {string} [string=''] The string to modify.
  13686. * @param {RegExp|string} pattern The pattern to replace.
  13687. * @param {Function|string} replacement The match replacement.
  13688. * @returns {string} Returns the modified string.
  13689. * @example
  13690. *
  13691. * _.replace('Hi Fred', 'Fred', 'Barney');
  13692. * // => 'Hi Barney'
  13693. */
  13694. function replace() {
  13695. var args = arguments,
  13696. string = toString(args[0]);
  13697. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13698. }
  13699. /**
  13700. * Converts `string` to
  13701. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13702. *
  13703. * @static
  13704. * @memberOf _
  13705. * @since 3.0.0
  13706. * @category String
  13707. * @param {string} [string=''] The string to convert.
  13708. * @returns {string} Returns the snake cased string.
  13709. * @example
  13710. *
  13711. * _.snakeCase('Foo Bar');
  13712. * // => 'foo_bar'
  13713. *
  13714. * _.snakeCase('fooBar');
  13715. * // => 'foo_bar'
  13716. *
  13717. * _.snakeCase('--FOO-BAR--');
  13718. * // => 'foo_bar'
  13719. */
  13720. var snakeCase = createCompounder(function(result, word, index) {
  13721. return result + (index ? '_' : '') + word.toLowerCase();
  13722. });
  13723. /**
  13724. * Splits `string` by `separator`.
  13725. *
  13726. * **Note:** This method is based on
  13727. * [`String#split`](https://mdn.io/String/split).
  13728. *
  13729. * @static
  13730. * @memberOf _
  13731. * @since 4.0.0
  13732. * @category String
  13733. * @param {string} [string=''] The string to split.
  13734. * @param {RegExp|string} separator The separator pattern to split by.
  13735. * @param {number} [limit] The length to truncate results to.
  13736. * @returns {Array} Returns the string segments.
  13737. * @example
  13738. *
  13739. * _.split('a-b-c', '-', 2);
  13740. * // => ['a', 'b']
  13741. */
  13742. function split(string, separator, limit) {
  13743. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13744. separator = limit = undefined;
  13745. }
  13746. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13747. if (!limit) {
  13748. return [];
  13749. }
  13750. string = toString(string);
  13751. if (string && (
  13752. typeof separator == 'string' ||
  13753. (separator != null && !isRegExp(separator))
  13754. )) {
  13755. separator = baseToString(separator);
  13756. if (!separator && hasUnicode(string)) {
  13757. return castSlice(stringToArray(string), 0, limit);
  13758. }
  13759. }
  13760. return string.split(separator, limit);
  13761. }
  13762. /**
  13763. * Converts `string` to
  13764. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13765. *
  13766. * @static
  13767. * @memberOf _
  13768. * @since 3.1.0
  13769. * @category String
  13770. * @param {string} [string=''] The string to convert.
  13771. * @returns {string} Returns the start cased string.
  13772. * @example
  13773. *
  13774. * _.startCase('--foo-bar--');
  13775. * // => 'Foo Bar'
  13776. *
  13777. * _.startCase('fooBar');
  13778. * // => 'Foo Bar'
  13779. *
  13780. * _.startCase('__FOO_BAR__');
  13781. * // => 'FOO BAR'
  13782. */
  13783. var startCase = createCompounder(function(result, word, index) {
  13784. return result + (index ? ' ' : '') + upperFirst(word);
  13785. });
  13786. /**
  13787. * Checks if `string` starts with the given target string.
  13788. *
  13789. * @static
  13790. * @memberOf _
  13791. * @since 3.0.0
  13792. * @category String
  13793. * @param {string} [string=''] The string to inspect.
  13794. * @param {string} [target] The string to search for.
  13795. * @param {number} [position=0] The position to search from.
  13796. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13797. * else `false`.
  13798. * @example
  13799. *
  13800. * _.startsWith('abc', 'a');
  13801. * // => true
  13802. *
  13803. * _.startsWith('abc', 'b');
  13804. * // => false
  13805. *
  13806. * _.startsWith('abc', 'b', 1);
  13807. * // => true
  13808. */
  13809. function startsWith(string, target, position) {
  13810. string = toString(string);
  13811. position = position == null
  13812. ? 0
  13813. : baseClamp(toInteger(position), 0, string.length);
  13814. target = baseToString(target);
  13815. return string.slice(position, position + target.length) == target;
  13816. }
  13817. /**
  13818. * Creates a compiled template function that can interpolate data properties
  13819. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13820. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13821. * properties may be accessed as free variables in the template. If a setting
  13822. * object is given, it takes precedence over `_.templateSettings` values.
  13823. *
  13824. * **Note:** In the development build `_.template` utilizes
  13825. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13826. * for easier debugging.
  13827. *
  13828. * For more information on precompiling templates see
  13829. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13830. *
  13831. * For more information on Chrome extension sandboxes see
  13832. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13833. *
  13834. * @static
  13835. * @since 0.1.0
  13836. * @memberOf _
  13837. * @category String
  13838. * @param {string} [string=''] The template string.
  13839. * @param {Object} [options={}] The options object.
  13840. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13841. * The HTML "escape" delimiter.
  13842. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13843. * The "evaluate" delimiter.
  13844. * @param {Object} [options.imports=_.templateSettings.imports]
  13845. * An object to import into the template as free variables.
  13846. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13847. * The "interpolate" delimiter.
  13848. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13849. * The sourceURL of the compiled template.
  13850. * @param {string} [options.variable='obj']
  13851. * The data object variable name.
  13852. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13853. * @returns {Function} Returns the compiled template function.
  13854. * @example
  13855. *
  13856. * // Use the "interpolate" delimiter to create a compiled template.
  13857. * var compiled = _.template('hello <%= user %>!');
  13858. * compiled({ 'user': 'fred' });
  13859. * // => 'hello fred!'
  13860. *
  13861. * // Use the HTML "escape" delimiter to escape data property values.
  13862. * var compiled = _.template('<b><%- value %></b>');
  13863. * compiled({ 'value': '<script>' });
  13864. * // => '<b>&lt;script&gt;</b>'
  13865. *
  13866. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13867. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13868. * compiled({ 'users': ['fred', 'barney'] });
  13869. * // => '<li>fred</li><li>barney</li>'
  13870. *
  13871. * // Use the internal `print` function in "evaluate" delimiters.
  13872. * var compiled = _.template('<% print("hello " + user); %>!');
  13873. * compiled({ 'user': 'barney' });
  13874. * // => 'hello barney!'
  13875. *
  13876. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13877. * // Disable support by replacing the "interpolate" delimiter.
  13878. * var compiled = _.template('hello ${ user }!');
  13879. * compiled({ 'user': 'pebbles' });
  13880. * // => 'hello pebbles!'
  13881. *
  13882. * // Use backslashes to treat delimiters as plain text.
  13883. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13884. * compiled({ 'value': 'ignored' });
  13885. * // => '<%- value %>'
  13886. *
  13887. * // Use the `imports` option to import `jQuery` as `jq`.
  13888. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13889. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13890. * compiled({ 'users': ['fred', 'barney'] });
  13891. * // => '<li>fred</li><li>barney</li>'
  13892. *
  13893. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13894. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13895. * compiled(data);
  13896. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13897. *
  13898. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13899. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13900. * compiled.source;
  13901. * // => function(data) {
  13902. * // var __t, __p = '';
  13903. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13904. * // return __p;
  13905. * // }
  13906. *
  13907. * // Use custom template delimiters.
  13908. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13909. * var compiled = _.template('hello {{ user }}!');
  13910. * compiled({ 'user': 'mustache' });
  13911. * // => 'hello mustache!'
  13912. *
  13913. * // Use the `source` property to inline compiled templates for meaningful
  13914. * // line numbers in error messages and stack traces.
  13915. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13916. * var JST = {\
  13917. * "main": ' + _.template(mainText).source + '\
  13918. * };\
  13919. * ');
  13920. */
  13921. function template(string, options, guard) {
  13922. // Based on John Resig's `tmpl` implementation
  13923. // (http://ejohn.org/blog/javascript-micro-templating/)
  13924. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13925. var settings = lodash.templateSettings;
  13926. if (guard && isIterateeCall(string, options, guard)) {
  13927. options = undefined;
  13928. }
  13929. string = toString(string);
  13930. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13931. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13932. importsKeys = keys(imports),
  13933. importsValues = baseValues(imports, importsKeys);
  13934. var isEscaping,
  13935. isEvaluating,
  13936. index = 0,
  13937. interpolate = options.interpolate || reNoMatch,
  13938. source = "__p += '";
  13939. // Compile the regexp to match each delimiter.
  13940. var reDelimiters = RegExp(
  13941. (options.escape || reNoMatch).source + '|' +
  13942. interpolate.source + '|' +
  13943. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13944. (options.evaluate || reNoMatch).source + '|$'
  13945. , 'g');
  13946. // Use a sourceURL for easier debugging.
  13947. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13948. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  13949. // and escape the comment, thus injecting code that gets evaled.
  13950. var sourceURL = '//# sourceURL=' +
  13951. (hasOwnProperty.call(options, 'sourceURL')
  13952. ? (options.sourceURL + '').replace(/\s/g, ' ')
  13953. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13954. ) + '\n';
  13955. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13956. interpolateValue || (interpolateValue = esTemplateValue);
  13957. // Escape characters that can't be included in string literals.
  13958. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13959. // Replace delimiters with snippets.
  13960. if (escapeValue) {
  13961. isEscaping = true;
  13962. source += "' +\n__e(" + escapeValue + ") +\n'";
  13963. }
  13964. if (evaluateValue) {
  13965. isEvaluating = true;
  13966. source += "';\n" + evaluateValue + ";\n__p += '";
  13967. }
  13968. if (interpolateValue) {
  13969. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13970. }
  13971. index = offset + match.length;
  13972. // The JS engine embedded in Adobe products needs `match` returned in
  13973. // order to produce the correct `offset` value.
  13974. return match;
  13975. });
  13976. source += "';\n";
  13977. // If `variable` is not specified wrap a with-statement around the generated
  13978. // code to add the data object to the top of the scope chain.
  13979. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13980. if (!variable) {
  13981. source = 'with (obj) {\n' + source + '\n}\n';
  13982. }
  13983. // Throw an error if a forbidden character was found in `variable`, to prevent
  13984. // potential command injection attacks.
  13985. else if (reForbiddenIdentifierChars.test(variable)) {
  13986. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  13987. }
  13988. // Cleanup code by stripping empty strings.
  13989. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13990. .replace(reEmptyStringMiddle, '$1')
  13991. .replace(reEmptyStringTrailing, '$1;');
  13992. // Frame code as the function body.
  13993. source = 'function(' + (variable || 'obj') + ') {\n' +
  13994. (variable
  13995. ? ''
  13996. : 'obj || (obj = {});\n'
  13997. ) +
  13998. "var __t, __p = ''" +
  13999. (isEscaping
  14000. ? ', __e = _.escape'
  14001. : ''
  14002. ) +
  14003. (isEvaluating
  14004. ? ', __j = Array.prototype.join;\n' +
  14005. "function print() { __p += __j.call(arguments, '') }\n"
  14006. : ';\n'
  14007. ) +
  14008. source +
  14009. 'return __p\n}';
  14010. var result = attempt(function() {
  14011. return Function(importsKeys, sourceURL + 'return ' + source)
  14012. .apply(undefined, importsValues);
  14013. });
  14014. // Provide the compiled function's source by its `toString` method or
  14015. // the `source` property as a convenience for inlining compiled templates.
  14016. result.source = source;
  14017. if (isError(result)) {
  14018. throw result;
  14019. }
  14020. return result;
  14021. }
  14022. /**
  14023. * Converts `string`, as a whole, to lower case just like
  14024. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14025. *
  14026. * @static
  14027. * @memberOf _
  14028. * @since 4.0.0
  14029. * @category String
  14030. * @param {string} [string=''] The string to convert.
  14031. * @returns {string} Returns the lower cased string.
  14032. * @example
  14033. *
  14034. * _.toLower('--Foo-Bar--');
  14035. * // => '--foo-bar--'
  14036. *
  14037. * _.toLower('fooBar');
  14038. * // => 'foobar'
  14039. *
  14040. * _.toLower('__FOO_BAR__');
  14041. * // => '__foo_bar__'
  14042. */
  14043. function toLower(value) {
  14044. return toString(value).toLowerCase();
  14045. }
  14046. /**
  14047. * Converts `string`, as a whole, to upper case just like
  14048. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14049. *
  14050. * @static
  14051. * @memberOf _
  14052. * @since 4.0.0
  14053. * @category String
  14054. * @param {string} [string=''] The string to convert.
  14055. * @returns {string} Returns the upper cased string.
  14056. * @example
  14057. *
  14058. * _.toUpper('--foo-bar--');
  14059. * // => '--FOO-BAR--'
  14060. *
  14061. * _.toUpper('fooBar');
  14062. * // => 'FOOBAR'
  14063. *
  14064. * _.toUpper('__foo_bar__');
  14065. * // => '__FOO_BAR__'
  14066. */
  14067. function toUpper(value) {
  14068. return toString(value).toUpperCase();
  14069. }
  14070. /**
  14071. * Removes leading and trailing whitespace or specified characters from `string`.
  14072. *
  14073. * @static
  14074. * @memberOf _
  14075. * @since 3.0.0
  14076. * @category String
  14077. * @param {string} [string=''] The string to trim.
  14078. * @param {string} [chars=whitespace] The characters to trim.
  14079. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14080. * @returns {string} Returns the trimmed string.
  14081. * @example
  14082. *
  14083. * _.trim(' abc ');
  14084. * // => 'abc'
  14085. *
  14086. * _.trim('-_-abc-_-', '_-');
  14087. * // => 'abc'
  14088. *
  14089. * _.map([' foo ', ' bar '], _.trim);
  14090. * // => ['foo', 'bar']
  14091. */
  14092. function trim(string, chars, guard) {
  14093. string = toString(string);
  14094. if (string && (guard || chars === undefined)) {
  14095. return baseTrim(string);
  14096. }
  14097. if (!string || !(chars = baseToString(chars))) {
  14098. return string;
  14099. }
  14100. var strSymbols = stringToArray(string),
  14101. chrSymbols = stringToArray(chars),
  14102. start = charsStartIndex(strSymbols, chrSymbols),
  14103. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14104. return castSlice(strSymbols, start, end).join('');
  14105. }
  14106. /**
  14107. * Removes trailing whitespace or specified characters from `string`.
  14108. *
  14109. * @static
  14110. * @memberOf _
  14111. * @since 4.0.0
  14112. * @category String
  14113. * @param {string} [string=''] The string to trim.
  14114. * @param {string} [chars=whitespace] The characters to trim.
  14115. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14116. * @returns {string} Returns the trimmed string.
  14117. * @example
  14118. *
  14119. * _.trimEnd(' abc ');
  14120. * // => ' abc'
  14121. *
  14122. * _.trimEnd('-_-abc-_-', '_-');
  14123. * // => '-_-abc'
  14124. */
  14125. function trimEnd(string, chars, guard) {
  14126. string = toString(string);
  14127. if (string && (guard || chars === undefined)) {
  14128. return string.slice(0, trimmedEndIndex(string) + 1);
  14129. }
  14130. if (!string || !(chars = baseToString(chars))) {
  14131. return string;
  14132. }
  14133. var strSymbols = stringToArray(string),
  14134. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14135. return castSlice(strSymbols, 0, end).join('');
  14136. }
  14137. /**
  14138. * Removes leading whitespace or specified characters from `string`.
  14139. *
  14140. * @static
  14141. * @memberOf _
  14142. * @since 4.0.0
  14143. * @category String
  14144. * @param {string} [string=''] The string to trim.
  14145. * @param {string} [chars=whitespace] The characters to trim.
  14146. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14147. * @returns {string} Returns the trimmed string.
  14148. * @example
  14149. *
  14150. * _.trimStart(' abc ');
  14151. * // => 'abc '
  14152. *
  14153. * _.trimStart('-_-abc-_-', '_-');
  14154. * // => 'abc-_-'
  14155. */
  14156. function trimStart(string, chars, guard) {
  14157. string = toString(string);
  14158. if (string && (guard || chars === undefined)) {
  14159. return string.replace(reTrimStart, '');
  14160. }
  14161. if (!string || !(chars = baseToString(chars))) {
  14162. return string;
  14163. }
  14164. var strSymbols = stringToArray(string),
  14165. start = charsStartIndex(strSymbols, stringToArray(chars));
  14166. return castSlice(strSymbols, start).join('');
  14167. }
  14168. /**
  14169. * Truncates `string` if it's longer than the given maximum string length.
  14170. * The last characters of the truncated string are replaced with the omission
  14171. * string which defaults to "...".
  14172. *
  14173. * @static
  14174. * @memberOf _
  14175. * @since 4.0.0
  14176. * @category String
  14177. * @param {string} [string=''] The string to truncate.
  14178. * @param {Object} [options={}] The options object.
  14179. * @param {number} [options.length=30] The maximum string length.
  14180. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14181. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14182. * @returns {string} Returns the truncated string.
  14183. * @example
  14184. *
  14185. * _.truncate('hi-diddly-ho there, neighborino');
  14186. * // => 'hi-diddly-ho there, neighbo...'
  14187. *
  14188. * _.truncate('hi-diddly-ho there, neighborino', {
  14189. * 'length': 24,
  14190. * 'separator': ' '
  14191. * });
  14192. * // => 'hi-diddly-ho there,...'
  14193. *
  14194. * _.truncate('hi-diddly-ho there, neighborino', {
  14195. * 'length': 24,
  14196. * 'separator': /,? +/
  14197. * });
  14198. * // => 'hi-diddly-ho there...'
  14199. *
  14200. * _.truncate('hi-diddly-ho there, neighborino', {
  14201. * 'omission': ' [...]'
  14202. * });
  14203. * // => 'hi-diddly-ho there, neig [...]'
  14204. */
  14205. function truncate(string, options) {
  14206. var length = DEFAULT_TRUNC_LENGTH,
  14207. omission = DEFAULT_TRUNC_OMISSION;
  14208. if (isObject(options)) {
  14209. var separator = 'separator' in options ? options.separator : separator;
  14210. length = 'length' in options ? toInteger(options.length) : length;
  14211. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14212. }
  14213. string = toString(string);
  14214. var strLength = string.length;
  14215. if (hasUnicode(string)) {
  14216. var strSymbols = stringToArray(string);
  14217. strLength = strSymbols.length;
  14218. }
  14219. if (length >= strLength) {
  14220. return string;
  14221. }
  14222. var end = length - stringSize(omission);
  14223. if (end < 1) {
  14224. return omission;
  14225. }
  14226. var result = strSymbols
  14227. ? castSlice(strSymbols, 0, end).join('')
  14228. : string.slice(0, end);
  14229. if (separator === undefined) {
  14230. return result + omission;
  14231. }
  14232. if (strSymbols) {
  14233. end += (result.length - end);
  14234. }
  14235. if (isRegExp(separator)) {
  14236. if (string.slice(end).search(separator)) {
  14237. var match,
  14238. substring = result;
  14239. if (!separator.global) {
  14240. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14241. }
  14242. separator.lastIndex = 0;
  14243. while ((match = separator.exec(substring))) {
  14244. var newEnd = match.index;
  14245. }
  14246. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14247. }
  14248. } else if (string.indexOf(baseToString(separator), end) != end) {
  14249. var index = result.lastIndexOf(separator);
  14250. if (index > -1) {
  14251. result = result.slice(0, index);
  14252. }
  14253. }
  14254. return result + omission;
  14255. }
  14256. /**
  14257. * The inverse of `_.escape`; this method converts the HTML entities
  14258. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14259. * their corresponding characters.
  14260. *
  14261. * **Note:** No other HTML entities are unescaped. To unescape additional
  14262. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14263. *
  14264. * @static
  14265. * @memberOf _
  14266. * @since 0.6.0
  14267. * @category String
  14268. * @param {string} [string=''] The string to unescape.
  14269. * @returns {string} Returns the unescaped string.
  14270. * @example
  14271. *
  14272. * _.unescape('fred, barney, &amp; pebbles');
  14273. * // => 'fred, barney, & pebbles'
  14274. */
  14275. function unescape(string) {
  14276. string = toString(string);
  14277. return (string && reHasEscapedHtml.test(string))
  14278. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14279. : string;
  14280. }
  14281. /**
  14282. * Converts `string`, as space separated words, to upper case.
  14283. *
  14284. * @static
  14285. * @memberOf _
  14286. * @since 4.0.0
  14287. * @category String
  14288. * @param {string} [string=''] The string to convert.
  14289. * @returns {string} Returns the upper cased string.
  14290. * @example
  14291. *
  14292. * _.upperCase('--foo-bar');
  14293. * // => 'FOO BAR'
  14294. *
  14295. * _.upperCase('fooBar');
  14296. * // => 'FOO BAR'
  14297. *
  14298. * _.upperCase('__foo_bar__');
  14299. * // => 'FOO BAR'
  14300. */
  14301. var upperCase = createCompounder(function(result, word, index) {
  14302. return result + (index ? ' ' : '') + word.toUpperCase();
  14303. });
  14304. /**
  14305. * Converts the first character of `string` to upper case.
  14306. *
  14307. * @static
  14308. * @memberOf _
  14309. * @since 4.0.0
  14310. * @category String
  14311. * @param {string} [string=''] The string to convert.
  14312. * @returns {string} Returns the converted string.
  14313. * @example
  14314. *
  14315. * _.upperFirst('fred');
  14316. * // => 'Fred'
  14317. *
  14318. * _.upperFirst('FRED');
  14319. * // => 'FRED'
  14320. */
  14321. var upperFirst = createCaseFirst('toUpperCase');
  14322. /**
  14323. * Splits `string` into an array of its words.
  14324. *
  14325. * @static
  14326. * @memberOf _
  14327. * @since 3.0.0
  14328. * @category String
  14329. * @param {string} [string=''] The string to inspect.
  14330. * @param {RegExp|string} [pattern] The pattern to match words.
  14331. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14332. * @returns {Array} Returns the words of `string`.
  14333. * @example
  14334. *
  14335. * _.words('fred, barney, & pebbles');
  14336. * // => ['fred', 'barney', 'pebbles']
  14337. *
  14338. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14339. * // => ['fred', 'barney', '&', 'pebbles']
  14340. */
  14341. function words(string, pattern, guard) {
  14342. string = toString(string);
  14343. pattern = guard ? undefined : pattern;
  14344. if (pattern === undefined) {
  14345. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14346. }
  14347. return string.match(pattern) || [];
  14348. }
  14349. /*------------------------------------------------------------------------*/
  14350. /**
  14351. * Attempts to invoke `func`, returning either the result or the caught error
  14352. * object. Any additional arguments are provided to `func` when it's invoked.
  14353. *
  14354. * @static
  14355. * @memberOf _
  14356. * @since 3.0.0
  14357. * @category Util
  14358. * @param {Function} func The function to attempt.
  14359. * @param {...*} [args] The arguments to invoke `func` with.
  14360. * @returns {*} Returns the `func` result or error object.
  14361. * @example
  14362. *
  14363. * // Avoid throwing errors for invalid selectors.
  14364. * var elements = _.attempt(function(selector) {
  14365. * return document.querySelectorAll(selector);
  14366. * }, '>_>');
  14367. *
  14368. * if (_.isError(elements)) {
  14369. * elements = [];
  14370. * }
  14371. */
  14372. var attempt = baseRest(function(func, args) {
  14373. try {
  14374. return apply(func, undefined, args);
  14375. } catch (e) {
  14376. return isError(e) ? e : new Error(e);
  14377. }
  14378. });
  14379. /**
  14380. * Binds methods of an object to the object itself, overwriting the existing
  14381. * method.
  14382. *
  14383. * **Note:** This method doesn't set the "length" property of bound functions.
  14384. *
  14385. * @static
  14386. * @since 0.1.0
  14387. * @memberOf _
  14388. * @category Util
  14389. * @param {Object} object The object to bind and assign the bound methods to.
  14390. * @param {...(string|string[])} methodNames The object method names to bind.
  14391. * @returns {Object} Returns `object`.
  14392. * @example
  14393. *
  14394. * var view = {
  14395. * 'label': 'docs',
  14396. * 'click': function() {
  14397. * console.log('clicked ' + this.label);
  14398. * }
  14399. * };
  14400. *
  14401. * _.bindAll(view, ['click']);
  14402. * jQuery(element).on('click', view.click);
  14403. * // => Logs 'clicked docs' when clicked.
  14404. */
  14405. var bindAll = flatRest(function(object, methodNames) {
  14406. arrayEach(methodNames, function(key) {
  14407. key = toKey(key);
  14408. baseAssignValue(object, key, bind(object[key], object));
  14409. });
  14410. return object;
  14411. });
  14412. /**
  14413. * Creates a function that iterates over `pairs` and invokes the corresponding
  14414. * function of the first predicate to return truthy. The predicate-function
  14415. * pairs are invoked with the `this` binding and arguments of the created
  14416. * function.
  14417. *
  14418. * @static
  14419. * @memberOf _
  14420. * @since 4.0.0
  14421. * @category Util
  14422. * @param {Array} pairs The predicate-function pairs.
  14423. * @returns {Function} Returns the new composite function.
  14424. * @example
  14425. *
  14426. * var func = _.cond([
  14427. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14428. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14429. * [_.stubTrue, _.constant('no match')]
  14430. * ]);
  14431. *
  14432. * func({ 'a': 1, 'b': 2 });
  14433. * // => 'matches A'
  14434. *
  14435. * func({ 'a': 0, 'b': 1 });
  14436. * // => 'matches B'
  14437. *
  14438. * func({ 'a': '1', 'b': '2' });
  14439. * // => 'no match'
  14440. */
  14441. function cond(pairs) {
  14442. var length = pairs == null ? 0 : pairs.length,
  14443. toIteratee = getIteratee();
  14444. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14445. if (typeof pair[1] != 'function') {
  14446. throw new TypeError(FUNC_ERROR_TEXT);
  14447. }
  14448. return [toIteratee(pair[0]), pair[1]];
  14449. });
  14450. return baseRest(function(args) {
  14451. var index = -1;
  14452. while (++index < length) {
  14453. var pair = pairs[index];
  14454. if (apply(pair[0], this, args)) {
  14455. return apply(pair[1], this, args);
  14456. }
  14457. }
  14458. });
  14459. }
  14460. /**
  14461. * Creates a function that invokes the predicate properties of `source` with
  14462. * the corresponding property values of a given object, returning `true` if
  14463. * all predicates return truthy, else `false`.
  14464. *
  14465. * **Note:** The created function is equivalent to `_.conformsTo` with
  14466. * `source` partially applied.
  14467. *
  14468. * @static
  14469. * @memberOf _
  14470. * @since 4.0.0
  14471. * @category Util
  14472. * @param {Object} source The object of property predicates to conform to.
  14473. * @returns {Function} Returns the new spec function.
  14474. * @example
  14475. *
  14476. * var objects = [
  14477. * { 'a': 2, 'b': 1 },
  14478. * { 'a': 1, 'b': 2 }
  14479. * ];
  14480. *
  14481. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14482. * // => [{ 'a': 1, 'b': 2 }]
  14483. */
  14484. function conforms(source) {
  14485. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14486. }
  14487. /**
  14488. * Creates a function that returns `value`.
  14489. *
  14490. * @static
  14491. * @memberOf _
  14492. * @since 2.4.0
  14493. * @category Util
  14494. * @param {*} value The value to return from the new function.
  14495. * @returns {Function} Returns the new constant function.
  14496. * @example
  14497. *
  14498. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14499. *
  14500. * console.log(objects);
  14501. * // => [{ 'a': 1 }, { 'a': 1 }]
  14502. *
  14503. * console.log(objects[0] === objects[1]);
  14504. * // => true
  14505. */
  14506. function constant(value) {
  14507. return function() {
  14508. return value;
  14509. };
  14510. }
  14511. /**
  14512. * Checks `value` to determine whether a default value should be returned in
  14513. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14514. * or `undefined`.
  14515. *
  14516. * @static
  14517. * @memberOf _
  14518. * @since 4.14.0
  14519. * @category Util
  14520. * @param {*} value The value to check.
  14521. * @param {*} defaultValue The default value.
  14522. * @returns {*} Returns the resolved value.
  14523. * @example
  14524. *
  14525. * _.defaultTo(1, 10);
  14526. * // => 1
  14527. *
  14528. * _.defaultTo(undefined, 10);
  14529. * // => 10
  14530. */
  14531. function defaultTo(value, defaultValue) {
  14532. return (value == null || value !== value) ? defaultValue : value;
  14533. }
  14534. /**
  14535. * Creates a function that returns the result of invoking the given functions
  14536. * with the `this` binding of the created function, where each successive
  14537. * invocation is supplied the return value of the previous.
  14538. *
  14539. * @static
  14540. * @memberOf _
  14541. * @since 3.0.0
  14542. * @category Util
  14543. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14544. * @returns {Function} Returns the new composite function.
  14545. * @see _.flowRight
  14546. * @example
  14547. *
  14548. * function square(n) {
  14549. * return n * n;
  14550. * }
  14551. *
  14552. * var addSquare = _.flow([_.add, square]);
  14553. * addSquare(1, 2);
  14554. * // => 9
  14555. */
  14556. var flow = createFlow();
  14557. /**
  14558. * This method is like `_.flow` except that it creates a function that
  14559. * invokes the given functions from right to left.
  14560. *
  14561. * @static
  14562. * @since 3.0.0
  14563. * @memberOf _
  14564. * @category Util
  14565. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14566. * @returns {Function} Returns the new composite function.
  14567. * @see _.flow
  14568. * @example
  14569. *
  14570. * function square(n) {
  14571. * return n * n;
  14572. * }
  14573. *
  14574. * var addSquare = _.flowRight([square, _.add]);
  14575. * addSquare(1, 2);
  14576. * // => 9
  14577. */
  14578. var flowRight = createFlow(true);
  14579. /**
  14580. * This method returns the first argument it receives.
  14581. *
  14582. * @static
  14583. * @since 0.1.0
  14584. * @memberOf _
  14585. * @category Util
  14586. * @param {*} value Any value.
  14587. * @returns {*} Returns `value`.
  14588. * @example
  14589. *
  14590. * var object = { 'a': 1 };
  14591. *
  14592. * console.log(_.identity(object) === object);
  14593. * // => true
  14594. */
  14595. function identity(value) {
  14596. return value;
  14597. }
  14598. /**
  14599. * Creates a function that invokes `func` with the arguments of the created
  14600. * function. If `func` is a property name, the created function returns the
  14601. * property value for a given element. If `func` is an array or object, the
  14602. * created function returns `true` for elements that contain the equivalent
  14603. * source properties, otherwise it returns `false`.
  14604. *
  14605. * @static
  14606. * @since 4.0.0
  14607. * @memberOf _
  14608. * @category Util
  14609. * @param {*} [func=_.identity] The value to convert to a callback.
  14610. * @returns {Function} Returns the callback.
  14611. * @example
  14612. *
  14613. * var users = [
  14614. * { 'user': 'barney', 'age': 36, 'active': true },
  14615. * { 'user': 'fred', 'age': 40, 'active': false }
  14616. * ];
  14617. *
  14618. * // The `_.matches` iteratee shorthand.
  14619. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14620. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14621. *
  14622. * // The `_.matchesProperty` iteratee shorthand.
  14623. * _.filter(users, _.iteratee(['user', 'fred']));
  14624. * // => [{ 'user': 'fred', 'age': 40 }]
  14625. *
  14626. * // The `_.property` iteratee shorthand.
  14627. * _.map(users, _.iteratee('user'));
  14628. * // => ['barney', 'fred']
  14629. *
  14630. * // Create custom iteratee shorthands.
  14631. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14632. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14633. * return func.test(string);
  14634. * };
  14635. * });
  14636. *
  14637. * _.filter(['abc', 'def'], /ef/);
  14638. * // => ['def']
  14639. */
  14640. function iteratee(func) {
  14641. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14642. }
  14643. /**
  14644. * Creates a function that performs a partial deep comparison between a given
  14645. * object and `source`, returning `true` if the given object has equivalent
  14646. * property values, else `false`.
  14647. *
  14648. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14649. * partially applied.
  14650. *
  14651. * Partial comparisons will match empty array and empty object `source`
  14652. * values against any array or object value, respectively. See `_.isEqual`
  14653. * for a list of supported value comparisons.
  14654. *
  14655. * **Note:** Multiple values can be checked by combining several matchers
  14656. * using `_.overSome`
  14657. *
  14658. * @static
  14659. * @memberOf _
  14660. * @since 3.0.0
  14661. * @category Util
  14662. * @param {Object} source The object of property values to match.
  14663. * @returns {Function} Returns the new spec function.
  14664. * @example
  14665. *
  14666. * var objects = [
  14667. * { 'a': 1, 'b': 2, 'c': 3 },
  14668. * { 'a': 4, 'b': 5, 'c': 6 }
  14669. * ];
  14670. *
  14671. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14672. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14673. *
  14674. * // Checking for several possible values
  14675. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  14676. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14677. */
  14678. function matches(source) {
  14679. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14680. }
  14681. /**
  14682. * Creates a function that performs a partial deep comparison between the
  14683. * value at `path` of a given object to `srcValue`, returning `true` if the
  14684. * object value is equivalent, else `false`.
  14685. *
  14686. * **Note:** Partial comparisons will match empty array and empty object
  14687. * `srcValue` values against any array or object value, respectively. See
  14688. * `_.isEqual` for a list of supported value comparisons.
  14689. *
  14690. * **Note:** Multiple values can be checked by combining several matchers
  14691. * using `_.overSome`
  14692. *
  14693. * @static
  14694. * @memberOf _
  14695. * @since 3.2.0
  14696. * @category Util
  14697. * @param {Array|string} path The path of the property to get.
  14698. * @param {*} srcValue The value to match.
  14699. * @returns {Function} Returns the new spec function.
  14700. * @example
  14701. *
  14702. * var objects = [
  14703. * { 'a': 1, 'b': 2, 'c': 3 },
  14704. * { 'a': 4, 'b': 5, 'c': 6 }
  14705. * ];
  14706. *
  14707. * _.find(objects, _.matchesProperty('a', 4));
  14708. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14709. *
  14710. * // Checking for several possible values
  14711. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  14712. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14713. */
  14714. function matchesProperty(path, srcValue) {
  14715. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14716. }
  14717. /**
  14718. * Creates a function that invokes the method at `path` of a given object.
  14719. * Any additional arguments are provided to the invoked method.
  14720. *
  14721. * @static
  14722. * @memberOf _
  14723. * @since 3.7.0
  14724. * @category Util
  14725. * @param {Array|string} path The path of the method to invoke.
  14726. * @param {...*} [args] The arguments to invoke the method with.
  14727. * @returns {Function} Returns the new invoker function.
  14728. * @example
  14729. *
  14730. * var objects = [
  14731. * { 'a': { 'b': _.constant(2) } },
  14732. * { 'a': { 'b': _.constant(1) } }
  14733. * ];
  14734. *
  14735. * _.map(objects, _.method('a.b'));
  14736. * // => [2, 1]
  14737. *
  14738. * _.map(objects, _.method(['a', 'b']));
  14739. * // => [2, 1]
  14740. */
  14741. var method = baseRest(function(path, args) {
  14742. return function(object) {
  14743. return baseInvoke(object, path, args);
  14744. };
  14745. });
  14746. /**
  14747. * The opposite of `_.method`; this method creates a function that invokes
  14748. * the method at a given path of `object`. Any additional arguments are
  14749. * provided to the invoked method.
  14750. *
  14751. * @static
  14752. * @memberOf _
  14753. * @since 3.7.0
  14754. * @category Util
  14755. * @param {Object} object The object to query.
  14756. * @param {...*} [args] The arguments to invoke the method with.
  14757. * @returns {Function} Returns the new invoker function.
  14758. * @example
  14759. *
  14760. * var array = _.times(3, _.constant),
  14761. * object = { 'a': array, 'b': array, 'c': array };
  14762. *
  14763. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14764. * // => [2, 0]
  14765. *
  14766. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14767. * // => [2, 0]
  14768. */
  14769. var methodOf = baseRest(function(object, args) {
  14770. return function(path) {
  14771. return baseInvoke(object, path, args);
  14772. };
  14773. });
  14774. /**
  14775. * Adds all own enumerable string keyed function properties of a source
  14776. * object to the destination object. If `object` is a function, then methods
  14777. * are added to its prototype as well.
  14778. *
  14779. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14780. * avoid conflicts caused by modifying the original.
  14781. *
  14782. * @static
  14783. * @since 0.1.0
  14784. * @memberOf _
  14785. * @category Util
  14786. * @param {Function|Object} [object=lodash] The destination object.
  14787. * @param {Object} source The object of functions to add.
  14788. * @param {Object} [options={}] The options object.
  14789. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14790. * @returns {Function|Object} Returns `object`.
  14791. * @example
  14792. *
  14793. * function vowels(string) {
  14794. * return _.filter(string, function(v) {
  14795. * return /[aeiou]/i.test(v);
  14796. * });
  14797. * }
  14798. *
  14799. * _.mixin({ 'vowels': vowels });
  14800. * _.vowels('fred');
  14801. * // => ['e']
  14802. *
  14803. * _('fred').vowels().value();
  14804. * // => ['e']
  14805. *
  14806. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14807. * _('fred').vowels();
  14808. * // => ['e']
  14809. */
  14810. function mixin(object, source, options) {
  14811. var props = keys(source),
  14812. methodNames = baseFunctions(source, props);
  14813. if (options == null &&
  14814. !(isObject(source) && (methodNames.length || !props.length))) {
  14815. options = source;
  14816. source = object;
  14817. object = this;
  14818. methodNames = baseFunctions(source, keys(source));
  14819. }
  14820. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14821. isFunc = isFunction(object);
  14822. arrayEach(methodNames, function(methodName) {
  14823. var func = source[methodName];
  14824. object[methodName] = func;
  14825. if (isFunc) {
  14826. object.prototype[methodName] = function() {
  14827. var chainAll = this.__chain__;
  14828. if (chain || chainAll) {
  14829. var result = object(this.__wrapped__),
  14830. actions = result.__actions__ = copyArray(this.__actions__);
  14831. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14832. result.__chain__ = chainAll;
  14833. return result;
  14834. }
  14835. return func.apply(object, arrayPush([this.value()], arguments));
  14836. };
  14837. }
  14838. });
  14839. return object;
  14840. }
  14841. /**
  14842. * Reverts the `_` variable to its previous value and returns a reference to
  14843. * the `lodash` function.
  14844. *
  14845. * @static
  14846. * @since 0.1.0
  14847. * @memberOf _
  14848. * @category Util
  14849. * @returns {Function} Returns the `lodash` function.
  14850. * @example
  14851. *
  14852. * var lodash = _.noConflict();
  14853. */
  14854. function noConflict() {
  14855. if (root._ === this) {
  14856. root._ = oldDash;
  14857. }
  14858. return this;
  14859. }
  14860. /**
  14861. * This method returns `undefined`.
  14862. *
  14863. * @static
  14864. * @memberOf _
  14865. * @since 2.3.0
  14866. * @category Util
  14867. * @example
  14868. *
  14869. * _.times(2, _.noop);
  14870. * // => [undefined, undefined]
  14871. */
  14872. function noop() {
  14873. // No operation performed.
  14874. }
  14875. /**
  14876. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14877. * the nth argument from the end is returned.
  14878. *
  14879. * @static
  14880. * @memberOf _
  14881. * @since 4.0.0
  14882. * @category Util
  14883. * @param {number} [n=0] The index of the argument to return.
  14884. * @returns {Function} Returns the new pass-thru function.
  14885. * @example
  14886. *
  14887. * var func = _.nthArg(1);
  14888. * func('a', 'b', 'c', 'd');
  14889. * // => 'b'
  14890. *
  14891. * var func = _.nthArg(-2);
  14892. * func('a', 'b', 'c', 'd');
  14893. * // => 'c'
  14894. */
  14895. function nthArg(n) {
  14896. n = toInteger(n);
  14897. return baseRest(function(args) {
  14898. return baseNth(args, n);
  14899. });
  14900. }
  14901. /**
  14902. * Creates a function that invokes `iteratees` with the arguments it receives
  14903. * and returns their results.
  14904. *
  14905. * @static
  14906. * @memberOf _
  14907. * @since 4.0.0
  14908. * @category Util
  14909. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14910. * The iteratees to invoke.
  14911. * @returns {Function} Returns the new function.
  14912. * @example
  14913. *
  14914. * var func = _.over([Math.max, Math.min]);
  14915. *
  14916. * func(1, 2, 3, 4);
  14917. * // => [4, 1]
  14918. */
  14919. var over = createOver(arrayMap);
  14920. /**
  14921. * Creates a function that checks if **all** of the `predicates` return
  14922. * truthy when invoked with the arguments it receives.
  14923. *
  14924. * Following shorthands are possible for providing predicates.
  14925. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14926. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14927. *
  14928. * @static
  14929. * @memberOf _
  14930. * @since 4.0.0
  14931. * @category Util
  14932. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14933. * The predicates to check.
  14934. * @returns {Function} Returns the new function.
  14935. * @example
  14936. *
  14937. * var func = _.overEvery([Boolean, isFinite]);
  14938. *
  14939. * func('1');
  14940. * // => true
  14941. *
  14942. * func(null);
  14943. * // => false
  14944. *
  14945. * func(NaN);
  14946. * // => false
  14947. */
  14948. var overEvery = createOver(arrayEvery);
  14949. /**
  14950. * Creates a function that checks if **any** of the `predicates` return
  14951. * truthy when invoked with the arguments it receives.
  14952. *
  14953. * Following shorthands are possible for providing predicates.
  14954. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14955. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14956. *
  14957. * @static
  14958. * @memberOf _
  14959. * @since 4.0.0
  14960. * @category Util
  14961. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14962. * The predicates to check.
  14963. * @returns {Function} Returns the new function.
  14964. * @example
  14965. *
  14966. * var func = _.overSome([Boolean, isFinite]);
  14967. *
  14968. * func('1');
  14969. * // => true
  14970. *
  14971. * func(null);
  14972. * // => true
  14973. *
  14974. * func(NaN);
  14975. * // => false
  14976. *
  14977. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  14978. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  14979. */
  14980. var overSome = createOver(arraySome);
  14981. /**
  14982. * Creates a function that returns the value at `path` of a given object.
  14983. *
  14984. * @static
  14985. * @memberOf _
  14986. * @since 2.4.0
  14987. * @category Util
  14988. * @param {Array|string} path The path of the property to get.
  14989. * @returns {Function} Returns the new accessor function.
  14990. * @example
  14991. *
  14992. * var objects = [
  14993. * { 'a': { 'b': 2 } },
  14994. * { 'a': { 'b': 1 } }
  14995. * ];
  14996. *
  14997. * _.map(objects, _.property('a.b'));
  14998. * // => [2, 1]
  14999. *
  15000. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  15001. * // => [1, 2]
  15002. */
  15003. function property(path) {
  15004. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  15005. }
  15006. /**
  15007. * The opposite of `_.property`; this method creates a function that returns
  15008. * the value at a given path of `object`.
  15009. *
  15010. * @static
  15011. * @memberOf _
  15012. * @since 3.0.0
  15013. * @category Util
  15014. * @param {Object} object The object to query.
  15015. * @returns {Function} Returns the new accessor function.
  15016. * @example
  15017. *
  15018. * var array = [0, 1, 2],
  15019. * object = { 'a': array, 'b': array, 'c': array };
  15020. *
  15021. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15022. * // => [2, 0]
  15023. *
  15024. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15025. * // => [2, 0]
  15026. */
  15027. function propertyOf(object) {
  15028. return function(path) {
  15029. return object == null ? undefined : baseGet(object, path);
  15030. };
  15031. }
  15032. /**
  15033. * Creates an array of numbers (positive and/or negative) progressing from
  15034. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15035. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15036. * it's set to `start` with `start` then set to `0`.
  15037. *
  15038. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15039. * floating-point values which can produce unexpected results.
  15040. *
  15041. * @static
  15042. * @since 0.1.0
  15043. * @memberOf _
  15044. * @category Util
  15045. * @param {number} [start=0] The start of the range.
  15046. * @param {number} end The end of the range.
  15047. * @param {number} [step=1] The value to increment or decrement by.
  15048. * @returns {Array} Returns the range of numbers.
  15049. * @see _.inRange, _.rangeRight
  15050. * @example
  15051. *
  15052. * _.range(4);
  15053. * // => [0, 1, 2, 3]
  15054. *
  15055. * _.range(-4);
  15056. * // => [0, -1, -2, -3]
  15057. *
  15058. * _.range(1, 5);
  15059. * // => [1, 2, 3, 4]
  15060. *
  15061. * _.range(0, 20, 5);
  15062. * // => [0, 5, 10, 15]
  15063. *
  15064. * _.range(0, -4, -1);
  15065. * // => [0, -1, -2, -3]
  15066. *
  15067. * _.range(1, 4, 0);
  15068. * // => [1, 1, 1]
  15069. *
  15070. * _.range(0);
  15071. * // => []
  15072. */
  15073. var range = createRange();
  15074. /**
  15075. * This method is like `_.range` except that it populates values in
  15076. * descending order.
  15077. *
  15078. * @static
  15079. * @memberOf _
  15080. * @since 4.0.0
  15081. * @category Util
  15082. * @param {number} [start=0] The start of the range.
  15083. * @param {number} end The end of the range.
  15084. * @param {number} [step=1] The value to increment or decrement by.
  15085. * @returns {Array} Returns the range of numbers.
  15086. * @see _.inRange, _.range
  15087. * @example
  15088. *
  15089. * _.rangeRight(4);
  15090. * // => [3, 2, 1, 0]
  15091. *
  15092. * _.rangeRight(-4);
  15093. * // => [-3, -2, -1, 0]
  15094. *
  15095. * _.rangeRight(1, 5);
  15096. * // => [4, 3, 2, 1]
  15097. *
  15098. * _.rangeRight(0, 20, 5);
  15099. * // => [15, 10, 5, 0]
  15100. *
  15101. * _.rangeRight(0, -4, -1);
  15102. * // => [-3, -2, -1, 0]
  15103. *
  15104. * _.rangeRight(1, 4, 0);
  15105. * // => [1, 1, 1]
  15106. *
  15107. * _.rangeRight(0);
  15108. * // => []
  15109. */
  15110. var rangeRight = createRange(true);
  15111. /**
  15112. * This method returns a new empty array.
  15113. *
  15114. * @static
  15115. * @memberOf _
  15116. * @since 4.13.0
  15117. * @category Util
  15118. * @returns {Array} Returns the new empty array.
  15119. * @example
  15120. *
  15121. * var arrays = _.times(2, _.stubArray);
  15122. *
  15123. * console.log(arrays);
  15124. * // => [[], []]
  15125. *
  15126. * console.log(arrays[0] === arrays[1]);
  15127. * // => false
  15128. */
  15129. function stubArray() {
  15130. return [];
  15131. }
  15132. /**
  15133. * This method returns `false`.
  15134. *
  15135. * @static
  15136. * @memberOf _
  15137. * @since 4.13.0
  15138. * @category Util
  15139. * @returns {boolean} Returns `false`.
  15140. * @example
  15141. *
  15142. * _.times(2, _.stubFalse);
  15143. * // => [false, false]
  15144. */
  15145. function stubFalse() {
  15146. return false;
  15147. }
  15148. /**
  15149. * This method returns a new empty object.
  15150. *
  15151. * @static
  15152. * @memberOf _
  15153. * @since 4.13.0
  15154. * @category Util
  15155. * @returns {Object} Returns the new empty object.
  15156. * @example
  15157. *
  15158. * var objects = _.times(2, _.stubObject);
  15159. *
  15160. * console.log(objects);
  15161. * // => [{}, {}]
  15162. *
  15163. * console.log(objects[0] === objects[1]);
  15164. * // => false
  15165. */
  15166. function stubObject() {
  15167. return {};
  15168. }
  15169. /**
  15170. * This method returns an empty string.
  15171. *
  15172. * @static
  15173. * @memberOf _
  15174. * @since 4.13.0
  15175. * @category Util
  15176. * @returns {string} Returns the empty string.
  15177. * @example
  15178. *
  15179. * _.times(2, _.stubString);
  15180. * // => ['', '']
  15181. */
  15182. function stubString() {
  15183. return '';
  15184. }
  15185. /**
  15186. * This method returns `true`.
  15187. *
  15188. * @static
  15189. * @memberOf _
  15190. * @since 4.13.0
  15191. * @category Util
  15192. * @returns {boolean} Returns `true`.
  15193. * @example
  15194. *
  15195. * _.times(2, _.stubTrue);
  15196. * // => [true, true]
  15197. */
  15198. function stubTrue() {
  15199. return true;
  15200. }
  15201. /**
  15202. * Invokes the iteratee `n` times, returning an array of the results of
  15203. * each invocation. The iteratee is invoked with one argument; (index).
  15204. *
  15205. * @static
  15206. * @since 0.1.0
  15207. * @memberOf _
  15208. * @category Util
  15209. * @param {number} n The number of times to invoke `iteratee`.
  15210. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15211. * @returns {Array} Returns the array of results.
  15212. * @example
  15213. *
  15214. * _.times(3, String);
  15215. * // => ['0', '1', '2']
  15216. *
  15217. * _.times(4, _.constant(0));
  15218. * // => [0, 0, 0, 0]
  15219. */
  15220. function times(n, iteratee) {
  15221. n = toInteger(n);
  15222. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15223. return [];
  15224. }
  15225. var index = MAX_ARRAY_LENGTH,
  15226. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15227. iteratee = getIteratee(iteratee);
  15228. n -= MAX_ARRAY_LENGTH;
  15229. var result = baseTimes(length, iteratee);
  15230. while (++index < n) {
  15231. iteratee(index);
  15232. }
  15233. return result;
  15234. }
  15235. /**
  15236. * Converts `value` to a property path array.
  15237. *
  15238. * @static
  15239. * @memberOf _
  15240. * @since 4.0.0
  15241. * @category Util
  15242. * @param {*} value The value to convert.
  15243. * @returns {Array} Returns the new property path array.
  15244. * @example
  15245. *
  15246. * _.toPath('a.b.c');
  15247. * // => ['a', 'b', 'c']
  15248. *
  15249. * _.toPath('a[0].b.c');
  15250. * // => ['a', '0', 'b', 'c']
  15251. */
  15252. function toPath(value) {
  15253. if (isArray(value)) {
  15254. return arrayMap(value, toKey);
  15255. }
  15256. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15257. }
  15258. /**
  15259. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15260. *
  15261. * @static
  15262. * @since 0.1.0
  15263. * @memberOf _
  15264. * @category Util
  15265. * @param {string} [prefix=''] The value to prefix the ID with.
  15266. * @returns {string} Returns the unique ID.
  15267. * @example
  15268. *
  15269. * _.uniqueId('contact_');
  15270. * // => 'contact_104'
  15271. *
  15272. * _.uniqueId();
  15273. * // => '105'
  15274. */
  15275. function uniqueId(prefix) {
  15276. var id = ++idCounter;
  15277. return toString(prefix) + id;
  15278. }
  15279. /*------------------------------------------------------------------------*/
  15280. /**
  15281. * Adds two numbers.
  15282. *
  15283. * @static
  15284. * @memberOf _
  15285. * @since 3.4.0
  15286. * @category Math
  15287. * @param {number} augend The first number in an addition.
  15288. * @param {number} addend The second number in an addition.
  15289. * @returns {number} Returns the total.
  15290. * @example
  15291. *
  15292. * _.add(6, 4);
  15293. * // => 10
  15294. */
  15295. var add = createMathOperation(function(augend, addend) {
  15296. return augend + addend;
  15297. }, 0);
  15298. /**
  15299. * Computes `number` rounded up to `precision`.
  15300. *
  15301. * @static
  15302. * @memberOf _
  15303. * @since 3.10.0
  15304. * @category Math
  15305. * @param {number} number The number to round up.
  15306. * @param {number} [precision=0] The precision to round up to.
  15307. * @returns {number} Returns the rounded up number.
  15308. * @example
  15309. *
  15310. * _.ceil(4.006);
  15311. * // => 5
  15312. *
  15313. * _.ceil(6.004, 2);
  15314. * // => 6.01
  15315. *
  15316. * _.ceil(6040, -2);
  15317. * // => 6100
  15318. */
  15319. var ceil = createRound('ceil');
  15320. /**
  15321. * Divide two numbers.
  15322. *
  15323. * @static
  15324. * @memberOf _
  15325. * @since 4.7.0
  15326. * @category Math
  15327. * @param {number} dividend The first number in a division.
  15328. * @param {number} divisor The second number in a division.
  15329. * @returns {number} Returns the quotient.
  15330. * @example
  15331. *
  15332. * _.divide(6, 4);
  15333. * // => 1.5
  15334. */
  15335. var divide = createMathOperation(function(dividend, divisor) {
  15336. return dividend / divisor;
  15337. }, 1);
  15338. /**
  15339. * Computes `number` rounded down to `precision`.
  15340. *
  15341. * @static
  15342. * @memberOf _
  15343. * @since 3.10.0
  15344. * @category Math
  15345. * @param {number} number The number to round down.
  15346. * @param {number} [precision=0] The precision to round down to.
  15347. * @returns {number} Returns the rounded down number.
  15348. * @example
  15349. *
  15350. * _.floor(4.006);
  15351. * // => 4
  15352. *
  15353. * _.floor(0.046, 2);
  15354. * // => 0.04
  15355. *
  15356. * _.floor(4060, -2);
  15357. * // => 4000
  15358. */
  15359. var floor = createRound('floor');
  15360. /**
  15361. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15362. * `undefined` is returned.
  15363. *
  15364. * @static
  15365. * @since 0.1.0
  15366. * @memberOf _
  15367. * @category Math
  15368. * @param {Array} array The array to iterate over.
  15369. * @returns {*} Returns the maximum value.
  15370. * @example
  15371. *
  15372. * _.max([4, 2, 8, 6]);
  15373. * // => 8
  15374. *
  15375. * _.max([]);
  15376. * // => undefined
  15377. */
  15378. function max(array) {
  15379. return (array && array.length)
  15380. ? baseExtremum(array, identity, baseGt)
  15381. : undefined;
  15382. }
  15383. /**
  15384. * This method is like `_.max` except that it accepts `iteratee` which is
  15385. * invoked for each element in `array` to generate the criterion by which
  15386. * the value is ranked. The iteratee is invoked with one argument: (value).
  15387. *
  15388. * @static
  15389. * @memberOf _
  15390. * @since 4.0.0
  15391. * @category Math
  15392. * @param {Array} array The array to iterate over.
  15393. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15394. * @returns {*} Returns the maximum value.
  15395. * @example
  15396. *
  15397. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15398. *
  15399. * _.maxBy(objects, function(o) { return o.n; });
  15400. * // => { 'n': 2 }
  15401. *
  15402. * // The `_.property` iteratee shorthand.
  15403. * _.maxBy(objects, 'n');
  15404. * // => { 'n': 2 }
  15405. */
  15406. function maxBy(array, iteratee) {
  15407. return (array && array.length)
  15408. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15409. : undefined;
  15410. }
  15411. /**
  15412. * Computes the mean of the values in `array`.
  15413. *
  15414. * @static
  15415. * @memberOf _
  15416. * @since 4.0.0
  15417. * @category Math
  15418. * @param {Array} array The array to iterate over.
  15419. * @returns {number} Returns the mean.
  15420. * @example
  15421. *
  15422. * _.mean([4, 2, 8, 6]);
  15423. * // => 5
  15424. */
  15425. function mean(array) {
  15426. return baseMean(array, identity);
  15427. }
  15428. /**
  15429. * This method is like `_.mean` except that it accepts `iteratee` which is
  15430. * invoked for each element in `array` to generate the value to be averaged.
  15431. * The iteratee is invoked with one argument: (value).
  15432. *
  15433. * @static
  15434. * @memberOf _
  15435. * @since 4.7.0
  15436. * @category Math
  15437. * @param {Array} array The array to iterate over.
  15438. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15439. * @returns {number} Returns the mean.
  15440. * @example
  15441. *
  15442. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15443. *
  15444. * _.meanBy(objects, function(o) { return o.n; });
  15445. * // => 5
  15446. *
  15447. * // The `_.property` iteratee shorthand.
  15448. * _.meanBy(objects, 'n');
  15449. * // => 5
  15450. */
  15451. function meanBy(array, iteratee) {
  15452. return baseMean(array, getIteratee(iteratee, 2));
  15453. }
  15454. /**
  15455. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15456. * `undefined` is returned.
  15457. *
  15458. * @static
  15459. * @since 0.1.0
  15460. * @memberOf _
  15461. * @category Math
  15462. * @param {Array} array The array to iterate over.
  15463. * @returns {*} Returns the minimum value.
  15464. * @example
  15465. *
  15466. * _.min([4, 2, 8, 6]);
  15467. * // => 2
  15468. *
  15469. * _.min([]);
  15470. * // => undefined
  15471. */
  15472. function min(array) {
  15473. return (array && array.length)
  15474. ? baseExtremum(array, identity, baseLt)
  15475. : undefined;
  15476. }
  15477. /**
  15478. * This method is like `_.min` except that it accepts `iteratee` which is
  15479. * invoked for each element in `array` to generate the criterion by which
  15480. * the value is ranked. The iteratee is invoked with one argument: (value).
  15481. *
  15482. * @static
  15483. * @memberOf _
  15484. * @since 4.0.0
  15485. * @category Math
  15486. * @param {Array} array The array to iterate over.
  15487. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15488. * @returns {*} Returns the minimum value.
  15489. * @example
  15490. *
  15491. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15492. *
  15493. * _.minBy(objects, function(o) { return o.n; });
  15494. * // => { 'n': 1 }
  15495. *
  15496. * // The `_.property` iteratee shorthand.
  15497. * _.minBy(objects, 'n');
  15498. * // => { 'n': 1 }
  15499. */
  15500. function minBy(array, iteratee) {
  15501. return (array && array.length)
  15502. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15503. : undefined;
  15504. }
  15505. /**
  15506. * Multiply two numbers.
  15507. *
  15508. * @static
  15509. * @memberOf _
  15510. * @since 4.7.0
  15511. * @category Math
  15512. * @param {number} multiplier The first number in a multiplication.
  15513. * @param {number} multiplicand The second number in a multiplication.
  15514. * @returns {number} Returns the product.
  15515. * @example
  15516. *
  15517. * _.multiply(6, 4);
  15518. * // => 24
  15519. */
  15520. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15521. return multiplier * multiplicand;
  15522. }, 1);
  15523. /**
  15524. * Computes `number` rounded to `precision`.
  15525. *
  15526. * @static
  15527. * @memberOf _
  15528. * @since 3.10.0
  15529. * @category Math
  15530. * @param {number} number The number to round.
  15531. * @param {number} [precision=0] The precision to round to.
  15532. * @returns {number} Returns the rounded number.
  15533. * @example
  15534. *
  15535. * _.round(4.006);
  15536. * // => 4
  15537. *
  15538. * _.round(4.006, 2);
  15539. * // => 4.01
  15540. *
  15541. * _.round(4060, -2);
  15542. * // => 4100
  15543. */
  15544. var round = createRound('round');
  15545. /**
  15546. * Subtract two numbers.
  15547. *
  15548. * @static
  15549. * @memberOf _
  15550. * @since 4.0.0
  15551. * @category Math
  15552. * @param {number} minuend The first number in a subtraction.
  15553. * @param {number} subtrahend The second number in a subtraction.
  15554. * @returns {number} Returns the difference.
  15555. * @example
  15556. *
  15557. * _.subtract(6, 4);
  15558. * // => 2
  15559. */
  15560. var subtract = createMathOperation(function(minuend, subtrahend) {
  15561. return minuend - subtrahend;
  15562. }, 0);
  15563. /**
  15564. * Computes the sum of the values in `array`.
  15565. *
  15566. * @static
  15567. * @memberOf _
  15568. * @since 3.4.0
  15569. * @category Math
  15570. * @param {Array} array The array to iterate over.
  15571. * @returns {number} Returns the sum.
  15572. * @example
  15573. *
  15574. * _.sum([4, 2, 8, 6]);
  15575. * // => 20
  15576. */
  15577. function sum(array) {
  15578. return (array && array.length)
  15579. ? baseSum(array, identity)
  15580. : 0;
  15581. }
  15582. /**
  15583. * This method is like `_.sum` except that it accepts `iteratee` which is
  15584. * invoked for each element in `array` to generate the value to be summed.
  15585. * The iteratee is invoked with one argument: (value).
  15586. *
  15587. * @static
  15588. * @memberOf _
  15589. * @since 4.0.0
  15590. * @category Math
  15591. * @param {Array} array The array to iterate over.
  15592. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15593. * @returns {number} Returns the sum.
  15594. * @example
  15595. *
  15596. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15597. *
  15598. * _.sumBy(objects, function(o) { return o.n; });
  15599. * // => 20
  15600. *
  15601. * // The `_.property` iteratee shorthand.
  15602. * _.sumBy(objects, 'n');
  15603. * // => 20
  15604. */
  15605. function sumBy(array, iteratee) {
  15606. return (array && array.length)
  15607. ? baseSum(array, getIteratee(iteratee, 2))
  15608. : 0;
  15609. }
  15610. /*------------------------------------------------------------------------*/
  15611. // Add methods that return wrapped values in chain sequences.
  15612. lodash.after = after;
  15613. lodash.ary = ary;
  15614. lodash.assign = assign;
  15615. lodash.assignIn = assignIn;
  15616. lodash.assignInWith = assignInWith;
  15617. lodash.assignWith = assignWith;
  15618. lodash.at = at;
  15619. lodash.before = before;
  15620. lodash.bind = bind;
  15621. lodash.bindAll = bindAll;
  15622. lodash.bindKey = bindKey;
  15623. lodash.castArray = castArray;
  15624. lodash.chain = chain;
  15625. lodash.chunk = chunk;
  15626. lodash.compact = compact;
  15627. lodash.concat = concat;
  15628. lodash.cond = cond;
  15629. lodash.conforms = conforms;
  15630. lodash.constant = constant;
  15631. lodash.countBy = countBy;
  15632. lodash.create = create;
  15633. lodash.curry = curry;
  15634. lodash.curryRight = curryRight;
  15635. lodash.debounce = debounce;
  15636. lodash.defaults = defaults;
  15637. lodash.defaultsDeep = defaultsDeep;
  15638. lodash.defer = defer;
  15639. lodash.delay = delay;
  15640. lodash.difference = difference;
  15641. lodash.differenceBy = differenceBy;
  15642. lodash.differenceWith = differenceWith;
  15643. lodash.drop = drop;
  15644. lodash.dropRight = dropRight;
  15645. lodash.dropRightWhile = dropRightWhile;
  15646. lodash.dropWhile = dropWhile;
  15647. lodash.fill = fill;
  15648. lodash.filter = filter;
  15649. lodash.flatMap = flatMap;
  15650. lodash.flatMapDeep = flatMapDeep;
  15651. lodash.flatMapDepth = flatMapDepth;
  15652. lodash.flatten = flatten;
  15653. lodash.flattenDeep = flattenDeep;
  15654. lodash.flattenDepth = flattenDepth;
  15655. lodash.flip = flip;
  15656. lodash.flow = flow;
  15657. lodash.flowRight = flowRight;
  15658. lodash.fromPairs = fromPairs;
  15659. lodash.functions = functions;
  15660. lodash.functionsIn = functionsIn;
  15661. lodash.groupBy = groupBy;
  15662. lodash.initial = initial;
  15663. lodash.intersection = intersection;
  15664. lodash.intersectionBy = intersectionBy;
  15665. lodash.intersectionWith = intersectionWith;
  15666. lodash.invert = invert;
  15667. lodash.invertBy = invertBy;
  15668. lodash.invokeMap = invokeMap;
  15669. lodash.iteratee = iteratee;
  15670. lodash.keyBy = keyBy;
  15671. lodash.keys = keys;
  15672. lodash.keysIn = keysIn;
  15673. lodash.map = map;
  15674. lodash.mapKeys = mapKeys;
  15675. lodash.mapValues = mapValues;
  15676. lodash.matches = matches;
  15677. lodash.matchesProperty = matchesProperty;
  15678. lodash.memoize = memoize;
  15679. lodash.merge = merge;
  15680. lodash.mergeWith = mergeWith;
  15681. lodash.method = method;
  15682. lodash.methodOf = methodOf;
  15683. lodash.mixin = mixin;
  15684. lodash.negate = negate;
  15685. lodash.nthArg = nthArg;
  15686. lodash.omit = omit;
  15687. lodash.omitBy = omitBy;
  15688. lodash.once = once;
  15689. lodash.orderBy = orderBy;
  15690. lodash.over = over;
  15691. lodash.overArgs = overArgs;
  15692. lodash.overEvery = overEvery;
  15693. lodash.overSome = overSome;
  15694. lodash.partial = partial;
  15695. lodash.partialRight = partialRight;
  15696. lodash.partition = partition;
  15697. lodash.pick = pick;
  15698. lodash.pickBy = pickBy;
  15699. lodash.property = property;
  15700. lodash.propertyOf = propertyOf;
  15701. lodash.pull = pull;
  15702. lodash.pullAll = pullAll;
  15703. lodash.pullAllBy = pullAllBy;
  15704. lodash.pullAllWith = pullAllWith;
  15705. lodash.pullAt = pullAt;
  15706. lodash.range = range;
  15707. lodash.rangeRight = rangeRight;
  15708. lodash.rearg = rearg;
  15709. lodash.reject = reject;
  15710. lodash.remove = remove;
  15711. lodash.rest = rest;
  15712. lodash.reverse = reverse;
  15713. lodash.sampleSize = sampleSize;
  15714. lodash.set = set;
  15715. lodash.setWith = setWith;
  15716. lodash.shuffle = shuffle;
  15717. lodash.slice = slice;
  15718. lodash.sortBy = sortBy;
  15719. lodash.sortedUniq = sortedUniq;
  15720. lodash.sortedUniqBy = sortedUniqBy;
  15721. lodash.split = split;
  15722. lodash.spread = spread;
  15723. lodash.tail = tail;
  15724. lodash.take = take;
  15725. lodash.takeRight = takeRight;
  15726. lodash.takeRightWhile = takeRightWhile;
  15727. lodash.takeWhile = takeWhile;
  15728. lodash.tap = tap;
  15729. lodash.throttle = throttle;
  15730. lodash.thru = thru;
  15731. lodash.toArray = toArray;
  15732. lodash.toPairs = toPairs;
  15733. lodash.toPairsIn = toPairsIn;
  15734. lodash.toPath = toPath;
  15735. lodash.toPlainObject = toPlainObject;
  15736. lodash.transform = transform;
  15737. lodash.unary = unary;
  15738. lodash.union = union;
  15739. lodash.unionBy = unionBy;
  15740. lodash.unionWith = unionWith;
  15741. lodash.uniq = uniq;
  15742. lodash.uniqBy = uniqBy;
  15743. lodash.uniqWith = uniqWith;
  15744. lodash.unset = unset;
  15745. lodash.unzip = unzip;
  15746. lodash.unzipWith = unzipWith;
  15747. lodash.update = update;
  15748. lodash.updateWith = updateWith;
  15749. lodash.values = values;
  15750. lodash.valuesIn = valuesIn;
  15751. lodash.without = without;
  15752. lodash.words = words;
  15753. lodash.wrap = wrap;
  15754. lodash.xor = xor;
  15755. lodash.xorBy = xorBy;
  15756. lodash.xorWith = xorWith;
  15757. lodash.zip = zip;
  15758. lodash.zipObject = zipObject;
  15759. lodash.zipObjectDeep = zipObjectDeep;
  15760. lodash.zipWith = zipWith;
  15761. // Add aliases.
  15762. lodash.entries = toPairs;
  15763. lodash.entriesIn = toPairsIn;
  15764. lodash.extend = assignIn;
  15765. lodash.extendWith = assignInWith;
  15766. // Add methods to `lodash.prototype`.
  15767. mixin(lodash, lodash);
  15768. /*------------------------------------------------------------------------*/
  15769. // Add methods that return unwrapped values in chain sequences.
  15770. lodash.add = add;
  15771. lodash.attempt = attempt;
  15772. lodash.camelCase = camelCase;
  15773. lodash.capitalize = capitalize;
  15774. lodash.ceil = ceil;
  15775. lodash.clamp = clamp;
  15776. lodash.clone = clone;
  15777. lodash.cloneDeep = cloneDeep;
  15778. lodash.cloneDeepWith = cloneDeepWith;
  15779. lodash.cloneWith = cloneWith;
  15780. lodash.conformsTo = conformsTo;
  15781. lodash.deburr = deburr;
  15782. lodash.defaultTo = defaultTo;
  15783. lodash.divide = divide;
  15784. lodash.endsWith = endsWith;
  15785. lodash.eq = eq;
  15786. lodash.escape = escape;
  15787. lodash.escapeRegExp = escapeRegExp;
  15788. lodash.every = every;
  15789. lodash.find = find;
  15790. lodash.findIndex = findIndex;
  15791. lodash.findKey = findKey;
  15792. lodash.findLast = findLast;
  15793. lodash.findLastIndex = findLastIndex;
  15794. lodash.findLastKey = findLastKey;
  15795. lodash.floor = floor;
  15796. lodash.forEach = forEach;
  15797. lodash.forEachRight = forEachRight;
  15798. lodash.forIn = forIn;
  15799. lodash.forInRight = forInRight;
  15800. lodash.forOwn = forOwn;
  15801. lodash.forOwnRight = forOwnRight;
  15802. lodash.get = get;
  15803. lodash.gt = gt;
  15804. lodash.gte = gte;
  15805. lodash.has = has;
  15806. lodash.hasIn = hasIn;
  15807. lodash.head = head;
  15808. lodash.identity = identity;
  15809. lodash.includes = includes;
  15810. lodash.indexOf = indexOf;
  15811. lodash.inRange = inRange;
  15812. lodash.invoke = invoke;
  15813. lodash.isArguments = isArguments;
  15814. lodash.isArray = isArray;
  15815. lodash.isArrayBuffer = isArrayBuffer;
  15816. lodash.isArrayLike = isArrayLike;
  15817. lodash.isArrayLikeObject = isArrayLikeObject;
  15818. lodash.isBoolean = isBoolean;
  15819. lodash.isBuffer = isBuffer;
  15820. lodash.isDate = isDate;
  15821. lodash.isElement = isElement;
  15822. lodash.isEmpty = isEmpty;
  15823. lodash.isEqual = isEqual;
  15824. lodash.isEqualWith = isEqualWith;
  15825. lodash.isError = isError;
  15826. lodash.isFinite = isFinite;
  15827. lodash.isFunction = isFunction;
  15828. lodash.isInteger = isInteger;
  15829. lodash.isLength = isLength;
  15830. lodash.isMap = isMap;
  15831. lodash.isMatch = isMatch;
  15832. lodash.isMatchWith = isMatchWith;
  15833. lodash.isNaN = isNaN;
  15834. lodash.isNative = isNative;
  15835. lodash.isNil = isNil;
  15836. lodash.isNull = isNull;
  15837. lodash.isNumber = isNumber;
  15838. lodash.isObject = isObject;
  15839. lodash.isObjectLike = isObjectLike;
  15840. lodash.isPlainObject = isPlainObject;
  15841. lodash.isRegExp = isRegExp;
  15842. lodash.isSafeInteger = isSafeInteger;
  15843. lodash.isSet = isSet;
  15844. lodash.isString = isString;
  15845. lodash.isSymbol = isSymbol;
  15846. lodash.isTypedArray = isTypedArray;
  15847. lodash.isUndefined = isUndefined;
  15848. lodash.isWeakMap = isWeakMap;
  15849. lodash.isWeakSet = isWeakSet;
  15850. lodash.join = join;
  15851. lodash.kebabCase = kebabCase;
  15852. lodash.last = last;
  15853. lodash.lastIndexOf = lastIndexOf;
  15854. lodash.lowerCase = lowerCase;
  15855. lodash.lowerFirst = lowerFirst;
  15856. lodash.lt = lt;
  15857. lodash.lte = lte;
  15858. lodash.max = max;
  15859. lodash.maxBy = maxBy;
  15860. lodash.mean = mean;
  15861. lodash.meanBy = meanBy;
  15862. lodash.min = min;
  15863. lodash.minBy = minBy;
  15864. lodash.stubArray = stubArray;
  15865. lodash.stubFalse = stubFalse;
  15866. lodash.stubObject = stubObject;
  15867. lodash.stubString = stubString;
  15868. lodash.stubTrue = stubTrue;
  15869. lodash.multiply = multiply;
  15870. lodash.nth = nth;
  15871. lodash.noConflict = noConflict;
  15872. lodash.noop = noop;
  15873. lodash.now = now;
  15874. lodash.pad = pad;
  15875. lodash.padEnd = padEnd;
  15876. lodash.padStart = padStart;
  15877. lodash.parseInt = parseInt;
  15878. lodash.random = random;
  15879. lodash.reduce = reduce;
  15880. lodash.reduceRight = reduceRight;
  15881. lodash.repeat = repeat;
  15882. lodash.replace = replace;
  15883. lodash.result = result;
  15884. lodash.round = round;
  15885. lodash.runInContext = runInContext;
  15886. lodash.sample = sample;
  15887. lodash.size = size;
  15888. lodash.snakeCase = snakeCase;
  15889. lodash.some = some;
  15890. lodash.sortedIndex = sortedIndex;
  15891. lodash.sortedIndexBy = sortedIndexBy;
  15892. lodash.sortedIndexOf = sortedIndexOf;
  15893. lodash.sortedLastIndex = sortedLastIndex;
  15894. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15895. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15896. lodash.startCase = startCase;
  15897. lodash.startsWith = startsWith;
  15898. lodash.subtract = subtract;
  15899. lodash.sum = sum;
  15900. lodash.sumBy = sumBy;
  15901. lodash.template = template;
  15902. lodash.times = times;
  15903. lodash.toFinite = toFinite;
  15904. lodash.toInteger = toInteger;
  15905. lodash.toLength = toLength;
  15906. lodash.toLower = toLower;
  15907. lodash.toNumber = toNumber;
  15908. lodash.toSafeInteger = toSafeInteger;
  15909. lodash.toString = toString;
  15910. lodash.toUpper = toUpper;
  15911. lodash.trim = trim;
  15912. lodash.trimEnd = trimEnd;
  15913. lodash.trimStart = trimStart;
  15914. lodash.truncate = truncate;
  15915. lodash.unescape = unescape;
  15916. lodash.uniqueId = uniqueId;
  15917. lodash.upperCase = upperCase;
  15918. lodash.upperFirst = upperFirst;
  15919. // Add aliases.
  15920. lodash.each = forEach;
  15921. lodash.eachRight = forEachRight;
  15922. lodash.first = head;
  15923. mixin(lodash, (function() {
  15924. var source = {};
  15925. baseForOwn(lodash, function(func, methodName) {
  15926. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15927. source[methodName] = func;
  15928. }
  15929. });
  15930. return source;
  15931. }()), { 'chain': false });
  15932. /*------------------------------------------------------------------------*/
  15933. /**
  15934. * The semantic version number.
  15935. *
  15936. * @static
  15937. * @memberOf _
  15938. * @type {string}
  15939. */
  15940. lodash.VERSION = VERSION;
  15941. // Assign default placeholders.
  15942. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15943. lodash[methodName].placeholder = lodash;
  15944. });
  15945. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15946. arrayEach(['drop', 'take'], function(methodName, index) {
  15947. LazyWrapper.prototype[methodName] = function(n) {
  15948. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15949. var result = (this.__filtered__ && !index)
  15950. ? new LazyWrapper(this)
  15951. : this.clone();
  15952. if (result.__filtered__) {
  15953. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15954. } else {
  15955. result.__views__.push({
  15956. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15957. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15958. });
  15959. }
  15960. return result;
  15961. };
  15962. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15963. return this.reverse()[methodName](n).reverse();
  15964. };
  15965. });
  15966. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15967. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15968. var type = index + 1,
  15969. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15970. LazyWrapper.prototype[methodName] = function(iteratee) {
  15971. var result = this.clone();
  15972. result.__iteratees__.push({
  15973. 'iteratee': getIteratee(iteratee, 3),
  15974. 'type': type
  15975. });
  15976. result.__filtered__ = result.__filtered__ || isFilter;
  15977. return result;
  15978. };
  15979. });
  15980. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15981. arrayEach(['head', 'last'], function(methodName, index) {
  15982. var takeName = 'take' + (index ? 'Right' : '');
  15983. LazyWrapper.prototype[methodName] = function() {
  15984. return this[takeName](1).value()[0];
  15985. };
  15986. });
  15987. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15988. arrayEach(['initial', 'tail'], function(methodName, index) {
  15989. var dropName = 'drop' + (index ? '' : 'Right');
  15990. LazyWrapper.prototype[methodName] = function() {
  15991. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15992. };
  15993. });
  15994. LazyWrapper.prototype.compact = function() {
  15995. return this.filter(identity);
  15996. };
  15997. LazyWrapper.prototype.find = function(predicate) {
  15998. return this.filter(predicate).head();
  15999. };
  16000. LazyWrapper.prototype.findLast = function(predicate) {
  16001. return this.reverse().find(predicate);
  16002. };
  16003. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  16004. if (typeof path == 'function') {
  16005. return new LazyWrapper(this);
  16006. }
  16007. return this.map(function(value) {
  16008. return baseInvoke(value, path, args);
  16009. });
  16010. });
  16011. LazyWrapper.prototype.reject = function(predicate) {
  16012. return this.filter(negate(getIteratee(predicate)));
  16013. };
  16014. LazyWrapper.prototype.slice = function(start, end) {
  16015. start = toInteger(start);
  16016. var result = this;
  16017. if (result.__filtered__ && (start > 0 || end < 0)) {
  16018. return new LazyWrapper(result);
  16019. }
  16020. if (start < 0) {
  16021. result = result.takeRight(-start);
  16022. } else if (start) {
  16023. result = result.drop(start);
  16024. }
  16025. if (end !== undefined) {
  16026. end = toInteger(end);
  16027. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16028. }
  16029. return result;
  16030. };
  16031. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16032. return this.reverse().takeWhile(predicate).reverse();
  16033. };
  16034. LazyWrapper.prototype.toArray = function() {
  16035. return this.take(MAX_ARRAY_LENGTH);
  16036. };
  16037. // Add `LazyWrapper` methods to `lodash.prototype`.
  16038. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16039. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16040. isTaker = /^(?:head|last)$/.test(methodName),
  16041. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16042. retUnwrapped = isTaker || /^find/.test(methodName);
  16043. if (!lodashFunc) {
  16044. return;
  16045. }
  16046. lodash.prototype[methodName] = function() {
  16047. var value = this.__wrapped__,
  16048. args = isTaker ? [1] : arguments,
  16049. isLazy = value instanceof LazyWrapper,
  16050. iteratee = args[0],
  16051. useLazy = isLazy || isArray(value);
  16052. var interceptor = function(value) {
  16053. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16054. return (isTaker && chainAll) ? result[0] : result;
  16055. };
  16056. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16057. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16058. isLazy = useLazy = false;
  16059. }
  16060. var chainAll = this.__chain__,
  16061. isHybrid = !!this.__actions__.length,
  16062. isUnwrapped = retUnwrapped && !chainAll,
  16063. onlyLazy = isLazy && !isHybrid;
  16064. if (!retUnwrapped && useLazy) {
  16065. value = onlyLazy ? value : new LazyWrapper(this);
  16066. var result = func.apply(value, args);
  16067. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16068. return new LodashWrapper(result, chainAll);
  16069. }
  16070. if (isUnwrapped && onlyLazy) {
  16071. return func.apply(this, args);
  16072. }
  16073. result = this.thru(interceptor);
  16074. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16075. };
  16076. });
  16077. // Add `Array` methods to `lodash.prototype`.
  16078. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16079. var func = arrayProto[methodName],
  16080. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16081. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16082. lodash.prototype[methodName] = function() {
  16083. var args = arguments;
  16084. if (retUnwrapped && !this.__chain__) {
  16085. var value = this.value();
  16086. return func.apply(isArray(value) ? value : [], args);
  16087. }
  16088. return this[chainName](function(value) {
  16089. return func.apply(isArray(value) ? value : [], args);
  16090. });
  16091. };
  16092. });
  16093. // Map minified method names to their real names.
  16094. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16095. var lodashFunc = lodash[methodName];
  16096. if (lodashFunc) {
  16097. var key = lodashFunc.name + '';
  16098. if (!hasOwnProperty.call(realNames, key)) {
  16099. realNames[key] = [];
  16100. }
  16101. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16102. }
  16103. });
  16104. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16105. 'name': 'wrapper',
  16106. 'func': undefined
  16107. }];
  16108. // Add methods to `LazyWrapper`.
  16109. LazyWrapper.prototype.clone = lazyClone;
  16110. LazyWrapper.prototype.reverse = lazyReverse;
  16111. LazyWrapper.prototype.value = lazyValue;
  16112. // Add chain sequence methods to the `lodash` wrapper.
  16113. lodash.prototype.at = wrapperAt;
  16114. lodash.prototype.chain = wrapperChain;
  16115. lodash.prototype.commit = wrapperCommit;
  16116. lodash.prototype.next = wrapperNext;
  16117. lodash.prototype.plant = wrapperPlant;
  16118. lodash.prototype.reverse = wrapperReverse;
  16119. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16120. // Add lazy aliases.
  16121. lodash.prototype.first = lodash.prototype.head;
  16122. if (symIterator) {
  16123. lodash.prototype[symIterator] = wrapperToIterator;
  16124. }
  16125. return lodash;
  16126. });
  16127. /*--------------------------------------------------------------------------*/
  16128. // Export lodash.
  16129. var _ = runInContext();
  16130. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16131. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16132. // Expose Lodash on the global object to prevent errors when Lodash is
  16133. // loaded by a script tag in the presence of an AMD loader.
  16134. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16135. // Use `_.noConflict` to remove Lodash from the global object.
  16136. root._ = _;
  16137. // Define as an anonymous module so, through path mapping, it can be
  16138. // referenced as the "underscore" module.
  16139. define(function() {
  16140. return _;
  16141. });
  16142. }
  16143. // Check for `exports` after `define` in case a build optimizer adds it.
  16144. else if (freeModule) {
  16145. // Export for Node.js.
  16146. (freeModule.exports = _)._ = _;
  16147. // Export for CommonJS support.
  16148. freeExports._ = _;
  16149. }
  16150. else {
  16151. // Export to the global object.
  16152. root._ = _;
  16153. }
  16154. }.call(this));