Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lodash.js 528KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112
  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.15';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function';
  19. /** Used to stand-in for `undefined` hash values. */
  20. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21. /** Used as the maximum memoize cache size. */
  22. var MAX_MEMOIZE_SIZE = 500;
  23. /** Used as the internal argument placeholder. */
  24. var PLACEHOLDER = '__lodash_placeholder__';
  25. /** Used to compose bitmasks for cloning. */
  26. var CLONE_DEEP_FLAG = 1,
  27. CLONE_FLAT_FLAG = 2,
  28. CLONE_SYMBOLS_FLAG = 4;
  29. /** Used to compose bitmasks for value comparisons. */
  30. var COMPARE_PARTIAL_FLAG = 1,
  31. COMPARE_UNORDERED_FLAG = 2;
  32. /** Used to compose bitmasks for function metadata. */
  33. var WRAP_BIND_FLAG = 1,
  34. WRAP_BIND_KEY_FLAG = 2,
  35. WRAP_CURRY_BOUND_FLAG = 4,
  36. WRAP_CURRY_FLAG = 8,
  37. WRAP_CURRY_RIGHT_FLAG = 16,
  38. WRAP_PARTIAL_FLAG = 32,
  39. WRAP_PARTIAL_RIGHT_FLAG = 64,
  40. WRAP_ARY_FLAG = 128,
  41. WRAP_REARG_FLAG = 256,
  42. WRAP_FLIP_FLAG = 512;
  43. /** Used as default options for `_.truncate`. */
  44. var DEFAULT_TRUNC_LENGTH = 30,
  45. DEFAULT_TRUNC_OMISSION = '...';
  46. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  47. var HOT_COUNT = 800,
  48. HOT_SPAN = 16;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2,
  52. LAZY_WHILE_FLAG = 3;
  53. /** Used as references for various `Number` constants. */
  54. var INFINITY = 1 / 0,
  55. MAX_SAFE_INTEGER = 9007199254740991,
  56. MAX_INTEGER = 1.7976931348623157e+308,
  57. NAN = 0 / 0;
  58. /** Used as references for the maximum length and index of an array. */
  59. var MAX_ARRAY_LENGTH = 4294967295,
  60. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  61. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  62. /** Used to associate wrap methods with their bit flags. */
  63. var wrapFlags = [
  64. ['ary', WRAP_ARY_FLAG],
  65. ['bind', WRAP_BIND_FLAG],
  66. ['bindKey', WRAP_BIND_KEY_FLAG],
  67. ['curry', WRAP_CURRY_FLAG],
  68. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  69. ['flip', WRAP_FLIP_FLAG],
  70. ['partial', WRAP_PARTIAL_FLAG],
  71. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  72. ['rearg', WRAP_REARG_FLAG]
  73. ];
  74. /** `Object#toString` result references. */
  75. var argsTag = '[object Arguments]',
  76. arrayTag = '[object Array]',
  77. asyncTag = '[object AsyncFunction]',
  78. boolTag = '[object Boolean]',
  79. dateTag = '[object Date]',
  80. domExcTag = '[object DOMException]',
  81. errorTag = '[object Error]',
  82. funcTag = '[object Function]',
  83. genTag = '[object GeneratorFunction]',
  84. mapTag = '[object Map]',
  85. numberTag = '[object Number]',
  86. nullTag = '[object Null]',
  87. objectTag = '[object Object]',
  88. promiseTag = '[object Promise]',
  89. proxyTag = '[object Proxy]',
  90. regexpTag = '[object RegExp]',
  91. setTag = '[object Set]',
  92. stringTag = '[object String]',
  93. symbolTag = '[object Symbol]',
  94. undefinedTag = '[object Undefined]',
  95. weakMapTag = '[object WeakMap]',
  96. weakSetTag = '[object WeakSet]';
  97. var arrayBufferTag = '[object ArrayBuffer]',
  98. dataViewTag = '[object DataView]',
  99. float32Tag = '[object Float32Array]',
  100. float64Tag = '[object Float64Array]',
  101. int8Tag = '[object Int8Array]',
  102. int16Tag = '[object Int16Array]',
  103. int32Tag = '[object Int32Array]',
  104. uint8Tag = '[object Uint8Array]',
  105. uint8ClampedTag = '[object Uint8ClampedArray]',
  106. uint16Tag = '[object Uint16Array]',
  107. uint32Tag = '[object Uint32Array]';
  108. /** Used to match empty string literals in compiled template source. */
  109. var reEmptyStringLeading = /\b__p \+= '';/g,
  110. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  111. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  112. /** Used to match HTML entities and HTML characters. */
  113. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  114. reUnescapedHtml = /[&<>"']/g,
  115. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  116. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  117. /** Used to match template delimiters. */
  118. var reEscape = /<%-([\s\S]+?)%>/g,
  119. reEvaluate = /<%([\s\S]+?)%>/g,
  120. reInterpolate = /<%=([\s\S]+?)%>/g;
  121. /** Used to match property names within property paths. */
  122. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  123. reIsPlainProp = /^\w*$/,
  124. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  125. /**
  126. * Used to match `RegExp`
  127. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  128. */
  129. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  130. reHasRegExpChar = RegExp(reRegExpChar.source);
  131. /** Used to match leading and trailing whitespace. */
  132. var reTrim = /^\s+|\s+$/g,
  133. reTrimStart = /^\s+/,
  134. reTrimEnd = /\s+$/;
  135. /** Used to match wrap detail comments. */
  136. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  137. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  138. reSplitDetails = /,? & /;
  139. /** Used to match words composed of alphanumeric characters. */
  140. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  141. /** Used to match backslashes in property paths. */
  142. var reEscapeChar = /\\(\\)?/g;
  143. /**
  144. * Used to match
  145. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  146. */
  147. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  148. /** Used to match `RegExp` flags from their coerced string values. */
  149. var reFlags = /\w*$/;
  150. /** Used to detect bad signed hexadecimal string values. */
  151. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  152. /** Used to detect binary string values. */
  153. var reIsBinary = /^0b[01]+$/i;
  154. /** Used to detect host constructors (Safari). */
  155. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  156. /** Used to detect octal string values. */
  157. var reIsOctal = /^0o[0-7]+$/i;
  158. /** Used to detect unsigned integer values. */
  159. var reIsUint = /^(?:0|[1-9]\d*)$/;
  160. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  161. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  162. /** Used to ensure capturing order of template delimiters. */
  163. var reNoMatch = /($^)/;
  164. /** Used to match unescaped characters in compiled string literals. */
  165. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  166. /** Used to compose unicode character classes. */
  167. var rsAstralRange = '\\ud800-\\udfff',
  168. rsComboMarksRange = '\\u0300-\\u036f',
  169. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  170. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  171. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  172. rsDingbatRange = '\\u2700-\\u27bf',
  173. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  174. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  175. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  176. rsPunctuationRange = '\\u2000-\\u206f',
  177. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  178. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  179. rsVarRange = '\\ufe0e\\ufe0f',
  180. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  181. /** Used to compose unicode capture groups. */
  182. var rsApos = "['\u2019]",
  183. rsAstral = '[' + rsAstralRange + ']',
  184. rsBreak = '[' + rsBreakRange + ']',
  185. rsCombo = '[' + rsComboRange + ']',
  186. rsDigits = '\\d+',
  187. rsDingbat = '[' + rsDingbatRange + ']',
  188. rsLower = '[' + rsLowerRange + ']',
  189. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  190. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  191. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  192. rsNonAstral = '[^' + rsAstralRange + ']',
  193. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  194. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  195. rsUpper = '[' + rsUpperRange + ']',
  196. rsZWJ = '\\u200d';
  197. /** Used to compose unicode regexes. */
  198. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  199. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  200. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  201. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  202. reOptMod = rsModifier + '?',
  203. rsOptVar = '[' + rsVarRange + ']?',
  204. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  205. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  206. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  207. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  208. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  209. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  210. /** Used to match apostrophes. */
  211. var reApos = RegExp(rsApos, 'g');
  212. /**
  213. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  214. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  215. */
  216. var reComboMark = RegExp(rsCombo, 'g');
  217. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  218. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  219. /** Used to match complex or compound words. */
  220. var reUnicodeWord = RegExp([
  221. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  222. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  223. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  224. rsUpper + '+' + rsOptContrUpper,
  225. rsOrdUpper,
  226. rsOrdLower,
  227. rsDigits,
  228. rsEmoji
  229. ].join('|'), 'g');
  230. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  231. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  232. /** Used to detect strings that need a more robust regexp to match words. */
  233. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  234. /** Used to assign default `context` object properties. */
  235. var contextProps = [
  236. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  237. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  238. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  239. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  240. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  241. ];
  242. /** Used to make template sourceURLs easier to identify. */
  243. var templateCounter = -1;
  244. /** Used to identify `toStringTag` values of typed arrays. */
  245. var typedArrayTags = {};
  246. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  247. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  248. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  249. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  250. typedArrayTags[uint32Tag] = true;
  251. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  252. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  253. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  254. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  255. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  256. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  257. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  258. typedArrayTags[weakMapTag] = false;
  259. /** Used to identify `toStringTag` values supported by `_.clone`. */
  260. var cloneableTags = {};
  261. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  262. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  263. cloneableTags[boolTag] = cloneableTags[dateTag] =
  264. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  265. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  266. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  267. cloneableTags[numberTag] = cloneableTags[objectTag] =
  268. cloneableTags[regexpTag] = cloneableTags[setTag] =
  269. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  270. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  271. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  272. cloneableTags[errorTag] = cloneableTags[funcTag] =
  273. cloneableTags[weakMapTag] = false;
  274. /** Used to map Latin Unicode letters to basic Latin letters. */
  275. var deburredLetters = {
  276. // Latin-1 Supplement block.
  277. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  278. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  279. '\xc7': 'C', '\xe7': 'c',
  280. '\xd0': 'D', '\xf0': 'd',
  281. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  282. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  283. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  284. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  285. '\xd1': 'N', '\xf1': 'n',
  286. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  287. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  288. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  289. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  290. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  291. '\xc6': 'Ae', '\xe6': 'ae',
  292. '\xde': 'Th', '\xfe': 'th',
  293. '\xdf': 'ss',
  294. // Latin Extended-A block.
  295. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  296. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  297. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  298. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  299. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  300. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  301. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  302. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  303. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  304. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  305. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  306. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  307. '\u0134': 'J', '\u0135': 'j',
  308. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  309. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  310. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  311. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  312. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  313. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  314. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  315. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  316. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  317. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  318. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  319. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  320. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  321. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  322. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  323. '\u0174': 'W', '\u0175': 'w',
  324. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  325. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  326. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  327. '\u0132': 'IJ', '\u0133': 'ij',
  328. '\u0152': 'Oe', '\u0153': 'oe',
  329. '\u0149': "'n", '\u017f': 's'
  330. };
  331. /** Used to map characters to HTML entities. */
  332. var htmlEscapes = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '"': '&quot;',
  337. "'": '&#39;'
  338. };
  339. /** Used to map HTML entities to characters. */
  340. var htmlUnescapes = {
  341. '&amp;': '&',
  342. '&lt;': '<',
  343. '&gt;': '>',
  344. '&quot;': '"',
  345. '&#39;': "'"
  346. };
  347. /** Used to escape characters for inclusion in compiled string literals. */
  348. var stringEscapes = {
  349. '\\': '\\',
  350. "'": "'",
  351. '\n': 'n',
  352. '\r': 'r',
  353. '\u2028': 'u2028',
  354. '\u2029': 'u2029'
  355. };
  356. /** Built-in method references without a dependency on `root`. */
  357. var freeParseFloat = parseFloat,
  358. freeParseInt = parseInt;
  359. /** Detect free variable `global` from Node.js. */
  360. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  361. /** Detect free variable `self`. */
  362. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  363. /** Used as a reference to the global object. */
  364. var root = freeGlobal || freeSelf || Function('return this')();
  365. /** Detect free variable `exports`. */
  366. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  367. /** Detect free variable `module`. */
  368. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  369. /** Detect the popular CommonJS extension `module.exports`. */
  370. var moduleExports = freeModule && freeModule.exports === freeExports;
  371. /** Detect free variable `process` from Node.js. */
  372. var freeProcess = moduleExports && freeGlobal.process;
  373. /** Used to access faster Node.js helpers. */
  374. var nodeUtil = (function() {
  375. try {
  376. // Use `util.types` for Node.js 10+.
  377. var types = freeModule && freeModule.require && freeModule.require('util').types;
  378. if (types) {
  379. return types;
  380. }
  381. // Legacy `process.binding('util')` for Node.js < 10.
  382. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  383. } catch (e) {}
  384. }());
  385. /* Node.js helper references. */
  386. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  387. nodeIsDate = nodeUtil && nodeUtil.isDate,
  388. nodeIsMap = nodeUtil && nodeUtil.isMap,
  389. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  390. nodeIsSet = nodeUtil && nodeUtil.isSet,
  391. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  392. /*--------------------------------------------------------------------------*/
  393. /**
  394. * A faster alternative to `Function#apply`, this function invokes `func`
  395. * with the `this` binding of `thisArg` and the arguments of `args`.
  396. *
  397. * @private
  398. * @param {Function} func The function to invoke.
  399. * @param {*} thisArg The `this` binding of `func`.
  400. * @param {Array} args The arguments to invoke `func` with.
  401. * @returns {*} Returns the result of `func`.
  402. */
  403. function apply(func, thisArg, args) {
  404. switch (args.length) {
  405. case 0: return func.call(thisArg);
  406. case 1: return func.call(thisArg, args[0]);
  407. case 2: return func.call(thisArg, args[0], args[1]);
  408. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  409. }
  410. return func.apply(thisArg, args);
  411. }
  412. /**
  413. * A specialized version of `baseAggregator` for arrays.
  414. *
  415. * @private
  416. * @param {Array} [array] The array to iterate over.
  417. * @param {Function} setter The function to set `accumulator` values.
  418. * @param {Function} iteratee The iteratee to transform keys.
  419. * @param {Object} accumulator The initial aggregated object.
  420. * @returns {Function} Returns `accumulator`.
  421. */
  422. function arrayAggregator(array, setter, iteratee, accumulator) {
  423. var index = -1,
  424. length = array == null ? 0 : array.length;
  425. while (++index < length) {
  426. var value = array[index];
  427. setter(accumulator, value, iteratee(value), array);
  428. }
  429. return accumulator;
  430. }
  431. /**
  432. * A specialized version of `_.forEach` for arrays without support for
  433. * iteratee shorthands.
  434. *
  435. * @private
  436. * @param {Array} [array] The array to iterate over.
  437. * @param {Function} iteratee The function invoked per iteration.
  438. * @returns {Array} Returns `array`.
  439. */
  440. function arrayEach(array, iteratee) {
  441. var index = -1,
  442. length = array == null ? 0 : array.length;
  443. while (++index < length) {
  444. if (iteratee(array[index], index, array) === false) {
  445. break;
  446. }
  447. }
  448. return array;
  449. }
  450. /**
  451. * A specialized version of `_.forEachRight` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEachRight(array, iteratee) {
  460. var length = array == null ? 0 : array.length;
  461. while (length--) {
  462. if (iteratee(array[length], length, array) === false) {
  463. break;
  464. }
  465. }
  466. return array;
  467. }
  468. /**
  469. * A specialized version of `_.every` for arrays without support for
  470. * iteratee shorthands.
  471. *
  472. * @private
  473. * @param {Array} [array] The array to iterate over.
  474. * @param {Function} predicate The function invoked per iteration.
  475. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  476. * else `false`.
  477. */
  478. function arrayEvery(array, predicate) {
  479. var index = -1,
  480. length = array == null ? 0 : array.length;
  481. while (++index < length) {
  482. if (!predicate(array[index], index, array)) {
  483. return false;
  484. }
  485. }
  486. return true;
  487. }
  488. /**
  489. * A specialized version of `_.filter` for arrays without support for
  490. * iteratee shorthands.
  491. *
  492. * @private
  493. * @param {Array} [array] The array to iterate over.
  494. * @param {Function} predicate The function invoked per iteration.
  495. * @returns {Array} Returns the new filtered array.
  496. */
  497. function arrayFilter(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length,
  500. resIndex = 0,
  501. result = [];
  502. while (++index < length) {
  503. var value = array[index];
  504. if (predicate(value, index, array)) {
  505. result[resIndex++] = value;
  506. }
  507. }
  508. return result;
  509. }
  510. /**
  511. * A specialized version of `_.includes` for arrays without support for
  512. * specifying an index to search from.
  513. *
  514. * @private
  515. * @param {Array} [array] The array to inspect.
  516. * @param {*} target The value to search for.
  517. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  518. */
  519. function arrayIncludes(array, value) {
  520. var length = array == null ? 0 : array.length;
  521. return !!length && baseIndexOf(array, value, 0) > -1;
  522. }
  523. /**
  524. * This function is like `arrayIncludes` except that it accepts a comparator.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @param {Function} comparator The comparator invoked per element.
  530. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  531. */
  532. function arrayIncludesWith(array, value, comparator) {
  533. var index = -1,
  534. length = array == null ? 0 : array.length;
  535. while (++index < length) {
  536. if (comparator(value, array[index])) {
  537. return true;
  538. }
  539. }
  540. return false;
  541. }
  542. /**
  543. * A specialized version of `_.map` for arrays without support for iteratee
  544. * shorthands.
  545. *
  546. * @private
  547. * @param {Array} [array] The array to iterate over.
  548. * @param {Function} iteratee The function invoked per iteration.
  549. * @returns {Array} Returns the new mapped array.
  550. */
  551. function arrayMap(array, iteratee) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length,
  554. result = Array(length);
  555. while (++index < length) {
  556. result[index] = iteratee(array[index], index, array);
  557. }
  558. return result;
  559. }
  560. /**
  561. * Appends the elements of `values` to `array`.
  562. *
  563. * @private
  564. * @param {Array} array The array to modify.
  565. * @param {Array} values The values to append.
  566. * @returns {Array} Returns `array`.
  567. */
  568. function arrayPush(array, values) {
  569. var index = -1,
  570. length = values.length,
  571. offset = array.length;
  572. while (++index < length) {
  573. array[offset + index] = values[index];
  574. }
  575. return array;
  576. }
  577. /**
  578. * A specialized version of `_.reduce` for arrays without support for
  579. * iteratee shorthands.
  580. *
  581. * @private
  582. * @param {Array} [array] The array to iterate over.
  583. * @param {Function} iteratee The function invoked per iteration.
  584. * @param {*} [accumulator] The initial value.
  585. * @param {boolean} [initAccum] Specify using the first element of `array` as
  586. * the initial value.
  587. * @returns {*} Returns the accumulated value.
  588. */
  589. function arrayReduce(array, iteratee, accumulator, initAccum) {
  590. var index = -1,
  591. length = array == null ? 0 : array.length;
  592. if (initAccum && length) {
  593. accumulator = array[++index];
  594. }
  595. while (++index < length) {
  596. accumulator = iteratee(accumulator, array[index], index, array);
  597. }
  598. return accumulator;
  599. }
  600. /**
  601. * A specialized version of `_.reduceRight` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} iteratee The function invoked per iteration.
  607. * @param {*} [accumulator] The initial value.
  608. * @param {boolean} [initAccum] Specify using the last element of `array` as
  609. * the initial value.
  610. * @returns {*} Returns the accumulated value.
  611. */
  612. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  613. var length = array == null ? 0 : array.length;
  614. if (initAccum && length) {
  615. accumulator = array[--length];
  616. }
  617. while (length--) {
  618. accumulator = iteratee(accumulator, array[length], length, array);
  619. }
  620. return accumulator;
  621. }
  622. /**
  623. * A specialized version of `_.some` for arrays without support for iteratee
  624. * shorthands.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to iterate over.
  628. * @param {Function} predicate The function invoked per iteration.
  629. * @returns {boolean} Returns `true` if any element passes the predicate check,
  630. * else `false`.
  631. */
  632. function arraySome(array, predicate) {
  633. var index = -1,
  634. length = array == null ? 0 : array.length;
  635. while (++index < length) {
  636. if (predicate(array[index], index, array)) {
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642. /**
  643. * Gets the size of an ASCII `string`.
  644. *
  645. * @private
  646. * @param {string} string The string inspect.
  647. * @returns {number} Returns the string size.
  648. */
  649. var asciiSize = baseProperty('length');
  650. /**
  651. * Converts an ASCII `string` to an array.
  652. *
  653. * @private
  654. * @param {string} string The string to convert.
  655. * @returns {Array} Returns the converted array.
  656. */
  657. function asciiToArray(string) {
  658. return string.split('');
  659. }
  660. /**
  661. * Splits an ASCII `string` into an array of its words.
  662. *
  663. * @private
  664. * @param {string} The string to inspect.
  665. * @returns {Array} Returns the words of `string`.
  666. */
  667. function asciiWords(string) {
  668. return string.match(reAsciiWord) || [];
  669. }
  670. /**
  671. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  672. * without support for iteratee shorthands, which iterates over `collection`
  673. * using `eachFunc`.
  674. *
  675. * @private
  676. * @param {Array|Object} collection The collection to inspect.
  677. * @param {Function} predicate The function invoked per iteration.
  678. * @param {Function} eachFunc The function to iterate over `collection`.
  679. * @returns {*} Returns the found element or its key, else `undefined`.
  680. */
  681. function baseFindKey(collection, predicate, eachFunc) {
  682. var result;
  683. eachFunc(collection, function(value, key, collection) {
  684. if (predicate(value, key, collection)) {
  685. result = key;
  686. return false;
  687. }
  688. });
  689. return result;
  690. }
  691. /**
  692. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  693. * support for iteratee shorthands.
  694. *
  695. * @private
  696. * @param {Array} array The array to inspect.
  697. * @param {Function} predicate The function invoked per iteration.
  698. * @param {number} fromIndex The index to search from.
  699. * @param {boolean} [fromRight] Specify iterating from right to left.
  700. * @returns {number} Returns the index of the matched value, else `-1`.
  701. */
  702. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  703. var length = array.length,
  704. index = fromIndex + (fromRight ? 1 : -1);
  705. while ((fromRight ? index-- : ++index < length)) {
  706. if (predicate(array[index], index, array)) {
  707. return index;
  708. }
  709. }
  710. return -1;
  711. }
  712. /**
  713. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  714. *
  715. * @private
  716. * @param {Array} array The array to inspect.
  717. * @param {*} value The value to search for.
  718. * @param {number} fromIndex The index to search from.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseIndexOf(array, value, fromIndex) {
  722. return value === value
  723. ? strictIndexOf(array, value, fromIndex)
  724. : baseFindIndex(array, baseIsNaN, fromIndex);
  725. }
  726. /**
  727. * This function is like `baseIndexOf` except that it accepts a comparator.
  728. *
  729. * @private
  730. * @param {Array} array The array to inspect.
  731. * @param {*} value The value to search for.
  732. * @param {number} fromIndex The index to search from.
  733. * @param {Function} comparator The comparator invoked per element.
  734. * @returns {number} Returns the index of the matched value, else `-1`.
  735. */
  736. function baseIndexOfWith(array, value, fromIndex, comparator) {
  737. var index = fromIndex - 1,
  738. length = array.length;
  739. while (++index < length) {
  740. if (comparator(array[index], value)) {
  741. return index;
  742. }
  743. }
  744. return -1;
  745. }
  746. /**
  747. * The base implementation of `_.isNaN` without support for number objects.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  752. */
  753. function baseIsNaN(value) {
  754. return value !== value;
  755. }
  756. /**
  757. * The base implementation of `_.mean` and `_.meanBy` without support for
  758. * iteratee shorthands.
  759. *
  760. * @private
  761. * @param {Array} array The array to iterate over.
  762. * @param {Function} iteratee The function invoked per iteration.
  763. * @returns {number} Returns the mean.
  764. */
  765. function baseMean(array, iteratee) {
  766. var length = array == null ? 0 : array.length;
  767. return length ? (baseSum(array, iteratee) / length) : NAN;
  768. }
  769. /**
  770. * The base implementation of `_.property` without support for deep paths.
  771. *
  772. * @private
  773. * @param {string} key The key of the property to get.
  774. * @returns {Function} Returns the new accessor function.
  775. */
  776. function baseProperty(key) {
  777. return function(object) {
  778. return object == null ? undefined : object[key];
  779. };
  780. }
  781. /**
  782. * The base implementation of `_.propertyOf` without support for deep paths.
  783. *
  784. * @private
  785. * @param {Object} object The object to query.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function basePropertyOf(object) {
  789. return function(key) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  795. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  796. *
  797. * @private
  798. * @param {Array|Object} collection The collection to iterate over.
  799. * @param {Function} iteratee The function invoked per iteration.
  800. * @param {*} accumulator The initial value.
  801. * @param {boolean} initAccum Specify using the first or last element of
  802. * `collection` as the initial value.
  803. * @param {Function} eachFunc The function to iterate over `collection`.
  804. * @returns {*} Returns the accumulated value.
  805. */
  806. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  807. eachFunc(collection, function(value, index, collection) {
  808. accumulator = initAccum
  809. ? (initAccum = false, value)
  810. : iteratee(accumulator, value, index, collection);
  811. });
  812. return accumulator;
  813. }
  814. /**
  815. * The base implementation of `_.sortBy` which uses `comparer` to define the
  816. * sort order of `array` and replaces criteria objects with their corresponding
  817. * values.
  818. *
  819. * @private
  820. * @param {Array} array The array to sort.
  821. * @param {Function} comparer The function to define sort order.
  822. * @returns {Array} Returns `array`.
  823. */
  824. function baseSortBy(array, comparer) {
  825. var length = array.length;
  826. array.sort(comparer);
  827. while (length--) {
  828. array[length] = array[length].value;
  829. }
  830. return array;
  831. }
  832. /**
  833. * The base implementation of `_.sum` and `_.sumBy` without support for
  834. * iteratee shorthands.
  835. *
  836. * @private
  837. * @param {Array} array The array to iterate over.
  838. * @param {Function} iteratee The function invoked per iteration.
  839. * @returns {number} Returns the sum.
  840. */
  841. function baseSum(array, iteratee) {
  842. var result,
  843. index = -1,
  844. length = array.length;
  845. while (++index < length) {
  846. var current = iteratee(array[index]);
  847. if (current !== undefined) {
  848. result = result === undefined ? current : (result + current);
  849. }
  850. }
  851. return result;
  852. }
  853. /**
  854. * The base implementation of `_.times` without support for iteratee shorthands
  855. * or max array length checks.
  856. *
  857. * @private
  858. * @param {number} n The number of times to invoke `iteratee`.
  859. * @param {Function} iteratee The function invoked per iteration.
  860. * @returns {Array} Returns the array of results.
  861. */
  862. function baseTimes(n, iteratee) {
  863. var index = -1,
  864. result = Array(n);
  865. while (++index < n) {
  866. result[index] = iteratee(index);
  867. }
  868. return result;
  869. }
  870. /**
  871. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  872. * of key-value pairs for `object` corresponding to the property names of `props`.
  873. *
  874. * @private
  875. * @param {Object} object The object to query.
  876. * @param {Array} props The property names to get values for.
  877. * @returns {Object} Returns the key-value pairs.
  878. */
  879. function baseToPairs(object, props) {
  880. return arrayMap(props, function(key) {
  881. return [key, object[key]];
  882. });
  883. }
  884. /**
  885. * The base implementation of `_.unary` without support for storing metadata.
  886. *
  887. * @private
  888. * @param {Function} func The function to cap arguments for.
  889. * @returns {Function} Returns the new capped function.
  890. */
  891. function baseUnary(func) {
  892. return function(value) {
  893. return func(value);
  894. };
  895. }
  896. /**
  897. * The base implementation of `_.values` and `_.valuesIn` which creates an
  898. * array of `object` property values corresponding to the property names
  899. * of `props`.
  900. *
  901. * @private
  902. * @param {Object} object The object to query.
  903. * @param {Array} props The property names to get values for.
  904. * @returns {Object} Returns the array of property values.
  905. */
  906. function baseValues(object, props) {
  907. return arrayMap(props, function(key) {
  908. return object[key];
  909. });
  910. }
  911. /**
  912. * Checks if a `cache` value for `key` exists.
  913. *
  914. * @private
  915. * @param {Object} cache The cache to query.
  916. * @param {string} key The key of the entry to check.
  917. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  918. */
  919. function cacheHas(cache, key) {
  920. return cache.has(key);
  921. }
  922. /**
  923. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  924. * that is not found in the character symbols.
  925. *
  926. * @private
  927. * @param {Array} strSymbols The string symbols to inspect.
  928. * @param {Array} chrSymbols The character symbols to find.
  929. * @returns {number} Returns the index of the first unmatched string symbol.
  930. */
  931. function charsStartIndex(strSymbols, chrSymbols) {
  932. var index = -1,
  933. length = strSymbols.length;
  934. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  935. return index;
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the last unmatched string symbol.
  945. */
  946. function charsEndIndex(strSymbols, chrSymbols) {
  947. var index = strSymbols.length;
  948. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  949. return index;
  950. }
  951. /**
  952. * Gets the number of `placeholder` occurrences in `array`.
  953. *
  954. * @private
  955. * @param {Array} array The array to inspect.
  956. * @param {*} placeholder The placeholder to search for.
  957. * @returns {number} Returns the placeholder count.
  958. */
  959. function countHolders(array, placeholder) {
  960. var length = array.length,
  961. result = 0;
  962. while (length--) {
  963. if (array[length] === placeholder) {
  964. ++result;
  965. }
  966. }
  967. return result;
  968. }
  969. /**
  970. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  971. * letters to basic Latin letters.
  972. *
  973. * @private
  974. * @param {string} letter The matched letter to deburr.
  975. * @returns {string} Returns the deburred letter.
  976. */
  977. var deburrLetter = basePropertyOf(deburredLetters);
  978. /**
  979. * Used by `_.escape` to convert characters to HTML entities.
  980. *
  981. * @private
  982. * @param {string} chr The matched character to escape.
  983. * @returns {string} Returns the escaped character.
  984. */
  985. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  986. /**
  987. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  988. *
  989. * @private
  990. * @param {string} chr The matched character to escape.
  991. * @returns {string} Returns the escaped character.
  992. */
  993. function escapeStringChar(chr) {
  994. return '\\' + stringEscapes[chr];
  995. }
  996. /**
  997. * Gets the value at `key` of `object`.
  998. *
  999. * @private
  1000. * @param {Object} [object] The object to query.
  1001. * @param {string} key The key of the property to get.
  1002. * @returns {*} Returns the property value.
  1003. */
  1004. function getValue(object, key) {
  1005. return object == null ? undefined : object[key];
  1006. }
  1007. /**
  1008. * Checks if `string` contains Unicode symbols.
  1009. *
  1010. * @private
  1011. * @param {string} string The string to inspect.
  1012. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1013. */
  1014. function hasUnicode(string) {
  1015. return reHasUnicode.test(string);
  1016. }
  1017. /**
  1018. * Checks if `string` contains a word composed of Unicode symbols.
  1019. *
  1020. * @private
  1021. * @param {string} string The string to inspect.
  1022. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1023. */
  1024. function hasUnicodeWord(string) {
  1025. return reHasUnicodeWord.test(string);
  1026. }
  1027. /**
  1028. * Converts `iterator` to an array.
  1029. *
  1030. * @private
  1031. * @param {Object} iterator The iterator to convert.
  1032. * @returns {Array} Returns the converted array.
  1033. */
  1034. function iteratorToArray(iterator) {
  1035. var data,
  1036. result = [];
  1037. while (!(data = iterator.next()).done) {
  1038. result.push(data.value);
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. * Converts `map` to its key-value pairs.
  1044. *
  1045. * @private
  1046. * @param {Object} map The map to convert.
  1047. * @returns {Array} Returns the key-value pairs.
  1048. */
  1049. function mapToArray(map) {
  1050. var index = -1,
  1051. result = Array(map.size);
  1052. map.forEach(function(value, key) {
  1053. result[++index] = [key, value];
  1054. });
  1055. return result;
  1056. }
  1057. /**
  1058. * Creates a unary function that invokes `func` with its argument transformed.
  1059. *
  1060. * @private
  1061. * @param {Function} func The function to wrap.
  1062. * @param {Function} transform The argument transform.
  1063. * @returns {Function} Returns the new function.
  1064. */
  1065. function overArg(func, transform) {
  1066. return function(arg) {
  1067. return func(transform(arg));
  1068. };
  1069. }
  1070. /**
  1071. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1072. * and returns an array of their indexes.
  1073. *
  1074. * @private
  1075. * @param {Array} array The array to modify.
  1076. * @param {*} placeholder The placeholder to replace.
  1077. * @returns {Array} Returns the new array of placeholder indexes.
  1078. */
  1079. function replaceHolders(array, placeholder) {
  1080. var index = -1,
  1081. length = array.length,
  1082. resIndex = 0,
  1083. result = [];
  1084. while (++index < length) {
  1085. var value = array[index];
  1086. if (value === placeholder || value === PLACEHOLDER) {
  1087. array[index] = PLACEHOLDER;
  1088. result[resIndex++] = index;
  1089. }
  1090. }
  1091. return result;
  1092. }
  1093. /**
  1094. * Converts `set` to an array of its values.
  1095. *
  1096. * @private
  1097. * @param {Object} set The set to convert.
  1098. * @returns {Array} Returns the values.
  1099. */
  1100. function setToArray(set) {
  1101. var index = -1,
  1102. result = Array(set.size);
  1103. set.forEach(function(value) {
  1104. result[++index] = value;
  1105. });
  1106. return result;
  1107. }
  1108. /**
  1109. * Converts `set` to its value-value pairs.
  1110. *
  1111. * @private
  1112. * @param {Object} set The set to convert.
  1113. * @returns {Array} Returns the value-value pairs.
  1114. */
  1115. function setToPairs(set) {
  1116. var index = -1,
  1117. result = Array(set.size);
  1118. set.forEach(function(value) {
  1119. result[++index] = [value, value];
  1120. });
  1121. return result;
  1122. }
  1123. /**
  1124. * A specialized version of `_.indexOf` which performs strict equality
  1125. * comparisons of values, i.e. `===`.
  1126. *
  1127. * @private
  1128. * @param {Array} array The array to inspect.
  1129. * @param {*} value The value to search for.
  1130. * @param {number} fromIndex The index to search from.
  1131. * @returns {number} Returns the index of the matched value, else `-1`.
  1132. */
  1133. function strictIndexOf(array, value, fromIndex) {
  1134. var index = fromIndex - 1,
  1135. length = array.length;
  1136. while (++index < length) {
  1137. if (array[index] === value) {
  1138. return index;
  1139. }
  1140. }
  1141. return -1;
  1142. }
  1143. /**
  1144. * A specialized version of `_.lastIndexOf` which performs strict equality
  1145. * comparisons of values, i.e. `===`.
  1146. *
  1147. * @private
  1148. * @param {Array} array The array to inspect.
  1149. * @param {*} value The value to search for.
  1150. * @param {number} fromIndex The index to search from.
  1151. * @returns {number} Returns the index of the matched value, else `-1`.
  1152. */
  1153. function strictLastIndexOf(array, value, fromIndex) {
  1154. var index = fromIndex + 1;
  1155. while (index--) {
  1156. if (array[index] === value) {
  1157. return index;
  1158. }
  1159. }
  1160. return index;
  1161. }
  1162. /**
  1163. * Gets the number of symbols in `string`.
  1164. *
  1165. * @private
  1166. * @param {string} string The string to inspect.
  1167. * @returns {number} Returns the string size.
  1168. */
  1169. function stringSize(string) {
  1170. return hasUnicode(string)
  1171. ? unicodeSize(string)
  1172. : asciiSize(string);
  1173. }
  1174. /**
  1175. * Converts `string` to an array.
  1176. *
  1177. * @private
  1178. * @param {string} string The string to convert.
  1179. * @returns {Array} Returns the converted array.
  1180. */
  1181. function stringToArray(string) {
  1182. return hasUnicode(string)
  1183. ? unicodeToArray(string)
  1184. : asciiToArray(string);
  1185. }
  1186. /**
  1187. * Used by `_.unescape` to convert HTML entities to characters.
  1188. *
  1189. * @private
  1190. * @param {string} chr The matched character to unescape.
  1191. * @returns {string} Returns the unescaped character.
  1192. */
  1193. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1194. /**
  1195. * Gets the size of a Unicode `string`.
  1196. *
  1197. * @private
  1198. * @param {string} string The string inspect.
  1199. * @returns {number} Returns the string size.
  1200. */
  1201. function unicodeSize(string) {
  1202. var result = reUnicode.lastIndex = 0;
  1203. while (reUnicode.test(string)) {
  1204. ++result;
  1205. }
  1206. return result;
  1207. }
  1208. /**
  1209. * Converts a Unicode `string` to an array.
  1210. *
  1211. * @private
  1212. * @param {string} string The string to convert.
  1213. * @returns {Array} Returns the converted array.
  1214. */
  1215. function unicodeToArray(string) {
  1216. return string.match(reUnicode) || [];
  1217. }
  1218. /**
  1219. * Splits a Unicode `string` into an array of its words.
  1220. *
  1221. * @private
  1222. * @param {string} The string to inspect.
  1223. * @returns {Array} Returns the words of `string`.
  1224. */
  1225. function unicodeWords(string) {
  1226. return string.match(reUnicodeWord) || [];
  1227. }
  1228. /*--------------------------------------------------------------------------*/
  1229. /**
  1230. * Create a new pristine `lodash` function using the `context` object.
  1231. *
  1232. * @static
  1233. * @memberOf _
  1234. * @since 1.1.0
  1235. * @category Util
  1236. * @param {Object} [context=root] The context object.
  1237. * @returns {Function} Returns a new `lodash` function.
  1238. * @example
  1239. *
  1240. * _.mixin({ 'foo': _.constant('foo') });
  1241. *
  1242. * var lodash = _.runInContext();
  1243. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1244. *
  1245. * _.isFunction(_.foo);
  1246. * // => true
  1247. * _.isFunction(_.bar);
  1248. * // => false
  1249. *
  1250. * lodash.isFunction(lodash.foo);
  1251. * // => false
  1252. * lodash.isFunction(lodash.bar);
  1253. * // => true
  1254. *
  1255. * // Create a suped-up `defer` in Node.js.
  1256. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1257. */
  1258. var runInContext = (function runInContext(context) {
  1259. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1260. /** Built-in constructor references. */
  1261. var Array = context.Array,
  1262. Date = context.Date,
  1263. Error = context.Error,
  1264. Function = context.Function,
  1265. Math = context.Math,
  1266. Object = context.Object,
  1267. RegExp = context.RegExp,
  1268. String = context.String,
  1269. TypeError = context.TypeError;
  1270. /** Used for built-in method references. */
  1271. var arrayProto = Array.prototype,
  1272. funcProto = Function.prototype,
  1273. objectProto = Object.prototype;
  1274. /** Used to detect overreaching core-js shims. */
  1275. var coreJsData = context['__core-js_shared__'];
  1276. /** Used to resolve the decompiled source of functions. */
  1277. var funcToString = funcProto.toString;
  1278. /** Used to check objects for own properties. */
  1279. var hasOwnProperty = objectProto.hasOwnProperty;
  1280. /** Used to generate unique IDs. */
  1281. var idCounter = 0;
  1282. /** Used to detect methods masquerading as native. */
  1283. var maskSrcKey = (function() {
  1284. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1285. return uid ? ('Symbol(src)_1.' + uid) : '';
  1286. }());
  1287. /**
  1288. * Used to resolve the
  1289. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1290. * of values.
  1291. */
  1292. var nativeObjectToString = objectProto.toString;
  1293. /** Used to infer the `Object` constructor. */
  1294. var objectCtorString = funcToString.call(Object);
  1295. /** Used to restore the original `_` reference in `_.noConflict`. */
  1296. var oldDash = root._;
  1297. /** Used to detect if a method is native. */
  1298. var reIsNative = RegExp('^' +
  1299. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1300. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1301. );
  1302. /** Built-in value references. */
  1303. var Buffer = moduleExports ? context.Buffer : undefined,
  1304. Symbol = context.Symbol,
  1305. Uint8Array = context.Uint8Array,
  1306. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1307. getPrototype = overArg(Object.getPrototypeOf, Object),
  1308. objectCreate = Object.create,
  1309. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1310. splice = arrayProto.splice,
  1311. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1312. symIterator = Symbol ? Symbol.iterator : undefined,
  1313. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1314. var defineProperty = (function() {
  1315. try {
  1316. var func = getNative(Object, 'defineProperty');
  1317. func({}, '', {});
  1318. return func;
  1319. } catch (e) {}
  1320. }());
  1321. /** Mocked built-ins. */
  1322. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1323. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1324. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1325. /* Built-in method references for those with the same name as other `lodash` methods. */
  1326. var nativeCeil = Math.ceil,
  1327. nativeFloor = Math.floor,
  1328. nativeGetSymbols = Object.getOwnPropertySymbols,
  1329. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1330. nativeIsFinite = context.isFinite,
  1331. nativeJoin = arrayProto.join,
  1332. nativeKeys = overArg(Object.keys, Object),
  1333. nativeMax = Math.max,
  1334. nativeMin = Math.min,
  1335. nativeNow = Date.now,
  1336. nativeParseInt = context.parseInt,
  1337. nativeRandom = Math.random,
  1338. nativeReverse = arrayProto.reverse;
  1339. /* Built-in method references that are verified to be native. */
  1340. var DataView = getNative(context, 'DataView'),
  1341. Map = getNative(context, 'Map'),
  1342. Promise = getNative(context, 'Promise'),
  1343. Set = getNative(context, 'Set'),
  1344. WeakMap = getNative(context, 'WeakMap'),
  1345. nativeCreate = getNative(Object, 'create');
  1346. /** Used to store function metadata. */
  1347. var metaMap = WeakMap && new WeakMap;
  1348. /** Used to lookup unminified function names. */
  1349. var realNames = {};
  1350. /** Used to detect maps, sets, and weakmaps. */
  1351. var dataViewCtorString = toSource(DataView),
  1352. mapCtorString = toSource(Map),
  1353. promiseCtorString = toSource(Promise),
  1354. setCtorString = toSource(Set),
  1355. weakMapCtorString = toSource(WeakMap);
  1356. /** Used to convert symbols to primitives and strings. */
  1357. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1358. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1359. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1360. /*------------------------------------------------------------------------*/
  1361. /**
  1362. * Creates a `lodash` object which wraps `value` to enable implicit method
  1363. * chain sequences. Methods that operate on and return arrays, collections,
  1364. * and functions can be chained together. Methods that retrieve a single value
  1365. * or may return a primitive value will automatically end the chain sequence
  1366. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1367. * with `_#value`.
  1368. *
  1369. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1370. * enabled using `_.chain`.
  1371. *
  1372. * The execution of chained methods is lazy, that is, it's deferred until
  1373. * `_#value` is implicitly or explicitly called.
  1374. *
  1375. * Lazy evaluation allows several methods to support shortcut fusion.
  1376. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1377. * the creation of intermediate arrays and can greatly reduce the number of
  1378. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1379. * fusion if the section is applied to an array and iteratees accept only
  1380. * one argument. The heuristic for whether a section qualifies for shortcut
  1381. * fusion is subject to change.
  1382. *
  1383. * Chaining is supported in custom builds as long as the `_#value` method is
  1384. * directly or indirectly included in the build.
  1385. *
  1386. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1387. *
  1388. * The wrapper `Array` methods are:
  1389. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1390. *
  1391. * The wrapper `String` methods are:
  1392. * `replace` and `split`
  1393. *
  1394. * The wrapper methods that support shortcut fusion are:
  1395. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1396. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1397. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1398. *
  1399. * The chainable wrapper methods are:
  1400. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1401. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1402. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1403. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1404. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1405. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1406. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1407. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1408. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1409. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1410. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1411. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1412. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1413. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1414. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1415. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1416. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1417. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1418. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1419. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1420. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1421. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1422. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1423. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1424. *
  1425. * The wrapper methods that are **not** chainable by default are:
  1426. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1427. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1428. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1429. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1430. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1431. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1432. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1433. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1434. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1435. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1436. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1437. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1438. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1439. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1440. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1441. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1442. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1443. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1444. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1445. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1446. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1447. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1448. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1449. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1450. * `upperFirst`, `value`, and `words`
  1451. *
  1452. * @name _
  1453. * @constructor
  1454. * @category Seq
  1455. * @param {*} value The value to wrap in a `lodash` instance.
  1456. * @returns {Object} Returns the new `lodash` wrapper instance.
  1457. * @example
  1458. *
  1459. * function square(n) {
  1460. * return n * n;
  1461. * }
  1462. *
  1463. * var wrapped = _([1, 2, 3]);
  1464. *
  1465. * // Returns an unwrapped value.
  1466. * wrapped.reduce(_.add);
  1467. * // => 6
  1468. *
  1469. * // Returns a wrapped value.
  1470. * var squares = wrapped.map(square);
  1471. *
  1472. * _.isArray(squares);
  1473. * // => false
  1474. *
  1475. * _.isArray(squares.value());
  1476. * // => true
  1477. */
  1478. function lodash(value) {
  1479. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1480. if (value instanceof LodashWrapper) {
  1481. return value;
  1482. }
  1483. if (hasOwnProperty.call(value, '__wrapped__')) {
  1484. return wrapperClone(value);
  1485. }
  1486. }
  1487. return new LodashWrapper(value);
  1488. }
  1489. /**
  1490. * The base implementation of `_.create` without support for assigning
  1491. * properties to the created object.
  1492. *
  1493. * @private
  1494. * @param {Object} proto The object to inherit from.
  1495. * @returns {Object} Returns the new object.
  1496. */
  1497. var baseCreate = (function() {
  1498. function object() {}
  1499. return function(proto) {
  1500. if (!isObject(proto)) {
  1501. return {};
  1502. }
  1503. if (objectCreate) {
  1504. return objectCreate(proto);
  1505. }
  1506. object.prototype = proto;
  1507. var result = new object;
  1508. object.prototype = undefined;
  1509. return result;
  1510. };
  1511. }());
  1512. /**
  1513. * The function whose prototype chain sequence wrappers inherit from.
  1514. *
  1515. * @private
  1516. */
  1517. function baseLodash() {
  1518. // No operation performed.
  1519. }
  1520. /**
  1521. * The base constructor for creating `lodash` wrapper objects.
  1522. *
  1523. * @private
  1524. * @param {*} value The value to wrap.
  1525. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1526. */
  1527. function LodashWrapper(value, chainAll) {
  1528. this.__wrapped__ = value;
  1529. this.__actions__ = [];
  1530. this.__chain__ = !!chainAll;
  1531. this.__index__ = 0;
  1532. this.__values__ = undefined;
  1533. }
  1534. /**
  1535. * By default, the template delimiters used by lodash are like those in
  1536. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1537. * following template settings to use alternative delimiters.
  1538. *
  1539. * @static
  1540. * @memberOf _
  1541. * @type {Object}
  1542. */
  1543. lodash.templateSettings = {
  1544. /**
  1545. * Used to detect `data` property values to be HTML-escaped.
  1546. *
  1547. * @memberOf _.templateSettings
  1548. * @type {RegExp}
  1549. */
  1550. 'escape': reEscape,
  1551. /**
  1552. * Used to detect code to be evaluated.
  1553. *
  1554. * @memberOf _.templateSettings
  1555. * @type {RegExp}
  1556. */
  1557. 'evaluate': reEvaluate,
  1558. /**
  1559. * Used to detect `data` property values to inject.
  1560. *
  1561. * @memberOf _.templateSettings
  1562. * @type {RegExp}
  1563. */
  1564. 'interpolate': reInterpolate,
  1565. /**
  1566. * Used to reference the data object in the template text.
  1567. *
  1568. * @memberOf _.templateSettings
  1569. * @type {string}
  1570. */
  1571. 'variable': '',
  1572. /**
  1573. * Used to import variables into the compiled template.
  1574. *
  1575. * @memberOf _.templateSettings
  1576. * @type {Object}
  1577. */
  1578. 'imports': {
  1579. /**
  1580. * A reference to the `lodash` function.
  1581. *
  1582. * @memberOf _.templateSettings.imports
  1583. * @type {Function}
  1584. */
  1585. '_': lodash
  1586. }
  1587. };
  1588. // Ensure wrappers are instances of `baseLodash`.
  1589. lodash.prototype = baseLodash.prototype;
  1590. lodash.prototype.constructor = lodash;
  1591. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1592. LodashWrapper.prototype.constructor = LodashWrapper;
  1593. /*------------------------------------------------------------------------*/
  1594. /**
  1595. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1596. *
  1597. * @private
  1598. * @constructor
  1599. * @param {*} value The value to wrap.
  1600. */
  1601. function LazyWrapper(value) {
  1602. this.__wrapped__ = value;
  1603. this.__actions__ = [];
  1604. this.__dir__ = 1;
  1605. this.__filtered__ = false;
  1606. this.__iteratees__ = [];
  1607. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1608. this.__views__ = [];
  1609. }
  1610. /**
  1611. * Creates a clone of the lazy wrapper object.
  1612. *
  1613. * @private
  1614. * @name clone
  1615. * @memberOf LazyWrapper
  1616. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1617. */
  1618. function lazyClone() {
  1619. var result = new LazyWrapper(this.__wrapped__);
  1620. result.__actions__ = copyArray(this.__actions__);
  1621. result.__dir__ = this.__dir__;
  1622. result.__filtered__ = this.__filtered__;
  1623. result.__iteratees__ = copyArray(this.__iteratees__);
  1624. result.__takeCount__ = this.__takeCount__;
  1625. result.__views__ = copyArray(this.__views__);
  1626. return result;
  1627. }
  1628. /**
  1629. * Reverses the direction of lazy iteration.
  1630. *
  1631. * @private
  1632. * @name reverse
  1633. * @memberOf LazyWrapper
  1634. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1635. */
  1636. function lazyReverse() {
  1637. if (this.__filtered__) {
  1638. var result = new LazyWrapper(this);
  1639. result.__dir__ = -1;
  1640. result.__filtered__ = true;
  1641. } else {
  1642. result = this.clone();
  1643. result.__dir__ *= -1;
  1644. }
  1645. return result;
  1646. }
  1647. /**
  1648. * Extracts the unwrapped value from its lazy wrapper.
  1649. *
  1650. * @private
  1651. * @name value
  1652. * @memberOf LazyWrapper
  1653. * @returns {*} Returns the unwrapped value.
  1654. */
  1655. function lazyValue() {
  1656. var array = this.__wrapped__.value(),
  1657. dir = this.__dir__,
  1658. isArr = isArray(array),
  1659. isRight = dir < 0,
  1660. arrLength = isArr ? array.length : 0,
  1661. view = getView(0, arrLength, this.__views__),
  1662. start = view.start,
  1663. end = view.end,
  1664. length = end - start,
  1665. index = isRight ? end : (start - 1),
  1666. iteratees = this.__iteratees__,
  1667. iterLength = iteratees.length,
  1668. resIndex = 0,
  1669. takeCount = nativeMin(length, this.__takeCount__);
  1670. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1671. return baseWrapperValue(array, this.__actions__);
  1672. }
  1673. var result = [];
  1674. outer:
  1675. while (length-- && resIndex < takeCount) {
  1676. index += dir;
  1677. var iterIndex = -1,
  1678. value = array[index];
  1679. while (++iterIndex < iterLength) {
  1680. var data = iteratees[iterIndex],
  1681. iteratee = data.iteratee,
  1682. type = data.type,
  1683. computed = iteratee(value);
  1684. if (type == LAZY_MAP_FLAG) {
  1685. value = computed;
  1686. } else if (!computed) {
  1687. if (type == LAZY_FILTER_FLAG) {
  1688. continue outer;
  1689. } else {
  1690. break outer;
  1691. }
  1692. }
  1693. }
  1694. result[resIndex++] = value;
  1695. }
  1696. return result;
  1697. }
  1698. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1699. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1700. LazyWrapper.prototype.constructor = LazyWrapper;
  1701. /*------------------------------------------------------------------------*/
  1702. /**
  1703. * Creates a hash object.
  1704. *
  1705. * @private
  1706. * @constructor
  1707. * @param {Array} [entries] The key-value pairs to cache.
  1708. */
  1709. function Hash(entries) {
  1710. var index = -1,
  1711. length = entries == null ? 0 : entries.length;
  1712. this.clear();
  1713. while (++index < length) {
  1714. var entry = entries[index];
  1715. this.set(entry[0], entry[1]);
  1716. }
  1717. }
  1718. /**
  1719. * Removes all key-value entries from the hash.
  1720. *
  1721. * @private
  1722. * @name clear
  1723. * @memberOf Hash
  1724. */
  1725. function hashClear() {
  1726. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1727. this.size = 0;
  1728. }
  1729. /**
  1730. * Removes `key` and its value from the hash.
  1731. *
  1732. * @private
  1733. * @name delete
  1734. * @memberOf Hash
  1735. * @param {Object} hash The hash to modify.
  1736. * @param {string} key The key of the value to remove.
  1737. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1738. */
  1739. function hashDelete(key) {
  1740. var result = this.has(key) && delete this.__data__[key];
  1741. this.size -= result ? 1 : 0;
  1742. return result;
  1743. }
  1744. /**
  1745. * Gets the hash value for `key`.
  1746. *
  1747. * @private
  1748. * @name get
  1749. * @memberOf Hash
  1750. * @param {string} key The key of the value to get.
  1751. * @returns {*} Returns the entry value.
  1752. */
  1753. function hashGet(key) {
  1754. var data = this.__data__;
  1755. if (nativeCreate) {
  1756. var result = data[key];
  1757. return result === HASH_UNDEFINED ? undefined : result;
  1758. }
  1759. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1760. }
  1761. /**
  1762. * Checks if a hash value for `key` exists.
  1763. *
  1764. * @private
  1765. * @name has
  1766. * @memberOf Hash
  1767. * @param {string} key The key of the entry to check.
  1768. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1769. */
  1770. function hashHas(key) {
  1771. var data = this.__data__;
  1772. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1773. }
  1774. /**
  1775. * Sets the hash `key` to `value`.
  1776. *
  1777. * @private
  1778. * @name set
  1779. * @memberOf Hash
  1780. * @param {string} key The key of the value to set.
  1781. * @param {*} value The value to set.
  1782. * @returns {Object} Returns the hash instance.
  1783. */
  1784. function hashSet(key, value) {
  1785. var data = this.__data__;
  1786. this.size += this.has(key) ? 0 : 1;
  1787. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1788. return this;
  1789. }
  1790. // Add methods to `Hash`.
  1791. Hash.prototype.clear = hashClear;
  1792. Hash.prototype['delete'] = hashDelete;
  1793. Hash.prototype.get = hashGet;
  1794. Hash.prototype.has = hashHas;
  1795. Hash.prototype.set = hashSet;
  1796. /*------------------------------------------------------------------------*/
  1797. /**
  1798. * Creates an list cache object.
  1799. *
  1800. * @private
  1801. * @constructor
  1802. * @param {Array} [entries] The key-value pairs to cache.
  1803. */
  1804. function ListCache(entries) {
  1805. var index = -1,
  1806. length = entries == null ? 0 : entries.length;
  1807. this.clear();
  1808. while (++index < length) {
  1809. var entry = entries[index];
  1810. this.set(entry[0], entry[1]);
  1811. }
  1812. }
  1813. /**
  1814. * Removes all key-value entries from the list cache.
  1815. *
  1816. * @private
  1817. * @name clear
  1818. * @memberOf ListCache
  1819. */
  1820. function listCacheClear() {
  1821. this.__data__ = [];
  1822. this.size = 0;
  1823. }
  1824. /**
  1825. * Removes `key` and its value from the list cache.
  1826. *
  1827. * @private
  1828. * @name delete
  1829. * @memberOf ListCache
  1830. * @param {string} key The key of the value to remove.
  1831. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1832. */
  1833. function listCacheDelete(key) {
  1834. var data = this.__data__,
  1835. index = assocIndexOf(data, key);
  1836. if (index < 0) {
  1837. return false;
  1838. }
  1839. var lastIndex = data.length - 1;
  1840. if (index == lastIndex) {
  1841. data.pop();
  1842. } else {
  1843. splice.call(data, index, 1);
  1844. }
  1845. --this.size;
  1846. return true;
  1847. }
  1848. /**
  1849. * Gets the list cache value for `key`.
  1850. *
  1851. * @private
  1852. * @name get
  1853. * @memberOf ListCache
  1854. * @param {string} key The key of the value to get.
  1855. * @returns {*} Returns the entry value.
  1856. */
  1857. function listCacheGet(key) {
  1858. var data = this.__data__,
  1859. index = assocIndexOf(data, key);
  1860. return index < 0 ? undefined : data[index][1];
  1861. }
  1862. /**
  1863. * Checks if a list cache value for `key` exists.
  1864. *
  1865. * @private
  1866. * @name has
  1867. * @memberOf ListCache
  1868. * @param {string} key The key of the entry to check.
  1869. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1870. */
  1871. function listCacheHas(key) {
  1872. return assocIndexOf(this.__data__, key) > -1;
  1873. }
  1874. /**
  1875. * Sets the list cache `key` to `value`.
  1876. *
  1877. * @private
  1878. * @name set
  1879. * @memberOf ListCache
  1880. * @param {string} key The key of the value to set.
  1881. * @param {*} value The value to set.
  1882. * @returns {Object} Returns the list cache instance.
  1883. */
  1884. function listCacheSet(key, value) {
  1885. var data = this.__data__,
  1886. index = assocIndexOf(data, key);
  1887. if (index < 0) {
  1888. ++this.size;
  1889. data.push([key, value]);
  1890. } else {
  1891. data[index][1] = value;
  1892. }
  1893. return this;
  1894. }
  1895. // Add methods to `ListCache`.
  1896. ListCache.prototype.clear = listCacheClear;
  1897. ListCache.prototype['delete'] = listCacheDelete;
  1898. ListCache.prototype.get = listCacheGet;
  1899. ListCache.prototype.has = listCacheHas;
  1900. ListCache.prototype.set = listCacheSet;
  1901. /*------------------------------------------------------------------------*/
  1902. /**
  1903. * Creates a map cache object to store key-value pairs.
  1904. *
  1905. * @private
  1906. * @constructor
  1907. * @param {Array} [entries] The key-value pairs to cache.
  1908. */
  1909. function MapCache(entries) {
  1910. var index = -1,
  1911. length = entries == null ? 0 : entries.length;
  1912. this.clear();
  1913. while (++index < length) {
  1914. var entry = entries[index];
  1915. this.set(entry[0], entry[1]);
  1916. }
  1917. }
  1918. /**
  1919. * Removes all key-value entries from the map.
  1920. *
  1921. * @private
  1922. * @name clear
  1923. * @memberOf MapCache
  1924. */
  1925. function mapCacheClear() {
  1926. this.size = 0;
  1927. this.__data__ = {
  1928. 'hash': new Hash,
  1929. 'map': new (Map || ListCache),
  1930. 'string': new Hash
  1931. };
  1932. }
  1933. /**
  1934. * Removes `key` and its value from the map.
  1935. *
  1936. * @private
  1937. * @name delete
  1938. * @memberOf MapCache
  1939. * @param {string} key The key of the value to remove.
  1940. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1941. */
  1942. function mapCacheDelete(key) {
  1943. var result = getMapData(this, key)['delete'](key);
  1944. this.size -= result ? 1 : 0;
  1945. return result;
  1946. }
  1947. /**
  1948. * Gets the map value for `key`.
  1949. *
  1950. * @private
  1951. * @name get
  1952. * @memberOf MapCache
  1953. * @param {string} key The key of the value to get.
  1954. * @returns {*} Returns the entry value.
  1955. */
  1956. function mapCacheGet(key) {
  1957. return getMapData(this, key).get(key);
  1958. }
  1959. /**
  1960. * Checks if a map value for `key` exists.
  1961. *
  1962. * @private
  1963. * @name has
  1964. * @memberOf MapCache
  1965. * @param {string} key The key of the entry to check.
  1966. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1967. */
  1968. function mapCacheHas(key) {
  1969. return getMapData(this, key).has(key);
  1970. }
  1971. /**
  1972. * Sets the map `key` to `value`.
  1973. *
  1974. * @private
  1975. * @name set
  1976. * @memberOf MapCache
  1977. * @param {string} key The key of the value to set.
  1978. * @param {*} value The value to set.
  1979. * @returns {Object} Returns the map cache instance.
  1980. */
  1981. function mapCacheSet(key, value) {
  1982. var data = getMapData(this, key),
  1983. size = data.size;
  1984. data.set(key, value);
  1985. this.size += data.size == size ? 0 : 1;
  1986. return this;
  1987. }
  1988. // Add methods to `MapCache`.
  1989. MapCache.prototype.clear = mapCacheClear;
  1990. MapCache.prototype['delete'] = mapCacheDelete;
  1991. MapCache.prototype.get = mapCacheGet;
  1992. MapCache.prototype.has = mapCacheHas;
  1993. MapCache.prototype.set = mapCacheSet;
  1994. /*------------------------------------------------------------------------*/
  1995. /**
  1996. *
  1997. * Creates an array cache object to store unique values.
  1998. *
  1999. * @private
  2000. * @constructor
  2001. * @param {Array} [values] The values to cache.
  2002. */
  2003. function SetCache(values) {
  2004. var index = -1,
  2005. length = values == null ? 0 : values.length;
  2006. this.__data__ = new MapCache;
  2007. while (++index < length) {
  2008. this.add(values[index]);
  2009. }
  2010. }
  2011. /**
  2012. * Adds `value` to the array cache.
  2013. *
  2014. * @private
  2015. * @name add
  2016. * @memberOf SetCache
  2017. * @alias push
  2018. * @param {*} value The value to cache.
  2019. * @returns {Object} Returns the cache instance.
  2020. */
  2021. function setCacheAdd(value) {
  2022. this.__data__.set(value, HASH_UNDEFINED);
  2023. return this;
  2024. }
  2025. /**
  2026. * Checks if `value` is in the array cache.
  2027. *
  2028. * @private
  2029. * @name has
  2030. * @memberOf SetCache
  2031. * @param {*} value The value to search for.
  2032. * @returns {number} Returns `true` if `value` is found, else `false`.
  2033. */
  2034. function setCacheHas(value) {
  2035. return this.__data__.has(value);
  2036. }
  2037. // Add methods to `SetCache`.
  2038. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2039. SetCache.prototype.has = setCacheHas;
  2040. /*------------------------------------------------------------------------*/
  2041. /**
  2042. * Creates a stack cache object to store key-value pairs.
  2043. *
  2044. * @private
  2045. * @constructor
  2046. * @param {Array} [entries] The key-value pairs to cache.
  2047. */
  2048. function Stack(entries) {
  2049. var data = this.__data__ = new ListCache(entries);
  2050. this.size = data.size;
  2051. }
  2052. /**
  2053. * Removes all key-value entries from the stack.
  2054. *
  2055. * @private
  2056. * @name clear
  2057. * @memberOf Stack
  2058. */
  2059. function stackClear() {
  2060. this.__data__ = new ListCache;
  2061. this.size = 0;
  2062. }
  2063. /**
  2064. * Removes `key` and its value from the stack.
  2065. *
  2066. * @private
  2067. * @name delete
  2068. * @memberOf Stack
  2069. * @param {string} key The key of the value to remove.
  2070. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2071. */
  2072. function stackDelete(key) {
  2073. var data = this.__data__,
  2074. result = data['delete'](key);
  2075. this.size = data.size;
  2076. return result;
  2077. }
  2078. /**
  2079. * Gets the stack value for `key`.
  2080. *
  2081. * @private
  2082. * @name get
  2083. * @memberOf Stack
  2084. * @param {string} key The key of the value to get.
  2085. * @returns {*} Returns the entry value.
  2086. */
  2087. function stackGet(key) {
  2088. return this.__data__.get(key);
  2089. }
  2090. /**
  2091. * Checks if a stack value for `key` exists.
  2092. *
  2093. * @private
  2094. * @name has
  2095. * @memberOf Stack
  2096. * @param {string} key The key of the entry to check.
  2097. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2098. */
  2099. function stackHas(key) {
  2100. return this.__data__.has(key);
  2101. }
  2102. /**
  2103. * Sets the stack `key` to `value`.
  2104. *
  2105. * @private
  2106. * @name set
  2107. * @memberOf Stack
  2108. * @param {string} key The key of the value to set.
  2109. * @param {*} value The value to set.
  2110. * @returns {Object} Returns the stack cache instance.
  2111. */
  2112. function stackSet(key, value) {
  2113. var data = this.__data__;
  2114. if (data instanceof ListCache) {
  2115. var pairs = data.__data__;
  2116. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2117. pairs.push([key, value]);
  2118. this.size = ++data.size;
  2119. return this;
  2120. }
  2121. data = this.__data__ = new MapCache(pairs);
  2122. }
  2123. data.set(key, value);
  2124. this.size = data.size;
  2125. return this;
  2126. }
  2127. // Add methods to `Stack`.
  2128. Stack.prototype.clear = stackClear;
  2129. Stack.prototype['delete'] = stackDelete;
  2130. Stack.prototype.get = stackGet;
  2131. Stack.prototype.has = stackHas;
  2132. Stack.prototype.set = stackSet;
  2133. /*------------------------------------------------------------------------*/
  2134. /**
  2135. * Creates an array of the enumerable property names of the array-like `value`.
  2136. *
  2137. * @private
  2138. * @param {*} value The value to query.
  2139. * @param {boolean} inherited Specify returning inherited property names.
  2140. * @returns {Array} Returns the array of property names.
  2141. */
  2142. function arrayLikeKeys(value, inherited) {
  2143. var isArr = isArray(value),
  2144. isArg = !isArr && isArguments(value),
  2145. isBuff = !isArr && !isArg && isBuffer(value),
  2146. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2147. skipIndexes = isArr || isArg || isBuff || isType,
  2148. result = skipIndexes ? baseTimes(value.length, String) : [],
  2149. length = result.length;
  2150. for (var key in value) {
  2151. if ((inherited || hasOwnProperty.call(value, key)) &&
  2152. !(skipIndexes && (
  2153. // Safari 9 has enumerable `arguments.length` in strict mode.
  2154. key == 'length' ||
  2155. // Node.js 0.10 has enumerable non-index properties on buffers.
  2156. (isBuff && (key == 'offset' || key == 'parent')) ||
  2157. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2158. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2159. // Skip index properties.
  2160. isIndex(key, length)
  2161. ))) {
  2162. result.push(key);
  2163. }
  2164. }
  2165. return result;
  2166. }
  2167. /**
  2168. * A specialized version of `_.sample` for arrays.
  2169. *
  2170. * @private
  2171. * @param {Array} array The array to sample.
  2172. * @returns {*} Returns the random element.
  2173. */
  2174. function arraySample(array) {
  2175. var length = array.length;
  2176. return length ? array[baseRandom(0, length - 1)] : undefined;
  2177. }
  2178. /**
  2179. * A specialized version of `_.sampleSize` for arrays.
  2180. *
  2181. * @private
  2182. * @param {Array} array The array to sample.
  2183. * @param {number} n The number of elements to sample.
  2184. * @returns {Array} Returns the random elements.
  2185. */
  2186. function arraySampleSize(array, n) {
  2187. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2188. }
  2189. /**
  2190. * A specialized version of `_.shuffle` for arrays.
  2191. *
  2192. * @private
  2193. * @param {Array} array The array to shuffle.
  2194. * @returns {Array} Returns the new shuffled array.
  2195. */
  2196. function arrayShuffle(array) {
  2197. return shuffleSelf(copyArray(array));
  2198. }
  2199. /**
  2200. * This function is like `assignValue` except that it doesn't assign
  2201. * `undefined` values.
  2202. *
  2203. * @private
  2204. * @param {Object} object The object to modify.
  2205. * @param {string} key The key of the property to assign.
  2206. * @param {*} value The value to assign.
  2207. */
  2208. function assignMergeValue(object, key, value) {
  2209. if ((value !== undefined && !eq(object[key], value)) ||
  2210. (value === undefined && !(key in object))) {
  2211. baseAssignValue(object, key, value);
  2212. }
  2213. }
  2214. /**
  2215. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2216. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2217. * for equality comparisons.
  2218. *
  2219. * @private
  2220. * @param {Object} object The object to modify.
  2221. * @param {string} key The key of the property to assign.
  2222. * @param {*} value The value to assign.
  2223. */
  2224. function assignValue(object, key, value) {
  2225. var objValue = object[key];
  2226. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2227. (value === undefined && !(key in object))) {
  2228. baseAssignValue(object, key, value);
  2229. }
  2230. }
  2231. /**
  2232. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2233. *
  2234. * @private
  2235. * @param {Array} array The array to inspect.
  2236. * @param {*} key The key to search for.
  2237. * @returns {number} Returns the index of the matched value, else `-1`.
  2238. */
  2239. function assocIndexOf(array, key) {
  2240. var length = array.length;
  2241. while (length--) {
  2242. if (eq(array[length][0], key)) {
  2243. return length;
  2244. }
  2245. }
  2246. return -1;
  2247. }
  2248. /**
  2249. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2250. * by `iteratee` and values set by `setter`.
  2251. *
  2252. * @private
  2253. * @param {Array|Object} collection The collection to iterate over.
  2254. * @param {Function} setter The function to set `accumulator` values.
  2255. * @param {Function} iteratee The iteratee to transform keys.
  2256. * @param {Object} accumulator The initial aggregated object.
  2257. * @returns {Function} Returns `accumulator`.
  2258. */
  2259. function baseAggregator(collection, setter, iteratee, accumulator) {
  2260. baseEach(collection, function(value, key, collection) {
  2261. setter(accumulator, value, iteratee(value), collection);
  2262. });
  2263. return accumulator;
  2264. }
  2265. /**
  2266. * The base implementation of `_.assign` without support for multiple sources
  2267. * or `customizer` functions.
  2268. *
  2269. * @private
  2270. * @param {Object} object The destination object.
  2271. * @param {Object} source The source object.
  2272. * @returns {Object} Returns `object`.
  2273. */
  2274. function baseAssign(object, source) {
  2275. return object && copyObject(source, keys(source), object);
  2276. }
  2277. /**
  2278. * The base implementation of `_.assignIn` without support for multiple sources
  2279. * or `customizer` functions.
  2280. *
  2281. * @private
  2282. * @param {Object} object The destination object.
  2283. * @param {Object} source The source object.
  2284. * @returns {Object} Returns `object`.
  2285. */
  2286. function baseAssignIn(object, source) {
  2287. return object && copyObject(source, keysIn(source), object);
  2288. }
  2289. /**
  2290. * The base implementation of `assignValue` and `assignMergeValue` without
  2291. * value checks.
  2292. *
  2293. * @private
  2294. * @param {Object} object The object to modify.
  2295. * @param {string} key The key of the property to assign.
  2296. * @param {*} value The value to assign.
  2297. */
  2298. function baseAssignValue(object, key, value) {
  2299. if (key == '__proto__' && defineProperty) {
  2300. defineProperty(object, key, {
  2301. 'configurable': true,
  2302. 'enumerable': true,
  2303. 'value': value,
  2304. 'writable': true
  2305. });
  2306. } else {
  2307. object[key] = value;
  2308. }
  2309. }
  2310. /**
  2311. * The base implementation of `_.at` without support for individual paths.
  2312. *
  2313. * @private
  2314. * @param {Object} object The object to iterate over.
  2315. * @param {string[]} paths The property paths to pick.
  2316. * @returns {Array} Returns the picked elements.
  2317. */
  2318. function baseAt(object, paths) {
  2319. var index = -1,
  2320. length = paths.length,
  2321. result = Array(length),
  2322. skip = object == null;
  2323. while (++index < length) {
  2324. result[index] = skip ? undefined : get(object, paths[index]);
  2325. }
  2326. return result;
  2327. }
  2328. /**
  2329. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2330. *
  2331. * @private
  2332. * @param {number} number The number to clamp.
  2333. * @param {number} [lower] The lower bound.
  2334. * @param {number} upper The upper bound.
  2335. * @returns {number} Returns the clamped number.
  2336. */
  2337. function baseClamp(number, lower, upper) {
  2338. if (number === number) {
  2339. if (upper !== undefined) {
  2340. number = number <= upper ? number : upper;
  2341. }
  2342. if (lower !== undefined) {
  2343. number = number >= lower ? number : lower;
  2344. }
  2345. }
  2346. return number;
  2347. }
  2348. /**
  2349. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2350. * traversed objects.
  2351. *
  2352. * @private
  2353. * @param {*} value The value to clone.
  2354. * @param {boolean} bitmask The bitmask flags.
  2355. * 1 - Deep clone
  2356. * 2 - Flatten inherited properties
  2357. * 4 - Clone symbols
  2358. * @param {Function} [customizer] The function to customize cloning.
  2359. * @param {string} [key] The key of `value`.
  2360. * @param {Object} [object] The parent object of `value`.
  2361. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2362. * @returns {*} Returns the cloned value.
  2363. */
  2364. function baseClone(value, bitmask, customizer, key, object, stack) {
  2365. var result,
  2366. isDeep = bitmask & CLONE_DEEP_FLAG,
  2367. isFlat = bitmask & CLONE_FLAT_FLAG,
  2368. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2369. if (customizer) {
  2370. result = object ? customizer(value, key, object, stack) : customizer(value);
  2371. }
  2372. if (result !== undefined) {
  2373. return result;
  2374. }
  2375. if (!isObject(value)) {
  2376. return value;
  2377. }
  2378. var isArr = isArray(value);
  2379. if (isArr) {
  2380. result = initCloneArray(value);
  2381. if (!isDeep) {
  2382. return copyArray(value, result);
  2383. }
  2384. } else {
  2385. var tag = getTag(value),
  2386. isFunc = tag == funcTag || tag == genTag;
  2387. if (isBuffer(value)) {
  2388. return cloneBuffer(value, isDeep);
  2389. }
  2390. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2391. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2392. if (!isDeep) {
  2393. return isFlat
  2394. ? copySymbolsIn(value, baseAssignIn(result, value))
  2395. : copySymbols(value, baseAssign(result, value));
  2396. }
  2397. } else {
  2398. if (!cloneableTags[tag]) {
  2399. return object ? value : {};
  2400. }
  2401. result = initCloneByTag(value, tag, isDeep);
  2402. }
  2403. }
  2404. // Check for circular references and return its corresponding clone.
  2405. stack || (stack = new Stack);
  2406. var stacked = stack.get(value);
  2407. if (stacked) {
  2408. return stacked;
  2409. }
  2410. stack.set(value, result);
  2411. if (isSet(value)) {
  2412. value.forEach(function(subValue) {
  2413. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2414. });
  2415. } else if (isMap(value)) {
  2416. value.forEach(function(subValue, key) {
  2417. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2418. });
  2419. }
  2420. var keysFunc = isFull
  2421. ? (isFlat ? getAllKeysIn : getAllKeys)
  2422. : (isFlat ? keysIn : keys);
  2423. var props = isArr ? undefined : keysFunc(value);
  2424. arrayEach(props || value, function(subValue, key) {
  2425. if (props) {
  2426. key = subValue;
  2427. subValue = value[key];
  2428. }
  2429. // Recursively populate clone (susceptible to call stack limits).
  2430. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2431. });
  2432. return result;
  2433. }
  2434. /**
  2435. * The base implementation of `_.conforms` which doesn't clone `source`.
  2436. *
  2437. * @private
  2438. * @param {Object} source The object of property predicates to conform to.
  2439. * @returns {Function} Returns the new spec function.
  2440. */
  2441. function baseConforms(source) {
  2442. var props = keys(source);
  2443. return function(object) {
  2444. return baseConformsTo(object, source, props);
  2445. };
  2446. }
  2447. /**
  2448. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2449. *
  2450. * @private
  2451. * @param {Object} object The object to inspect.
  2452. * @param {Object} source The object of property predicates to conform to.
  2453. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2454. */
  2455. function baseConformsTo(object, source, props) {
  2456. var length = props.length;
  2457. if (object == null) {
  2458. return !length;
  2459. }
  2460. object = Object(object);
  2461. while (length--) {
  2462. var key = props[length],
  2463. predicate = source[key],
  2464. value = object[key];
  2465. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2466. return false;
  2467. }
  2468. }
  2469. return true;
  2470. }
  2471. /**
  2472. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2473. * to provide to `func`.
  2474. *
  2475. * @private
  2476. * @param {Function} func The function to delay.
  2477. * @param {number} wait The number of milliseconds to delay invocation.
  2478. * @param {Array} args The arguments to provide to `func`.
  2479. * @returns {number|Object} Returns the timer id or timeout object.
  2480. */
  2481. function baseDelay(func, wait, args) {
  2482. if (typeof func != 'function') {
  2483. throw new TypeError(FUNC_ERROR_TEXT);
  2484. }
  2485. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2486. }
  2487. /**
  2488. * The base implementation of methods like `_.difference` without support
  2489. * for excluding multiple arrays or iteratee shorthands.
  2490. *
  2491. * @private
  2492. * @param {Array} array The array to inspect.
  2493. * @param {Array} values The values to exclude.
  2494. * @param {Function} [iteratee] The iteratee invoked per element.
  2495. * @param {Function} [comparator] The comparator invoked per element.
  2496. * @returns {Array} Returns the new array of filtered values.
  2497. */
  2498. function baseDifference(array, values, iteratee, comparator) {
  2499. var index = -1,
  2500. includes = arrayIncludes,
  2501. isCommon = true,
  2502. length = array.length,
  2503. result = [],
  2504. valuesLength = values.length;
  2505. if (!length) {
  2506. return result;
  2507. }
  2508. if (iteratee) {
  2509. values = arrayMap(values, baseUnary(iteratee));
  2510. }
  2511. if (comparator) {
  2512. includes = arrayIncludesWith;
  2513. isCommon = false;
  2514. }
  2515. else if (values.length >= LARGE_ARRAY_SIZE) {
  2516. includes = cacheHas;
  2517. isCommon = false;
  2518. values = new SetCache(values);
  2519. }
  2520. outer:
  2521. while (++index < length) {
  2522. var value = array[index],
  2523. computed = iteratee == null ? value : iteratee(value);
  2524. value = (comparator || value !== 0) ? value : 0;
  2525. if (isCommon && computed === computed) {
  2526. var valuesIndex = valuesLength;
  2527. while (valuesIndex--) {
  2528. if (values[valuesIndex] === computed) {
  2529. continue outer;
  2530. }
  2531. }
  2532. result.push(value);
  2533. }
  2534. else if (!includes(values, computed, comparator)) {
  2535. result.push(value);
  2536. }
  2537. }
  2538. return result;
  2539. }
  2540. /**
  2541. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2542. *
  2543. * @private
  2544. * @param {Array|Object} collection The collection to iterate over.
  2545. * @param {Function} iteratee The function invoked per iteration.
  2546. * @returns {Array|Object} Returns `collection`.
  2547. */
  2548. var baseEach = createBaseEach(baseForOwn);
  2549. /**
  2550. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2551. *
  2552. * @private
  2553. * @param {Array|Object} collection The collection to iterate over.
  2554. * @param {Function} iteratee The function invoked per iteration.
  2555. * @returns {Array|Object} Returns `collection`.
  2556. */
  2557. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2558. /**
  2559. * The base implementation of `_.every` without support for iteratee shorthands.
  2560. *
  2561. * @private
  2562. * @param {Array|Object} collection The collection to iterate over.
  2563. * @param {Function} predicate The function invoked per iteration.
  2564. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2565. * else `false`
  2566. */
  2567. function baseEvery(collection, predicate) {
  2568. var result = true;
  2569. baseEach(collection, function(value, index, collection) {
  2570. result = !!predicate(value, index, collection);
  2571. return result;
  2572. });
  2573. return result;
  2574. }
  2575. /**
  2576. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2577. * `comparator` to determine the extremum value.
  2578. *
  2579. * @private
  2580. * @param {Array} array The array to iterate over.
  2581. * @param {Function} iteratee The iteratee invoked per iteration.
  2582. * @param {Function} comparator The comparator used to compare values.
  2583. * @returns {*} Returns the extremum value.
  2584. */
  2585. function baseExtremum(array, iteratee, comparator) {
  2586. var index = -1,
  2587. length = array.length;
  2588. while (++index < length) {
  2589. var value = array[index],
  2590. current = iteratee(value);
  2591. if (current != null && (computed === undefined
  2592. ? (current === current && !isSymbol(current))
  2593. : comparator(current, computed)
  2594. )) {
  2595. var computed = current,
  2596. result = value;
  2597. }
  2598. }
  2599. return result;
  2600. }
  2601. /**
  2602. * The base implementation of `_.fill` without an iteratee call guard.
  2603. *
  2604. * @private
  2605. * @param {Array} array The array to fill.
  2606. * @param {*} value The value to fill `array` with.
  2607. * @param {number} [start=0] The start position.
  2608. * @param {number} [end=array.length] The end position.
  2609. * @returns {Array} Returns `array`.
  2610. */
  2611. function baseFill(array, value, start, end) {
  2612. var length = array.length;
  2613. start = toInteger(start);
  2614. if (start < 0) {
  2615. start = -start > length ? 0 : (length + start);
  2616. }
  2617. end = (end === undefined || end > length) ? length : toInteger(end);
  2618. if (end < 0) {
  2619. end += length;
  2620. }
  2621. end = start > end ? 0 : toLength(end);
  2622. while (start < end) {
  2623. array[start++] = value;
  2624. }
  2625. return array;
  2626. }
  2627. /**
  2628. * The base implementation of `_.filter` without support for iteratee shorthands.
  2629. *
  2630. * @private
  2631. * @param {Array|Object} collection The collection to iterate over.
  2632. * @param {Function} predicate The function invoked per iteration.
  2633. * @returns {Array} Returns the new filtered array.
  2634. */
  2635. function baseFilter(collection, predicate) {
  2636. var result = [];
  2637. baseEach(collection, function(value, index, collection) {
  2638. if (predicate(value, index, collection)) {
  2639. result.push(value);
  2640. }
  2641. });
  2642. return result;
  2643. }
  2644. /**
  2645. * The base implementation of `_.flatten` with support for restricting flattening.
  2646. *
  2647. * @private
  2648. * @param {Array} array The array to flatten.
  2649. * @param {number} depth The maximum recursion depth.
  2650. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2651. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2652. * @param {Array} [result=[]] The initial result value.
  2653. * @returns {Array} Returns the new flattened array.
  2654. */
  2655. function baseFlatten(array, depth, predicate, isStrict, result) {
  2656. var index = -1,
  2657. length = array.length;
  2658. predicate || (predicate = isFlattenable);
  2659. result || (result = []);
  2660. while (++index < length) {
  2661. var value = array[index];
  2662. if (depth > 0 && predicate(value)) {
  2663. if (depth > 1) {
  2664. // Recursively flatten arrays (susceptible to call stack limits).
  2665. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2666. } else {
  2667. arrayPush(result, value);
  2668. }
  2669. } else if (!isStrict) {
  2670. result[result.length] = value;
  2671. }
  2672. }
  2673. return result;
  2674. }
  2675. /**
  2676. * The base implementation of `baseForOwn` which iterates over `object`
  2677. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2678. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2679. *
  2680. * @private
  2681. * @param {Object} object The object to iterate over.
  2682. * @param {Function} iteratee The function invoked per iteration.
  2683. * @param {Function} keysFunc The function to get the keys of `object`.
  2684. * @returns {Object} Returns `object`.
  2685. */
  2686. var baseFor = createBaseFor();
  2687. /**
  2688. * This function is like `baseFor` except that it iterates over properties
  2689. * in the opposite order.
  2690. *
  2691. * @private
  2692. * @param {Object} object The object to iterate over.
  2693. * @param {Function} iteratee The function invoked per iteration.
  2694. * @param {Function} keysFunc The function to get the keys of `object`.
  2695. * @returns {Object} Returns `object`.
  2696. */
  2697. var baseForRight = createBaseFor(true);
  2698. /**
  2699. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2700. *
  2701. * @private
  2702. * @param {Object} object The object to iterate over.
  2703. * @param {Function} iteratee The function invoked per iteration.
  2704. * @returns {Object} Returns `object`.
  2705. */
  2706. function baseForOwn(object, iteratee) {
  2707. return object && baseFor(object, iteratee, keys);
  2708. }
  2709. /**
  2710. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2711. *
  2712. * @private
  2713. * @param {Object} object The object to iterate over.
  2714. * @param {Function} iteratee The function invoked per iteration.
  2715. * @returns {Object} Returns `object`.
  2716. */
  2717. function baseForOwnRight(object, iteratee) {
  2718. return object && baseForRight(object, iteratee, keys);
  2719. }
  2720. /**
  2721. * The base implementation of `_.functions` which creates an array of
  2722. * `object` function property names filtered from `props`.
  2723. *
  2724. * @private
  2725. * @param {Object} object The object to inspect.
  2726. * @param {Array} props The property names to filter.
  2727. * @returns {Array} Returns the function names.
  2728. */
  2729. function baseFunctions(object, props) {
  2730. return arrayFilter(props, function(key) {
  2731. return isFunction(object[key]);
  2732. });
  2733. }
  2734. /**
  2735. * The base implementation of `_.get` without support for default values.
  2736. *
  2737. * @private
  2738. * @param {Object} object The object to query.
  2739. * @param {Array|string} path The path of the property to get.
  2740. * @returns {*} Returns the resolved value.
  2741. */
  2742. function baseGet(object, path) {
  2743. path = castPath(path, object);
  2744. var index = 0,
  2745. length = path.length;
  2746. while (object != null && index < length) {
  2747. object = object[toKey(path[index++])];
  2748. }
  2749. return (index && index == length) ? object : undefined;
  2750. }
  2751. /**
  2752. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2753. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2754. * symbols of `object`.
  2755. *
  2756. * @private
  2757. * @param {Object} object The object to query.
  2758. * @param {Function} keysFunc The function to get the keys of `object`.
  2759. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2760. * @returns {Array} Returns the array of property names and symbols.
  2761. */
  2762. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2763. var result = keysFunc(object);
  2764. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2765. }
  2766. /**
  2767. * The base implementation of `getTag` without fallbacks for buggy environments.
  2768. *
  2769. * @private
  2770. * @param {*} value The value to query.
  2771. * @returns {string} Returns the `toStringTag`.
  2772. */
  2773. function baseGetTag(value) {
  2774. if (value == null) {
  2775. return value === undefined ? undefinedTag : nullTag;
  2776. }
  2777. return (symToStringTag && symToStringTag in Object(value))
  2778. ? getRawTag(value)
  2779. : objectToString(value);
  2780. }
  2781. /**
  2782. * The base implementation of `_.gt` which doesn't coerce arguments.
  2783. *
  2784. * @private
  2785. * @param {*} value The value to compare.
  2786. * @param {*} other The other value to compare.
  2787. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2788. * else `false`.
  2789. */
  2790. function baseGt(value, other) {
  2791. return value > other;
  2792. }
  2793. /**
  2794. * The base implementation of `_.has` without support for deep paths.
  2795. *
  2796. * @private
  2797. * @param {Object} [object] The object to query.
  2798. * @param {Array|string} key The key to check.
  2799. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2800. */
  2801. function baseHas(object, key) {
  2802. return object != null && hasOwnProperty.call(object, key);
  2803. }
  2804. /**
  2805. * The base implementation of `_.hasIn` without support for deep paths.
  2806. *
  2807. * @private
  2808. * @param {Object} [object] The object to query.
  2809. * @param {Array|string} key The key to check.
  2810. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2811. */
  2812. function baseHasIn(object, key) {
  2813. return object != null && key in Object(object);
  2814. }
  2815. /**
  2816. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2817. *
  2818. * @private
  2819. * @param {number} number The number to check.
  2820. * @param {number} start The start of the range.
  2821. * @param {number} end The end of the range.
  2822. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2823. */
  2824. function baseInRange(number, start, end) {
  2825. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2826. }
  2827. /**
  2828. * The base implementation of methods like `_.intersection`, without support
  2829. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2830. *
  2831. * @private
  2832. * @param {Array} arrays The arrays to inspect.
  2833. * @param {Function} [iteratee] The iteratee invoked per element.
  2834. * @param {Function} [comparator] The comparator invoked per element.
  2835. * @returns {Array} Returns the new array of shared values.
  2836. */
  2837. function baseIntersection(arrays, iteratee, comparator) {
  2838. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2839. length = arrays[0].length,
  2840. othLength = arrays.length,
  2841. othIndex = othLength,
  2842. caches = Array(othLength),
  2843. maxLength = Infinity,
  2844. result = [];
  2845. while (othIndex--) {
  2846. var array = arrays[othIndex];
  2847. if (othIndex && iteratee) {
  2848. array = arrayMap(array, baseUnary(iteratee));
  2849. }
  2850. maxLength = nativeMin(array.length, maxLength);
  2851. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2852. ? new SetCache(othIndex && array)
  2853. : undefined;
  2854. }
  2855. array = arrays[0];
  2856. var index = -1,
  2857. seen = caches[0];
  2858. outer:
  2859. while (++index < length && result.length < maxLength) {
  2860. var value = array[index],
  2861. computed = iteratee ? iteratee(value) : value;
  2862. value = (comparator || value !== 0) ? value : 0;
  2863. if (!(seen
  2864. ? cacheHas(seen, computed)
  2865. : includes(result, computed, comparator)
  2866. )) {
  2867. othIndex = othLength;
  2868. while (--othIndex) {
  2869. var cache = caches[othIndex];
  2870. if (!(cache
  2871. ? cacheHas(cache, computed)
  2872. : includes(arrays[othIndex], computed, comparator))
  2873. ) {
  2874. continue outer;
  2875. }
  2876. }
  2877. if (seen) {
  2878. seen.push(computed);
  2879. }
  2880. result.push(value);
  2881. }
  2882. }
  2883. return result;
  2884. }
  2885. /**
  2886. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2887. * `object` with values transformed by `iteratee` and set by `setter`.
  2888. *
  2889. * @private
  2890. * @param {Object} object The object to iterate over.
  2891. * @param {Function} setter The function to set `accumulator` values.
  2892. * @param {Function} iteratee The iteratee to transform values.
  2893. * @param {Object} accumulator The initial inverted object.
  2894. * @returns {Function} Returns `accumulator`.
  2895. */
  2896. function baseInverter(object, setter, iteratee, accumulator) {
  2897. baseForOwn(object, function(value, key, object) {
  2898. setter(accumulator, iteratee(value), key, object);
  2899. });
  2900. return accumulator;
  2901. }
  2902. /**
  2903. * The base implementation of `_.invoke` without support for individual
  2904. * method arguments.
  2905. *
  2906. * @private
  2907. * @param {Object} object The object to query.
  2908. * @param {Array|string} path The path of the method to invoke.
  2909. * @param {Array} args The arguments to invoke the method with.
  2910. * @returns {*} Returns the result of the invoked method.
  2911. */
  2912. function baseInvoke(object, path, args) {
  2913. path = castPath(path, object);
  2914. object = parent(object, path);
  2915. var func = object == null ? object : object[toKey(last(path))];
  2916. return func == null ? undefined : apply(func, object, args);
  2917. }
  2918. /**
  2919. * The base implementation of `_.isArguments`.
  2920. *
  2921. * @private
  2922. * @param {*} value The value to check.
  2923. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2924. */
  2925. function baseIsArguments(value) {
  2926. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2927. }
  2928. /**
  2929. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2930. *
  2931. * @private
  2932. * @param {*} value The value to check.
  2933. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2934. */
  2935. function baseIsArrayBuffer(value) {
  2936. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2937. }
  2938. /**
  2939. * The base implementation of `_.isDate` without Node.js optimizations.
  2940. *
  2941. * @private
  2942. * @param {*} value The value to check.
  2943. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2944. */
  2945. function baseIsDate(value) {
  2946. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2947. }
  2948. /**
  2949. * The base implementation of `_.isEqual` which supports partial comparisons
  2950. * and tracks traversed objects.
  2951. *
  2952. * @private
  2953. * @param {*} value The value to compare.
  2954. * @param {*} other The other value to compare.
  2955. * @param {boolean} bitmask The bitmask flags.
  2956. * 1 - Unordered comparison
  2957. * 2 - Partial comparison
  2958. * @param {Function} [customizer] The function to customize comparisons.
  2959. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2960. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2961. */
  2962. function baseIsEqual(value, other, bitmask, customizer, stack) {
  2963. if (value === other) {
  2964. return true;
  2965. }
  2966. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  2967. return value !== value && other !== other;
  2968. }
  2969. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  2970. }
  2971. /**
  2972. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2973. * deep comparisons and tracks traversed objects enabling objects with circular
  2974. * references to be compared.
  2975. *
  2976. * @private
  2977. * @param {Object} object The object to compare.
  2978. * @param {Object} other The other object to compare.
  2979. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  2980. * @param {Function} customizer The function to customize comparisons.
  2981. * @param {Function} equalFunc The function to determine equivalents of values.
  2982. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2983. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2984. */
  2985. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  2986. var objIsArr = isArray(object),
  2987. othIsArr = isArray(other),
  2988. objTag = objIsArr ? arrayTag : getTag(object),
  2989. othTag = othIsArr ? arrayTag : getTag(other);
  2990. objTag = objTag == argsTag ? objectTag : objTag;
  2991. othTag = othTag == argsTag ? objectTag : othTag;
  2992. var objIsObj = objTag == objectTag,
  2993. othIsObj = othTag == objectTag,
  2994. isSameTag = objTag == othTag;
  2995. if (isSameTag && isBuffer(object)) {
  2996. if (!isBuffer(other)) {
  2997. return false;
  2998. }
  2999. objIsArr = true;
  3000. objIsObj = false;
  3001. }
  3002. if (isSameTag && !objIsObj) {
  3003. stack || (stack = new Stack);
  3004. return (objIsArr || isTypedArray(object))
  3005. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3006. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3007. }
  3008. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3009. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3010. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3011. if (objIsWrapped || othIsWrapped) {
  3012. var objUnwrapped = objIsWrapped ? object.value() : object,
  3013. othUnwrapped = othIsWrapped ? other.value() : other;
  3014. stack || (stack = new Stack);
  3015. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3016. }
  3017. }
  3018. if (!isSameTag) {
  3019. return false;
  3020. }
  3021. stack || (stack = new Stack);
  3022. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3023. }
  3024. /**
  3025. * The base implementation of `_.isMap` without Node.js optimizations.
  3026. *
  3027. * @private
  3028. * @param {*} value The value to check.
  3029. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3030. */
  3031. function baseIsMap(value) {
  3032. return isObjectLike(value) && getTag(value) == mapTag;
  3033. }
  3034. /**
  3035. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3036. *
  3037. * @private
  3038. * @param {Object} object The object to inspect.
  3039. * @param {Object} source The object of property values to match.
  3040. * @param {Array} matchData The property names, values, and compare flags to match.
  3041. * @param {Function} [customizer] The function to customize comparisons.
  3042. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3043. */
  3044. function baseIsMatch(object, source, matchData, customizer) {
  3045. var index = matchData.length,
  3046. length = index,
  3047. noCustomizer = !customizer;
  3048. if (object == null) {
  3049. return !length;
  3050. }
  3051. object = Object(object);
  3052. while (index--) {
  3053. var data = matchData[index];
  3054. if ((noCustomizer && data[2])
  3055. ? data[1] !== object[data[0]]
  3056. : !(data[0] in object)
  3057. ) {
  3058. return false;
  3059. }
  3060. }
  3061. while (++index < length) {
  3062. data = matchData[index];
  3063. var key = data[0],
  3064. objValue = object[key],
  3065. srcValue = data[1];
  3066. if (noCustomizer && data[2]) {
  3067. if (objValue === undefined && !(key in object)) {
  3068. return false;
  3069. }
  3070. } else {
  3071. var stack = new Stack;
  3072. if (customizer) {
  3073. var result = customizer(objValue, srcValue, key, object, source, stack);
  3074. }
  3075. if (!(result === undefined
  3076. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3077. : result
  3078. )) {
  3079. return false;
  3080. }
  3081. }
  3082. }
  3083. return true;
  3084. }
  3085. /**
  3086. * The base implementation of `_.isNative` without bad shim checks.
  3087. *
  3088. * @private
  3089. * @param {*} value The value to check.
  3090. * @returns {boolean} Returns `true` if `value` is a native function,
  3091. * else `false`.
  3092. */
  3093. function baseIsNative(value) {
  3094. if (!isObject(value) || isMasked(value)) {
  3095. return false;
  3096. }
  3097. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3098. return pattern.test(toSource(value));
  3099. }
  3100. /**
  3101. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3102. *
  3103. * @private
  3104. * @param {*} value The value to check.
  3105. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3106. */
  3107. function baseIsRegExp(value) {
  3108. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3109. }
  3110. /**
  3111. * The base implementation of `_.isSet` without Node.js optimizations.
  3112. *
  3113. * @private
  3114. * @param {*} value The value to check.
  3115. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3116. */
  3117. function baseIsSet(value) {
  3118. return isObjectLike(value) && getTag(value) == setTag;
  3119. }
  3120. /**
  3121. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3122. *
  3123. * @private
  3124. * @param {*} value The value to check.
  3125. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3126. */
  3127. function baseIsTypedArray(value) {
  3128. return isObjectLike(value) &&
  3129. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3130. }
  3131. /**
  3132. * The base implementation of `_.iteratee`.
  3133. *
  3134. * @private
  3135. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3136. * @returns {Function} Returns the iteratee.
  3137. */
  3138. function baseIteratee(value) {
  3139. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3140. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3141. if (typeof value == 'function') {
  3142. return value;
  3143. }
  3144. if (value == null) {
  3145. return identity;
  3146. }
  3147. if (typeof value == 'object') {
  3148. return isArray(value)
  3149. ? baseMatchesProperty(value[0], value[1])
  3150. : baseMatches(value);
  3151. }
  3152. return property(value);
  3153. }
  3154. /**
  3155. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3156. *
  3157. * @private
  3158. * @param {Object} object The object to query.
  3159. * @returns {Array} Returns the array of property names.
  3160. */
  3161. function baseKeys(object) {
  3162. if (!isPrototype(object)) {
  3163. return nativeKeys(object);
  3164. }
  3165. var result = [];
  3166. for (var key in Object(object)) {
  3167. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3168. result.push(key);
  3169. }
  3170. }
  3171. return result;
  3172. }
  3173. /**
  3174. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3175. *
  3176. * @private
  3177. * @param {Object} object The object to query.
  3178. * @returns {Array} Returns the array of property names.
  3179. */
  3180. function baseKeysIn(object) {
  3181. if (!isObject(object)) {
  3182. return nativeKeysIn(object);
  3183. }
  3184. var isProto = isPrototype(object),
  3185. result = [];
  3186. for (var key in object) {
  3187. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3188. result.push(key);
  3189. }
  3190. }
  3191. return result;
  3192. }
  3193. /**
  3194. * The base implementation of `_.lt` which doesn't coerce arguments.
  3195. *
  3196. * @private
  3197. * @param {*} value The value to compare.
  3198. * @param {*} other The other value to compare.
  3199. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3200. * else `false`.
  3201. */
  3202. function baseLt(value, other) {
  3203. return value < other;
  3204. }
  3205. /**
  3206. * The base implementation of `_.map` without support for iteratee shorthands.
  3207. *
  3208. * @private
  3209. * @param {Array|Object} collection The collection to iterate over.
  3210. * @param {Function} iteratee The function invoked per iteration.
  3211. * @returns {Array} Returns the new mapped array.
  3212. */
  3213. function baseMap(collection, iteratee) {
  3214. var index = -1,
  3215. result = isArrayLike(collection) ? Array(collection.length) : [];
  3216. baseEach(collection, function(value, key, collection) {
  3217. result[++index] = iteratee(value, key, collection);
  3218. });
  3219. return result;
  3220. }
  3221. /**
  3222. * The base implementation of `_.matches` which doesn't clone `source`.
  3223. *
  3224. * @private
  3225. * @param {Object} source The object of property values to match.
  3226. * @returns {Function} Returns the new spec function.
  3227. */
  3228. function baseMatches(source) {
  3229. var matchData = getMatchData(source);
  3230. if (matchData.length == 1 && matchData[0][2]) {
  3231. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3232. }
  3233. return function(object) {
  3234. return object === source || baseIsMatch(object, source, matchData);
  3235. };
  3236. }
  3237. /**
  3238. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3239. *
  3240. * @private
  3241. * @param {string} path The path of the property to get.
  3242. * @param {*} srcValue The value to match.
  3243. * @returns {Function} Returns the new spec function.
  3244. */
  3245. function baseMatchesProperty(path, srcValue) {
  3246. if (isKey(path) && isStrictComparable(srcValue)) {
  3247. return matchesStrictComparable(toKey(path), srcValue);
  3248. }
  3249. return function(object) {
  3250. var objValue = get(object, path);
  3251. return (objValue === undefined && objValue === srcValue)
  3252. ? hasIn(object, path)
  3253. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3254. };
  3255. }
  3256. /**
  3257. * The base implementation of `_.merge` without support for multiple sources.
  3258. *
  3259. * @private
  3260. * @param {Object} object The destination object.
  3261. * @param {Object} source The source object.
  3262. * @param {number} srcIndex The index of `source`.
  3263. * @param {Function} [customizer] The function to customize merged values.
  3264. * @param {Object} [stack] Tracks traversed source values and their merged
  3265. * counterparts.
  3266. */
  3267. function baseMerge(object, source, srcIndex, customizer, stack) {
  3268. if (object === source) {
  3269. return;
  3270. }
  3271. baseFor(source, function(srcValue, key) {
  3272. stack || (stack = new Stack);
  3273. if (isObject(srcValue)) {
  3274. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3275. }
  3276. else {
  3277. var newValue = customizer
  3278. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3279. : undefined;
  3280. if (newValue === undefined) {
  3281. newValue = srcValue;
  3282. }
  3283. assignMergeValue(object, key, newValue);
  3284. }
  3285. }, keysIn);
  3286. }
  3287. /**
  3288. * A specialized version of `baseMerge` for arrays and objects which performs
  3289. * deep merges and tracks traversed objects enabling objects with circular
  3290. * references to be merged.
  3291. *
  3292. * @private
  3293. * @param {Object} object The destination object.
  3294. * @param {Object} source The source object.
  3295. * @param {string} key The key of the value to merge.
  3296. * @param {number} srcIndex The index of `source`.
  3297. * @param {Function} mergeFunc The function to merge values.
  3298. * @param {Function} [customizer] The function to customize assigned values.
  3299. * @param {Object} [stack] Tracks traversed source values and their merged
  3300. * counterparts.
  3301. */
  3302. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3303. var objValue = safeGet(object, key),
  3304. srcValue = safeGet(source, key),
  3305. stacked = stack.get(srcValue);
  3306. if (stacked) {
  3307. assignMergeValue(object, key, stacked);
  3308. return;
  3309. }
  3310. var newValue = customizer
  3311. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3312. : undefined;
  3313. var isCommon = newValue === undefined;
  3314. if (isCommon) {
  3315. var isArr = isArray(srcValue),
  3316. isBuff = !isArr && isBuffer(srcValue),
  3317. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3318. newValue = srcValue;
  3319. if (isArr || isBuff || isTyped) {
  3320. if (isArray(objValue)) {
  3321. newValue = objValue;
  3322. }
  3323. else if (isArrayLikeObject(objValue)) {
  3324. newValue = copyArray(objValue);
  3325. }
  3326. else if (isBuff) {
  3327. isCommon = false;
  3328. newValue = cloneBuffer(srcValue, true);
  3329. }
  3330. else if (isTyped) {
  3331. isCommon = false;
  3332. newValue = cloneTypedArray(srcValue, true);
  3333. }
  3334. else {
  3335. newValue = [];
  3336. }
  3337. }
  3338. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3339. newValue = objValue;
  3340. if (isArguments(objValue)) {
  3341. newValue = toPlainObject(objValue);
  3342. }
  3343. else if (!isObject(objValue) || isFunction(objValue)) {
  3344. newValue = initCloneObject(srcValue);
  3345. }
  3346. }
  3347. else {
  3348. isCommon = false;
  3349. }
  3350. }
  3351. if (isCommon) {
  3352. // Recursively merge objects and arrays (susceptible to call stack limits).
  3353. stack.set(srcValue, newValue);
  3354. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3355. stack['delete'](srcValue);
  3356. }
  3357. assignMergeValue(object, key, newValue);
  3358. }
  3359. /**
  3360. * The base implementation of `_.nth` which doesn't coerce arguments.
  3361. *
  3362. * @private
  3363. * @param {Array} array The array to query.
  3364. * @param {number} n The index of the element to return.
  3365. * @returns {*} Returns the nth element of `array`.
  3366. */
  3367. function baseNth(array, n) {
  3368. var length = array.length;
  3369. if (!length) {
  3370. return;
  3371. }
  3372. n += n < 0 ? length : 0;
  3373. return isIndex(n, length) ? array[n] : undefined;
  3374. }
  3375. /**
  3376. * The base implementation of `_.orderBy` without param guards.
  3377. *
  3378. * @private
  3379. * @param {Array|Object} collection The collection to iterate over.
  3380. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3381. * @param {string[]} orders The sort orders of `iteratees`.
  3382. * @returns {Array} Returns the new sorted array.
  3383. */
  3384. function baseOrderBy(collection, iteratees, orders) {
  3385. var index = -1;
  3386. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3387. var result = baseMap(collection, function(value, key, collection) {
  3388. var criteria = arrayMap(iteratees, function(iteratee) {
  3389. return iteratee(value);
  3390. });
  3391. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3392. });
  3393. return baseSortBy(result, function(object, other) {
  3394. return compareMultiple(object, other, orders);
  3395. });
  3396. }
  3397. /**
  3398. * The base implementation of `_.pick` without support for individual
  3399. * property identifiers.
  3400. *
  3401. * @private
  3402. * @param {Object} object The source object.
  3403. * @param {string[]} paths The property paths to pick.
  3404. * @returns {Object} Returns the new object.
  3405. */
  3406. function basePick(object, paths) {
  3407. return basePickBy(object, paths, function(value, path) {
  3408. return hasIn(object, path);
  3409. });
  3410. }
  3411. /**
  3412. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3413. *
  3414. * @private
  3415. * @param {Object} object The source object.
  3416. * @param {string[]} paths The property paths to pick.
  3417. * @param {Function} predicate The function invoked per property.
  3418. * @returns {Object} Returns the new object.
  3419. */
  3420. function basePickBy(object, paths, predicate) {
  3421. var index = -1,
  3422. length = paths.length,
  3423. result = {};
  3424. while (++index < length) {
  3425. var path = paths[index],
  3426. value = baseGet(object, path);
  3427. if (predicate(value, path)) {
  3428. baseSet(result, castPath(path, object), value);
  3429. }
  3430. }
  3431. return result;
  3432. }
  3433. /**
  3434. * A specialized version of `baseProperty` which supports deep paths.
  3435. *
  3436. * @private
  3437. * @param {Array|string} path The path of the property to get.
  3438. * @returns {Function} Returns the new accessor function.
  3439. */
  3440. function basePropertyDeep(path) {
  3441. return function(object) {
  3442. return baseGet(object, path);
  3443. };
  3444. }
  3445. /**
  3446. * The base implementation of `_.pullAllBy` without support for iteratee
  3447. * shorthands.
  3448. *
  3449. * @private
  3450. * @param {Array} array The array to modify.
  3451. * @param {Array} values The values to remove.
  3452. * @param {Function} [iteratee] The iteratee invoked per element.
  3453. * @param {Function} [comparator] The comparator invoked per element.
  3454. * @returns {Array} Returns `array`.
  3455. */
  3456. function basePullAll(array, values, iteratee, comparator) {
  3457. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3458. index = -1,
  3459. length = values.length,
  3460. seen = array;
  3461. if (array === values) {
  3462. values = copyArray(values);
  3463. }
  3464. if (iteratee) {
  3465. seen = arrayMap(array, baseUnary(iteratee));
  3466. }
  3467. while (++index < length) {
  3468. var fromIndex = 0,
  3469. value = values[index],
  3470. computed = iteratee ? iteratee(value) : value;
  3471. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3472. if (seen !== array) {
  3473. splice.call(seen, fromIndex, 1);
  3474. }
  3475. splice.call(array, fromIndex, 1);
  3476. }
  3477. }
  3478. return array;
  3479. }
  3480. /**
  3481. * The base implementation of `_.pullAt` without support for individual
  3482. * indexes or capturing the removed elements.
  3483. *
  3484. * @private
  3485. * @param {Array} array The array to modify.
  3486. * @param {number[]} indexes The indexes of elements to remove.
  3487. * @returns {Array} Returns `array`.
  3488. */
  3489. function basePullAt(array, indexes) {
  3490. var length = array ? indexes.length : 0,
  3491. lastIndex = length - 1;
  3492. while (length--) {
  3493. var index = indexes[length];
  3494. if (length == lastIndex || index !== previous) {
  3495. var previous = index;
  3496. if (isIndex(index)) {
  3497. splice.call(array, index, 1);
  3498. } else {
  3499. baseUnset(array, index);
  3500. }
  3501. }
  3502. }
  3503. return array;
  3504. }
  3505. /**
  3506. * The base implementation of `_.random` without support for returning
  3507. * floating-point numbers.
  3508. *
  3509. * @private
  3510. * @param {number} lower The lower bound.
  3511. * @param {number} upper The upper bound.
  3512. * @returns {number} Returns the random number.
  3513. */
  3514. function baseRandom(lower, upper) {
  3515. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3516. }
  3517. /**
  3518. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3519. * coerce arguments.
  3520. *
  3521. * @private
  3522. * @param {number} start The start of the range.
  3523. * @param {number} end The end of the range.
  3524. * @param {number} step The value to increment or decrement by.
  3525. * @param {boolean} [fromRight] Specify iterating from right to left.
  3526. * @returns {Array} Returns the range of numbers.
  3527. */
  3528. function baseRange(start, end, step, fromRight) {
  3529. var index = -1,
  3530. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3531. result = Array(length);
  3532. while (length--) {
  3533. result[fromRight ? length : ++index] = start;
  3534. start += step;
  3535. }
  3536. return result;
  3537. }
  3538. /**
  3539. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3540. *
  3541. * @private
  3542. * @param {string} string The string to repeat.
  3543. * @param {number} n The number of times to repeat the string.
  3544. * @returns {string} Returns the repeated string.
  3545. */
  3546. function baseRepeat(string, n) {
  3547. var result = '';
  3548. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3549. return result;
  3550. }
  3551. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3552. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3553. do {
  3554. if (n % 2) {
  3555. result += string;
  3556. }
  3557. n = nativeFloor(n / 2);
  3558. if (n) {
  3559. string += string;
  3560. }
  3561. } while (n);
  3562. return result;
  3563. }
  3564. /**
  3565. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3566. *
  3567. * @private
  3568. * @param {Function} func The function to apply a rest parameter to.
  3569. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3570. * @returns {Function} Returns the new function.
  3571. */
  3572. function baseRest(func, start) {
  3573. return setToString(overRest(func, start, identity), func + '');
  3574. }
  3575. /**
  3576. * The base implementation of `_.sample`.
  3577. *
  3578. * @private
  3579. * @param {Array|Object} collection The collection to sample.
  3580. * @returns {*} Returns the random element.
  3581. */
  3582. function baseSample(collection) {
  3583. return arraySample(values(collection));
  3584. }
  3585. /**
  3586. * The base implementation of `_.sampleSize` without param guards.
  3587. *
  3588. * @private
  3589. * @param {Array|Object} collection The collection to sample.
  3590. * @param {number} n The number of elements to sample.
  3591. * @returns {Array} Returns the random elements.
  3592. */
  3593. function baseSampleSize(collection, n) {
  3594. var array = values(collection);
  3595. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3596. }
  3597. /**
  3598. * The base implementation of `_.set`.
  3599. *
  3600. * @private
  3601. * @param {Object} object The object to modify.
  3602. * @param {Array|string} path The path of the property to set.
  3603. * @param {*} value The value to set.
  3604. * @param {Function} [customizer] The function to customize path creation.
  3605. * @returns {Object} Returns `object`.
  3606. */
  3607. function baseSet(object, path, value, customizer) {
  3608. if (!isObject(object)) {
  3609. return object;
  3610. }
  3611. path = castPath(path, object);
  3612. var index = -1,
  3613. length = path.length,
  3614. lastIndex = length - 1,
  3615. nested = object;
  3616. while (nested != null && ++index < length) {
  3617. var key = toKey(path[index]),
  3618. newValue = value;
  3619. if (index != lastIndex) {
  3620. var objValue = nested[key];
  3621. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3622. if (newValue === undefined) {
  3623. newValue = isObject(objValue)
  3624. ? objValue
  3625. : (isIndex(path[index + 1]) ? [] : {});
  3626. }
  3627. }
  3628. assignValue(nested, key, newValue);
  3629. nested = nested[key];
  3630. }
  3631. return object;
  3632. }
  3633. /**
  3634. * The base implementation of `setData` without support for hot loop shorting.
  3635. *
  3636. * @private
  3637. * @param {Function} func The function to associate metadata with.
  3638. * @param {*} data The metadata.
  3639. * @returns {Function} Returns `func`.
  3640. */
  3641. var baseSetData = !metaMap ? identity : function(func, data) {
  3642. metaMap.set(func, data);
  3643. return func;
  3644. };
  3645. /**
  3646. * The base implementation of `setToString` without support for hot loop shorting.
  3647. *
  3648. * @private
  3649. * @param {Function} func The function to modify.
  3650. * @param {Function} string The `toString` result.
  3651. * @returns {Function} Returns `func`.
  3652. */
  3653. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3654. return defineProperty(func, 'toString', {
  3655. 'configurable': true,
  3656. 'enumerable': false,
  3657. 'value': constant(string),
  3658. 'writable': true
  3659. });
  3660. };
  3661. /**
  3662. * The base implementation of `_.shuffle`.
  3663. *
  3664. * @private
  3665. * @param {Array|Object} collection The collection to shuffle.
  3666. * @returns {Array} Returns the new shuffled array.
  3667. */
  3668. function baseShuffle(collection) {
  3669. return shuffleSelf(values(collection));
  3670. }
  3671. /**
  3672. * The base implementation of `_.slice` without an iteratee call guard.
  3673. *
  3674. * @private
  3675. * @param {Array} array The array to slice.
  3676. * @param {number} [start=0] The start position.
  3677. * @param {number} [end=array.length] The end position.
  3678. * @returns {Array} Returns the slice of `array`.
  3679. */
  3680. function baseSlice(array, start, end) {
  3681. var index = -1,
  3682. length = array.length;
  3683. if (start < 0) {
  3684. start = -start > length ? 0 : (length + start);
  3685. }
  3686. end = end > length ? length : end;
  3687. if (end < 0) {
  3688. end += length;
  3689. }
  3690. length = start > end ? 0 : ((end - start) >>> 0);
  3691. start >>>= 0;
  3692. var result = Array(length);
  3693. while (++index < length) {
  3694. result[index] = array[index + start];
  3695. }
  3696. return result;
  3697. }
  3698. /**
  3699. * The base implementation of `_.some` without support for iteratee shorthands.
  3700. *
  3701. * @private
  3702. * @param {Array|Object} collection The collection to iterate over.
  3703. * @param {Function} predicate The function invoked per iteration.
  3704. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3705. * else `false`.
  3706. */
  3707. function baseSome(collection, predicate) {
  3708. var result;
  3709. baseEach(collection, function(value, index, collection) {
  3710. result = predicate(value, index, collection);
  3711. return !result;
  3712. });
  3713. return !!result;
  3714. }
  3715. /**
  3716. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3717. * performs a binary search of `array` to determine the index at which `value`
  3718. * should be inserted into `array` in order to maintain its sort order.
  3719. *
  3720. * @private
  3721. * @param {Array} array The sorted array to inspect.
  3722. * @param {*} value The value to evaluate.
  3723. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3724. * @returns {number} Returns the index at which `value` should be inserted
  3725. * into `array`.
  3726. */
  3727. function baseSortedIndex(array, value, retHighest) {
  3728. var low = 0,
  3729. high = array == null ? low : array.length;
  3730. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3731. while (low < high) {
  3732. var mid = (low + high) >>> 1,
  3733. computed = array[mid];
  3734. if (computed !== null && !isSymbol(computed) &&
  3735. (retHighest ? (computed <= value) : (computed < value))) {
  3736. low = mid + 1;
  3737. } else {
  3738. high = mid;
  3739. }
  3740. }
  3741. return high;
  3742. }
  3743. return baseSortedIndexBy(array, value, identity, retHighest);
  3744. }
  3745. /**
  3746. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3747. * which invokes `iteratee` for `value` and each element of `array` to compute
  3748. * their sort ranking. The iteratee is invoked with one argument; (value).
  3749. *
  3750. * @private
  3751. * @param {Array} array The sorted array to inspect.
  3752. * @param {*} value The value to evaluate.
  3753. * @param {Function} iteratee The iteratee invoked per element.
  3754. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3755. * @returns {number} Returns the index at which `value` should be inserted
  3756. * into `array`.
  3757. */
  3758. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3759. value = iteratee(value);
  3760. var low = 0,
  3761. high = array == null ? 0 : array.length,
  3762. valIsNaN = value !== value,
  3763. valIsNull = value === null,
  3764. valIsSymbol = isSymbol(value),
  3765. valIsUndefined = value === undefined;
  3766. while (low < high) {
  3767. var mid = nativeFloor((low + high) / 2),
  3768. computed = iteratee(array[mid]),
  3769. othIsDefined = computed !== undefined,
  3770. othIsNull = computed === null,
  3771. othIsReflexive = computed === computed,
  3772. othIsSymbol = isSymbol(computed);
  3773. if (valIsNaN) {
  3774. var setLow = retHighest || othIsReflexive;
  3775. } else if (valIsUndefined) {
  3776. setLow = othIsReflexive && (retHighest || othIsDefined);
  3777. } else if (valIsNull) {
  3778. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3779. } else if (valIsSymbol) {
  3780. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3781. } else if (othIsNull || othIsSymbol) {
  3782. setLow = false;
  3783. } else {
  3784. setLow = retHighest ? (computed <= value) : (computed < value);
  3785. }
  3786. if (setLow) {
  3787. low = mid + 1;
  3788. } else {
  3789. high = mid;
  3790. }
  3791. }
  3792. return nativeMin(high, MAX_ARRAY_INDEX);
  3793. }
  3794. /**
  3795. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3796. * support for iteratee shorthands.
  3797. *
  3798. * @private
  3799. * @param {Array} array The array to inspect.
  3800. * @param {Function} [iteratee] The iteratee invoked per element.
  3801. * @returns {Array} Returns the new duplicate free array.
  3802. */
  3803. function baseSortedUniq(array, iteratee) {
  3804. var index = -1,
  3805. length = array.length,
  3806. resIndex = 0,
  3807. result = [];
  3808. while (++index < length) {
  3809. var value = array[index],
  3810. computed = iteratee ? iteratee(value) : value;
  3811. if (!index || !eq(computed, seen)) {
  3812. var seen = computed;
  3813. result[resIndex++] = value === 0 ? 0 : value;
  3814. }
  3815. }
  3816. return result;
  3817. }
  3818. /**
  3819. * The base implementation of `_.toNumber` which doesn't ensure correct
  3820. * conversions of binary, hexadecimal, or octal string values.
  3821. *
  3822. * @private
  3823. * @param {*} value The value to process.
  3824. * @returns {number} Returns the number.
  3825. */
  3826. function baseToNumber(value) {
  3827. if (typeof value == 'number') {
  3828. return value;
  3829. }
  3830. if (isSymbol(value)) {
  3831. return NAN;
  3832. }
  3833. return +value;
  3834. }
  3835. /**
  3836. * The base implementation of `_.toString` which doesn't convert nullish
  3837. * values to empty strings.
  3838. *
  3839. * @private
  3840. * @param {*} value The value to process.
  3841. * @returns {string} Returns the string.
  3842. */
  3843. function baseToString(value) {
  3844. // Exit early for strings to avoid a performance hit in some environments.
  3845. if (typeof value == 'string') {
  3846. return value;
  3847. }
  3848. if (isArray(value)) {
  3849. // Recursively convert values (susceptible to call stack limits).
  3850. return arrayMap(value, baseToString) + '';
  3851. }
  3852. if (isSymbol(value)) {
  3853. return symbolToString ? symbolToString.call(value) : '';
  3854. }
  3855. var result = (value + '');
  3856. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3857. }
  3858. /**
  3859. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3860. *
  3861. * @private
  3862. * @param {Array} array The array to inspect.
  3863. * @param {Function} [iteratee] The iteratee invoked per element.
  3864. * @param {Function} [comparator] The comparator invoked per element.
  3865. * @returns {Array} Returns the new duplicate free array.
  3866. */
  3867. function baseUniq(array, iteratee, comparator) {
  3868. var index = -1,
  3869. includes = arrayIncludes,
  3870. length = array.length,
  3871. isCommon = true,
  3872. result = [],
  3873. seen = result;
  3874. if (comparator) {
  3875. isCommon = false;
  3876. includes = arrayIncludesWith;
  3877. }
  3878. else if (length >= LARGE_ARRAY_SIZE) {
  3879. var set = iteratee ? null : createSet(array);
  3880. if (set) {
  3881. return setToArray(set);
  3882. }
  3883. isCommon = false;
  3884. includes = cacheHas;
  3885. seen = new SetCache;
  3886. }
  3887. else {
  3888. seen = iteratee ? [] : result;
  3889. }
  3890. outer:
  3891. while (++index < length) {
  3892. var value = array[index],
  3893. computed = iteratee ? iteratee(value) : value;
  3894. value = (comparator || value !== 0) ? value : 0;
  3895. if (isCommon && computed === computed) {
  3896. var seenIndex = seen.length;
  3897. while (seenIndex--) {
  3898. if (seen[seenIndex] === computed) {
  3899. continue outer;
  3900. }
  3901. }
  3902. if (iteratee) {
  3903. seen.push(computed);
  3904. }
  3905. result.push(value);
  3906. }
  3907. else if (!includes(seen, computed, comparator)) {
  3908. if (seen !== result) {
  3909. seen.push(computed);
  3910. }
  3911. result.push(value);
  3912. }
  3913. }
  3914. return result;
  3915. }
  3916. /**
  3917. * The base implementation of `_.unset`.
  3918. *
  3919. * @private
  3920. * @param {Object} object The object to modify.
  3921. * @param {Array|string} path The property path to unset.
  3922. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3923. */
  3924. function baseUnset(object, path) {
  3925. path = castPath(path, object);
  3926. object = parent(object, path);
  3927. return object == null || delete object[toKey(last(path))];
  3928. }
  3929. /**
  3930. * The base implementation of `_.update`.
  3931. *
  3932. * @private
  3933. * @param {Object} object The object to modify.
  3934. * @param {Array|string} path The path of the property to update.
  3935. * @param {Function} updater The function to produce the updated value.
  3936. * @param {Function} [customizer] The function to customize path creation.
  3937. * @returns {Object} Returns `object`.
  3938. */
  3939. function baseUpdate(object, path, updater, customizer) {
  3940. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3941. }
  3942. /**
  3943. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3944. * without support for iteratee shorthands.
  3945. *
  3946. * @private
  3947. * @param {Array} array The array to query.
  3948. * @param {Function} predicate The function invoked per iteration.
  3949. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3950. * @param {boolean} [fromRight] Specify iterating from right to left.
  3951. * @returns {Array} Returns the slice of `array`.
  3952. */
  3953. function baseWhile(array, predicate, isDrop, fromRight) {
  3954. var length = array.length,
  3955. index = fromRight ? length : -1;
  3956. while ((fromRight ? index-- : ++index < length) &&
  3957. predicate(array[index], index, array)) {}
  3958. return isDrop
  3959. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3960. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3961. }
  3962. /**
  3963. * The base implementation of `wrapperValue` which returns the result of
  3964. * performing a sequence of actions on the unwrapped `value`, where each
  3965. * successive action is supplied the return value of the previous.
  3966. *
  3967. * @private
  3968. * @param {*} value The unwrapped value.
  3969. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3970. * @returns {*} Returns the resolved value.
  3971. */
  3972. function baseWrapperValue(value, actions) {
  3973. var result = value;
  3974. if (result instanceof LazyWrapper) {
  3975. result = result.value();
  3976. }
  3977. return arrayReduce(actions, function(result, action) {
  3978. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3979. }, result);
  3980. }
  3981. /**
  3982. * The base implementation of methods like `_.xor`, without support for
  3983. * iteratee shorthands, that accepts an array of arrays to inspect.
  3984. *
  3985. * @private
  3986. * @param {Array} arrays The arrays to inspect.
  3987. * @param {Function} [iteratee] The iteratee invoked per element.
  3988. * @param {Function} [comparator] The comparator invoked per element.
  3989. * @returns {Array} Returns the new array of values.
  3990. */
  3991. function baseXor(arrays, iteratee, comparator) {
  3992. var length = arrays.length;
  3993. if (length < 2) {
  3994. return length ? baseUniq(arrays[0]) : [];
  3995. }
  3996. var index = -1,
  3997. result = Array(length);
  3998. while (++index < length) {
  3999. var array = arrays[index],
  4000. othIndex = -1;
  4001. while (++othIndex < length) {
  4002. if (othIndex != index) {
  4003. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4004. }
  4005. }
  4006. }
  4007. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4008. }
  4009. /**
  4010. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4011. *
  4012. * @private
  4013. * @param {Array} props The property identifiers.
  4014. * @param {Array} values The property values.
  4015. * @param {Function} assignFunc The function to assign values.
  4016. * @returns {Object} Returns the new object.
  4017. */
  4018. function baseZipObject(props, values, assignFunc) {
  4019. var index = -1,
  4020. length = props.length,
  4021. valsLength = values.length,
  4022. result = {};
  4023. while (++index < length) {
  4024. var value = index < valsLength ? values[index] : undefined;
  4025. assignFunc(result, props[index], value);
  4026. }
  4027. return result;
  4028. }
  4029. /**
  4030. * Casts `value` to an empty array if it's not an array like object.
  4031. *
  4032. * @private
  4033. * @param {*} value The value to inspect.
  4034. * @returns {Array|Object} Returns the cast array-like object.
  4035. */
  4036. function castArrayLikeObject(value) {
  4037. return isArrayLikeObject(value) ? value : [];
  4038. }
  4039. /**
  4040. * Casts `value` to `identity` if it's not a function.
  4041. *
  4042. * @private
  4043. * @param {*} value The value to inspect.
  4044. * @returns {Function} Returns cast function.
  4045. */
  4046. function castFunction(value) {
  4047. return typeof value == 'function' ? value : identity;
  4048. }
  4049. /**
  4050. * Casts `value` to a path array if it's not one.
  4051. *
  4052. * @private
  4053. * @param {*} value The value to inspect.
  4054. * @param {Object} [object] The object to query keys on.
  4055. * @returns {Array} Returns the cast property path array.
  4056. */
  4057. function castPath(value, object) {
  4058. if (isArray(value)) {
  4059. return value;
  4060. }
  4061. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4062. }
  4063. /**
  4064. * A `baseRest` alias which can be replaced with `identity` by module
  4065. * replacement plugins.
  4066. *
  4067. * @private
  4068. * @type {Function}
  4069. * @param {Function} func The function to apply a rest parameter to.
  4070. * @returns {Function} Returns the new function.
  4071. */
  4072. var castRest = baseRest;
  4073. /**
  4074. * Casts `array` to a slice if it's needed.
  4075. *
  4076. * @private
  4077. * @param {Array} array The array to inspect.
  4078. * @param {number} start The start position.
  4079. * @param {number} [end=array.length] The end position.
  4080. * @returns {Array} Returns the cast slice.
  4081. */
  4082. function castSlice(array, start, end) {
  4083. var length = array.length;
  4084. end = end === undefined ? length : end;
  4085. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4086. }
  4087. /**
  4088. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4089. *
  4090. * @private
  4091. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4092. */
  4093. var clearTimeout = ctxClearTimeout || function(id) {
  4094. return root.clearTimeout(id);
  4095. };
  4096. /**
  4097. * Creates a clone of `buffer`.
  4098. *
  4099. * @private
  4100. * @param {Buffer} buffer The buffer to clone.
  4101. * @param {boolean} [isDeep] Specify a deep clone.
  4102. * @returns {Buffer} Returns the cloned buffer.
  4103. */
  4104. function cloneBuffer(buffer, isDeep) {
  4105. if (isDeep) {
  4106. return buffer.slice();
  4107. }
  4108. var length = buffer.length,
  4109. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4110. buffer.copy(result);
  4111. return result;
  4112. }
  4113. /**
  4114. * Creates a clone of `arrayBuffer`.
  4115. *
  4116. * @private
  4117. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4118. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4119. */
  4120. function cloneArrayBuffer(arrayBuffer) {
  4121. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4122. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4123. return result;
  4124. }
  4125. /**
  4126. * Creates a clone of `dataView`.
  4127. *
  4128. * @private
  4129. * @param {Object} dataView The data view to clone.
  4130. * @param {boolean} [isDeep] Specify a deep clone.
  4131. * @returns {Object} Returns the cloned data view.
  4132. */
  4133. function cloneDataView(dataView, isDeep) {
  4134. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4135. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4136. }
  4137. /**
  4138. * Creates a clone of `regexp`.
  4139. *
  4140. * @private
  4141. * @param {Object} regexp The regexp to clone.
  4142. * @returns {Object} Returns the cloned regexp.
  4143. */
  4144. function cloneRegExp(regexp) {
  4145. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4146. result.lastIndex = regexp.lastIndex;
  4147. return result;
  4148. }
  4149. /**
  4150. * Creates a clone of the `symbol` object.
  4151. *
  4152. * @private
  4153. * @param {Object} symbol The symbol object to clone.
  4154. * @returns {Object} Returns the cloned symbol object.
  4155. */
  4156. function cloneSymbol(symbol) {
  4157. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4158. }
  4159. /**
  4160. * Creates a clone of `typedArray`.
  4161. *
  4162. * @private
  4163. * @param {Object} typedArray The typed array to clone.
  4164. * @param {boolean} [isDeep] Specify a deep clone.
  4165. * @returns {Object} Returns the cloned typed array.
  4166. */
  4167. function cloneTypedArray(typedArray, isDeep) {
  4168. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4169. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4170. }
  4171. /**
  4172. * Compares values to sort them in ascending order.
  4173. *
  4174. * @private
  4175. * @param {*} value The value to compare.
  4176. * @param {*} other The other value to compare.
  4177. * @returns {number} Returns the sort order indicator for `value`.
  4178. */
  4179. function compareAscending(value, other) {
  4180. if (value !== other) {
  4181. var valIsDefined = value !== undefined,
  4182. valIsNull = value === null,
  4183. valIsReflexive = value === value,
  4184. valIsSymbol = isSymbol(value);
  4185. var othIsDefined = other !== undefined,
  4186. othIsNull = other === null,
  4187. othIsReflexive = other === other,
  4188. othIsSymbol = isSymbol(other);
  4189. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4190. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4191. (valIsNull && othIsDefined && othIsReflexive) ||
  4192. (!valIsDefined && othIsReflexive) ||
  4193. !valIsReflexive) {
  4194. return 1;
  4195. }
  4196. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4197. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4198. (othIsNull && valIsDefined && valIsReflexive) ||
  4199. (!othIsDefined && valIsReflexive) ||
  4200. !othIsReflexive) {
  4201. return -1;
  4202. }
  4203. }
  4204. return 0;
  4205. }
  4206. /**
  4207. * Used by `_.orderBy` to compare multiple properties of a value to another
  4208. * and stable sort them.
  4209. *
  4210. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4211. * specify an order of "desc" for descending or "asc" for ascending sort order
  4212. * of corresponding values.
  4213. *
  4214. * @private
  4215. * @param {Object} object The object to compare.
  4216. * @param {Object} other The other object to compare.
  4217. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4218. * @returns {number} Returns the sort order indicator for `object`.
  4219. */
  4220. function compareMultiple(object, other, orders) {
  4221. var index = -1,
  4222. objCriteria = object.criteria,
  4223. othCriteria = other.criteria,
  4224. length = objCriteria.length,
  4225. ordersLength = orders.length;
  4226. while (++index < length) {
  4227. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4228. if (result) {
  4229. if (index >= ordersLength) {
  4230. return result;
  4231. }
  4232. var order = orders[index];
  4233. return result * (order == 'desc' ? -1 : 1);
  4234. }
  4235. }
  4236. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4237. // that causes it, under certain circumstances, to provide the same value for
  4238. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4239. // for more details.
  4240. //
  4241. // This also ensures a stable sort in V8 and other engines.
  4242. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4243. return object.index - other.index;
  4244. }
  4245. /**
  4246. * Creates an array that is the composition of partially applied arguments,
  4247. * placeholders, and provided arguments into a single array of arguments.
  4248. *
  4249. * @private
  4250. * @param {Array} args The provided arguments.
  4251. * @param {Array} partials The arguments to prepend to those provided.
  4252. * @param {Array} holders The `partials` placeholder indexes.
  4253. * @params {boolean} [isCurried] Specify composing for a curried function.
  4254. * @returns {Array} Returns the new array of composed arguments.
  4255. */
  4256. function composeArgs(args, partials, holders, isCurried) {
  4257. var argsIndex = -1,
  4258. argsLength = args.length,
  4259. holdersLength = holders.length,
  4260. leftIndex = -1,
  4261. leftLength = partials.length,
  4262. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4263. result = Array(leftLength + rangeLength),
  4264. isUncurried = !isCurried;
  4265. while (++leftIndex < leftLength) {
  4266. result[leftIndex] = partials[leftIndex];
  4267. }
  4268. while (++argsIndex < holdersLength) {
  4269. if (isUncurried || argsIndex < argsLength) {
  4270. result[holders[argsIndex]] = args[argsIndex];
  4271. }
  4272. }
  4273. while (rangeLength--) {
  4274. result[leftIndex++] = args[argsIndex++];
  4275. }
  4276. return result;
  4277. }
  4278. /**
  4279. * This function is like `composeArgs` except that the arguments composition
  4280. * is tailored for `_.partialRight`.
  4281. *
  4282. * @private
  4283. * @param {Array} args The provided arguments.
  4284. * @param {Array} partials The arguments to append to those provided.
  4285. * @param {Array} holders The `partials` placeholder indexes.
  4286. * @params {boolean} [isCurried] Specify composing for a curried function.
  4287. * @returns {Array} Returns the new array of composed arguments.
  4288. */
  4289. function composeArgsRight(args, partials, holders, isCurried) {
  4290. var argsIndex = -1,
  4291. argsLength = args.length,
  4292. holdersIndex = -1,
  4293. holdersLength = holders.length,
  4294. rightIndex = -1,
  4295. rightLength = partials.length,
  4296. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4297. result = Array(rangeLength + rightLength),
  4298. isUncurried = !isCurried;
  4299. while (++argsIndex < rangeLength) {
  4300. result[argsIndex] = args[argsIndex];
  4301. }
  4302. var offset = argsIndex;
  4303. while (++rightIndex < rightLength) {
  4304. result[offset + rightIndex] = partials[rightIndex];
  4305. }
  4306. while (++holdersIndex < holdersLength) {
  4307. if (isUncurried || argsIndex < argsLength) {
  4308. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4309. }
  4310. }
  4311. return result;
  4312. }
  4313. /**
  4314. * Copies the values of `source` to `array`.
  4315. *
  4316. * @private
  4317. * @param {Array} source The array to copy values from.
  4318. * @param {Array} [array=[]] The array to copy values to.
  4319. * @returns {Array} Returns `array`.
  4320. */
  4321. function copyArray(source, array) {
  4322. var index = -1,
  4323. length = source.length;
  4324. array || (array = Array(length));
  4325. while (++index < length) {
  4326. array[index] = source[index];
  4327. }
  4328. return array;
  4329. }
  4330. /**
  4331. * Copies properties of `source` to `object`.
  4332. *
  4333. * @private
  4334. * @param {Object} source The object to copy properties from.
  4335. * @param {Array} props The property identifiers to copy.
  4336. * @param {Object} [object={}] The object to copy properties to.
  4337. * @param {Function} [customizer] The function to customize copied values.
  4338. * @returns {Object} Returns `object`.
  4339. */
  4340. function copyObject(source, props, object, customizer) {
  4341. var isNew = !object;
  4342. object || (object = {});
  4343. var index = -1,
  4344. length = props.length;
  4345. while (++index < length) {
  4346. var key = props[index];
  4347. var newValue = customizer
  4348. ? customizer(object[key], source[key], key, object, source)
  4349. : undefined;
  4350. if (newValue === undefined) {
  4351. newValue = source[key];
  4352. }
  4353. if (isNew) {
  4354. baseAssignValue(object, key, newValue);
  4355. } else {
  4356. assignValue(object, key, newValue);
  4357. }
  4358. }
  4359. return object;
  4360. }
  4361. /**
  4362. * Copies own symbols of `source` to `object`.
  4363. *
  4364. * @private
  4365. * @param {Object} source The object to copy symbols from.
  4366. * @param {Object} [object={}] The object to copy symbols to.
  4367. * @returns {Object} Returns `object`.
  4368. */
  4369. function copySymbols(source, object) {
  4370. return copyObject(source, getSymbols(source), object);
  4371. }
  4372. /**
  4373. * Copies own and inherited symbols of `source` to `object`.
  4374. *
  4375. * @private
  4376. * @param {Object} source The object to copy symbols from.
  4377. * @param {Object} [object={}] The object to copy symbols to.
  4378. * @returns {Object} Returns `object`.
  4379. */
  4380. function copySymbolsIn(source, object) {
  4381. return copyObject(source, getSymbolsIn(source), object);
  4382. }
  4383. /**
  4384. * Creates a function like `_.groupBy`.
  4385. *
  4386. * @private
  4387. * @param {Function} setter The function to set accumulator values.
  4388. * @param {Function} [initializer] The accumulator object initializer.
  4389. * @returns {Function} Returns the new aggregator function.
  4390. */
  4391. function createAggregator(setter, initializer) {
  4392. return function(collection, iteratee) {
  4393. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4394. accumulator = initializer ? initializer() : {};
  4395. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4396. };
  4397. }
  4398. /**
  4399. * Creates a function like `_.assign`.
  4400. *
  4401. * @private
  4402. * @param {Function} assigner The function to assign values.
  4403. * @returns {Function} Returns the new assigner function.
  4404. */
  4405. function createAssigner(assigner) {
  4406. return baseRest(function(object, sources) {
  4407. var index = -1,
  4408. length = sources.length,
  4409. customizer = length > 1 ? sources[length - 1] : undefined,
  4410. guard = length > 2 ? sources[2] : undefined;
  4411. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4412. ? (length--, customizer)
  4413. : undefined;
  4414. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4415. customizer = length < 3 ? undefined : customizer;
  4416. length = 1;
  4417. }
  4418. object = Object(object);
  4419. while (++index < length) {
  4420. var source = sources[index];
  4421. if (source) {
  4422. assigner(object, source, index, customizer);
  4423. }
  4424. }
  4425. return object;
  4426. });
  4427. }
  4428. /**
  4429. * Creates a `baseEach` or `baseEachRight` function.
  4430. *
  4431. * @private
  4432. * @param {Function} eachFunc The function to iterate over a collection.
  4433. * @param {boolean} [fromRight] Specify iterating from right to left.
  4434. * @returns {Function} Returns the new base function.
  4435. */
  4436. function createBaseEach(eachFunc, fromRight) {
  4437. return function(collection, iteratee) {
  4438. if (collection == null) {
  4439. return collection;
  4440. }
  4441. if (!isArrayLike(collection)) {
  4442. return eachFunc(collection, iteratee);
  4443. }
  4444. var length = collection.length,
  4445. index = fromRight ? length : -1,
  4446. iterable = Object(collection);
  4447. while ((fromRight ? index-- : ++index < length)) {
  4448. if (iteratee(iterable[index], index, iterable) === false) {
  4449. break;
  4450. }
  4451. }
  4452. return collection;
  4453. };
  4454. }
  4455. /**
  4456. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4457. *
  4458. * @private
  4459. * @param {boolean} [fromRight] Specify iterating from right to left.
  4460. * @returns {Function} Returns the new base function.
  4461. */
  4462. function createBaseFor(fromRight) {
  4463. return function(object, iteratee, keysFunc) {
  4464. var index = -1,
  4465. iterable = Object(object),
  4466. props = keysFunc(object),
  4467. length = props.length;
  4468. while (length--) {
  4469. var key = props[fromRight ? length : ++index];
  4470. if (iteratee(iterable[key], key, iterable) === false) {
  4471. break;
  4472. }
  4473. }
  4474. return object;
  4475. };
  4476. }
  4477. /**
  4478. * Creates a function that wraps `func` to invoke it with the optional `this`
  4479. * binding of `thisArg`.
  4480. *
  4481. * @private
  4482. * @param {Function} func The function to wrap.
  4483. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4484. * @param {*} [thisArg] The `this` binding of `func`.
  4485. * @returns {Function} Returns the new wrapped function.
  4486. */
  4487. function createBind(func, bitmask, thisArg) {
  4488. var isBind = bitmask & WRAP_BIND_FLAG,
  4489. Ctor = createCtor(func);
  4490. function wrapper() {
  4491. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4492. return fn.apply(isBind ? thisArg : this, arguments);
  4493. }
  4494. return wrapper;
  4495. }
  4496. /**
  4497. * Creates a function like `_.lowerFirst`.
  4498. *
  4499. * @private
  4500. * @param {string} methodName The name of the `String` case method to use.
  4501. * @returns {Function} Returns the new case function.
  4502. */
  4503. function createCaseFirst(methodName) {
  4504. return function(string) {
  4505. string = toString(string);
  4506. var strSymbols = hasUnicode(string)
  4507. ? stringToArray(string)
  4508. : undefined;
  4509. var chr = strSymbols
  4510. ? strSymbols[0]
  4511. : string.charAt(0);
  4512. var trailing = strSymbols
  4513. ? castSlice(strSymbols, 1).join('')
  4514. : string.slice(1);
  4515. return chr[methodName]() + trailing;
  4516. };
  4517. }
  4518. /**
  4519. * Creates a function like `_.camelCase`.
  4520. *
  4521. * @private
  4522. * @param {Function} callback The function to combine each word.
  4523. * @returns {Function} Returns the new compounder function.
  4524. */
  4525. function createCompounder(callback) {
  4526. return function(string) {
  4527. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4528. };
  4529. }
  4530. /**
  4531. * Creates a function that produces an instance of `Ctor` regardless of
  4532. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4533. *
  4534. * @private
  4535. * @param {Function} Ctor The constructor to wrap.
  4536. * @returns {Function} Returns the new wrapped function.
  4537. */
  4538. function createCtor(Ctor) {
  4539. return function() {
  4540. // Use a `switch` statement to work with class constructors. See
  4541. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4542. // for more details.
  4543. var args = arguments;
  4544. switch (args.length) {
  4545. case 0: return new Ctor;
  4546. case 1: return new Ctor(args[0]);
  4547. case 2: return new Ctor(args[0], args[1]);
  4548. case 3: return new Ctor(args[0], args[1], args[2]);
  4549. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4550. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4551. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4552. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4553. }
  4554. var thisBinding = baseCreate(Ctor.prototype),
  4555. result = Ctor.apply(thisBinding, args);
  4556. // Mimic the constructor's `return` behavior.
  4557. // See https://es5.github.io/#x13.2.2 for more details.
  4558. return isObject(result) ? result : thisBinding;
  4559. };
  4560. }
  4561. /**
  4562. * Creates a function that wraps `func` to enable currying.
  4563. *
  4564. * @private
  4565. * @param {Function} func The function to wrap.
  4566. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4567. * @param {number} arity The arity of `func`.
  4568. * @returns {Function} Returns the new wrapped function.
  4569. */
  4570. function createCurry(func, bitmask, arity) {
  4571. var Ctor = createCtor(func);
  4572. function wrapper() {
  4573. var length = arguments.length,
  4574. args = Array(length),
  4575. index = length,
  4576. placeholder = getHolder(wrapper);
  4577. while (index--) {
  4578. args[index] = arguments[index];
  4579. }
  4580. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4581. ? []
  4582. : replaceHolders(args, placeholder);
  4583. length -= holders.length;
  4584. if (length < arity) {
  4585. return createRecurry(
  4586. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4587. args, holders, undefined, undefined, arity - length);
  4588. }
  4589. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4590. return apply(fn, this, args);
  4591. }
  4592. return wrapper;
  4593. }
  4594. /**
  4595. * Creates a `_.find` or `_.findLast` function.
  4596. *
  4597. * @private
  4598. * @param {Function} findIndexFunc The function to find the collection index.
  4599. * @returns {Function} Returns the new find function.
  4600. */
  4601. function createFind(findIndexFunc) {
  4602. return function(collection, predicate, fromIndex) {
  4603. var iterable = Object(collection);
  4604. if (!isArrayLike(collection)) {
  4605. var iteratee = getIteratee(predicate, 3);
  4606. collection = keys(collection);
  4607. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4608. }
  4609. var index = findIndexFunc(collection, predicate, fromIndex);
  4610. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4611. };
  4612. }
  4613. /**
  4614. * Creates a `_.flow` or `_.flowRight` function.
  4615. *
  4616. * @private
  4617. * @param {boolean} [fromRight] Specify iterating from right to left.
  4618. * @returns {Function} Returns the new flow function.
  4619. */
  4620. function createFlow(fromRight) {
  4621. return flatRest(function(funcs) {
  4622. var length = funcs.length,
  4623. index = length,
  4624. prereq = LodashWrapper.prototype.thru;
  4625. if (fromRight) {
  4626. funcs.reverse();
  4627. }
  4628. while (index--) {
  4629. var func = funcs[index];
  4630. if (typeof func != 'function') {
  4631. throw new TypeError(FUNC_ERROR_TEXT);
  4632. }
  4633. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4634. var wrapper = new LodashWrapper([], true);
  4635. }
  4636. }
  4637. index = wrapper ? index : length;
  4638. while (++index < length) {
  4639. func = funcs[index];
  4640. var funcName = getFuncName(func),
  4641. data = funcName == 'wrapper' ? getData(func) : undefined;
  4642. if (data && isLaziable(data[0]) &&
  4643. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4644. !data[4].length && data[9] == 1
  4645. ) {
  4646. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4647. } else {
  4648. wrapper = (func.length == 1 && isLaziable(func))
  4649. ? wrapper[funcName]()
  4650. : wrapper.thru(func);
  4651. }
  4652. }
  4653. return function() {
  4654. var args = arguments,
  4655. value = args[0];
  4656. if (wrapper && args.length == 1 && isArray(value)) {
  4657. return wrapper.plant(value).value();
  4658. }
  4659. var index = 0,
  4660. result = length ? funcs[index].apply(this, args) : value;
  4661. while (++index < length) {
  4662. result = funcs[index].call(this, result);
  4663. }
  4664. return result;
  4665. };
  4666. });
  4667. }
  4668. /**
  4669. * Creates a function that wraps `func` to invoke it with optional `this`
  4670. * binding of `thisArg`, partial application, and currying.
  4671. *
  4672. * @private
  4673. * @param {Function|string} func The function or method name to wrap.
  4674. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4675. * @param {*} [thisArg] The `this` binding of `func`.
  4676. * @param {Array} [partials] The arguments to prepend to those provided to
  4677. * the new function.
  4678. * @param {Array} [holders] The `partials` placeholder indexes.
  4679. * @param {Array} [partialsRight] The arguments to append to those provided
  4680. * to the new function.
  4681. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4682. * @param {Array} [argPos] The argument positions of the new function.
  4683. * @param {number} [ary] The arity cap of `func`.
  4684. * @param {number} [arity] The arity of `func`.
  4685. * @returns {Function} Returns the new wrapped function.
  4686. */
  4687. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4688. var isAry = bitmask & WRAP_ARY_FLAG,
  4689. isBind = bitmask & WRAP_BIND_FLAG,
  4690. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4691. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4692. isFlip = bitmask & WRAP_FLIP_FLAG,
  4693. Ctor = isBindKey ? undefined : createCtor(func);
  4694. function wrapper() {
  4695. var length = arguments.length,
  4696. args = Array(length),
  4697. index = length;
  4698. while (index--) {
  4699. args[index] = arguments[index];
  4700. }
  4701. if (isCurried) {
  4702. var placeholder = getHolder(wrapper),
  4703. holdersCount = countHolders(args, placeholder);
  4704. }
  4705. if (partials) {
  4706. args = composeArgs(args, partials, holders, isCurried);
  4707. }
  4708. if (partialsRight) {
  4709. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4710. }
  4711. length -= holdersCount;
  4712. if (isCurried && length < arity) {
  4713. var newHolders = replaceHolders(args, placeholder);
  4714. return createRecurry(
  4715. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4716. args, newHolders, argPos, ary, arity - length
  4717. );
  4718. }
  4719. var thisBinding = isBind ? thisArg : this,
  4720. fn = isBindKey ? thisBinding[func] : func;
  4721. length = args.length;
  4722. if (argPos) {
  4723. args = reorder(args, argPos);
  4724. } else if (isFlip && length > 1) {
  4725. args.reverse();
  4726. }
  4727. if (isAry && ary < length) {
  4728. args.length = ary;
  4729. }
  4730. if (this && this !== root && this instanceof wrapper) {
  4731. fn = Ctor || createCtor(fn);
  4732. }
  4733. return fn.apply(thisBinding, args);
  4734. }
  4735. return wrapper;
  4736. }
  4737. /**
  4738. * Creates a function like `_.invertBy`.
  4739. *
  4740. * @private
  4741. * @param {Function} setter The function to set accumulator values.
  4742. * @param {Function} toIteratee The function to resolve iteratees.
  4743. * @returns {Function} Returns the new inverter function.
  4744. */
  4745. function createInverter(setter, toIteratee) {
  4746. return function(object, iteratee) {
  4747. return baseInverter(object, setter, toIteratee(iteratee), {});
  4748. };
  4749. }
  4750. /**
  4751. * Creates a function that performs a mathematical operation on two values.
  4752. *
  4753. * @private
  4754. * @param {Function} operator The function to perform the operation.
  4755. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4756. * @returns {Function} Returns the new mathematical operation function.
  4757. */
  4758. function createMathOperation(operator, defaultValue) {
  4759. return function(value, other) {
  4760. var result;
  4761. if (value === undefined && other === undefined) {
  4762. return defaultValue;
  4763. }
  4764. if (value !== undefined) {
  4765. result = value;
  4766. }
  4767. if (other !== undefined) {
  4768. if (result === undefined) {
  4769. return other;
  4770. }
  4771. if (typeof value == 'string' || typeof other == 'string') {
  4772. value = baseToString(value);
  4773. other = baseToString(other);
  4774. } else {
  4775. value = baseToNumber(value);
  4776. other = baseToNumber(other);
  4777. }
  4778. result = operator(value, other);
  4779. }
  4780. return result;
  4781. };
  4782. }
  4783. /**
  4784. * Creates a function like `_.over`.
  4785. *
  4786. * @private
  4787. * @param {Function} arrayFunc The function to iterate over iteratees.
  4788. * @returns {Function} Returns the new over function.
  4789. */
  4790. function createOver(arrayFunc) {
  4791. return flatRest(function(iteratees) {
  4792. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4793. return baseRest(function(args) {
  4794. var thisArg = this;
  4795. return arrayFunc(iteratees, function(iteratee) {
  4796. return apply(iteratee, thisArg, args);
  4797. });
  4798. });
  4799. });
  4800. }
  4801. /**
  4802. * Creates the padding for `string` based on `length`. The `chars` string
  4803. * is truncated if the number of characters exceeds `length`.
  4804. *
  4805. * @private
  4806. * @param {number} length The padding length.
  4807. * @param {string} [chars=' '] The string used as padding.
  4808. * @returns {string} Returns the padding for `string`.
  4809. */
  4810. function createPadding(length, chars) {
  4811. chars = chars === undefined ? ' ' : baseToString(chars);
  4812. var charsLength = chars.length;
  4813. if (charsLength < 2) {
  4814. return charsLength ? baseRepeat(chars, length) : chars;
  4815. }
  4816. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4817. return hasUnicode(chars)
  4818. ? castSlice(stringToArray(result), 0, length).join('')
  4819. : result.slice(0, length);
  4820. }
  4821. /**
  4822. * Creates a function that wraps `func` to invoke it with the `this` binding
  4823. * of `thisArg` and `partials` prepended to the arguments it receives.
  4824. *
  4825. * @private
  4826. * @param {Function} func The function to wrap.
  4827. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4828. * @param {*} thisArg The `this` binding of `func`.
  4829. * @param {Array} partials The arguments to prepend to those provided to
  4830. * the new function.
  4831. * @returns {Function} Returns the new wrapped function.
  4832. */
  4833. function createPartial(func, bitmask, thisArg, partials) {
  4834. var isBind = bitmask & WRAP_BIND_FLAG,
  4835. Ctor = createCtor(func);
  4836. function wrapper() {
  4837. var argsIndex = -1,
  4838. argsLength = arguments.length,
  4839. leftIndex = -1,
  4840. leftLength = partials.length,
  4841. args = Array(leftLength + argsLength),
  4842. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4843. while (++leftIndex < leftLength) {
  4844. args[leftIndex] = partials[leftIndex];
  4845. }
  4846. while (argsLength--) {
  4847. args[leftIndex++] = arguments[++argsIndex];
  4848. }
  4849. return apply(fn, isBind ? thisArg : this, args);
  4850. }
  4851. return wrapper;
  4852. }
  4853. /**
  4854. * Creates a `_.range` or `_.rangeRight` function.
  4855. *
  4856. * @private
  4857. * @param {boolean} [fromRight] Specify iterating from right to left.
  4858. * @returns {Function} Returns the new range function.
  4859. */
  4860. function createRange(fromRight) {
  4861. return function(start, end, step) {
  4862. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4863. end = step = undefined;
  4864. }
  4865. // Ensure the sign of `-0` is preserved.
  4866. start = toFinite(start);
  4867. if (end === undefined) {
  4868. end = start;
  4869. start = 0;
  4870. } else {
  4871. end = toFinite(end);
  4872. }
  4873. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4874. return baseRange(start, end, step, fromRight);
  4875. };
  4876. }
  4877. /**
  4878. * Creates a function that performs a relational operation on two values.
  4879. *
  4880. * @private
  4881. * @param {Function} operator The function to perform the operation.
  4882. * @returns {Function} Returns the new relational operation function.
  4883. */
  4884. function createRelationalOperation(operator) {
  4885. return function(value, other) {
  4886. if (!(typeof value == 'string' && typeof other == 'string')) {
  4887. value = toNumber(value);
  4888. other = toNumber(other);
  4889. }
  4890. return operator(value, other);
  4891. };
  4892. }
  4893. /**
  4894. * Creates a function that wraps `func` to continue currying.
  4895. *
  4896. * @private
  4897. * @param {Function} func The function to wrap.
  4898. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4899. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4900. * @param {*} placeholder The placeholder value.
  4901. * @param {*} [thisArg] The `this` binding of `func`.
  4902. * @param {Array} [partials] The arguments to prepend to those provided to
  4903. * the new function.
  4904. * @param {Array} [holders] The `partials` placeholder indexes.
  4905. * @param {Array} [argPos] The argument positions of the new function.
  4906. * @param {number} [ary] The arity cap of `func`.
  4907. * @param {number} [arity] The arity of `func`.
  4908. * @returns {Function} Returns the new wrapped function.
  4909. */
  4910. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4911. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4912. newHolders = isCurry ? holders : undefined,
  4913. newHoldersRight = isCurry ? undefined : holders,
  4914. newPartials = isCurry ? partials : undefined,
  4915. newPartialsRight = isCurry ? undefined : partials;
  4916. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4917. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4918. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4919. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4920. }
  4921. var newData = [
  4922. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4923. newHoldersRight, argPos, ary, arity
  4924. ];
  4925. var result = wrapFunc.apply(undefined, newData);
  4926. if (isLaziable(func)) {
  4927. setData(result, newData);
  4928. }
  4929. result.placeholder = placeholder;
  4930. return setWrapToString(result, func, bitmask);
  4931. }
  4932. /**
  4933. * Creates a function like `_.round`.
  4934. *
  4935. * @private
  4936. * @param {string} methodName The name of the `Math` method to use when rounding.
  4937. * @returns {Function} Returns the new round function.
  4938. */
  4939. function createRound(methodName) {
  4940. var func = Math[methodName];
  4941. return function(number, precision) {
  4942. number = toNumber(number);
  4943. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4944. if (precision && nativeIsFinite(number)) {
  4945. // Shift with exponential notation to avoid floating-point issues.
  4946. // See [MDN](https://mdn.io/round#Examples) for more details.
  4947. var pair = (toString(number) + 'e').split('e'),
  4948. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4949. pair = (toString(value) + 'e').split('e');
  4950. return +(pair[0] + 'e' + (+pair[1] - precision));
  4951. }
  4952. return func(number);
  4953. };
  4954. }
  4955. /**
  4956. * Creates a set object of `values`.
  4957. *
  4958. * @private
  4959. * @param {Array} values The values to add to the set.
  4960. * @returns {Object} Returns the new set.
  4961. */
  4962. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4963. return new Set(values);
  4964. };
  4965. /**
  4966. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4967. *
  4968. * @private
  4969. * @param {Function} keysFunc The function to get the keys of a given object.
  4970. * @returns {Function} Returns the new pairs function.
  4971. */
  4972. function createToPairs(keysFunc) {
  4973. return function(object) {
  4974. var tag = getTag(object);
  4975. if (tag == mapTag) {
  4976. return mapToArray(object);
  4977. }
  4978. if (tag == setTag) {
  4979. return setToPairs(object);
  4980. }
  4981. return baseToPairs(object, keysFunc(object));
  4982. };
  4983. }
  4984. /**
  4985. * Creates a function that either curries or invokes `func` with optional
  4986. * `this` binding and partially applied arguments.
  4987. *
  4988. * @private
  4989. * @param {Function|string} func The function or method name to wrap.
  4990. * @param {number} bitmask The bitmask flags.
  4991. * 1 - `_.bind`
  4992. * 2 - `_.bindKey`
  4993. * 4 - `_.curry` or `_.curryRight` of a bound function
  4994. * 8 - `_.curry`
  4995. * 16 - `_.curryRight`
  4996. * 32 - `_.partial`
  4997. * 64 - `_.partialRight`
  4998. * 128 - `_.rearg`
  4999. * 256 - `_.ary`
  5000. * 512 - `_.flip`
  5001. * @param {*} [thisArg] The `this` binding of `func`.
  5002. * @param {Array} [partials] The arguments to be partially applied.
  5003. * @param {Array} [holders] The `partials` placeholder indexes.
  5004. * @param {Array} [argPos] The argument positions of the new function.
  5005. * @param {number} [ary] The arity cap of `func`.
  5006. * @param {number} [arity] The arity of `func`.
  5007. * @returns {Function} Returns the new wrapped function.
  5008. */
  5009. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5010. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5011. if (!isBindKey && typeof func != 'function') {
  5012. throw new TypeError(FUNC_ERROR_TEXT);
  5013. }
  5014. var length = partials ? partials.length : 0;
  5015. if (!length) {
  5016. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5017. partials = holders = undefined;
  5018. }
  5019. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5020. arity = arity === undefined ? arity : toInteger(arity);
  5021. length -= holders ? holders.length : 0;
  5022. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5023. var partialsRight = partials,
  5024. holdersRight = holders;
  5025. partials = holders = undefined;
  5026. }
  5027. var data = isBindKey ? undefined : getData(func);
  5028. var newData = [
  5029. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5030. argPos, ary, arity
  5031. ];
  5032. if (data) {
  5033. mergeData(newData, data);
  5034. }
  5035. func = newData[0];
  5036. bitmask = newData[1];
  5037. thisArg = newData[2];
  5038. partials = newData[3];
  5039. holders = newData[4];
  5040. arity = newData[9] = newData[9] === undefined
  5041. ? (isBindKey ? 0 : func.length)
  5042. : nativeMax(newData[9] - length, 0);
  5043. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5044. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5045. }
  5046. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5047. var result = createBind(func, bitmask, thisArg);
  5048. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5049. result = createCurry(func, bitmask, arity);
  5050. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5051. result = createPartial(func, bitmask, thisArg, partials);
  5052. } else {
  5053. result = createHybrid.apply(undefined, newData);
  5054. }
  5055. var setter = data ? baseSetData : setData;
  5056. return setWrapToString(setter(result, newData), func, bitmask);
  5057. }
  5058. /**
  5059. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5060. * of source objects to the destination object for all destination properties
  5061. * that resolve to `undefined`.
  5062. *
  5063. * @private
  5064. * @param {*} objValue The destination value.
  5065. * @param {*} srcValue The source value.
  5066. * @param {string} key The key of the property to assign.
  5067. * @param {Object} object The parent object of `objValue`.
  5068. * @returns {*} Returns the value to assign.
  5069. */
  5070. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5071. if (objValue === undefined ||
  5072. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5073. return srcValue;
  5074. }
  5075. return objValue;
  5076. }
  5077. /**
  5078. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5079. * objects into destination objects that are passed thru.
  5080. *
  5081. * @private
  5082. * @param {*} objValue The destination value.
  5083. * @param {*} srcValue The source value.
  5084. * @param {string} key The key of the property to merge.
  5085. * @param {Object} object The parent object of `objValue`.
  5086. * @param {Object} source The parent object of `srcValue`.
  5087. * @param {Object} [stack] Tracks traversed source values and their merged
  5088. * counterparts.
  5089. * @returns {*} Returns the value to assign.
  5090. */
  5091. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5092. if (isObject(objValue) && isObject(srcValue)) {
  5093. // Recursively merge objects and arrays (susceptible to call stack limits).
  5094. stack.set(srcValue, objValue);
  5095. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5096. stack['delete'](srcValue);
  5097. }
  5098. return objValue;
  5099. }
  5100. /**
  5101. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5102. * objects.
  5103. *
  5104. * @private
  5105. * @param {*} value The value to inspect.
  5106. * @param {string} key The key of the property to inspect.
  5107. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5108. */
  5109. function customOmitClone(value) {
  5110. return isPlainObject(value) ? undefined : value;
  5111. }
  5112. /**
  5113. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5114. * partial deep comparisons.
  5115. *
  5116. * @private
  5117. * @param {Array} array The array to compare.
  5118. * @param {Array} other The other array to compare.
  5119. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5120. * @param {Function} customizer The function to customize comparisons.
  5121. * @param {Function} equalFunc The function to determine equivalents of values.
  5122. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5123. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5124. */
  5125. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5126. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5127. arrLength = array.length,
  5128. othLength = other.length;
  5129. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5130. return false;
  5131. }
  5132. // Assume cyclic values are equal.
  5133. var stacked = stack.get(array);
  5134. if (stacked && stack.get(other)) {
  5135. return stacked == other;
  5136. }
  5137. var index = -1,
  5138. result = true,
  5139. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5140. stack.set(array, other);
  5141. stack.set(other, array);
  5142. // Ignore non-index properties.
  5143. while (++index < arrLength) {
  5144. var arrValue = array[index],
  5145. othValue = other[index];
  5146. if (customizer) {
  5147. var compared = isPartial
  5148. ? customizer(othValue, arrValue, index, other, array, stack)
  5149. : customizer(arrValue, othValue, index, array, other, stack);
  5150. }
  5151. if (compared !== undefined) {
  5152. if (compared) {
  5153. continue;
  5154. }
  5155. result = false;
  5156. break;
  5157. }
  5158. // Recursively compare arrays (susceptible to call stack limits).
  5159. if (seen) {
  5160. if (!arraySome(other, function(othValue, othIndex) {
  5161. if (!cacheHas(seen, othIndex) &&
  5162. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5163. return seen.push(othIndex);
  5164. }
  5165. })) {
  5166. result = false;
  5167. break;
  5168. }
  5169. } else if (!(
  5170. arrValue === othValue ||
  5171. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5172. )) {
  5173. result = false;
  5174. break;
  5175. }
  5176. }
  5177. stack['delete'](array);
  5178. stack['delete'](other);
  5179. return result;
  5180. }
  5181. /**
  5182. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5183. * the same `toStringTag`.
  5184. *
  5185. * **Note:** This function only supports comparing values with tags of
  5186. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5187. *
  5188. * @private
  5189. * @param {Object} object The object to compare.
  5190. * @param {Object} other The other object to compare.
  5191. * @param {string} tag The `toStringTag` of the objects to compare.
  5192. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5193. * @param {Function} customizer The function to customize comparisons.
  5194. * @param {Function} equalFunc The function to determine equivalents of values.
  5195. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5196. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5197. */
  5198. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5199. switch (tag) {
  5200. case dataViewTag:
  5201. if ((object.byteLength != other.byteLength) ||
  5202. (object.byteOffset != other.byteOffset)) {
  5203. return false;
  5204. }
  5205. object = object.buffer;
  5206. other = other.buffer;
  5207. case arrayBufferTag:
  5208. if ((object.byteLength != other.byteLength) ||
  5209. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5210. return false;
  5211. }
  5212. return true;
  5213. case boolTag:
  5214. case dateTag:
  5215. case numberTag:
  5216. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5217. // Invalid dates are coerced to `NaN`.
  5218. return eq(+object, +other);
  5219. case errorTag:
  5220. return object.name == other.name && object.message == other.message;
  5221. case regexpTag:
  5222. case stringTag:
  5223. // Coerce regexes to strings and treat strings, primitives and objects,
  5224. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5225. // for more details.
  5226. return object == (other + '');
  5227. case mapTag:
  5228. var convert = mapToArray;
  5229. case setTag:
  5230. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5231. convert || (convert = setToArray);
  5232. if (object.size != other.size && !isPartial) {
  5233. return false;
  5234. }
  5235. // Assume cyclic values are equal.
  5236. var stacked = stack.get(object);
  5237. if (stacked) {
  5238. return stacked == other;
  5239. }
  5240. bitmask |= COMPARE_UNORDERED_FLAG;
  5241. // Recursively compare objects (susceptible to call stack limits).
  5242. stack.set(object, other);
  5243. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5244. stack['delete'](object);
  5245. return result;
  5246. case symbolTag:
  5247. if (symbolValueOf) {
  5248. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5249. }
  5250. }
  5251. return false;
  5252. }
  5253. /**
  5254. * A specialized version of `baseIsEqualDeep` for objects with support for
  5255. * partial deep comparisons.
  5256. *
  5257. * @private
  5258. * @param {Object} object The object to compare.
  5259. * @param {Object} other The other object to compare.
  5260. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5261. * @param {Function} customizer The function to customize comparisons.
  5262. * @param {Function} equalFunc The function to determine equivalents of values.
  5263. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5264. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5265. */
  5266. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5267. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5268. objProps = getAllKeys(object),
  5269. objLength = objProps.length,
  5270. othProps = getAllKeys(other),
  5271. othLength = othProps.length;
  5272. if (objLength != othLength && !isPartial) {
  5273. return false;
  5274. }
  5275. var index = objLength;
  5276. while (index--) {
  5277. var key = objProps[index];
  5278. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5279. return false;
  5280. }
  5281. }
  5282. // Assume cyclic values are equal.
  5283. var stacked = stack.get(object);
  5284. if (stacked && stack.get(other)) {
  5285. return stacked == other;
  5286. }
  5287. var result = true;
  5288. stack.set(object, other);
  5289. stack.set(other, object);
  5290. var skipCtor = isPartial;
  5291. while (++index < objLength) {
  5292. key = objProps[index];
  5293. var objValue = object[key],
  5294. othValue = other[key];
  5295. if (customizer) {
  5296. var compared = isPartial
  5297. ? customizer(othValue, objValue, key, other, object, stack)
  5298. : customizer(objValue, othValue, key, object, other, stack);
  5299. }
  5300. // Recursively compare objects (susceptible to call stack limits).
  5301. if (!(compared === undefined
  5302. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5303. : compared
  5304. )) {
  5305. result = false;
  5306. break;
  5307. }
  5308. skipCtor || (skipCtor = key == 'constructor');
  5309. }
  5310. if (result && !skipCtor) {
  5311. var objCtor = object.constructor,
  5312. othCtor = other.constructor;
  5313. // Non `Object` object instances with different constructors are not equal.
  5314. if (objCtor != othCtor &&
  5315. ('constructor' in object && 'constructor' in other) &&
  5316. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5317. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5318. result = false;
  5319. }
  5320. }
  5321. stack['delete'](object);
  5322. stack['delete'](other);
  5323. return result;
  5324. }
  5325. /**
  5326. * A specialized version of `baseRest` which flattens the rest array.
  5327. *
  5328. * @private
  5329. * @param {Function} func The function to apply a rest parameter to.
  5330. * @returns {Function} Returns the new function.
  5331. */
  5332. function flatRest(func) {
  5333. return setToString(overRest(func, undefined, flatten), func + '');
  5334. }
  5335. /**
  5336. * Creates an array of own enumerable property names and symbols of `object`.
  5337. *
  5338. * @private
  5339. * @param {Object} object The object to query.
  5340. * @returns {Array} Returns the array of property names and symbols.
  5341. */
  5342. function getAllKeys(object) {
  5343. return baseGetAllKeys(object, keys, getSymbols);
  5344. }
  5345. /**
  5346. * Creates an array of own and inherited enumerable property names and
  5347. * symbols of `object`.
  5348. *
  5349. * @private
  5350. * @param {Object} object The object to query.
  5351. * @returns {Array} Returns the array of property names and symbols.
  5352. */
  5353. function getAllKeysIn(object) {
  5354. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5355. }
  5356. /**
  5357. * Gets metadata for `func`.
  5358. *
  5359. * @private
  5360. * @param {Function} func The function to query.
  5361. * @returns {*} Returns the metadata for `func`.
  5362. */
  5363. var getData = !metaMap ? noop : function(func) {
  5364. return metaMap.get(func);
  5365. };
  5366. /**
  5367. * Gets the name of `func`.
  5368. *
  5369. * @private
  5370. * @param {Function} func The function to query.
  5371. * @returns {string} Returns the function name.
  5372. */
  5373. function getFuncName(func) {
  5374. var result = (func.name + ''),
  5375. array = realNames[result],
  5376. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5377. while (length--) {
  5378. var data = array[length],
  5379. otherFunc = data.func;
  5380. if (otherFunc == null || otherFunc == func) {
  5381. return data.name;
  5382. }
  5383. }
  5384. return result;
  5385. }
  5386. /**
  5387. * Gets the argument placeholder value for `func`.
  5388. *
  5389. * @private
  5390. * @param {Function} func The function to inspect.
  5391. * @returns {*} Returns the placeholder value.
  5392. */
  5393. function getHolder(func) {
  5394. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5395. return object.placeholder;
  5396. }
  5397. /**
  5398. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5399. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5400. * If arguments are provided, the chosen function is invoked with them and
  5401. * its result is returned.
  5402. *
  5403. * @private
  5404. * @param {*} [value] The value to convert to an iteratee.
  5405. * @param {number} [arity] The arity of the created iteratee.
  5406. * @returns {Function} Returns the chosen function or its result.
  5407. */
  5408. function getIteratee() {
  5409. var result = lodash.iteratee || iteratee;
  5410. result = result === iteratee ? baseIteratee : result;
  5411. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5412. }
  5413. /**
  5414. * Gets the data for `map`.
  5415. *
  5416. * @private
  5417. * @param {Object} map The map to query.
  5418. * @param {string} key The reference key.
  5419. * @returns {*} Returns the map data.
  5420. */
  5421. function getMapData(map, key) {
  5422. var data = map.__data__;
  5423. return isKeyable(key)
  5424. ? data[typeof key == 'string' ? 'string' : 'hash']
  5425. : data.map;
  5426. }
  5427. /**
  5428. * Gets the property names, values, and compare flags of `object`.
  5429. *
  5430. * @private
  5431. * @param {Object} object The object to query.
  5432. * @returns {Array} Returns the match data of `object`.
  5433. */
  5434. function getMatchData(object) {
  5435. var result = keys(object),
  5436. length = result.length;
  5437. while (length--) {
  5438. var key = result[length],
  5439. value = object[key];
  5440. result[length] = [key, value, isStrictComparable(value)];
  5441. }
  5442. return result;
  5443. }
  5444. /**
  5445. * Gets the native function at `key` of `object`.
  5446. *
  5447. * @private
  5448. * @param {Object} object The object to query.
  5449. * @param {string} key The key of the method to get.
  5450. * @returns {*} Returns the function if it's native, else `undefined`.
  5451. */
  5452. function getNative(object, key) {
  5453. var value = getValue(object, key);
  5454. return baseIsNative(value) ? value : undefined;
  5455. }
  5456. /**
  5457. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5458. *
  5459. * @private
  5460. * @param {*} value The value to query.
  5461. * @returns {string} Returns the raw `toStringTag`.
  5462. */
  5463. function getRawTag(value) {
  5464. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5465. tag = value[symToStringTag];
  5466. try {
  5467. value[symToStringTag] = undefined;
  5468. var unmasked = true;
  5469. } catch (e) {}
  5470. var result = nativeObjectToString.call(value);
  5471. if (unmasked) {
  5472. if (isOwn) {
  5473. value[symToStringTag] = tag;
  5474. } else {
  5475. delete value[symToStringTag];
  5476. }
  5477. }
  5478. return result;
  5479. }
  5480. /**
  5481. * Creates an array of the own enumerable symbols of `object`.
  5482. *
  5483. * @private
  5484. * @param {Object} object The object to query.
  5485. * @returns {Array} Returns the array of symbols.
  5486. */
  5487. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5488. if (object == null) {
  5489. return [];
  5490. }
  5491. object = Object(object);
  5492. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5493. return propertyIsEnumerable.call(object, symbol);
  5494. });
  5495. };
  5496. /**
  5497. * Creates an array of the own and inherited enumerable symbols of `object`.
  5498. *
  5499. * @private
  5500. * @param {Object} object The object to query.
  5501. * @returns {Array} Returns the array of symbols.
  5502. */
  5503. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5504. var result = [];
  5505. while (object) {
  5506. arrayPush(result, getSymbols(object));
  5507. object = getPrototype(object);
  5508. }
  5509. return result;
  5510. };
  5511. /**
  5512. * Gets the `toStringTag` of `value`.
  5513. *
  5514. * @private
  5515. * @param {*} value The value to query.
  5516. * @returns {string} Returns the `toStringTag`.
  5517. */
  5518. var getTag = baseGetTag;
  5519. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5520. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5521. (Map && getTag(new Map) != mapTag) ||
  5522. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5523. (Set && getTag(new Set) != setTag) ||
  5524. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5525. getTag = function(value) {
  5526. var result = baseGetTag(value),
  5527. Ctor = result == objectTag ? value.constructor : undefined,
  5528. ctorString = Ctor ? toSource(Ctor) : '';
  5529. if (ctorString) {
  5530. switch (ctorString) {
  5531. case dataViewCtorString: return dataViewTag;
  5532. case mapCtorString: return mapTag;
  5533. case promiseCtorString: return promiseTag;
  5534. case setCtorString: return setTag;
  5535. case weakMapCtorString: return weakMapTag;
  5536. }
  5537. }
  5538. return result;
  5539. };
  5540. }
  5541. /**
  5542. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5543. *
  5544. * @private
  5545. * @param {number} start The start of the view.
  5546. * @param {number} end The end of the view.
  5547. * @param {Array} transforms The transformations to apply to the view.
  5548. * @returns {Object} Returns an object containing the `start` and `end`
  5549. * positions of the view.
  5550. */
  5551. function getView(start, end, transforms) {
  5552. var index = -1,
  5553. length = transforms.length;
  5554. while (++index < length) {
  5555. var data = transforms[index],
  5556. size = data.size;
  5557. switch (data.type) {
  5558. case 'drop': start += size; break;
  5559. case 'dropRight': end -= size; break;
  5560. case 'take': end = nativeMin(end, start + size); break;
  5561. case 'takeRight': start = nativeMax(start, end - size); break;
  5562. }
  5563. }
  5564. return { 'start': start, 'end': end };
  5565. }
  5566. /**
  5567. * Extracts wrapper details from the `source` body comment.
  5568. *
  5569. * @private
  5570. * @param {string} source The source to inspect.
  5571. * @returns {Array} Returns the wrapper details.
  5572. */
  5573. function getWrapDetails(source) {
  5574. var match = source.match(reWrapDetails);
  5575. return match ? match[1].split(reSplitDetails) : [];
  5576. }
  5577. /**
  5578. * Checks if `path` exists on `object`.
  5579. *
  5580. * @private
  5581. * @param {Object} object The object to query.
  5582. * @param {Array|string} path The path to check.
  5583. * @param {Function} hasFunc The function to check properties.
  5584. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5585. */
  5586. function hasPath(object, path, hasFunc) {
  5587. path = castPath(path, object);
  5588. var index = -1,
  5589. length = path.length,
  5590. result = false;
  5591. while (++index < length) {
  5592. var key = toKey(path[index]);
  5593. if (!(result = object != null && hasFunc(object, key))) {
  5594. break;
  5595. }
  5596. object = object[key];
  5597. }
  5598. if (result || ++index != length) {
  5599. return result;
  5600. }
  5601. length = object == null ? 0 : object.length;
  5602. return !!length && isLength(length) && isIndex(key, length) &&
  5603. (isArray(object) || isArguments(object));
  5604. }
  5605. /**
  5606. * Initializes an array clone.
  5607. *
  5608. * @private
  5609. * @param {Array} array The array to clone.
  5610. * @returns {Array} Returns the initialized clone.
  5611. */
  5612. function initCloneArray(array) {
  5613. var length = array.length,
  5614. result = new array.constructor(length);
  5615. // Add properties assigned by `RegExp#exec`.
  5616. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5617. result.index = array.index;
  5618. result.input = array.input;
  5619. }
  5620. return result;
  5621. }
  5622. /**
  5623. * Initializes an object clone.
  5624. *
  5625. * @private
  5626. * @param {Object} object The object to clone.
  5627. * @returns {Object} Returns the initialized clone.
  5628. */
  5629. function initCloneObject(object) {
  5630. return (typeof object.constructor == 'function' && !isPrototype(object))
  5631. ? baseCreate(getPrototype(object))
  5632. : {};
  5633. }
  5634. /**
  5635. * Initializes an object clone based on its `toStringTag`.
  5636. *
  5637. * **Note:** This function only supports cloning values with tags of
  5638. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5639. *
  5640. * @private
  5641. * @param {Object} object The object to clone.
  5642. * @param {string} tag The `toStringTag` of the object to clone.
  5643. * @param {boolean} [isDeep] Specify a deep clone.
  5644. * @returns {Object} Returns the initialized clone.
  5645. */
  5646. function initCloneByTag(object, tag, isDeep) {
  5647. var Ctor = object.constructor;
  5648. switch (tag) {
  5649. case arrayBufferTag:
  5650. return cloneArrayBuffer(object);
  5651. case boolTag:
  5652. case dateTag:
  5653. return new Ctor(+object);
  5654. case dataViewTag:
  5655. return cloneDataView(object, isDeep);
  5656. case float32Tag: case float64Tag:
  5657. case int8Tag: case int16Tag: case int32Tag:
  5658. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5659. return cloneTypedArray(object, isDeep);
  5660. case mapTag:
  5661. return new Ctor;
  5662. case numberTag:
  5663. case stringTag:
  5664. return new Ctor(object);
  5665. case regexpTag:
  5666. return cloneRegExp(object);
  5667. case setTag:
  5668. return new Ctor;
  5669. case symbolTag:
  5670. return cloneSymbol(object);
  5671. }
  5672. }
  5673. /**
  5674. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5675. *
  5676. * @private
  5677. * @param {string} source The source to modify.
  5678. * @returns {Array} details The details to insert.
  5679. * @returns {string} Returns the modified source.
  5680. */
  5681. function insertWrapDetails(source, details) {
  5682. var length = details.length;
  5683. if (!length) {
  5684. return source;
  5685. }
  5686. var lastIndex = length - 1;
  5687. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5688. details = details.join(length > 2 ? ', ' : ' ');
  5689. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5690. }
  5691. /**
  5692. * Checks if `value` is a flattenable `arguments` object or array.
  5693. *
  5694. * @private
  5695. * @param {*} value The value to check.
  5696. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5697. */
  5698. function isFlattenable(value) {
  5699. return isArray(value) || isArguments(value) ||
  5700. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5701. }
  5702. /**
  5703. * Checks if `value` is a valid array-like index.
  5704. *
  5705. * @private
  5706. * @param {*} value The value to check.
  5707. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5708. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5709. */
  5710. function isIndex(value, length) {
  5711. var type = typeof value;
  5712. length = length == null ? MAX_SAFE_INTEGER : length;
  5713. return !!length &&
  5714. (type == 'number' ||
  5715. (type != 'symbol' && reIsUint.test(value))) &&
  5716. (value > -1 && value % 1 == 0 && value < length);
  5717. }
  5718. /**
  5719. * Checks if the given arguments are from an iteratee call.
  5720. *
  5721. * @private
  5722. * @param {*} value The potential iteratee value argument.
  5723. * @param {*} index The potential iteratee index or key argument.
  5724. * @param {*} object The potential iteratee object argument.
  5725. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5726. * else `false`.
  5727. */
  5728. function isIterateeCall(value, index, object) {
  5729. if (!isObject(object)) {
  5730. return false;
  5731. }
  5732. var type = typeof index;
  5733. if (type == 'number'
  5734. ? (isArrayLike(object) && isIndex(index, object.length))
  5735. : (type == 'string' && index in object)
  5736. ) {
  5737. return eq(object[index], value);
  5738. }
  5739. return false;
  5740. }
  5741. /**
  5742. * Checks if `value` is a property name and not a property path.
  5743. *
  5744. * @private
  5745. * @param {*} value The value to check.
  5746. * @param {Object} [object] The object to query keys on.
  5747. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5748. */
  5749. function isKey(value, object) {
  5750. if (isArray(value)) {
  5751. return false;
  5752. }
  5753. var type = typeof value;
  5754. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5755. value == null || isSymbol(value)) {
  5756. return true;
  5757. }
  5758. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5759. (object != null && value in Object(object));
  5760. }
  5761. /**
  5762. * Checks if `value` is suitable for use as unique object key.
  5763. *
  5764. * @private
  5765. * @param {*} value The value to check.
  5766. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5767. */
  5768. function isKeyable(value) {
  5769. var type = typeof value;
  5770. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5771. ? (value !== '__proto__')
  5772. : (value === null);
  5773. }
  5774. /**
  5775. * Checks if `func` has a lazy counterpart.
  5776. *
  5777. * @private
  5778. * @param {Function} func The function to check.
  5779. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5780. * else `false`.
  5781. */
  5782. function isLaziable(func) {
  5783. var funcName = getFuncName(func),
  5784. other = lodash[funcName];
  5785. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5786. return false;
  5787. }
  5788. if (func === other) {
  5789. return true;
  5790. }
  5791. var data = getData(other);
  5792. return !!data && func === data[0];
  5793. }
  5794. /**
  5795. * Checks if `func` has its source masked.
  5796. *
  5797. * @private
  5798. * @param {Function} func The function to check.
  5799. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5800. */
  5801. function isMasked(func) {
  5802. return !!maskSrcKey && (maskSrcKey in func);
  5803. }
  5804. /**
  5805. * Checks if `func` is capable of being masked.
  5806. *
  5807. * @private
  5808. * @param {*} value The value to check.
  5809. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5810. */
  5811. var isMaskable = coreJsData ? isFunction : stubFalse;
  5812. /**
  5813. * Checks if `value` is likely a prototype object.
  5814. *
  5815. * @private
  5816. * @param {*} value The value to check.
  5817. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5818. */
  5819. function isPrototype(value) {
  5820. var Ctor = value && value.constructor,
  5821. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5822. return value === proto;
  5823. }
  5824. /**
  5825. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5826. *
  5827. * @private
  5828. * @param {*} value The value to check.
  5829. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5830. * equality comparisons, else `false`.
  5831. */
  5832. function isStrictComparable(value) {
  5833. return value === value && !isObject(value);
  5834. }
  5835. /**
  5836. * A specialized version of `matchesProperty` for source values suitable
  5837. * for strict equality comparisons, i.e. `===`.
  5838. *
  5839. * @private
  5840. * @param {string} key The key of the property to get.
  5841. * @param {*} srcValue The value to match.
  5842. * @returns {Function} Returns the new spec function.
  5843. */
  5844. function matchesStrictComparable(key, srcValue) {
  5845. return function(object) {
  5846. if (object == null) {
  5847. return false;
  5848. }
  5849. return object[key] === srcValue &&
  5850. (srcValue !== undefined || (key in Object(object)));
  5851. };
  5852. }
  5853. /**
  5854. * A specialized version of `_.memoize` which clears the memoized function's
  5855. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5856. *
  5857. * @private
  5858. * @param {Function} func The function to have its output memoized.
  5859. * @returns {Function} Returns the new memoized function.
  5860. */
  5861. function memoizeCapped(func) {
  5862. var result = memoize(func, function(key) {
  5863. if (cache.size === MAX_MEMOIZE_SIZE) {
  5864. cache.clear();
  5865. }
  5866. return key;
  5867. });
  5868. var cache = result.cache;
  5869. return result;
  5870. }
  5871. /**
  5872. * Merges the function metadata of `source` into `data`.
  5873. *
  5874. * Merging metadata reduces the number of wrappers used to invoke a function.
  5875. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5876. * may be applied regardless of execution order. Methods like `_.ary` and
  5877. * `_.rearg` modify function arguments, making the order in which they are
  5878. * executed important, preventing the merging of metadata. However, we make
  5879. * an exception for a safe combined case where curried functions have `_.ary`
  5880. * and or `_.rearg` applied.
  5881. *
  5882. * @private
  5883. * @param {Array} data The destination metadata.
  5884. * @param {Array} source The source metadata.
  5885. * @returns {Array} Returns `data`.
  5886. */
  5887. function mergeData(data, source) {
  5888. var bitmask = data[1],
  5889. srcBitmask = source[1],
  5890. newBitmask = bitmask | srcBitmask,
  5891. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5892. var isCombo =
  5893. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5894. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5895. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5896. // Exit early if metadata can't be merged.
  5897. if (!(isCommon || isCombo)) {
  5898. return data;
  5899. }
  5900. // Use source `thisArg` if available.
  5901. if (srcBitmask & WRAP_BIND_FLAG) {
  5902. data[2] = source[2];
  5903. // Set when currying a bound function.
  5904. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5905. }
  5906. // Compose partial arguments.
  5907. var value = source[3];
  5908. if (value) {
  5909. var partials = data[3];
  5910. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5911. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5912. }
  5913. // Compose partial right arguments.
  5914. value = source[5];
  5915. if (value) {
  5916. partials = data[5];
  5917. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5918. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5919. }
  5920. // Use source `argPos` if available.
  5921. value = source[7];
  5922. if (value) {
  5923. data[7] = value;
  5924. }
  5925. // Use source `ary` if it's smaller.
  5926. if (srcBitmask & WRAP_ARY_FLAG) {
  5927. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5928. }
  5929. // Use source `arity` if one is not provided.
  5930. if (data[9] == null) {
  5931. data[9] = source[9];
  5932. }
  5933. // Use source `func` and merge bitmasks.
  5934. data[0] = source[0];
  5935. data[1] = newBitmask;
  5936. return data;
  5937. }
  5938. /**
  5939. * This function is like
  5940. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5941. * except that it includes inherited enumerable properties.
  5942. *
  5943. * @private
  5944. * @param {Object} object The object to query.
  5945. * @returns {Array} Returns the array of property names.
  5946. */
  5947. function nativeKeysIn(object) {
  5948. var result = [];
  5949. if (object != null) {
  5950. for (var key in Object(object)) {
  5951. result.push(key);
  5952. }
  5953. }
  5954. return result;
  5955. }
  5956. /**
  5957. * Converts `value` to a string using `Object.prototype.toString`.
  5958. *
  5959. * @private
  5960. * @param {*} value The value to convert.
  5961. * @returns {string} Returns the converted string.
  5962. */
  5963. function objectToString(value) {
  5964. return nativeObjectToString.call(value);
  5965. }
  5966. /**
  5967. * A specialized version of `baseRest` which transforms the rest array.
  5968. *
  5969. * @private
  5970. * @param {Function} func The function to apply a rest parameter to.
  5971. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5972. * @param {Function} transform The rest array transform.
  5973. * @returns {Function} Returns the new function.
  5974. */
  5975. function overRest(func, start, transform) {
  5976. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  5977. return function() {
  5978. var args = arguments,
  5979. index = -1,
  5980. length = nativeMax(args.length - start, 0),
  5981. array = Array(length);
  5982. while (++index < length) {
  5983. array[index] = args[start + index];
  5984. }
  5985. index = -1;
  5986. var otherArgs = Array(start + 1);
  5987. while (++index < start) {
  5988. otherArgs[index] = args[index];
  5989. }
  5990. otherArgs[start] = transform(array);
  5991. return apply(func, this, otherArgs);
  5992. };
  5993. }
  5994. /**
  5995. * Gets the parent value at `path` of `object`.
  5996. *
  5997. * @private
  5998. * @param {Object} object The object to query.
  5999. * @param {Array} path The path to get the parent value of.
  6000. * @returns {*} Returns the parent value.
  6001. */
  6002. function parent(object, path) {
  6003. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6004. }
  6005. /**
  6006. * Reorder `array` according to the specified indexes where the element at
  6007. * the first index is assigned as the first element, the element at
  6008. * the second index is assigned as the second element, and so on.
  6009. *
  6010. * @private
  6011. * @param {Array} array The array to reorder.
  6012. * @param {Array} indexes The arranged array indexes.
  6013. * @returns {Array} Returns `array`.
  6014. */
  6015. function reorder(array, indexes) {
  6016. var arrLength = array.length,
  6017. length = nativeMin(indexes.length, arrLength),
  6018. oldArray = copyArray(array);
  6019. while (length--) {
  6020. var index = indexes[length];
  6021. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6022. }
  6023. return array;
  6024. }
  6025. /**
  6026. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6027. *
  6028. * @private
  6029. * @param {Object} object The object to query.
  6030. * @param {string} key The key of the property to get.
  6031. * @returns {*} Returns the property value.
  6032. */
  6033. function safeGet(object, key) {
  6034. if (key === 'constructor' && typeof object[key] === 'function') {
  6035. return;
  6036. }
  6037. if (key == '__proto__') {
  6038. return;
  6039. }
  6040. return object[key];
  6041. }
  6042. /**
  6043. * Sets metadata for `func`.
  6044. *
  6045. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6046. * period of time, it will trip its breaker and transition to an identity
  6047. * function to avoid garbage collection pauses in V8. See
  6048. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6049. * for more details.
  6050. *
  6051. * @private
  6052. * @param {Function} func The function to associate metadata with.
  6053. * @param {*} data The metadata.
  6054. * @returns {Function} Returns `func`.
  6055. */
  6056. var setData = shortOut(baseSetData);
  6057. /**
  6058. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6059. *
  6060. * @private
  6061. * @param {Function} func The function to delay.
  6062. * @param {number} wait The number of milliseconds to delay invocation.
  6063. * @returns {number|Object} Returns the timer id or timeout object.
  6064. */
  6065. var setTimeout = ctxSetTimeout || function(func, wait) {
  6066. return root.setTimeout(func, wait);
  6067. };
  6068. /**
  6069. * Sets the `toString` method of `func` to return `string`.
  6070. *
  6071. * @private
  6072. * @param {Function} func The function to modify.
  6073. * @param {Function} string The `toString` result.
  6074. * @returns {Function} Returns `func`.
  6075. */
  6076. var setToString = shortOut(baseSetToString);
  6077. /**
  6078. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6079. * with wrapper details in a comment at the top of the source body.
  6080. *
  6081. * @private
  6082. * @param {Function} wrapper The function to modify.
  6083. * @param {Function} reference The reference function.
  6084. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6085. * @returns {Function} Returns `wrapper`.
  6086. */
  6087. function setWrapToString(wrapper, reference, bitmask) {
  6088. var source = (reference + '');
  6089. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6090. }
  6091. /**
  6092. * Creates a function that'll short out and invoke `identity` instead
  6093. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6094. * milliseconds.
  6095. *
  6096. * @private
  6097. * @param {Function} func The function to restrict.
  6098. * @returns {Function} Returns the new shortable function.
  6099. */
  6100. function shortOut(func) {
  6101. var count = 0,
  6102. lastCalled = 0;
  6103. return function() {
  6104. var stamp = nativeNow(),
  6105. remaining = HOT_SPAN - (stamp - lastCalled);
  6106. lastCalled = stamp;
  6107. if (remaining > 0) {
  6108. if (++count >= HOT_COUNT) {
  6109. return arguments[0];
  6110. }
  6111. } else {
  6112. count = 0;
  6113. }
  6114. return func.apply(undefined, arguments);
  6115. };
  6116. }
  6117. /**
  6118. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6119. *
  6120. * @private
  6121. * @param {Array} array The array to shuffle.
  6122. * @param {number} [size=array.length] The size of `array`.
  6123. * @returns {Array} Returns `array`.
  6124. */
  6125. function shuffleSelf(array, size) {
  6126. var index = -1,
  6127. length = array.length,
  6128. lastIndex = length - 1;
  6129. size = size === undefined ? length : size;
  6130. while (++index < size) {
  6131. var rand = baseRandom(index, lastIndex),
  6132. value = array[rand];
  6133. array[rand] = array[index];
  6134. array[index] = value;
  6135. }
  6136. array.length = size;
  6137. return array;
  6138. }
  6139. /**
  6140. * Converts `string` to a property path array.
  6141. *
  6142. * @private
  6143. * @param {string} string The string to convert.
  6144. * @returns {Array} Returns the property path array.
  6145. */
  6146. var stringToPath = memoizeCapped(function(string) {
  6147. var result = [];
  6148. if (string.charCodeAt(0) === 46 /* . */) {
  6149. result.push('');
  6150. }
  6151. string.replace(rePropName, function(match, number, quote, subString) {
  6152. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6153. });
  6154. return result;
  6155. });
  6156. /**
  6157. * Converts `value` to a string key if it's not a string or symbol.
  6158. *
  6159. * @private
  6160. * @param {*} value The value to inspect.
  6161. * @returns {string|symbol} Returns the key.
  6162. */
  6163. function toKey(value) {
  6164. if (typeof value == 'string' || isSymbol(value)) {
  6165. return value;
  6166. }
  6167. var result = (value + '');
  6168. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6169. }
  6170. /**
  6171. * Converts `func` to its source code.
  6172. *
  6173. * @private
  6174. * @param {Function} func The function to convert.
  6175. * @returns {string} Returns the source code.
  6176. */
  6177. function toSource(func) {
  6178. if (func != null) {
  6179. try {
  6180. return funcToString.call(func);
  6181. } catch (e) {}
  6182. try {
  6183. return (func + '');
  6184. } catch (e) {}
  6185. }
  6186. return '';
  6187. }
  6188. /**
  6189. * Updates wrapper `details` based on `bitmask` flags.
  6190. *
  6191. * @private
  6192. * @returns {Array} details The details to modify.
  6193. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6194. * @returns {Array} Returns `details`.
  6195. */
  6196. function updateWrapDetails(details, bitmask) {
  6197. arrayEach(wrapFlags, function(pair) {
  6198. var value = '_.' + pair[0];
  6199. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6200. details.push(value);
  6201. }
  6202. });
  6203. return details.sort();
  6204. }
  6205. /**
  6206. * Creates a clone of `wrapper`.
  6207. *
  6208. * @private
  6209. * @param {Object} wrapper The wrapper to clone.
  6210. * @returns {Object} Returns the cloned wrapper.
  6211. */
  6212. function wrapperClone(wrapper) {
  6213. if (wrapper instanceof LazyWrapper) {
  6214. return wrapper.clone();
  6215. }
  6216. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6217. result.__actions__ = copyArray(wrapper.__actions__);
  6218. result.__index__ = wrapper.__index__;
  6219. result.__values__ = wrapper.__values__;
  6220. return result;
  6221. }
  6222. /*------------------------------------------------------------------------*/
  6223. /**
  6224. * Creates an array of elements split into groups the length of `size`.
  6225. * If `array` can't be split evenly, the final chunk will be the remaining
  6226. * elements.
  6227. *
  6228. * @static
  6229. * @memberOf _
  6230. * @since 3.0.0
  6231. * @category Array
  6232. * @param {Array} array The array to process.
  6233. * @param {number} [size=1] The length of each chunk
  6234. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6235. * @returns {Array} Returns the new array of chunks.
  6236. * @example
  6237. *
  6238. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6239. * // => [['a', 'b'], ['c', 'd']]
  6240. *
  6241. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6242. * // => [['a', 'b', 'c'], ['d']]
  6243. */
  6244. function chunk(array, size, guard) {
  6245. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6246. size = 1;
  6247. } else {
  6248. size = nativeMax(toInteger(size), 0);
  6249. }
  6250. var length = array == null ? 0 : array.length;
  6251. if (!length || size < 1) {
  6252. return [];
  6253. }
  6254. var index = 0,
  6255. resIndex = 0,
  6256. result = Array(nativeCeil(length / size));
  6257. while (index < length) {
  6258. result[resIndex++] = baseSlice(array, index, (index += size));
  6259. }
  6260. return result;
  6261. }
  6262. /**
  6263. * Creates an array with all falsey values removed. The values `false`, `null`,
  6264. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6265. *
  6266. * @static
  6267. * @memberOf _
  6268. * @since 0.1.0
  6269. * @category Array
  6270. * @param {Array} array The array to compact.
  6271. * @returns {Array} Returns the new array of filtered values.
  6272. * @example
  6273. *
  6274. * _.compact([0, 1, false, 2, '', 3]);
  6275. * // => [1, 2, 3]
  6276. */
  6277. function compact(array) {
  6278. var index = -1,
  6279. length = array == null ? 0 : array.length,
  6280. resIndex = 0,
  6281. result = [];
  6282. while (++index < length) {
  6283. var value = array[index];
  6284. if (value) {
  6285. result[resIndex++] = value;
  6286. }
  6287. }
  6288. return result;
  6289. }
  6290. /**
  6291. * Creates a new array concatenating `array` with any additional arrays
  6292. * and/or values.
  6293. *
  6294. * @static
  6295. * @memberOf _
  6296. * @since 4.0.0
  6297. * @category Array
  6298. * @param {Array} array The array to concatenate.
  6299. * @param {...*} [values] The values to concatenate.
  6300. * @returns {Array} Returns the new concatenated array.
  6301. * @example
  6302. *
  6303. * var array = [1];
  6304. * var other = _.concat(array, 2, [3], [[4]]);
  6305. *
  6306. * console.log(other);
  6307. * // => [1, 2, 3, [4]]
  6308. *
  6309. * console.log(array);
  6310. * // => [1]
  6311. */
  6312. function concat() {
  6313. var length = arguments.length;
  6314. if (!length) {
  6315. return [];
  6316. }
  6317. var args = Array(length - 1),
  6318. array = arguments[0],
  6319. index = length;
  6320. while (index--) {
  6321. args[index - 1] = arguments[index];
  6322. }
  6323. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6324. }
  6325. /**
  6326. * Creates an array of `array` values not included in the other given arrays
  6327. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6328. * for equality comparisons. The order and references of result values are
  6329. * determined by the first array.
  6330. *
  6331. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6332. *
  6333. * @static
  6334. * @memberOf _
  6335. * @since 0.1.0
  6336. * @category Array
  6337. * @param {Array} array The array to inspect.
  6338. * @param {...Array} [values] The values to exclude.
  6339. * @returns {Array} Returns the new array of filtered values.
  6340. * @see _.without, _.xor
  6341. * @example
  6342. *
  6343. * _.difference([2, 1], [2, 3]);
  6344. * // => [1]
  6345. */
  6346. var difference = baseRest(function(array, values) {
  6347. return isArrayLikeObject(array)
  6348. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6349. : [];
  6350. });
  6351. /**
  6352. * This method is like `_.difference` except that it accepts `iteratee` which
  6353. * is invoked for each element of `array` and `values` to generate the criterion
  6354. * by which they're compared. The order and references of result values are
  6355. * determined by the first array. The iteratee is invoked with one argument:
  6356. * (value).
  6357. *
  6358. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6359. *
  6360. * @static
  6361. * @memberOf _
  6362. * @since 4.0.0
  6363. * @category Array
  6364. * @param {Array} array The array to inspect.
  6365. * @param {...Array} [values] The values to exclude.
  6366. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6367. * @returns {Array} Returns the new array of filtered values.
  6368. * @example
  6369. *
  6370. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6371. * // => [1.2]
  6372. *
  6373. * // The `_.property` iteratee shorthand.
  6374. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6375. * // => [{ 'x': 2 }]
  6376. */
  6377. var differenceBy = baseRest(function(array, values) {
  6378. var iteratee = last(values);
  6379. if (isArrayLikeObject(iteratee)) {
  6380. iteratee = undefined;
  6381. }
  6382. return isArrayLikeObject(array)
  6383. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6384. : [];
  6385. });
  6386. /**
  6387. * This method is like `_.difference` except that it accepts `comparator`
  6388. * which is invoked to compare elements of `array` to `values`. The order and
  6389. * references of result values are determined by the first array. The comparator
  6390. * is invoked with two arguments: (arrVal, othVal).
  6391. *
  6392. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6393. *
  6394. * @static
  6395. * @memberOf _
  6396. * @since 4.0.0
  6397. * @category Array
  6398. * @param {Array} array The array to inspect.
  6399. * @param {...Array} [values] The values to exclude.
  6400. * @param {Function} [comparator] The comparator invoked per element.
  6401. * @returns {Array} Returns the new array of filtered values.
  6402. * @example
  6403. *
  6404. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6405. *
  6406. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6407. * // => [{ 'x': 2, 'y': 1 }]
  6408. */
  6409. var differenceWith = baseRest(function(array, values) {
  6410. var comparator = last(values);
  6411. if (isArrayLikeObject(comparator)) {
  6412. comparator = undefined;
  6413. }
  6414. return isArrayLikeObject(array)
  6415. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6416. : [];
  6417. });
  6418. /**
  6419. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6420. *
  6421. * @static
  6422. * @memberOf _
  6423. * @since 0.5.0
  6424. * @category Array
  6425. * @param {Array} array The array to query.
  6426. * @param {number} [n=1] The number of elements to drop.
  6427. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6428. * @returns {Array} Returns the slice of `array`.
  6429. * @example
  6430. *
  6431. * _.drop([1, 2, 3]);
  6432. * // => [2, 3]
  6433. *
  6434. * _.drop([1, 2, 3], 2);
  6435. * // => [3]
  6436. *
  6437. * _.drop([1, 2, 3], 5);
  6438. * // => []
  6439. *
  6440. * _.drop([1, 2, 3], 0);
  6441. * // => [1, 2, 3]
  6442. */
  6443. function drop(array, n, guard) {
  6444. var length = array == null ? 0 : array.length;
  6445. if (!length) {
  6446. return [];
  6447. }
  6448. n = (guard || n === undefined) ? 1 : toInteger(n);
  6449. return baseSlice(array, n < 0 ? 0 : n, length);
  6450. }
  6451. /**
  6452. * Creates a slice of `array` with `n` elements dropped from the end.
  6453. *
  6454. * @static
  6455. * @memberOf _
  6456. * @since 3.0.0
  6457. * @category Array
  6458. * @param {Array} array The array to query.
  6459. * @param {number} [n=1] The number of elements to drop.
  6460. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6461. * @returns {Array} Returns the slice of `array`.
  6462. * @example
  6463. *
  6464. * _.dropRight([1, 2, 3]);
  6465. * // => [1, 2]
  6466. *
  6467. * _.dropRight([1, 2, 3], 2);
  6468. * // => [1]
  6469. *
  6470. * _.dropRight([1, 2, 3], 5);
  6471. * // => []
  6472. *
  6473. * _.dropRight([1, 2, 3], 0);
  6474. * // => [1, 2, 3]
  6475. */
  6476. function dropRight(array, n, guard) {
  6477. var length = array == null ? 0 : array.length;
  6478. if (!length) {
  6479. return [];
  6480. }
  6481. n = (guard || n === undefined) ? 1 : toInteger(n);
  6482. n = length - n;
  6483. return baseSlice(array, 0, n < 0 ? 0 : n);
  6484. }
  6485. /**
  6486. * Creates a slice of `array` excluding elements dropped from the end.
  6487. * Elements are dropped until `predicate` returns falsey. The predicate is
  6488. * invoked with three arguments: (value, index, array).
  6489. *
  6490. * @static
  6491. * @memberOf _
  6492. * @since 3.0.0
  6493. * @category Array
  6494. * @param {Array} array The array to query.
  6495. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6496. * @returns {Array} Returns the slice of `array`.
  6497. * @example
  6498. *
  6499. * var users = [
  6500. * { 'user': 'barney', 'active': true },
  6501. * { 'user': 'fred', 'active': false },
  6502. * { 'user': 'pebbles', 'active': false }
  6503. * ];
  6504. *
  6505. * _.dropRightWhile(users, function(o) { return !o.active; });
  6506. * // => objects for ['barney']
  6507. *
  6508. * // The `_.matches` iteratee shorthand.
  6509. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6510. * // => objects for ['barney', 'fred']
  6511. *
  6512. * // The `_.matchesProperty` iteratee shorthand.
  6513. * _.dropRightWhile(users, ['active', false]);
  6514. * // => objects for ['barney']
  6515. *
  6516. * // The `_.property` iteratee shorthand.
  6517. * _.dropRightWhile(users, 'active');
  6518. * // => objects for ['barney', 'fred', 'pebbles']
  6519. */
  6520. function dropRightWhile(array, predicate) {
  6521. return (array && array.length)
  6522. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6523. : [];
  6524. }
  6525. /**
  6526. * Creates a slice of `array` excluding elements dropped from the beginning.
  6527. * Elements are dropped until `predicate` returns falsey. The predicate is
  6528. * invoked with three arguments: (value, index, array).
  6529. *
  6530. * @static
  6531. * @memberOf _
  6532. * @since 3.0.0
  6533. * @category Array
  6534. * @param {Array} array The array to query.
  6535. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6536. * @returns {Array} Returns the slice of `array`.
  6537. * @example
  6538. *
  6539. * var users = [
  6540. * { 'user': 'barney', 'active': false },
  6541. * { 'user': 'fred', 'active': false },
  6542. * { 'user': 'pebbles', 'active': true }
  6543. * ];
  6544. *
  6545. * _.dropWhile(users, function(o) { return !o.active; });
  6546. * // => objects for ['pebbles']
  6547. *
  6548. * // The `_.matches` iteratee shorthand.
  6549. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6550. * // => objects for ['fred', 'pebbles']
  6551. *
  6552. * // The `_.matchesProperty` iteratee shorthand.
  6553. * _.dropWhile(users, ['active', false]);
  6554. * // => objects for ['pebbles']
  6555. *
  6556. * // The `_.property` iteratee shorthand.
  6557. * _.dropWhile(users, 'active');
  6558. * // => objects for ['barney', 'fred', 'pebbles']
  6559. */
  6560. function dropWhile(array, predicate) {
  6561. return (array && array.length)
  6562. ? baseWhile(array, getIteratee(predicate, 3), true)
  6563. : [];
  6564. }
  6565. /**
  6566. * Fills elements of `array` with `value` from `start` up to, but not
  6567. * including, `end`.
  6568. *
  6569. * **Note:** This method mutates `array`.
  6570. *
  6571. * @static
  6572. * @memberOf _
  6573. * @since 3.2.0
  6574. * @category Array
  6575. * @param {Array} array The array to fill.
  6576. * @param {*} value The value to fill `array` with.
  6577. * @param {number} [start=0] The start position.
  6578. * @param {number} [end=array.length] The end position.
  6579. * @returns {Array} Returns `array`.
  6580. * @example
  6581. *
  6582. * var array = [1, 2, 3];
  6583. *
  6584. * _.fill(array, 'a');
  6585. * console.log(array);
  6586. * // => ['a', 'a', 'a']
  6587. *
  6588. * _.fill(Array(3), 2);
  6589. * // => [2, 2, 2]
  6590. *
  6591. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6592. * // => [4, '*', '*', 10]
  6593. */
  6594. function fill(array, value, start, end) {
  6595. var length = array == null ? 0 : array.length;
  6596. if (!length) {
  6597. return [];
  6598. }
  6599. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6600. start = 0;
  6601. end = length;
  6602. }
  6603. return baseFill(array, value, start, end);
  6604. }
  6605. /**
  6606. * This method is like `_.find` except that it returns the index of the first
  6607. * element `predicate` returns truthy for instead of the element itself.
  6608. *
  6609. * @static
  6610. * @memberOf _
  6611. * @since 1.1.0
  6612. * @category Array
  6613. * @param {Array} array The array to inspect.
  6614. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6615. * @param {number} [fromIndex=0] The index to search from.
  6616. * @returns {number} Returns the index of the found element, else `-1`.
  6617. * @example
  6618. *
  6619. * var users = [
  6620. * { 'user': 'barney', 'active': false },
  6621. * { 'user': 'fred', 'active': false },
  6622. * { 'user': 'pebbles', 'active': true }
  6623. * ];
  6624. *
  6625. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6626. * // => 0
  6627. *
  6628. * // The `_.matches` iteratee shorthand.
  6629. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6630. * // => 1
  6631. *
  6632. * // The `_.matchesProperty` iteratee shorthand.
  6633. * _.findIndex(users, ['active', false]);
  6634. * // => 0
  6635. *
  6636. * // The `_.property` iteratee shorthand.
  6637. * _.findIndex(users, 'active');
  6638. * // => 2
  6639. */
  6640. function findIndex(array, predicate, fromIndex) {
  6641. var length = array == null ? 0 : array.length;
  6642. if (!length) {
  6643. return -1;
  6644. }
  6645. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6646. if (index < 0) {
  6647. index = nativeMax(length + index, 0);
  6648. }
  6649. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6650. }
  6651. /**
  6652. * This method is like `_.findIndex` except that it iterates over elements
  6653. * of `collection` from right to left.
  6654. *
  6655. * @static
  6656. * @memberOf _
  6657. * @since 2.0.0
  6658. * @category Array
  6659. * @param {Array} array The array to inspect.
  6660. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6661. * @param {number} [fromIndex=array.length-1] The index to search from.
  6662. * @returns {number} Returns the index of the found element, else `-1`.
  6663. * @example
  6664. *
  6665. * var users = [
  6666. * { 'user': 'barney', 'active': true },
  6667. * { 'user': 'fred', 'active': false },
  6668. * { 'user': 'pebbles', 'active': false }
  6669. * ];
  6670. *
  6671. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6672. * // => 2
  6673. *
  6674. * // The `_.matches` iteratee shorthand.
  6675. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6676. * // => 0
  6677. *
  6678. * // The `_.matchesProperty` iteratee shorthand.
  6679. * _.findLastIndex(users, ['active', false]);
  6680. * // => 2
  6681. *
  6682. * // The `_.property` iteratee shorthand.
  6683. * _.findLastIndex(users, 'active');
  6684. * // => 0
  6685. */
  6686. function findLastIndex(array, predicate, fromIndex) {
  6687. var length = array == null ? 0 : array.length;
  6688. if (!length) {
  6689. return -1;
  6690. }
  6691. var index = length - 1;
  6692. if (fromIndex !== undefined) {
  6693. index = toInteger(fromIndex);
  6694. index = fromIndex < 0
  6695. ? nativeMax(length + index, 0)
  6696. : nativeMin(index, length - 1);
  6697. }
  6698. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6699. }
  6700. /**
  6701. * Flattens `array` a single level deep.
  6702. *
  6703. * @static
  6704. * @memberOf _
  6705. * @since 0.1.0
  6706. * @category Array
  6707. * @param {Array} array The array to flatten.
  6708. * @returns {Array} Returns the new flattened array.
  6709. * @example
  6710. *
  6711. * _.flatten([1, [2, [3, [4]], 5]]);
  6712. * // => [1, 2, [3, [4]], 5]
  6713. */
  6714. function flatten(array) {
  6715. var length = array == null ? 0 : array.length;
  6716. return length ? baseFlatten(array, 1) : [];
  6717. }
  6718. /**
  6719. * Recursively flattens `array`.
  6720. *
  6721. * @static
  6722. * @memberOf _
  6723. * @since 3.0.0
  6724. * @category Array
  6725. * @param {Array} array The array to flatten.
  6726. * @returns {Array} Returns the new flattened array.
  6727. * @example
  6728. *
  6729. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6730. * // => [1, 2, 3, 4, 5]
  6731. */
  6732. function flattenDeep(array) {
  6733. var length = array == null ? 0 : array.length;
  6734. return length ? baseFlatten(array, INFINITY) : [];
  6735. }
  6736. /**
  6737. * Recursively flatten `array` up to `depth` times.
  6738. *
  6739. * @static
  6740. * @memberOf _
  6741. * @since 4.4.0
  6742. * @category Array
  6743. * @param {Array} array The array to flatten.
  6744. * @param {number} [depth=1] The maximum recursion depth.
  6745. * @returns {Array} Returns the new flattened array.
  6746. * @example
  6747. *
  6748. * var array = [1, [2, [3, [4]], 5]];
  6749. *
  6750. * _.flattenDepth(array, 1);
  6751. * // => [1, 2, [3, [4]], 5]
  6752. *
  6753. * _.flattenDepth(array, 2);
  6754. * // => [1, 2, 3, [4], 5]
  6755. */
  6756. function flattenDepth(array, depth) {
  6757. var length = array == null ? 0 : array.length;
  6758. if (!length) {
  6759. return [];
  6760. }
  6761. depth = depth === undefined ? 1 : toInteger(depth);
  6762. return baseFlatten(array, depth);
  6763. }
  6764. /**
  6765. * The inverse of `_.toPairs`; this method returns an object composed
  6766. * from key-value `pairs`.
  6767. *
  6768. * @static
  6769. * @memberOf _
  6770. * @since 4.0.0
  6771. * @category Array
  6772. * @param {Array} pairs The key-value pairs.
  6773. * @returns {Object} Returns the new object.
  6774. * @example
  6775. *
  6776. * _.fromPairs([['a', 1], ['b', 2]]);
  6777. * // => { 'a': 1, 'b': 2 }
  6778. */
  6779. function fromPairs(pairs) {
  6780. var index = -1,
  6781. length = pairs == null ? 0 : pairs.length,
  6782. result = {};
  6783. while (++index < length) {
  6784. var pair = pairs[index];
  6785. result[pair[0]] = pair[1];
  6786. }
  6787. return result;
  6788. }
  6789. /**
  6790. * Gets the first element of `array`.
  6791. *
  6792. * @static
  6793. * @memberOf _
  6794. * @since 0.1.0
  6795. * @alias first
  6796. * @category Array
  6797. * @param {Array} array The array to query.
  6798. * @returns {*} Returns the first element of `array`.
  6799. * @example
  6800. *
  6801. * _.head([1, 2, 3]);
  6802. * // => 1
  6803. *
  6804. * _.head([]);
  6805. * // => undefined
  6806. */
  6807. function head(array) {
  6808. return (array && array.length) ? array[0] : undefined;
  6809. }
  6810. /**
  6811. * Gets the index at which the first occurrence of `value` is found in `array`
  6812. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6813. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6814. * offset from the end of `array`.
  6815. *
  6816. * @static
  6817. * @memberOf _
  6818. * @since 0.1.0
  6819. * @category Array
  6820. * @param {Array} array The array to inspect.
  6821. * @param {*} value The value to search for.
  6822. * @param {number} [fromIndex=0] The index to search from.
  6823. * @returns {number} Returns the index of the matched value, else `-1`.
  6824. * @example
  6825. *
  6826. * _.indexOf([1, 2, 1, 2], 2);
  6827. * // => 1
  6828. *
  6829. * // Search from the `fromIndex`.
  6830. * _.indexOf([1, 2, 1, 2], 2, 2);
  6831. * // => 3
  6832. */
  6833. function indexOf(array, value, fromIndex) {
  6834. var length = array == null ? 0 : array.length;
  6835. if (!length) {
  6836. return -1;
  6837. }
  6838. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6839. if (index < 0) {
  6840. index = nativeMax(length + index, 0);
  6841. }
  6842. return baseIndexOf(array, value, index);
  6843. }
  6844. /**
  6845. * Gets all but the last element of `array`.
  6846. *
  6847. * @static
  6848. * @memberOf _
  6849. * @since 0.1.0
  6850. * @category Array
  6851. * @param {Array} array The array to query.
  6852. * @returns {Array} Returns the slice of `array`.
  6853. * @example
  6854. *
  6855. * _.initial([1, 2, 3]);
  6856. * // => [1, 2]
  6857. */
  6858. function initial(array) {
  6859. var length = array == null ? 0 : array.length;
  6860. return length ? baseSlice(array, 0, -1) : [];
  6861. }
  6862. /**
  6863. * Creates an array of unique values that are included in all given arrays
  6864. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6865. * for equality comparisons. The order and references of result values are
  6866. * determined by the first array.
  6867. *
  6868. * @static
  6869. * @memberOf _
  6870. * @since 0.1.0
  6871. * @category Array
  6872. * @param {...Array} [arrays] The arrays to inspect.
  6873. * @returns {Array} Returns the new array of intersecting values.
  6874. * @example
  6875. *
  6876. * _.intersection([2, 1], [2, 3]);
  6877. * // => [2]
  6878. */
  6879. var intersection = baseRest(function(arrays) {
  6880. var mapped = arrayMap(arrays, castArrayLikeObject);
  6881. return (mapped.length && mapped[0] === arrays[0])
  6882. ? baseIntersection(mapped)
  6883. : [];
  6884. });
  6885. /**
  6886. * This method is like `_.intersection` except that it accepts `iteratee`
  6887. * which is invoked for each element of each `arrays` to generate the criterion
  6888. * by which they're compared. The order and references of result values are
  6889. * determined by the first array. The iteratee is invoked with one argument:
  6890. * (value).
  6891. *
  6892. * @static
  6893. * @memberOf _
  6894. * @since 4.0.0
  6895. * @category Array
  6896. * @param {...Array} [arrays] The arrays to inspect.
  6897. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6898. * @returns {Array} Returns the new array of intersecting values.
  6899. * @example
  6900. *
  6901. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6902. * // => [2.1]
  6903. *
  6904. * // The `_.property` iteratee shorthand.
  6905. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6906. * // => [{ 'x': 1 }]
  6907. */
  6908. var intersectionBy = baseRest(function(arrays) {
  6909. var iteratee = last(arrays),
  6910. mapped = arrayMap(arrays, castArrayLikeObject);
  6911. if (iteratee === last(mapped)) {
  6912. iteratee = undefined;
  6913. } else {
  6914. mapped.pop();
  6915. }
  6916. return (mapped.length && mapped[0] === arrays[0])
  6917. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6918. : [];
  6919. });
  6920. /**
  6921. * This method is like `_.intersection` except that it accepts `comparator`
  6922. * which is invoked to compare elements of `arrays`. The order and references
  6923. * of result values are determined by the first array. The comparator is
  6924. * invoked with two arguments: (arrVal, othVal).
  6925. *
  6926. * @static
  6927. * @memberOf _
  6928. * @since 4.0.0
  6929. * @category Array
  6930. * @param {...Array} [arrays] The arrays to inspect.
  6931. * @param {Function} [comparator] The comparator invoked per element.
  6932. * @returns {Array} Returns the new array of intersecting values.
  6933. * @example
  6934. *
  6935. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6936. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6937. *
  6938. * _.intersectionWith(objects, others, _.isEqual);
  6939. * // => [{ 'x': 1, 'y': 2 }]
  6940. */
  6941. var intersectionWith = baseRest(function(arrays) {
  6942. var comparator = last(arrays),
  6943. mapped = arrayMap(arrays, castArrayLikeObject);
  6944. comparator = typeof comparator == 'function' ? comparator : undefined;
  6945. if (comparator) {
  6946. mapped.pop();
  6947. }
  6948. return (mapped.length && mapped[0] === arrays[0])
  6949. ? baseIntersection(mapped, undefined, comparator)
  6950. : [];
  6951. });
  6952. /**
  6953. * Converts all elements in `array` into a string separated by `separator`.
  6954. *
  6955. * @static
  6956. * @memberOf _
  6957. * @since 4.0.0
  6958. * @category Array
  6959. * @param {Array} array The array to convert.
  6960. * @param {string} [separator=','] The element separator.
  6961. * @returns {string} Returns the joined string.
  6962. * @example
  6963. *
  6964. * _.join(['a', 'b', 'c'], '~');
  6965. * // => 'a~b~c'
  6966. */
  6967. function join(array, separator) {
  6968. return array == null ? '' : nativeJoin.call(array, separator);
  6969. }
  6970. /**
  6971. * Gets the last element of `array`.
  6972. *
  6973. * @static
  6974. * @memberOf _
  6975. * @since 0.1.0
  6976. * @category Array
  6977. * @param {Array} array The array to query.
  6978. * @returns {*} Returns the last element of `array`.
  6979. * @example
  6980. *
  6981. * _.last([1, 2, 3]);
  6982. * // => 3
  6983. */
  6984. function last(array) {
  6985. var length = array == null ? 0 : array.length;
  6986. return length ? array[length - 1] : undefined;
  6987. }
  6988. /**
  6989. * This method is like `_.indexOf` except that it iterates over elements of
  6990. * `array` from right to left.
  6991. *
  6992. * @static
  6993. * @memberOf _
  6994. * @since 0.1.0
  6995. * @category Array
  6996. * @param {Array} array The array to inspect.
  6997. * @param {*} value The value to search for.
  6998. * @param {number} [fromIndex=array.length-1] The index to search from.
  6999. * @returns {number} Returns the index of the matched value, else `-1`.
  7000. * @example
  7001. *
  7002. * _.lastIndexOf([1, 2, 1, 2], 2);
  7003. * // => 3
  7004. *
  7005. * // Search from the `fromIndex`.
  7006. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7007. * // => 1
  7008. */
  7009. function lastIndexOf(array, value, fromIndex) {
  7010. var length = array == null ? 0 : array.length;
  7011. if (!length) {
  7012. return -1;
  7013. }
  7014. var index = length;
  7015. if (fromIndex !== undefined) {
  7016. index = toInteger(fromIndex);
  7017. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7018. }
  7019. return value === value
  7020. ? strictLastIndexOf(array, value, index)
  7021. : baseFindIndex(array, baseIsNaN, index, true);
  7022. }
  7023. /**
  7024. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7025. * element from the end is returned.
  7026. *
  7027. * @static
  7028. * @memberOf _
  7029. * @since 4.11.0
  7030. * @category Array
  7031. * @param {Array} array The array to query.
  7032. * @param {number} [n=0] The index of the element to return.
  7033. * @returns {*} Returns the nth element of `array`.
  7034. * @example
  7035. *
  7036. * var array = ['a', 'b', 'c', 'd'];
  7037. *
  7038. * _.nth(array, 1);
  7039. * // => 'b'
  7040. *
  7041. * _.nth(array, -2);
  7042. * // => 'c';
  7043. */
  7044. function nth(array, n) {
  7045. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7046. }
  7047. /**
  7048. * Removes all given values from `array` using
  7049. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7050. * for equality comparisons.
  7051. *
  7052. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7053. * to remove elements from an array by predicate.
  7054. *
  7055. * @static
  7056. * @memberOf _
  7057. * @since 2.0.0
  7058. * @category Array
  7059. * @param {Array} array The array to modify.
  7060. * @param {...*} [values] The values to remove.
  7061. * @returns {Array} Returns `array`.
  7062. * @example
  7063. *
  7064. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7065. *
  7066. * _.pull(array, 'a', 'c');
  7067. * console.log(array);
  7068. * // => ['b', 'b']
  7069. */
  7070. var pull = baseRest(pullAll);
  7071. /**
  7072. * This method is like `_.pull` except that it accepts an array of values to remove.
  7073. *
  7074. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7075. *
  7076. * @static
  7077. * @memberOf _
  7078. * @since 4.0.0
  7079. * @category Array
  7080. * @param {Array} array The array to modify.
  7081. * @param {Array} values The values to remove.
  7082. * @returns {Array} Returns `array`.
  7083. * @example
  7084. *
  7085. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7086. *
  7087. * _.pullAll(array, ['a', 'c']);
  7088. * console.log(array);
  7089. * // => ['b', 'b']
  7090. */
  7091. function pullAll(array, values) {
  7092. return (array && array.length && values && values.length)
  7093. ? basePullAll(array, values)
  7094. : array;
  7095. }
  7096. /**
  7097. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7098. * invoked for each element of `array` and `values` to generate the criterion
  7099. * by which they're compared. The iteratee is invoked with one argument: (value).
  7100. *
  7101. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7102. *
  7103. * @static
  7104. * @memberOf _
  7105. * @since 4.0.0
  7106. * @category Array
  7107. * @param {Array} array The array to modify.
  7108. * @param {Array} values The values to remove.
  7109. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7110. * @returns {Array} Returns `array`.
  7111. * @example
  7112. *
  7113. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7114. *
  7115. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7116. * console.log(array);
  7117. * // => [{ 'x': 2 }]
  7118. */
  7119. function pullAllBy(array, values, iteratee) {
  7120. return (array && array.length && values && values.length)
  7121. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7122. : array;
  7123. }
  7124. /**
  7125. * This method is like `_.pullAll` except that it accepts `comparator` which
  7126. * is invoked to compare elements of `array` to `values`. The comparator is
  7127. * invoked with two arguments: (arrVal, othVal).
  7128. *
  7129. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7130. *
  7131. * @static
  7132. * @memberOf _
  7133. * @since 4.6.0
  7134. * @category Array
  7135. * @param {Array} array The array to modify.
  7136. * @param {Array} values The values to remove.
  7137. * @param {Function} [comparator] The comparator invoked per element.
  7138. * @returns {Array} Returns `array`.
  7139. * @example
  7140. *
  7141. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7142. *
  7143. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7144. * console.log(array);
  7145. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7146. */
  7147. function pullAllWith(array, values, comparator) {
  7148. return (array && array.length && values && values.length)
  7149. ? basePullAll(array, values, undefined, comparator)
  7150. : array;
  7151. }
  7152. /**
  7153. * Removes elements from `array` corresponding to `indexes` and returns an
  7154. * array of removed elements.
  7155. *
  7156. * **Note:** Unlike `_.at`, this method mutates `array`.
  7157. *
  7158. * @static
  7159. * @memberOf _
  7160. * @since 3.0.0
  7161. * @category Array
  7162. * @param {Array} array The array to modify.
  7163. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7164. * @returns {Array} Returns the new array of removed elements.
  7165. * @example
  7166. *
  7167. * var array = ['a', 'b', 'c', 'd'];
  7168. * var pulled = _.pullAt(array, [1, 3]);
  7169. *
  7170. * console.log(array);
  7171. * // => ['a', 'c']
  7172. *
  7173. * console.log(pulled);
  7174. * // => ['b', 'd']
  7175. */
  7176. var pullAt = flatRest(function(array, indexes) {
  7177. var length = array == null ? 0 : array.length,
  7178. result = baseAt(array, indexes);
  7179. basePullAt(array, arrayMap(indexes, function(index) {
  7180. return isIndex(index, length) ? +index : index;
  7181. }).sort(compareAscending));
  7182. return result;
  7183. });
  7184. /**
  7185. * Removes all elements from `array` that `predicate` returns truthy for
  7186. * and returns an array of the removed elements. The predicate is invoked
  7187. * with three arguments: (value, index, array).
  7188. *
  7189. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7190. * to pull elements from an array by value.
  7191. *
  7192. * @static
  7193. * @memberOf _
  7194. * @since 2.0.0
  7195. * @category Array
  7196. * @param {Array} array The array to modify.
  7197. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7198. * @returns {Array} Returns the new array of removed elements.
  7199. * @example
  7200. *
  7201. * var array = [1, 2, 3, 4];
  7202. * var evens = _.remove(array, function(n) {
  7203. * return n % 2 == 0;
  7204. * });
  7205. *
  7206. * console.log(array);
  7207. * // => [1, 3]
  7208. *
  7209. * console.log(evens);
  7210. * // => [2, 4]
  7211. */
  7212. function remove(array, predicate) {
  7213. var result = [];
  7214. if (!(array && array.length)) {
  7215. return result;
  7216. }
  7217. var index = -1,
  7218. indexes = [],
  7219. length = array.length;
  7220. predicate = getIteratee(predicate, 3);
  7221. while (++index < length) {
  7222. var value = array[index];
  7223. if (predicate(value, index, array)) {
  7224. result.push(value);
  7225. indexes.push(index);
  7226. }
  7227. }
  7228. basePullAt(array, indexes);
  7229. return result;
  7230. }
  7231. /**
  7232. * Reverses `array` so that the first element becomes the last, the second
  7233. * element becomes the second to last, and so on.
  7234. *
  7235. * **Note:** This method mutates `array` and is based on
  7236. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7237. *
  7238. * @static
  7239. * @memberOf _
  7240. * @since 4.0.0
  7241. * @category Array
  7242. * @param {Array} array The array to modify.
  7243. * @returns {Array} Returns `array`.
  7244. * @example
  7245. *
  7246. * var array = [1, 2, 3];
  7247. *
  7248. * _.reverse(array);
  7249. * // => [3, 2, 1]
  7250. *
  7251. * console.log(array);
  7252. * // => [3, 2, 1]
  7253. */
  7254. function reverse(array) {
  7255. return array == null ? array : nativeReverse.call(array);
  7256. }
  7257. /**
  7258. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7259. *
  7260. * **Note:** This method is used instead of
  7261. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7262. * returned.
  7263. *
  7264. * @static
  7265. * @memberOf _
  7266. * @since 3.0.0
  7267. * @category Array
  7268. * @param {Array} array The array to slice.
  7269. * @param {number} [start=0] The start position.
  7270. * @param {number} [end=array.length] The end position.
  7271. * @returns {Array} Returns the slice of `array`.
  7272. */
  7273. function slice(array, start, end) {
  7274. var length = array == null ? 0 : array.length;
  7275. if (!length) {
  7276. return [];
  7277. }
  7278. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7279. start = 0;
  7280. end = length;
  7281. }
  7282. else {
  7283. start = start == null ? 0 : toInteger(start);
  7284. end = end === undefined ? length : toInteger(end);
  7285. }
  7286. return baseSlice(array, start, end);
  7287. }
  7288. /**
  7289. * Uses a binary search to determine the lowest index at which `value`
  7290. * should be inserted into `array` in order to maintain its sort order.
  7291. *
  7292. * @static
  7293. * @memberOf _
  7294. * @since 0.1.0
  7295. * @category Array
  7296. * @param {Array} array The sorted array to inspect.
  7297. * @param {*} value The value to evaluate.
  7298. * @returns {number} Returns the index at which `value` should be inserted
  7299. * into `array`.
  7300. * @example
  7301. *
  7302. * _.sortedIndex([30, 50], 40);
  7303. * // => 1
  7304. */
  7305. function sortedIndex(array, value) {
  7306. return baseSortedIndex(array, value);
  7307. }
  7308. /**
  7309. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7310. * which is invoked for `value` and each element of `array` to compute their
  7311. * sort ranking. The iteratee is invoked with one argument: (value).
  7312. *
  7313. * @static
  7314. * @memberOf _
  7315. * @since 4.0.0
  7316. * @category Array
  7317. * @param {Array} array The sorted array to inspect.
  7318. * @param {*} value The value to evaluate.
  7319. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7320. * @returns {number} Returns the index at which `value` should be inserted
  7321. * into `array`.
  7322. * @example
  7323. *
  7324. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7325. *
  7326. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7327. * // => 0
  7328. *
  7329. * // The `_.property` iteratee shorthand.
  7330. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7331. * // => 0
  7332. */
  7333. function sortedIndexBy(array, value, iteratee) {
  7334. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7335. }
  7336. /**
  7337. * This method is like `_.indexOf` except that it performs a binary
  7338. * search on a sorted `array`.
  7339. *
  7340. * @static
  7341. * @memberOf _
  7342. * @since 4.0.0
  7343. * @category Array
  7344. * @param {Array} array The array to inspect.
  7345. * @param {*} value The value to search for.
  7346. * @returns {number} Returns the index of the matched value, else `-1`.
  7347. * @example
  7348. *
  7349. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7350. * // => 1
  7351. */
  7352. function sortedIndexOf(array, value) {
  7353. var length = array == null ? 0 : array.length;
  7354. if (length) {
  7355. var index = baseSortedIndex(array, value);
  7356. if (index < length && eq(array[index], value)) {
  7357. return index;
  7358. }
  7359. }
  7360. return -1;
  7361. }
  7362. /**
  7363. * This method is like `_.sortedIndex` except that it returns the highest
  7364. * index at which `value` should be inserted into `array` in order to
  7365. * maintain its sort order.
  7366. *
  7367. * @static
  7368. * @memberOf _
  7369. * @since 3.0.0
  7370. * @category Array
  7371. * @param {Array} array The sorted array to inspect.
  7372. * @param {*} value The value to evaluate.
  7373. * @returns {number} Returns the index at which `value` should be inserted
  7374. * into `array`.
  7375. * @example
  7376. *
  7377. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7378. * // => 4
  7379. */
  7380. function sortedLastIndex(array, value) {
  7381. return baseSortedIndex(array, value, true);
  7382. }
  7383. /**
  7384. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7385. * which is invoked for `value` and each element of `array` to compute their
  7386. * sort ranking. The iteratee is invoked with one argument: (value).
  7387. *
  7388. * @static
  7389. * @memberOf _
  7390. * @since 4.0.0
  7391. * @category Array
  7392. * @param {Array} array The sorted array to inspect.
  7393. * @param {*} value The value to evaluate.
  7394. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7395. * @returns {number} Returns the index at which `value` should be inserted
  7396. * into `array`.
  7397. * @example
  7398. *
  7399. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7400. *
  7401. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7402. * // => 1
  7403. *
  7404. * // The `_.property` iteratee shorthand.
  7405. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7406. * // => 1
  7407. */
  7408. function sortedLastIndexBy(array, value, iteratee) {
  7409. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7410. }
  7411. /**
  7412. * This method is like `_.lastIndexOf` except that it performs a binary
  7413. * search on a sorted `array`.
  7414. *
  7415. * @static
  7416. * @memberOf _
  7417. * @since 4.0.0
  7418. * @category Array
  7419. * @param {Array} array The array to inspect.
  7420. * @param {*} value The value to search for.
  7421. * @returns {number} Returns the index of the matched value, else `-1`.
  7422. * @example
  7423. *
  7424. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7425. * // => 3
  7426. */
  7427. function sortedLastIndexOf(array, value) {
  7428. var length = array == null ? 0 : array.length;
  7429. if (length) {
  7430. var index = baseSortedIndex(array, value, true) - 1;
  7431. if (eq(array[index], value)) {
  7432. return index;
  7433. }
  7434. }
  7435. return -1;
  7436. }
  7437. /**
  7438. * This method is like `_.uniq` except that it's designed and optimized
  7439. * for sorted arrays.
  7440. *
  7441. * @static
  7442. * @memberOf _
  7443. * @since 4.0.0
  7444. * @category Array
  7445. * @param {Array} array The array to inspect.
  7446. * @returns {Array} Returns the new duplicate free array.
  7447. * @example
  7448. *
  7449. * _.sortedUniq([1, 1, 2]);
  7450. * // => [1, 2]
  7451. */
  7452. function sortedUniq(array) {
  7453. return (array && array.length)
  7454. ? baseSortedUniq(array)
  7455. : [];
  7456. }
  7457. /**
  7458. * This method is like `_.uniqBy` except that it's designed and optimized
  7459. * for sorted arrays.
  7460. *
  7461. * @static
  7462. * @memberOf _
  7463. * @since 4.0.0
  7464. * @category Array
  7465. * @param {Array} array The array to inspect.
  7466. * @param {Function} [iteratee] The iteratee invoked per element.
  7467. * @returns {Array} Returns the new duplicate free array.
  7468. * @example
  7469. *
  7470. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7471. * // => [1.1, 2.3]
  7472. */
  7473. function sortedUniqBy(array, iteratee) {
  7474. return (array && array.length)
  7475. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7476. : [];
  7477. }
  7478. /**
  7479. * Gets all but the first element of `array`.
  7480. *
  7481. * @static
  7482. * @memberOf _
  7483. * @since 4.0.0
  7484. * @category Array
  7485. * @param {Array} array The array to query.
  7486. * @returns {Array} Returns the slice of `array`.
  7487. * @example
  7488. *
  7489. * _.tail([1, 2, 3]);
  7490. * // => [2, 3]
  7491. */
  7492. function tail(array) {
  7493. var length = array == null ? 0 : array.length;
  7494. return length ? baseSlice(array, 1, length) : [];
  7495. }
  7496. /**
  7497. * Creates a slice of `array` with `n` elements taken from the beginning.
  7498. *
  7499. * @static
  7500. * @memberOf _
  7501. * @since 0.1.0
  7502. * @category Array
  7503. * @param {Array} array The array to query.
  7504. * @param {number} [n=1] The number of elements to take.
  7505. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7506. * @returns {Array} Returns the slice of `array`.
  7507. * @example
  7508. *
  7509. * _.take([1, 2, 3]);
  7510. * // => [1]
  7511. *
  7512. * _.take([1, 2, 3], 2);
  7513. * // => [1, 2]
  7514. *
  7515. * _.take([1, 2, 3], 5);
  7516. * // => [1, 2, 3]
  7517. *
  7518. * _.take([1, 2, 3], 0);
  7519. * // => []
  7520. */
  7521. function take(array, n, guard) {
  7522. if (!(array && array.length)) {
  7523. return [];
  7524. }
  7525. n = (guard || n === undefined) ? 1 : toInteger(n);
  7526. return baseSlice(array, 0, n < 0 ? 0 : n);
  7527. }
  7528. /**
  7529. * Creates a slice of `array` with `n` elements taken from the end.
  7530. *
  7531. * @static
  7532. * @memberOf _
  7533. * @since 3.0.0
  7534. * @category Array
  7535. * @param {Array} array The array to query.
  7536. * @param {number} [n=1] The number of elements to take.
  7537. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7538. * @returns {Array} Returns the slice of `array`.
  7539. * @example
  7540. *
  7541. * _.takeRight([1, 2, 3]);
  7542. * // => [3]
  7543. *
  7544. * _.takeRight([1, 2, 3], 2);
  7545. * // => [2, 3]
  7546. *
  7547. * _.takeRight([1, 2, 3], 5);
  7548. * // => [1, 2, 3]
  7549. *
  7550. * _.takeRight([1, 2, 3], 0);
  7551. * // => []
  7552. */
  7553. function takeRight(array, n, guard) {
  7554. var length = array == null ? 0 : array.length;
  7555. if (!length) {
  7556. return [];
  7557. }
  7558. n = (guard || n === undefined) ? 1 : toInteger(n);
  7559. n = length - n;
  7560. return baseSlice(array, n < 0 ? 0 : n, length);
  7561. }
  7562. /**
  7563. * Creates a slice of `array` with elements taken from the end. Elements are
  7564. * taken until `predicate` returns falsey. The predicate is invoked with
  7565. * three arguments: (value, index, array).
  7566. *
  7567. * @static
  7568. * @memberOf _
  7569. * @since 3.0.0
  7570. * @category Array
  7571. * @param {Array} array The array to query.
  7572. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7573. * @returns {Array} Returns the slice of `array`.
  7574. * @example
  7575. *
  7576. * var users = [
  7577. * { 'user': 'barney', 'active': true },
  7578. * { 'user': 'fred', 'active': false },
  7579. * { 'user': 'pebbles', 'active': false }
  7580. * ];
  7581. *
  7582. * _.takeRightWhile(users, function(o) { return !o.active; });
  7583. * // => objects for ['fred', 'pebbles']
  7584. *
  7585. * // The `_.matches` iteratee shorthand.
  7586. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7587. * // => objects for ['pebbles']
  7588. *
  7589. * // The `_.matchesProperty` iteratee shorthand.
  7590. * _.takeRightWhile(users, ['active', false]);
  7591. * // => objects for ['fred', 'pebbles']
  7592. *
  7593. * // The `_.property` iteratee shorthand.
  7594. * _.takeRightWhile(users, 'active');
  7595. * // => []
  7596. */
  7597. function takeRightWhile(array, predicate) {
  7598. return (array && array.length)
  7599. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7600. : [];
  7601. }
  7602. /**
  7603. * Creates a slice of `array` with elements taken from the beginning. Elements
  7604. * are taken until `predicate` returns falsey. The predicate is invoked with
  7605. * three arguments: (value, index, array).
  7606. *
  7607. * @static
  7608. * @memberOf _
  7609. * @since 3.0.0
  7610. * @category Array
  7611. * @param {Array} array The array to query.
  7612. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7613. * @returns {Array} Returns the slice of `array`.
  7614. * @example
  7615. *
  7616. * var users = [
  7617. * { 'user': 'barney', 'active': false },
  7618. * { 'user': 'fred', 'active': false },
  7619. * { 'user': 'pebbles', 'active': true }
  7620. * ];
  7621. *
  7622. * _.takeWhile(users, function(o) { return !o.active; });
  7623. * // => objects for ['barney', 'fred']
  7624. *
  7625. * // The `_.matches` iteratee shorthand.
  7626. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7627. * // => objects for ['barney']
  7628. *
  7629. * // The `_.matchesProperty` iteratee shorthand.
  7630. * _.takeWhile(users, ['active', false]);
  7631. * // => objects for ['barney', 'fred']
  7632. *
  7633. * // The `_.property` iteratee shorthand.
  7634. * _.takeWhile(users, 'active');
  7635. * // => []
  7636. */
  7637. function takeWhile(array, predicate) {
  7638. return (array && array.length)
  7639. ? baseWhile(array, getIteratee(predicate, 3))
  7640. : [];
  7641. }
  7642. /**
  7643. * Creates an array of unique values, in order, from all given arrays using
  7644. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7645. * for equality comparisons.
  7646. *
  7647. * @static
  7648. * @memberOf _
  7649. * @since 0.1.0
  7650. * @category Array
  7651. * @param {...Array} [arrays] The arrays to inspect.
  7652. * @returns {Array} Returns the new array of combined values.
  7653. * @example
  7654. *
  7655. * _.union([2], [1, 2]);
  7656. * // => [2, 1]
  7657. */
  7658. var union = baseRest(function(arrays) {
  7659. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7660. });
  7661. /**
  7662. * This method is like `_.union` except that it accepts `iteratee` which is
  7663. * invoked for each element of each `arrays` to generate the criterion by
  7664. * which uniqueness is computed. Result values are chosen from the first
  7665. * array in which the value occurs. The iteratee is invoked with one argument:
  7666. * (value).
  7667. *
  7668. * @static
  7669. * @memberOf _
  7670. * @since 4.0.0
  7671. * @category Array
  7672. * @param {...Array} [arrays] The arrays to inspect.
  7673. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7674. * @returns {Array} Returns the new array of combined values.
  7675. * @example
  7676. *
  7677. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7678. * // => [2.1, 1.2]
  7679. *
  7680. * // The `_.property` iteratee shorthand.
  7681. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7682. * // => [{ 'x': 1 }, { 'x': 2 }]
  7683. */
  7684. var unionBy = baseRest(function(arrays) {
  7685. var iteratee = last(arrays);
  7686. if (isArrayLikeObject(iteratee)) {
  7687. iteratee = undefined;
  7688. }
  7689. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7690. });
  7691. /**
  7692. * This method is like `_.union` except that it accepts `comparator` which
  7693. * is invoked to compare elements of `arrays`. Result values are chosen from
  7694. * the first array in which the value occurs. The comparator is invoked
  7695. * with two arguments: (arrVal, othVal).
  7696. *
  7697. * @static
  7698. * @memberOf _
  7699. * @since 4.0.0
  7700. * @category Array
  7701. * @param {...Array} [arrays] The arrays to inspect.
  7702. * @param {Function} [comparator] The comparator invoked per element.
  7703. * @returns {Array} Returns the new array of combined values.
  7704. * @example
  7705. *
  7706. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7707. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7708. *
  7709. * _.unionWith(objects, others, _.isEqual);
  7710. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7711. */
  7712. var unionWith = baseRest(function(arrays) {
  7713. var comparator = last(arrays);
  7714. comparator = typeof comparator == 'function' ? comparator : undefined;
  7715. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7716. });
  7717. /**
  7718. * Creates a duplicate-free version of an array, using
  7719. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7720. * for equality comparisons, in which only the first occurrence of each element
  7721. * is kept. The order of result values is determined by the order they occur
  7722. * in the array.
  7723. *
  7724. * @static
  7725. * @memberOf _
  7726. * @since 0.1.0
  7727. * @category Array
  7728. * @param {Array} array The array to inspect.
  7729. * @returns {Array} Returns the new duplicate free array.
  7730. * @example
  7731. *
  7732. * _.uniq([2, 1, 2]);
  7733. * // => [2, 1]
  7734. */
  7735. function uniq(array) {
  7736. return (array && array.length) ? baseUniq(array) : [];
  7737. }
  7738. /**
  7739. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7740. * invoked for each element in `array` to generate the criterion by which
  7741. * uniqueness is computed. The order of result values is determined by the
  7742. * order they occur in the array. The iteratee is invoked with one argument:
  7743. * (value).
  7744. *
  7745. * @static
  7746. * @memberOf _
  7747. * @since 4.0.0
  7748. * @category Array
  7749. * @param {Array} array The array to inspect.
  7750. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7751. * @returns {Array} Returns the new duplicate free array.
  7752. * @example
  7753. *
  7754. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7755. * // => [2.1, 1.2]
  7756. *
  7757. * // The `_.property` iteratee shorthand.
  7758. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7759. * // => [{ 'x': 1 }, { 'x': 2 }]
  7760. */
  7761. function uniqBy(array, iteratee) {
  7762. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7763. }
  7764. /**
  7765. * This method is like `_.uniq` except that it accepts `comparator` which
  7766. * is invoked to compare elements of `array`. The order of result values is
  7767. * determined by the order they occur in the array.The comparator is invoked
  7768. * with two arguments: (arrVal, othVal).
  7769. *
  7770. * @static
  7771. * @memberOf _
  7772. * @since 4.0.0
  7773. * @category Array
  7774. * @param {Array} array The array to inspect.
  7775. * @param {Function} [comparator] The comparator invoked per element.
  7776. * @returns {Array} Returns the new duplicate free array.
  7777. * @example
  7778. *
  7779. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7780. *
  7781. * _.uniqWith(objects, _.isEqual);
  7782. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7783. */
  7784. function uniqWith(array, comparator) {
  7785. comparator = typeof comparator == 'function' ? comparator : undefined;
  7786. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7787. }
  7788. /**
  7789. * This method is like `_.zip` except that it accepts an array of grouped
  7790. * elements and creates an array regrouping the elements to their pre-zip
  7791. * configuration.
  7792. *
  7793. * @static
  7794. * @memberOf _
  7795. * @since 1.2.0
  7796. * @category Array
  7797. * @param {Array} array The array of grouped elements to process.
  7798. * @returns {Array} Returns the new array of regrouped elements.
  7799. * @example
  7800. *
  7801. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7802. * // => [['a', 1, true], ['b', 2, false]]
  7803. *
  7804. * _.unzip(zipped);
  7805. * // => [['a', 'b'], [1, 2], [true, false]]
  7806. */
  7807. function unzip(array) {
  7808. if (!(array && array.length)) {
  7809. return [];
  7810. }
  7811. var length = 0;
  7812. array = arrayFilter(array, function(group) {
  7813. if (isArrayLikeObject(group)) {
  7814. length = nativeMax(group.length, length);
  7815. return true;
  7816. }
  7817. });
  7818. return baseTimes(length, function(index) {
  7819. return arrayMap(array, baseProperty(index));
  7820. });
  7821. }
  7822. /**
  7823. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7824. * how regrouped values should be combined. The iteratee is invoked with the
  7825. * elements of each group: (...group).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 3.8.0
  7830. * @category Array
  7831. * @param {Array} array The array of grouped elements to process.
  7832. * @param {Function} [iteratee=_.identity] The function to combine
  7833. * regrouped values.
  7834. * @returns {Array} Returns the new array of regrouped elements.
  7835. * @example
  7836. *
  7837. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7838. * // => [[1, 10, 100], [2, 20, 200]]
  7839. *
  7840. * _.unzipWith(zipped, _.add);
  7841. * // => [3, 30, 300]
  7842. */
  7843. function unzipWith(array, iteratee) {
  7844. if (!(array && array.length)) {
  7845. return [];
  7846. }
  7847. var result = unzip(array);
  7848. if (iteratee == null) {
  7849. return result;
  7850. }
  7851. return arrayMap(result, function(group) {
  7852. return apply(iteratee, undefined, group);
  7853. });
  7854. }
  7855. /**
  7856. * Creates an array excluding all given values using
  7857. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7858. * for equality comparisons.
  7859. *
  7860. * **Note:** Unlike `_.pull`, this method returns a new array.
  7861. *
  7862. * @static
  7863. * @memberOf _
  7864. * @since 0.1.0
  7865. * @category Array
  7866. * @param {Array} array The array to inspect.
  7867. * @param {...*} [values] The values to exclude.
  7868. * @returns {Array} Returns the new array of filtered values.
  7869. * @see _.difference, _.xor
  7870. * @example
  7871. *
  7872. * _.without([2, 1, 2, 3], 1, 2);
  7873. * // => [3]
  7874. */
  7875. var without = baseRest(function(array, values) {
  7876. return isArrayLikeObject(array)
  7877. ? baseDifference(array, values)
  7878. : [];
  7879. });
  7880. /**
  7881. * Creates an array of unique values that is the
  7882. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7883. * of the given arrays. The order of result values is determined by the order
  7884. * they occur in the arrays.
  7885. *
  7886. * @static
  7887. * @memberOf _
  7888. * @since 2.4.0
  7889. * @category Array
  7890. * @param {...Array} [arrays] The arrays to inspect.
  7891. * @returns {Array} Returns the new array of filtered values.
  7892. * @see _.difference, _.without
  7893. * @example
  7894. *
  7895. * _.xor([2, 1], [2, 3]);
  7896. * // => [1, 3]
  7897. */
  7898. var xor = baseRest(function(arrays) {
  7899. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7900. });
  7901. /**
  7902. * This method is like `_.xor` except that it accepts `iteratee` which is
  7903. * invoked for each element of each `arrays` to generate the criterion by
  7904. * which by which they're compared. The order of result values is determined
  7905. * by the order they occur in the arrays. The iteratee is invoked with one
  7906. * argument: (value).
  7907. *
  7908. * @static
  7909. * @memberOf _
  7910. * @since 4.0.0
  7911. * @category Array
  7912. * @param {...Array} [arrays] The arrays to inspect.
  7913. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7914. * @returns {Array} Returns the new array of filtered values.
  7915. * @example
  7916. *
  7917. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7918. * // => [1.2, 3.4]
  7919. *
  7920. * // The `_.property` iteratee shorthand.
  7921. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7922. * // => [{ 'x': 2 }]
  7923. */
  7924. var xorBy = baseRest(function(arrays) {
  7925. var iteratee = last(arrays);
  7926. if (isArrayLikeObject(iteratee)) {
  7927. iteratee = undefined;
  7928. }
  7929. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7930. });
  7931. /**
  7932. * This method is like `_.xor` except that it accepts `comparator` which is
  7933. * invoked to compare elements of `arrays`. The order of result values is
  7934. * determined by the order they occur in the arrays. The comparator is invoked
  7935. * with two arguments: (arrVal, othVal).
  7936. *
  7937. * @static
  7938. * @memberOf _
  7939. * @since 4.0.0
  7940. * @category Array
  7941. * @param {...Array} [arrays] The arrays to inspect.
  7942. * @param {Function} [comparator] The comparator invoked per element.
  7943. * @returns {Array} Returns the new array of filtered values.
  7944. * @example
  7945. *
  7946. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7947. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7948. *
  7949. * _.xorWith(objects, others, _.isEqual);
  7950. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7951. */
  7952. var xorWith = baseRest(function(arrays) {
  7953. var comparator = last(arrays);
  7954. comparator = typeof comparator == 'function' ? comparator : undefined;
  7955. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7956. });
  7957. /**
  7958. * Creates an array of grouped elements, the first of which contains the
  7959. * first elements of the given arrays, the second of which contains the
  7960. * second elements of the given arrays, and so on.
  7961. *
  7962. * @static
  7963. * @memberOf _
  7964. * @since 0.1.0
  7965. * @category Array
  7966. * @param {...Array} [arrays] The arrays to process.
  7967. * @returns {Array} Returns the new array of grouped elements.
  7968. * @example
  7969. *
  7970. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7971. * // => [['a', 1, true], ['b', 2, false]]
  7972. */
  7973. var zip = baseRest(unzip);
  7974. /**
  7975. * This method is like `_.fromPairs` except that it accepts two arrays,
  7976. * one of property identifiers and one of corresponding values.
  7977. *
  7978. * @static
  7979. * @memberOf _
  7980. * @since 0.4.0
  7981. * @category Array
  7982. * @param {Array} [props=[]] The property identifiers.
  7983. * @param {Array} [values=[]] The property values.
  7984. * @returns {Object} Returns the new object.
  7985. * @example
  7986. *
  7987. * _.zipObject(['a', 'b'], [1, 2]);
  7988. * // => { 'a': 1, 'b': 2 }
  7989. */
  7990. function zipObject(props, values) {
  7991. return baseZipObject(props || [], values || [], assignValue);
  7992. }
  7993. /**
  7994. * This method is like `_.zipObject` except that it supports property paths.
  7995. *
  7996. * @static
  7997. * @memberOf _
  7998. * @since 4.1.0
  7999. * @category Array
  8000. * @param {Array} [props=[]] The property identifiers.
  8001. * @param {Array} [values=[]] The property values.
  8002. * @returns {Object} Returns the new object.
  8003. * @example
  8004. *
  8005. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8006. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8007. */
  8008. function zipObjectDeep(props, values) {
  8009. return baseZipObject(props || [], values || [], baseSet);
  8010. }
  8011. /**
  8012. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8013. * how grouped values should be combined. The iteratee is invoked with the
  8014. * elements of each group: (...group).
  8015. *
  8016. * @static
  8017. * @memberOf _
  8018. * @since 3.8.0
  8019. * @category Array
  8020. * @param {...Array} [arrays] The arrays to process.
  8021. * @param {Function} [iteratee=_.identity] The function to combine
  8022. * grouped values.
  8023. * @returns {Array} Returns the new array of grouped elements.
  8024. * @example
  8025. *
  8026. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8027. * return a + b + c;
  8028. * });
  8029. * // => [111, 222]
  8030. */
  8031. var zipWith = baseRest(function(arrays) {
  8032. var length = arrays.length,
  8033. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8034. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8035. return unzipWith(arrays, iteratee);
  8036. });
  8037. /*------------------------------------------------------------------------*/
  8038. /**
  8039. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8040. * chain sequences enabled. The result of such sequences must be unwrapped
  8041. * with `_#value`.
  8042. *
  8043. * @static
  8044. * @memberOf _
  8045. * @since 1.3.0
  8046. * @category Seq
  8047. * @param {*} value The value to wrap.
  8048. * @returns {Object} Returns the new `lodash` wrapper instance.
  8049. * @example
  8050. *
  8051. * var users = [
  8052. * { 'user': 'barney', 'age': 36 },
  8053. * { 'user': 'fred', 'age': 40 },
  8054. * { 'user': 'pebbles', 'age': 1 }
  8055. * ];
  8056. *
  8057. * var youngest = _
  8058. * .chain(users)
  8059. * .sortBy('age')
  8060. * .map(function(o) {
  8061. * return o.user + ' is ' + o.age;
  8062. * })
  8063. * .head()
  8064. * .value();
  8065. * // => 'pebbles is 1'
  8066. */
  8067. function chain(value) {
  8068. var result = lodash(value);
  8069. result.__chain__ = true;
  8070. return result;
  8071. }
  8072. /**
  8073. * This method invokes `interceptor` and returns `value`. The interceptor
  8074. * is invoked with one argument; (value). The purpose of this method is to
  8075. * "tap into" a method chain sequence in order to modify intermediate results.
  8076. *
  8077. * @static
  8078. * @memberOf _
  8079. * @since 0.1.0
  8080. * @category Seq
  8081. * @param {*} value The value to provide to `interceptor`.
  8082. * @param {Function} interceptor The function to invoke.
  8083. * @returns {*} Returns `value`.
  8084. * @example
  8085. *
  8086. * _([1, 2, 3])
  8087. * .tap(function(array) {
  8088. * // Mutate input array.
  8089. * array.pop();
  8090. * })
  8091. * .reverse()
  8092. * .value();
  8093. * // => [2, 1]
  8094. */
  8095. function tap(value, interceptor) {
  8096. interceptor(value);
  8097. return value;
  8098. }
  8099. /**
  8100. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8101. * The purpose of this method is to "pass thru" values replacing intermediate
  8102. * results in a method chain sequence.
  8103. *
  8104. * @static
  8105. * @memberOf _
  8106. * @since 3.0.0
  8107. * @category Seq
  8108. * @param {*} value The value to provide to `interceptor`.
  8109. * @param {Function} interceptor The function to invoke.
  8110. * @returns {*} Returns the result of `interceptor`.
  8111. * @example
  8112. *
  8113. * _(' abc ')
  8114. * .chain()
  8115. * .trim()
  8116. * .thru(function(value) {
  8117. * return [value];
  8118. * })
  8119. * .value();
  8120. * // => ['abc']
  8121. */
  8122. function thru(value, interceptor) {
  8123. return interceptor(value);
  8124. }
  8125. /**
  8126. * This method is the wrapper version of `_.at`.
  8127. *
  8128. * @name at
  8129. * @memberOf _
  8130. * @since 1.0.0
  8131. * @category Seq
  8132. * @param {...(string|string[])} [paths] The property paths to pick.
  8133. * @returns {Object} Returns the new `lodash` wrapper instance.
  8134. * @example
  8135. *
  8136. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8137. *
  8138. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8139. * // => [3, 4]
  8140. */
  8141. var wrapperAt = flatRest(function(paths) {
  8142. var length = paths.length,
  8143. start = length ? paths[0] : 0,
  8144. value = this.__wrapped__,
  8145. interceptor = function(object) { return baseAt(object, paths); };
  8146. if (length > 1 || this.__actions__.length ||
  8147. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8148. return this.thru(interceptor);
  8149. }
  8150. value = value.slice(start, +start + (length ? 1 : 0));
  8151. value.__actions__.push({
  8152. 'func': thru,
  8153. 'args': [interceptor],
  8154. 'thisArg': undefined
  8155. });
  8156. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8157. if (length && !array.length) {
  8158. array.push(undefined);
  8159. }
  8160. return array;
  8161. });
  8162. });
  8163. /**
  8164. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8165. *
  8166. * @name chain
  8167. * @memberOf _
  8168. * @since 0.1.0
  8169. * @category Seq
  8170. * @returns {Object} Returns the new `lodash` wrapper instance.
  8171. * @example
  8172. *
  8173. * var users = [
  8174. * { 'user': 'barney', 'age': 36 },
  8175. * { 'user': 'fred', 'age': 40 }
  8176. * ];
  8177. *
  8178. * // A sequence without explicit chaining.
  8179. * _(users).head();
  8180. * // => { 'user': 'barney', 'age': 36 }
  8181. *
  8182. * // A sequence with explicit chaining.
  8183. * _(users)
  8184. * .chain()
  8185. * .head()
  8186. * .pick('user')
  8187. * .value();
  8188. * // => { 'user': 'barney' }
  8189. */
  8190. function wrapperChain() {
  8191. return chain(this);
  8192. }
  8193. /**
  8194. * Executes the chain sequence and returns the wrapped result.
  8195. *
  8196. * @name commit
  8197. * @memberOf _
  8198. * @since 3.2.0
  8199. * @category Seq
  8200. * @returns {Object} Returns the new `lodash` wrapper instance.
  8201. * @example
  8202. *
  8203. * var array = [1, 2];
  8204. * var wrapped = _(array).push(3);
  8205. *
  8206. * console.log(array);
  8207. * // => [1, 2]
  8208. *
  8209. * wrapped = wrapped.commit();
  8210. * console.log(array);
  8211. * // => [1, 2, 3]
  8212. *
  8213. * wrapped.last();
  8214. * // => 3
  8215. *
  8216. * console.log(array);
  8217. * // => [1, 2, 3]
  8218. */
  8219. function wrapperCommit() {
  8220. return new LodashWrapper(this.value(), this.__chain__);
  8221. }
  8222. /**
  8223. * Gets the next value on a wrapped object following the
  8224. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8225. *
  8226. * @name next
  8227. * @memberOf _
  8228. * @since 4.0.0
  8229. * @category Seq
  8230. * @returns {Object} Returns the next iterator value.
  8231. * @example
  8232. *
  8233. * var wrapped = _([1, 2]);
  8234. *
  8235. * wrapped.next();
  8236. * // => { 'done': false, 'value': 1 }
  8237. *
  8238. * wrapped.next();
  8239. * // => { 'done': false, 'value': 2 }
  8240. *
  8241. * wrapped.next();
  8242. * // => { 'done': true, 'value': undefined }
  8243. */
  8244. function wrapperNext() {
  8245. if (this.__values__ === undefined) {
  8246. this.__values__ = toArray(this.value());
  8247. }
  8248. var done = this.__index__ >= this.__values__.length,
  8249. value = done ? undefined : this.__values__[this.__index__++];
  8250. return { 'done': done, 'value': value };
  8251. }
  8252. /**
  8253. * Enables the wrapper to be iterable.
  8254. *
  8255. * @name Symbol.iterator
  8256. * @memberOf _
  8257. * @since 4.0.0
  8258. * @category Seq
  8259. * @returns {Object} Returns the wrapper object.
  8260. * @example
  8261. *
  8262. * var wrapped = _([1, 2]);
  8263. *
  8264. * wrapped[Symbol.iterator]() === wrapped;
  8265. * // => true
  8266. *
  8267. * Array.from(wrapped);
  8268. * // => [1, 2]
  8269. */
  8270. function wrapperToIterator() {
  8271. return this;
  8272. }
  8273. /**
  8274. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8275. *
  8276. * @name plant
  8277. * @memberOf _
  8278. * @since 3.2.0
  8279. * @category Seq
  8280. * @param {*} value The value to plant.
  8281. * @returns {Object} Returns the new `lodash` wrapper instance.
  8282. * @example
  8283. *
  8284. * function square(n) {
  8285. * return n * n;
  8286. * }
  8287. *
  8288. * var wrapped = _([1, 2]).map(square);
  8289. * var other = wrapped.plant([3, 4]);
  8290. *
  8291. * other.value();
  8292. * // => [9, 16]
  8293. *
  8294. * wrapped.value();
  8295. * // => [1, 4]
  8296. */
  8297. function wrapperPlant(value) {
  8298. var result,
  8299. parent = this;
  8300. while (parent instanceof baseLodash) {
  8301. var clone = wrapperClone(parent);
  8302. clone.__index__ = 0;
  8303. clone.__values__ = undefined;
  8304. if (result) {
  8305. previous.__wrapped__ = clone;
  8306. } else {
  8307. result = clone;
  8308. }
  8309. var previous = clone;
  8310. parent = parent.__wrapped__;
  8311. }
  8312. previous.__wrapped__ = value;
  8313. return result;
  8314. }
  8315. /**
  8316. * This method is the wrapper version of `_.reverse`.
  8317. *
  8318. * **Note:** This method mutates the wrapped array.
  8319. *
  8320. * @name reverse
  8321. * @memberOf _
  8322. * @since 0.1.0
  8323. * @category Seq
  8324. * @returns {Object} Returns the new `lodash` wrapper instance.
  8325. * @example
  8326. *
  8327. * var array = [1, 2, 3];
  8328. *
  8329. * _(array).reverse().value()
  8330. * // => [3, 2, 1]
  8331. *
  8332. * console.log(array);
  8333. * // => [3, 2, 1]
  8334. */
  8335. function wrapperReverse() {
  8336. var value = this.__wrapped__;
  8337. if (value instanceof LazyWrapper) {
  8338. var wrapped = value;
  8339. if (this.__actions__.length) {
  8340. wrapped = new LazyWrapper(this);
  8341. }
  8342. wrapped = wrapped.reverse();
  8343. wrapped.__actions__.push({
  8344. 'func': thru,
  8345. 'args': [reverse],
  8346. 'thisArg': undefined
  8347. });
  8348. return new LodashWrapper(wrapped, this.__chain__);
  8349. }
  8350. return this.thru(reverse);
  8351. }
  8352. /**
  8353. * Executes the chain sequence to resolve the unwrapped value.
  8354. *
  8355. * @name value
  8356. * @memberOf _
  8357. * @since 0.1.0
  8358. * @alias toJSON, valueOf
  8359. * @category Seq
  8360. * @returns {*} Returns the resolved unwrapped value.
  8361. * @example
  8362. *
  8363. * _([1, 2, 3]).value();
  8364. * // => [1, 2, 3]
  8365. */
  8366. function wrapperValue() {
  8367. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8368. }
  8369. /*------------------------------------------------------------------------*/
  8370. /**
  8371. * Creates an object composed of keys generated from the results of running
  8372. * each element of `collection` thru `iteratee`. The corresponding value of
  8373. * each key is the number of times the key was returned by `iteratee`. The
  8374. * iteratee is invoked with one argument: (value).
  8375. *
  8376. * @static
  8377. * @memberOf _
  8378. * @since 0.5.0
  8379. * @category Collection
  8380. * @param {Array|Object} collection The collection to iterate over.
  8381. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8382. * @returns {Object} Returns the composed aggregate object.
  8383. * @example
  8384. *
  8385. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8386. * // => { '4': 1, '6': 2 }
  8387. *
  8388. * // The `_.property` iteratee shorthand.
  8389. * _.countBy(['one', 'two', 'three'], 'length');
  8390. * // => { '3': 2, '5': 1 }
  8391. */
  8392. var countBy = createAggregator(function(result, value, key) {
  8393. if (hasOwnProperty.call(result, key)) {
  8394. ++result[key];
  8395. } else {
  8396. baseAssignValue(result, key, 1);
  8397. }
  8398. });
  8399. /**
  8400. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8401. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8402. * invoked with three arguments: (value, index|key, collection).
  8403. *
  8404. * **Note:** This method returns `true` for
  8405. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8406. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8407. * elements of empty collections.
  8408. *
  8409. * @static
  8410. * @memberOf _
  8411. * @since 0.1.0
  8412. * @category Collection
  8413. * @param {Array|Object} collection The collection to iterate over.
  8414. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8415. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8416. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8417. * else `false`.
  8418. * @example
  8419. *
  8420. * _.every([true, 1, null, 'yes'], Boolean);
  8421. * // => false
  8422. *
  8423. * var users = [
  8424. * { 'user': 'barney', 'age': 36, 'active': false },
  8425. * { 'user': 'fred', 'age': 40, 'active': false }
  8426. * ];
  8427. *
  8428. * // The `_.matches` iteratee shorthand.
  8429. * _.every(users, { 'user': 'barney', 'active': false });
  8430. * // => false
  8431. *
  8432. * // The `_.matchesProperty` iteratee shorthand.
  8433. * _.every(users, ['active', false]);
  8434. * // => true
  8435. *
  8436. * // The `_.property` iteratee shorthand.
  8437. * _.every(users, 'active');
  8438. * // => false
  8439. */
  8440. function every(collection, predicate, guard) {
  8441. var func = isArray(collection) ? arrayEvery : baseEvery;
  8442. if (guard && isIterateeCall(collection, predicate, guard)) {
  8443. predicate = undefined;
  8444. }
  8445. return func(collection, getIteratee(predicate, 3));
  8446. }
  8447. /**
  8448. * Iterates over elements of `collection`, returning an array of all elements
  8449. * `predicate` returns truthy for. The predicate is invoked with three
  8450. * arguments: (value, index|key, collection).
  8451. *
  8452. * **Note:** Unlike `_.remove`, this method returns a new array.
  8453. *
  8454. * @static
  8455. * @memberOf _
  8456. * @since 0.1.0
  8457. * @category Collection
  8458. * @param {Array|Object} collection The collection to iterate over.
  8459. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8460. * @returns {Array} Returns the new filtered array.
  8461. * @see _.reject
  8462. * @example
  8463. *
  8464. * var users = [
  8465. * { 'user': 'barney', 'age': 36, 'active': true },
  8466. * { 'user': 'fred', 'age': 40, 'active': false }
  8467. * ];
  8468. *
  8469. * _.filter(users, function(o) { return !o.active; });
  8470. * // => objects for ['fred']
  8471. *
  8472. * // The `_.matches` iteratee shorthand.
  8473. * _.filter(users, { 'age': 36, 'active': true });
  8474. * // => objects for ['barney']
  8475. *
  8476. * // The `_.matchesProperty` iteratee shorthand.
  8477. * _.filter(users, ['active', false]);
  8478. * // => objects for ['fred']
  8479. *
  8480. * // The `_.property` iteratee shorthand.
  8481. * _.filter(users, 'active');
  8482. * // => objects for ['barney']
  8483. */
  8484. function filter(collection, predicate) {
  8485. var func = isArray(collection) ? arrayFilter : baseFilter;
  8486. return func(collection, getIteratee(predicate, 3));
  8487. }
  8488. /**
  8489. * Iterates over elements of `collection`, returning the first element
  8490. * `predicate` returns truthy for. The predicate is invoked with three
  8491. * arguments: (value, index|key, collection).
  8492. *
  8493. * @static
  8494. * @memberOf _
  8495. * @since 0.1.0
  8496. * @category Collection
  8497. * @param {Array|Object} collection The collection to inspect.
  8498. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8499. * @param {number} [fromIndex=0] The index to search from.
  8500. * @returns {*} Returns the matched element, else `undefined`.
  8501. * @example
  8502. *
  8503. * var users = [
  8504. * { 'user': 'barney', 'age': 36, 'active': true },
  8505. * { 'user': 'fred', 'age': 40, 'active': false },
  8506. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8507. * ];
  8508. *
  8509. * _.find(users, function(o) { return o.age < 40; });
  8510. * // => object for 'barney'
  8511. *
  8512. * // The `_.matches` iteratee shorthand.
  8513. * _.find(users, { 'age': 1, 'active': true });
  8514. * // => object for 'pebbles'
  8515. *
  8516. * // The `_.matchesProperty` iteratee shorthand.
  8517. * _.find(users, ['active', false]);
  8518. * // => object for 'fred'
  8519. *
  8520. * // The `_.property` iteratee shorthand.
  8521. * _.find(users, 'active');
  8522. * // => object for 'barney'
  8523. */
  8524. var find = createFind(findIndex);
  8525. /**
  8526. * This method is like `_.find` except that it iterates over elements of
  8527. * `collection` from right to left.
  8528. *
  8529. * @static
  8530. * @memberOf _
  8531. * @since 2.0.0
  8532. * @category Collection
  8533. * @param {Array|Object} collection The collection to inspect.
  8534. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8535. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8536. * @returns {*} Returns the matched element, else `undefined`.
  8537. * @example
  8538. *
  8539. * _.findLast([1, 2, 3, 4], function(n) {
  8540. * return n % 2 == 1;
  8541. * });
  8542. * // => 3
  8543. */
  8544. var findLast = createFind(findLastIndex);
  8545. /**
  8546. * Creates a flattened array of values by running each element in `collection`
  8547. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8548. * with three arguments: (value, index|key, collection).
  8549. *
  8550. * @static
  8551. * @memberOf _
  8552. * @since 4.0.0
  8553. * @category Collection
  8554. * @param {Array|Object} collection The collection to iterate over.
  8555. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8556. * @returns {Array} Returns the new flattened array.
  8557. * @example
  8558. *
  8559. * function duplicate(n) {
  8560. * return [n, n];
  8561. * }
  8562. *
  8563. * _.flatMap([1, 2], duplicate);
  8564. * // => [1, 1, 2, 2]
  8565. */
  8566. function flatMap(collection, iteratee) {
  8567. return baseFlatten(map(collection, iteratee), 1);
  8568. }
  8569. /**
  8570. * This method is like `_.flatMap` except that it recursively flattens the
  8571. * mapped results.
  8572. *
  8573. * @static
  8574. * @memberOf _
  8575. * @since 4.7.0
  8576. * @category Collection
  8577. * @param {Array|Object} collection The collection to iterate over.
  8578. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8579. * @returns {Array} Returns the new flattened array.
  8580. * @example
  8581. *
  8582. * function duplicate(n) {
  8583. * return [[[n, n]]];
  8584. * }
  8585. *
  8586. * _.flatMapDeep([1, 2], duplicate);
  8587. * // => [1, 1, 2, 2]
  8588. */
  8589. function flatMapDeep(collection, iteratee) {
  8590. return baseFlatten(map(collection, iteratee), INFINITY);
  8591. }
  8592. /**
  8593. * This method is like `_.flatMap` except that it recursively flattens the
  8594. * mapped results up to `depth` times.
  8595. *
  8596. * @static
  8597. * @memberOf _
  8598. * @since 4.7.0
  8599. * @category Collection
  8600. * @param {Array|Object} collection The collection to iterate over.
  8601. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8602. * @param {number} [depth=1] The maximum recursion depth.
  8603. * @returns {Array} Returns the new flattened array.
  8604. * @example
  8605. *
  8606. * function duplicate(n) {
  8607. * return [[[n, n]]];
  8608. * }
  8609. *
  8610. * _.flatMapDepth([1, 2], duplicate, 2);
  8611. * // => [[1, 1], [2, 2]]
  8612. */
  8613. function flatMapDepth(collection, iteratee, depth) {
  8614. depth = depth === undefined ? 1 : toInteger(depth);
  8615. return baseFlatten(map(collection, iteratee), depth);
  8616. }
  8617. /**
  8618. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8619. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8620. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8621. *
  8622. * **Note:** As with other "Collections" methods, objects with a "length"
  8623. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8624. * or `_.forOwn` for object iteration.
  8625. *
  8626. * @static
  8627. * @memberOf _
  8628. * @since 0.1.0
  8629. * @alias each
  8630. * @category Collection
  8631. * @param {Array|Object} collection The collection to iterate over.
  8632. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8633. * @returns {Array|Object} Returns `collection`.
  8634. * @see _.forEachRight
  8635. * @example
  8636. *
  8637. * _.forEach([1, 2], function(value) {
  8638. * console.log(value);
  8639. * });
  8640. * // => Logs `1` then `2`.
  8641. *
  8642. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8643. * console.log(key);
  8644. * });
  8645. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8646. */
  8647. function forEach(collection, iteratee) {
  8648. var func = isArray(collection) ? arrayEach : baseEach;
  8649. return func(collection, getIteratee(iteratee, 3));
  8650. }
  8651. /**
  8652. * This method is like `_.forEach` except that it iterates over elements of
  8653. * `collection` from right to left.
  8654. *
  8655. * @static
  8656. * @memberOf _
  8657. * @since 2.0.0
  8658. * @alias eachRight
  8659. * @category Collection
  8660. * @param {Array|Object} collection The collection to iterate over.
  8661. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8662. * @returns {Array|Object} Returns `collection`.
  8663. * @see _.forEach
  8664. * @example
  8665. *
  8666. * _.forEachRight([1, 2], function(value) {
  8667. * console.log(value);
  8668. * });
  8669. * // => Logs `2` then `1`.
  8670. */
  8671. function forEachRight(collection, iteratee) {
  8672. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8673. return func(collection, getIteratee(iteratee, 3));
  8674. }
  8675. /**
  8676. * Creates an object composed of keys generated from the results of running
  8677. * each element of `collection` thru `iteratee`. The order of grouped values
  8678. * is determined by the order they occur in `collection`. The corresponding
  8679. * value of each key is an array of elements responsible for generating the
  8680. * key. The iteratee is invoked with one argument: (value).
  8681. *
  8682. * @static
  8683. * @memberOf _
  8684. * @since 0.1.0
  8685. * @category Collection
  8686. * @param {Array|Object} collection The collection to iterate over.
  8687. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8688. * @returns {Object} Returns the composed aggregate object.
  8689. * @example
  8690. *
  8691. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8692. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8693. *
  8694. * // The `_.property` iteratee shorthand.
  8695. * _.groupBy(['one', 'two', 'three'], 'length');
  8696. * // => { '3': ['one', 'two'], '5': ['three'] }
  8697. */
  8698. var groupBy = createAggregator(function(result, value, key) {
  8699. if (hasOwnProperty.call(result, key)) {
  8700. result[key].push(value);
  8701. } else {
  8702. baseAssignValue(result, key, [value]);
  8703. }
  8704. });
  8705. /**
  8706. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8707. * checked for a substring of `value`, otherwise
  8708. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8709. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8710. * the offset from the end of `collection`.
  8711. *
  8712. * @static
  8713. * @memberOf _
  8714. * @since 0.1.0
  8715. * @category Collection
  8716. * @param {Array|Object|string} collection The collection to inspect.
  8717. * @param {*} value The value to search for.
  8718. * @param {number} [fromIndex=0] The index to search from.
  8719. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8720. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8721. * @example
  8722. *
  8723. * _.includes([1, 2, 3], 1);
  8724. * // => true
  8725. *
  8726. * _.includes([1, 2, 3], 1, 2);
  8727. * // => false
  8728. *
  8729. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8730. * // => true
  8731. *
  8732. * _.includes('abcd', 'bc');
  8733. * // => true
  8734. */
  8735. function includes(collection, value, fromIndex, guard) {
  8736. collection = isArrayLike(collection) ? collection : values(collection);
  8737. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8738. var length = collection.length;
  8739. if (fromIndex < 0) {
  8740. fromIndex = nativeMax(length + fromIndex, 0);
  8741. }
  8742. return isString(collection)
  8743. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8744. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8745. }
  8746. /**
  8747. * Invokes the method at `path` of each element in `collection`, returning
  8748. * an array of the results of each invoked method. Any additional arguments
  8749. * are provided to each invoked method. If `path` is a function, it's invoked
  8750. * for, and `this` bound to, each element in `collection`.
  8751. *
  8752. * @static
  8753. * @memberOf _
  8754. * @since 4.0.0
  8755. * @category Collection
  8756. * @param {Array|Object} collection The collection to iterate over.
  8757. * @param {Array|Function|string} path The path of the method to invoke or
  8758. * the function invoked per iteration.
  8759. * @param {...*} [args] The arguments to invoke each method with.
  8760. * @returns {Array} Returns the array of results.
  8761. * @example
  8762. *
  8763. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8764. * // => [[1, 5, 7], [1, 2, 3]]
  8765. *
  8766. * _.invokeMap([123, 456], String.prototype.split, '');
  8767. * // => [['1', '2', '3'], ['4', '5', '6']]
  8768. */
  8769. var invokeMap = baseRest(function(collection, path, args) {
  8770. var index = -1,
  8771. isFunc = typeof path == 'function',
  8772. result = isArrayLike(collection) ? Array(collection.length) : [];
  8773. baseEach(collection, function(value) {
  8774. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8775. });
  8776. return result;
  8777. });
  8778. /**
  8779. * Creates an object composed of keys generated from the results of running
  8780. * each element of `collection` thru `iteratee`. The corresponding value of
  8781. * each key is the last element responsible for generating the key. The
  8782. * iteratee is invoked with one argument: (value).
  8783. *
  8784. * @static
  8785. * @memberOf _
  8786. * @since 4.0.0
  8787. * @category Collection
  8788. * @param {Array|Object} collection The collection to iterate over.
  8789. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8790. * @returns {Object} Returns the composed aggregate object.
  8791. * @example
  8792. *
  8793. * var array = [
  8794. * { 'dir': 'left', 'code': 97 },
  8795. * { 'dir': 'right', 'code': 100 }
  8796. * ];
  8797. *
  8798. * _.keyBy(array, function(o) {
  8799. * return String.fromCharCode(o.code);
  8800. * });
  8801. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8802. *
  8803. * _.keyBy(array, 'dir');
  8804. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8805. */
  8806. var keyBy = createAggregator(function(result, value, key) {
  8807. baseAssignValue(result, key, value);
  8808. });
  8809. /**
  8810. * Creates an array of values by running each element in `collection` thru
  8811. * `iteratee`. The iteratee is invoked with three arguments:
  8812. * (value, index|key, collection).
  8813. *
  8814. * Many lodash methods are guarded to work as iteratees for methods like
  8815. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8816. *
  8817. * The guarded methods are:
  8818. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8819. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8820. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8821. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8822. *
  8823. * @static
  8824. * @memberOf _
  8825. * @since 0.1.0
  8826. * @category Collection
  8827. * @param {Array|Object} collection The collection to iterate over.
  8828. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8829. * @returns {Array} Returns the new mapped array.
  8830. * @example
  8831. *
  8832. * function square(n) {
  8833. * return n * n;
  8834. * }
  8835. *
  8836. * _.map([4, 8], square);
  8837. * // => [16, 64]
  8838. *
  8839. * _.map({ 'a': 4, 'b': 8 }, square);
  8840. * // => [16, 64] (iteration order is not guaranteed)
  8841. *
  8842. * var users = [
  8843. * { 'user': 'barney' },
  8844. * { 'user': 'fred' }
  8845. * ];
  8846. *
  8847. * // The `_.property` iteratee shorthand.
  8848. * _.map(users, 'user');
  8849. * // => ['barney', 'fred']
  8850. */
  8851. function map(collection, iteratee) {
  8852. var func = isArray(collection) ? arrayMap : baseMap;
  8853. return func(collection, getIteratee(iteratee, 3));
  8854. }
  8855. /**
  8856. * This method is like `_.sortBy` except that it allows specifying the sort
  8857. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8858. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8859. * descending or "asc" for ascending sort order of corresponding values.
  8860. *
  8861. * @static
  8862. * @memberOf _
  8863. * @since 4.0.0
  8864. * @category Collection
  8865. * @param {Array|Object} collection The collection to iterate over.
  8866. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8867. * The iteratees to sort by.
  8868. * @param {string[]} [orders] The sort orders of `iteratees`.
  8869. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8870. * @returns {Array} Returns the new sorted array.
  8871. * @example
  8872. *
  8873. * var users = [
  8874. * { 'user': 'fred', 'age': 48 },
  8875. * { 'user': 'barney', 'age': 34 },
  8876. * { 'user': 'fred', 'age': 40 },
  8877. * { 'user': 'barney', 'age': 36 }
  8878. * ];
  8879. *
  8880. * // Sort by `user` in ascending order and by `age` in descending order.
  8881. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8882. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8883. */
  8884. function orderBy(collection, iteratees, orders, guard) {
  8885. if (collection == null) {
  8886. return [];
  8887. }
  8888. if (!isArray(iteratees)) {
  8889. iteratees = iteratees == null ? [] : [iteratees];
  8890. }
  8891. orders = guard ? undefined : orders;
  8892. if (!isArray(orders)) {
  8893. orders = orders == null ? [] : [orders];
  8894. }
  8895. return baseOrderBy(collection, iteratees, orders);
  8896. }
  8897. /**
  8898. * Creates an array of elements split into two groups, the first of which
  8899. * contains elements `predicate` returns truthy for, the second of which
  8900. * contains elements `predicate` returns falsey for. The predicate is
  8901. * invoked with one argument: (value).
  8902. *
  8903. * @static
  8904. * @memberOf _
  8905. * @since 3.0.0
  8906. * @category Collection
  8907. * @param {Array|Object} collection The collection to iterate over.
  8908. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8909. * @returns {Array} Returns the array of grouped elements.
  8910. * @example
  8911. *
  8912. * var users = [
  8913. * { 'user': 'barney', 'age': 36, 'active': false },
  8914. * { 'user': 'fred', 'age': 40, 'active': true },
  8915. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8916. * ];
  8917. *
  8918. * _.partition(users, function(o) { return o.active; });
  8919. * // => objects for [['fred'], ['barney', 'pebbles']]
  8920. *
  8921. * // The `_.matches` iteratee shorthand.
  8922. * _.partition(users, { 'age': 1, 'active': false });
  8923. * // => objects for [['pebbles'], ['barney', 'fred']]
  8924. *
  8925. * // The `_.matchesProperty` iteratee shorthand.
  8926. * _.partition(users, ['active', false]);
  8927. * // => objects for [['barney', 'pebbles'], ['fred']]
  8928. *
  8929. * // The `_.property` iteratee shorthand.
  8930. * _.partition(users, 'active');
  8931. * // => objects for [['fred'], ['barney', 'pebbles']]
  8932. */
  8933. var partition = createAggregator(function(result, value, key) {
  8934. result[key ? 0 : 1].push(value);
  8935. }, function() { return [[], []]; });
  8936. /**
  8937. * Reduces `collection` to a value which is the accumulated result of running
  8938. * each element in `collection` thru `iteratee`, where each successive
  8939. * invocation is supplied the return value of the previous. If `accumulator`
  8940. * is not given, the first element of `collection` is used as the initial
  8941. * value. The iteratee is invoked with four arguments:
  8942. * (accumulator, value, index|key, collection).
  8943. *
  8944. * Many lodash methods are guarded to work as iteratees for methods like
  8945. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8946. *
  8947. * The guarded methods are:
  8948. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8949. * and `sortBy`
  8950. *
  8951. * @static
  8952. * @memberOf _
  8953. * @since 0.1.0
  8954. * @category Collection
  8955. * @param {Array|Object} collection The collection to iterate over.
  8956. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8957. * @param {*} [accumulator] The initial value.
  8958. * @returns {*} Returns the accumulated value.
  8959. * @see _.reduceRight
  8960. * @example
  8961. *
  8962. * _.reduce([1, 2], function(sum, n) {
  8963. * return sum + n;
  8964. * }, 0);
  8965. * // => 3
  8966. *
  8967. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8968. * (result[value] || (result[value] = [])).push(key);
  8969. * return result;
  8970. * }, {});
  8971. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8972. */
  8973. function reduce(collection, iteratee, accumulator) {
  8974. var func = isArray(collection) ? arrayReduce : baseReduce,
  8975. initAccum = arguments.length < 3;
  8976. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8977. }
  8978. /**
  8979. * This method is like `_.reduce` except that it iterates over elements of
  8980. * `collection` from right to left.
  8981. *
  8982. * @static
  8983. * @memberOf _
  8984. * @since 0.1.0
  8985. * @category Collection
  8986. * @param {Array|Object} collection The collection to iterate over.
  8987. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8988. * @param {*} [accumulator] The initial value.
  8989. * @returns {*} Returns the accumulated value.
  8990. * @see _.reduce
  8991. * @example
  8992. *
  8993. * var array = [[0, 1], [2, 3], [4, 5]];
  8994. *
  8995. * _.reduceRight(array, function(flattened, other) {
  8996. * return flattened.concat(other);
  8997. * }, []);
  8998. * // => [4, 5, 2, 3, 0, 1]
  8999. */
  9000. function reduceRight(collection, iteratee, accumulator) {
  9001. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9002. initAccum = arguments.length < 3;
  9003. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9004. }
  9005. /**
  9006. * The opposite of `_.filter`; this method returns the elements of `collection`
  9007. * that `predicate` does **not** return truthy for.
  9008. *
  9009. * @static
  9010. * @memberOf _
  9011. * @since 0.1.0
  9012. * @category Collection
  9013. * @param {Array|Object} collection The collection to iterate over.
  9014. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9015. * @returns {Array} Returns the new filtered array.
  9016. * @see _.filter
  9017. * @example
  9018. *
  9019. * var users = [
  9020. * { 'user': 'barney', 'age': 36, 'active': false },
  9021. * { 'user': 'fred', 'age': 40, 'active': true }
  9022. * ];
  9023. *
  9024. * _.reject(users, function(o) { return !o.active; });
  9025. * // => objects for ['fred']
  9026. *
  9027. * // The `_.matches` iteratee shorthand.
  9028. * _.reject(users, { 'age': 40, 'active': true });
  9029. * // => objects for ['barney']
  9030. *
  9031. * // The `_.matchesProperty` iteratee shorthand.
  9032. * _.reject(users, ['active', false]);
  9033. * // => objects for ['fred']
  9034. *
  9035. * // The `_.property` iteratee shorthand.
  9036. * _.reject(users, 'active');
  9037. * // => objects for ['barney']
  9038. */
  9039. function reject(collection, predicate) {
  9040. var func = isArray(collection) ? arrayFilter : baseFilter;
  9041. return func(collection, negate(getIteratee(predicate, 3)));
  9042. }
  9043. /**
  9044. * Gets a random element from `collection`.
  9045. *
  9046. * @static
  9047. * @memberOf _
  9048. * @since 2.0.0
  9049. * @category Collection
  9050. * @param {Array|Object} collection The collection to sample.
  9051. * @returns {*} Returns the random element.
  9052. * @example
  9053. *
  9054. * _.sample([1, 2, 3, 4]);
  9055. * // => 2
  9056. */
  9057. function sample(collection) {
  9058. var func = isArray(collection) ? arraySample : baseSample;
  9059. return func(collection);
  9060. }
  9061. /**
  9062. * Gets `n` random elements at unique keys from `collection` up to the
  9063. * size of `collection`.
  9064. *
  9065. * @static
  9066. * @memberOf _
  9067. * @since 4.0.0
  9068. * @category Collection
  9069. * @param {Array|Object} collection The collection to sample.
  9070. * @param {number} [n=1] The number of elements to sample.
  9071. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9072. * @returns {Array} Returns the random elements.
  9073. * @example
  9074. *
  9075. * _.sampleSize([1, 2, 3], 2);
  9076. * // => [3, 1]
  9077. *
  9078. * _.sampleSize([1, 2, 3], 4);
  9079. * // => [2, 3, 1]
  9080. */
  9081. function sampleSize(collection, n, guard) {
  9082. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9083. n = 1;
  9084. } else {
  9085. n = toInteger(n);
  9086. }
  9087. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9088. return func(collection, n);
  9089. }
  9090. /**
  9091. * Creates an array of shuffled values, using a version of the
  9092. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9093. *
  9094. * @static
  9095. * @memberOf _
  9096. * @since 0.1.0
  9097. * @category Collection
  9098. * @param {Array|Object} collection The collection to shuffle.
  9099. * @returns {Array} Returns the new shuffled array.
  9100. * @example
  9101. *
  9102. * _.shuffle([1, 2, 3, 4]);
  9103. * // => [4, 1, 3, 2]
  9104. */
  9105. function shuffle(collection) {
  9106. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9107. return func(collection);
  9108. }
  9109. /**
  9110. * Gets the size of `collection` by returning its length for array-like
  9111. * values or the number of own enumerable string keyed properties for objects.
  9112. *
  9113. * @static
  9114. * @memberOf _
  9115. * @since 0.1.0
  9116. * @category Collection
  9117. * @param {Array|Object|string} collection The collection to inspect.
  9118. * @returns {number} Returns the collection size.
  9119. * @example
  9120. *
  9121. * _.size([1, 2, 3]);
  9122. * // => 3
  9123. *
  9124. * _.size({ 'a': 1, 'b': 2 });
  9125. * // => 2
  9126. *
  9127. * _.size('pebbles');
  9128. * // => 7
  9129. */
  9130. function size(collection) {
  9131. if (collection == null) {
  9132. return 0;
  9133. }
  9134. if (isArrayLike(collection)) {
  9135. return isString(collection) ? stringSize(collection) : collection.length;
  9136. }
  9137. var tag = getTag(collection);
  9138. if (tag == mapTag || tag == setTag) {
  9139. return collection.size;
  9140. }
  9141. return baseKeys(collection).length;
  9142. }
  9143. /**
  9144. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9145. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9146. * invoked with three arguments: (value, index|key, collection).
  9147. *
  9148. * @static
  9149. * @memberOf _
  9150. * @since 0.1.0
  9151. * @category Collection
  9152. * @param {Array|Object} collection The collection to iterate over.
  9153. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9154. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9155. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9156. * else `false`.
  9157. * @example
  9158. *
  9159. * _.some([null, 0, 'yes', false], Boolean);
  9160. * // => true
  9161. *
  9162. * var users = [
  9163. * { 'user': 'barney', 'active': true },
  9164. * { 'user': 'fred', 'active': false }
  9165. * ];
  9166. *
  9167. * // The `_.matches` iteratee shorthand.
  9168. * _.some(users, { 'user': 'barney', 'active': false });
  9169. * // => false
  9170. *
  9171. * // The `_.matchesProperty` iteratee shorthand.
  9172. * _.some(users, ['active', false]);
  9173. * // => true
  9174. *
  9175. * // The `_.property` iteratee shorthand.
  9176. * _.some(users, 'active');
  9177. * // => true
  9178. */
  9179. function some(collection, predicate, guard) {
  9180. var func = isArray(collection) ? arraySome : baseSome;
  9181. if (guard && isIterateeCall(collection, predicate, guard)) {
  9182. predicate = undefined;
  9183. }
  9184. return func(collection, getIteratee(predicate, 3));
  9185. }
  9186. /**
  9187. * Creates an array of elements, sorted in ascending order by the results of
  9188. * running each element in a collection thru each iteratee. This method
  9189. * performs a stable sort, that is, it preserves the original sort order of
  9190. * equal elements. The iteratees are invoked with one argument: (value).
  9191. *
  9192. * @static
  9193. * @memberOf _
  9194. * @since 0.1.0
  9195. * @category Collection
  9196. * @param {Array|Object} collection The collection to iterate over.
  9197. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9198. * The iteratees to sort by.
  9199. * @returns {Array} Returns the new sorted array.
  9200. * @example
  9201. *
  9202. * var users = [
  9203. * { 'user': 'fred', 'age': 48 },
  9204. * { 'user': 'barney', 'age': 36 },
  9205. * { 'user': 'fred', 'age': 40 },
  9206. * { 'user': 'barney', 'age': 34 }
  9207. * ];
  9208. *
  9209. * _.sortBy(users, [function(o) { return o.user; }]);
  9210. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9211. *
  9212. * _.sortBy(users, ['user', 'age']);
  9213. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9214. */
  9215. var sortBy = baseRest(function(collection, iteratees) {
  9216. if (collection == null) {
  9217. return [];
  9218. }
  9219. var length = iteratees.length;
  9220. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9221. iteratees = [];
  9222. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9223. iteratees = [iteratees[0]];
  9224. }
  9225. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9226. });
  9227. /*------------------------------------------------------------------------*/
  9228. /**
  9229. * Gets the timestamp of the number of milliseconds that have elapsed since
  9230. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9231. *
  9232. * @static
  9233. * @memberOf _
  9234. * @since 2.4.0
  9235. * @category Date
  9236. * @returns {number} Returns the timestamp.
  9237. * @example
  9238. *
  9239. * _.defer(function(stamp) {
  9240. * console.log(_.now() - stamp);
  9241. * }, _.now());
  9242. * // => Logs the number of milliseconds it took for the deferred invocation.
  9243. */
  9244. var now = ctxNow || function() {
  9245. return root.Date.now();
  9246. };
  9247. /*------------------------------------------------------------------------*/
  9248. /**
  9249. * The opposite of `_.before`; this method creates a function that invokes
  9250. * `func` once it's called `n` or more times.
  9251. *
  9252. * @static
  9253. * @memberOf _
  9254. * @since 0.1.0
  9255. * @category Function
  9256. * @param {number} n The number of calls before `func` is invoked.
  9257. * @param {Function} func The function to restrict.
  9258. * @returns {Function} Returns the new restricted function.
  9259. * @example
  9260. *
  9261. * var saves = ['profile', 'settings'];
  9262. *
  9263. * var done = _.after(saves.length, function() {
  9264. * console.log('done saving!');
  9265. * });
  9266. *
  9267. * _.forEach(saves, function(type) {
  9268. * asyncSave({ 'type': type, 'complete': done });
  9269. * });
  9270. * // => Logs 'done saving!' after the two async saves have completed.
  9271. */
  9272. function after(n, func) {
  9273. if (typeof func != 'function') {
  9274. throw new TypeError(FUNC_ERROR_TEXT);
  9275. }
  9276. n = toInteger(n);
  9277. return function() {
  9278. if (--n < 1) {
  9279. return func.apply(this, arguments);
  9280. }
  9281. };
  9282. }
  9283. /**
  9284. * Creates a function that invokes `func`, with up to `n` arguments,
  9285. * ignoring any additional arguments.
  9286. *
  9287. * @static
  9288. * @memberOf _
  9289. * @since 3.0.0
  9290. * @category Function
  9291. * @param {Function} func The function to cap arguments for.
  9292. * @param {number} [n=func.length] The arity cap.
  9293. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9294. * @returns {Function} Returns the new capped function.
  9295. * @example
  9296. *
  9297. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9298. * // => [6, 8, 10]
  9299. */
  9300. function ary(func, n, guard) {
  9301. n = guard ? undefined : n;
  9302. n = (func && n == null) ? func.length : n;
  9303. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9304. }
  9305. /**
  9306. * Creates a function that invokes `func`, with the `this` binding and arguments
  9307. * of the created function, while it's called less than `n` times. Subsequent
  9308. * calls to the created function return the result of the last `func` invocation.
  9309. *
  9310. * @static
  9311. * @memberOf _
  9312. * @since 3.0.0
  9313. * @category Function
  9314. * @param {number} n The number of calls at which `func` is no longer invoked.
  9315. * @param {Function} func The function to restrict.
  9316. * @returns {Function} Returns the new restricted function.
  9317. * @example
  9318. *
  9319. * jQuery(element).on('click', _.before(5, addContactToList));
  9320. * // => Allows adding up to 4 contacts to the list.
  9321. */
  9322. function before(n, func) {
  9323. var result;
  9324. if (typeof func != 'function') {
  9325. throw new TypeError(FUNC_ERROR_TEXT);
  9326. }
  9327. n = toInteger(n);
  9328. return function() {
  9329. if (--n > 0) {
  9330. result = func.apply(this, arguments);
  9331. }
  9332. if (n <= 1) {
  9333. func = undefined;
  9334. }
  9335. return result;
  9336. };
  9337. }
  9338. /**
  9339. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9340. * and `partials` prepended to the arguments it receives.
  9341. *
  9342. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9343. * may be used as a placeholder for partially applied arguments.
  9344. *
  9345. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9346. * property of bound functions.
  9347. *
  9348. * @static
  9349. * @memberOf _
  9350. * @since 0.1.0
  9351. * @category Function
  9352. * @param {Function} func The function to bind.
  9353. * @param {*} thisArg The `this` binding of `func`.
  9354. * @param {...*} [partials] The arguments to be partially applied.
  9355. * @returns {Function} Returns the new bound function.
  9356. * @example
  9357. *
  9358. * function greet(greeting, punctuation) {
  9359. * return greeting + ' ' + this.user + punctuation;
  9360. * }
  9361. *
  9362. * var object = { 'user': 'fred' };
  9363. *
  9364. * var bound = _.bind(greet, object, 'hi');
  9365. * bound('!');
  9366. * // => 'hi fred!'
  9367. *
  9368. * // Bound with placeholders.
  9369. * var bound = _.bind(greet, object, _, '!');
  9370. * bound('hi');
  9371. * // => 'hi fred!'
  9372. */
  9373. var bind = baseRest(function(func, thisArg, partials) {
  9374. var bitmask = WRAP_BIND_FLAG;
  9375. if (partials.length) {
  9376. var holders = replaceHolders(partials, getHolder(bind));
  9377. bitmask |= WRAP_PARTIAL_FLAG;
  9378. }
  9379. return createWrap(func, bitmask, thisArg, partials, holders);
  9380. });
  9381. /**
  9382. * Creates a function that invokes the method at `object[key]` with `partials`
  9383. * prepended to the arguments it receives.
  9384. *
  9385. * This method differs from `_.bind` by allowing bound functions to reference
  9386. * methods that may be redefined or don't yet exist. See
  9387. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9388. * for more details.
  9389. *
  9390. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9391. * builds, may be used as a placeholder for partially applied arguments.
  9392. *
  9393. * @static
  9394. * @memberOf _
  9395. * @since 0.10.0
  9396. * @category Function
  9397. * @param {Object} object The object to invoke the method on.
  9398. * @param {string} key The key of the method.
  9399. * @param {...*} [partials] The arguments to be partially applied.
  9400. * @returns {Function} Returns the new bound function.
  9401. * @example
  9402. *
  9403. * var object = {
  9404. * 'user': 'fred',
  9405. * 'greet': function(greeting, punctuation) {
  9406. * return greeting + ' ' + this.user + punctuation;
  9407. * }
  9408. * };
  9409. *
  9410. * var bound = _.bindKey(object, 'greet', 'hi');
  9411. * bound('!');
  9412. * // => 'hi fred!'
  9413. *
  9414. * object.greet = function(greeting, punctuation) {
  9415. * return greeting + 'ya ' + this.user + punctuation;
  9416. * };
  9417. *
  9418. * bound('!');
  9419. * // => 'hiya fred!'
  9420. *
  9421. * // Bound with placeholders.
  9422. * var bound = _.bindKey(object, 'greet', _, '!');
  9423. * bound('hi');
  9424. * // => 'hiya fred!'
  9425. */
  9426. var bindKey = baseRest(function(object, key, partials) {
  9427. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9428. if (partials.length) {
  9429. var holders = replaceHolders(partials, getHolder(bindKey));
  9430. bitmask |= WRAP_PARTIAL_FLAG;
  9431. }
  9432. return createWrap(key, bitmask, object, partials, holders);
  9433. });
  9434. /**
  9435. * Creates a function that accepts arguments of `func` and either invokes
  9436. * `func` returning its result, if at least `arity` number of arguments have
  9437. * been provided, or returns a function that accepts the remaining `func`
  9438. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9439. * is not sufficient.
  9440. *
  9441. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9442. * may be used as a placeholder for provided arguments.
  9443. *
  9444. * **Note:** This method doesn't set the "length" property of curried functions.
  9445. *
  9446. * @static
  9447. * @memberOf _
  9448. * @since 2.0.0
  9449. * @category Function
  9450. * @param {Function} func The function to curry.
  9451. * @param {number} [arity=func.length] The arity of `func`.
  9452. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9453. * @returns {Function} Returns the new curried function.
  9454. * @example
  9455. *
  9456. * var abc = function(a, b, c) {
  9457. * return [a, b, c];
  9458. * };
  9459. *
  9460. * var curried = _.curry(abc);
  9461. *
  9462. * curried(1)(2)(3);
  9463. * // => [1, 2, 3]
  9464. *
  9465. * curried(1, 2)(3);
  9466. * // => [1, 2, 3]
  9467. *
  9468. * curried(1, 2, 3);
  9469. * // => [1, 2, 3]
  9470. *
  9471. * // Curried with placeholders.
  9472. * curried(1)(_, 3)(2);
  9473. * // => [1, 2, 3]
  9474. */
  9475. function curry(func, arity, guard) {
  9476. arity = guard ? undefined : arity;
  9477. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9478. result.placeholder = curry.placeholder;
  9479. return result;
  9480. }
  9481. /**
  9482. * This method is like `_.curry` except that arguments are applied to `func`
  9483. * in the manner of `_.partialRight` instead of `_.partial`.
  9484. *
  9485. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9486. * builds, may be used as a placeholder for provided arguments.
  9487. *
  9488. * **Note:** This method doesn't set the "length" property of curried functions.
  9489. *
  9490. * @static
  9491. * @memberOf _
  9492. * @since 3.0.0
  9493. * @category Function
  9494. * @param {Function} func The function to curry.
  9495. * @param {number} [arity=func.length] The arity of `func`.
  9496. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9497. * @returns {Function} Returns the new curried function.
  9498. * @example
  9499. *
  9500. * var abc = function(a, b, c) {
  9501. * return [a, b, c];
  9502. * };
  9503. *
  9504. * var curried = _.curryRight(abc);
  9505. *
  9506. * curried(3)(2)(1);
  9507. * // => [1, 2, 3]
  9508. *
  9509. * curried(2, 3)(1);
  9510. * // => [1, 2, 3]
  9511. *
  9512. * curried(1, 2, 3);
  9513. * // => [1, 2, 3]
  9514. *
  9515. * // Curried with placeholders.
  9516. * curried(3)(1, _)(2);
  9517. * // => [1, 2, 3]
  9518. */
  9519. function curryRight(func, arity, guard) {
  9520. arity = guard ? undefined : arity;
  9521. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9522. result.placeholder = curryRight.placeholder;
  9523. return result;
  9524. }
  9525. /**
  9526. * Creates a debounced function that delays invoking `func` until after `wait`
  9527. * milliseconds have elapsed since the last time the debounced function was
  9528. * invoked. The debounced function comes with a `cancel` method to cancel
  9529. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9530. * Provide `options` to indicate whether `func` should be invoked on the
  9531. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9532. * with the last arguments provided to the debounced function. Subsequent
  9533. * calls to the debounced function return the result of the last `func`
  9534. * invocation.
  9535. *
  9536. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9537. * invoked on the trailing edge of the timeout only if the debounced function
  9538. * is invoked more than once during the `wait` timeout.
  9539. *
  9540. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9541. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9542. *
  9543. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9544. * for details over the differences between `_.debounce` and `_.throttle`.
  9545. *
  9546. * @static
  9547. * @memberOf _
  9548. * @since 0.1.0
  9549. * @category Function
  9550. * @param {Function} func The function to debounce.
  9551. * @param {number} [wait=0] The number of milliseconds to delay.
  9552. * @param {Object} [options={}] The options object.
  9553. * @param {boolean} [options.leading=false]
  9554. * Specify invoking on the leading edge of the timeout.
  9555. * @param {number} [options.maxWait]
  9556. * The maximum time `func` is allowed to be delayed before it's invoked.
  9557. * @param {boolean} [options.trailing=true]
  9558. * Specify invoking on the trailing edge of the timeout.
  9559. * @returns {Function} Returns the new debounced function.
  9560. * @example
  9561. *
  9562. * // Avoid costly calculations while the window size is in flux.
  9563. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9564. *
  9565. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9566. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9567. * 'leading': true,
  9568. * 'trailing': false
  9569. * }));
  9570. *
  9571. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9572. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9573. * var source = new EventSource('/stream');
  9574. * jQuery(source).on('message', debounced);
  9575. *
  9576. * // Cancel the trailing debounced invocation.
  9577. * jQuery(window).on('popstate', debounced.cancel);
  9578. */
  9579. function debounce(func, wait, options) {
  9580. var lastArgs,
  9581. lastThis,
  9582. maxWait,
  9583. result,
  9584. timerId,
  9585. lastCallTime,
  9586. lastInvokeTime = 0,
  9587. leading = false,
  9588. maxing = false,
  9589. trailing = true;
  9590. if (typeof func != 'function') {
  9591. throw new TypeError(FUNC_ERROR_TEXT);
  9592. }
  9593. wait = toNumber(wait) || 0;
  9594. if (isObject(options)) {
  9595. leading = !!options.leading;
  9596. maxing = 'maxWait' in options;
  9597. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9598. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9599. }
  9600. function invokeFunc(time) {
  9601. var args = lastArgs,
  9602. thisArg = lastThis;
  9603. lastArgs = lastThis = undefined;
  9604. lastInvokeTime = time;
  9605. result = func.apply(thisArg, args);
  9606. return result;
  9607. }
  9608. function leadingEdge(time) {
  9609. // Reset any `maxWait` timer.
  9610. lastInvokeTime = time;
  9611. // Start the timer for the trailing edge.
  9612. timerId = setTimeout(timerExpired, wait);
  9613. // Invoke the leading edge.
  9614. return leading ? invokeFunc(time) : result;
  9615. }
  9616. function remainingWait(time) {
  9617. var timeSinceLastCall = time - lastCallTime,
  9618. timeSinceLastInvoke = time - lastInvokeTime,
  9619. timeWaiting = wait - timeSinceLastCall;
  9620. return maxing
  9621. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9622. : timeWaiting;
  9623. }
  9624. function shouldInvoke(time) {
  9625. var timeSinceLastCall = time - lastCallTime,
  9626. timeSinceLastInvoke = time - lastInvokeTime;
  9627. // Either this is the first call, activity has stopped and we're at the
  9628. // trailing edge, the system time has gone backwards and we're treating
  9629. // it as the trailing edge, or we've hit the `maxWait` limit.
  9630. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9631. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9632. }
  9633. function timerExpired() {
  9634. var time = now();
  9635. if (shouldInvoke(time)) {
  9636. return trailingEdge(time);
  9637. }
  9638. // Restart the timer.
  9639. timerId = setTimeout(timerExpired, remainingWait(time));
  9640. }
  9641. function trailingEdge(time) {
  9642. timerId = undefined;
  9643. // Only invoke if we have `lastArgs` which means `func` has been
  9644. // debounced at least once.
  9645. if (trailing && lastArgs) {
  9646. return invokeFunc(time);
  9647. }
  9648. lastArgs = lastThis = undefined;
  9649. return result;
  9650. }
  9651. function cancel() {
  9652. if (timerId !== undefined) {
  9653. clearTimeout(timerId);
  9654. }
  9655. lastInvokeTime = 0;
  9656. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9657. }
  9658. function flush() {
  9659. return timerId === undefined ? result : trailingEdge(now());
  9660. }
  9661. function debounced() {
  9662. var time = now(),
  9663. isInvoking = shouldInvoke(time);
  9664. lastArgs = arguments;
  9665. lastThis = this;
  9666. lastCallTime = time;
  9667. if (isInvoking) {
  9668. if (timerId === undefined) {
  9669. return leadingEdge(lastCallTime);
  9670. }
  9671. if (maxing) {
  9672. // Handle invocations in a tight loop.
  9673. clearTimeout(timerId);
  9674. timerId = setTimeout(timerExpired, wait);
  9675. return invokeFunc(lastCallTime);
  9676. }
  9677. }
  9678. if (timerId === undefined) {
  9679. timerId = setTimeout(timerExpired, wait);
  9680. }
  9681. return result;
  9682. }
  9683. debounced.cancel = cancel;
  9684. debounced.flush = flush;
  9685. return debounced;
  9686. }
  9687. /**
  9688. * Defers invoking the `func` until the current call stack has cleared. Any
  9689. * additional arguments are provided to `func` when it's invoked.
  9690. *
  9691. * @static
  9692. * @memberOf _
  9693. * @since 0.1.0
  9694. * @category Function
  9695. * @param {Function} func The function to defer.
  9696. * @param {...*} [args] The arguments to invoke `func` with.
  9697. * @returns {number} Returns the timer id.
  9698. * @example
  9699. *
  9700. * _.defer(function(text) {
  9701. * console.log(text);
  9702. * }, 'deferred');
  9703. * // => Logs 'deferred' after one millisecond.
  9704. */
  9705. var defer = baseRest(function(func, args) {
  9706. return baseDelay(func, 1, args);
  9707. });
  9708. /**
  9709. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9710. * provided to `func` when it's invoked.
  9711. *
  9712. * @static
  9713. * @memberOf _
  9714. * @since 0.1.0
  9715. * @category Function
  9716. * @param {Function} func The function to delay.
  9717. * @param {number} wait The number of milliseconds to delay invocation.
  9718. * @param {...*} [args] The arguments to invoke `func` with.
  9719. * @returns {number} Returns the timer id.
  9720. * @example
  9721. *
  9722. * _.delay(function(text) {
  9723. * console.log(text);
  9724. * }, 1000, 'later');
  9725. * // => Logs 'later' after one second.
  9726. */
  9727. var delay = baseRest(function(func, wait, args) {
  9728. return baseDelay(func, toNumber(wait) || 0, args);
  9729. });
  9730. /**
  9731. * Creates a function that invokes `func` with arguments reversed.
  9732. *
  9733. * @static
  9734. * @memberOf _
  9735. * @since 4.0.0
  9736. * @category Function
  9737. * @param {Function} func The function to flip arguments for.
  9738. * @returns {Function} Returns the new flipped function.
  9739. * @example
  9740. *
  9741. * var flipped = _.flip(function() {
  9742. * return _.toArray(arguments);
  9743. * });
  9744. *
  9745. * flipped('a', 'b', 'c', 'd');
  9746. * // => ['d', 'c', 'b', 'a']
  9747. */
  9748. function flip(func) {
  9749. return createWrap(func, WRAP_FLIP_FLAG);
  9750. }
  9751. /**
  9752. * Creates a function that memoizes the result of `func`. If `resolver` is
  9753. * provided, it determines the cache key for storing the result based on the
  9754. * arguments provided to the memoized function. By default, the first argument
  9755. * provided to the memoized function is used as the map cache key. The `func`
  9756. * is invoked with the `this` binding of the memoized function.
  9757. *
  9758. * **Note:** The cache is exposed as the `cache` property on the memoized
  9759. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9760. * constructor with one whose instances implement the
  9761. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9762. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9763. *
  9764. * @static
  9765. * @memberOf _
  9766. * @since 0.1.0
  9767. * @category Function
  9768. * @param {Function} func The function to have its output memoized.
  9769. * @param {Function} [resolver] The function to resolve the cache key.
  9770. * @returns {Function} Returns the new memoized function.
  9771. * @example
  9772. *
  9773. * var object = { 'a': 1, 'b': 2 };
  9774. * var other = { 'c': 3, 'd': 4 };
  9775. *
  9776. * var values = _.memoize(_.values);
  9777. * values(object);
  9778. * // => [1, 2]
  9779. *
  9780. * values(other);
  9781. * // => [3, 4]
  9782. *
  9783. * object.a = 2;
  9784. * values(object);
  9785. * // => [1, 2]
  9786. *
  9787. * // Modify the result cache.
  9788. * values.cache.set(object, ['a', 'b']);
  9789. * values(object);
  9790. * // => ['a', 'b']
  9791. *
  9792. * // Replace `_.memoize.Cache`.
  9793. * _.memoize.Cache = WeakMap;
  9794. */
  9795. function memoize(func, resolver) {
  9796. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9797. throw new TypeError(FUNC_ERROR_TEXT);
  9798. }
  9799. var memoized = function() {
  9800. var args = arguments,
  9801. key = resolver ? resolver.apply(this, args) : args[0],
  9802. cache = memoized.cache;
  9803. if (cache.has(key)) {
  9804. return cache.get(key);
  9805. }
  9806. var result = func.apply(this, args);
  9807. memoized.cache = cache.set(key, result) || cache;
  9808. return result;
  9809. };
  9810. memoized.cache = new (memoize.Cache || MapCache);
  9811. return memoized;
  9812. }
  9813. // Expose `MapCache`.
  9814. memoize.Cache = MapCache;
  9815. /**
  9816. * Creates a function that negates the result of the predicate `func`. The
  9817. * `func` predicate is invoked with the `this` binding and arguments of the
  9818. * created function.
  9819. *
  9820. * @static
  9821. * @memberOf _
  9822. * @since 3.0.0
  9823. * @category Function
  9824. * @param {Function} predicate The predicate to negate.
  9825. * @returns {Function} Returns the new negated function.
  9826. * @example
  9827. *
  9828. * function isEven(n) {
  9829. * return n % 2 == 0;
  9830. * }
  9831. *
  9832. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9833. * // => [1, 3, 5]
  9834. */
  9835. function negate(predicate) {
  9836. if (typeof predicate != 'function') {
  9837. throw new TypeError(FUNC_ERROR_TEXT);
  9838. }
  9839. return function() {
  9840. var args = arguments;
  9841. switch (args.length) {
  9842. case 0: return !predicate.call(this);
  9843. case 1: return !predicate.call(this, args[0]);
  9844. case 2: return !predicate.call(this, args[0], args[1]);
  9845. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9846. }
  9847. return !predicate.apply(this, args);
  9848. };
  9849. }
  9850. /**
  9851. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9852. * to the function return the value of the first invocation. The `func` is
  9853. * invoked with the `this` binding and arguments of the created function.
  9854. *
  9855. * @static
  9856. * @memberOf _
  9857. * @since 0.1.0
  9858. * @category Function
  9859. * @param {Function} func The function to restrict.
  9860. * @returns {Function} Returns the new restricted function.
  9861. * @example
  9862. *
  9863. * var initialize = _.once(createApplication);
  9864. * initialize();
  9865. * initialize();
  9866. * // => `createApplication` is invoked once
  9867. */
  9868. function once(func) {
  9869. return before(2, func);
  9870. }
  9871. /**
  9872. * Creates a function that invokes `func` with its arguments transformed.
  9873. *
  9874. * @static
  9875. * @since 4.0.0
  9876. * @memberOf _
  9877. * @category Function
  9878. * @param {Function} func The function to wrap.
  9879. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9880. * The argument transforms.
  9881. * @returns {Function} Returns the new function.
  9882. * @example
  9883. *
  9884. * function doubled(n) {
  9885. * return n * 2;
  9886. * }
  9887. *
  9888. * function square(n) {
  9889. * return n * n;
  9890. * }
  9891. *
  9892. * var func = _.overArgs(function(x, y) {
  9893. * return [x, y];
  9894. * }, [square, doubled]);
  9895. *
  9896. * func(9, 3);
  9897. * // => [81, 6]
  9898. *
  9899. * func(10, 5);
  9900. * // => [100, 10]
  9901. */
  9902. var overArgs = castRest(function(func, transforms) {
  9903. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9904. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9905. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9906. var funcsLength = transforms.length;
  9907. return baseRest(function(args) {
  9908. var index = -1,
  9909. length = nativeMin(args.length, funcsLength);
  9910. while (++index < length) {
  9911. args[index] = transforms[index].call(this, args[index]);
  9912. }
  9913. return apply(func, this, args);
  9914. });
  9915. });
  9916. /**
  9917. * Creates a function that invokes `func` with `partials` prepended to the
  9918. * arguments it receives. This method is like `_.bind` except it does **not**
  9919. * alter the `this` binding.
  9920. *
  9921. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9922. * builds, may be used as a placeholder for partially applied arguments.
  9923. *
  9924. * **Note:** This method doesn't set the "length" property of partially
  9925. * applied functions.
  9926. *
  9927. * @static
  9928. * @memberOf _
  9929. * @since 0.2.0
  9930. * @category Function
  9931. * @param {Function} func The function to partially apply arguments to.
  9932. * @param {...*} [partials] The arguments to be partially applied.
  9933. * @returns {Function} Returns the new partially applied function.
  9934. * @example
  9935. *
  9936. * function greet(greeting, name) {
  9937. * return greeting + ' ' + name;
  9938. * }
  9939. *
  9940. * var sayHelloTo = _.partial(greet, 'hello');
  9941. * sayHelloTo('fred');
  9942. * // => 'hello fred'
  9943. *
  9944. * // Partially applied with placeholders.
  9945. * var greetFred = _.partial(greet, _, 'fred');
  9946. * greetFred('hi');
  9947. * // => 'hi fred'
  9948. */
  9949. var partial = baseRest(function(func, partials) {
  9950. var holders = replaceHolders(partials, getHolder(partial));
  9951. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  9952. });
  9953. /**
  9954. * This method is like `_.partial` except that partially applied arguments
  9955. * are appended to the arguments it receives.
  9956. *
  9957. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9958. * builds, may be used as a placeholder for partially applied arguments.
  9959. *
  9960. * **Note:** This method doesn't set the "length" property of partially
  9961. * applied functions.
  9962. *
  9963. * @static
  9964. * @memberOf _
  9965. * @since 1.0.0
  9966. * @category Function
  9967. * @param {Function} func The function to partially apply arguments to.
  9968. * @param {...*} [partials] The arguments to be partially applied.
  9969. * @returns {Function} Returns the new partially applied function.
  9970. * @example
  9971. *
  9972. * function greet(greeting, name) {
  9973. * return greeting + ' ' + name;
  9974. * }
  9975. *
  9976. * var greetFred = _.partialRight(greet, 'fred');
  9977. * greetFred('hi');
  9978. * // => 'hi fred'
  9979. *
  9980. * // Partially applied with placeholders.
  9981. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9982. * sayHelloTo('fred');
  9983. * // => 'hello fred'
  9984. */
  9985. var partialRight = baseRest(function(func, partials) {
  9986. var holders = replaceHolders(partials, getHolder(partialRight));
  9987. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9988. });
  9989. /**
  9990. * Creates a function that invokes `func` with arguments arranged according
  9991. * to the specified `indexes` where the argument value at the first index is
  9992. * provided as the first argument, the argument value at the second index is
  9993. * provided as the second argument, and so on.
  9994. *
  9995. * @static
  9996. * @memberOf _
  9997. * @since 3.0.0
  9998. * @category Function
  9999. * @param {Function} func The function to rearrange arguments for.
  10000. * @param {...(number|number[])} indexes The arranged argument indexes.
  10001. * @returns {Function} Returns the new function.
  10002. * @example
  10003. *
  10004. * var rearged = _.rearg(function(a, b, c) {
  10005. * return [a, b, c];
  10006. * }, [2, 0, 1]);
  10007. *
  10008. * rearged('b', 'c', 'a')
  10009. * // => ['a', 'b', 'c']
  10010. */
  10011. var rearg = flatRest(function(func, indexes) {
  10012. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10013. });
  10014. /**
  10015. * Creates a function that invokes `func` with the `this` binding of the
  10016. * created function and arguments from `start` and beyond provided as
  10017. * an array.
  10018. *
  10019. * **Note:** This method is based on the
  10020. * [rest parameter](https://mdn.io/rest_parameters).
  10021. *
  10022. * @static
  10023. * @memberOf _
  10024. * @since 4.0.0
  10025. * @category Function
  10026. * @param {Function} func The function to apply a rest parameter to.
  10027. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10028. * @returns {Function} Returns the new function.
  10029. * @example
  10030. *
  10031. * var say = _.rest(function(what, names) {
  10032. * return what + ' ' + _.initial(names).join(', ') +
  10033. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10034. * });
  10035. *
  10036. * say('hello', 'fred', 'barney', 'pebbles');
  10037. * // => 'hello fred, barney, & pebbles'
  10038. */
  10039. function rest(func, start) {
  10040. if (typeof func != 'function') {
  10041. throw new TypeError(FUNC_ERROR_TEXT);
  10042. }
  10043. start = start === undefined ? start : toInteger(start);
  10044. return baseRest(func, start);
  10045. }
  10046. /**
  10047. * Creates a function that invokes `func` with the `this` binding of the
  10048. * create function and an array of arguments much like
  10049. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10050. *
  10051. * **Note:** This method is based on the
  10052. * [spread operator](https://mdn.io/spread_operator).
  10053. *
  10054. * @static
  10055. * @memberOf _
  10056. * @since 3.2.0
  10057. * @category Function
  10058. * @param {Function} func The function to spread arguments over.
  10059. * @param {number} [start=0] The start position of the spread.
  10060. * @returns {Function} Returns the new function.
  10061. * @example
  10062. *
  10063. * var say = _.spread(function(who, what) {
  10064. * return who + ' says ' + what;
  10065. * });
  10066. *
  10067. * say(['fred', 'hello']);
  10068. * // => 'fred says hello'
  10069. *
  10070. * var numbers = Promise.all([
  10071. * Promise.resolve(40),
  10072. * Promise.resolve(36)
  10073. * ]);
  10074. *
  10075. * numbers.then(_.spread(function(x, y) {
  10076. * return x + y;
  10077. * }));
  10078. * // => a Promise of 76
  10079. */
  10080. function spread(func, start) {
  10081. if (typeof func != 'function') {
  10082. throw new TypeError(FUNC_ERROR_TEXT);
  10083. }
  10084. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10085. return baseRest(function(args) {
  10086. var array = args[start],
  10087. otherArgs = castSlice(args, 0, start);
  10088. if (array) {
  10089. arrayPush(otherArgs, array);
  10090. }
  10091. return apply(func, this, otherArgs);
  10092. });
  10093. }
  10094. /**
  10095. * Creates a throttled function that only invokes `func` at most once per
  10096. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10097. * method to cancel delayed `func` invocations and a `flush` method to
  10098. * immediately invoke them. Provide `options` to indicate whether `func`
  10099. * should be invoked on the leading and/or trailing edge of the `wait`
  10100. * timeout. The `func` is invoked with the last arguments provided to the
  10101. * throttled function. Subsequent calls to the throttled function return the
  10102. * result of the last `func` invocation.
  10103. *
  10104. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10105. * invoked on the trailing edge of the timeout only if the throttled function
  10106. * is invoked more than once during the `wait` timeout.
  10107. *
  10108. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10109. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10110. *
  10111. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10112. * for details over the differences between `_.throttle` and `_.debounce`.
  10113. *
  10114. * @static
  10115. * @memberOf _
  10116. * @since 0.1.0
  10117. * @category Function
  10118. * @param {Function} func The function to throttle.
  10119. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10120. * @param {Object} [options={}] The options object.
  10121. * @param {boolean} [options.leading=true]
  10122. * Specify invoking on the leading edge of the timeout.
  10123. * @param {boolean} [options.trailing=true]
  10124. * Specify invoking on the trailing edge of the timeout.
  10125. * @returns {Function} Returns the new throttled function.
  10126. * @example
  10127. *
  10128. * // Avoid excessively updating the position while scrolling.
  10129. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10130. *
  10131. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10132. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10133. * jQuery(element).on('click', throttled);
  10134. *
  10135. * // Cancel the trailing throttled invocation.
  10136. * jQuery(window).on('popstate', throttled.cancel);
  10137. */
  10138. function throttle(func, wait, options) {
  10139. var leading = true,
  10140. trailing = true;
  10141. if (typeof func != 'function') {
  10142. throw new TypeError(FUNC_ERROR_TEXT);
  10143. }
  10144. if (isObject(options)) {
  10145. leading = 'leading' in options ? !!options.leading : leading;
  10146. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10147. }
  10148. return debounce(func, wait, {
  10149. 'leading': leading,
  10150. 'maxWait': wait,
  10151. 'trailing': trailing
  10152. });
  10153. }
  10154. /**
  10155. * Creates a function that accepts up to one argument, ignoring any
  10156. * additional arguments.
  10157. *
  10158. * @static
  10159. * @memberOf _
  10160. * @since 4.0.0
  10161. * @category Function
  10162. * @param {Function} func The function to cap arguments for.
  10163. * @returns {Function} Returns the new capped function.
  10164. * @example
  10165. *
  10166. * _.map(['6', '8', '10'], _.unary(parseInt));
  10167. * // => [6, 8, 10]
  10168. */
  10169. function unary(func) {
  10170. return ary(func, 1);
  10171. }
  10172. /**
  10173. * Creates a function that provides `value` to `wrapper` as its first
  10174. * argument. Any additional arguments provided to the function are appended
  10175. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10176. * binding of the created function.
  10177. *
  10178. * @static
  10179. * @memberOf _
  10180. * @since 0.1.0
  10181. * @category Function
  10182. * @param {*} value The value to wrap.
  10183. * @param {Function} [wrapper=identity] The wrapper function.
  10184. * @returns {Function} Returns the new function.
  10185. * @example
  10186. *
  10187. * var p = _.wrap(_.escape, function(func, text) {
  10188. * return '<p>' + func(text) + '</p>';
  10189. * });
  10190. *
  10191. * p('fred, barney, & pebbles');
  10192. * // => '<p>fred, barney, &amp; pebbles</p>'
  10193. */
  10194. function wrap(value, wrapper) {
  10195. return partial(castFunction(wrapper), value);
  10196. }
  10197. /*------------------------------------------------------------------------*/
  10198. /**
  10199. * Casts `value` as an array if it's not one.
  10200. *
  10201. * @static
  10202. * @memberOf _
  10203. * @since 4.4.0
  10204. * @category Lang
  10205. * @param {*} value The value to inspect.
  10206. * @returns {Array} Returns the cast array.
  10207. * @example
  10208. *
  10209. * _.castArray(1);
  10210. * // => [1]
  10211. *
  10212. * _.castArray({ 'a': 1 });
  10213. * // => [{ 'a': 1 }]
  10214. *
  10215. * _.castArray('abc');
  10216. * // => ['abc']
  10217. *
  10218. * _.castArray(null);
  10219. * // => [null]
  10220. *
  10221. * _.castArray(undefined);
  10222. * // => [undefined]
  10223. *
  10224. * _.castArray();
  10225. * // => []
  10226. *
  10227. * var array = [1, 2, 3];
  10228. * console.log(_.castArray(array) === array);
  10229. * // => true
  10230. */
  10231. function castArray() {
  10232. if (!arguments.length) {
  10233. return [];
  10234. }
  10235. var value = arguments[0];
  10236. return isArray(value) ? value : [value];
  10237. }
  10238. /**
  10239. * Creates a shallow clone of `value`.
  10240. *
  10241. * **Note:** This method is loosely based on the
  10242. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10243. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10244. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10245. * arrays. The own enumerable properties of `arguments` objects are cloned
  10246. * as plain objects. An empty object is returned for uncloneable values such
  10247. * as error objects, functions, DOM nodes, and WeakMaps.
  10248. *
  10249. * @static
  10250. * @memberOf _
  10251. * @since 0.1.0
  10252. * @category Lang
  10253. * @param {*} value The value to clone.
  10254. * @returns {*} Returns the cloned value.
  10255. * @see _.cloneDeep
  10256. * @example
  10257. *
  10258. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10259. *
  10260. * var shallow = _.clone(objects);
  10261. * console.log(shallow[0] === objects[0]);
  10262. * // => true
  10263. */
  10264. function clone(value) {
  10265. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10266. }
  10267. /**
  10268. * This method is like `_.clone` except that it accepts `customizer` which
  10269. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10270. * cloning is handled by the method instead. The `customizer` is invoked with
  10271. * up to four arguments; (value [, index|key, object, stack]).
  10272. *
  10273. * @static
  10274. * @memberOf _
  10275. * @since 4.0.0
  10276. * @category Lang
  10277. * @param {*} value The value to clone.
  10278. * @param {Function} [customizer] The function to customize cloning.
  10279. * @returns {*} Returns the cloned value.
  10280. * @see _.cloneDeepWith
  10281. * @example
  10282. *
  10283. * function customizer(value) {
  10284. * if (_.isElement(value)) {
  10285. * return value.cloneNode(false);
  10286. * }
  10287. * }
  10288. *
  10289. * var el = _.cloneWith(document.body, customizer);
  10290. *
  10291. * console.log(el === document.body);
  10292. * // => false
  10293. * console.log(el.nodeName);
  10294. * // => 'BODY'
  10295. * console.log(el.childNodes.length);
  10296. * // => 0
  10297. */
  10298. function cloneWith(value, customizer) {
  10299. customizer = typeof customizer == 'function' ? customizer : undefined;
  10300. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10301. }
  10302. /**
  10303. * This method is like `_.clone` except that it recursively clones `value`.
  10304. *
  10305. * @static
  10306. * @memberOf _
  10307. * @since 1.0.0
  10308. * @category Lang
  10309. * @param {*} value The value to recursively clone.
  10310. * @returns {*} Returns the deep cloned value.
  10311. * @see _.clone
  10312. * @example
  10313. *
  10314. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10315. *
  10316. * var deep = _.cloneDeep(objects);
  10317. * console.log(deep[0] === objects[0]);
  10318. * // => false
  10319. */
  10320. function cloneDeep(value) {
  10321. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10322. }
  10323. /**
  10324. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10325. *
  10326. * @static
  10327. * @memberOf _
  10328. * @since 4.0.0
  10329. * @category Lang
  10330. * @param {*} value The value to recursively clone.
  10331. * @param {Function} [customizer] The function to customize cloning.
  10332. * @returns {*} Returns the deep cloned value.
  10333. * @see _.cloneWith
  10334. * @example
  10335. *
  10336. * function customizer(value) {
  10337. * if (_.isElement(value)) {
  10338. * return value.cloneNode(true);
  10339. * }
  10340. * }
  10341. *
  10342. * var el = _.cloneDeepWith(document.body, customizer);
  10343. *
  10344. * console.log(el === document.body);
  10345. * // => false
  10346. * console.log(el.nodeName);
  10347. * // => 'BODY'
  10348. * console.log(el.childNodes.length);
  10349. * // => 20
  10350. */
  10351. function cloneDeepWith(value, customizer) {
  10352. customizer = typeof customizer == 'function' ? customizer : undefined;
  10353. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10354. }
  10355. /**
  10356. * Checks if `object` conforms to `source` by invoking the predicate
  10357. * properties of `source` with the corresponding property values of `object`.
  10358. *
  10359. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10360. * partially applied.
  10361. *
  10362. * @static
  10363. * @memberOf _
  10364. * @since 4.14.0
  10365. * @category Lang
  10366. * @param {Object} object The object to inspect.
  10367. * @param {Object} source The object of property predicates to conform to.
  10368. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10369. * @example
  10370. *
  10371. * var object = { 'a': 1, 'b': 2 };
  10372. *
  10373. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10374. * // => true
  10375. *
  10376. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10377. * // => false
  10378. */
  10379. function conformsTo(object, source) {
  10380. return source == null || baseConformsTo(object, source, keys(source));
  10381. }
  10382. /**
  10383. * Performs a
  10384. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10385. * comparison between two values to determine if they are equivalent.
  10386. *
  10387. * @static
  10388. * @memberOf _
  10389. * @since 4.0.0
  10390. * @category Lang
  10391. * @param {*} value The value to compare.
  10392. * @param {*} other The other value to compare.
  10393. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10394. * @example
  10395. *
  10396. * var object = { 'a': 1 };
  10397. * var other = { 'a': 1 };
  10398. *
  10399. * _.eq(object, object);
  10400. * // => true
  10401. *
  10402. * _.eq(object, other);
  10403. * // => false
  10404. *
  10405. * _.eq('a', 'a');
  10406. * // => true
  10407. *
  10408. * _.eq('a', Object('a'));
  10409. * // => false
  10410. *
  10411. * _.eq(NaN, NaN);
  10412. * // => true
  10413. */
  10414. function eq(value, other) {
  10415. return value === other || (value !== value && other !== other);
  10416. }
  10417. /**
  10418. * Checks if `value` is greater than `other`.
  10419. *
  10420. * @static
  10421. * @memberOf _
  10422. * @since 3.9.0
  10423. * @category Lang
  10424. * @param {*} value The value to compare.
  10425. * @param {*} other The other value to compare.
  10426. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10427. * else `false`.
  10428. * @see _.lt
  10429. * @example
  10430. *
  10431. * _.gt(3, 1);
  10432. * // => true
  10433. *
  10434. * _.gt(3, 3);
  10435. * // => false
  10436. *
  10437. * _.gt(1, 3);
  10438. * // => false
  10439. */
  10440. var gt = createRelationalOperation(baseGt);
  10441. /**
  10442. * Checks if `value` is greater than or equal to `other`.
  10443. *
  10444. * @static
  10445. * @memberOf _
  10446. * @since 3.9.0
  10447. * @category Lang
  10448. * @param {*} value The value to compare.
  10449. * @param {*} other The other value to compare.
  10450. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10451. * `other`, else `false`.
  10452. * @see _.lte
  10453. * @example
  10454. *
  10455. * _.gte(3, 1);
  10456. * // => true
  10457. *
  10458. * _.gte(3, 3);
  10459. * // => true
  10460. *
  10461. * _.gte(1, 3);
  10462. * // => false
  10463. */
  10464. var gte = createRelationalOperation(function(value, other) {
  10465. return value >= other;
  10466. });
  10467. /**
  10468. * Checks if `value` is likely an `arguments` object.
  10469. *
  10470. * @static
  10471. * @memberOf _
  10472. * @since 0.1.0
  10473. * @category Lang
  10474. * @param {*} value The value to check.
  10475. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10476. * else `false`.
  10477. * @example
  10478. *
  10479. * _.isArguments(function() { return arguments; }());
  10480. * // => true
  10481. *
  10482. * _.isArguments([1, 2, 3]);
  10483. * // => false
  10484. */
  10485. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10486. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10487. !propertyIsEnumerable.call(value, 'callee');
  10488. };
  10489. /**
  10490. * Checks if `value` is classified as an `Array` object.
  10491. *
  10492. * @static
  10493. * @memberOf _
  10494. * @since 0.1.0
  10495. * @category Lang
  10496. * @param {*} value The value to check.
  10497. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10498. * @example
  10499. *
  10500. * _.isArray([1, 2, 3]);
  10501. * // => true
  10502. *
  10503. * _.isArray(document.body.children);
  10504. * // => false
  10505. *
  10506. * _.isArray('abc');
  10507. * // => false
  10508. *
  10509. * _.isArray(_.noop);
  10510. * // => false
  10511. */
  10512. var isArray = Array.isArray;
  10513. /**
  10514. * Checks if `value` is classified as an `ArrayBuffer` object.
  10515. *
  10516. * @static
  10517. * @memberOf _
  10518. * @since 4.3.0
  10519. * @category Lang
  10520. * @param {*} value The value to check.
  10521. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10522. * @example
  10523. *
  10524. * _.isArrayBuffer(new ArrayBuffer(2));
  10525. * // => true
  10526. *
  10527. * _.isArrayBuffer(new Array(2));
  10528. * // => false
  10529. */
  10530. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10531. /**
  10532. * Checks if `value` is array-like. A value is considered array-like if it's
  10533. * not a function and has a `value.length` that's an integer greater than or
  10534. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10535. *
  10536. * @static
  10537. * @memberOf _
  10538. * @since 4.0.0
  10539. * @category Lang
  10540. * @param {*} value The value to check.
  10541. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10542. * @example
  10543. *
  10544. * _.isArrayLike([1, 2, 3]);
  10545. * // => true
  10546. *
  10547. * _.isArrayLike(document.body.children);
  10548. * // => true
  10549. *
  10550. * _.isArrayLike('abc');
  10551. * // => true
  10552. *
  10553. * _.isArrayLike(_.noop);
  10554. * // => false
  10555. */
  10556. function isArrayLike(value) {
  10557. return value != null && isLength(value.length) && !isFunction(value);
  10558. }
  10559. /**
  10560. * This method is like `_.isArrayLike` except that it also checks if `value`
  10561. * is an object.
  10562. *
  10563. * @static
  10564. * @memberOf _
  10565. * @since 4.0.0
  10566. * @category Lang
  10567. * @param {*} value The value to check.
  10568. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10569. * else `false`.
  10570. * @example
  10571. *
  10572. * _.isArrayLikeObject([1, 2, 3]);
  10573. * // => true
  10574. *
  10575. * _.isArrayLikeObject(document.body.children);
  10576. * // => true
  10577. *
  10578. * _.isArrayLikeObject('abc');
  10579. * // => false
  10580. *
  10581. * _.isArrayLikeObject(_.noop);
  10582. * // => false
  10583. */
  10584. function isArrayLikeObject(value) {
  10585. return isObjectLike(value) && isArrayLike(value);
  10586. }
  10587. /**
  10588. * Checks if `value` is classified as a boolean primitive or object.
  10589. *
  10590. * @static
  10591. * @memberOf _
  10592. * @since 0.1.0
  10593. * @category Lang
  10594. * @param {*} value The value to check.
  10595. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10596. * @example
  10597. *
  10598. * _.isBoolean(false);
  10599. * // => true
  10600. *
  10601. * _.isBoolean(null);
  10602. * // => false
  10603. */
  10604. function isBoolean(value) {
  10605. return value === true || value === false ||
  10606. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10607. }
  10608. /**
  10609. * Checks if `value` is a buffer.
  10610. *
  10611. * @static
  10612. * @memberOf _
  10613. * @since 4.3.0
  10614. * @category Lang
  10615. * @param {*} value The value to check.
  10616. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10617. * @example
  10618. *
  10619. * _.isBuffer(new Buffer(2));
  10620. * // => true
  10621. *
  10622. * _.isBuffer(new Uint8Array(2));
  10623. * // => false
  10624. */
  10625. var isBuffer = nativeIsBuffer || stubFalse;
  10626. /**
  10627. * Checks if `value` is classified as a `Date` object.
  10628. *
  10629. * @static
  10630. * @memberOf _
  10631. * @since 0.1.0
  10632. * @category Lang
  10633. * @param {*} value The value to check.
  10634. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10635. * @example
  10636. *
  10637. * _.isDate(new Date);
  10638. * // => true
  10639. *
  10640. * _.isDate('Mon April 23 2012');
  10641. * // => false
  10642. */
  10643. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10644. /**
  10645. * Checks if `value` is likely a DOM element.
  10646. *
  10647. * @static
  10648. * @memberOf _
  10649. * @since 0.1.0
  10650. * @category Lang
  10651. * @param {*} value The value to check.
  10652. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10653. * @example
  10654. *
  10655. * _.isElement(document.body);
  10656. * // => true
  10657. *
  10658. * _.isElement('<body>');
  10659. * // => false
  10660. */
  10661. function isElement(value) {
  10662. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10663. }
  10664. /**
  10665. * Checks if `value` is an empty object, collection, map, or set.
  10666. *
  10667. * Objects are considered empty if they have no own enumerable string keyed
  10668. * properties.
  10669. *
  10670. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10671. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10672. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10673. *
  10674. * @static
  10675. * @memberOf _
  10676. * @since 0.1.0
  10677. * @category Lang
  10678. * @param {*} value The value to check.
  10679. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10680. * @example
  10681. *
  10682. * _.isEmpty(null);
  10683. * // => true
  10684. *
  10685. * _.isEmpty(true);
  10686. * // => true
  10687. *
  10688. * _.isEmpty(1);
  10689. * // => true
  10690. *
  10691. * _.isEmpty([1, 2, 3]);
  10692. * // => false
  10693. *
  10694. * _.isEmpty({ 'a': 1 });
  10695. * // => false
  10696. */
  10697. function isEmpty(value) {
  10698. if (value == null) {
  10699. return true;
  10700. }
  10701. if (isArrayLike(value) &&
  10702. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10703. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10704. return !value.length;
  10705. }
  10706. var tag = getTag(value);
  10707. if (tag == mapTag || tag == setTag) {
  10708. return !value.size;
  10709. }
  10710. if (isPrototype(value)) {
  10711. return !baseKeys(value).length;
  10712. }
  10713. for (var key in value) {
  10714. if (hasOwnProperty.call(value, key)) {
  10715. return false;
  10716. }
  10717. }
  10718. return true;
  10719. }
  10720. /**
  10721. * Performs a deep comparison between two values to determine if they are
  10722. * equivalent.
  10723. *
  10724. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10725. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10726. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10727. * by their own, not inherited, enumerable properties. Functions and DOM
  10728. * nodes are compared by strict equality, i.e. `===`.
  10729. *
  10730. * @static
  10731. * @memberOf _
  10732. * @since 0.1.0
  10733. * @category Lang
  10734. * @param {*} value The value to compare.
  10735. * @param {*} other The other value to compare.
  10736. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10737. * @example
  10738. *
  10739. * var object = { 'a': 1 };
  10740. * var other = { 'a': 1 };
  10741. *
  10742. * _.isEqual(object, other);
  10743. * // => true
  10744. *
  10745. * object === other;
  10746. * // => false
  10747. */
  10748. function isEqual(value, other) {
  10749. return baseIsEqual(value, other);
  10750. }
  10751. /**
  10752. * This method is like `_.isEqual` except that it accepts `customizer` which
  10753. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10754. * are handled by the method instead. The `customizer` is invoked with up to
  10755. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10756. *
  10757. * @static
  10758. * @memberOf _
  10759. * @since 4.0.0
  10760. * @category Lang
  10761. * @param {*} value The value to compare.
  10762. * @param {*} other The other value to compare.
  10763. * @param {Function} [customizer] The function to customize comparisons.
  10764. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10765. * @example
  10766. *
  10767. * function isGreeting(value) {
  10768. * return /^h(?:i|ello)$/.test(value);
  10769. * }
  10770. *
  10771. * function customizer(objValue, othValue) {
  10772. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10773. * return true;
  10774. * }
  10775. * }
  10776. *
  10777. * var array = ['hello', 'goodbye'];
  10778. * var other = ['hi', 'goodbye'];
  10779. *
  10780. * _.isEqualWith(array, other, customizer);
  10781. * // => true
  10782. */
  10783. function isEqualWith(value, other, customizer) {
  10784. customizer = typeof customizer == 'function' ? customizer : undefined;
  10785. var result = customizer ? customizer(value, other) : undefined;
  10786. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10787. }
  10788. /**
  10789. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10790. * `SyntaxError`, `TypeError`, or `URIError` object.
  10791. *
  10792. * @static
  10793. * @memberOf _
  10794. * @since 3.0.0
  10795. * @category Lang
  10796. * @param {*} value The value to check.
  10797. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10798. * @example
  10799. *
  10800. * _.isError(new Error);
  10801. * // => true
  10802. *
  10803. * _.isError(Error);
  10804. * // => false
  10805. */
  10806. function isError(value) {
  10807. if (!isObjectLike(value)) {
  10808. return false;
  10809. }
  10810. var tag = baseGetTag(value);
  10811. return tag == errorTag || tag == domExcTag ||
  10812. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10813. }
  10814. /**
  10815. * Checks if `value` is a finite primitive number.
  10816. *
  10817. * **Note:** This method is based on
  10818. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10819. *
  10820. * @static
  10821. * @memberOf _
  10822. * @since 0.1.0
  10823. * @category Lang
  10824. * @param {*} value The value to check.
  10825. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10826. * @example
  10827. *
  10828. * _.isFinite(3);
  10829. * // => true
  10830. *
  10831. * _.isFinite(Number.MIN_VALUE);
  10832. * // => true
  10833. *
  10834. * _.isFinite(Infinity);
  10835. * // => false
  10836. *
  10837. * _.isFinite('3');
  10838. * // => false
  10839. */
  10840. function isFinite(value) {
  10841. return typeof value == 'number' && nativeIsFinite(value);
  10842. }
  10843. /**
  10844. * Checks if `value` is classified as a `Function` object.
  10845. *
  10846. * @static
  10847. * @memberOf _
  10848. * @since 0.1.0
  10849. * @category Lang
  10850. * @param {*} value The value to check.
  10851. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10852. * @example
  10853. *
  10854. * _.isFunction(_);
  10855. * // => true
  10856. *
  10857. * _.isFunction(/abc/);
  10858. * // => false
  10859. */
  10860. function isFunction(value) {
  10861. if (!isObject(value)) {
  10862. return false;
  10863. }
  10864. // The use of `Object#toString` avoids issues with the `typeof` operator
  10865. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10866. var tag = baseGetTag(value);
  10867. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10868. }
  10869. /**
  10870. * Checks if `value` is an integer.
  10871. *
  10872. * **Note:** This method is based on
  10873. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10874. *
  10875. * @static
  10876. * @memberOf _
  10877. * @since 4.0.0
  10878. * @category Lang
  10879. * @param {*} value The value to check.
  10880. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10881. * @example
  10882. *
  10883. * _.isInteger(3);
  10884. * // => true
  10885. *
  10886. * _.isInteger(Number.MIN_VALUE);
  10887. * // => false
  10888. *
  10889. * _.isInteger(Infinity);
  10890. * // => false
  10891. *
  10892. * _.isInteger('3');
  10893. * // => false
  10894. */
  10895. function isInteger(value) {
  10896. return typeof value == 'number' && value == toInteger(value);
  10897. }
  10898. /**
  10899. * Checks if `value` is a valid array-like length.
  10900. *
  10901. * **Note:** This method is loosely based on
  10902. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10903. *
  10904. * @static
  10905. * @memberOf _
  10906. * @since 4.0.0
  10907. * @category Lang
  10908. * @param {*} value The value to check.
  10909. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10910. * @example
  10911. *
  10912. * _.isLength(3);
  10913. * // => true
  10914. *
  10915. * _.isLength(Number.MIN_VALUE);
  10916. * // => false
  10917. *
  10918. * _.isLength(Infinity);
  10919. * // => false
  10920. *
  10921. * _.isLength('3');
  10922. * // => false
  10923. */
  10924. function isLength(value) {
  10925. return typeof value == 'number' &&
  10926. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10927. }
  10928. /**
  10929. * Checks if `value` is the
  10930. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10931. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10932. *
  10933. * @static
  10934. * @memberOf _
  10935. * @since 0.1.0
  10936. * @category Lang
  10937. * @param {*} value The value to check.
  10938. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10939. * @example
  10940. *
  10941. * _.isObject({});
  10942. * // => true
  10943. *
  10944. * _.isObject([1, 2, 3]);
  10945. * // => true
  10946. *
  10947. * _.isObject(_.noop);
  10948. * // => true
  10949. *
  10950. * _.isObject(null);
  10951. * // => false
  10952. */
  10953. function isObject(value) {
  10954. var type = typeof value;
  10955. return value != null && (type == 'object' || type == 'function');
  10956. }
  10957. /**
  10958. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10959. * and has a `typeof` result of "object".
  10960. *
  10961. * @static
  10962. * @memberOf _
  10963. * @since 4.0.0
  10964. * @category Lang
  10965. * @param {*} value The value to check.
  10966. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10967. * @example
  10968. *
  10969. * _.isObjectLike({});
  10970. * // => true
  10971. *
  10972. * _.isObjectLike([1, 2, 3]);
  10973. * // => true
  10974. *
  10975. * _.isObjectLike(_.noop);
  10976. * // => false
  10977. *
  10978. * _.isObjectLike(null);
  10979. * // => false
  10980. */
  10981. function isObjectLike(value) {
  10982. return value != null && typeof value == 'object';
  10983. }
  10984. /**
  10985. * Checks if `value` is classified as a `Map` object.
  10986. *
  10987. * @static
  10988. * @memberOf _
  10989. * @since 4.3.0
  10990. * @category Lang
  10991. * @param {*} value The value to check.
  10992. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10993. * @example
  10994. *
  10995. * _.isMap(new Map);
  10996. * // => true
  10997. *
  10998. * _.isMap(new WeakMap);
  10999. * // => false
  11000. */
  11001. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11002. /**
  11003. * Performs a partial deep comparison between `object` and `source` to
  11004. * determine if `object` contains equivalent property values.
  11005. *
  11006. * **Note:** This method is equivalent to `_.matches` when `source` is
  11007. * partially applied.
  11008. *
  11009. * Partial comparisons will match empty array and empty object `source`
  11010. * values against any array or object value, respectively. See `_.isEqual`
  11011. * for a list of supported value comparisons.
  11012. *
  11013. * @static
  11014. * @memberOf _
  11015. * @since 3.0.0
  11016. * @category Lang
  11017. * @param {Object} object The object to inspect.
  11018. * @param {Object} source The object of property values to match.
  11019. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11020. * @example
  11021. *
  11022. * var object = { 'a': 1, 'b': 2 };
  11023. *
  11024. * _.isMatch(object, { 'b': 2 });
  11025. * // => true
  11026. *
  11027. * _.isMatch(object, { 'b': 1 });
  11028. * // => false
  11029. */
  11030. function isMatch(object, source) {
  11031. return object === source || baseIsMatch(object, source, getMatchData(source));
  11032. }
  11033. /**
  11034. * This method is like `_.isMatch` except that it accepts `customizer` which
  11035. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11036. * are handled by the method instead. The `customizer` is invoked with five
  11037. * arguments: (objValue, srcValue, index|key, object, source).
  11038. *
  11039. * @static
  11040. * @memberOf _
  11041. * @since 4.0.0
  11042. * @category Lang
  11043. * @param {Object} object The object to inspect.
  11044. * @param {Object} source The object of property values to match.
  11045. * @param {Function} [customizer] The function to customize comparisons.
  11046. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11047. * @example
  11048. *
  11049. * function isGreeting(value) {
  11050. * return /^h(?:i|ello)$/.test(value);
  11051. * }
  11052. *
  11053. * function customizer(objValue, srcValue) {
  11054. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11055. * return true;
  11056. * }
  11057. * }
  11058. *
  11059. * var object = { 'greeting': 'hello' };
  11060. * var source = { 'greeting': 'hi' };
  11061. *
  11062. * _.isMatchWith(object, source, customizer);
  11063. * // => true
  11064. */
  11065. function isMatchWith(object, source, customizer) {
  11066. customizer = typeof customizer == 'function' ? customizer : undefined;
  11067. return baseIsMatch(object, source, getMatchData(source), customizer);
  11068. }
  11069. /**
  11070. * Checks if `value` is `NaN`.
  11071. *
  11072. * **Note:** This method is based on
  11073. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11074. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11075. * `undefined` and other non-number values.
  11076. *
  11077. * @static
  11078. * @memberOf _
  11079. * @since 0.1.0
  11080. * @category Lang
  11081. * @param {*} value The value to check.
  11082. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11083. * @example
  11084. *
  11085. * _.isNaN(NaN);
  11086. * // => true
  11087. *
  11088. * _.isNaN(new Number(NaN));
  11089. * // => true
  11090. *
  11091. * isNaN(undefined);
  11092. * // => true
  11093. *
  11094. * _.isNaN(undefined);
  11095. * // => false
  11096. */
  11097. function isNaN(value) {
  11098. // An `NaN` primitive is the only value that is not equal to itself.
  11099. // Perform the `toStringTag` check first to avoid errors with some
  11100. // ActiveX objects in IE.
  11101. return isNumber(value) && value != +value;
  11102. }
  11103. /**
  11104. * Checks if `value` is a pristine native function.
  11105. *
  11106. * **Note:** This method can't reliably detect native functions in the presence
  11107. * of the core-js package because core-js circumvents this kind of detection.
  11108. * Despite multiple requests, the core-js maintainer has made it clear: any
  11109. * attempt to fix the detection will be obstructed. As a result, we're left
  11110. * with little choice but to throw an error. Unfortunately, this also affects
  11111. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11112. * which rely on core-js.
  11113. *
  11114. * @static
  11115. * @memberOf _
  11116. * @since 3.0.0
  11117. * @category Lang
  11118. * @param {*} value The value to check.
  11119. * @returns {boolean} Returns `true` if `value` is a native function,
  11120. * else `false`.
  11121. * @example
  11122. *
  11123. * _.isNative(Array.prototype.push);
  11124. * // => true
  11125. *
  11126. * _.isNative(_);
  11127. * // => false
  11128. */
  11129. function isNative(value) {
  11130. if (isMaskable(value)) {
  11131. throw new Error(CORE_ERROR_TEXT);
  11132. }
  11133. return baseIsNative(value);
  11134. }
  11135. /**
  11136. * Checks if `value` is `null`.
  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 `null`, else `false`.
  11144. * @example
  11145. *
  11146. * _.isNull(null);
  11147. * // => true
  11148. *
  11149. * _.isNull(void 0);
  11150. * // => false
  11151. */
  11152. function isNull(value) {
  11153. return value === null;
  11154. }
  11155. /**
  11156. * Checks if `value` is `null` or `undefined`.
  11157. *
  11158. * @static
  11159. * @memberOf _
  11160. * @since 4.0.0
  11161. * @category Lang
  11162. * @param {*} value The value to check.
  11163. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11164. * @example
  11165. *
  11166. * _.isNil(null);
  11167. * // => true
  11168. *
  11169. * _.isNil(void 0);
  11170. * // => true
  11171. *
  11172. * _.isNil(NaN);
  11173. * // => false
  11174. */
  11175. function isNil(value) {
  11176. return value == null;
  11177. }
  11178. /**
  11179. * Checks if `value` is classified as a `Number` primitive or object.
  11180. *
  11181. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11182. * classified as numbers, use the `_.isFinite` method.
  11183. *
  11184. * @static
  11185. * @memberOf _
  11186. * @since 0.1.0
  11187. * @category Lang
  11188. * @param {*} value The value to check.
  11189. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11190. * @example
  11191. *
  11192. * _.isNumber(3);
  11193. * // => true
  11194. *
  11195. * _.isNumber(Number.MIN_VALUE);
  11196. * // => true
  11197. *
  11198. * _.isNumber(Infinity);
  11199. * // => true
  11200. *
  11201. * _.isNumber('3');
  11202. * // => false
  11203. */
  11204. function isNumber(value) {
  11205. return typeof value == 'number' ||
  11206. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11207. }
  11208. /**
  11209. * Checks if `value` is a plain object, that is, an object created by the
  11210. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11211. *
  11212. * @static
  11213. * @memberOf _
  11214. * @since 0.8.0
  11215. * @category Lang
  11216. * @param {*} value The value to check.
  11217. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11218. * @example
  11219. *
  11220. * function Foo() {
  11221. * this.a = 1;
  11222. * }
  11223. *
  11224. * _.isPlainObject(new Foo);
  11225. * // => false
  11226. *
  11227. * _.isPlainObject([1, 2, 3]);
  11228. * // => false
  11229. *
  11230. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11231. * // => true
  11232. *
  11233. * _.isPlainObject(Object.create(null));
  11234. * // => true
  11235. */
  11236. function isPlainObject(value) {
  11237. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11238. return false;
  11239. }
  11240. var proto = getPrototype(value);
  11241. if (proto === null) {
  11242. return true;
  11243. }
  11244. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11245. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11246. funcToString.call(Ctor) == objectCtorString;
  11247. }
  11248. /**
  11249. * Checks if `value` is classified as a `RegExp` object.
  11250. *
  11251. * @static
  11252. * @memberOf _
  11253. * @since 0.1.0
  11254. * @category Lang
  11255. * @param {*} value The value to check.
  11256. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11257. * @example
  11258. *
  11259. * _.isRegExp(/abc/);
  11260. * // => true
  11261. *
  11262. * _.isRegExp('/abc/');
  11263. * // => false
  11264. */
  11265. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11266. /**
  11267. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11268. * double precision number which isn't the result of a rounded unsafe integer.
  11269. *
  11270. * **Note:** This method is based on
  11271. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11272. *
  11273. * @static
  11274. * @memberOf _
  11275. * @since 4.0.0
  11276. * @category Lang
  11277. * @param {*} value The value to check.
  11278. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11279. * @example
  11280. *
  11281. * _.isSafeInteger(3);
  11282. * // => true
  11283. *
  11284. * _.isSafeInteger(Number.MIN_VALUE);
  11285. * // => false
  11286. *
  11287. * _.isSafeInteger(Infinity);
  11288. * // => false
  11289. *
  11290. * _.isSafeInteger('3');
  11291. * // => false
  11292. */
  11293. function isSafeInteger(value) {
  11294. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11295. }
  11296. /**
  11297. * Checks if `value` is classified as a `Set` object.
  11298. *
  11299. * @static
  11300. * @memberOf _
  11301. * @since 4.3.0
  11302. * @category Lang
  11303. * @param {*} value The value to check.
  11304. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11305. * @example
  11306. *
  11307. * _.isSet(new Set);
  11308. * // => true
  11309. *
  11310. * _.isSet(new WeakSet);
  11311. * // => false
  11312. */
  11313. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11314. /**
  11315. * Checks if `value` is classified as a `String` primitive or object.
  11316. *
  11317. * @static
  11318. * @since 0.1.0
  11319. * @memberOf _
  11320. * @category Lang
  11321. * @param {*} value The value to check.
  11322. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11323. * @example
  11324. *
  11325. * _.isString('abc');
  11326. * // => true
  11327. *
  11328. * _.isString(1);
  11329. * // => false
  11330. */
  11331. function isString(value) {
  11332. return typeof value == 'string' ||
  11333. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11334. }
  11335. /**
  11336. * Checks if `value` is classified as a `Symbol` primitive or object.
  11337. *
  11338. * @static
  11339. * @memberOf _
  11340. * @since 4.0.0
  11341. * @category Lang
  11342. * @param {*} value The value to check.
  11343. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11344. * @example
  11345. *
  11346. * _.isSymbol(Symbol.iterator);
  11347. * // => true
  11348. *
  11349. * _.isSymbol('abc');
  11350. * // => false
  11351. */
  11352. function isSymbol(value) {
  11353. return typeof value == 'symbol' ||
  11354. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11355. }
  11356. /**
  11357. * Checks if `value` is classified as a typed array.
  11358. *
  11359. * @static
  11360. * @memberOf _
  11361. * @since 3.0.0
  11362. * @category Lang
  11363. * @param {*} value The value to check.
  11364. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11365. * @example
  11366. *
  11367. * _.isTypedArray(new Uint8Array);
  11368. * // => true
  11369. *
  11370. * _.isTypedArray([]);
  11371. * // => false
  11372. */
  11373. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11374. /**
  11375. * Checks if `value` is `undefined`.
  11376. *
  11377. * @static
  11378. * @since 0.1.0
  11379. * @memberOf _
  11380. * @category Lang
  11381. * @param {*} value The value to check.
  11382. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11383. * @example
  11384. *
  11385. * _.isUndefined(void 0);
  11386. * // => true
  11387. *
  11388. * _.isUndefined(null);
  11389. * // => false
  11390. */
  11391. function isUndefined(value) {
  11392. return value === undefined;
  11393. }
  11394. /**
  11395. * Checks if `value` is classified as a `WeakMap` object.
  11396. *
  11397. * @static
  11398. * @memberOf _
  11399. * @since 4.3.0
  11400. * @category Lang
  11401. * @param {*} value The value to check.
  11402. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11403. * @example
  11404. *
  11405. * _.isWeakMap(new WeakMap);
  11406. * // => true
  11407. *
  11408. * _.isWeakMap(new Map);
  11409. * // => false
  11410. */
  11411. function isWeakMap(value) {
  11412. return isObjectLike(value) && getTag(value) == weakMapTag;
  11413. }
  11414. /**
  11415. * Checks if `value` is classified as a `WeakSet` object.
  11416. *
  11417. * @static
  11418. * @memberOf _
  11419. * @since 4.3.0
  11420. * @category Lang
  11421. * @param {*} value The value to check.
  11422. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11423. * @example
  11424. *
  11425. * _.isWeakSet(new WeakSet);
  11426. * // => true
  11427. *
  11428. * _.isWeakSet(new Set);
  11429. * // => false
  11430. */
  11431. function isWeakSet(value) {
  11432. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11433. }
  11434. /**
  11435. * Checks if `value` is less than `other`.
  11436. *
  11437. * @static
  11438. * @memberOf _
  11439. * @since 3.9.0
  11440. * @category Lang
  11441. * @param {*} value The value to compare.
  11442. * @param {*} other The other value to compare.
  11443. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11444. * else `false`.
  11445. * @see _.gt
  11446. * @example
  11447. *
  11448. * _.lt(1, 3);
  11449. * // => true
  11450. *
  11451. * _.lt(3, 3);
  11452. * // => false
  11453. *
  11454. * _.lt(3, 1);
  11455. * // => false
  11456. */
  11457. var lt = createRelationalOperation(baseLt);
  11458. /**
  11459. * Checks if `value` is less than or equal to `other`.
  11460. *
  11461. * @static
  11462. * @memberOf _
  11463. * @since 3.9.0
  11464. * @category Lang
  11465. * @param {*} value The value to compare.
  11466. * @param {*} other The other value to compare.
  11467. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11468. * `other`, else `false`.
  11469. * @see _.gte
  11470. * @example
  11471. *
  11472. * _.lte(1, 3);
  11473. * // => true
  11474. *
  11475. * _.lte(3, 3);
  11476. * // => true
  11477. *
  11478. * _.lte(3, 1);
  11479. * // => false
  11480. */
  11481. var lte = createRelationalOperation(function(value, other) {
  11482. return value <= other;
  11483. });
  11484. /**
  11485. * Converts `value` to an array.
  11486. *
  11487. * @static
  11488. * @since 0.1.0
  11489. * @memberOf _
  11490. * @category Lang
  11491. * @param {*} value The value to convert.
  11492. * @returns {Array} Returns the converted array.
  11493. * @example
  11494. *
  11495. * _.toArray({ 'a': 1, 'b': 2 });
  11496. * // => [1, 2]
  11497. *
  11498. * _.toArray('abc');
  11499. * // => ['a', 'b', 'c']
  11500. *
  11501. * _.toArray(1);
  11502. * // => []
  11503. *
  11504. * _.toArray(null);
  11505. * // => []
  11506. */
  11507. function toArray(value) {
  11508. if (!value) {
  11509. return [];
  11510. }
  11511. if (isArrayLike(value)) {
  11512. return isString(value) ? stringToArray(value) : copyArray(value);
  11513. }
  11514. if (symIterator && value[symIterator]) {
  11515. return iteratorToArray(value[symIterator]());
  11516. }
  11517. var tag = getTag(value),
  11518. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11519. return func(value);
  11520. }
  11521. /**
  11522. * Converts `value` to a finite number.
  11523. *
  11524. * @static
  11525. * @memberOf _
  11526. * @since 4.12.0
  11527. * @category Lang
  11528. * @param {*} value The value to convert.
  11529. * @returns {number} Returns the converted number.
  11530. * @example
  11531. *
  11532. * _.toFinite(3.2);
  11533. * // => 3.2
  11534. *
  11535. * _.toFinite(Number.MIN_VALUE);
  11536. * // => 5e-324
  11537. *
  11538. * _.toFinite(Infinity);
  11539. * // => 1.7976931348623157e+308
  11540. *
  11541. * _.toFinite('3.2');
  11542. * // => 3.2
  11543. */
  11544. function toFinite(value) {
  11545. if (!value) {
  11546. return value === 0 ? value : 0;
  11547. }
  11548. value = toNumber(value);
  11549. if (value === INFINITY || value === -INFINITY) {
  11550. var sign = (value < 0 ? -1 : 1);
  11551. return sign * MAX_INTEGER;
  11552. }
  11553. return value === value ? value : 0;
  11554. }
  11555. /**
  11556. * Converts `value` to an integer.
  11557. *
  11558. * **Note:** This method is loosely based on
  11559. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11560. *
  11561. * @static
  11562. * @memberOf _
  11563. * @since 4.0.0
  11564. * @category Lang
  11565. * @param {*} value The value to convert.
  11566. * @returns {number} Returns the converted integer.
  11567. * @example
  11568. *
  11569. * _.toInteger(3.2);
  11570. * // => 3
  11571. *
  11572. * _.toInteger(Number.MIN_VALUE);
  11573. * // => 0
  11574. *
  11575. * _.toInteger(Infinity);
  11576. * // => 1.7976931348623157e+308
  11577. *
  11578. * _.toInteger('3.2');
  11579. * // => 3
  11580. */
  11581. function toInteger(value) {
  11582. var result = toFinite(value),
  11583. remainder = result % 1;
  11584. return result === result ? (remainder ? result - remainder : result) : 0;
  11585. }
  11586. /**
  11587. * Converts `value` to an integer suitable for use as the length of an
  11588. * array-like object.
  11589. *
  11590. * **Note:** This method is based on
  11591. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11592. *
  11593. * @static
  11594. * @memberOf _
  11595. * @since 4.0.0
  11596. * @category Lang
  11597. * @param {*} value The value to convert.
  11598. * @returns {number} Returns the converted integer.
  11599. * @example
  11600. *
  11601. * _.toLength(3.2);
  11602. * // => 3
  11603. *
  11604. * _.toLength(Number.MIN_VALUE);
  11605. * // => 0
  11606. *
  11607. * _.toLength(Infinity);
  11608. * // => 4294967295
  11609. *
  11610. * _.toLength('3.2');
  11611. * // => 3
  11612. */
  11613. function toLength(value) {
  11614. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11615. }
  11616. /**
  11617. * Converts `value` to a number.
  11618. *
  11619. * @static
  11620. * @memberOf _
  11621. * @since 4.0.0
  11622. * @category Lang
  11623. * @param {*} value The value to process.
  11624. * @returns {number} Returns the number.
  11625. * @example
  11626. *
  11627. * _.toNumber(3.2);
  11628. * // => 3.2
  11629. *
  11630. * _.toNumber(Number.MIN_VALUE);
  11631. * // => 5e-324
  11632. *
  11633. * _.toNumber(Infinity);
  11634. * // => Infinity
  11635. *
  11636. * _.toNumber('3.2');
  11637. * // => 3.2
  11638. */
  11639. function toNumber(value) {
  11640. if (typeof value == 'number') {
  11641. return value;
  11642. }
  11643. if (isSymbol(value)) {
  11644. return NAN;
  11645. }
  11646. if (isObject(value)) {
  11647. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11648. value = isObject(other) ? (other + '') : other;
  11649. }
  11650. if (typeof value != 'string') {
  11651. return value === 0 ? value : +value;
  11652. }
  11653. value = value.replace(reTrim, '');
  11654. var isBinary = reIsBinary.test(value);
  11655. return (isBinary || reIsOctal.test(value))
  11656. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11657. : (reIsBadHex.test(value) ? NAN : +value);
  11658. }
  11659. /**
  11660. * Converts `value` to a plain object flattening inherited enumerable string
  11661. * keyed properties of `value` to own properties of the plain object.
  11662. *
  11663. * @static
  11664. * @memberOf _
  11665. * @since 3.0.0
  11666. * @category Lang
  11667. * @param {*} value The value to convert.
  11668. * @returns {Object} Returns the converted plain object.
  11669. * @example
  11670. *
  11671. * function Foo() {
  11672. * this.b = 2;
  11673. * }
  11674. *
  11675. * Foo.prototype.c = 3;
  11676. *
  11677. * _.assign({ 'a': 1 }, new Foo);
  11678. * // => { 'a': 1, 'b': 2 }
  11679. *
  11680. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11681. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11682. */
  11683. function toPlainObject(value) {
  11684. return copyObject(value, keysIn(value));
  11685. }
  11686. /**
  11687. * Converts `value` to a safe integer. A safe integer can be compared and
  11688. * represented correctly.
  11689. *
  11690. * @static
  11691. * @memberOf _
  11692. * @since 4.0.0
  11693. * @category Lang
  11694. * @param {*} value The value to convert.
  11695. * @returns {number} Returns the converted integer.
  11696. * @example
  11697. *
  11698. * _.toSafeInteger(3.2);
  11699. * // => 3
  11700. *
  11701. * _.toSafeInteger(Number.MIN_VALUE);
  11702. * // => 0
  11703. *
  11704. * _.toSafeInteger(Infinity);
  11705. * // => 9007199254740991
  11706. *
  11707. * _.toSafeInteger('3.2');
  11708. * // => 3
  11709. */
  11710. function toSafeInteger(value) {
  11711. return value
  11712. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11713. : (value === 0 ? value : 0);
  11714. }
  11715. /**
  11716. * Converts `value` to a string. An empty string is returned for `null`
  11717. * and `undefined` values. The sign of `-0` is preserved.
  11718. *
  11719. * @static
  11720. * @memberOf _
  11721. * @since 4.0.0
  11722. * @category Lang
  11723. * @param {*} value The value to convert.
  11724. * @returns {string} Returns the converted string.
  11725. * @example
  11726. *
  11727. * _.toString(null);
  11728. * // => ''
  11729. *
  11730. * _.toString(-0);
  11731. * // => '-0'
  11732. *
  11733. * _.toString([1, 2, 3]);
  11734. * // => '1,2,3'
  11735. */
  11736. function toString(value) {
  11737. return value == null ? '' : baseToString(value);
  11738. }
  11739. /*------------------------------------------------------------------------*/
  11740. /**
  11741. * Assigns own enumerable string keyed properties of source objects to the
  11742. * destination object. Source objects are applied from left to right.
  11743. * Subsequent sources overwrite property assignments of previous sources.
  11744. *
  11745. * **Note:** This method mutates `object` and is loosely based on
  11746. * [`Object.assign`](https://mdn.io/Object/assign).
  11747. *
  11748. * @static
  11749. * @memberOf _
  11750. * @since 0.10.0
  11751. * @category Object
  11752. * @param {Object} object The destination object.
  11753. * @param {...Object} [sources] The source objects.
  11754. * @returns {Object} Returns `object`.
  11755. * @see _.assignIn
  11756. * @example
  11757. *
  11758. * function Foo() {
  11759. * this.a = 1;
  11760. * }
  11761. *
  11762. * function Bar() {
  11763. * this.c = 3;
  11764. * }
  11765. *
  11766. * Foo.prototype.b = 2;
  11767. * Bar.prototype.d = 4;
  11768. *
  11769. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11770. * // => { 'a': 1, 'c': 3 }
  11771. */
  11772. var assign = createAssigner(function(object, source) {
  11773. if (isPrototype(source) || isArrayLike(source)) {
  11774. copyObject(source, keys(source), object);
  11775. return;
  11776. }
  11777. for (var key in source) {
  11778. if (hasOwnProperty.call(source, key)) {
  11779. assignValue(object, key, source[key]);
  11780. }
  11781. }
  11782. });
  11783. /**
  11784. * This method is like `_.assign` except that it iterates over own and
  11785. * inherited source properties.
  11786. *
  11787. * **Note:** This method mutates `object`.
  11788. *
  11789. * @static
  11790. * @memberOf _
  11791. * @since 4.0.0
  11792. * @alias extend
  11793. * @category Object
  11794. * @param {Object} object The destination object.
  11795. * @param {...Object} [sources] The source objects.
  11796. * @returns {Object} Returns `object`.
  11797. * @see _.assign
  11798. * @example
  11799. *
  11800. * function Foo() {
  11801. * this.a = 1;
  11802. * }
  11803. *
  11804. * function Bar() {
  11805. * this.c = 3;
  11806. * }
  11807. *
  11808. * Foo.prototype.b = 2;
  11809. * Bar.prototype.d = 4;
  11810. *
  11811. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11812. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11813. */
  11814. var assignIn = createAssigner(function(object, source) {
  11815. copyObject(source, keysIn(source), object);
  11816. });
  11817. /**
  11818. * This method is like `_.assignIn` except that it accepts `customizer`
  11819. * which is invoked to produce the assigned values. If `customizer` returns
  11820. * `undefined`, assignment is handled by the method instead. The `customizer`
  11821. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11822. *
  11823. * **Note:** This method mutates `object`.
  11824. *
  11825. * @static
  11826. * @memberOf _
  11827. * @since 4.0.0
  11828. * @alias extendWith
  11829. * @category Object
  11830. * @param {Object} object The destination object.
  11831. * @param {...Object} sources The source objects.
  11832. * @param {Function} [customizer] The function to customize assigned values.
  11833. * @returns {Object} Returns `object`.
  11834. * @see _.assignWith
  11835. * @example
  11836. *
  11837. * function customizer(objValue, srcValue) {
  11838. * return _.isUndefined(objValue) ? srcValue : objValue;
  11839. * }
  11840. *
  11841. * var defaults = _.partialRight(_.assignInWith, customizer);
  11842. *
  11843. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11844. * // => { 'a': 1, 'b': 2 }
  11845. */
  11846. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11847. copyObject(source, keysIn(source), object, customizer);
  11848. });
  11849. /**
  11850. * This method is like `_.assign` except that it accepts `customizer`
  11851. * which is invoked to produce the assigned values. If `customizer` returns
  11852. * `undefined`, assignment is handled by the method instead. The `customizer`
  11853. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11854. *
  11855. * **Note:** This method mutates `object`.
  11856. *
  11857. * @static
  11858. * @memberOf _
  11859. * @since 4.0.0
  11860. * @category Object
  11861. * @param {Object} object The destination object.
  11862. * @param {...Object} sources The source objects.
  11863. * @param {Function} [customizer] The function to customize assigned values.
  11864. * @returns {Object} Returns `object`.
  11865. * @see _.assignInWith
  11866. * @example
  11867. *
  11868. * function customizer(objValue, srcValue) {
  11869. * return _.isUndefined(objValue) ? srcValue : objValue;
  11870. * }
  11871. *
  11872. * var defaults = _.partialRight(_.assignWith, customizer);
  11873. *
  11874. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11875. * // => { 'a': 1, 'b': 2 }
  11876. */
  11877. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11878. copyObject(source, keys(source), object, customizer);
  11879. });
  11880. /**
  11881. * Creates an array of values corresponding to `paths` of `object`.
  11882. *
  11883. * @static
  11884. * @memberOf _
  11885. * @since 1.0.0
  11886. * @category Object
  11887. * @param {Object} object The object to iterate over.
  11888. * @param {...(string|string[])} [paths] The property paths to pick.
  11889. * @returns {Array} Returns the picked values.
  11890. * @example
  11891. *
  11892. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11893. *
  11894. * _.at(object, ['a[0].b.c', 'a[1]']);
  11895. * // => [3, 4]
  11896. */
  11897. var at = flatRest(baseAt);
  11898. /**
  11899. * Creates an object that inherits from the `prototype` object. If a
  11900. * `properties` object is given, its own enumerable string keyed properties
  11901. * are assigned to the created object.
  11902. *
  11903. * @static
  11904. * @memberOf _
  11905. * @since 2.3.0
  11906. * @category Object
  11907. * @param {Object} prototype The object to inherit from.
  11908. * @param {Object} [properties] The properties to assign to the object.
  11909. * @returns {Object} Returns the new object.
  11910. * @example
  11911. *
  11912. * function Shape() {
  11913. * this.x = 0;
  11914. * this.y = 0;
  11915. * }
  11916. *
  11917. * function Circle() {
  11918. * Shape.call(this);
  11919. * }
  11920. *
  11921. * Circle.prototype = _.create(Shape.prototype, {
  11922. * 'constructor': Circle
  11923. * });
  11924. *
  11925. * var circle = new Circle;
  11926. * circle instanceof Circle;
  11927. * // => true
  11928. *
  11929. * circle instanceof Shape;
  11930. * // => true
  11931. */
  11932. function create(prototype, properties) {
  11933. var result = baseCreate(prototype);
  11934. return properties == null ? result : baseAssign(result, properties);
  11935. }
  11936. /**
  11937. * Assigns own and inherited enumerable string keyed properties of source
  11938. * objects to the destination object for all destination properties that
  11939. * resolve to `undefined`. Source objects are applied from left to right.
  11940. * Once a property is set, additional values of the same property are ignored.
  11941. *
  11942. * **Note:** This method mutates `object`.
  11943. *
  11944. * @static
  11945. * @since 0.1.0
  11946. * @memberOf _
  11947. * @category Object
  11948. * @param {Object} object The destination object.
  11949. * @param {...Object} [sources] The source objects.
  11950. * @returns {Object} Returns `object`.
  11951. * @see _.defaultsDeep
  11952. * @example
  11953. *
  11954. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11955. * // => { 'a': 1, 'b': 2 }
  11956. */
  11957. var defaults = baseRest(function(object, sources) {
  11958. object = Object(object);
  11959. var index = -1;
  11960. var length = sources.length;
  11961. var guard = length > 2 ? sources[2] : undefined;
  11962. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  11963. length = 1;
  11964. }
  11965. while (++index < length) {
  11966. var source = sources[index];
  11967. var props = keysIn(source);
  11968. var propsIndex = -1;
  11969. var propsLength = props.length;
  11970. while (++propsIndex < propsLength) {
  11971. var key = props[propsIndex];
  11972. var value = object[key];
  11973. if (value === undefined ||
  11974. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  11975. object[key] = source[key];
  11976. }
  11977. }
  11978. }
  11979. return object;
  11980. });
  11981. /**
  11982. * This method is like `_.defaults` except that it recursively assigns
  11983. * default properties.
  11984. *
  11985. * **Note:** This method mutates `object`.
  11986. *
  11987. * @static
  11988. * @memberOf _
  11989. * @since 3.10.0
  11990. * @category Object
  11991. * @param {Object} object The destination object.
  11992. * @param {...Object} [sources] The source objects.
  11993. * @returns {Object} Returns `object`.
  11994. * @see _.defaults
  11995. * @example
  11996. *
  11997. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11998. * // => { 'a': { 'b': 2, 'c': 3 } }
  11999. */
  12000. var defaultsDeep = baseRest(function(args) {
  12001. args.push(undefined, customDefaultsMerge);
  12002. return apply(mergeWith, undefined, args);
  12003. });
  12004. /**
  12005. * This method is like `_.find` except that it returns the key of the first
  12006. * element `predicate` returns truthy for instead of the element itself.
  12007. *
  12008. * @static
  12009. * @memberOf _
  12010. * @since 1.1.0
  12011. * @category Object
  12012. * @param {Object} object The object to inspect.
  12013. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12014. * @returns {string|undefined} Returns the key of the matched element,
  12015. * else `undefined`.
  12016. * @example
  12017. *
  12018. * var users = {
  12019. * 'barney': { 'age': 36, 'active': true },
  12020. * 'fred': { 'age': 40, 'active': false },
  12021. * 'pebbles': { 'age': 1, 'active': true }
  12022. * };
  12023. *
  12024. * _.findKey(users, function(o) { return o.age < 40; });
  12025. * // => 'barney' (iteration order is not guaranteed)
  12026. *
  12027. * // The `_.matches` iteratee shorthand.
  12028. * _.findKey(users, { 'age': 1, 'active': true });
  12029. * // => 'pebbles'
  12030. *
  12031. * // The `_.matchesProperty` iteratee shorthand.
  12032. * _.findKey(users, ['active', false]);
  12033. * // => 'fred'
  12034. *
  12035. * // The `_.property` iteratee shorthand.
  12036. * _.findKey(users, 'active');
  12037. * // => 'barney'
  12038. */
  12039. function findKey(object, predicate) {
  12040. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12041. }
  12042. /**
  12043. * This method is like `_.findKey` except that it iterates over elements of
  12044. * a collection in the opposite order.
  12045. *
  12046. * @static
  12047. * @memberOf _
  12048. * @since 2.0.0
  12049. * @category Object
  12050. * @param {Object} object The object to inspect.
  12051. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12052. * @returns {string|undefined} Returns the key of the matched element,
  12053. * else `undefined`.
  12054. * @example
  12055. *
  12056. * var users = {
  12057. * 'barney': { 'age': 36, 'active': true },
  12058. * 'fred': { 'age': 40, 'active': false },
  12059. * 'pebbles': { 'age': 1, 'active': true }
  12060. * };
  12061. *
  12062. * _.findLastKey(users, function(o) { return o.age < 40; });
  12063. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12064. *
  12065. * // The `_.matches` iteratee shorthand.
  12066. * _.findLastKey(users, { 'age': 36, 'active': true });
  12067. * // => 'barney'
  12068. *
  12069. * // The `_.matchesProperty` iteratee shorthand.
  12070. * _.findLastKey(users, ['active', false]);
  12071. * // => 'fred'
  12072. *
  12073. * // The `_.property` iteratee shorthand.
  12074. * _.findLastKey(users, 'active');
  12075. * // => 'pebbles'
  12076. */
  12077. function findLastKey(object, predicate) {
  12078. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12079. }
  12080. /**
  12081. * Iterates over own and inherited enumerable string keyed properties of an
  12082. * object and invokes `iteratee` for each property. The iteratee is invoked
  12083. * with three arguments: (value, key, object). Iteratee functions may exit
  12084. * iteration early by explicitly returning `false`.
  12085. *
  12086. * @static
  12087. * @memberOf _
  12088. * @since 0.3.0
  12089. * @category Object
  12090. * @param {Object} object The object to iterate over.
  12091. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12092. * @returns {Object} Returns `object`.
  12093. * @see _.forInRight
  12094. * @example
  12095. *
  12096. * function Foo() {
  12097. * this.a = 1;
  12098. * this.b = 2;
  12099. * }
  12100. *
  12101. * Foo.prototype.c = 3;
  12102. *
  12103. * _.forIn(new Foo, function(value, key) {
  12104. * console.log(key);
  12105. * });
  12106. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12107. */
  12108. function forIn(object, iteratee) {
  12109. return object == null
  12110. ? object
  12111. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12112. }
  12113. /**
  12114. * This method is like `_.forIn` except that it iterates over properties of
  12115. * `object` in the opposite order.
  12116. *
  12117. * @static
  12118. * @memberOf _
  12119. * @since 2.0.0
  12120. * @category Object
  12121. * @param {Object} object The object to iterate over.
  12122. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12123. * @returns {Object} Returns `object`.
  12124. * @see _.forIn
  12125. * @example
  12126. *
  12127. * function Foo() {
  12128. * this.a = 1;
  12129. * this.b = 2;
  12130. * }
  12131. *
  12132. * Foo.prototype.c = 3;
  12133. *
  12134. * _.forInRight(new Foo, function(value, key) {
  12135. * console.log(key);
  12136. * });
  12137. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12138. */
  12139. function forInRight(object, iteratee) {
  12140. return object == null
  12141. ? object
  12142. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12143. }
  12144. /**
  12145. * Iterates over own enumerable string keyed properties of an object and
  12146. * invokes `iteratee` for each property. The iteratee is invoked with three
  12147. * arguments: (value, key, object). Iteratee functions may exit iteration
  12148. * early by explicitly returning `false`.
  12149. *
  12150. * @static
  12151. * @memberOf _
  12152. * @since 0.3.0
  12153. * @category Object
  12154. * @param {Object} object The object to iterate over.
  12155. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12156. * @returns {Object} Returns `object`.
  12157. * @see _.forOwnRight
  12158. * @example
  12159. *
  12160. * function Foo() {
  12161. * this.a = 1;
  12162. * this.b = 2;
  12163. * }
  12164. *
  12165. * Foo.prototype.c = 3;
  12166. *
  12167. * _.forOwn(new Foo, function(value, key) {
  12168. * console.log(key);
  12169. * });
  12170. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12171. */
  12172. function forOwn(object, iteratee) {
  12173. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12174. }
  12175. /**
  12176. * This method is like `_.forOwn` except that it iterates over properties of
  12177. * `object` in the opposite order.
  12178. *
  12179. * @static
  12180. * @memberOf _
  12181. * @since 2.0.0
  12182. * @category Object
  12183. * @param {Object} object The object to iterate over.
  12184. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12185. * @returns {Object} Returns `object`.
  12186. * @see _.forOwn
  12187. * @example
  12188. *
  12189. * function Foo() {
  12190. * this.a = 1;
  12191. * this.b = 2;
  12192. * }
  12193. *
  12194. * Foo.prototype.c = 3;
  12195. *
  12196. * _.forOwnRight(new Foo, function(value, key) {
  12197. * console.log(key);
  12198. * });
  12199. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12200. */
  12201. function forOwnRight(object, iteratee) {
  12202. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12203. }
  12204. /**
  12205. * Creates an array of function property names from own enumerable properties
  12206. * of `object`.
  12207. *
  12208. * @static
  12209. * @since 0.1.0
  12210. * @memberOf _
  12211. * @category Object
  12212. * @param {Object} object The object to inspect.
  12213. * @returns {Array} Returns the function names.
  12214. * @see _.functionsIn
  12215. * @example
  12216. *
  12217. * function Foo() {
  12218. * this.a = _.constant('a');
  12219. * this.b = _.constant('b');
  12220. * }
  12221. *
  12222. * Foo.prototype.c = _.constant('c');
  12223. *
  12224. * _.functions(new Foo);
  12225. * // => ['a', 'b']
  12226. */
  12227. function functions(object) {
  12228. return object == null ? [] : baseFunctions(object, keys(object));
  12229. }
  12230. /**
  12231. * Creates an array of function property names from own and inherited
  12232. * enumerable properties of `object`.
  12233. *
  12234. * @static
  12235. * @memberOf _
  12236. * @since 4.0.0
  12237. * @category Object
  12238. * @param {Object} object The object to inspect.
  12239. * @returns {Array} Returns the function names.
  12240. * @see _.functions
  12241. * @example
  12242. *
  12243. * function Foo() {
  12244. * this.a = _.constant('a');
  12245. * this.b = _.constant('b');
  12246. * }
  12247. *
  12248. * Foo.prototype.c = _.constant('c');
  12249. *
  12250. * _.functionsIn(new Foo);
  12251. * // => ['a', 'b', 'c']
  12252. */
  12253. function functionsIn(object) {
  12254. return object == null ? [] : baseFunctions(object, keysIn(object));
  12255. }
  12256. /**
  12257. * Gets the value at `path` of `object`. If the resolved value is
  12258. * `undefined`, the `defaultValue` is returned in its place.
  12259. *
  12260. * @static
  12261. * @memberOf _
  12262. * @since 3.7.0
  12263. * @category Object
  12264. * @param {Object} object The object to query.
  12265. * @param {Array|string} path The path of the property to get.
  12266. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12267. * @returns {*} Returns the resolved value.
  12268. * @example
  12269. *
  12270. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12271. *
  12272. * _.get(object, 'a[0].b.c');
  12273. * // => 3
  12274. *
  12275. * _.get(object, ['a', '0', 'b', 'c']);
  12276. * // => 3
  12277. *
  12278. * _.get(object, 'a.b.c', 'default');
  12279. * // => 'default'
  12280. */
  12281. function get(object, path, defaultValue) {
  12282. var result = object == null ? undefined : baseGet(object, path);
  12283. return result === undefined ? defaultValue : result;
  12284. }
  12285. /**
  12286. * Checks if `path` is a direct property of `object`.
  12287. *
  12288. * @static
  12289. * @since 0.1.0
  12290. * @memberOf _
  12291. * @category Object
  12292. * @param {Object} object The object to query.
  12293. * @param {Array|string} path The path to check.
  12294. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12295. * @example
  12296. *
  12297. * var object = { 'a': { 'b': 2 } };
  12298. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12299. *
  12300. * _.has(object, 'a');
  12301. * // => true
  12302. *
  12303. * _.has(object, 'a.b');
  12304. * // => true
  12305. *
  12306. * _.has(object, ['a', 'b']);
  12307. * // => true
  12308. *
  12309. * _.has(other, 'a');
  12310. * // => false
  12311. */
  12312. function has(object, path) {
  12313. return object != null && hasPath(object, path, baseHas);
  12314. }
  12315. /**
  12316. * Checks if `path` is a direct or inherited property of `object`.
  12317. *
  12318. * @static
  12319. * @memberOf _
  12320. * @since 4.0.0
  12321. * @category Object
  12322. * @param {Object} object The object to query.
  12323. * @param {Array|string} path The path to check.
  12324. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12325. * @example
  12326. *
  12327. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12328. *
  12329. * _.hasIn(object, 'a');
  12330. * // => true
  12331. *
  12332. * _.hasIn(object, 'a.b');
  12333. * // => true
  12334. *
  12335. * _.hasIn(object, ['a', 'b']);
  12336. * // => true
  12337. *
  12338. * _.hasIn(object, 'b');
  12339. * // => false
  12340. */
  12341. function hasIn(object, path) {
  12342. return object != null && hasPath(object, path, baseHasIn);
  12343. }
  12344. /**
  12345. * Creates an object composed of the inverted keys and values of `object`.
  12346. * If `object` contains duplicate values, subsequent values overwrite
  12347. * property assignments of previous values.
  12348. *
  12349. * @static
  12350. * @memberOf _
  12351. * @since 0.7.0
  12352. * @category Object
  12353. * @param {Object} object The object to invert.
  12354. * @returns {Object} Returns the new inverted object.
  12355. * @example
  12356. *
  12357. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12358. *
  12359. * _.invert(object);
  12360. * // => { '1': 'c', '2': 'b' }
  12361. */
  12362. var invert = createInverter(function(result, value, key) {
  12363. if (value != null &&
  12364. typeof value.toString != 'function') {
  12365. value = nativeObjectToString.call(value);
  12366. }
  12367. result[value] = key;
  12368. }, constant(identity));
  12369. /**
  12370. * This method is like `_.invert` except that the inverted object is generated
  12371. * from the results of running each element of `object` thru `iteratee`. The
  12372. * corresponding inverted value of each inverted key is an array of keys
  12373. * responsible for generating the inverted value. The iteratee is invoked
  12374. * with one argument: (value).
  12375. *
  12376. * @static
  12377. * @memberOf _
  12378. * @since 4.1.0
  12379. * @category Object
  12380. * @param {Object} object The object to invert.
  12381. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12382. * @returns {Object} Returns the new inverted object.
  12383. * @example
  12384. *
  12385. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12386. *
  12387. * _.invertBy(object);
  12388. * // => { '1': ['a', 'c'], '2': ['b'] }
  12389. *
  12390. * _.invertBy(object, function(value) {
  12391. * return 'group' + value;
  12392. * });
  12393. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12394. */
  12395. var invertBy = createInverter(function(result, value, key) {
  12396. if (value != null &&
  12397. typeof value.toString != 'function') {
  12398. value = nativeObjectToString.call(value);
  12399. }
  12400. if (hasOwnProperty.call(result, value)) {
  12401. result[value].push(key);
  12402. } else {
  12403. result[value] = [key];
  12404. }
  12405. }, getIteratee);
  12406. /**
  12407. * Invokes the method at `path` of `object`.
  12408. *
  12409. * @static
  12410. * @memberOf _
  12411. * @since 4.0.0
  12412. * @category Object
  12413. * @param {Object} object The object to query.
  12414. * @param {Array|string} path The path of the method to invoke.
  12415. * @param {...*} [args] The arguments to invoke the method with.
  12416. * @returns {*} Returns the result of the invoked method.
  12417. * @example
  12418. *
  12419. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12420. *
  12421. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12422. * // => [2, 3]
  12423. */
  12424. var invoke = baseRest(baseInvoke);
  12425. /**
  12426. * Creates an array of the own enumerable property names of `object`.
  12427. *
  12428. * **Note:** Non-object values are coerced to objects. See the
  12429. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12430. * for more details.
  12431. *
  12432. * @static
  12433. * @since 0.1.0
  12434. * @memberOf _
  12435. * @category Object
  12436. * @param {Object} object The object to query.
  12437. * @returns {Array} Returns the array of property names.
  12438. * @example
  12439. *
  12440. * function Foo() {
  12441. * this.a = 1;
  12442. * this.b = 2;
  12443. * }
  12444. *
  12445. * Foo.prototype.c = 3;
  12446. *
  12447. * _.keys(new Foo);
  12448. * // => ['a', 'b'] (iteration order is not guaranteed)
  12449. *
  12450. * _.keys('hi');
  12451. * // => ['0', '1']
  12452. */
  12453. function keys(object) {
  12454. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12455. }
  12456. /**
  12457. * Creates an array of the own and inherited enumerable property names of `object`.
  12458. *
  12459. * **Note:** Non-object values are coerced to objects.
  12460. *
  12461. * @static
  12462. * @memberOf _
  12463. * @since 3.0.0
  12464. * @category Object
  12465. * @param {Object} object The object to query.
  12466. * @returns {Array} Returns the array of property names.
  12467. * @example
  12468. *
  12469. * function Foo() {
  12470. * this.a = 1;
  12471. * this.b = 2;
  12472. * }
  12473. *
  12474. * Foo.prototype.c = 3;
  12475. *
  12476. * _.keysIn(new Foo);
  12477. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12478. */
  12479. function keysIn(object) {
  12480. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12481. }
  12482. /**
  12483. * The opposite of `_.mapValues`; this method creates an object with the
  12484. * same values as `object` and keys generated by running each own enumerable
  12485. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12486. * with three arguments: (value, key, object).
  12487. *
  12488. * @static
  12489. * @memberOf _
  12490. * @since 3.8.0
  12491. * @category Object
  12492. * @param {Object} object The object to iterate over.
  12493. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12494. * @returns {Object} Returns the new mapped object.
  12495. * @see _.mapValues
  12496. * @example
  12497. *
  12498. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12499. * return key + value;
  12500. * });
  12501. * // => { 'a1': 1, 'b2': 2 }
  12502. */
  12503. function mapKeys(object, iteratee) {
  12504. var result = {};
  12505. iteratee = getIteratee(iteratee, 3);
  12506. baseForOwn(object, function(value, key, object) {
  12507. baseAssignValue(result, iteratee(value, key, object), value);
  12508. });
  12509. return result;
  12510. }
  12511. /**
  12512. * Creates an object with the same keys as `object` and values generated
  12513. * by running each own enumerable string keyed property of `object` thru
  12514. * `iteratee`. The iteratee is invoked with three arguments:
  12515. * (value, key, object).
  12516. *
  12517. * @static
  12518. * @memberOf _
  12519. * @since 2.4.0
  12520. * @category Object
  12521. * @param {Object} object The object to iterate over.
  12522. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12523. * @returns {Object} Returns the new mapped object.
  12524. * @see _.mapKeys
  12525. * @example
  12526. *
  12527. * var users = {
  12528. * 'fred': { 'user': 'fred', 'age': 40 },
  12529. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12530. * };
  12531. *
  12532. * _.mapValues(users, function(o) { return o.age; });
  12533. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12534. *
  12535. * // The `_.property` iteratee shorthand.
  12536. * _.mapValues(users, 'age');
  12537. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12538. */
  12539. function mapValues(object, iteratee) {
  12540. var result = {};
  12541. iteratee = getIteratee(iteratee, 3);
  12542. baseForOwn(object, function(value, key, object) {
  12543. baseAssignValue(result, key, iteratee(value, key, object));
  12544. });
  12545. return result;
  12546. }
  12547. /**
  12548. * This method is like `_.assign` except that it recursively merges own and
  12549. * inherited enumerable string keyed properties of source objects into the
  12550. * destination object. Source properties that resolve to `undefined` are
  12551. * skipped if a destination value exists. Array and plain object properties
  12552. * are merged recursively. Other objects and value types are overridden by
  12553. * assignment. Source objects are applied from left to right. Subsequent
  12554. * sources overwrite property assignments of previous sources.
  12555. *
  12556. * **Note:** This method mutates `object`.
  12557. *
  12558. * @static
  12559. * @memberOf _
  12560. * @since 0.5.0
  12561. * @category Object
  12562. * @param {Object} object The destination object.
  12563. * @param {...Object} [sources] The source objects.
  12564. * @returns {Object} Returns `object`.
  12565. * @example
  12566. *
  12567. * var object = {
  12568. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12569. * };
  12570. *
  12571. * var other = {
  12572. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12573. * };
  12574. *
  12575. * _.merge(object, other);
  12576. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12577. */
  12578. var merge = createAssigner(function(object, source, srcIndex) {
  12579. baseMerge(object, source, srcIndex);
  12580. });
  12581. /**
  12582. * This method is like `_.merge` except that it accepts `customizer` which
  12583. * is invoked to produce the merged values of the destination and source
  12584. * properties. If `customizer` returns `undefined`, merging is handled by the
  12585. * method instead. The `customizer` is invoked with six arguments:
  12586. * (objValue, srcValue, key, object, source, stack).
  12587. *
  12588. * **Note:** This method mutates `object`.
  12589. *
  12590. * @static
  12591. * @memberOf _
  12592. * @since 4.0.0
  12593. * @category Object
  12594. * @param {Object} object The destination object.
  12595. * @param {...Object} sources The source objects.
  12596. * @param {Function} customizer The function to customize assigned values.
  12597. * @returns {Object} Returns `object`.
  12598. * @example
  12599. *
  12600. * function customizer(objValue, srcValue) {
  12601. * if (_.isArray(objValue)) {
  12602. * return objValue.concat(srcValue);
  12603. * }
  12604. * }
  12605. *
  12606. * var object = { 'a': [1], 'b': [2] };
  12607. * var other = { 'a': [3], 'b': [4] };
  12608. *
  12609. * _.mergeWith(object, other, customizer);
  12610. * // => { 'a': [1, 3], 'b': [2, 4] }
  12611. */
  12612. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12613. baseMerge(object, source, srcIndex, customizer);
  12614. });
  12615. /**
  12616. * The opposite of `_.pick`; this method creates an object composed of the
  12617. * own and inherited enumerable property paths of `object` that are not omitted.
  12618. *
  12619. * **Note:** This method is considerably slower than `_.pick`.
  12620. *
  12621. * @static
  12622. * @since 0.1.0
  12623. * @memberOf _
  12624. * @category Object
  12625. * @param {Object} object The source object.
  12626. * @param {...(string|string[])} [paths] The property paths to omit.
  12627. * @returns {Object} Returns the new object.
  12628. * @example
  12629. *
  12630. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12631. *
  12632. * _.omit(object, ['a', 'c']);
  12633. * // => { 'b': '2' }
  12634. */
  12635. var omit = flatRest(function(object, paths) {
  12636. var result = {};
  12637. if (object == null) {
  12638. return result;
  12639. }
  12640. var isDeep = false;
  12641. paths = arrayMap(paths, function(path) {
  12642. path = castPath(path, object);
  12643. isDeep || (isDeep = path.length > 1);
  12644. return path;
  12645. });
  12646. copyObject(object, getAllKeysIn(object), result);
  12647. if (isDeep) {
  12648. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12649. }
  12650. var length = paths.length;
  12651. while (length--) {
  12652. baseUnset(result, paths[length]);
  12653. }
  12654. return result;
  12655. });
  12656. /**
  12657. * The opposite of `_.pickBy`; this method creates an object composed of
  12658. * the own and inherited enumerable string keyed properties of `object` that
  12659. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12660. * arguments: (value, key).
  12661. *
  12662. * @static
  12663. * @memberOf _
  12664. * @since 4.0.0
  12665. * @category Object
  12666. * @param {Object} object The source object.
  12667. * @param {Function} [predicate=_.identity] The function invoked per property.
  12668. * @returns {Object} Returns the new object.
  12669. * @example
  12670. *
  12671. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12672. *
  12673. * _.omitBy(object, _.isNumber);
  12674. * // => { 'b': '2' }
  12675. */
  12676. function omitBy(object, predicate) {
  12677. return pickBy(object, negate(getIteratee(predicate)));
  12678. }
  12679. /**
  12680. * Creates an object composed of the picked `object` properties.
  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 pick.
  12688. * @returns {Object} Returns the new object.
  12689. * @example
  12690. *
  12691. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12692. *
  12693. * _.pick(object, ['a', 'c']);
  12694. * // => { 'a': 1, 'c': 3 }
  12695. */
  12696. var pick = flatRest(function(object, paths) {
  12697. return object == null ? {} : basePick(object, paths);
  12698. });
  12699. /**
  12700. * Creates an object composed of the `object` properties `predicate` returns
  12701. * truthy for. The predicate is invoked with two arguments: (value, key).
  12702. *
  12703. * @static
  12704. * @memberOf _
  12705. * @since 4.0.0
  12706. * @category Object
  12707. * @param {Object} object The source object.
  12708. * @param {Function} [predicate=_.identity] The function invoked per property.
  12709. * @returns {Object} Returns the new object.
  12710. * @example
  12711. *
  12712. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12713. *
  12714. * _.pickBy(object, _.isNumber);
  12715. * // => { 'a': 1, 'c': 3 }
  12716. */
  12717. function pickBy(object, predicate) {
  12718. if (object == null) {
  12719. return {};
  12720. }
  12721. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12722. return [prop];
  12723. });
  12724. predicate = getIteratee(predicate);
  12725. return basePickBy(object, props, function(value, path) {
  12726. return predicate(value, path[0]);
  12727. });
  12728. }
  12729. /**
  12730. * This method is like `_.get` except that if the resolved value is a
  12731. * function it's invoked with the `this` binding of its parent object and
  12732. * its result is returned.
  12733. *
  12734. * @static
  12735. * @since 0.1.0
  12736. * @memberOf _
  12737. * @category Object
  12738. * @param {Object} object The object to query.
  12739. * @param {Array|string} path The path of the property to resolve.
  12740. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12741. * @returns {*} Returns the resolved value.
  12742. * @example
  12743. *
  12744. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12745. *
  12746. * _.result(object, 'a[0].b.c1');
  12747. * // => 3
  12748. *
  12749. * _.result(object, 'a[0].b.c2');
  12750. * // => 4
  12751. *
  12752. * _.result(object, 'a[0].b.c3', 'default');
  12753. * // => 'default'
  12754. *
  12755. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12756. * // => 'default'
  12757. */
  12758. function result(object, path, defaultValue) {
  12759. path = castPath(path, object);
  12760. var index = -1,
  12761. length = path.length;
  12762. // Ensure the loop is entered when path is empty.
  12763. if (!length) {
  12764. length = 1;
  12765. object = undefined;
  12766. }
  12767. while (++index < length) {
  12768. var value = object == null ? undefined : object[toKey(path[index])];
  12769. if (value === undefined) {
  12770. index = length;
  12771. value = defaultValue;
  12772. }
  12773. object = isFunction(value) ? value.call(object) : value;
  12774. }
  12775. return object;
  12776. }
  12777. /**
  12778. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12779. * it's created. Arrays are created for missing index properties while objects
  12780. * are created for all other missing properties. Use `_.setWith` to customize
  12781. * `path` creation.
  12782. *
  12783. * **Note:** This method mutates `object`.
  12784. *
  12785. * @static
  12786. * @memberOf _
  12787. * @since 3.7.0
  12788. * @category Object
  12789. * @param {Object} object The object to modify.
  12790. * @param {Array|string} path The path of the property to set.
  12791. * @param {*} value The value to set.
  12792. * @returns {Object} Returns `object`.
  12793. * @example
  12794. *
  12795. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12796. *
  12797. * _.set(object, 'a[0].b.c', 4);
  12798. * console.log(object.a[0].b.c);
  12799. * // => 4
  12800. *
  12801. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12802. * console.log(object.x[0].y.z);
  12803. * // => 5
  12804. */
  12805. function set(object, path, value) {
  12806. return object == null ? object : baseSet(object, path, value);
  12807. }
  12808. /**
  12809. * This method is like `_.set` except that it accepts `customizer` which is
  12810. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12811. * path creation is handled by the method instead. The `customizer` is invoked
  12812. * with three arguments: (nsValue, key, nsObject).
  12813. *
  12814. * **Note:** This method mutates `object`.
  12815. *
  12816. * @static
  12817. * @memberOf _
  12818. * @since 4.0.0
  12819. * @category Object
  12820. * @param {Object} object The object to modify.
  12821. * @param {Array|string} path The path of the property to set.
  12822. * @param {*} value The value to set.
  12823. * @param {Function} [customizer] The function to customize assigned values.
  12824. * @returns {Object} Returns `object`.
  12825. * @example
  12826. *
  12827. * var object = {};
  12828. *
  12829. * _.setWith(object, '[0][1]', 'a', Object);
  12830. * // => { '0': { '1': 'a' } }
  12831. */
  12832. function setWith(object, path, value, customizer) {
  12833. customizer = typeof customizer == 'function' ? customizer : undefined;
  12834. return object == null ? object : baseSet(object, path, value, customizer);
  12835. }
  12836. /**
  12837. * Creates an array of own enumerable string keyed-value pairs for `object`
  12838. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12839. * entries are returned.
  12840. *
  12841. * @static
  12842. * @memberOf _
  12843. * @since 4.0.0
  12844. * @alias entries
  12845. * @category Object
  12846. * @param {Object} object The object to query.
  12847. * @returns {Array} Returns the key-value pairs.
  12848. * @example
  12849. *
  12850. * function Foo() {
  12851. * this.a = 1;
  12852. * this.b = 2;
  12853. * }
  12854. *
  12855. * Foo.prototype.c = 3;
  12856. *
  12857. * _.toPairs(new Foo);
  12858. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12859. */
  12860. var toPairs = createToPairs(keys);
  12861. /**
  12862. * Creates an array of own and inherited enumerable string keyed-value pairs
  12863. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12864. * or set, its entries are returned.
  12865. *
  12866. * @static
  12867. * @memberOf _
  12868. * @since 4.0.0
  12869. * @alias entriesIn
  12870. * @category Object
  12871. * @param {Object} object The object to query.
  12872. * @returns {Array} Returns the key-value pairs.
  12873. * @example
  12874. *
  12875. * function Foo() {
  12876. * this.a = 1;
  12877. * this.b = 2;
  12878. * }
  12879. *
  12880. * Foo.prototype.c = 3;
  12881. *
  12882. * _.toPairsIn(new Foo);
  12883. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12884. */
  12885. var toPairsIn = createToPairs(keysIn);
  12886. /**
  12887. * An alternative to `_.reduce`; this method transforms `object` to a new
  12888. * `accumulator` object which is the result of running each of its own
  12889. * enumerable string keyed properties thru `iteratee`, with each invocation
  12890. * potentially mutating the `accumulator` object. If `accumulator` is not
  12891. * provided, a new object with the same `[[Prototype]]` will be used. The
  12892. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12893. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12894. *
  12895. * @static
  12896. * @memberOf _
  12897. * @since 1.3.0
  12898. * @category Object
  12899. * @param {Object} object The object to iterate over.
  12900. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12901. * @param {*} [accumulator] The custom accumulator value.
  12902. * @returns {*} Returns the accumulated value.
  12903. * @example
  12904. *
  12905. * _.transform([2, 3, 4], function(result, n) {
  12906. * result.push(n *= n);
  12907. * return n % 2 == 0;
  12908. * }, []);
  12909. * // => [4, 9]
  12910. *
  12911. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12912. * (result[value] || (result[value] = [])).push(key);
  12913. * }, {});
  12914. * // => { '1': ['a', 'c'], '2': ['b'] }
  12915. */
  12916. function transform(object, iteratee, accumulator) {
  12917. var isArr = isArray(object),
  12918. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12919. iteratee = getIteratee(iteratee, 4);
  12920. if (accumulator == null) {
  12921. var Ctor = object && object.constructor;
  12922. if (isArrLike) {
  12923. accumulator = isArr ? new Ctor : [];
  12924. }
  12925. else if (isObject(object)) {
  12926. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12927. }
  12928. else {
  12929. accumulator = {};
  12930. }
  12931. }
  12932. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12933. return iteratee(accumulator, value, index, object);
  12934. });
  12935. return accumulator;
  12936. }
  12937. /**
  12938. * Removes the property at `path` of `object`.
  12939. *
  12940. * **Note:** This method mutates `object`.
  12941. *
  12942. * @static
  12943. * @memberOf _
  12944. * @since 4.0.0
  12945. * @category Object
  12946. * @param {Object} object The object to modify.
  12947. * @param {Array|string} path The path of the property to unset.
  12948. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12949. * @example
  12950. *
  12951. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12952. * _.unset(object, 'a[0].b.c');
  12953. * // => true
  12954. *
  12955. * console.log(object);
  12956. * // => { 'a': [{ 'b': {} }] };
  12957. *
  12958. * _.unset(object, ['a', '0', 'b', 'c']);
  12959. * // => true
  12960. *
  12961. * console.log(object);
  12962. * // => { 'a': [{ 'b': {} }] };
  12963. */
  12964. function unset(object, path) {
  12965. return object == null ? true : baseUnset(object, path);
  12966. }
  12967. /**
  12968. * This method is like `_.set` except that accepts `updater` to produce the
  12969. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12970. * is invoked with one argument: (value).
  12971. *
  12972. * **Note:** This method mutates `object`.
  12973. *
  12974. * @static
  12975. * @memberOf _
  12976. * @since 4.6.0
  12977. * @category Object
  12978. * @param {Object} object The object to modify.
  12979. * @param {Array|string} path The path of the property to set.
  12980. * @param {Function} updater The function to produce the updated value.
  12981. * @returns {Object} Returns `object`.
  12982. * @example
  12983. *
  12984. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12985. *
  12986. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12987. * console.log(object.a[0].b.c);
  12988. * // => 9
  12989. *
  12990. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12991. * console.log(object.x[0].y.z);
  12992. * // => 0
  12993. */
  12994. function update(object, path, updater) {
  12995. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12996. }
  12997. /**
  12998. * This method is like `_.update` except that it accepts `customizer` which is
  12999. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13000. * path creation is handled by the method instead. The `customizer` is invoked
  13001. * with three arguments: (nsValue, key, nsObject).
  13002. *
  13003. * **Note:** This method mutates `object`.
  13004. *
  13005. * @static
  13006. * @memberOf _
  13007. * @since 4.6.0
  13008. * @category Object
  13009. * @param {Object} object The object to modify.
  13010. * @param {Array|string} path The path of the property to set.
  13011. * @param {Function} updater The function to produce the updated value.
  13012. * @param {Function} [customizer] The function to customize assigned values.
  13013. * @returns {Object} Returns `object`.
  13014. * @example
  13015. *
  13016. * var object = {};
  13017. *
  13018. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13019. * // => { '0': { '1': 'a' } }
  13020. */
  13021. function updateWith(object, path, updater, customizer) {
  13022. customizer = typeof customizer == 'function' ? customizer : undefined;
  13023. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13024. }
  13025. /**
  13026. * Creates an array of the own enumerable string keyed property values of `object`.
  13027. *
  13028. * **Note:** Non-object values are coerced to objects.
  13029. *
  13030. * @static
  13031. * @since 0.1.0
  13032. * @memberOf _
  13033. * @category Object
  13034. * @param {Object} object The object to query.
  13035. * @returns {Array} Returns the array of property values.
  13036. * @example
  13037. *
  13038. * function Foo() {
  13039. * this.a = 1;
  13040. * this.b = 2;
  13041. * }
  13042. *
  13043. * Foo.prototype.c = 3;
  13044. *
  13045. * _.values(new Foo);
  13046. * // => [1, 2] (iteration order is not guaranteed)
  13047. *
  13048. * _.values('hi');
  13049. * // => ['h', 'i']
  13050. */
  13051. function values(object) {
  13052. return object == null ? [] : baseValues(object, keys(object));
  13053. }
  13054. /**
  13055. * Creates an array of the own and inherited enumerable string keyed property
  13056. * values of `object`.
  13057. *
  13058. * **Note:** Non-object values are coerced to objects.
  13059. *
  13060. * @static
  13061. * @memberOf _
  13062. * @since 3.0.0
  13063. * @category Object
  13064. * @param {Object} object The object to query.
  13065. * @returns {Array} Returns the array of property values.
  13066. * @example
  13067. *
  13068. * function Foo() {
  13069. * this.a = 1;
  13070. * this.b = 2;
  13071. * }
  13072. *
  13073. * Foo.prototype.c = 3;
  13074. *
  13075. * _.valuesIn(new Foo);
  13076. * // => [1, 2, 3] (iteration order is not guaranteed)
  13077. */
  13078. function valuesIn(object) {
  13079. return object == null ? [] : baseValues(object, keysIn(object));
  13080. }
  13081. /*------------------------------------------------------------------------*/
  13082. /**
  13083. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13084. *
  13085. * @static
  13086. * @memberOf _
  13087. * @since 4.0.0
  13088. * @category Number
  13089. * @param {number} number The number to clamp.
  13090. * @param {number} [lower] The lower bound.
  13091. * @param {number} upper The upper bound.
  13092. * @returns {number} Returns the clamped number.
  13093. * @example
  13094. *
  13095. * _.clamp(-10, -5, 5);
  13096. * // => -5
  13097. *
  13098. * _.clamp(10, -5, 5);
  13099. * // => 5
  13100. */
  13101. function clamp(number, lower, upper) {
  13102. if (upper === undefined) {
  13103. upper = lower;
  13104. lower = undefined;
  13105. }
  13106. if (upper !== undefined) {
  13107. upper = toNumber(upper);
  13108. upper = upper === upper ? upper : 0;
  13109. }
  13110. if (lower !== undefined) {
  13111. lower = toNumber(lower);
  13112. lower = lower === lower ? lower : 0;
  13113. }
  13114. return baseClamp(toNumber(number), lower, upper);
  13115. }
  13116. /**
  13117. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13118. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13119. * If `start` is greater than `end` the params are swapped to support
  13120. * negative ranges.
  13121. *
  13122. * @static
  13123. * @memberOf _
  13124. * @since 3.3.0
  13125. * @category Number
  13126. * @param {number} number The number to check.
  13127. * @param {number} [start=0] The start of the range.
  13128. * @param {number} end The end of the range.
  13129. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13130. * @see _.range, _.rangeRight
  13131. * @example
  13132. *
  13133. * _.inRange(3, 2, 4);
  13134. * // => true
  13135. *
  13136. * _.inRange(4, 8);
  13137. * // => true
  13138. *
  13139. * _.inRange(4, 2);
  13140. * // => false
  13141. *
  13142. * _.inRange(2, 2);
  13143. * // => false
  13144. *
  13145. * _.inRange(1.2, 2);
  13146. * // => true
  13147. *
  13148. * _.inRange(5.2, 4);
  13149. * // => false
  13150. *
  13151. * _.inRange(-3, -2, -6);
  13152. * // => true
  13153. */
  13154. function inRange(number, start, end) {
  13155. start = toFinite(start);
  13156. if (end === undefined) {
  13157. end = start;
  13158. start = 0;
  13159. } else {
  13160. end = toFinite(end);
  13161. }
  13162. number = toNumber(number);
  13163. return baseInRange(number, start, end);
  13164. }
  13165. /**
  13166. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13167. * If only one argument is provided a number between `0` and the given number
  13168. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13169. * floats, a floating-point number is returned instead of an integer.
  13170. *
  13171. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13172. * floating-point values which can produce unexpected results.
  13173. *
  13174. * @static
  13175. * @memberOf _
  13176. * @since 0.7.0
  13177. * @category Number
  13178. * @param {number} [lower=0] The lower bound.
  13179. * @param {number} [upper=1] The upper bound.
  13180. * @param {boolean} [floating] Specify returning a floating-point number.
  13181. * @returns {number} Returns the random number.
  13182. * @example
  13183. *
  13184. * _.random(0, 5);
  13185. * // => an integer between 0 and 5
  13186. *
  13187. * _.random(5);
  13188. * // => also an integer between 0 and 5
  13189. *
  13190. * _.random(5, true);
  13191. * // => a floating-point number between 0 and 5
  13192. *
  13193. * _.random(1.2, 5.2);
  13194. * // => a floating-point number between 1.2 and 5.2
  13195. */
  13196. function random(lower, upper, floating) {
  13197. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13198. upper = floating = undefined;
  13199. }
  13200. if (floating === undefined) {
  13201. if (typeof upper == 'boolean') {
  13202. floating = upper;
  13203. upper = undefined;
  13204. }
  13205. else if (typeof lower == 'boolean') {
  13206. floating = lower;
  13207. lower = undefined;
  13208. }
  13209. }
  13210. if (lower === undefined && upper === undefined) {
  13211. lower = 0;
  13212. upper = 1;
  13213. }
  13214. else {
  13215. lower = toFinite(lower);
  13216. if (upper === undefined) {
  13217. upper = lower;
  13218. lower = 0;
  13219. } else {
  13220. upper = toFinite(upper);
  13221. }
  13222. }
  13223. if (lower > upper) {
  13224. var temp = lower;
  13225. lower = upper;
  13226. upper = temp;
  13227. }
  13228. if (floating || lower % 1 || upper % 1) {
  13229. var rand = nativeRandom();
  13230. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13231. }
  13232. return baseRandom(lower, upper);
  13233. }
  13234. /*------------------------------------------------------------------------*/
  13235. /**
  13236. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13237. *
  13238. * @static
  13239. * @memberOf _
  13240. * @since 3.0.0
  13241. * @category String
  13242. * @param {string} [string=''] The string to convert.
  13243. * @returns {string} Returns the camel cased string.
  13244. * @example
  13245. *
  13246. * _.camelCase('Foo Bar');
  13247. * // => 'fooBar'
  13248. *
  13249. * _.camelCase('--foo-bar--');
  13250. * // => 'fooBar'
  13251. *
  13252. * _.camelCase('__FOO_BAR__');
  13253. * // => 'fooBar'
  13254. */
  13255. var camelCase = createCompounder(function(result, word, index) {
  13256. word = word.toLowerCase();
  13257. return result + (index ? capitalize(word) : word);
  13258. });
  13259. /**
  13260. * Converts the first character of `string` to upper case and the remaining
  13261. * to lower case.
  13262. *
  13263. * @static
  13264. * @memberOf _
  13265. * @since 3.0.0
  13266. * @category String
  13267. * @param {string} [string=''] The string to capitalize.
  13268. * @returns {string} Returns the capitalized string.
  13269. * @example
  13270. *
  13271. * _.capitalize('FRED');
  13272. * // => 'Fred'
  13273. */
  13274. function capitalize(string) {
  13275. return upperFirst(toString(string).toLowerCase());
  13276. }
  13277. /**
  13278. * Deburrs `string` by converting
  13279. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13280. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13281. * letters to basic Latin letters and removing
  13282. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13283. *
  13284. * @static
  13285. * @memberOf _
  13286. * @since 3.0.0
  13287. * @category String
  13288. * @param {string} [string=''] The string to deburr.
  13289. * @returns {string} Returns the deburred string.
  13290. * @example
  13291. *
  13292. * _.deburr('déjà vu');
  13293. * // => 'deja vu'
  13294. */
  13295. function deburr(string) {
  13296. string = toString(string);
  13297. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13298. }
  13299. /**
  13300. * Checks if `string` ends with the given target string.
  13301. *
  13302. * @static
  13303. * @memberOf _
  13304. * @since 3.0.0
  13305. * @category String
  13306. * @param {string} [string=''] The string to inspect.
  13307. * @param {string} [target] The string to search for.
  13308. * @param {number} [position=string.length] The position to search up to.
  13309. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13310. * else `false`.
  13311. * @example
  13312. *
  13313. * _.endsWith('abc', 'c');
  13314. * // => true
  13315. *
  13316. * _.endsWith('abc', 'b');
  13317. * // => false
  13318. *
  13319. * _.endsWith('abc', 'b', 2);
  13320. * // => true
  13321. */
  13322. function endsWith(string, target, position) {
  13323. string = toString(string);
  13324. target = baseToString(target);
  13325. var length = string.length;
  13326. position = position === undefined
  13327. ? length
  13328. : baseClamp(toInteger(position), 0, length);
  13329. var end = position;
  13330. position -= target.length;
  13331. return position >= 0 && string.slice(position, end) == target;
  13332. }
  13333. /**
  13334. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13335. * corresponding HTML entities.
  13336. *
  13337. * **Note:** No other characters are escaped. To escape additional
  13338. * characters use a third-party library like [_he_](https://mths.be/he).
  13339. *
  13340. * Though the ">" character is escaped for symmetry, characters like
  13341. * ">" and "/" don't need escaping in HTML and have no special meaning
  13342. * unless they're part of a tag or unquoted attribute value. See
  13343. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13344. * (under "semi-related fun fact") for more details.
  13345. *
  13346. * When working with HTML you should always
  13347. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13348. * XSS vectors.
  13349. *
  13350. * @static
  13351. * @since 0.1.0
  13352. * @memberOf _
  13353. * @category String
  13354. * @param {string} [string=''] The string to escape.
  13355. * @returns {string} Returns the escaped string.
  13356. * @example
  13357. *
  13358. * _.escape('fred, barney, & pebbles');
  13359. * // => 'fred, barney, &amp; pebbles'
  13360. */
  13361. function escape(string) {
  13362. string = toString(string);
  13363. return (string && reHasUnescapedHtml.test(string))
  13364. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13365. : string;
  13366. }
  13367. /**
  13368. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13369. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13370. *
  13371. * @static
  13372. * @memberOf _
  13373. * @since 3.0.0
  13374. * @category String
  13375. * @param {string} [string=''] The string to escape.
  13376. * @returns {string} Returns the escaped string.
  13377. * @example
  13378. *
  13379. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13380. * // => '\[lodash\]\(https://lodash\.com/\)'
  13381. */
  13382. function escapeRegExp(string) {
  13383. string = toString(string);
  13384. return (string && reHasRegExpChar.test(string))
  13385. ? string.replace(reRegExpChar, '\\$&')
  13386. : string;
  13387. }
  13388. /**
  13389. * Converts `string` to
  13390. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13391. *
  13392. * @static
  13393. * @memberOf _
  13394. * @since 3.0.0
  13395. * @category String
  13396. * @param {string} [string=''] The string to convert.
  13397. * @returns {string} Returns the kebab cased string.
  13398. * @example
  13399. *
  13400. * _.kebabCase('Foo Bar');
  13401. * // => 'foo-bar'
  13402. *
  13403. * _.kebabCase('fooBar');
  13404. * // => 'foo-bar'
  13405. *
  13406. * _.kebabCase('__FOO_BAR__');
  13407. * // => 'foo-bar'
  13408. */
  13409. var kebabCase = createCompounder(function(result, word, index) {
  13410. return result + (index ? '-' : '') + word.toLowerCase();
  13411. });
  13412. /**
  13413. * Converts `string`, as space separated words, to lower case.
  13414. *
  13415. * @static
  13416. * @memberOf _
  13417. * @since 4.0.0
  13418. * @category String
  13419. * @param {string} [string=''] The string to convert.
  13420. * @returns {string} Returns the lower cased string.
  13421. * @example
  13422. *
  13423. * _.lowerCase('--Foo-Bar--');
  13424. * // => 'foo bar'
  13425. *
  13426. * _.lowerCase('fooBar');
  13427. * // => 'foo bar'
  13428. *
  13429. * _.lowerCase('__FOO_BAR__');
  13430. * // => 'foo bar'
  13431. */
  13432. var lowerCase = createCompounder(function(result, word, index) {
  13433. return result + (index ? ' ' : '') + word.toLowerCase();
  13434. });
  13435. /**
  13436. * Converts the first character of `string` to lower case.
  13437. *
  13438. * @static
  13439. * @memberOf _
  13440. * @since 4.0.0
  13441. * @category String
  13442. * @param {string} [string=''] The string to convert.
  13443. * @returns {string} Returns the converted string.
  13444. * @example
  13445. *
  13446. * _.lowerFirst('Fred');
  13447. * // => 'fred'
  13448. *
  13449. * _.lowerFirst('FRED');
  13450. * // => 'fRED'
  13451. */
  13452. var lowerFirst = createCaseFirst('toLowerCase');
  13453. /**
  13454. * Pads `string` on the left and right sides if it's shorter than `length`.
  13455. * Padding characters are truncated if they can't be evenly divided by `length`.
  13456. *
  13457. * @static
  13458. * @memberOf _
  13459. * @since 3.0.0
  13460. * @category String
  13461. * @param {string} [string=''] The string to pad.
  13462. * @param {number} [length=0] The padding length.
  13463. * @param {string} [chars=' '] The string used as padding.
  13464. * @returns {string} Returns the padded string.
  13465. * @example
  13466. *
  13467. * _.pad('abc', 8);
  13468. * // => ' abc '
  13469. *
  13470. * _.pad('abc', 8, '_-');
  13471. * // => '_-abc_-_'
  13472. *
  13473. * _.pad('abc', 3);
  13474. * // => 'abc'
  13475. */
  13476. function pad(string, length, chars) {
  13477. string = toString(string);
  13478. length = toInteger(length);
  13479. var strLength = length ? stringSize(string) : 0;
  13480. if (!length || strLength >= length) {
  13481. return string;
  13482. }
  13483. var mid = (length - strLength) / 2;
  13484. return (
  13485. createPadding(nativeFloor(mid), chars) +
  13486. string +
  13487. createPadding(nativeCeil(mid), chars)
  13488. );
  13489. }
  13490. /**
  13491. * Pads `string` on the right side if it's shorter than `length`. Padding
  13492. * characters are truncated if they exceed `length`.
  13493. *
  13494. * @static
  13495. * @memberOf _
  13496. * @since 4.0.0
  13497. * @category String
  13498. * @param {string} [string=''] The string to pad.
  13499. * @param {number} [length=0] The padding length.
  13500. * @param {string} [chars=' '] The string used as padding.
  13501. * @returns {string} Returns the padded string.
  13502. * @example
  13503. *
  13504. * _.padEnd('abc', 6);
  13505. * // => 'abc '
  13506. *
  13507. * _.padEnd('abc', 6, '_-');
  13508. * // => 'abc_-_'
  13509. *
  13510. * _.padEnd('abc', 3);
  13511. * // => 'abc'
  13512. */
  13513. function padEnd(string, length, chars) {
  13514. string = toString(string);
  13515. length = toInteger(length);
  13516. var strLength = length ? stringSize(string) : 0;
  13517. return (length && strLength < length)
  13518. ? (string + createPadding(length - strLength, chars))
  13519. : string;
  13520. }
  13521. /**
  13522. * Pads `string` on the left side if it's shorter than `length`. Padding
  13523. * characters are truncated if they exceed `length`.
  13524. *
  13525. * @static
  13526. * @memberOf _
  13527. * @since 4.0.0
  13528. * @category String
  13529. * @param {string} [string=''] The string to pad.
  13530. * @param {number} [length=0] The padding length.
  13531. * @param {string} [chars=' '] The string used as padding.
  13532. * @returns {string} Returns the padded string.
  13533. * @example
  13534. *
  13535. * _.padStart('abc', 6);
  13536. * // => ' abc'
  13537. *
  13538. * _.padStart('abc', 6, '_-');
  13539. * // => '_-_abc'
  13540. *
  13541. * _.padStart('abc', 3);
  13542. * // => 'abc'
  13543. */
  13544. function padStart(string, length, chars) {
  13545. string = toString(string);
  13546. length = toInteger(length);
  13547. var strLength = length ? stringSize(string) : 0;
  13548. return (length && strLength < length)
  13549. ? (createPadding(length - strLength, chars) + string)
  13550. : string;
  13551. }
  13552. /**
  13553. * Converts `string` to an integer of the specified radix. If `radix` is
  13554. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13555. * hexadecimal, in which case a `radix` of `16` is used.
  13556. *
  13557. * **Note:** This method aligns with the
  13558. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13559. *
  13560. * @static
  13561. * @memberOf _
  13562. * @since 1.1.0
  13563. * @category String
  13564. * @param {string} string The string to convert.
  13565. * @param {number} [radix=10] The radix to interpret `value` by.
  13566. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13567. * @returns {number} Returns the converted integer.
  13568. * @example
  13569. *
  13570. * _.parseInt('08');
  13571. * // => 8
  13572. *
  13573. * _.map(['6', '08', '10'], _.parseInt);
  13574. * // => [6, 8, 10]
  13575. */
  13576. function parseInt(string, radix, guard) {
  13577. if (guard || radix == null) {
  13578. radix = 0;
  13579. } else if (radix) {
  13580. radix = +radix;
  13581. }
  13582. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13583. }
  13584. /**
  13585. * Repeats the given string `n` times.
  13586. *
  13587. * @static
  13588. * @memberOf _
  13589. * @since 3.0.0
  13590. * @category String
  13591. * @param {string} [string=''] The string to repeat.
  13592. * @param {number} [n=1] The number of times to repeat the string.
  13593. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13594. * @returns {string} Returns the repeated string.
  13595. * @example
  13596. *
  13597. * _.repeat('*', 3);
  13598. * // => '***'
  13599. *
  13600. * _.repeat('abc', 2);
  13601. * // => 'abcabc'
  13602. *
  13603. * _.repeat('abc', 0);
  13604. * // => ''
  13605. */
  13606. function repeat(string, n, guard) {
  13607. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13608. n = 1;
  13609. } else {
  13610. n = toInteger(n);
  13611. }
  13612. return baseRepeat(toString(string), n);
  13613. }
  13614. /**
  13615. * Replaces matches for `pattern` in `string` with `replacement`.
  13616. *
  13617. * **Note:** This method is based on
  13618. * [`String#replace`](https://mdn.io/String/replace).
  13619. *
  13620. * @static
  13621. * @memberOf _
  13622. * @since 4.0.0
  13623. * @category String
  13624. * @param {string} [string=''] The string to modify.
  13625. * @param {RegExp|string} pattern The pattern to replace.
  13626. * @param {Function|string} replacement The match replacement.
  13627. * @returns {string} Returns the modified string.
  13628. * @example
  13629. *
  13630. * _.replace('Hi Fred', 'Fred', 'Barney');
  13631. * // => 'Hi Barney'
  13632. */
  13633. function replace() {
  13634. var args = arguments,
  13635. string = toString(args[0]);
  13636. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13637. }
  13638. /**
  13639. * Converts `string` to
  13640. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13641. *
  13642. * @static
  13643. * @memberOf _
  13644. * @since 3.0.0
  13645. * @category String
  13646. * @param {string} [string=''] The string to convert.
  13647. * @returns {string} Returns the snake cased string.
  13648. * @example
  13649. *
  13650. * _.snakeCase('Foo Bar');
  13651. * // => 'foo_bar'
  13652. *
  13653. * _.snakeCase('fooBar');
  13654. * // => 'foo_bar'
  13655. *
  13656. * _.snakeCase('--FOO-BAR--');
  13657. * // => 'foo_bar'
  13658. */
  13659. var snakeCase = createCompounder(function(result, word, index) {
  13660. return result + (index ? '_' : '') + word.toLowerCase();
  13661. });
  13662. /**
  13663. * Splits `string` by `separator`.
  13664. *
  13665. * **Note:** This method is based on
  13666. * [`String#split`](https://mdn.io/String/split).
  13667. *
  13668. * @static
  13669. * @memberOf _
  13670. * @since 4.0.0
  13671. * @category String
  13672. * @param {string} [string=''] The string to split.
  13673. * @param {RegExp|string} separator The separator pattern to split by.
  13674. * @param {number} [limit] The length to truncate results to.
  13675. * @returns {Array} Returns the string segments.
  13676. * @example
  13677. *
  13678. * _.split('a-b-c', '-', 2);
  13679. * // => ['a', 'b']
  13680. */
  13681. function split(string, separator, limit) {
  13682. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13683. separator = limit = undefined;
  13684. }
  13685. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13686. if (!limit) {
  13687. return [];
  13688. }
  13689. string = toString(string);
  13690. if (string && (
  13691. typeof separator == 'string' ||
  13692. (separator != null && !isRegExp(separator))
  13693. )) {
  13694. separator = baseToString(separator);
  13695. if (!separator && hasUnicode(string)) {
  13696. return castSlice(stringToArray(string), 0, limit);
  13697. }
  13698. }
  13699. return string.split(separator, limit);
  13700. }
  13701. /**
  13702. * Converts `string` to
  13703. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13704. *
  13705. * @static
  13706. * @memberOf _
  13707. * @since 3.1.0
  13708. * @category String
  13709. * @param {string} [string=''] The string to convert.
  13710. * @returns {string} Returns the start cased string.
  13711. * @example
  13712. *
  13713. * _.startCase('--foo-bar--');
  13714. * // => 'Foo Bar'
  13715. *
  13716. * _.startCase('fooBar');
  13717. * // => 'Foo Bar'
  13718. *
  13719. * _.startCase('__FOO_BAR__');
  13720. * // => 'FOO BAR'
  13721. */
  13722. var startCase = createCompounder(function(result, word, index) {
  13723. return result + (index ? ' ' : '') + upperFirst(word);
  13724. });
  13725. /**
  13726. * Checks if `string` starts with the given target string.
  13727. *
  13728. * @static
  13729. * @memberOf _
  13730. * @since 3.0.0
  13731. * @category String
  13732. * @param {string} [string=''] The string to inspect.
  13733. * @param {string} [target] The string to search for.
  13734. * @param {number} [position=0] The position to search from.
  13735. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13736. * else `false`.
  13737. * @example
  13738. *
  13739. * _.startsWith('abc', 'a');
  13740. * // => true
  13741. *
  13742. * _.startsWith('abc', 'b');
  13743. * // => false
  13744. *
  13745. * _.startsWith('abc', 'b', 1);
  13746. * // => true
  13747. */
  13748. function startsWith(string, target, position) {
  13749. string = toString(string);
  13750. position = position == null
  13751. ? 0
  13752. : baseClamp(toInteger(position), 0, string.length);
  13753. target = baseToString(target);
  13754. return string.slice(position, position + target.length) == target;
  13755. }
  13756. /**
  13757. * Creates a compiled template function that can interpolate data properties
  13758. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13759. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13760. * properties may be accessed as free variables in the template. If a setting
  13761. * object is given, it takes precedence over `_.templateSettings` values.
  13762. *
  13763. * **Note:** In the development build `_.template` utilizes
  13764. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13765. * for easier debugging.
  13766. *
  13767. * For more information on precompiling templates see
  13768. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13769. *
  13770. * For more information on Chrome extension sandboxes see
  13771. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13772. *
  13773. * @static
  13774. * @since 0.1.0
  13775. * @memberOf _
  13776. * @category String
  13777. * @param {string} [string=''] The template string.
  13778. * @param {Object} [options={}] The options object.
  13779. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13780. * The HTML "escape" delimiter.
  13781. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13782. * The "evaluate" delimiter.
  13783. * @param {Object} [options.imports=_.templateSettings.imports]
  13784. * An object to import into the template as free variables.
  13785. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13786. * The "interpolate" delimiter.
  13787. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13788. * The sourceURL of the compiled template.
  13789. * @param {string} [options.variable='obj']
  13790. * The data object variable name.
  13791. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13792. * @returns {Function} Returns the compiled template function.
  13793. * @example
  13794. *
  13795. * // Use the "interpolate" delimiter to create a compiled template.
  13796. * var compiled = _.template('hello <%= user %>!');
  13797. * compiled({ 'user': 'fred' });
  13798. * // => 'hello fred!'
  13799. *
  13800. * // Use the HTML "escape" delimiter to escape data property values.
  13801. * var compiled = _.template('<b><%- value %></b>');
  13802. * compiled({ 'value': '<script>' });
  13803. * // => '<b>&lt;script&gt;</b>'
  13804. *
  13805. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13806. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13807. * compiled({ 'users': ['fred', 'barney'] });
  13808. * // => '<li>fred</li><li>barney</li>'
  13809. *
  13810. * // Use the internal `print` function in "evaluate" delimiters.
  13811. * var compiled = _.template('<% print("hello " + user); %>!');
  13812. * compiled({ 'user': 'barney' });
  13813. * // => 'hello barney!'
  13814. *
  13815. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13816. * // Disable support by replacing the "interpolate" delimiter.
  13817. * var compiled = _.template('hello ${ user }!');
  13818. * compiled({ 'user': 'pebbles' });
  13819. * // => 'hello pebbles!'
  13820. *
  13821. * // Use backslashes to treat delimiters as plain text.
  13822. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13823. * compiled({ 'value': 'ignored' });
  13824. * // => '<%- value %>'
  13825. *
  13826. * // Use the `imports` option to import `jQuery` as `jq`.
  13827. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13828. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13829. * compiled({ 'users': ['fred', 'barney'] });
  13830. * // => '<li>fred</li><li>barney</li>'
  13831. *
  13832. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13833. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13834. * compiled(data);
  13835. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13836. *
  13837. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13838. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13839. * compiled.source;
  13840. * // => function(data) {
  13841. * // var __t, __p = '';
  13842. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13843. * // return __p;
  13844. * // }
  13845. *
  13846. * // Use custom template delimiters.
  13847. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13848. * var compiled = _.template('hello {{ user }}!');
  13849. * compiled({ 'user': 'mustache' });
  13850. * // => 'hello mustache!'
  13851. *
  13852. * // Use the `source` property to inline compiled templates for meaningful
  13853. * // line numbers in error messages and stack traces.
  13854. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13855. * var JST = {\
  13856. * "main": ' + _.template(mainText).source + '\
  13857. * };\
  13858. * ');
  13859. */
  13860. function template(string, options, guard) {
  13861. // Based on John Resig's `tmpl` implementation
  13862. // (http://ejohn.org/blog/javascript-micro-templating/)
  13863. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13864. var settings = lodash.templateSettings;
  13865. if (guard && isIterateeCall(string, options, guard)) {
  13866. options = undefined;
  13867. }
  13868. string = toString(string);
  13869. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13870. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13871. importsKeys = keys(imports),
  13872. importsValues = baseValues(imports, importsKeys);
  13873. var isEscaping,
  13874. isEvaluating,
  13875. index = 0,
  13876. interpolate = options.interpolate || reNoMatch,
  13877. source = "__p += '";
  13878. // Compile the regexp to match each delimiter.
  13879. var reDelimiters = RegExp(
  13880. (options.escape || reNoMatch).source + '|' +
  13881. interpolate.source + '|' +
  13882. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13883. (options.evaluate || reNoMatch).source + '|$'
  13884. , 'g');
  13885. // Use a sourceURL for easier debugging.
  13886. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13887. // with lookup (in case of e.g. prototype pollution), and strip newlines if any.
  13888. // A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection.
  13889. var sourceURL = '//# sourceURL=' +
  13890. (hasOwnProperty.call(options, 'sourceURL')
  13891. ? (options.sourceURL + '').replace(/[\r\n]/g, ' ')
  13892. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13893. ) + '\n';
  13894. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13895. interpolateValue || (interpolateValue = esTemplateValue);
  13896. // Escape characters that can't be included in string literals.
  13897. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13898. // Replace delimiters with snippets.
  13899. if (escapeValue) {
  13900. isEscaping = true;
  13901. source += "' +\n__e(" + escapeValue + ") +\n'";
  13902. }
  13903. if (evaluateValue) {
  13904. isEvaluating = true;
  13905. source += "';\n" + evaluateValue + ";\n__p += '";
  13906. }
  13907. if (interpolateValue) {
  13908. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13909. }
  13910. index = offset + match.length;
  13911. // The JS engine embedded in Adobe products needs `match` returned in
  13912. // order to produce the correct `offset` value.
  13913. return match;
  13914. });
  13915. source += "';\n";
  13916. // If `variable` is not specified wrap a with-statement around the generated
  13917. // code to add the data object to the top of the scope chain.
  13918. // Like with sourceURL, we take care to not check the option's prototype,
  13919. // as this configuration is a code injection vector.
  13920. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13921. if (!variable) {
  13922. source = 'with (obj) {\n' + source + '\n}\n';
  13923. }
  13924. // Cleanup code by stripping empty strings.
  13925. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13926. .replace(reEmptyStringMiddle, '$1')
  13927. .replace(reEmptyStringTrailing, '$1;');
  13928. // Frame code as the function body.
  13929. source = 'function(' + (variable || 'obj') + ') {\n' +
  13930. (variable
  13931. ? ''
  13932. : 'obj || (obj = {});\n'
  13933. ) +
  13934. "var __t, __p = ''" +
  13935. (isEscaping
  13936. ? ', __e = _.escape'
  13937. : ''
  13938. ) +
  13939. (isEvaluating
  13940. ? ', __j = Array.prototype.join;\n' +
  13941. "function print() { __p += __j.call(arguments, '') }\n"
  13942. : ';\n'
  13943. ) +
  13944. source +
  13945. 'return __p\n}';
  13946. var result = attempt(function() {
  13947. return Function(importsKeys, sourceURL + 'return ' + source)
  13948. .apply(undefined, importsValues);
  13949. });
  13950. // Provide the compiled function's source by its `toString` method or
  13951. // the `source` property as a convenience for inlining compiled templates.
  13952. result.source = source;
  13953. if (isError(result)) {
  13954. throw result;
  13955. }
  13956. return result;
  13957. }
  13958. /**
  13959. * Converts `string`, as a whole, to lower case just like
  13960. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13961. *
  13962. * @static
  13963. * @memberOf _
  13964. * @since 4.0.0
  13965. * @category String
  13966. * @param {string} [string=''] The string to convert.
  13967. * @returns {string} Returns the lower cased string.
  13968. * @example
  13969. *
  13970. * _.toLower('--Foo-Bar--');
  13971. * // => '--foo-bar--'
  13972. *
  13973. * _.toLower('fooBar');
  13974. * // => 'foobar'
  13975. *
  13976. * _.toLower('__FOO_BAR__');
  13977. * // => '__foo_bar__'
  13978. */
  13979. function toLower(value) {
  13980. return toString(value).toLowerCase();
  13981. }
  13982. /**
  13983. * Converts `string`, as a whole, to upper case just like
  13984. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13985. *
  13986. * @static
  13987. * @memberOf _
  13988. * @since 4.0.0
  13989. * @category String
  13990. * @param {string} [string=''] The string to convert.
  13991. * @returns {string} Returns the upper cased string.
  13992. * @example
  13993. *
  13994. * _.toUpper('--foo-bar--');
  13995. * // => '--FOO-BAR--'
  13996. *
  13997. * _.toUpper('fooBar');
  13998. * // => 'FOOBAR'
  13999. *
  14000. * _.toUpper('__foo_bar__');
  14001. * // => '__FOO_BAR__'
  14002. */
  14003. function toUpper(value) {
  14004. return toString(value).toUpperCase();
  14005. }
  14006. /**
  14007. * Removes leading and trailing whitespace or specified characters from `string`.
  14008. *
  14009. * @static
  14010. * @memberOf _
  14011. * @since 3.0.0
  14012. * @category String
  14013. * @param {string} [string=''] The string to trim.
  14014. * @param {string} [chars=whitespace] The characters to trim.
  14015. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14016. * @returns {string} Returns the trimmed string.
  14017. * @example
  14018. *
  14019. * _.trim(' abc ');
  14020. * // => 'abc'
  14021. *
  14022. * _.trim('-_-abc-_-', '_-');
  14023. * // => 'abc'
  14024. *
  14025. * _.map([' foo ', ' bar '], _.trim);
  14026. * // => ['foo', 'bar']
  14027. */
  14028. function trim(string, chars, guard) {
  14029. string = toString(string);
  14030. if (string && (guard || chars === undefined)) {
  14031. return string.replace(reTrim, '');
  14032. }
  14033. if (!string || !(chars = baseToString(chars))) {
  14034. return string;
  14035. }
  14036. var strSymbols = stringToArray(string),
  14037. chrSymbols = stringToArray(chars),
  14038. start = charsStartIndex(strSymbols, chrSymbols),
  14039. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14040. return castSlice(strSymbols, start, end).join('');
  14041. }
  14042. /**
  14043. * Removes trailing whitespace or specified characters from `string`.
  14044. *
  14045. * @static
  14046. * @memberOf _
  14047. * @since 4.0.0
  14048. * @category String
  14049. * @param {string} [string=''] The string to trim.
  14050. * @param {string} [chars=whitespace] The characters to trim.
  14051. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14052. * @returns {string} Returns the trimmed string.
  14053. * @example
  14054. *
  14055. * _.trimEnd(' abc ');
  14056. * // => ' abc'
  14057. *
  14058. * _.trimEnd('-_-abc-_-', '_-');
  14059. * // => '-_-abc'
  14060. */
  14061. function trimEnd(string, chars, guard) {
  14062. string = toString(string);
  14063. if (string && (guard || chars === undefined)) {
  14064. return string.replace(reTrimEnd, '');
  14065. }
  14066. if (!string || !(chars = baseToString(chars))) {
  14067. return string;
  14068. }
  14069. var strSymbols = stringToArray(string),
  14070. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14071. return castSlice(strSymbols, 0, end).join('');
  14072. }
  14073. /**
  14074. * Removes leading whitespace or specified characters from `string`.
  14075. *
  14076. * @static
  14077. * @memberOf _
  14078. * @since 4.0.0
  14079. * @category String
  14080. * @param {string} [string=''] The string to trim.
  14081. * @param {string} [chars=whitespace] The characters to trim.
  14082. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14083. * @returns {string} Returns the trimmed string.
  14084. * @example
  14085. *
  14086. * _.trimStart(' abc ');
  14087. * // => 'abc '
  14088. *
  14089. * _.trimStart('-_-abc-_-', '_-');
  14090. * // => 'abc-_-'
  14091. */
  14092. function trimStart(string, chars, guard) {
  14093. string = toString(string);
  14094. if (string && (guard || chars === undefined)) {
  14095. return string.replace(reTrimStart, '');
  14096. }
  14097. if (!string || !(chars = baseToString(chars))) {
  14098. return string;
  14099. }
  14100. var strSymbols = stringToArray(string),
  14101. start = charsStartIndex(strSymbols, stringToArray(chars));
  14102. return castSlice(strSymbols, start).join('');
  14103. }
  14104. /**
  14105. * Truncates `string` if it's longer than the given maximum string length.
  14106. * The last characters of the truncated string are replaced with the omission
  14107. * string which defaults to "...".
  14108. *
  14109. * @static
  14110. * @memberOf _
  14111. * @since 4.0.0
  14112. * @category String
  14113. * @param {string} [string=''] The string to truncate.
  14114. * @param {Object} [options={}] The options object.
  14115. * @param {number} [options.length=30] The maximum string length.
  14116. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14117. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14118. * @returns {string} Returns the truncated string.
  14119. * @example
  14120. *
  14121. * _.truncate('hi-diddly-ho there, neighborino');
  14122. * // => 'hi-diddly-ho there, neighbo...'
  14123. *
  14124. * _.truncate('hi-diddly-ho there, neighborino', {
  14125. * 'length': 24,
  14126. * 'separator': ' '
  14127. * });
  14128. * // => 'hi-diddly-ho there,...'
  14129. *
  14130. * _.truncate('hi-diddly-ho there, neighborino', {
  14131. * 'length': 24,
  14132. * 'separator': /,? +/
  14133. * });
  14134. * // => 'hi-diddly-ho there...'
  14135. *
  14136. * _.truncate('hi-diddly-ho there, neighborino', {
  14137. * 'omission': ' [...]'
  14138. * });
  14139. * // => 'hi-diddly-ho there, neig [...]'
  14140. */
  14141. function truncate(string, options) {
  14142. var length = DEFAULT_TRUNC_LENGTH,
  14143. omission = DEFAULT_TRUNC_OMISSION;
  14144. if (isObject(options)) {
  14145. var separator = 'separator' in options ? options.separator : separator;
  14146. length = 'length' in options ? toInteger(options.length) : length;
  14147. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14148. }
  14149. string = toString(string);
  14150. var strLength = string.length;
  14151. if (hasUnicode(string)) {
  14152. var strSymbols = stringToArray(string);
  14153. strLength = strSymbols.length;
  14154. }
  14155. if (length >= strLength) {
  14156. return string;
  14157. }
  14158. var end = length - stringSize(omission);
  14159. if (end < 1) {
  14160. return omission;
  14161. }
  14162. var result = strSymbols
  14163. ? castSlice(strSymbols, 0, end).join('')
  14164. : string.slice(0, end);
  14165. if (separator === undefined) {
  14166. return result + omission;
  14167. }
  14168. if (strSymbols) {
  14169. end += (result.length - end);
  14170. }
  14171. if (isRegExp(separator)) {
  14172. if (string.slice(end).search(separator)) {
  14173. var match,
  14174. substring = result;
  14175. if (!separator.global) {
  14176. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14177. }
  14178. separator.lastIndex = 0;
  14179. while ((match = separator.exec(substring))) {
  14180. var newEnd = match.index;
  14181. }
  14182. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14183. }
  14184. } else if (string.indexOf(baseToString(separator), end) != end) {
  14185. var index = result.lastIndexOf(separator);
  14186. if (index > -1) {
  14187. result = result.slice(0, index);
  14188. }
  14189. }
  14190. return result + omission;
  14191. }
  14192. /**
  14193. * The inverse of `_.escape`; this method converts the HTML entities
  14194. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14195. * their corresponding characters.
  14196. *
  14197. * **Note:** No other HTML entities are unescaped. To unescape additional
  14198. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14199. *
  14200. * @static
  14201. * @memberOf _
  14202. * @since 0.6.0
  14203. * @category String
  14204. * @param {string} [string=''] The string to unescape.
  14205. * @returns {string} Returns the unescaped string.
  14206. * @example
  14207. *
  14208. * _.unescape('fred, barney, &amp; pebbles');
  14209. * // => 'fred, barney, & pebbles'
  14210. */
  14211. function unescape(string) {
  14212. string = toString(string);
  14213. return (string && reHasEscapedHtml.test(string))
  14214. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14215. : string;
  14216. }
  14217. /**
  14218. * Converts `string`, as space separated words, to upper case.
  14219. *
  14220. * @static
  14221. * @memberOf _
  14222. * @since 4.0.0
  14223. * @category String
  14224. * @param {string} [string=''] The string to convert.
  14225. * @returns {string} Returns the upper cased string.
  14226. * @example
  14227. *
  14228. * _.upperCase('--foo-bar');
  14229. * // => 'FOO BAR'
  14230. *
  14231. * _.upperCase('fooBar');
  14232. * // => 'FOO BAR'
  14233. *
  14234. * _.upperCase('__foo_bar__');
  14235. * // => 'FOO BAR'
  14236. */
  14237. var upperCase = createCompounder(function(result, word, index) {
  14238. return result + (index ? ' ' : '') + word.toUpperCase();
  14239. });
  14240. /**
  14241. * Converts the first character of `string` to upper case.
  14242. *
  14243. * @static
  14244. * @memberOf _
  14245. * @since 4.0.0
  14246. * @category String
  14247. * @param {string} [string=''] The string to convert.
  14248. * @returns {string} Returns the converted string.
  14249. * @example
  14250. *
  14251. * _.upperFirst('fred');
  14252. * // => 'Fred'
  14253. *
  14254. * _.upperFirst('FRED');
  14255. * // => 'FRED'
  14256. */
  14257. var upperFirst = createCaseFirst('toUpperCase');
  14258. /**
  14259. * Splits `string` into an array of its words.
  14260. *
  14261. * @static
  14262. * @memberOf _
  14263. * @since 3.0.0
  14264. * @category String
  14265. * @param {string} [string=''] The string to inspect.
  14266. * @param {RegExp|string} [pattern] The pattern to match words.
  14267. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14268. * @returns {Array} Returns the words of `string`.
  14269. * @example
  14270. *
  14271. * _.words('fred, barney, & pebbles');
  14272. * // => ['fred', 'barney', 'pebbles']
  14273. *
  14274. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14275. * // => ['fred', 'barney', '&', 'pebbles']
  14276. */
  14277. function words(string, pattern, guard) {
  14278. string = toString(string);
  14279. pattern = guard ? undefined : pattern;
  14280. if (pattern === undefined) {
  14281. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14282. }
  14283. return string.match(pattern) || [];
  14284. }
  14285. /*------------------------------------------------------------------------*/
  14286. /**
  14287. * Attempts to invoke `func`, returning either the result or the caught error
  14288. * object. Any additional arguments are provided to `func` when it's invoked.
  14289. *
  14290. * @static
  14291. * @memberOf _
  14292. * @since 3.0.0
  14293. * @category Util
  14294. * @param {Function} func The function to attempt.
  14295. * @param {...*} [args] The arguments to invoke `func` with.
  14296. * @returns {*} Returns the `func` result or error object.
  14297. * @example
  14298. *
  14299. * // Avoid throwing errors for invalid selectors.
  14300. * var elements = _.attempt(function(selector) {
  14301. * return document.querySelectorAll(selector);
  14302. * }, '>_>');
  14303. *
  14304. * if (_.isError(elements)) {
  14305. * elements = [];
  14306. * }
  14307. */
  14308. var attempt = baseRest(function(func, args) {
  14309. try {
  14310. return apply(func, undefined, args);
  14311. } catch (e) {
  14312. return isError(e) ? e : new Error(e);
  14313. }
  14314. });
  14315. /**
  14316. * Binds methods of an object to the object itself, overwriting the existing
  14317. * method.
  14318. *
  14319. * **Note:** This method doesn't set the "length" property of bound functions.
  14320. *
  14321. * @static
  14322. * @since 0.1.0
  14323. * @memberOf _
  14324. * @category Util
  14325. * @param {Object} object The object to bind and assign the bound methods to.
  14326. * @param {...(string|string[])} methodNames The object method names to bind.
  14327. * @returns {Object} Returns `object`.
  14328. * @example
  14329. *
  14330. * var view = {
  14331. * 'label': 'docs',
  14332. * 'click': function() {
  14333. * console.log('clicked ' + this.label);
  14334. * }
  14335. * };
  14336. *
  14337. * _.bindAll(view, ['click']);
  14338. * jQuery(element).on('click', view.click);
  14339. * // => Logs 'clicked docs' when clicked.
  14340. */
  14341. var bindAll = flatRest(function(object, methodNames) {
  14342. arrayEach(methodNames, function(key) {
  14343. key = toKey(key);
  14344. baseAssignValue(object, key, bind(object[key], object));
  14345. });
  14346. return object;
  14347. });
  14348. /**
  14349. * Creates a function that iterates over `pairs` and invokes the corresponding
  14350. * function of the first predicate to return truthy. The predicate-function
  14351. * pairs are invoked with the `this` binding and arguments of the created
  14352. * function.
  14353. *
  14354. * @static
  14355. * @memberOf _
  14356. * @since 4.0.0
  14357. * @category Util
  14358. * @param {Array} pairs The predicate-function pairs.
  14359. * @returns {Function} Returns the new composite function.
  14360. * @example
  14361. *
  14362. * var func = _.cond([
  14363. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14364. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14365. * [_.stubTrue, _.constant('no match')]
  14366. * ]);
  14367. *
  14368. * func({ 'a': 1, 'b': 2 });
  14369. * // => 'matches A'
  14370. *
  14371. * func({ 'a': 0, 'b': 1 });
  14372. * // => 'matches B'
  14373. *
  14374. * func({ 'a': '1', 'b': '2' });
  14375. * // => 'no match'
  14376. */
  14377. function cond(pairs) {
  14378. var length = pairs == null ? 0 : pairs.length,
  14379. toIteratee = getIteratee();
  14380. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14381. if (typeof pair[1] != 'function') {
  14382. throw new TypeError(FUNC_ERROR_TEXT);
  14383. }
  14384. return [toIteratee(pair[0]), pair[1]];
  14385. });
  14386. return baseRest(function(args) {
  14387. var index = -1;
  14388. while (++index < length) {
  14389. var pair = pairs[index];
  14390. if (apply(pair[0], this, args)) {
  14391. return apply(pair[1], this, args);
  14392. }
  14393. }
  14394. });
  14395. }
  14396. /**
  14397. * Creates a function that invokes the predicate properties of `source` with
  14398. * the corresponding property values of a given object, returning `true` if
  14399. * all predicates return truthy, else `false`.
  14400. *
  14401. * **Note:** The created function is equivalent to `_.conformsTo` with
  14402. * `source` partially applied.
  14403. *
  14404. * @static
  14405. * @memberOf _
  14406. * @since 4.0.0
  14407. * @category Util
  14408. * @param {Object} source The object of property predicates to conform to.
  14409. * @returns {Function} Returns the new spec function.
  14410. * @example
  14411. *
  14412. * var objects = [
  14413. * { 'a': 2, 'b': 1 },
  14414. * { 'a': 1, 'b': 2 }
  14415. * ];
  14416. *
  14417. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14418. * // => [{ 'a': 1, 'b': 2 }]
  14419. */
  14420. function conforms(source) {
  14421. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14422. }
  14423. /**
  14424. * Creates a function that returns `value`.
  14425. *
  14426. * @static
  14427. * @memberOf _
  14428. * @since 2.4.0
  14429. * @category Util
  14430. * @param {*} value The value to return from the new function.
  14431. * @returns {Function} Returns the new constant function.
  14432. * @example
  14433. *
  14434. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14435. *
  14436. * console.log(objects);
  14437. * // => [{ 'a': 1 }, { 'a': 1 }]
  14438. *
  14439. * console.log(objects[0] === objects[1]);
  14440. * // => true
  14441. */
  14442. function constant(value) {
  14443. return function() {
  14444. return value;
  14445. };
  14446. }
  14447. /**
  14448. * Checks `value` to determine whether a default value should be returned in
  14449. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14450. * or `undefined`.
  14451. *
  14452. * @static
  14453. * @memberOf _
  14454. * @since 4.14.0
  14455. * @category Util
  14456. * @param {*} value The value to check.
  14457. * @param {*} defaultValue The default value.
  14458. * @returns {*} Returns the resolved value.
  14459. * @example
  14460. *
  14461. * _.defaultTo(1, 10);
  14462. * // => 1
  14463. *
  14464. * _.defaultTo(undefined, 10);
  14465. * // => 10
  14466. */
  14467. function defaultTo(value, defaultValue) {
  14468. return (value == null || value !== value) ? defaultValue : value;
  14469. }
  14470. /**
  14471. * Creates a function that returns the result of invoking the given functions
  14472. * with the `this` binding of the created function, where each successive
  14473. * invocation is supplied the return value of the previous.
  14474. *
  14475. * @static
  14476. * @memberOf _
  14477. * @since 3.0.0
  14478. * @category Util
  14479. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14480. * @returns {Function} Returns the new composite function.
  14481. * @see _.flowRight
  14482. * @example
  14483. *
  14484. * function square(n) {
  14485. * return n * n;
  14486. * }
  14487. *
  14488. * var addSquare = _.flow([_.add, square]);
  14489. * addSquare(1, 2);
  14490. * // => 9
  14491. */
  14492. var flow = createFlow();
  14493. /**
  14494. * This method is like `_.flow` except that it creates a function that
  14495. * invokes the given functions from right to left.
  14496. *
  14497. * @static
  14498. * @since 3.0.0
  14499. * @memberOf _
  14500. * @category Util
  14501. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14502. * @returns {Function} Returns the new composite function.
  14503. * @see _.flow
  14504. * @example
  14505. *
  14506. * function square(n) {
  14507. * return n * n;
  14508. * }
  14509. *
  14510. * var addSquare = _.flowRight([square, _.add]);
  14511. * addSquare(1, 2);
  14512. * // => 9
  14513. */
  14514. var flowRight = createFlow(true);
  14515. /**
  14516. * This method returns the first argument it receives.
  14517. *
  14518. * @static
  14519. * @since 0.1.0
  14520. * @memberOf _
  14521. * @category Util
  14522. * @param {*} value Any value.
  14523. * @returns {*} Returns `value`.
  14524. * @example
  14525. *
  14526. * var object = { 'a': 1 };
  14527. *
  14528. * console.log(_.identity(object) === object);
  14529. * // => true
  14530. */
  14531. function identity(value) {
  14532. return value;
  14533. }
  14534. /**
  14535. * Creates a function that invokes `func` with the arguments of the created
  14536. * function. If `func` is a property name, the created function returns the
  14537. * property value for a given element. If `func` is an array or object, the
  14538. * created function returns `true` for elements that contain the equivalent
  14539. * source properties, otherwise it returns `false`.
  14540. *
  14541. * @static
  14542. * @since 4.0.0
  14543. * @memberOf _
  14544. * @category Util
  14545. * @param {*} [func=_.identity] The value to convert to a callback.
  14546. * @returns {Function} Returns the callback.
  14547. * @example
  14548. *
  14549. * var users = [
  14550. * { 'user': 'barney', 'age': 36, 'active': true },
  14551. * { 'user': 'fred', 'age': 40, 'active': false }
  14552. * ];
  14553. *
  14554. * // The `_.matches` iteratee shorthand.
  14555. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14556. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14557. *
  14558. * // The `_.matchesProperty` iteratee shorthand.
  14559. * _.filter(users, _.iteratee(['user', 'fred']));
  14560. * // => [{ 'user': 'fred', 'age': 40 }]
  14561. *
  14562. * // The `_.property` iteratee shorthand.
  14563. * _.map(users, _.iteratee('user'));
  14564. * // => ['barney', 'fred']
  14565. *
  14566. * // Create custom iteratee shorthands.
  14567. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14568. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14569. * return func.test(string);
  14570. * };
  14571. * });
  14572. *
  14573. * _.filter(['abc', 'def'], /ef/);
  14574. * // => ['def']
  14575. */
  14576. function iteratee(func) {
  14577. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14578. }
  14579. /**
  14580. * Creates a function that performs a partial deep comparison between a given
  14581. * object and `source`, returning `true` if the given object has equivalent
  14582. * property values, else `false`.
  14583. *
  14584. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14585. * partially applied.
  14586. *
  14587. * Partial comparisons will match empty array and empty object `source`
  14588. * values against any array or object value, respectively. See `_.isEqual`
  14589. * for a list of supported value comparisons.
  14590. *
  14591. * @static
  14592. * @memberOf _
  14593. * @since 3.0.0
  14594. * @category Util
  14595. * @param {Object} source The object of property values to match.
  14596. * @returns {Function} Returns the new spec function.
  14597. * @example
  14598. *
  14599. * var objects = [
  14600. * { 'a': 1, 'b': 2, 'c': 3 },
  14601. * { 'a': 4, 'b': 5, 'c': 6 }
  14602. * ];
  14603. *
  14604. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14605. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14606. */
  14607. function matches(source) {
  14608. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14609. }
  14610. /**
  14611. * Creates a function that performs a partial deep comparison between the
  14612. * value at `path` of a given object to `srcValue`, returning `true` if the
  14613. * object value is equivalent, else `false`.
  14614. *
  14615. * **Note:** Partial comparisons will match empty array and empty object
  14616. * `srcValue` values against any array or object value, respectively. See
  14617. * `_.isEqual` for a list of supported value comparisons.
  14618. *
  14619. * @static
  14620. * @memberOf _
  14621. * @since 3.2.0
  14622. * @category Util
  14623. * @param {Array|string} path The path of the property to get.
  14624. * @param {*} srcValue The value to match.
  14625. * @returns {Function} Returns the new spec function.
  14626. * @example
  14627. *
  14628. * var objects = [
  14629. * { 'a': 1, 'b': 2, 'c': 3 },
  14630. * { 'a': 4, 'b': 5, 'c': 6 }
  14631. * ];
  14632. *
  14633. * _.find(objects, _.matchesProperty('a', 4));
  14634. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14635. */
  14636. function matchesProperty(path, srcValue) {
  14637. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14638. }
  14639. /**
  14640. * Creates a function that invokes the method at `path` of a given object.
  14641. * Any additional arguments are provided to the invoked method.
  14642. *
  14643. * @static
  14644. * @memberOf _
  14645. * @since 3.7.0
  14646. * @category Util
  14647. * @param {Array|string} path The path of the method to invoke.
  14648. * @param {...*} [args] The arguments to invoke the method with.
  14649. * @returns {Function} Returns the new invoker function.
  14650. * @example
  14651. *
  14652. * var objects = [
  14653. * { 'a': { 'b': _.constant(2) } },
  14654. * { 'a': { 'b': _.constant(1) } }
  14655. * ];
  14656. *
  14657. * _.map(objects, _.method('a.b'));
  14658. * // => [2, 1]
  14659. *
  14660. * _.map(objects, _.method(['a', 'b']));
  14661. * // => [2, 1]
  14662. */
  14663. var method = baseRest(function(path, args) {
  14664. return function(object) {
  14665. return baseInvoke(object, path, args);
  14666. };
  14667. });
  14668. /**
  14669. * The opposite of `_.method`; this method creates a function that invokes
  14670. * the method at a given path of `object`. Any additional arguments are
  14671. * provided to the invoked method.
  14672. *
  14673. * @static
  14674. * @memberOf _
  14675. * @since 3.7.0
  14676. * @category Util
  14677. * @param {Object} object The object to query.
  14678. * @param {...*} [args] The arguments to invoke the method with.
  14679. * @returns {Function} Returns the new invoker function.
  14680. * @example
  14681. *
  14682. * var array = _.times(3, _.constant),
  14683. * object = { 'a': array, 'b': array, 'c': array };
  14684. *
  14685. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14686. * // => [2, 0]
  14687. *
  14688. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14689. * // => [2, 0]
  14690. */
  14691. var methodOf = baseRest(function(object, args) {
  14692. return function(path) {
  14693. return baseInvoke(object, path, args);
  14694. };
  14695. });
  14696. /**
  14697. * Adds all own enumerable string keyed function properties of a source
  14698. * object to the destination object. If `object` is a function, then methods
  14699. * are added to its prototype as well.
  14700. *
  14701. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14702. * avoid conflicts caused by modifying the original.
  14703. *
  14704. * @static
  14705. * @since 0.1.0
  14706. * @memberOf _
  14707. * @category Util
  14708. * @param {Function|Object} [object=lodash] The destination object.
  14709. * @param {Object} source The object of functions to add.
  14710. * @param {Object} [options={}] The options object.
  14711. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14712. * @returns {Function|Object} Returns `object`.
  14713. * @example
  14714. *
  14715. * function vowels(string) {
  14716. * return _.filter(string, function(v) {
  14717. * return /[aeiou]/i.test(v);
  14718. * });
  14719. * }
  14720. *
  14721. * _.mixin({ 'vowels': vowels });
  14722. * _.vowels('fred');
  14723. * // => ['e']
  14724. *
  14725. * _('fred').vowels().value();
  14726. * // => ['e']
  14727. *
  14728. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14729. * _('fred').vowels();
  14730. * // => ['e']
  14731. */
  14732. function mixin(object, source, options) {
  14733. var props = keys(source),
  14734. methodNames = baseFunctions(source, props);
  14735. if (options == null &&
  14736. !(isObject(source) && (methodNames.length || !props.length))) {
  14737. options = source;
  14738. source = object;
  14739. object = this;
  14740. methodNames = baseFunctions(source, keys(source));
  14741. }
  14742. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14743. isFunc = isFunction(object);
  14744. arrayEach(methodNames, function(methodName) {
  14745. var func = source[methodName];
  14746. object[methodName] = func;
  14747. if (isFunc) {
  14748. object.prototype[methodName] = function() {
  14749. var chainAll = this.__chain__;
  14750. if (chain || chainAll) {
  14751. var result = object(this.__wrapped__),
  14752. actions = result.__actions__ = copyArray(this.__actions__);
  14753. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14754. result.__chain__ = chainAll;
  14755. return result;
  14756. }
  14757. return func.apply(object, arrayPush([this.value()], arguments));
  14758. };
  14759. }
  14760. });
  14761. return object;
  14762. }
  14763. /**
  14764. * Reverts the `_` variable to its previous value and returns a reference to
  14765. * the `lodash` function.
  14766. *
  14767. * @static
  14768. * @since 0.1.0
  14769. * @memberOf _
  14770. * @category Util
  14771. * @returns {Function} Returns the `lodash` function.
  14772. * @example
  14773. *
  14774. * var lodash = _.noConflict();
  14775. */
  14776. function noConflict() {
  14777. if (root._ === this) {
  14778. root._ = oldDash;
  14779. }
  14780. return this;
  14781. }
  14782. /**
  14783. * This method returns `undefined`.
  14784. *
  14785. * @static
  14786. * @memberOf _
  14787. * @since 2.3.0
  14788. * @category Util
  14789. * @example
  14790. *
  14791. * _.times(2, _.noop);
  14792. * // => [undefined, undefined]
  14793. */
  14794. function noop() {
  14795. // No operation performed.
  14796. }
  14797. /**
  14798. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14799. * the nth argument from the end is returned.
  14800. *
  14801. * @static
  14802. * @memberOf _
  14803. * @since 4.0.0
  14804. * @category Util
  14805. * @param {number} [n=0] The index of the argument to return.
  14806. * @returns {Function} Returns the new pass-thru function.
  14807. * @example
  14808. *
  14809. * var func = _.nthArg(1);
  14810. * func('a', 'b', 'c', 'd');
  14811. * // => 'b'
  14812. *
  14813. * var func = _.nthArg(-2);
  14814. * func('a', 'b', 'c', 'd');
  14815. * // => 'c'
  14816. */
  14817. function nthArg(n) {
  14818. n = toInteger(n);
  14819. return baseRest(function(args) {
  14820. return baseNth(args, n);
  14821. });
  14822. }
  14823. /**
  14824. * Creates a function that invokes `iteratees` with the arguments it receives
  14825. * and returns their results.
  14826. *
  14827. * @static
  14828. * @memberOf _
  14829. * @since 4.0.0
  14830. * @category Util
  14831. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14832. * The iteratees to invoke.
  14833. * @returns {Function} Returns the new function.
  14834. * @example
  14835. *
  14836. * var func = _.over([Math.max, Math.min]);
  14837. *
  14838. * func(1, 2, 3, 4);
  14839. * // => [4, 1]
  14840. */
  14841. var over = createOver(arrayMap);
  14842. /**
  14843. * Creates a function that checks if **all** of the `predicates` return
  14844. * truthy when invoked with the arguments it receives.
  14845. *
  14846. * @static
  14847. * @memberOf _
  14848. * @since 4.0.0
  14849. * @category Util
  14850. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14851. * The predicates to check.
  14852. * @returns {Function} Returns the new function.
  14853. * @example
  14854. *
  14855. * var func = _.overEvery([Boolean, isFinite]);
  14856. *
  14857. * func('1');
  14858. * // => true
  14859. *
  14860. * func(null);
  14861. * // => false
  14862. *
  14863. * func(NaN);
  14864. * // => false
  14865. */
  14866. var overEvery = createOver(arrayEvery);
  14867. /**
  14868. * Creates a function that checks if **any** of the `predicates` return
  14869. * truthy when invoked with the arguments it receives.
  14870. *
  14871. * @static
  14872. * @memberOf _
  14873. * @since 4.0.0
  14874. * @category Util
  14875. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14876. * The predicates to check.
  14877. * @returns {Function} Returns the new function.
  14878. * @example
  14879. *
  14880. * var func = _.overSome([Boolean, isFinite]);
  14881. *
  14882. * func('1');
  14883. * // => true
  14884. *
  14885. * func(null);
  14886. * // => true
  14887. *
  14888. * func(NaN);
  14889. * // => false
  14890. */
  14891. var overSome = createOver(arraySome);
  14892. /**
  14893. * Creates a function that returns the value at `path` of a given object.
  14894. *
  14895. * @static
  14896. * @memberOf _
  14897. * @since 2.4.0
  14898. * @category Util
  14899. * @param {Array|string} path The path of the property to get.
  14900. * @returns {Function} Returns the new accessor function.
  14901. * @example
  14902. *
  14903. * var objects = [
  14904. * { 'a': { 'b': 2 } },
  14905. * { 'a': { 'b': 1 } }
  14906. * ];
  14907. *
  14908. * _.map(objects, _.property('a.b'));
  14909. * // => [2, 1]
  14910. *
  14911. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14912. * // => [1, 2]
  14913. */
  14914. function property(path) {
  14915. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14916. }
  14917. /**
  14918. * The opposite of `_.property`; this method creates a function that returns
  14919. * the value at a given path of `object`.
  14920. *
  14921. * @static
  14922. * @memberOf _
  14923. * @since 3.0.0
  14924. * @category Util
  14925. * @param {Object} object The object to query.
  14926. * @returns {Function} Returns the new accessor function.
  14927. * @example
  14928. *
  14929. * var array = [0, 1, 2],
  14930. * object = { 'a': array, 'b': array, 'c': array };
  14931. *
  14932. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14933. * // => [2, 0]
  14934. *
  14935. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14936. * // => [2, 0]
  14937. */
  14938. function propertyOf(object) {
  14939. return function(path) {
  14940. return object == null ? undefined : baseGet(object, path);
  14941. };
  14942. }
  14943. /**
  14944. * Creates an array of numbers (positive and/or negative) progressing from
  14945. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14946. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14947. * it's set to `start` with `start` then set to `0`.
  14948. *
  14949. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14950. * floating-point values which can produce unexpected results.
  14951. *
  14952. * @static
  14953. * @since 0.1.0
  14954. * @memberOf _
  14955. * @category Util
  14956. * @param {number} [start=0] The start of the range.
  14957. * @param {number} end The end of the range.
  14958. * @param {number} [step=1] The value to increment or decrement by.
  14959. * @returns {Array} Returns the range of numbers.
  14960. * @see _.inRange, _.rangeRight
  14961. * @example
  14962. *
  14963. * _.range(4);
  14964. * // => [0, 1, 2, 3]
  14965. *
  14966. * _.range(-4);
  14967. * // => [0, -1, -2, -3]
  14968. *
  14969. * _.range(1, 5);
  14970. * // => [1, 2, 3, 4]
  14971. *
  14972. * _.range(0, 20, 5);
  14973. * // => [0, 5, 10, 15]
  14974. *
  14975. * _.range(0, -4, -1);
  14976. * // => [0, -1, -2, -3]
  14977. *
  14978. * _.range(1, 4, 0);
  14979. * // => [1, 1, 1]
  14980. *
  14981. * _.range(0);
  14982. * // => []
  14983. */
  14984. var range = createRange();
  14985. /**
  14986. * This method is like `_.range` except that it populates values in
  14987. * descending order.
  14988. *
  14989. * @static
  14990. * @memberOf _
  14991. * @since 4.0.0
  14992. * @category Util
  14993. * @param {number} [start=0] The start of the range.
  14994. * @param {number} end The end of the range.
  14995. * @param {number} [step=1] The value to increment or decrement by.
  14996. * @returns {Array} Returns the range of numbers.
  14997. * @see _.inRange, _.range
  14998. * @example
  14999. *
  15000. * _.rangeRight(4);
  15001. * // => [3, 2, 1, 0]
  15002. *
  15003. * _.rangeRight(-4);
  15004. * // => [-3, -2, -1, 0]
  15005. *
  15006. * _.rangeRight(1, 5);
  15007. * // => [4, 3, 2, 1]
  15008. *
  15009. * _.rangeRight(0, 20, 5);
  15010. * // => [15, 10, 5, 0]
  15011. *
  15012. * _.rangeRight(0, -4, -1);
  15013. * // => [-3, -2, -1, 0]
  15014. *
  15015. * _.rangeRight(1, 4, 0);
  15016. * // => [1, 1, 1]
  15017. *
  15018. * _.rangeRight(0);
  15019. * // => []
  15020. */
  15021. var rangeRight = createRange(true);
  15022. /**
  15023. * This method returns a new empty array.
  15024. *
  15025. * @static
  15026. * @memberOf _
  15027. * @since 4.13.0
  15028. * @category Util
  15029. * @returns {Array} Returns the new empty array.
  15030. * @example
  15031. *
  15032. * var arrays = _.times(2, _.stubArray);
  15033. *
  15034. * console.log(arrays);
  15035. * // => [[], []]
  15036. *
  15037. * console.log(arrays[0] === arrays[1]);
  15038. * // => false
  15039. */
  15040. function stubArray() {
  15041. return [];
  15042. }
  15043. /**
  15044. * This method returns `false`.
  15045. *
  15046. * @static
  15047. * @memberOf _
  15048. * @since 4.13.0
  15049. * @category Util
  15050. * @returns {boolean} Returns `false`.
  15051. * @example
  15052. *
  15053. * _.times(2, _.stubFalse);
  15054. * // => [false, false]
  15055. */
  15056. function stubFalse() {
  15057. return false;
  15058. }
  15059. /**
  15060. * This method returns a new empty object.
  15061. *
  15062. * @static
  15063. * @memberOf _
  15064. * @since 4.13.0
  15065. * @category Util
  15066. * @returns {Object} Returns the new empty object.
  15067. * @example
  15068. *
  15069. * var objects = _.times(2, _.stubObject);
  15070. *
  15071. * console.log(objects);
  15072. * // => [{}, {}]
  15073. *
  15074. * console.log(objects[0] === objects[1]);
  15075. * // => false
  15076. */
  15077. function stubObject() {
  15078. return {};
  15079. }
  15080. /**
  15081. * This method returns an empty string.
  15082. *
  15083. * @static
  15084. * @memberOf _
  15085. * @since 4.13.0
  15086. * @category Util
  15087. * @returns {string} Returns the empty string.
  15088. * @example
  15089. *
  15090. * _.times(2, _.stubString);
  15091. * // => ['', '']
  15092. */
  15093. function stubString() {
  15094. return '';
  15095. }
  15096. /**
  15097. * This method returns `true`.
  15098. *
  15099. * @static
  15100. * @memberOf _
  15101. * @since 4.13.0
  15102. * @category Util
  15103. * @returns {boolean} Returns `true`.
  15104. * @example
  15105. *
  15106. * _.times(2, _.stubTrue);
  15107. * // => [true, true]
  15108. */
  15109. function stubTrue() {
  15110. return true;
  15111. }
  15112. /**
  15113. * Invokes the iteratee `n` times, returning an array of the results of
  15114. * each invocation. The iteratee is invoked with one argument; (index).
  15115. *
  15116. * @static
  15117. * @since 0.1.0
  15118. * @memberOf _
  15119. * @category Util
  15120. * @param {number} n The number of times to invoke `iteratee`.
  15121. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15122. * @returns {Array} Returns the array of results.
  15123. * @example
  15124. *
  15125. * _.times(3, String);
  15126. * // => ['0', '1', '2']
  15127. *
  15128. * _.times(4, _.constant(0));
  15129. * // => [0, 0, 0, 0]
  15130. */
  15131. function times(n, iteratee) {
  15132. n = toInteger(n);
  15133. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15134. return [];
  15135. }
  15136. var index = MAX_ARRAY_LENGTH,
  15137. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15138. iteratee = getIteratee(iteratee);
  15139. n -= MAX_ARRAY_LENGTH;
  15140. var result = baseTimes(length, iteratee);
  15141. while (++index < n) {
  15142. iteratee(index);
  15143. }
  15144. return result;
  15145. }
  15146. /**
  15147. * Converts `value` to a property path array.
  15148. *
  15149. * @static
  15150. * @memberOf _
  15151. * @since 4.0.0
  15152. * @category Util
  15153. * @param {*} value The value to convert.
  15154. * @returns {Array} Returns the new property path array.
  15155. * @example
  15156. *
  15157. * _.toPath('a.b.c');
  15158. * // => ['a', 'b', 'c']
  15159. *
  15160. * _.toPath('a[0].b.c');
  15161. * // => ['a', '0', 'b', 'c']
  15162. */
  15163. function toPath(value) {
  15164. if (isArray(value)) {
  15165. return arrayMap(value, toKey);
  15166. }
  15167. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15168. }
  15169. /**
  15170. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15171. *
  15172. * @static
  15173. * @since 0.1.0
  15174. * @memberOf _
  15175. * @category Util
  15176. * @param {string} [prefix=''] The value to prefix the ID with.
  15177. * @returns {string} Returns the unique ID.
  15178. * @example
  15179. *
  15180. * _.uniqueId('contact_');
  15181. * // => 'contact_104'
  15182. *
  15183. * _.uniqueId();
  15184. * // => '105'
  15185. */
  15186. function uniqueId(prefix) {
  15187. var id = ++idCounter;
  15188. return toString(prefix) + id;
  15189. }
  15190. /*------------------------------------------------------------------------*/
  15191. /**
  15192. * Adds two numbers.
  15193. *
  15194. * @static
  15195. * @memberOf _
  15196. * @since 3.4.0
  15197. * @category Math
  15198. * @param {number} augend The first number in an addition.
  15199. * @param {number} addend The second number in an addition.
  15200. * @returns {number} Returns the total.
  15201. * @example
  15202. *
  15203. * _.add(6, 4);
  15204. * // => 10
  15205. */
  15206. var add = createMathOperation(function(augend, addend) {
  15207. return augend + addend;
  15208. }, 0);
  15209. /**
  15210. * Computes `number` rounded up to `precision`.
  15211. *
  15212. * @static
  15213. * @memberOf _
  15214. * @since 3.10.0
  15215. * @category Math
  15216. * @param {number} number The number to round up.
  15217. * @param {number} [precision=0] The precision to round up to.
  15218. * @returns {number} Returns the rounded up number.
  15219. * @example
  15220. *
  15221. * _.ceil(4.006);
  15222. * // => 5
  15223. *
  15224. * _.ceil(6.004, 2);
  15225. * // => 6.01
  15226. *
  15227. * _.ceil(6040, -2);
  15228. * // => 6100
  15229. */
  15230. var ceil = createRound('ceil');
  15231. /**
  15232. * Divide two numbers.
  15233. *
  15234. * @static
  15235. * @memberOf _
  15236. * @since 4.7.0
  15237. * @category Math
  15238. * @param {number} dividend The first number in a division.
  15239. * @param {number} divisor The second number in a division.
  15240. * @returns {number} Returns the quotient.
  15241. * @example
  15242. *
  15243. * _.divide(6, 4);
  15244. * // => 1.5
  15245. */
  15246. var divide = createMathOperation(function(dividend, divisor) {
  15247. return dividend / divisor;
  15248. }, 1);
  15249. /**
  15250. * Computes `number` rounded down to `precision`.
  15251. *
  15252. * @static
  15253. * @memberOf _
  15254. * @since 3.10.0
  15255. * @category Math
  15256. * @param {number} number The number to round down.
  15257. * @param {number} [precision=0] The precision to round down to.
  15258. * @returns {number} Returns the rounded down number.
  15259. * @example
  15260. *
  15261. * _.floor(4.006);
  15262. * // => 4
  15263. *
  15264. * _.floor(0.046, 2);
  15265. * // => 0.04
  15266. *
  15267. * _.floor(4060, -2);
  15268. * // => 4000
  15269. */
  15270. var floor = createRound('floor');
  15271. /**
  15272. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15273. * `undefined` is returned.
  15274. *
  15275. * @static
  15276. * @since 0.1.0
  15277. * @memberOf _
  15278. * @category Math
  15279. * @param {Array} array The array to iterate over.
  15280. * @returns {*} Returns the maximum value.
  15281. * @example
  15282. *
  15283. * _.max([4, 2, 8, 6]);
  15284. * // => 8
  15285. *
  15286. * _.max([]);
  15287. * // => undefined
  15288. */
  15289. function max(array) {
  15290. return (array && array.length)
  15291. ? baseExtremum(array, identity, baseGt)
  15292. : undefined;
  15293. }
  15294. /**
  15295. * This method is like `_.max` except that it accepts `iteratee` which is
  15296. * invoked for each element in `array` to generate the criterion by which
  15297. * the value is ranked. The iteratee is invoked with one argument: (value).
  15298. *
  15299. * @static
  15300. * @memberOf _
  15301. * @since 4.0.0
  15302. * @category Math
  15303. * @param {Array} array The array to iterate over.
  15304. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15305. * @returns {*} Returns the maximum value.
  15306. * @example
  15307. *
  15308. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15309. *
  15310. * _.maxBy(objects, function(o) { return o.n; });
  15311. * // => { 'n': 2 }
  15312. *
  15313. * // The `_.property` iteratee shorthand.
  15314. * _.maxBy(objects, 'n');
  15315. * // => { 'n': 2 }
  15316. */
  15317. function maxBy(array, iteratee) {
  15318. return (array && array.length)
  15319. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15320. : undefined;
  15321. }
  15322. /**
  15323. * Computes the mean of the values in `array`.
  15324. *
  15325. * @static
  15326. * @memberOf _
  15327. * @since 4.0.0
  15328. * @category Math
  15329. * @param {Array} array The array to iterate over.
  15330. * @returns {number} Returns the mean.
  15331. * @example
  15332. *
  15333. * _.mean([4, 2, 8, 6]);
  15334. * // => 5
  15335. */
  15336. function mean(array) {
  15337. return baseMean(array, identity);
  15338. }
  15339. /**
  15340. * This method is like `_.mean` except that it accepts `iteratee` which is
  15341. * invoked for each element in `array` to generate the value to be averaged.
  15342. * The iteratee is invoked with one argument: (value).
  15343. *
  15344. * @static
  15345. * @memberOf _
  15346. * @since 4.7.0
  15347. * @category Math
  15348. * @param {Array} array The array to iterate over.
  15349. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15350. * @returns {number} Returns the mean.
  15351. * @example
  15352. *
  15353. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15354. *
  15355. * _.meanBy(objects, function(o) { return o.n; });
  15356. * // => 5
  15357. *
  15358. * // The `_.property` iteratee shorthand.
  15359. * _.meanBy(objects, 'n');
  15360. * // => 5
  15361. */
  15362. function meanBy(array, iteratee) {
  15363. return baseMean(array, getIteratee(iteratee, 2));
  15364. }
  15365. /**
  15366. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15367. * `undefined` is returned.
  15368. *
  15369. * @static
  15370. * @since 0.1.0
  15371. * @memberOf _
  15372. * @category Math
  15373. * @param {Array} array The array to iterate over.
  15374. * @returns {*} Returns the minimum value.
  15375. * @example
  15376. *
  15377. * _.min([4, 2, 8, 6]);
  15378. * // => 2
  15379. *
  15380. * _.min([]);
  15381. * // => undefined
  15382. */
  15383. function min(array) {
  15384. return (array && array.length)
  15385. ? baseExtremum(array, identity, baseLt)
  15386. : undefined;
  15387. }
  15388. /**
  15389. * This method is like `_.min` except that it accepts `iteratee` which is
  15390. * invoked for each element in `array` to generate the criterion by which
  15391. * the value is ranked. The iteratee is invoked with one argument: (value).
  15392. *
  15393. * @static
  15394. * @memberOf _
  15395. * @since 4.0.0
  15396. * @category Math
  15397. * @param {Array} array The array to iterate over.
  15398. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15399. * @returns {*} Returns the minimum value.
  15400. * @example
  15401. *
  15402. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15403. *
  15404. * _.minBy(objects, function(o) { return o.n; });
  15405. * // => { 'n': 1 }
  15406. *
  15407. * // The `_.property` iteratee shorthand.
  15408. * _.minBy(objects, 'n');
  15409. * // => { 'n': 1 }
  15410. */
  15411. function minBy(array, iteratee) {
  15412. return (array && array.length)
  15413. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15414. : undefined;
  15415. }
  15416. /**
  15417. * Multiply two numbers.
  15418. *
  15419. * @static
  15420. * @memberOf _
  15421. * @since 4.7.0
  15422. * @category Math
  15423. * @param {number} multiplier The first number in a multiplication.
  15424. * @param {number} multiplicand The second number in a multiplication.
  15425. * @returns {number} Returns the product.
  15426. * @example
  15427. *
  15428. * _.multiply(6, 4);
  15429. * // => 24
  15430. */
  15431. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15432. return multiplier * multiplicand;
  15433. }, 1);
  15434. /**
  15435. * Computes `number` rounded to `precision`.
  15436. *
  15437. * @static
  15438. * @memberOf _
  15439. * @since 3.10.0
  15440. * @category Math
  15441. * @param {number} number The number to round.
  15442. * @param {number} [precision=0] The precision to round to.
  15443. * @returns {number} Returns the rounded number.
  15444. * @example
  15445. *
  15446. * _.round(4.006);
  15447. * // => 4
  15448. *
  15449. * _.round(4.006, 2);
  15450. * // => 4.01
  15451. *
  15452. * _.round(4060, -2);
  15453. * // => 4100
  15454. */
  15455. var round = createRound('round');
  15456. /**
  15457. * Subtract two numbers.
  15458. *
  15459. * @static
  15460. * @memberOf _
  15461. * @since 4.0.0
  15462. * @category Math
  15463. * @param {number} minuend The first number in a subtraction.
  15464. * @param {number} subtrahend The second number in a subtraction.
  15465. * @returns {number} Returns the difference.
  15466. * @example
  15467. *
  15468. * _.subtract(6, 4);
  15469. * // => 2
  15470. */
  15471. var subtract = createMathOperation(function(minuend, subtrahend) {
  15472. return minuend - subtrahend;
  15473. }, 0);
  15474. /**
  15475. * Computes the sum of the values in `array`.
  15476. *
  15477. * @static
  15478. * @memberOf _
  15479. * @since 3.4.0
  15480. * @category Math
  15481. * @param {Array} array The array to iterate over.
  15482. * @returns {number} Returns the sum.
  15483. * @example
  15484. *
  15485. * _.sum([4, 2, 8, 6]);
  15486. * // => 20
  15487. */
  15488. function sum(array) {
  15489. return (array && array.length)
  15490. ? baseSum(array, identity)
  15491. : 0;
  15492. }
  15493. /**
  15494. * This method is like `_.sum` except that it accepts `iteratee` which is
  15495. * invoked for each element in `array` to generate the value to be summed.
  15496. * The iteratee is invoked with one argument: (value).
  15497. *
  15498. * @static
  15499. * @memberOf _
  15500. * @since 4.0.0
  15501. * @category Math
  15502. * @param {Array} array The array to iterate over.
  15503. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15504. * @returns {number} Returns the sum.
  15505. * @example
  15506. *
  15507. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15508. *
  15509. * _.sumBy(objects, function(o) { return o.n; });
  15510. * // => 20
  15511. *
  15512. * // The `_.property` iteratee shorthand.
  15513. * _.sumBy(objects, 'n');
  15514. * // => 20
  15515. */
  15516. function sumBy(array, iteratee) {
  15517. return (array && array.length)
  15518. ? baseSum(array, getIteratee(iteratee, 2))
  15519. : 0;
  15520. }
  15521. /*------------------------------------------------------------------------*/
  15522. // Add methods that return wrapped values in chain sequences.
  15523. lodash.after = after;
  15524. lodash.ary = ary;
  15525. lodash.assign = assign;
  15526. lodash.assignIn = assignIn;
  15527. lodash.assignInWith = assignInWith;
  15528. lodash.assignWith = assignWith;
  15529. lodash.at = at;
  15530. lodash.before = before;
  15531. lodash.bind = bind;
  15532. lodash.bindAll = bindAll;
  15533. lodash.bindKey = bindKey;
  15534. lodash.castArray = castArray;
  15535. lodash.chain = chain;
  15536. lodash.chunk = chunk;
  15537. lodash.compact = compact;
  15538. lodash.concat = concat;
  15539. lodash.cond = cond;
  15540. lodash.conforms = conforms;
  15541. lodash.constant = constant;
  15542. lodash.countBy = countBy;
  15543. lodash.create = create;
  15544. lodash.curry = curry;
  15545. lodash.curryRight = curryRight;
  15546. lodash.debounce = debounce;
  15547. lodash.defaults = defaults;
  15548. lodash.defaultsDeep = defaultsDeep;
  15549. lodash.defer = defer;
  15550. lodash.delay = delay;
  15551. lodash.difference = difference;
  15552. lodash.differenceBy = differenceBy;
  15553. lodash.differenceWith = differenceWith;
  15554. lodash.drop = drop;
  15555. lodash.dropRight = dropRight;
  15556. lodash.dropRightWhile = dropRightWhile;
  15557. lodash.dropWhile = dropWhile;
  15558. lodash.fill = fill;
  15559. lodash.filter = filter;
  15560. lodash.flatMap = flatMap;
  15561. lodash.flatMapDeep = flatMapDeep;
  15562. lodash.flatMapDepth = flatMapDepth;
  15563. lodash.flatten = flatten;
  15564. lodash.flattenDeep = flattenDeep;
  15565. lodash.flattenDepth = flattenDepth;
  15566. lodash.flip = flip;
  15567. lodash.flow = flow;
  15568. lodash.flowRight = flowRight;
  15569. lodash.fromPairs = fromPairs;
  15570. lodash.functions = functions;
  15571. lodash.functionsIn = functionsIn;
  15572. lodash.groupBy = groupBy;
  15573. lodash.initial = initial;
  15574. lodash.intersection = intersection;
  15575. lodash.intersectionBy = intersectionBy;
  15576. lodash.intersectionWith = intersectionWith;
  15577. lodash.invert = invert;
  15578. lodash.invertBy = invertBy;
  15579. lodash.invokeMap = invokeMap;
  15580. lodash.iteratee = iteratee;
  15581. lodash.keyBy = keyBy;
  15582. lodash.keys = keys;
  15583. lodash.keysIn = keysIn;
  15584. lodash.map = map;
  15585. lodash.mapKeys = mapKeys;
  15586. lodash.mapValues = mapValues;
  15587. lodash.matches = matches;
  15588. lodash.matchesProperty = matchesProperty;
  15589. lodash.memoize = memoize;
  15590. lodash.merge = merge;
  15591. lodash.mergeWith = mergeWith;
  15592. lodash.method = method;
  15593. lodash.methodOf = methodOf;
  15594. lodash.mixin = mixin;
  15595. lodash.negate = negate;
  15596. lodash.nthArg = nthArg;
  15597. lodash.omit = omit;
  15598. lodash.omitBy = omitBy;
  15599. lodash.once = once;
  15600. lodash.orderBy = orderBy;
  15601. lodash.over = over;
  15602. lodash.overArgs = overArgs;
  15603. lodash.overEvery = overEvery;
  15604. lodash.overSome = overSome;
  15605. lodash.partial = partial;
  15606. lodash.partialRight = partialRight;
  15607. lodash.partition = partition;
  15608. lodash.pick = pick;
  15609. lodash.pickBy = pickBy;
  15610. lodash.property = property;
  15611. lodash.propertyOf = propertyOf;
  15612. lodash.pull = pull;
  15613. lodash.pullAll = pullAll;
  15614. lodash.pullAllBy = pullAllBy;
  15615. lodash.pullAllWith = pullAllWith;
  15616. lodash.pullAt = pullAt;
  15617. lodash.range = range;
  15618. lodash.rangeRight = rangeRight;
  15619. lodash.rearg = rearg;
  15620. lodash.reject = reject;
  15621. lodash.remove = remove;
  15622. lodash.rest = rest;
  15623. lodash.reverse = reverse;
  15624. lodash.sampleSize = sampleSize;
  15625. lodash.set = set;
  15626. lodash.setWith = setWith;
  15627. lodash.shuffle = shuffle;
  15628. lodash.slice = slice;
  15629. lodash.sortBy = sortBy;
  15630. lodash.sortedUniq = sortedUniq;
  15631. lodash.sortedUniqBy = sortedUniqBy;
  15632. lodash.split = split;
  15633. lodash.spread = spread;
  15634. lodash.tail = tail;
  15635. lodash.take = take;
  15636. lodash.takeRight = takeRight;
  15637. lodash.takeRightWhile = takeRightWhile;
  15638. lodash.takeWhile = takeWhile;
  15639. lodash.tap = tap;
  15640. lodash.throttle = throttle;
  15641. lodash.thru = thru;
  15642. lodash.toArray = toArray;
  15643. lodash.toPairs = toPairs;
  15644. lodash.toPairsIn = toPairsIn;
  15645. lodash.toPath = toPath;
  15646. lodash.toPlainObject = toPlainObject;
  15647. lodash.transform = transform;
  15648. lodash.unary = unary;
  15649. lodash.union = union;
  15650. lodash.unionBy = unionBy;
  15651. lodash.unionWith = unionWith;
  15652. lodash.uniq = uniq;
  15653. lodash.uniqBy = uniqBy;
  15654. lodash.uniqWith = uniqWith;
  15655. lodash.unset = unset;
  15656. lodash.unzip = unzip;
  15657. lodash.unzipWith = unzipWith;
  15658. lodash.update = update;
  15659. lodash.updateWith = updateWith;
  15660. lodash.values = values;
  15661. lodash.valuesIn = valuesIn;
  15662. lodash.without = without;
  15663. lodash.words = words;
  15664. lodash.wrap = wrap;
  15665. lodash.xor = xor;
  15666. lodash.xorBy = xorBy;
  15667. lodash.xorWith = xorWith;
  15668. lodash.zip = zip;
  15669. lodash.zipObject = zipObject;
  15670. lodash.zipObjectDeep = zipObjectDeep;
  15671. lodash.zipWith = zipWith;
  15672. // Add aliases.
  15673. lodash.entries = toPairs;
  15674. lodash.entriesIn = toPairsIn;
  15675. lodash.extend = assignIn;
  15676. lodash.extendWith = assignInWith;
  15677. // Add methods to `lodash.prototype`.
  15678. mixin(lodash, lodash);
  15679. /*------------------------------------------------------------------------*/
  15680. // Add methods that return unwrapped values in chain sequences.
  15681. lodash.add = add;
  15682. lodash.attempt = attempt;
  15683. lodash.camelCase = camelCase;
  15684. lodash.capitalize = capitalize;
  15685. lodash.ceil = ceil;
  15686. lodash.clamp = clamp;
  15687. lodash.clone = clone;
  15688. lodash.cloneDeep = cloneDeep;
  15689. lodash.cloneDeepWith = cloneDeepWith;
  15690. lodash.cloneWith = cloneWith;
  15691. lodash.conformsTo = conformsTo;
  15692. lodash.deburr = deburr;
  15693. lodash.defaultTo = defaultTo;
  15694. lodash.divide = divide;
  15695. lodash.endsWith = endsWith;
  15696. lodash.eq = eq;
  15697. lodash.escape = escape;
  15698. lodash.escapeRegExp = escapeRegExp;
  15699. lodash.every = every;
  15700. lodash.find = find;
  15701. lodash.findIndex = findIndex;
  15702. lodash.findKey = findKey;
  15703. lodash.findLast = findLast;
  15704. lodash.findLastIndex = findLastIndex;
  15705. lodash.findLastKey = findLastKey;
  15706. lodash.floor = floor;
  15707. lodash.forEach = forEach;
  15708. lodash.forEachRight = forEachRight;
  15709. lodash.forIn = forIn;
  15710. lodash.forInRight = forInRight;
  15711. lodash.forOwn = forOwn;
  15712. lodash.forOwnRight = forOwnRight;
  15713. lodash.get = get;
  15714. lodash.gt = gt;
  15715. lodash.gte = gte;
  15716. lodash.has = has;
  15717. lodash.hasIn = hasIn;
  15718. lodash.head = head;
  15719. lodash.identity = identity;
  15720. lodash.includes = includes;
  15721. lodash.indexOf = indexOf;
  15722. lodash.inRange = inRange;
  15723. lodash.invoke = invoke;
  15724. lodash.isArguments = isArguments;
  15725. lodash.isArray = isArray;
  15726. lodash.isArrayBuffer = isArrayBuffer;
  15727. lodash.isArrayLike = isArrayLike;
  15728. lodash.isArrayLikeObject = isArrayLikeObject;
  15729. lodash.isBoolean = isBoolean;
  15730. lodash.isBuffer = isBuffer;
  15731. lodash.isDate = isDate;
  15732. lodash.isElement = isElement;
  15733. lodash.isEmpty = isEmpty;
  15734. lodash.isEqual = isEqual;
  15735. lodash.isEqualWith = isEqualWith;
  15736. lodash.isError = isError;
  15737. lodash.isFinite = isFinite;
  15738. lodash.isFunction = isFunction;
  15739. lodash.isInteger = isInteger;
  15740. lodash.isLength = isLength;
  15741. lodash.isMap = isMap;
  15742. lodash.isMatch = isMatch;
  15743. lodash.isMatchWith = isMatchWith;
  15744. lodash.isNaN = isNaN;
  15745. lodash.isNative = isNative;
  15746. lodash.isNil = isNil;
  15747. lodash.isNull = isNull;
  15748. lodash.isNumber = isNumber;
  15749. lodash.isObject = isObject;
  15750. lodash.isObjectLike = isObjectLike;
  15751. lodash.isPlainObject = isPlainObject;
  15752. lodash.isRegExp = isRegExp;
  15753. lodash.isSafeInteger = isSafeInteger;
  15754. lodash.isSet = isSet;
  15755. lodash.isString = isString;
  15756. lodash.isSymbol = isSymbol;
  15757. lodash.isTypedArray = isTypedArray;
  15758. lodash.isUndefined = isUndefined;
  15759. lodash.isWeakMap = isWeakMap;
  15760. lodash.isWeakSet = isWeakSet;
  15761. lodash.join = join;
  15762. lodash.kebabCase = kebabCase;
  15763. lodash.last = last;
  15764. lodash.lastIndexOf = lastIndexOf;
  15765. lodash.lowerCase = lowerCase;
  15766. lodash.lowerFirst = lowerFirst;
  15767. lodash.lt = lt;
  15768. lodash.lte = lte;
  15769. lodash.max = max;
  15770. lodash.maxBy = maxBy;
  15771. lodash.mean = mean;
  15772. lodash.meanBy = meanBy;
  15773. lodash.min = min;
  15774. lodash.minBy = minBy;
  15775. lodash.stubArray = stubArray;
  15776. lodash.stubFalse = stubFalse;
  15777. lodash.stubObject = stubObject;
  15778. lodash.stubString = stubString;
  15779. lodash.stubTrue = stubTrue;
  15780. lodash.multiply = multiply;
  15781. lodash.nth = nth;
  15782. lodash.noConflict = noConflict;
  15783. lodash.noop = noop;
  15784. lodash.now = now;
  15785. lodash.pad = pad;
  15786. lodash.padEnd = padEnd;
  15787. lodash.padStart = padStart;
  15788. lodash.parseInt = parseInt;
  15789. lodash.random = random;
  15790. lodash.reduce = reduce;
  15791. lodash.reduceRight = reduceRight;
  15792. lodash.repeat = repeat;
  15793. lodash.replace = replace;
  15794. lodash.result = result;
  15795. lodash.round = round;
  15796. lodash.runInContext = runInContext;
  15797. lodash.sample = sample;
  15798. lodash.size = size;
  15799. lodash.snakeCase = snakeCase;
  15800. lodash.some = some;
  15801. lodash.sortedIndex = sortedIndex;
  15802. lodash.sortedIndexBy = sortedIndexBy;
  15803. lodash.sortedIndexOf = sortedIndexOf;
  15804. lodash.sortedLastIndex = sortedLastIndex;
  15805. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15806. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15807. lodash.startCase = startCase;
  15808. lodash.startsWith = startsWith;
  15809. lodash.subtract = subtract;
  15810. lodash.sum = sum;
  15811. lodash.sumBy = sumBy;
  15812. lodash.template = template;
  15813. lodash.times = times;
  15814. lodash.toFinite = toFinite;
  15815. lodash.toInteger = toInteger;
  15816. lodash.toLength = toLength;
  15817. lodash.toLower = toLower;
  15818. lodash.toNumber = toNumber;
  15819. lodash.toSafeInteger = toSafeInteger;
  15820. lodash.toString = toString;
  15821. lodash.toUpper = toUpper;
  15822. lodash.trim = trim;
  15823. lodash.trimEnd = trimEnd;
  15824. lodash.trimStart = trimStart;
  15825. lodash.truncate = truncate;
  15826. lodash.unescape = unescape;
  15827. lodash.uniqueId = uniqueId;
  15828. lodash.upperCase = upperCase;
  15829. lodash.upperFirst = upperFirst;
  15830. // Add aliases.
  15831. lodash.each = forEach;
  15832. lodash.eachRight = forEachRight;
  15833. lodash.first = head;
  15834. mixin(lodash, (function() {
  15835. var source = {};
  15836. baseForOwn(lodash, function(func, methodName) {
  15837. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15838. source[methodName] = func;
  15839. }
  15840. });
  15841. return source;
  15842. }()), { 'chain': false });
  15843. /*------------------------------------------------------------------------*/
  15844. /**
  15845. * The semantic version number.
  15846. *
  15847. * @static
  15848. * @memberOf _
  15849. * @type {string}
  15850. */
  15851. lodash.VERSION = VERSION;
  15852. // Assign default placeholders.
  15853. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15854. lodash[methodName].placeholder = lodash;
  15855. });
  15856. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15857. arrayEach(['drop', 'take'], function(methodName, index) {
  15858. LazyWrapper.prototype[methodName] = function(n) {
  15859. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15860. var result = (this.__filtered__ && !index)
  15861. ? new LazyWrapper(this)
  15862. : this.clone();
  15863. if (result.__filtered__) {
  15864. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15865. } else {
  15866. result.__views__.push({
  15867. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15868. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15869. });
  15870. }
  15871. return result;
  15872. };
  15873. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15874. return this.reverse()[methodName](n).reverse();
  15875. };
  15876. });
  15877. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15878. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15879. var type = index + 1,
  15880. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15881. LazyWrapper.prototype[methodName] = function(iteratee) {
  15882. var result = this.clone();
  15883. result.__iteratees__.push({
  15884. 'iteratee': getIteratee(iteratee, 3),
  15885. 'type': type
  15886. });
  15887. result.__filtered__ = result.__filtered__ || isFilter;
  15888. return result;
  15889. };
  15890. });
  15891. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15892. arrayEach(['head', 'last'], function(methodName, index) {
  15893. var takeName = 'take' + (index ? 'Right' : '');
  15894. LazyWrapper.prototype[methodName] = function() {
  15895. return this[takeName](1).value()[0];
  15896. };
  15897. });
  15898. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15899. arrayEach(['initial', 'tail'], function(methodName, index) {
  15900. var dropName = 'drop' + (index ? '' : 'Right');
  15901. LazyWrapper.prototype[methodName] = function() {
  15902. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15903. };
  15904. });
  15905. LazyWrapper.prototype.compact = function() {
  15906. return this.filter(identity);
  15907. };
  15908. LazyWrapper.prototype.find = function(predicate) {
  15909. return this.filter(predicate).head();
  15910. };
  15911. LazyWrapper.prototype.findLast = function(predicate) {
  15912. return this.reverse().find(predicate);
  15913. };
  15914. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15915. if (typeof path == 'function') {
  15916. return new LazyWrapper(this);
  15917. }
  15918. return this.map(function(value) {
  15919. return baseInvoke(value, path, args);
  15920. });
  15921. });
  15922. LazyWrapper.prototype.reject = function(predicate) {
  15923. return this.filter(negate(getIteratee(predicate)));
  15924. };
  15925. LazyWrapper.prototype.slice = function(start, end) {
  15926. start = toInteger(start);
  15927. var result = this;
  15928. if (result.__filtered__ && (start > 0 || end < 0)) {
  15929. return new LazyWrapper(result);
  15930. }
  15931. if (start < 0) {
  15932. result = result.takeRight(-start);
  15933. } else if (start) {
  15934. result = result.drop(start);
  15935. }
  15936. if (end !== undefined) {
  15937. end = toInteger(end);
  15938. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15939. }
  15940. return result;
  15941. };
  15942. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15943. return this.reverse().takeWhile(predicate).reverse();
  15944. };
  15945. LazyWrapper.prototype.toArray = function() {
  15946. return this.take(MAX_ARRAY_LENGTH);
  15947. };
  15948. // Add `LazyWrapper` methods to `lodash.prototype`.
  15949. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15950. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15951. isTaker = /^(?:head|last)$/.test(methodName),
  15952. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15953. retUnwrapped = isTaker || /^find/.test(methodName);
  15954. if (!lodashFunc) {
  15955. return;
  15956. }
  15957. lodash.prototype[methodName] = function() {
  15958. var value = this.__wrapped__,
  15959. args = isTaker ? [1] : arguments,
  15960. isLazy = value instanceof LazyWrapper,
  15961. iteratee = args[0],
  15962. useLazy = isLazy || isArray(value);
  15963. var interceptor = function(value) {
  15964. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15965. return (isTaker && chainAll) ? result[0] : result;
  15966. };
  15967. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15968. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15969. isLazy = useLazy = false;
  15970. }
  15971. var chainAll = this.__chain__,
  15972. isHybrid = !!this.__actions__.length,
  15973. isUnwrapped = retUnwrapped && !chainAll,
  15974. onlyLazy = isLazy && !isHybrid;
  15975. if (!retUnwrapped && useLazy) {
  15976. value = onlyLazy ? value : new LazyWrapper(this);
  15977. var result = func.apply(value, args);
  15978. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15979. return new LodashWrapper(result, chainAll);
  15980. }
  15981. if (isUnwrapped && onlyLazy) {
  15982. return func.apply(this, args);
  15983. }
  15984. result = this.thru(interceptor);
  15985. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15986. };
  15987. });
  15988. // Add `Array` methods to `lodash.prototype`.
  15989. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15990. var func = arrayProto[methodName],
  15991. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15992. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15993. lodash.prototype[methodName] = function() {
  15994. var args = arguments;
  15995. if (retUnwrapped && !this.__chain__) {
  15996. var value = this.value();
  15997. return func.apply(isArray(value) ? value : [], args);
  15998. }
  15999. return this[chainName](function(value) {
  16000. return func.apply(isArray(value) ? value : [], args);
  16001. });
  16002. };
  16003. });
  16004. // Map minified method names to their real names.
  16005. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16006. var lodashFunc = lodash[methodName];
  16007. if (lodashFunc) {
  16008. var key = lodashFunc.name + '';
  16009. if (!hasOwnProperty.call(realNames, key)) {
  16010. realNames[key] = [];
  16011. }
  16012. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16013. }
  16014. });
  16015. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16016. 'name': 'wrapper',
  16017. 'func': undefined
  16018. }];
  16019. // Add methods to `LazyWrapper`.
  16020. LazyWrapper.prototype.clone = lazyClone;
  16021. LazyWrapper.prototype.reverse = lazyReverse;
  16022. LazyWrapper.prototype.value = lazyValue;
  16023. // Add chain sequence methods to the `lodash` wrapper.
  16024. lodash.prototype.at = wrapperAt;
  16025. lodash.prototype.chain = wrapperChain;
  16026. lodash.prototype.commit = wrapperCommit;
  16027. lodash.prototype.next = wrapperNext;
  16028. lodash.prototype.plant = wrapperPlant;
  16029. lodash.prototype.reverse = wrapperReverse;
  16030. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16031. // Add lazy aliases.
  16032. lodash.prototype.first = lodash.prototype.head;
  16033. if (symIterator) {
  16034. lodash.prototype[symIterator] = wrapperToIterator;
  16035. }
  16036. return lodash;
  16037. });
  16038. /*--------------------------------------------------------------------------*/
  16039. // Export lodash.
  16040. var _ = runInContext();
  16041. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16042. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16043. // Expose Lodash on the global object to prevent errors when Lodash is
  16044. // loaded by a script tag in the presence of an AMD loader.
  16045. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16046. // Use `_.noConflict` to remove Lodash from the global object.
  16047. root._ = _;
  16048. // Define as an anonymous module so, through path mapping, it can be
  16049. // referenced as the "underscore" module.
  16050. define(function() {
  16051. return _;
  16052. });
  16053. }
  16054. // Check for `exports` after `define` in case a build optimizer adds it.
  16055. else if (freeModule) {
  16056. // Export for Node.js.
  16057. (freeModule.exports = _)._ = _;
  16058. // Export for CommonJS support.
  16059. freeExports._ = _;
  16060. }
  16061. else {
  16062. // Export to the global object.
  16063. root._ = _;
  16064. }
  16065. }.call(this));