lodash.js 510 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592
  1. /**
  2. * @license
  3. * lodash <https://lodash.com/>
  4. * Copyright jQuery Foundation and other contributors <https://jquery.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.14.0';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Used as the `TypeError` message for "Functions" methods. */
  17. var FUNC_ERROR_TEXT = 'Expected a function';
  18. /** Used to stand-in for `undefined` hash values. */
  19. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  20. /** Used as the internal argument placeholder. */
  21. var PLACEHOLDER = '__lodash_placeholder__';
  22. /** Used to compose bitmasks for function metadata. */
  23. var BIND_FLAG = 1,
  24. BIND_KEY_FLAG = 2,
  25. CURRY_BOUND_FLAG = 4,
  26. CURRY_FLAG = 8,
  27. CURRY_RIGHT_FLAG = 16,
  28. PARTIAL_FLAG = 32,
  29. PARTIAL_RIGHT_FLAG = 64,
  30. ARY_FLAG = 128,
  31. REARG_FLAG = 256,
  32. FLIP_FLAG = 512;
  33. /** Used to compose bitmasks for comparison styles. */
  34. var UNORDERED_COMPARE_FLAG = 1,
  35. PARTIAL_COMPARE_FLAG = 2;
  36. /** Used as default options for `_.truncate`. */
  37. var DEFAULT_TRUNC_LENGTH = 30,
  38. DEFAULT_TRUNC_OMISSION = '...';
  39. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  40. var HOT_COUNT = 150,
  41. HOT_SPAN = 16;
  42. /** Used to indicate the type of lazy iteratees. */
  43. var LAZY_FILTER_FLAG = 1,
  44. LAZY_MAP_FLAG = 2,
  45. LAZY_WHILE_FLAG = 3;
  46. /** Used as references for various `Number` constants. */
  47. var INFINITY = 1 / 0,
  48. MAX_SAFE_INTEGER = 9007199254740991,
  49. MAX_INTEGER = 1.7976931348623157e+308,
  50. NAN = 0 / 0;
  51. /** Used as references for the maximum length and index of an array. */
  52. var MAX_ARRAY_LENGTH = 4294967295,
  53. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  54. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  55. /** Used to associate wrap methods with their bit flags. */
  56. var wrapFlags = [
  57. ['ary', ARY_FLAG],
  58. ['bind', BIND_FLAG],
  59. ['bindKey', BIND_KEY_FLAG],
  60. ['curry', CURRY_FLAG],
  61. ['curryRight', CURRY_RIGHT_FLAG],
  62. ['flip', FLIP_FLAG],
  63. ['partial', PARTIAL_FLAG],
  64. ['partialRight', PARTIAL_RIGHT_FLAG],
  65. ['rearg', REARG_FLAG]
  66. ];
  67. /** `Object#toString` result references. */
  68. var argsTag = '[object Arguments]',
  69. arrayTag = '[object Array]',
  70. boolTag = '[object Boolean]',
  71. dateTag = '[object Date]',
  72. errorTag = '[object Error]',
  73. funcTag = '[object Function]',
  74. genTag = '[object GeneratorFunction]',
  75. mapTag = '[object Map]',
  76. numberTag = '[object Number]',
  77. objectTag = '[object Object]',
  78. promiseTag = '[object Promise]',
  79. regexpTag = '[object RegExp]',
  80. setTag = '[object Set]',
  81. stringTag = '[object String]',
  82. symbolTag = '[object Symbol]',
  83. weakMapTag = '[object WeakMap]',
  84. weakSetTag = '[object WeakSet]';
  85. var arrayBufferTag = '[object ArrayBuffer]',
  86. dataViewTag = '[object DataView]',
  87. float32Tag = '[object Float32Array]',
  88. float64Tag = '[object Float64Array]',
  89. int8Tag = '[object Int8Array]',
  90. int16Tag = '[object Int16Array]',
  91. int32Tag = '[object Int32Array]',
  92. uint8Tag = '[object Uint8Array]',
  93. uint8ClampedTag = '[object Uint8ClampedArray]',
  94. uint16Tag = '[object Uint16Array]',
  95. uint32Tag = '[object Uint32Array]';
  96. /** Used to match empty string literals in compiled template source. */
  97. var reEmptyStringLeading = /\b__p \+= '';/g,
  98. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  99. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  100. /** Used to match HTML entities and HTML characters. */
  101. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  102. reUnescapedHtml = /[&<>"'`]/g,
  103. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  104. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  105. /** Used to match template delimiters. */
  106. var reEscape = /<%-([\s\S]+?)%>/g,
  107. reEvaluate = /<%([\s\S]+?)%>/g,
  108. reInterpolate = /<%=([\s\S]+?)%>/g;
  109. /** Used to match property names within property paths. */
  110. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  111. reIsPlainProp = /^\w*$/,
  112. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(\.|\[\])(?:\4|$))/g;
  113. /**
  114. * Used to match `RegExp`
  115. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  116. */
  117. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  118. reHasRegExpChar = RegExp(reRegExpChar.source);
  119. /** Used to match leading and trailing whitespace. */
  120. var reTrim = /^\s+|\s+$/g,
  121. reTrimStart = /^\s+/,
  122. reTrimEnd = /\s+$/;
  123. /** Used to match wrap detail comments. */
  124. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  125. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  126. reSplitDetails = /,? & /;
  127. /** Used to match non-compound words composed of alphanumeric characters. */
  128. var reBasicWord = /[a-zA-Z0-9]+/g;
  129. /** Used to match backslashes in property paths. */
  130. var reEscapeChar = /\\(\\)?/g;
  131. /**
  132. * Used to match
  133. * [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components).
  134. */
  135. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  136. /** Used to match `RegExp` flags from their coerced string values. */
  137. var reFlags = /\w*$/;
  138. /** Used to detect hexadecimal string values. */
  139. var reHasHexPrefix = /^0x/i;
  140. /** Used to detect bad signed hexadecimal string values. */
  141. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  142. /** Used to detect binary string values. */
  143. var reIsBinary = /^0b[01]+$/i;
  144. /** Used to detect host constructors (Safari). */
  145. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  146. /** Used to detect octal string values. */
  147. var reIsOctal = /^0o[0-7]+$/i;
  148. /** Used to detect unsigned integer values. */
  149. var reIsUint = /^(?:0|[1-9]\d*)$/;
  150. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  151. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  152. /** Used to ensure capturing order of template delimiters. */
  153. var reNoMatch = /($^)/;
  154. /** Used to match unescaped characters in compiled string literals. */
  155. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  156. /** Used to compose unicode character classes. */
  157. var rsAstralRange = '\\ud800-\\udfff',
  158. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  159. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  160. rsDingbatRange = '\\u2700-\\u27bf',
  161. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  162. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  163. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  164. rsPunctuationRange = '\\u2000-\\u206f',
  165. 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',
  166. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  167. rsVarRange = '\\ufe0e\\ufe0f',
  168. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  169. /** Used to compose unicode capture groups. */
  170. var rsApos = "['\u2019]",
  171. rsAstral = '[' + rsAstralRange + ']',
  172. rsBreak = '[' + rsBreakRange + ']',
  173. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  174. rsDigits = '\\d+',
  175. rsDingbat = '[' + rsDingbatRange + ']',
  176. rsLower = '[' + rsLowerRange + ']',
  177. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  178. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  179. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  180. rsNonAstral = '[^' + rsAstralRange + ']',
  181. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  182. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  183. rsUpper = '[' + rsUpperRange + ']',
  184. rsZWJ = '\\u200d';
  185. /** Used to compose unicode regexes. */
  186. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  187. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  188. rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  189. rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  190. reOptMod = rsModifier + '?',
  191. rsOptVar = '[' + rsVarRange + ']?',
  192. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  193. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  194. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  195. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  196. /** Used to match apostrophes. */
  197. var reApos = RegExp(rsApos, 'g');
  198. /**
  199. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  200. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  201. */
  202. var reComboMark = RegExp(rsCombo, 'g');
  203. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  204. var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  205. /** Used to match complex or compound words. */
  206. var reComplexWord = RegExp([
  207. rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  208. rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  209. rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
  210. rsUpper + '+' + rsOptUpperContr,
  211. rsDigits,
  212. rsEmoji
  213. ].join('|'), 'g');
  214. /** 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/). */
  215. var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  216. /** Used to detect strings that need a more robust regexp to match words. */
  217. var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  218. /** Used to assign default `context` object properties. */
  219. var contextProps = [
  220. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  221. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  222. 'Promise', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError',
  223. 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  224. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  225. ];
  226. /** Used to make template sourceURLs easier to identify. */
  227. var templateCounter = -1;
  228. /** Used to identify `toStringTag` values of typed arrays. */
  229. var typedArrayTags = {};
  230. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  231. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  232. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  233. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  234. typedArrayTags[uint32Tag] = true;
  235. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  236. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  237. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  238. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  239. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  240. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  241. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  242. typedArrayTags[weakMapTag] = false;
  243. /** Used to identify `toStringTag` values supported by `_.clone`. */
  244. var cloneableTags = {};
  245. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  246. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  247. cloneableTags[boolTag] = cloneableTags[dateTag] =
  248. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  249. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  250. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  251. cloneableTags[numberTag] = cloneableTags[objectTag] =
  252. cloneableTags[regexpTag] = cloneableTags[setTag] =
  253. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  254. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  255. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  256. cloneableTags[errorTag] = cloneableTags[funcTag] =
  257. cloneableTags[weakMapTag] = false;
  258. /** Used to map latin-1 supplementary letters to basic latin letters. */
  259. var deburredLetters = {
  260. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  261. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  262. '\xc7': 'C', '\xe7': 'c',
  263. '\xd0': 'D', '\xf0': 'd',
  264. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  265. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  266. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  267. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  268. '\xd1': 'N', '\xf1': 'n',
  269. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  270. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  271. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  272. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  273. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  274. '\xc6': 'Ae', '\xe6': 'ae',
  275. '\xde': 'Th', '\xfe': 'th',
  276. '\xdf': 'ss'
  277. };
  278. /** Used to map characters to HTML entities. */
  279. var htmlEscapes = {
  280. '&': '&amp;',
  281. '<': '&lt;',
  282. '>': '&gt;',
  283. '"': '&quot;',
  284. "'": '&#39;',
  285. '`': '&#96;'
  286. };
  287. /** Used to map HTML entities to characters. */
  288. var htmlUnescapes = {
  289. '&amp;': '&',
  290. '&lt;': '<',
  291. '&gt;': '>',
  292. '&quot;': '"',
  293. '&#39;': "'",
  294. '&#96;': '`'
  295. };
  296. /** Used to escape characters for inclusion in compiled string literals. */
  297. var stringEscapes = {
  298. '\\': '\\',
  299. "'": "'",
  300. '\n': 'n',
  301. '\r': 'r',
  302. '\u2028': 'u2028',
  303. '\u2029': 'u2029'
  304. };
  305. /** Built-in method references without a dependency on `root`. */
  306. var freeParseFloat = parseFloat,
  307. freeParseInt = parseInt;
  308. /** Detect free variable `global` from Node.js. */
  309. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  310. /** Detect free variable `self`. */
  311. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  312. /** Used as a reference to the global object. */
  313. var root = freeGlobal || freeSelf || Function('return this')();
  314. /** Detect free variable `exports`. */
  315. var freeExports = freeGlobal && typeof exports == 'object' && exports;
  316. /** Detect free variable `module`. */
  317. var freeModule = freeExports && typeof module == 'object' && module;
  318. /** Detect the popular CommonJS extension `module.exports`. */
  319. var moduleExports = freeModule && freeModule.exports === freeExports;
  320. /** Detect free variable `process` from Node.js. */
  321. var freeProcess = moduleExports && freeGlobal.process;
  322. /** Used to access faster Node.js helpers. */
  323. var nodeUtil = (function() {
  324. try {
  325. return freeProcess && freeProcess.binding('util');
  326. } catch (e) {}
  327. }());
  328. /* Node.js helper references. */
  329. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  330. nodeIsDate = nodeUtil && nodeUtil.isDate,
  331. nodeIsMap = nodeUtil && nodeUtil.isMap,
  332. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  333. nodeIsSet = nodeUtil && nodeUtil.isSet,
  334. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  335. /*--------------------------------------------------------------------------*/
  336. /**
  337. * Adds the key-value `pair` to `map`.
  338. *
  339. * @private
  340. * @param {Object} map The map to modify.
  341. * @param {Array} pair The key-value pair to add.
  342. * @returns {Object} Returns `map`.
  343. */
  344. function addMapEntry(map, pair) {
  345. // Don't return `map.set` because it's not chainable in IE 11.
  346. map.set(pair[0], pair[1]);
  347. return map;
  348. }
  349. /**
  350. * Adds `value` to `set`.
  351. *
  352. * @private
  353. * @param {Object} set The set to modify.
  354. * @param {*} value The value to add.
  355. * @returns {Object} Returns `set`.
  356. */
  357. function addSetEntry(set, value) {
  358. // Don't return `set.add` because it's not chainable in IE 11.
  359. set.add(value);
  360. return set;
  361. }
  362. /**
  363. * A faster alternative to `Function#apply`, this function invokes `func`
  364. * with the `this` binding of `thisArg` and the arguments of `args`.
  365. *
  366. * @private
  367. * @param {Function} func The function to invoke.
  368. * @param {*} thisArg The `this` binding of `func`.
  369. * @param {Array} args The arguments to invoke `func` with.
  370. * @returns {*} Returns the result of `func`.
  371. */
  372. function apply(func, thisArg, args) {
  373. switch (args.length) {
  374. case 0: return func.call(thisArg);
  375. case 1: return func.call(thisArg, args[0]);
  376. case 2: return func.call(thisArg, args[0], args[1]);
  377. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  378. }
  379. return func.apply(thisArg, args);
  380. }
  381. /**
  382. * A specialized version of `baseAggregator` for arrays.
  383. *
  384. * @private
  385. * @param {Array} [array] The array to iterate over.
  386. * @param {Function} setter The function to set `accumulator` values.
  387. * @param {Function} iteratee The iteratee to transform keys.
  388. * @param {Object} accumulator The initial aggregated object.
  389. * @returns {Function} Returns `accumulator`.
  390. */
  391. function arrayAggregator(array, setter, iteratee, accumulator) {
  392. var index = -1,
  393. length = array ? array.length : 0;
  394. while (++index < length) {
  395. var value = array[index];
  396. setter(accumulator, value, iteratee(value), array);
  397. }
  398. return accumulator;
  399. }
  400. /**
  401. * A specialized version of `_.forEach` for arrays without support for
  402. * iteratee shorthands.
  403. *
  404. * @private
  405. * @param {Array} [array] The array to iterate over.
  406. * @param {Function} iteratee The function invoked per iteration.
  407. * @returns {Array} Returns `array`.
  408. */
  409. function arrayEach(array, iteratee) {
  410. var index = -1,
  411. length = array ? array.length : 0;
  412. while (++index < length) {
  413. if (iteratee(array[index], index, array) === false) {
  414. break;
  415. }
  416. }
  417. return array;
  418. }
  419. /**
  420. * A specialized version of `_.forEachRight` for arrays without support for
  421. * iteratee shorthands.
  422. *
  423. * @private
  424. * @param {Array} [array] The array to iterate over.
  425. * @param {Function} iteratee The function invoked per iteration.
  426. * @returns {Array} Returns `array`.
  427. */
  428. function arrayEachRight(array, iteratee) {
  429. var length = array ? array.length : 0;
  430. while (length--) {
  431. if (iteratee(array[length], length, array) === false) {
  432. break;
  433. }
  434. }
  435. return array;
  436. }
  437. /**
  438. * A specialized version of `_.every` for arrays without support for
  439. * iteratee shorthands.
  440. *
  441. * @private
  442. * @param {Array} [array] The array to iterate over.
  443. * @param {Function} predicate The function invoked per iteration.
  444. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  445. * else `false`.
  446. */
  447. function arrayEvery(array, predicate) {
  448. var index = -1,
  449. length = array ? array.length : 0;
  450. while (++index < length) {
  451. if (!predicate(array[index], index, array)) {
  452. return false;
  453. }
  454. }
  455. return true;
  456. }
  457. /**
  458. * A specialized version of `_.filter` for arrays without support for
  459. * iteratee shorthands.
  460. *
  461. * @private
  462. * @param {Array} [array] The array to iterate over.
  463. * @param {Function} predicate The function invoked per iteration.
  464. * @returns {Array} Returns the new filtered array.
  465. */
  466. function arrayFilter(array, predicate) {
  467. var index = -1,
  468. length = array ? array.length : 0,
  469. resIndex = 0,
  470. result = [];
  471. while (++index < length) {
  472. var value = array[index];
  473. if (predicate(value, index, array)) {
  474. result[resIndex++] = value;
  475. }
  476. }
  477. return result;
  478. }
  479. /**
  480. * A specialized version of `_.includes` for arrays without support for
  481. * specifying an index to search from.
  482. *
  483. * @private
  484. * @param {Array} [array] The array to search.
  485. * @param {*} target The value to search for.
  486. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  487. */
  488. function arrayIncludes(array, value) {
  489. var length = array ? array.length : 0;
  490. return !!length && baseIndexOf(array, value, 0) > -1;
  491. }
  492. /**
  493. * This function is like `arrayIncludes` except that it accepts a comparator.
  494. *
  495. * @private
  496. * @param {Array} [array] The array to search.
  497. * @param {*} target The value to search for.
  498. * @param {Function} comparator The comparator invoked per element.
  499. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  500. */
  501. function arrayIncludesWith(array, value, comparator) {
  502. var index = -1,
  503. length = array ? array.length : 0;
  504. while (++index < length) {
  505. if (comparator(value, array[index])) {
  506. return true;
  507. }
  508. }
  509. return false;
  510. }
  511. /**
  512. * A specialized version of `_.map` for arrays without support for iteratee
  513. * shorthands.
  514. *
  515. * @private
  516. * @param {Array} [array] The array to iterate over.
  517. * @param {Function} iteratee The function invoked per iteration.
  518. * @returns {Array} Returns the new mapped array.
  519. */
  520. function arrayMap(array, iteratee) {
  521. var index = -1,
  522. length = array ? array.length : 0,
  523. result = Array(length);
  524. while (++index < length) {
  525. result[index] = iteratee(array[index], index, array);
  526. }
  527. return result;
  528. }
  529. /**
  530. * Appends the elements of `values` to `array`.
  531. *
  532. * @private
  533. * @param {Array} array The array to modify.
  534. * @param {Array} values The values to append.
  535. * @returns {Array} Returns `array`.
  536. */
  537. function arrayPush(array, values) {
  538. var index = -1,
  539. length = values.length,
  540. offset = array.length;
  541. while (++index < length) {
  542. array[offset + index] = values[index];
  543. }
  544. return array;
  545. }
  546. /**
  547. * A specialized version of `_.reduce` for arrays without support for
  548. * iteratee shorthands.
  549. *
  550. * @private
  551. * @param {Array} [array] The array to iterate over.
  552. * @param {Function} iteratee The function invoked per iteration.
  553. * @param {*} [accumulator] The initial value.
  554. * @param {boolean} [initAccum] Specify using the first element of `array` as
  555. * the initial value.
  556. * @returns {*} Returns the accumulated value.
  557. */
  558. function arrayReduce(array, iteratee, accumulator, initAccum) {
  559. var index = -1,
  560. length = array ? array.length : 0;
  561. if (initAccum && length) {
  562. accumulator = array[++index];
  563. }
  564. while (++index < length) {
  565. accumulator = iteratee(accumulator, array[index], index, array);
  566. }
  567. return accumulator;
  568. }
  569. /**
  570. * A specialized version of `_.reduceRight` for arrays without support for
  571. * iteratee shorthands.
  572. *
  573. * @private
  574. * @param {Array} [array] The array to iterate over.
  575. * @param {Function} iteratee The function invoked per iteration.
  576. * @param {*} [accumulator] The initial value.
  577. * @param {boolean} [initAccum] Specify using the last element of `array` as
  578. * the initial value.
  579. * @returns {*} Returns the accumulated value.
  580. */
  581. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  582. var length = array ? array.length : 0;
  583. if (initAccum && length) {
  584. accumulator = array[--length];
  585. }
  586. while (length--) {
  587. accumulator = iteratee(accumulator, array[length], length, array);
  588. }
  589. return accumulator;
  590. }
  591. /**
  592. * A specialized version of `_.some` for arrays without support for iteratee
  593. * shorthands.
  594. *
  595. * @private
  596. * @param {Array} [array] The array to iterate over.
  597. * @param {Function} predicate The function invoked per iteration.
  598. * @returns {boolean} Returns `true` if any element passes the predicate check,
  599. * else `false`.
  600. */
  601. function arraySome(array, predicate) {
  602. var index = -1,
  603. length = array ? array.length : 0;
  604. while (++index < length) {
  605. if (predicate(array[index], index, array)) {
  606. return true;
  607. }
  608. }
  609. return false;
  610. }
  611. /**
  612. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  613. * without support for iteratee shorthands, which iterates over `collection`
  614. * using `eachFunc`.
  615. *
  616. * @private
  617. * @param {Array|Object} collection The collection to search.
  618. * @param {Function} predicate The function invoked per iteration.
  619. * @param {Function} eachFunc The function to iterate over `collection`.
  620. * @returns {*} Returns the found element or its key, else `undefined`.
  621. */
  622. function baseFindKey(collection, predicate, eachFunc) {
  623. var result;
  624. eachFunc(collection, function(value, key, collection) {
  625. if (predicate(value, key, collection)) {
  626. result = key;
  627. return false;
  628. }
  629. });
  630. return result;
  631. }
  632. /**
  633. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  634. * support for iteratee shorthands.
  635. *
  636. * @private
  637. * @param {Array} array The array to search.
  638. * @param {Function} predicate The function invoked per iteration.
  639. * @param {number} fromIndex The index to search from.
  640. * @param {boolean} [fromRight] Specify iterating from right to left.
  641. * @returns {number} Returns the index of the matched value, else `-1`.
  642. */
  643. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  644. var length = array.length,
  645. index = fromIndex + (fromRight ? 1 : -1);
  646. while ((fromRight ? index-- : ++index < length)) {
  647. if (predicate(array[index], index, array)) {
  648. return index;
  649. }
  650. }
  651. return -1;
  652. }
  653. /**
  654. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  655. *
  656. * @private
  657. * @param {Array} array The array to search.
  658. * @param {*} value The value to search for.
  659. * @param {number} fromIndex The index to search from.
  660. * @returns {number} Returns the index of the matched value, else `-1`.
  661. */
  662. function baseIndexOf(array, value, fromIndex) {
  663. if (value !== value) {
  664. return baseFindIndex(array, baseIsNaN, fromIndex);
  665. }
  666. var index = fromIndex - 1,
  667. length = array.length;
  668. while (++index < length) {
  669. if (array[index] === value) {
  670. return index;
  671. }
  672. }
  673. return -1;
  674. }
  675. /**
  676. * This function is like `baseIndexOf` except that it accepts a comparator.
  677. *
  678. * @private
  679. * @param {Array} array The array to search.
  680. * @param {*} value The value to search for.
  681. * @param {number} fromIndex The index to search from.
  682. * @param {Function} comparator The comparator invoked per element.
  683. * @returns {number} Returns the index of the matched value, else `-1`.
  684. */
  685. function baseIndexOfWith(array, value, fromIndex, comparator) {
  686. var index = fromIndex - 1,
  687. length = array.length;
  688. while (++index < length) {
  689. if (comparator(array[index], value)) {
  690. return index;
  691. }
  692. }
  693. return -1;
  694. }
  695. /**
  696. * The base implementation of `_.isNaN` without support for number objects.
  697. *
  698. * @private
  699. * @param {*} value The value to check.
  700. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  701. */
  702. function baseIsNaN(value) {
  703. return value !== value;
  704. }
  705. /**
  706. * The base implementation of `_.mean` and `_.meanBy` without support for
  707. * iteratee shorthands.
  708. *
  709. * @private
  710. * @param {Array} array The array to iterate over.
  711. * @param {Function} iteratee The function invoked per iteration.
  712. * @returns {number} Returns the mean.
  713. */
  714. function baseMean(array, iteratee) {
  715. var length = array ? array.length : 0;
  716. return length ? (baseSum(array, iteratee) / length) : NAN;
  717. }
  718. /**
  719. * The base implementation of `_.property` without support for deep paths.
  720. *
  721. * @private
  722. * @param {string} key The key of the property to get.
  723. * @returns {Function} Returns the new accessor function.
  724. */
  725. function baseProperty(key) {
  726. return function(object) {
  727. return object == null ? undefined : object[key];
  728. };
  729. }
  730. /**
  731. * The base implementation of `_.propertyOf` without support for deep paths.
  732. *
  733. * @private
  734. * @param {Object} object The object to query.
  735. * @returns {Function} Returns the new accessor function.
  736. */
  737. function basePropertyOf(object) {
  738. return function(key) {
  739. return object == null ? undefined : object[key];
  740. };
  741. }
  742. /**
  743. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  744. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  745. *
  746. * @private
  747. * @param {Array|Object} collection The collection to iterate over.
  748. * @param {Function} iteratee The function invoked per iteration.
  749. * @param {*} accumulator The initial value.
  750. * @param {boolean} initAccum Specify using the first or last element of
  751. * `collection` as the initial value.
  752. * @param {Function} eachFunc The function to iterate over `collection`.
  753. * @returns {*} Returns the accumulated value.
  754. */
  755. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  756. eachFunc(collection, function(value, index, collection) {
  757. accumulator = initAccum
  758. ? (initAccum = false, value)
  759. : iteratee(accumulator, value, index, collection);
  760. });
  761. return accumulator;
  762. }
  763. /**
  764. * The base implementation of `_.sortBy` which uses `comparer` to define the
  765. * sort order of `array` and replaces criteria objects with their corresponding
  766. * values.
  767. *
  768. * @private
  769. * @param {Array} array The array to sort.
  770. * @param {Function} comparer The function to define sort order.
  771. * @returns {Array} Returns `array`.
  772. */
  773. function baseSortBy(array, comparer) {
  774. var length = array.length;
  775. array.sort(comparer);
  776. while (length--) {
  777. array[length] = array[length].value;
  778. }
  779. return array;
  780. }
  781. /**
  782. * The base implementation of `_.sum` and `_.sumBy` without support for
  783. * iteratee shorthands.
  784. *
  785. * @private
  786. * @param {Array} array The array to iterate over.
  787. * @param {Function} iteratee The function invoked per iteration.
  788. * @returns {number} Returns the sum.
  789. */
  790. function baseSum(array, iteratee) {
  791. var result,
  792. index = -1,
  793. length = array.length;
  794. while (++index < length) {
  795. var current = iteratee(array[index]);
  796. if (current !== undefined) {
  797. result = result === undefined ? current : (result + current);
  798. }
  799. }
  800. return result;
  801. }
  802. /**
  803. * The base implementation of `_.times` without support for iteratee shorthands
  804. * or max array length checks.
  805. *
  806. * @private
  807. * @param {number} n The number of times to invoke `iteratee`.
  808. * @param {Function} iteratee The function invoked per iteration.
  809. * @returns {Array} Returns the array of results.
  810. */
  811. function baseTimes(n, iteratee) {
  812. var index = -1,
  813. result = Array(n);
  814. while (++index < n) {
  815. result[index] = iteratee(index);
  816. }
  817. return result;
  818. }
  819. /**
  820. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  821. * of key-value pairs for `object` corresponding to the property names of `props`.
  822. *
  823. * @private
  824. * @param {Object} object The object to query.
  825. * @param {Array} props The property names to get values for.
  826. * @returns {Object} Returns the key-value pairs.
  827. */
  828. function baseToPairs(object, props) {
  829. return arrayMap(props, function(key) {
  830. return [key, object[key]];
  831. });
  832. }
  833. /**
  834. * The base implementation of `_.unary` without support for storing metadata.
  835. *
  836. * @private
  837. * @param {Function} func The function to cap arguments for.
  838. * @returns {Function} Returns the new capped function.
  839. */
  840. function baseUnary(func) {
  841. return function(value) {
  842. return func(value);
  843. };
  844. }
  845. /**
  846. * The base implementation of `_.values` and `_.valuesIn` which creates an
  847. * array of `object` property values corresponding to the property names
  848. * of `props`.
  849. *
  850. * @private
  851. * @param {Object} object The object to query.
  852. * @param {Array} props The property names to get values for.
  853. * @returns {Object} Returns the array of property values.
  854. */
  855. function baseValues(object, props) {
  856. return arrayMap(props, function(key) {
  857. return object[key];
  858. });
  859. }
  860. /**
  861. * Checks if a cache value for `key` exists.
  862. *
  863. * @private
  864. * @param {Object} cache The cache to query.
  865. * @param {string} key The key of the entry to check.
  866. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  867. */
  868. function cacheHas(cache, key) {
  869. return cache.has(key);
  870. }
  871. /**
  872. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  873. * that is not found in the character symbols.
  874. *
  875. * @private
  876. * @param {Array} strSymbols The string symbols to inspect.
  877. * @param {Array} chrSymbols The character symbols to find.
  878. * @returns {number} Returns the index of the first unmatched string symbol.
  879. */
  880. function charsStartIndex(strSymbols, chrSymbols) {
  881. var index = -1,
  882. length = strSymbols.length;
  883. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  884. return index;
  885. }
  886. /**
  887. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  888. * that is not found in the character symbols.
  889. *
  890. * @private
  891. * @param {Array} strSymbols The string symbols to inspect.
  892. * @param {Array} chrSymbols The character symbols to find.
  893. * @returns {number} Returns the index of the last unmatched string symbol.
  894. */
  895. function charsEndIndex(strSymbols, chrSymbols) {
  896. var index = strSymbols.length;
  897. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  898. return index;
  899. }
  900. /**
  901. * Gets the number of `placeholder` occurrences in `array`.
  902. *
  903. * @private
  904. * @param {Array} array The array to inspect.
  905. * @param {*} placeholder The placeholder to search for.
  906. * @returns {number} Returns the placeholder count.
  907. */
  908. function countHolders(array, placeholder) {
  909. var length = array.length,
  910. result = 0;
  911. while (length--) {
  912. if (array[length] === placeholder) {
  913. result++;
  914. }
  915. }
  916. return result;
  917. }
  918. /**
  919. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  920. *
  921. * @private
  922. * @param {string} letter The matched letter to deburr.
  923. * @returns {string} Returns the deburred letter.
  924. */
  925. var deburrLetter = basePropertyOf(deburredLetters);
  926. /**
  927. * Used by `_.escape` to convert characters to HTML entities.
  928. *
  929. * @private
  930. * @param {string} chr The matched character to escape.
  931. * @returns {string} Returns the escaped character.
  932. */
  933. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  934. /**
  935. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  936. *
  937. * @private
  938. * @param {string} chr The matched character to escape.
  939. * @returns {string} Returns the escaped character.
  940. */
  941. function escapeStringChar(chr) {
  942. return '\\' + stringEscapes[chr];
  943. }
  944. /**
  945. * Gets the value at `key` of `object`.
  946. *
  947. * @private
  948. * @param {Object} [object] The object to query.
  949. * @param {string} key The key of the property to get.
  950. * @returns {*} Returns the property value.
  951. */
  952. function getValue(object, key) {
  953. return object == null ? undefined : object[key];
  954. }
  955. /**
  956. * Checks if `value` is a host object in IE < 9.
  957. *
  958. * @private
  959. * @param {*} value The value to check.
  960. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  961. */
  962. function isHostObject(value) {
  963. // Many host objects are `Object` objects that can coerce to strings
  964. // despite having improperly defined `toString` methods.
  965. var result = false;
  966. if (value != null && typeof value.toString != 'function') {
  967. try {
  968. result = !!(value + '');
  969. } catch (e) {}
  970. }
  971. return result;
  972. }
  973. /**
  974. * Converts `iterator` to an array.
  975. *
  976. * @private
  977. * @param {Object} iterator The iterator to convert.
  978. * @returns {Array} Returns the converted array.
  979. */
  980. function iteratorToArray(iterator) {
  981. var data,
  982. result = [];
  983. while (!(data = iterator.next()).done) {
  984. result.push(data.value);
  985. }
  986. return result;
  987. }
  988. /**
  989. * Converts `map` to its key-value pairs.
  990. *
  991. * @private
  992. * @param {Object} map The map to convert.
  993. * @returns {Array} Returns the key-value pairs.
  994. */
  995. function mapToArray(map) {
  996. var index = -1,
  997. result = Array(map.size);
  998. map.forEach(function(value, key) {
  999. result[++index] = [key, value];
  1000. });
  1001. return result;
  1002. }
  1003. /**
  1004. * Creates a function that invokes `func` with its first argument transformed.
  1005. *
  1006. * @private
  1007. * @param {Function} func The function to wrap.
  1008. * @param {Function} transform The argument transform.
  1009. * @returns {Function} Returns the new function.
  1010. */
  1011. function overArg(func, transform) {
  1012. return function(arg) {
  1013. return func(transform(arg));
  1014. };
  1015. }
  1016. /**
  1017. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1018. * and returns an array of their indexes.
  1019. *
  1020. * @private
  1021. * @param {Array} array The array to modify.
  1022. * @param {*} placeholder The placeholder to replace.
  1023. * @returns {Array} Returns the new array of placeholder indexes.
  1024. */
  1025. function replaceHolders(array, placeholder) {
  1026. var index = -1,
  1027. length = array.length,
  1028. resIndex = 0,
  1029. result = [];
  1030. while (++index < length) {
  1031. var value = array[index];
  1032. if (value === placeholder || value === PLACEHOLDER) {
  1033. array[index] = PLACEHOLDER;
  1034. result[resIndex++] = index;
  1035. }
  1036. }
  1037. return result;
  1038. }
  1039. /**
  1040. * Converts `set` to an array of its values.
  1041. *
  1042. * @private
  1043. * @param {Object} set The set to convert.
  1044. * @returns {Array} Returns the values.
  1045. */
  1046. function setToArray(set) {
  1047. var index = -1,
  1048. result = Array(set.size);
  1049. set.forEach(function(value) {
  1050. result[++index] = value;
  1051. });
  1052. return result;
  1053. }
  1054. /**
  1055. * Converts `set` to its value-value pairs.
  1056. *
  1057. * @private
  1058. * @param {Object} set The set to convert.
  1059. * @returns {Array} Returns the value-value pairs.
  1060. */
  1061. function setToPairs(set) {
  1062. var index = -1,
  1063. result = Array(set.size);
  1064. set.forEach(function(value) {
  1065. result[++index] = [value, value];
  1066. });
  1067. return result;
  1068. }
  1069. /**
  1070. * Gets the number of symbols in `string`.
  1071. *
  1072. * @private
  1073. * @param {string} string The string to inspect.
  1074. * @returns {number} Returns the string size.
  1075. */
  1076. function stringSize(string) {
  1077. if (!(string && reHasComplexSymbol.test(string))) {
  1078. return string.length;
  1079. }
  1080. var result = reComplexSymbol.lastIndex = 0;
  1081. while (reComplexSymbol.test(string)) {
  1082. result++;
  1083. }
  1084. return result;
  1085. }
  1086. /**
  1087. * Converts `string` to an array.
  1088. *
  1089. * @private
  1090. * @param {string} string The string to convert.
  1091. * @returns {Array} Returns the converted array.
  1092. */
  1093. function stringToArray(string) {
  1094. return string.match(reComplexSymbol);
  1095. }
  1096. /**
  1097. * Used by `_.unescape` to convert HTML entities to characters.
  1098. *
  1099. * @private
  1100. * @param {string} chr The matched character to unescape.
  1101. * @returns {string} Returns the unescaped character.
  1102. */
  1103. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1104. /*--------------------------------------------------------------------------*/
  1105. /**
  1106. * Create a new pristine `lodash` function using the `context` object.
  1107. *
  1108. * @static
  1109. * @memberOf _
  1110. * @since 1.1.0
  1111. * @category Util
  1112. * @param {Object} [context=root] The context object.
  1113. * @returns {Function} Returns a new `lodash` function.
  1114. * @example
  1115. *
  1116. * _.mixin({ 'foo': _.constant('foo') });
  1117. *
  1118. * var lodash = _.runInContext();
  1119. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1120. *
  1121. * _.isFunction(_.foo);
  1122. * // => true
  1123. * _.isFunction(_.bar);
  1124. * // => false
  1125. *
  1126. * lodash.isFunction(lodash.foo);
  1127. * // => false
  1128. * lodash.isFunction(lodash.bar);
  1129. * // => true
  1130. *
  1131. * // Use `context` to stub `Date#getTime` use in `_.now`.
  1132. * var stubbed = _.runInContext({
  1133. * 'Date': function() {
  1134. * return { 'getTime': stubGetTime };
  1135. * }
  1136. * });
  1137. *
  1138. * // Create a suped-up `defer` in Node.js.
  1139. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1140. */
  1141. function runInContext(context) {
  1142. context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
  1143. /** Built-in constructor references. */
  1144. var Array = context.Array,
  1145. Date = context.Date,
  1146. Error = context.Error,
  1147. Math = context.Math,
  1148. RegExp = context.RegExp,
  1149. TypeError = context.TypeError;
  1150. /** Used for built-in method references. */
  1151. var arrayProto = context.Array.prototype,
  1152. objectProto = context.Object.prototype,
  1153. stringProto = context.String.prototype;
  1154. /** Used to detect overreaching core-js shims. */
  1155. var coreJsData = context['__core-js_shared__'];
  1156. /** Used to detect methods masquerading as native. */
  1157. var maskSrcKey = (function() {
  1158. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1159. return uid ? ('Symbol(src)_1.' + uid) : '';
  1160. }());
  1161. /** Used to resolve the decompiled source of functions. */
  1162. var funcToString = context.Function.prototype.toString;
  1163. /** Used to check objects for own properties. */
  1164. var hasOwnProperty = objectProto.hasOwnProperty;
  1165. /** Used to generate unique IDs. */
  1166. var idCounter = 0;
  1167. /** Used to infer the `Object` constructor. */
  1168. var objectCtorString = funcToString.call(Object);
  1169. /**
  1170. * Used to resolve the
  1171. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1172. * of values.
  1173. */
  1174. var objectToString = objectProto.toString;
  1175. /** Used to restore the original `_` reference in `_.noConflict`. */
  1176. var oldDash = root._;
  1177. /** Used to detect if a method is native. */
  1178. var reIsNative = RegExp('^' +
  1179. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1180. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1181. );
  1182. /** Built-in value references. */
  1183. var Buffer = moduleExports ? context.Buffer : undefined,
  1184. Reflect = context.Reflect,
  1185. Symbol = context.Symbol,
  1186. Uint8Array = context.Uint8Array,
  1187. enumerate = Reflect ? Reflect.enumerate : undefined,
  1188. iteratorSymbol = Symbol ? Symbol.iterator : undefined,
  1189. objectCreate = context.Object.create,
  1190. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1191. splice = arrayProto.splice,
  1192. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
  1193. /** Built-in method references that are mockable. */
  1194. var clearTimeout = function(id) { return context.clearTimeout.call(root, id); },
  1195. setTimeout = function(func, wait) { return context.setTimeout.call(root, func, wait); };
  1196. /* Built-in method references for those with the same name as other `lodash` methods. */
  1197. var nativeCeil = Math.ceil,
  1198. nativeFloor = Math.floor,
  1199. nativeGetPrototype = Object.getPrototypeOf,
  1200. nativeGetSymbols = Object.getOwnPropertySymbols,
  1201. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1202. nativeIsFinite = context.isFinite,
  1203. nativeJoin = arrayProto.join,
  1204. nativeKeys = Object.keys,
  1205. nativeMax = Math.max,
  1206. nativeMin = Math.min,
  1207. nativeParseInt = context.parseInt,
  1208. nativeRandom = Math.random,
  1209. nativeReplace = stringProto.replace,
  1210. nativeReverse = arrayProto.reverse,
  1211. nativeSplit = stringProto.split;
  1212. /* Built-in method references that are verified to be native. */
  1213. var DataView = getNative(context, 'DataView'),
  1214. Map = getNative(context, 'Map'),
  1215. Promise = getNative(context, 'Promise'),
  1216. Set = getNative(context, 'Set'),
  1217. WeakMap = getNative(context, 'WeakMap'),
  1218. nativeCreate = getNative(context.Object, 'create');
  1219. /* Used to set `toString` methods. */
  1220. var defineProperty = (function() {
  1221. var func = getNative(context.Object, 'defineProperty'),
  1222. name = getNative.name;
  1223. return (name && name.length > 2) ? func : undefined;
  1224. }());
  1225. /** Used to store function metadata. */
  1226. var metaMap = WeakMap && new WeakMap;
  1227. /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
  1228. var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
  1229. /** Used to lookup unminified function names. */
  1230. var realNames = {};
  1231. /** Used to detect maps, sets, and weakmaps. */
  1232. var dataViewCtorString = toSource(DataView),
  1233. mapCtorString = toSource(Map),
  1234. promiseCtorString = toSource(Promise),
  1235. setCtorString = toSource(Set),
  1236. weakMapCtorString = toSource(WeakMap);
  1237. /** Used to convert symbols to primitives and strings. */
  1238. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1239. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1240. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1241. /*------------------------------------------------------------------------*/
  1242. /**
  1243. * Creates a `lodash` object which wraps `value` to enable implicit method
  1244. * chain sequences. Methods that operate on and return arrays, collections,
  1245. * and functions can be chained together. Methods that retrieve a single value
  1246. * or may return a primitive value will automatically end the chain sequence
  1247. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1248. * with `_#value`.
  1249. *
  1250. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1251. * enabled using `_.chain`.
  1252. *
  1253. * The execution of chained methods is lazy, that is, it's deferred until
  1254. * `_#value` is implicitly or explicitly called.
  1255. *
  1256. * Lazy evaluation allows several methods to support shortcut fusion.
  1257. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1258. * the creation of intermediate arrays and can greatly reduce the number of
  1259. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1260. * fusion if the section is applied to an array of at least `200` elements
  1261. * and any iteratees accept only one argument. The heuristic for whether a
  1262. * section qualifies for shortcut fusion is subject to change.
  1263. *
  1264. * Chaining is supported in custom builds as long as the `_#value` method is
  1265. * directly or indirectly included in the build.
  1266. *
  1267. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1268. *
  1269. * The wrapper `Array` methods are:
  1270. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1271. *
  1272. * The wrapper `String` methods are:
  1273. * `replace` and `split`
  1274. *
  1275. * The wrapper methods that support shortcut fusion are:
  1276. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1277. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1278. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1279. *
  1280. * The chainable wrapper methods are:
  1281. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1282. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1283. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1284. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1285. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1286. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1287. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1288. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1289. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1290. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1291. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1292. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1293. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1294. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1295. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1296. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1297. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1298. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1299. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1300. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1301. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1302. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1303. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1304. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1305. *
  1306. * The wrapper methods that are **not** chainable by default are:
  1307. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1308. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1309. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1310. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1311. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1312. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1313. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1314. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1315. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1316. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1317. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1318. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1319. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1320. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1321. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1322. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1323. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1324. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1325. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1326. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1327. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1328. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1329. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1330. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1331. * `upperFirst`, `value`, and `words`
  1332. *
  1333. * @name _
  1334. * @constructor
  1335. * @category Seq
  1336. * @param {*} value The value to wrap in a `lodash` instance.
  1337. * @returns {Object} Returns the new `lodash` wrapper instance.
  1338. * @example
  1339. *
  1340. * function square(n) {
  1341. * return n * n;
  1342. * }
  1343. *
  1344. * var wrapped = _([1, 2, 3]);
  1345. *
  1346. * // Returns an unwrapped value.
  1347. * wrapped.reduce(_.add);
  1348. * // => 6
  1349. *
  1350. * // Returns a wrapped value.
  1351. * var squares = wrapped.map(square);
  1352. *
  1353. * _.isArray(squares);
  1354. * // => false
  1355. *
  1356. * _.isArray(squares.value());
  1357. * // => true
  1358. */
  1359. function lodash(value) {
  1360. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1361. if (value instanceof LodashWrapper) {
  1362. return value;
  1363. }
  1364. if (hasOwnProperty.call(value, '__wrapped__')) {
  1365. return wrapperClone(value);
  1366. }
  1367. }
  1368. return new LodashWrapper(value);
  1369. }
  1370. /**
  1371. * The function whose prototype chain sequence wrappers inherit from.
  1372. *
  1373. * @private
  1374. */
  1375. function baseLodash() {
  1376. // No operation performed.
  1377. }
  1378. /**
  1379. * The base constructor for creating `lodash` wrapper objects.
  1380. *
  1381. * @private
  1382. * @param {*} value The value to wrap.
  1383. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1384. */
  1385. function LodashWrapper(value, chainAll) {
  1386. this.__wrapped__ = value;
  1387. this.__actions__ = [];
  1388. this.__chain__ = !!chainAll;
  1389. this.__index__ = 0;
  1390. this.__values__ = undefined;
  1391. }
  1392. /**
  1393. * By default, the template delimiters used by lodash are like those in
  1394. * embedded Ruby (ERB). Change the following template settings to use
  1395. * alternative delimiters.
  1396. *
  1397. * @static
  1398. * @memberOf _
  1399. * @type {Object}
  1400. */
  1401. lodash.templateSettings = {
  1402. /**
  1403. * Used to detect `data` property values to be HTML-escaped.
  1404. *
  1405. * @memberOf _.templateSettings
  1406. * @type {RegExp}
  1407. */
  1408. 'escape': reEscape,
  1409. /**
  1410. * Used to detect code to be evaluated.
  1411. *
  1412. * @memberOf _.templateSettings
  1413. * @type {RegExp}
  1414. */
  1415. 'evaluate': reEvaluate,
  1416. /**
  1417. * Used to detect `data` property values to inject.
  1418. *
  1419. * @memberOf _.templateSettings
  1420. * @type {RegExp}
  1421. */
  1422. 'interpolate': reInterpolate,
  1423. /**
  1424. * Used to reference the data object in the template text.
  1425. *
  1426. * @memberOf _.templateSettings
  1427. * @type {string}
  1428. */
  1429. 'variable': '',
  1430. /**
  1431. * Used to import variables into the compiled template.
  1432. *
  1433. * @memberOf _.templateSettings
  1434. * @type {Object}
  1435. */
  1436. 'imports': {
  1437. /**
  1438. * A reference to the `lodash` function.
  1439. *
  1440. * @memberOf _.templateSettings.imports
  1441. * @type {Function}
  1442. */
  1443. '_': lodash
  1444. }
  1445. };
  1446. // Ensure wrappers are instances of `baseLodash`.
  1447. lodash.prototype = baseLodash.prototype;
  1448. lodash.prototype.constructor = lodash;
  1449. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1450. LodashWrapper.prototype.constructor = LodashWrapper;
  1451. /*------------------------------------------------------------------------*/
  1452. /**
  1453. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1454. *
  1455. * @private
  1456. * @constructor
  1457. * @param {*} value The value to wrap.
  1458. */
  1459. function LazyWrapper(value) {
  1460. this.__wrapped__ = value;
  1461. this.__actions__ = [];
  1462. this.__dir__ = 1;
  1463. this.__filtered__ = false;
  1464. this.__iteratees__ = [];
  1465. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1466. this.__views__ = [];
  1467. }
  1468. /**
  1469. * Creates a clone of the lazy wrapper object.
  1470. *
  1471. * @private
  1472. * @name clone
  1473. * @memberOf LazyWrapper
  1474. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1475. */
  1476. function lazyClone() {
  1477. var result = new LazyWrapper(this.__wrapped__);
  1478. result.__actions__ = copyArray(this.__actions__);
  1479. result.__dir__ = this.__dir__;
  1480. result.__filtered__ = this.__filtered__;
  1481. result.__iteratees__ = copyArray(this.__iteratees__);
  1482. result.__takeCount__ = this.__takeCount__;
  1483. result.__views__ = copyArray(this.__views__);
  1484. return result;
  1485. }
  1486. /**
  1487. * Reverses the direction of lazy iteration.
  1488. *
  1489. * @private
  1490. * @name reverse
  1491. * @memberOf LazyWrapper
  1492. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1493. */
  1494. function lazyReverse() {
  1495. if (this.__filtered__) {
  1496. var result = new LazyWrapper(this);
  1497. result.__dir__ = -1;
  1498. result.__filtered__ = true;
  1499. } else {
  1500. result = this.clone();
  1501. result.__dir__ *= -1;
  1502. }
  1503. return result;
  1504. }
  1505. /**
  1506. * Extracts the unwrapped value from its lazy wrapper.
  1507. *
  1508. * @private
  1509. * @name value
  1510. * @memberOf LazyWrapper
  1511. * @returns {*} Returns the unwrapped value.
  1512. */
  1513. function lazyValue() {
  1514. var array = this.__wrapped__.value(),
  1515. dir = this.__dir__,
  1516. isArr = isArray(array),
  1517. isRight = dir < 0,
  1518. arrLength = isArr ? array.length : 0,
  1519. view = getView(0, arrLength, this.__views__),
  1520. start = view.start,
  1521. end = view.end,
  1522. length = end - start,
  1523. index = isRight ? end : (start - 1),
  1524. iteratees = this.__iteratees__,
  1525. iterLength = iteratees.length,
  1526. resIndex = 0,
  1527. takeCount = nativeMin(length, this.__takeCount__);
  1528. if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
  1529. (arrLength == length && takeCount == length)) {
  1530. return baseWrapperValue(array, this.__actions__);
  1531. }
  1532. var result = [];
  1533. outer:
  1534. while (length-- && resIndex < takeCount) {
  1535. index += dir;
  1536. var iterIndex = -1,
  1537. value = array[index];
  1538. while (++iterIndex < iterLength) {
  1539. var data = iteratees[iterIndex],
  1540. iteratee = data.iteratee,
  1541. type = data.type,
  1542. computed = iteratee(value);
  1543. if (type == LAZY_MAP_FLAG) {
  1544. value = computed;
  1545. } else if (!computed) {
  1546. if (type == LAZY_FILTER_FLAG) {
  1547. continue outer;
  1548. } else {
  1549. break outer;
  1550. }
  1551. }
  1552. }
  1553. result[resIndex++] = value;
  1554. }
  1555. return result;
  1556. }
  1557. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1558. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1559. LazyWrapper.prototype.constructor = LazyWrapper;
  1560. /*------------------------------------------------------------------------*/
  1561. /**
  1562. * Creates a hash object.
  1563. *
  1564. * @private
  1565. * @constructor
  1566. * @param {Array} [entries] The key-value pairs to cache.
  1567. */
  1568. function Hash(entries) {
  1569. var index = -1,
  1570. length = entries ? entries.length : 0;
  1571. this.clear();
  1572. while (++index < length) {
  1573. var entry = entries[index];
  1574. this.set(entry[0], entry[1]);
  1575. }
  1576. }
  1577. /**
  1578. * Removes all key-value entries from the hash.
  1579. *
  1580. * @private
  1581. * @name clear
  1582. * @memberOf Hash
  1583. */
  1584. function hashClear() {
  1585. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1586. }
  1587. /**
  1588. * Removes `key` and its value from the hash.
  1589. *
  1590. * @private
  1591. * @name delete
  1592. * @memberOf Hash
  1593. * @param {Object} hash The hash to modify.
  1594. * @param {string} key The key of the value to remove.
  1595. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1596. */
  1597. function hashDelete(key) {
  1598. return this.has(key) && delete this.__data__[key];
  1599. }
  1600. /**
  1601. * Gets the hash value for `key`.
  1602. *
  1603. * @private
  1604. * @name get
  1605. * @memberOf Hash
  1606. * @param {string} key The key of the value to get.
  1607. * @returns {*} Returns the entry value.
  1608. */
  1609. function hashGet(key) {
  1610. var data = this.__data__;
  1611. if (nativeCreate) {
  1612. var result = data[key];
  1613. return result === HASH_UNDEFINED ? undefined : result;
  1614. }
  1615. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1616. }
  1617. /**
  1618. * Checks if a hash value for `key` exists.
  1619. *
  1620. * @private
  1621. * @name has
  1622. * @memberOf Hash
  1623. * @param {string} key The key of the entry to check.
  1624. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1625. */
  1626. function hashHas(key) {
  1627. var data = this.__data__;
  1628. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  1629. }
  1630. /**
  1631. * Sets the hash `key` to `value`.
  1632. *
  1633. * @private
  1634. * @name set
  1635. * @memberOf Hash
  1636. * @param {string} key The key of the value to set.
  1637. * @param {*} value The value to set.
  1638. * @returns {Object} Returns the hash instance.
  1639. */
  1640. function hashSet(key, value) {
  1641. var data = this.__data__;
  1642. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1643. return this;
  1644. }
  1645. // Add methods to `Hash`.
  1646. Hash.prototype.clear = hashClear;
  1647. Hash.prototype['delete'] = hashDelete;
  1648. Hash.prototype.get = hashGet;
  1649. Hash.prototype.has = hashHas;
  1650. Hash.prototype.set = hashSet;
  1651. /*------------------------------------------------------------------------*/
  1652. /**
  1653. * Creates an list cache object.
  1654. *
  1655. * @private
  1656. * @constructor
  1657. * @param {Array} [entries] The key-value pairs to cache.
  1658. */
  1659. function ListCache(entries) {
  1660. var index = -1,
  1661. length = entries ? entries.length : 0;
  1662. this.clear();
  1663. while (++index < length) {
  1664. var entry = entries[index];
  1665. this.set(entry[0], entry[1]);
  1666. }
  1667. }
  1668. /**
  1669. * Removes all key-value entries from the list cache.
  1670. *
  1671. * @private
  1672. * @name clear
  1673. * @memberOf ListCache
  1674. */
  1675. function listCacheClear() {
  1676. this.__data__ = [];
  1677. }
  1678. /**
  1679. * Removes `key` and its value from the list cache.
  1680. *
  1681. * @private
  1682. * @name delete
  1683. * @memberOf ListCache
  1684. * @param {string} key The key of the value to remove.
  1685. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1686. */
  1687. function listCacheDelete(key) {
  1688. var data = this.__data__,
  1689. index = assocIndexOf(data, key);
  1690. if (index < 0) {
  1691. return false;
  1692. }
  1693. var lastIndex = data.length - 1;
  1694. if (index == lastIndex) {
  1695. data.pop();
  1696. } else {
  1697. splice.call(data, index, 1);
  1698. }
  1699. return true;
  1700. }
  1701. /**
  1702. * Gets the list cache value for `key`.
  1703. *
  1704. * @private
  1705. * @name get
  1706. * @memberOf ListCache
  1707. * @param {string} key The key of the value to get.
  1708. * @returns {*} Returns the entry value.
  1709. */
  1710. function listCacheGet(key) {
  1711. var data = this.__data__,
  1712. index = assocIndexOf(data, key);
  1713. return index < 0 ? undefined : data[index][1];
  1714. }
  1715. /**
  1716. * Checks if a list cache value for `key` exists.
  1717. *
  1718. * @private
  1719. * @name has
  1720. * @memberOf ListCache
  1721. * @param {string} key The key of the entry to check.
  1722. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1723. */
  1724. function listCacheHas(key) {
  1725. return assocIndexOf(this.__data__, key) > -1;
  1726. }
  1727. /**
  1728. * Sets the list cache `key` to `value`.
  1729. *
  1730. * @private
  1731. * @name set
  1732. * @memberOf ListCache
  1733. * @param {string} key The key of the value to set.
  1734. * @param {*} value The value to set.
  1735. * @returns {Object} Returns the list cache instance.
  1736. */
  1737. function listCacheSet(key, value) {
  1738. var data = this.__data__,
  1739. index = assocIndexOf(data, key);
  1740. if (index < 0) {
  1741. data.push([key, value]);
  1742. } else {
  1743. data[index][1] = value;
  1744. }
  1745. return this;
  1746. }
  1747. // Add methods to `ListCache`.
  1748. ListCache.prototype.clear = listCacheClear;
  1749. ListCache.prototype['delete'] = listCacheDelete;
  1750. ListCache.prototype.get = listCacheGet;
  1751. ListCache.prototype.has = listCacheHas;
  1752. ListCache.prototype.set = listCacheSet;
  1753. /*------------------------------------------------------------------------*/
  1754. /**
  1755. * Creates a map cache object to store key-value pairs.
  1756. *
  1757. * @private
  1758. * @constructor
  1759. * @param {Array} [entries] The key-value pairs to cache.
  1760. */
  1761. function MapCache(entries) {
  1762. var index = -1,
  1763. length = entries ? entries.length : 0;
  1764. this.clear();
  1765. while (++index < length) {
  1766. var entry = entries[index];
  1767. this.set(entry[0], entry[1]);
  1768. }
  1769. }
  1770. /**
  1771. * Removes all key-value entries from the map.
  1772. *
  1773. * @private
  1774. * @name clear
  1775. * @memberOf MapCache
  1776. */
  1777. function mapCacheClear() {
  1778. this.__data__ = {
  1779. 'hash': new Hash,
  1780. 'map': new (Map || ListCache),
  1781. 'string': new Hash
  1782. };
  1783. }
  1784. /**
  1785. * Removes `key` and its value from the map.
  1786. *
  1787. * @private
  1788. * @name delete
  1789. * @memberOf MapCache
  1790. * @param {string} key The key of the value to remove.
  1791. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1792. */
  1793. function mapCacheDelete(key) {
  1794. return getMapData(this, key)['delete'](key);
  1795. }
  1796. /**
  1797. * Gets the map value for `key`.
  1798. *
  1799. * @private
  1800. * @name get
  1801. * @memberOf MapCache
  1802. * @param {string} key The key of the value to get.
  1803. * @returns {*} Returns the entry value.
  1804. */
  1805. function mapCacheGet(key) {
  1806. return getMapData(this, key).get(key);
  1807. }
  1808. /**
  1809. * Checks if a map value for `key` exists.
  1810. *
  1811. * @private
  1812. * @name has
  1813. * @memberOf MapCache
  1814. * @param {string} key The key of the entry to check.
  1815. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1816. */
  1817. function mapCacheHas(key) {
  1818. return getMapData(this, key).has(key);
  1819. }
  1820. /**
  1821. * Sets the map `key` to `value`.
  1822. *
  1823. * @private
  1824. * @name set
  1825. * @memberOf MapCache
  1826. * @param {string} key The key of the value to set.
  1827. * @param {*} value The value to set.
  1828. * @returns {Object} Returns the map cache instance.
  1829. */
  1830. function mapCacheSet(key, value) {
  1831. getMapData(this, key).set(key, value);
  1832. return this;
  1833. }
  1834. // Add methods to `MapCache`.
  1835. MapCache.prototype.clear = mapCacheClear;
  1836. MapCache.prototype['delete'] = mapCacheDelete;
  1837. MapCache.prototype.get = mapCacheGet;
  1838. MapCache.prototype.has = mapCacheHas;
  1839. MapCache.prototype.set = mapCacheSet;
  1840. /*------------------------------------------------------------------------*/
  1841. /**
  1842. *
  1843. * Creates an array cache object to store unique values.
  1844. *
  1845. * @private
  1846. * @constructor
  1847. * @param {Array} [values] The values to cache.
  1848. */
  1849. function SetCache(values) {
  1850. var index = -1,
  1851. length = values ? values.length : 0;
  1852. this.__data__ = new MapCache;
  1853. while (++index < length) {
  1854. this.add(values[index]);
  1855. }
  1856. }
  1857. /**
  1858. * Adds `value` to the array cache.
  1859. *
  1860. * @private
  1861. * @name add
  1862. * @memberOf SetCache
  1863. * @alias push
  1864. * @param {*} value The value to cache.
  1865. * @returns {Object} Returns the cache instance.
  1866. */
  1867. function setCacheAdd(value) {
  1868. this.__data__.set(value, HASH_UNDEFINED);
  1869. return this;
  1870. }
  1871. /**
  1872. * Checks if `value` is in the array cache.
  1873. *
  1874. * @private
  1875. * @name has
  1876. * @memberOf SetCache
  1877. * @param {*} value The value to search for.
  1878. * @returns {number} Returns `true` if `value` is found, else `false`.
  1879. */
  1880. function setCacheHas(value) {
  1881. return this.__data__.has(value);
  1882. }
  1883. // Add methods to `SetCache`.
  1884. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  1885. SetCache.prototype.has = setCacheHas;
  1886. /*------------------------------------------------------------------------*/
  1887. /**
  1888. * Creates a stack cache object to store key-value pairs.
  1889. *
  1890. * @private
  1891. * @constructor
  1892. * @param {Array} [entries] The key-value pairs to cache.
  1893. */
  1894. function Stack(entries) {
  1895. this.__data__ = new ListCache(entries);
  1896. }
  1897. /**
  1898. * Removes all key-value entries from the stack.
  1899. *
  1900. * @private
  1901. * @name clear
  1902. * @memberOf Stack
  1903. */
  1904. function stackClear() {
  1905. this.__data__ = new ListCache;
  1906. }
  1907. /**
  1908. * Removes `key` and its value from the stack.
  1909. *
  1910. * @private
  1911. * @name delete
  1912. * @memberOf Stack
  1913. * @param {string} key The key of the value to remove.
  1914. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1915. */
  1916. function stackDelete(key) {
  1917. return this.__data__['delete'](key);
  1918. }
  1919. /**
  1920. * Gets the stack value for `key`.
  1921. *
  1922. * @private
  1923. * @name get
  1924. * @memberOf Stack
  1925. * @param {string} key The key of the value to get.
  1926. * @returns {*} Returns the entry value.
  1927. */
  1928. function stackGet(key) {
  1929. return this.__data__.get(key);
  1930. }
  1931. /**
  1932. * Checks if a stack value for `key` exists.
  1933. *
  1934. * @private
  1935. * @name has
  1936. * @memberOf Stack
  1937. * @param {string} key The key of the entry to check.
  1938. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1939. */
  1940. function stackHas(key) {
  1941. return this.__data__.has(key);
  1942. }
  1943. /**
  1944. * Sets the stack `key` to `value`.
  1945. *
  1946. * @private
  1947. * @name set
  1948. * @memberOf Stack
  1949. * @param {string} key The key of the value to set.
  1950. * @param {*} value The value to set.
  1951. * @returns {Object} Returns the stack cache instance.
  1952. */
  1953. function stackSet(key, value) {
  1954. var cache = this.__data__;
  1955. if (cache instanceof ListCache) {
  1956. var pairs = cache.__data__;
  1957. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  1958. pairs.push([key, value]);
  1959. return this;
  1960. }
  1961. cache = this.__data__ = new MapCache(pairs);
  1962. }
  1963. cache.set(key, value);
  1964. return this;
  1965. }
  1966. // Add methods to `Stack`.
  1967. Stack.prototype.clear = stackClear;
  1968. Stack.prototype['delete'] = stackDelete;
  1969. Stack.prototype.get = stackGet;
  1970. Stack.prototype.has = stackHas;
  1971. Stack.prototype.set = stackSet;
  1972. /*------------------------------------------------------------------------*/
  1973. /**
  1974. * Used by `_.defaults` to customize its `_.assignIn` use.
  1975. *
  1976. * @private
  1977. * @param {*} objValue The destination value.
  1978. * @param {*} srcValue The source value.
  1979. * @param {string} key The key of the property to assign.
  1980. * @param {Object} object The parent object of `objValue`.
  1981. * @returns {*} Returns the value to assign.
  1982. */
  1983. function assignInDefaults(objValue, srcValue, key, object) {
  1984. if (objValue === undefined ||
  1985. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  1986. return srcValue;
  1987. }
  1988. return objValue;
  1989. }
  1990. /**
  1991. * This function is like `assignValue` except that it doesn't assign
  1992. * `undefined` values.
  1993. *
  1994. * @private
  1995. * @param {Object} object The object to modify.
  1996. * @param {string} key The key of the property to assign.
  1997. * @param {*} value The value to assign.
  1998. */
  1999. function assignMergeValue(object, key, value) {
  2000. if ((value !== undefined && !eq(object[key], value)) ||
  2001. (typeof key == 'number' && value === undefined && !(key in object))) {
  2002. object[key] = value;
  2003. }
  2004. }
  2005. /**
  2006. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2007. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  2008. * for equality comparisons.
  2009. *
  2010. * @private
  2011. * @param {Object} object The object to modify.
  2012. * @param {string} key The key of the property to assign.
  2013. * @param {*} value The value to assign.
  2014. */
  2015. function assignValue(object, key, value) {
  2016. var objValue = object[key];
  2017. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2018. (value === undefined && !(key in object))) {
  2019. object[key] = value;
  2020. }
  2021. }
  2022. /**
  2023. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2024. *
  2025. * @private
  2026. * @param {Array} array The array to search.
  2027. * @param {*} key The key to search for.
  2028. * @returns {number} Returns the index of the matched value, else `-1`.
  2029. */
  2030. function assocIndexOf(array, key) {
  2031. var length = array.length;
  2032. while (length--) {
  2033. if (eq(array[length][0], key)) {
  2034. return length;
  2035. }
  2036. }
  2037. return -1;
  2038. }
  2039. /**
  2040. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2041. * by `iteratee` and values set by `setter`.
  2042. *
  2043. * @private
  2044. * @param {Array|Object} collection The collection to iterate over.
  2045. * @param {Function} setter The function to set `accumulator` values.
  2046. * @param {Function} iteratee The iteratee to transform keys.
  2047. * @param {Object} accumulator The initial aggregated object.
  2048. * @returns {Function} Returns `accumulator`.
  2049. */
  2050. function baseAggregator(collection, setter, iteratee, accumulator) {
  2051. baseEach(collection, function(value, key, collection) {
  2052. setter(accumulator, value, iteratee(value), collection);
  2053. });
  2054. return accumulator;
  2055. }
  2056. /**
  2057. * The base implementation of `_.assign` without support for multiple sources
  2058. * or `customizer` functions.
  2059. *
  2060. * @private
  2061. * @param {Object} object The destination object.
  2062. * @param {Object} source The source object.
  2063. * @returns {Object} Returns `object`.
  2064. */
  2065. function baseAssign(object, source) {
  2066. return object && copyObject(source, keys(source), object);
  2067. }
  2068. /**
  2069. * The base implementation of `_.at` without support for individual paths.
  2070. *
  2071. * @private
  2072. * @param {Object} object The object to iterate over.
  2073. * @param {string[]} paths The property paths of elements to pick.
  2074. * @returns {Array} Returns the picked elements.
  2075. */
  2076. function baseAt(object, paths) {
  2077. var index = -1,
  2078. isNil = object == null,
  2079. length = paths.length,
  2080. result = Array(length);
  2081. while (++index < length) {
  2082. result[index] = isNil ? undefined : get(object, paths[index]);
  2083. }
  2084. return result;
  2085. }
  2086. /**
  2087. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2088. *
  2089. * @private
  2090. * @param {number} number The number to clamp.
  2091. * @param {number} [lower] The lower bound.
  2092. * @param {number} upper The upper bound.
  2093. * @returns {number} Returns the clamped number.
  2094. */
  2095. function baseClamp(number, lower, upper) {
  2096. if (number === number) {
  2097. if (upper !== undefined) {
  2098. number = number <= upper ? number : upper;
  2099. }
  2100. if (lower !== undefined) {
  2101. number = number >= lower ? number : lower;
  2102. }
  2103. }
  2104. return number;
  2105. }
  2106. /**
  2107. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2108. * traversed objects.
  2109. *
  2110. * @private
  2111. * @param {*} value The value to clone.
  2112. * @param {boolean} [isDeep] Specify a deep clone.
  2113. * @param {boolean} [isFull] Specify a clone including symbols.
  2114. * @param {Function} [customizer] The function to customize cloning.
  2115. * @param {string} [key] The key of `value`.
  2116. * @param {Object} [object] The parent object of `value`.
  2117. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2118. * @returns {*} Returns the cloned value.
  2119. */
  2120. function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
  2121. var result;
  2122. if (customizer) {
  2123. result = object ? customizer(value, key, object, stack) : customizer(value);
  2124. }
  2125. if (result !== undefined) {
  2126. return result;
  2127. }
  2128. if (!isObject(value)) {
  2129. return value;
  2130. }
  2131. var isArr = isArray(value);
  2132. if (isArr) {
  2133. result = initCloneArray(value);
  2134. if (!isDeep) {
  2135. return copyArray(value, result);
  2136. }
  2137. } else {
  2138. var tag = getTag(value),
  2139. isFunc = tag == funcTag || tag == genTag;
  2140. if (isBuffer(value)) {
  2141. return cloneBuffer(value, isDeep);
  2142. }
  2143. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2144. if (isHostObject(value)) {
  2145. return object ? value : {};
  2146. }
  2147. result = initCloneObject(isFunc ? {} : value);
  2148. if (!isDeep) {
  2149. return copySymbols(value, baseAssign(result, value));
  2150. }
  2151. } else {
  2152. if (!cloneableTags[tag]) {
  2153. return object ? value : {};
  2154. }
  2155. result = initCloneByTag(value, tag, baseClone, isDeep);
  2156. }
  2157. }
  2158. // Check for circular references and return its corresponding clone.
  2159. stack || (stack = new Stack);
  2160. var stacked = stack.get(value);
  2161. if (stacked) {
  2162. return stacked;
  2163. }
  2164. stack.set(value, result);
  2165. if (!isArr) {
  2166. var props = isFull ? getAllKeys(value) : keys(value);
  2167. }
  2168. arrayEach(props || value, function(subValue, key) {
  2169. if (props) {
  2170. key = subValue;
  2171. subValue = value[key];
  2172. }
  2173. // Recursively populate clone (susceptible to call stack limits).
  2174. assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
  2175. });
  2176. if (!isFull) {
  2177. stack['delete'](value);
  2178. }
  2179. return result;
  2180. }
  2181. /**
  2182. * The base implementation of `_.conforms` which doesn't clone `source`.
  2183. *
  2184. * @private
  2185. * @param {Object} source The object of property predicates to conform to.
  2186. * @returns {Function} Returns the new spec function.
  2187. */
  2188. function baseConforms(source) {
  2189. var props = keys(source);
  2190. return function(object) {
  2191. return baseConformsTo(object, source, props);
  2192. };
  2193. }
  2194. /**
  2195. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2196. *
  2197. * @private
  2198. * @param {Object} object The object to inspect.
  2199. * @param {Object} source The object of property predicates to conform to.
  2200. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2201. */
  2202. function baseConformsTo(object, source, props) {
  2203. var length = props.length;
  2204. if (object == null) {
  2205. return !length;
  2206. }
  2207. var index = length;
  2208. while (index--) {
  2209. var key = props[index],
  2210. predicate = source[key],
  2211. value = object[key];
  2212. if ((value === undefined &&
  2213. !(key in Object(object))) || !predicate(value)) {
  2214. return false;
  2215. }
  2216. }
  2217. return true;
  2218. }
  2219. /**
  2220. * The base implementation of `_.create` without support for assigning
  2221. * properties to the created object.
  2222. *
  2223. * @private
  2224. * @param {Object} prototype The object to inherit from.
  2225. * @returns {Object} Returns the new object.
  2226. */
  2227. function baseCreate(proto) {
  2228. return isObject(proto) ? objectCreate(proto) : {};
  2229. }
  2230. /**
  2231. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2232. * to provide to `func`.
  2233. *
  2234. * @private
  2235. * @param {Function} func The function to delay.
  2236. * @param {number} wait The number of milliseconds to delay invocation.
  2237. * @param {Array} args The arguments to provide to `func`.
  2238. * @returns {number} Returns the timer id.
  2239. */
  2240. function baseDelay(func, wait, args) {
  2241. if (typeof func != 'function') {
  2242. throw new TypeError(FUNC_ERROR_TEXT);
  2243. }
  2244. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2245. }
  2246. /**
  2247. * The base implementation of methods like `_.difference` without support
  2248. * for excluding multiple arrays or iteratee shorthands.
  2249. *
  2250. * @private
  2251. * @param {Array} array The array to inspect.
  2252. * @param {Array} values The values to exclude.
  2253. * @param {Function} [iteratee] The iteratee invoked per element.
  2254. * @param {Function} [comparator] The comparator invoked per element.
  2255. * @returns {Array} Returns the new array of filtered values.
  2256. */
  2257. function baseDifference(array, values, iteratee, comparator) {
  2258. var index = -1,
  2259. includes = arrayIncludes,
  2260. isCommon = true,
  2261. length = array.length,
  2262. result = [],
  2263. valuesLength = values.length;
  2264. if (!length) {
  2265. return result;
  2266. }
  2267. if (iteratee) {
  2268. values = arrayMap(values, baseUnary(iteratee));
  2269. }
  2270. if (comparator) {
  2271. includes = arrayIncludesWith;
  2272. isCommon = false;
  2273. }
  2274. else if (values.length >= LARGE_ARRAY_SIZE) {
  2275. includes = cacheHas;
  2276. isCommon = false;
  2277. values = new SetCache(values);
  2278. }
  2279. outer:
  2280. while (++index < length) {
  2281. var value = array[index],
  2282. computed = iteratee ? iteratee(value) : value;
  2283. value = (comparator || value !== 0) ? value : 0;
  2284. if (isCommon && computed === computed) {
  2285. var valuesIndex = valuesLength;
  2286. while (valuesIndex--) {
  2287. if (values[valuesIndex] === computed) {
  2288. continue outer;
  2289. }
  2290. }
  2291. result.push(value);
  2292. }
  2293. else if (!includes(values, computed, comparator)) {
  2294. result.push(value);
  2295. }
  2296. }
  2297. return result;
  2298. }
  2299. /**
  2300. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2301. *
  2302. * @private
  2303. * @param {Array|Object} collection The collection to iterate over.
  2304. * @param {Function} iteratee The function invoked per iteration.
  2305. * @returns {Array|Object} Returns `collection`.
  2306. */
  2307. var baseEach = createBaseEach(baseForOwn);
  2308. /**
  2309. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2310. *
  2311. * @private
  2312. * @param {Array|Object} collection The collection to iterate over.
  2313. * @param {Function} iteratee The function invoked per iteration.
  2314. * @returns {Array|Object} Returns `collection`.
  2315. */
  2316. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2317. /**
  2318. * The base implementation of `_.every` without support for iteratee shorthands.
  2319. *
  2320. * @private
  2321. * @param {Array|Object} collection The collection to iterate over.
  2322. * @param {Function} predicate The function invoked per iteration.
  2323. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2324. * else `false`
  2325. */
  2326. function baseEvery(collection, predicate) {
  2327. var result = true;
  2328. baseEach(collection, function(value, index, collection) {
  2329. result = !!predicate(value, index, collection);
  2330. return result;
  2331. });
  2332. return result;
  2333. }
  2334. /**
  2335. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2336. * `comparator` to determine the extremum value.
  2337. *
  2338. * @private
  2339. * @param {Array} array The array to iterate over.
  2340. * @param {Function} iteratee The iteratee invoked per iteration.
  2341. * @param {Function} comparator The comparator used to compare values.
  2342. * @returns {*} Returns the extremum value.
  2343. */
  2344. function baseExtremum(array, iteratee, comparator) {
  2345. var index = -1,
  2346. length = array.length;
  2347. while (++index < length) {
  2348. var value = array[index],
  2349. current = iteratee(value);
  2350. if (current != null && (computed === undefined
  2351. ? (current === current && !isSymbol(current))
  2352. : comparator(current, computed)
  2353. )) {
  2354. var computed = current,
  2355. result = value;
  2356. }
  2357. }
  2358. return result;
  2359. }
  2360. /**
  2361. * The base implementation of `_.fill` without an iteratee call guard.
  2362. *
  2363. * @private
  2364. * @param {Array} array The array to fill.
  2365. * @param {*} value The value to fill `array` with.
  2366. * @param {number} [start=0] The start position.
  2367. * @param {number} [end=array.length] The end position.
  2368. * @returns {Array} Returns `array`.
  2369. */
  2370. function baseFill(array, value, start, end) {
  2371. var length = array.length;
  2372. start = toInteger(start);
  2373. if (start < 0) {
  2374. start = -start > length ? 0 : (length + start);
  2375. }
  2376. end = (end === undefined || end > length) ? length : toInteger(end);
  2377. if (end < 0) {
  2378. end += length;
  2379. }
  2380. end = start > end ? 0 : toLength(end);
  2381. while (start < end) {
  2382. array[start++] = value;
  2383. }
  2384. return array;
  2385. }
  2386. /**
  2387. * The base implementation of `_.filter` without support for iteratee shorthands.
  2388. *
  2389. * @private
  2390. * @param {Array|Object} collection The collection to iterate over.
  2391. * @param {Function} predicate The function invoked per iteration.
  2392. * @returns {Array} Returns the new filtered array.
  2393. */
  2394. function baseFilter(collection, predicate) {
  2395. var result = [];
  2396. baseEach(collection, function(value, index, collection) {
  2397. if (predicate(value, index, collection)) {
  2398. result.push(value);
  2399. }
  2400. });
  2401. return result;
  2402. }
  2403. /**
  2404. * The base implementation of `_.flatten` with support for restricting flattening.
  2405. *
  2406. * @private
  2407. * @param {Array} array The array to flatten.
  2408. * @param {number} depth The maximum recursion depth.
  2409. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2410. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2411. * @param {Array} [result=[]] The initial result value.
  2412. * @returns {Array} Returns the new flattened array.
  2413. */
  2414. function baseFlatten(array, depth, predicate, isStrict, result) {
  2415. var index = -1,
  2416. length = array.length;
  2417. predicate || (predicate = isFlattenable);
  2418. result || (result = []);
  2419. while (++index < length) {
  2420. var value = array[index];
  2421. if (depth > 0 && predicate(value)) {
  2422. if (depth > 1) {
  2423. // Recursively flatten arrays (susceptible to call stack limits).
  2424. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2425. } else {
  2426. arrayPush(result, value);
  2427. }
  2428. } else if (!isStrict) {
  2429. result[result.length] = value;
  2430. }
  2431. }
  2432. return result;
  2433. }
  2434. /**
  2435. * The base implementation of `baseForOwn` which iterates over `object`
  2436. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2437. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2438. *
  2439. * @private
  2440. * @param {Object} object The object to iterate over.
  2441. * @param {Function} iteratee The function invoked per iteration.
  2442. * @param {Function} keysFunc The function to get the keys of `object`.
  2443. * @returns {Object} Returns `object`.
  2444. */
  2445. var baseFor = createBaseFor();
  2446. /**
  2447. * This function is like `baseFor` except that it iterates over properties
  2448. * in the opposite order.
  2449. *
  2450. * @private
  2451. * @param {Object} object The object to iterate over.
  2452. * @param {Function} iteratee The function invoked per iteration.
  2453. * @param {Function} keysFunc The function to get the keys of `object`.
  2454. * @returns {Object} Returns `object`.
  2455. */
  2456. var baseForRight = createBaseFor(true);
  2457. /**
  2458. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2459. *
  2460. * @private
  2461. * @param {Object} object The object to iterate over.
  2462. * @param {Function} iteratee The function invoked per iteration.
  2463. * @returns {Object} Returns `object`.
  2464. */
  2465. function baseForOwn(object, iteratee) {
  2466. return object && baseFor(object, iteratee, keys);
  2467. }
  2468. /**
  2469. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2470. *
  2471. * @private
  2472. * @param {Object} object The object to iterate over.
  2473. * @param {Function} iteratee The function invoked per iteration.
  2474. * @returns {Object} Returns `object`.
  2475. */
  2476. function baseForOwnRight(object, iteratee) {
  2477. return object && baseForRight(object, iteratee, keys);
  2478. }
  2479. /**
  2480. * The base implementation of `_.functions` which creates an array of
  2481. * `object` function property names filtered from `props`.
  2482. *
  2483. * @private
  2484. * @param {Object} object The object to inspect.
  2485. * @param {Array} props The property names to filter.
  2486. * @returns {Array} Returns the function names.
  2487. */
  2488. function baseFunctions(object, props) {
  2489. return arrayFilter(props, function(key) {
  2490. return isFunction(object[key]);
  2491. });
  2492. }
  2493. /**
  2494. * The base implementation of `_.get` without support for default values.
  2495. *
  2496. * @private
  2497. * @param {Object} object The object to query.
  2498. * @param {Array|string} path The path of the property to get.
  2499. * @returns {*} Returns the resolved value.
  2500. */
  2501. function baseGet(object, path) {
  2502. path = isKey(path, object) ? [path] : castPath(path);
  2503. var index = 0,
  2504. length = path.length;
  2505. while (object != null && index < length) {
  2506. object = object[toKey(path[index++])];
  2507. }
  2508. return (index && index == length) ? object : undefined;
  2509. }
  2510. /**
  2511. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2512. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2513. * symbols of `object`.
  2514. *
  2515. * @private
  2516. * @param {Object} object The object to query.
  2517. * @param {Function} keysFunc The function to get the keys of `object`.
  2518. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2519. * @returns {Array} Returns the array of property names and symbols.
  2520. */
  2521. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2522. var result = keysFunc(object);
  2523. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2524. }
  2525. /**
  2526. * The base implementation of `getTag`.
  2527. *
  2528. * @private
  2529. * @param {*} value The value to query.
  2530. * @returns {string} Returns the `toStringTag`.
  2531. */
  2532. function baseGetTag(value) {
  2533. return objectToString.call(value);
  2534. }
  2535. /**
  2536. * The base implementation of `_.gt` which doesn't coerce arguments.
  2537. *
  2538. * @private
  2539. * @param {*} value The value to compare.
  2540. * @param {*} other The other value to compare.
  2541. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2542. * else `false`.
  2543. */
  2544. function baseGt(value, other) {
  2545. return value > other;
  2546. }
  2547. /**
  2548. * The base implementation of `_.has` without support for deep paths.
  2549. *
  2550. * @private
  2551. * @param {Object} [object] The object to query.
  2552. * @param {Array|string} key The key to check.
  2553. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2554. */
  2555. function baseHas(object, key) {
  2556. // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
  2557. // that are composed entirely of index properties, return `false` for
  2558. // `hasOwnProperty` checks of them.
  2559. return object != null &&
  2560. (hasOwnProperty.call(object, key) ||
  2561. (typeof object == 'object' && key in object && getPrototype(object) === null));
  2562. }
  2563. /**
  2564. * The base implementation of `_.hasIn` without support for deep paths.
  2565. *
  2566. * @private
  2567. * @param {Object} [object] The object to query.
  2568. * @param {Array|string} key The key to check.
  2569. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2570. */
  2571. function baseHasIn(object, key) {
  2572. return object != null && key in Object(object);
  2573. }
  2574. /**
  2575. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2576. *
  2577. * @private
  2578. * @param {number} number The number to check.
  2579. * @param {number} start The start of the range.
  2580. * @param {number} end The end of the range.
  2581. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2582. */
  2583. function baseInRange(number, start, end) {
  2584. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2585. }
  2586. /**
  2587. * The base implementation of methods like `_.intersection`, without support
  2588. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2589. *
  2590. * @private
  2591. * @param {Array} arrays The arrays to inspect.
  2592. * @param {Function} [iteratee] The iteratee invoked per element.
  2593. * @param {Function} [comparator] The comparator invoked per element.
  2594. * @returns {Array} Returns the new array of shared values.
  2595. */
  2596. function baseIntersection(arrays, iteratee, comparator) {
  2597. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2598. length = arrays[0].length,
  2599. othLength = arrays.length,
  2600. othIndex = othLength,
  2601. caches = Array(othLength),
  2602. maxLength = Infinity,
  2603. result = [];
  2604. while (othIndex--) {
  2605. var array = arrays[othIndex];
  2606. if (othIndex && iteratee) {
  2607. array = arrayMap(array, baseUnary(iteratee));
  2608. }
  2609. maxLength = nativeMin(array.length, maxLength);
  2610. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2611. ? new SetCache(othIndex && array)
  2612. : undefined;
  2613. }
  2614. array = arrays[0];
  2615. var index = -1,
  2616. seen = caches[0];
  2617. outer:
  2618. while (++index < length && result.length < maxLength) {
  2619. var value = array[index],
  2620. computed = iteratee ? iteratee(value) : value;
  2621. value = (comparator || value !== 0) ? value : 0;
  2622. if (!(seen
  2623. ? cacheHas(seen, computed)
  2624. : includes(result, computed, comparator)
  2625. )) {
  2626. othIndex = othLength;
  2627. while (--othIndex) {
  2628. var cache = caches[othIndex];
  2629. if (!(cache
  2630. ? cacheHas(cache, computed)
  2631. : includes(arrays[othIndex], computed, comparator))
  2632. ) {
  2633. continue outer;
  2634. }
  2635. }
  2636. if (seen) {
  2637. seen.push(computed);
  2638. }
  2639. result.push(value);
  2640. }
  2641. }
  2642. return result;
  2643. }
  2644. /**
  2645. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2646. * `object` with values transformed by `iteratee` and set by `setter`.
  2647. *
  2648. * @private
  2649. * @param {Object} object The object to iterate over.
  2650. * @param {Function} setter The function to set `accumulator` values.
  2651. * @param {Function} iteratee The iteratee to transform values.
  2652. * @param {Object} accumulator The initial inverted object.
  2653. * @returns {Function} Returns `accumulator`.
  2654. */
  2655. function baseInverter(object, setter, iteratee, accumulator) {
  2656. baseForOwn(object, function(value, key, object) {
  2657. setter(accumulator, iteratee(value), key, object);
  2658. });
  2659. return accumulator;
  2660. }
  2661. /**
  2662. * The base implementation of `_.invoke` without support for individual
  2663. * method arguments.
  2664. *
  2665. * @private
  2666. * @param {Object} object The object to query.
  2667. * @param {Array|string} path The path of the method to invoke.
  2668. * @param {Array} args The arguments to invoke the method with.
  2669. * @returns {*} Returns the result of the invoked method.
  2670. */
  2671. function baseInvoke(object, path, args) {
  2672. if (!isKey(path, object)) {
  2673. path = castPath(path);
  2674. object = parent(object, path);
  2675. path = last(path);
  2676. }
  2677. var func = object == null ? object : object[toKey(path)];
  2678. return func == null ? undefined : apply(func, object, args);
  2679. }
  2680. /**
  2681. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2682. *
  2683. * @private
  2684. * @param {*} value The value to check.
  2685. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2686. */
  2687. function baseIsArrayBuffer(value) {
  2688. return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
  2689. }
  2690. /**
  2691. * The base implementation of `_.isDate` without Node.js optimizations.
  2692. *
  2693. * @private
  2694. * @param {*} value The value to check.
  2695. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2696. */
  2697. function baseIsDate(value) {
  2698. return isObjectLike(value) && objectToString.call(value) == dateTag;
  2699. }
  2700. /**
  2701. * The base implementation of `_.isEqual` which supports partial comparisons
  2702. * and tracks traversed objects.
  2703. *
  2704. * @private
  2705. * @param {*} value The value to compare.
  2706. * @param {*} other The other value to compare.
  2707. * @param {Function} [customizer] The function to customize comparisons.
  2708. * @param {boolean} [bitmask] The bitmask of comparison flags.
  2709. * The bitmask may be composed of the following flags:
  2710. * 1 - Unordered comparison
  2711. * 2 - Partial comparison
  2712. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2713. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2714. */
  2715. function baseIsEqual(value, other, customizer, bitmask, stack) {
  2716. if (value === other) {
  2717. return true;
  2718. }
  2719. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  2720. return value !== value && other !== other;
  2721. }
  2722. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  2723. }
  2724. /**
  2725. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2726. * deep comparisons and tracks traversed objects enabling objects with circular
  2727. * references to be compared.
  2728. *
  2729. * @private
  2730. * @param {Object} object The object to compare.
  2731. * @param {Object} other The other object to compare.
  2732. * @param {Function} equalFunc The function to determine equivalents of values.
  2733. * @param {Function} [customizer] The function to customize comparisons.
  2734. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  2735. * for more details.
  2736. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2737. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2738. */
  2739. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  2740. var objIsArr = isArray(object),
  2741. othIsArr = isArray(other),
  2742. objTag = arrayTag,
  2743. othTag = arrayTag;
  2744. if (!objIsArr) {
  2745. objTag = getTag(object);
  2746. objTag = objTag == argsTag ? objectTag : objTag;
  2747. }
  2748. if (!othIsArr) {
  2749. othTag = getTag(other);
  2750. othTag = othTag == argsTag ? objectTag : othTag;
  2751. }
  2752. var objIsObj = objTag == objectTag && !isHostObject(object),
  2753. othIsObj = othTag == objectTag && !isHostObject(other),
  2754. isSameTag = objTag == othTag;
  2755. if (isSameTag && !objIsObj) {
  2756. stack || (stack = new Stack);
  2757. return (objIsArr || isTypedArray(object))
  2758. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  2759. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  2760. }
  2761. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  2762. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2763. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2764. if (objIsWrapped || othIsWrapped) {
  2765. var objUnwrapped = objIsWrapped ? object.value() : object,
  2766. othUnwrapped = othIsWrapped ? other.value() : other;
  2767. stack || (stack = new Stack);
  2768. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  2769. }
  2770. }
  2771. if (!isSameTag) {
  2772. return false;
  2773. }
  2774. stack || (stack = new Stack);
  2775. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  2776. }
  2777. /**
  2778. * The base implementation of `_.isMap` without Node.js optimizations.
  2779. *
  2780. * @private
  2781. * @param {*} value The value to check.
  2782. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  2783. */
  2784. function baseIsMap(value) {
  2785. return isObjectLike(value) && getTag(value) == mapTag;
  2786. }
  2787. /**
  2788. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  2789. *
  2790. * @private
  2791. * @param {Object} object The object to inspect.
  2792. * @param {Object} source The object of property values to match.
  2793. * @param {Array} matchData The property names, values, and compare flags to match.
  2794. * @param {Function} [customizer] The function to customize comparisons.
  2795. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2796. */
  2797. function baseIsMatch(object, source, matchData, customizer) {
  2798. var index = matchData.length,
  2799. length = index,
  2800. noCustomizer = !customizer;
  2801. if (object == null) {
  2802. return !length;
  2803. }
  2804. object = Object(object);
  2805. while (index--) {
  2806. var data = matchData[index];
  2807. if ((noCustomizer && data[2])
  2808. ? data[1] !== object[data[0]]
  2809. : !(data[0] in object)
  2810. ) {
  2811. return false;
  2812. }
  2813. }
  2814. while (++index < length) {
  2815. data = matchData[index];
  2816. var key = data[0],
  2817. objValue = object[key],
  2818. srcValue = data[1];
  2819. if (noCustomizer && data[2]) {
  2820. if (objValue === undefined && !(key in object)) {
  2821. return false;
  2822. }
  2823. } else {
  2824. var stack = new Stack;
  2825. if (customizer) {
  2826. var result = customizer(objValue, srcValue, key, object, source, stack);
  2827. }
  2828. if (!(result === undefined
  2829. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  2830. : result
  2831. )) {
  2832. return false;
  2833. }
  2834. }
  2835. }
  2836. return true;
  2837. }
  2838. /**
  2839. * The base implementation of `_.isNative` without bad shim checks.
  2840. *
  2841. * @private
  2842. * @param {*} value The value to check.
  2843. * @returns {boolean} Returns `true` if `value` is a native function,
  2844. * else `false`.
  2845. */
  2846. function baseIsNative(value) {
  2847. if (!isObject(value) || isMasked(value)) {
  2848. return false;
  2849. }
  2850. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  2851. return pattern.test(toSource(value));
  2852. }
  2853. /**
  2854. * The base implementation of `_.isRegExp` without Node.js optimizations.
  2855. *
  2856. * @private
  2857. * @param {*} value The value to check.
  2858. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  2859. */
  2860. function baseIsRegExp(value) {
  2861. return isObject(value) && objectToString.call(value) == regexpTag;
  2862. }
  2863. /**
  2864. * The base implementation of `_.isSet` without Node.js optimizations.
  2865. *
  2866. * @private
  2867. * @param {*} value The value to check.
  2868. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  2869. */
  2870. function baseIsSet(value) {
  2871. return isObjectLike(value) && getTag(value) == setTag;
  2872. }
  2873. /**
  2874. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  2875. *
  2876. * @private
  2877. * @param {*} value The value to check.
  2878. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  2879. */
  2880. function baseIsTypedArray(value) {
  2881. return isObjectLike(value) &&
  2882. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  2883. }
  2884. /**
  2885. * The base implementation of `_.iteratee`.
  2886. *
  2887. * @private
  2888. * @param {*} [value=_.identity] The value to convert to an iteratee.
  2889. * @returns {Function} Returns the iteratee.
  2890. */
  2891. function baseIteratee(value) {
  2892. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  2893. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  2894. if (typeof value == 'function') {
  2895. return value;
  2896. }
  2897. if (value == null) {
  2898. return identity;
  2899. }
  2900. if (typeof value == 'object') {
  2901. return isArray(value)
  2902. ? baseMatchesProperty(value[0], value[1])
  2903. : baseMatches(value);
  2904. }
  2905. return property(value);
  2906. }
  2907. /**
  2908. * The base implementation of `_.keys` which doesn't skip the constructor
  2909. * property of prototypes or treat sparse arrays as dense.
  2910. *
  2911. * @private
  2912. * @param {Object} object The object to query.
  2913. * @returns {Array} Returns the array of property names.
  2914. */
  2915. var baseKeys = overArg(nativeKeys, Object);
  2916. /**
  2917. * The base implementation of `_.keysIn` which doesn't skip the constructor
  2918. * property of prototypes or treat sparse arrays as dense.
  2919. *
  2920. * @private
  2921. * @param {Object} object The object to query.
  2922. * @returns {Array} Returns the array of property names.
  2923. */
  2924. function baseKeysIn(object) {
  2925. object = object == null ? object : Object(object);
  2926. var result = [];
  2927. for (var key in object) {
  2928. result.push(key);
  2929. }
  2930. return result;
  2931. }
  2932. // Fallback for IE < 9 with es6-shim.
  2933. if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
  2934. baseKeysIn = function(object) {
  2935. return iteratorToArray(enumerate(object));
  2936. };
  2937. }
  2938. /**
  2939. * The base implementation of `_.lt` which doesn't coerce arguments.
  2940. *
  2941. * @private
  2942. * @param {*} value The value to compare.
  2943. * @param {*} other The other value to compare.
  2944. * @returns {boolean} Returns `true` if `value` is less than `other`,
  2945. * else `false`.
  2946. */
  2947. function baseLt(value, other) {
  2948. return value < other;
  2949. }
  2950. /**
  2951. * The base implementation of `_.map` without support for iteratee shorthands.
  2952. *
  2953. * @private
  2954. * @param {Array|Object} collection The collection to iterate over.
  2955. * @param {Function} iteratee The function invoked per iteration.
  2956. * @returns {Array} Returns the new mapped array.
  2957. */
  2958. function baseMap(collection, iteratee) {
  2959. var index = -1,
  2960. result = isArrayLike(collection) ? Array(collection.length) : [];
  2961. baseEach(collection, function(value, key, collection) {
  2962. result[++index] = iteratee(value, key, collection);
  2963. });
  2964. return result;
  2965. }
  2966. /**
  2967. * The base implementation of `_.matches` which doesn't clone `source`.
  2968. *
  2969. * @private
  2970. * @param {Object} source The object of property values to match.
  2971. * @returns {Function} Returns the new spec function.
  2972. */
  2973. function baseMatches(source) {
  2974. var matchData = getMatchData(source);
  2975. if (matchData.length == 1 && matchData[0][2]) {
  2976. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  2977. }
  2978. return function(object) {
  2979. return object === source || baseIsMatch(object, source, matchData);
  2980. };
  2981. }
  2982. /**
  2983. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  2984. *
  2985. * @private
  2986. * @param {string} path The path of the property to get.
  2987. * @param {*} srcValue The value to match.
  2988. * @returns {Function} Returns the new spec function.
  2989. */
  2990. function baseMatchesProperty(path, srcValue) {
  2991. if (isKey(path) && isStrictComparable(srcValue)) {
  2992. return matchesStrictComparable(toKey(path), srcValue);
  2993. }
  2994. return function(object) {
  2995. var objValue = get(object, path);
  2996. return (objValue === undefined && objValue === srcValue)
  2997. ? hasIn(object, path)
  2998. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  2999. };
  3000. }
  3001. /**
  3002. * The base implementation of `_.merge` without support for multiple sources.
  3003. *
  3004. * @private
  3005. * @param {Object} object The destination object.
  3006. * @param {Object} source The source object.
  3007. * @param {number} srcIndex The index of `source`.
  3008. * @param {Function} [customizer] The function to customize merged values.
  3009. * @param {Object} [stack] Tracks traversed source values and their merged
  3010. * counterparts.
  3011. */
  3012. function baseMerge(object, source, srcIndex, customizer, stack) {
  3013. if (object === source) {
  3014. return;
  3015. }
  3016. if (!(isArray(source) || isTypedArray(source))) {
  3017. var props = keysIn(source);
  3018. }
  3019. arrayEach(props || source, function(srcValue, key) {
  3020. if (props) {
  3021. key = srcValue;
  3022. srcValue = source[key];
  3023. }
  3024. if (isObject(srcValue)) {
  3025. stack || (stack = new Stack);
  3026. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3027. }
  3028. else {
  3029. var newValue = customizer
  3030. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  3031. : undefined;
  3032. if (newValue === undefined) {
  3033. newValue = srcValue;
  3034. }
  3035. assignMergeValue(object, key, newValue);
  3036. }
  3037. });
  3038. }
  3039. /**
  3040. * A specialized version of `baseMerge` for arrays and objects which performs
  3041. * deep merges and tracks traversed objects enabling objects with circular
  3042. * references to be merged.
  3043. *
  3044. * @private
  3045. * @param {Object} object The destination object.
  3046. * @param {Object} source The source object.
  3047. * @param {string} key The key of the value to merge.
  3048. * @param {number} srcIndex The index of `source`.
  3049. * @param {Function} mergeFunc The function to merge values.
  3050. * @param {Function} [customizer] The function to customize assigned values.
  3051. * @param {Object} [stack] Tracks traversed source values and their merged
  3052. * counterparts.
  3053. */
  3054. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3055. var objValue = object[key],
  3056. srcValue = source[key],
  3057. stacked = stack.get(srcValue);
  3058. if (stacked) {
  3059. assignMergeValue(object, key, stacked);
  3060. return;
  3061. }
  3062. var newValue = customizer
  3063. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3064. : undefined;
  3065. var isCommon = newValue === undefined;
  3066. if (isCommon) {
  3067. newValue = srcValue;
  3068. if (isArray(srcValue) || isTypedArray(srcValue)) {
  3069. if (isArray(objValue)) {
  3070. newValue = objValue;
  3071. }
  3072. else if (isArrayLikeObject(objValue)) {
  3073. newValue = copyArray(objValue);
  3074. }
  3075. else {
  3076. isCommon = false;
  3077. newValue = baseClone(srcValue, true);
  3078. }
  3079. }
  3080. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3081. if (isArguments(objValue)) {
  3082. newValue = toPlainObject(objValue);
  3083. }
  3084. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3085. isCommon = false;
  3086. newValue = baseClone(srcValue, true);
  3087. }
  3088. else {
  3089. newValue = objValue;
  3090. }
  3091. }
  3092. else {
  3093. isCommon = false;
  3094. }
  3095. }
  3096. if (isCommon) {
  3097. // Recursively merge objects and arrays (susceptible to call stack limits).
  3098. stack.set(srcValue, newValue);
  3099. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3100. stack['delete'](srcValue);
  3101. }
  3102. assignMergeValue(object, key, newValue);
  3103. }
  3104. /**
  3105. * The base implementation of `_.nth` which doesn't coerce arguments.
  3106. *
  3107. * @private
  3108. * @param {Array} array The array to query.
  3109. * @param {number} n The index of the element to return.
  3110. * @returns {*} Returns the nth element of `array`.
  3111. */
  3112. function baseNth(array, n) {
  3113. var length = array.length;
  3114. if (!length) {
  3115. return;
  3116. }
  3117. n += n < 0 ? length : 0;
  3118. return isIndex(n, length) ? array[n] : undefined;
  3119. }
  3120. /**
  3121. * The base implementation of `_.orderBy` without param guards.
  3122. *
  3123. * @private
  3124. * @param {Array|Object} collection The collection to iterate over.
  3125. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3126. * @param {string[]} orders The sort orders of `iteratees`.
  3127. * @returns {Array} Returns the new sorted array.
  3128. */
  3129. function baseOrderBy(collection, iteratees, orders) {
  3130. var index = -1;
  3131. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3132. var result = baseMap(collection, function(value, key, collection) {
  3133. var criteria = arrayMap(iteratees, function(iteratee) {
  3134. return iteratee(value);
  3135. });
  3136. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3137. });
  3138. return baseSortBy(result, function(object, other) {
  3139. return compareMultiple(object, other, orders);
  3140. });
  3141. }
  3142. /**
  3143. * The base implementation of `_.pick` without support for individual
  3144. * property identifiers.
  3145. *
  3146. * @private
  3147. * @param {Object} object The source object.
  3148. * @param {string[]} props The property identifiers to pick.
  3149. * @returns {Object} Returns the new object.
  3150. */
  3151. function basePick(object, props) {
  3152. object = Object(object);
  3153. return basePickBy(object, props, function(value, key) {
  3154. return key in object;
  3155. });
  3156. }
  3157. /**
  3158. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3159. *
  3160. * @private
  3161. * @param {Object} object The source object.
  3162. * @param {string[]} props The property identifiers to pick from.
  3163. * @param {Function} predicate The function invoked per property.
  3164. * @returns {Object} Returns the new object.
  3165. */
  3166. function basePickBy(object, props, predicate) {
  3167. var index = -1,
  3168. length = props.length,
  3169. result = {};
  3170. while (++index < length) {
  3171. var key = props[index],
  3172. value = object[key];
  3173. if (predicate(value, key)) {
  3174. result[key] = value;
  3175. }
  3176. }
  3177. return result;
  3178. }
  3179. /**
  3180. * A specialized version of `baseProperty` which supports deep paths.
  3181. *
  3182. * @private
  3183. * @param {Array|string} path The path of the property to get.
  3184. * @returns {Function} Returns the new accessor function.
  3185. */
  3186. function basePropertyDeep(path) {
  3187. return function(object) {
  3188. return baseGet(object, path);
  3189. };
  3190. }
  3191. /**
  3192. * The base implementation of `_.pullAllBy` without support for iteratee
  3193. * shorthands.
  3194. *
  3195. * @private
  3196. * @param {Array} array The array to modify.
  3197. * @param {Array} values The values to remove.
  3198. * @param {Function} [iteratee] The iteratee invoked per element.
  3199. * @param {Function} [comparator] The comparator invoked per element.
  3200. * @returns {Array} Returns `array`.
  3201. */
  3202. function basePullAll(array, values, iteratee, comparator) {
  3203. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3204. index = -1,
  3205. length = values.length,
  3206. seen = array;
  3207. if (array === values) {
  3208. values = copyArray(values);
  3209. }
  3210. if (iteratee) {
  3211. seen = arrayMap(array, baseUnary(iteratee));
  3212. }
  3213. while (++index < length) {
  3214. var fromIndex = 0,
  3215. value = values[index],
  3216. computed = iteratee ? iteratee(value) : value;
  3217. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3218. if (seen !== array) {
  3219. splice.call(seen, fromIndex, 1);
  3220. }
  3221. splice.call(array, fromIndex, 1);
  3222. }
  3223. }
  3224. return array;
  3225. }
  3226. /**
  3227. * The base implementation of `_.pullAt` without support for individual
  3228. * indexes or capturing the removed elements.
  3229. *
  3230. * @private
  3231. * @param {Array} array The array to modify.
  3232. * @param {number[]} indexes The indexes of elements to remove.
  3233. * @returns {Array} Returns `array`.
  3234. */
  3235. function basePullAt(array, indexes) {
  3236. var length = array ? indexes.length : 0,
  3237. lastIndex = length - 1;
  3238. while (length--) {
  3239. var index = indexes[length];
  3240. if (length == lastIndex || index !== previous) {
  3241. var previous = index;
  3242. if (isIndex(index)) {
  3243. splice.call(array, index, 1);
  3244. }
  3245. else if (!isKey(index, array)) {
  3246. var path = castPath(index),
  3247. object = parent(array, path);
  3248. if (object != null) {
  3249. delete object[toKey(last(path))];
  3250. }
  3251. }
  3252. else {
  3253. delete array[toKey(index)];
  3254. }
  3255. }
  3256. }
  3257. return array;
  3258. }
  3259. /**
  3260. * The base implementation of `_.random` without support for returning
  3261. * floating-point numbers.
  3262. *
  3263. * @private
  3264. * @param {number} lower The lower bound.
  3265. * @param {number} upper The upper bound.
  3266. * @returns {number} Returns the random number.
  3267. */
  3268. function baseRandom(lower, upper) {
  3269. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3270. }
  3271. /**
  3272. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3273. * coerce arguments.
  3274. *
  3275. * @private
  3276. * @param {number} start The start of the range.
  3277. * @param {number} end The end of the range.
  3278. * @param {number} step The value to increment or decrement by.
  3279. * @param {boolean} [fromRight] Specify iterating from right to left.
  3280. * @returns {Array} Returns the range of numbers.
  3281. */
  3282. function baseRange(start, end, step, fromRight) {
  3283. var index = -1,
  3284. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3285. result = Array(length);
  3286. while (length--) {
  3287. result[fromRight ? length : ++index] = start;
  3288. start += step;
  3289. }
  3290. return result;
  3291. }
  3292. /**
  3293. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3294. *
  3295. * @private
  3296. * @param {string} string The string to repeat.
  3297. * @param {number} n The number of times to repeat the string.
  3298. * @returns {string} Returns the repeated string.
  3299. */
  3300. function baseRepeat(string, n) {
  3301. var result = '';
  3302. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3303. return result;
  3304. }
  3305. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3306. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3307. do {
  3308. if (n % 2) {
  3309. result += string;
  3310. }
  3311. n = nativeFloor(n / 2);
  3312. if (n) {
  3313. string += string;
  3314. }
  3315. } while (n);
  3316. return result;
  3317. }
  3318. /**
  3319. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3320. *
  3321. * @private
  3322. * @param {Function} func The function to apply a rest parameter to.
  3323. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3324. * @returns {Function} Returns the new function.
  3325. */
  3326. function baseRest(func, start) {
  3327. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  3328. return function() {
  3329. var args = arguments,
  3330. index = -1,
  3331. length = nativeMax(args.length - start, 0),
  3332. array = Array(length);
  3333. while (++index < length) {
  3334. array[index] = args[start + index];
  3335. }
  3336. index = -1;
  3337. var otherArgs = Array(start + 1);
  3338. while (++index < start) {
  3339. otherArgs[index] = args[index];
  3340. }
  3341. otherArgs[start] = array;
  3342. return apply(func, this, otherArgs);
  3343. };
  3344. }
  3345. /**
  3346. * The base implementation of `_.set`.
  3347. *
  3348. * @private
  3349. * @param {Object} object The object to query.
  3350. * @param {Array|string} path The path of the property to set.
  3351. * @param {*} value The value to set.
  3352. * @param {Function} [customizer] The function to customize path creation.
  3353. * @returns {Object} Returns `object`.
  3354. */
  3355. function baseSet(object, path, value, customizer) {
  3356. path = isKey(path, object) ? [path] : castPath(path);
  3357. var index = -1,
  3358. length = path.length,
  3359. lastIndex = length - 1,
  3360. nested = object;
  3361. while (nested != null && ++index < length) {
  3362. var key = toKey(path[index]);
  3363. if (isObject(nested)) {
  3364. var newValue = value;
  3365. if (index != lastIndex) {
  3366. var objValue = nested[key];
  3367. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3368. if (newValue === undefined) {
  3369. newValue = objValue == null
  3370. ? (isIndex(path[index + 1]) ? [] : {})
  3371. : objValue;
  3372. }
  3373. }
  3374. assignValue(nested, key, newValue);
  3375. }
  3376. nested = nested[key];
  3377. }
  3378. return object;
  3379. }
  3380. /**
  3381. * The base implementation of `setData` without support for hot loop detection.
  3382. *
  3383. * @private
  3384. * @param {Function} func The function to associate metadata with.
  3385. * @param {*} data The metadata.
  3386. * @returns {Function} Returns `func`.
  3387. */
  3388. var baseSetData = !metaMap ? identity : function(func, data) {
  3389. metaMap.set(func, data);
  3390. return func;
  3391. };
  3392. /**
  3393. * The base implementation of `_.slice` without an iteratee call guard.
  3394. *
  3395. * @private
  3396. * @param {Array} array The array to slice.
  3397. * @param {number} [start=0] The start position.
  3398. * @param {number} [end=array.length] The end position.
  3399. * @returns {Array} Returns the slice of `array`.
  3400. */
  3401. function baseSlice(array, start, end) {
  3402. var index = -1,
  3403. length = array.length;
  3404. if (start < 0) {
  3405. start = -start > length ? 0 : (length + start);
  3406. }
  3407. end = end > length ? length : end;
  3408. if (end < 0) {
  3409. end += length;
  3410. }
  3411. length = start > end ? 0 : ((end - start) >>> 0);
  3412. start >>>= 0;
  3413. var result = Array(length);
  3414. while (++index < length) {
  3415. result[index] = array[index + start];
  3416. }
  3417. return result;
  3418. }
  3419. /**
  3420. * The base implementation of `_.some` without support for iteratee shorthands.
  3421. *
  3422. * @private
  3423. * @param {Array|Object} collection The collection to iterate over.
  3424. * @param {Function} predicate The function invoked per iteration.
  3425. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3426. * else `false`.
  3427. */
  3428. function baseSome(collection, predicate) {
  3429. var result;
  3430. baseEach(collection, function(value, index, collection) {
  3431. result = predicate(value, index, collection);
  3432. return !result;
  3433. });
  3434. return !!result;
  3435. }
  3436. /**
  3437. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3438. * performs a binary search of `array` to determine the index at which `value`
  3439. * should be inserted into `array` in order to maintain its sort order.
  3440. *
  3441. * @private
  3442. * @param {Array} array The sorted array to inspect.
  3443. * @param {*} value The value to evaluate.
  3444. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3445. * @returns {number} Returns the index at which `value` should be inserted
  3446. * into `array`.
  3447. */
  3448. function baseSortedIndex(array, value, retHighest) {
  3449. var low = 0,
  3450. high = array ? array.length : low;
  3451. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3452. while (low < high) {
  3453. var mid = (low + high) >>> 1,
  3454. computed = array[mid];
  3455. if (computed !== null && !isSymbol(computed) &&
  3456. (retHighest ? (computed <= value) : (computed < value))) {
  3457. low = mid + 1;
  3458. } else {
  3459. high = mid;
  3460. }
  3461. }
  3462. return high;
  3463. }
  3464. return baseSortedIndexBy(array, value, identity, retHighest);
  3465. }
  3466. /**
  3467. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3468. * which invokes `iteratee` for `value` and each element of `array` to compute
  3469. * their sort ranking. The iteratee is invoked with one argument; (value).
  3470. *
  3471. * @private
  3472. * @param {Array} array The sorted array to inspect.
  3473. * @param {*} value The value to evaluate.
  3474. * @param {Function} iteratee The iteratee invoked per element.
  3475. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3476. * @returns {number} Returns the index at which `value` should be inserted
  3477. * into `array`.
  3478. */
  3479. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3480. value = iteratee(value);
  3481. var low = 0,
  3482. high = array ? array.length : 0,
  3483. valIsNaN = value !== value,
  3484. valIsNull = value === null,
  3485. valIsSymbol = isSymbol(value),
  3486. valIsUndefined = value === undefined;
  3487. while (low < high) {
  3488. var mid = nativeFloor((low + high) / 2),
  3489. computed = iteratee(array[mid]),
  3490. othIsDefined = computed !== undefined,
  3491. othIsNull = computed === null,
  3492. othIsReflexive = computed === computed,
  3493. othIsSymbol = isSymbol(computed);
  3494. if (valIsNaN) {
  3495. var setLow = retHighest || othIsReflexive;
  3496. } else if (valIsUndefined) {
  3497. setLow = othIsReflexive && (retHighest || othIsDefined);
  3498. } else if (valIsNull) {
  3499. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3500. } else if (valIsSymbol) {
  3501. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3502. } else if (othIsNull || othIsSymbol) {
  3503. setLow = false;
  3504. } else {
  3505. setLow = retHighest ? (computed <= value) : (computed < value);
  3506. }
  3507. if (setLow) {
  3508. low = mid + 1;
  3509. } else {
  3510. high = mid;
  3511. }
  3512. }
  3513. return nativeMin(high, MAX_ARRAY_INDEX);
  3514. }
  3515. /**
  3516. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3517. * support for iteratee shorthands.
  3518. *
  3519. * @private
  3520. * @param {Array} array The array to inspect.
  3521. * @param {Function} [iteratee] The iteratee invoked per element.
  3522. * @returns {Array} Returns the new duplicate free array.
  3523. */
  3524. function baseSortedUniq(array, iteratee) {
  3525. var index = -1,
  3526. length = array.length,
  3527. resIndex = 0,
  3528. result = [];
  3529. while (++index < length) {
  3530. var value = array[index],
  3531. computed = iteratee ? iteratee(value) : value;
  3532. if (!index || !eq(computed, seen)) {
  3533. var seen = computed;
  3534. result[resIndex++] = value === 0 ? 0 : value;
  3535. }
  3536. }
  3537. return result;
  3538. }
  3539. /**
  3540. * The base implementation of `_.toNumber` which doesn't ensure correct
  3541. * conversions of binary, hexadecimal, or octal string values.
  3542. *
  3543. * @private
  3544. * @param {*} value The value to process.
  3545. * @returns {number} Returns the number.
  3546. */
  3547. function baseToNumber(value) {
  3548. if (typeof value == 'number') {
  3549. return value;
  3550. }
  3551. if (isSymbol(value)) {
  3552. return NAN;
  3553. }
  3554. return +value;
  3555. }
  3556. /**
  3557. * The base implementation of `_.toString` which doesn't convert nullish
  3558. * values to empty strings.
  3559. *
  3560. * @private
  3561. * @param {*} value The value to process.
  3562. * @returns {string} Returns the string.
  3563. */
  3564. function baseToString(value) {
  3565. // Exit early for strings to avoid a performance hit in some environments.
  3566. if (typeof value == 'string') {
  3567. return value;
  3568. }
  3569. if (isSymbol(value)) {
  3570. return symbolToString ? symbolToString.call(value) : '';
  3571. }
  3572. var result = (value + '');
  3573. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3574. }
  3575. /**
  3576. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3577. *
  3578. * @private
  3579. * @param {Array} array The array to inspect.
  3580. * @param {Function} [iteratee] The iteratee invoked per element.
  3581. * @param {Function} [comparator] The comparator invoked per element.
  3582. * @returns {Array} Returns the new duplicate free array.
  3583. */
  3584. function baseUniq(array, iteratee, comparator) {
  3585. var index = -1,
  3586. includes = arrayIncludes,
  3587. length = array.length,
  3588. isCommon = true,
  3589. result = [],
  3590. seen = result;
  3591. if (comparator) {
  3592. isCommon = false;
  3593. includes = arrayIncludesWith;
  3594. }
  3595. else if (length >= LARGE_ARRAY_SIZE) {
  3596. var set = iteratee ? null : createSet(array);
  3597. if (set) {
  3598. return setToArray(set);
  3599. }
  3600. isCommon = false;
  3601. includes = cacheHas;
  3602. seen = new SetCache;
  3603. }
  3604. else {
  3605. seen = iteratee ? [] : result;
  3606. }
  3607. outer:
  3608. while (++index < length) {
  3609. var value = array[index],
  3610. computed = iteratee ? iteratee(value) : value;
  3611. value = (comparator || value !== 0) ? value : 0;
  3612. if (isCommon && computed === computed) {
  3613. var seenIndex = seen.length;
  3614. while (seenIndex--) {
  3615. if (seen[seenIndex] === computed) {
  3616. continue outer;
  3617. }
  3618. }
  3619. if (iteratee) {
  3620. seen.push(computed);
  3621. }
  3622. result.push(value);
  3623. }
  3624. else if (!includes(seen, computed, comparator)) {
  3625. if (seen !== result) {
  3626. seen.push(computed);
  3627. }
  3628. result.push(value);
  3629. }
  3630. }
  3631. return result;
  3632. }
  3633. /**
  3634. * The base implementation of `_.unset`.
  3635. *
  3636. * @private
  3637. * @param {Object} object The object to modify.
  3638. * @param {Array|string} path The path of the property to unset.
  3639. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3640. */
  3641. function baseUnset(object, path) {
  3642. path = isKey(path, object) ? [path] : castPath(path);
  3643. object = parent(object, path);
  3644. var key = toKey(last(path));
  3645. return !(object != null && baseHas(object, key)) || delete object[key];
  3646. }
  3647. /**
  3648. * The base implementation of `_.update`.
  3649. *
  3650. * @private
  3651. * @param {Object} object The object to query.
  3652. * @param {Array|string} path The path of the property to update.
  3653. * @param {Function} updater The function to produce the updated value.
  3654. * @param {Function} [customizer] The function to customize path creation.
  3655. * @returns {Object} Returns `object`.
  3656. */
  3657. function baseUpdate(object, path, updater, customizer) {
  3658. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3659. }
  3660. /**
  3661. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3662. * without support for iteratee shorthands.
  3663. *
  3664. * @private
  3665. * @param {Array} array The array to query.
  3666. * @param {Function} predicate The function invoked per iteration.
  3667. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3668. * @param {boolean} [fromRight] Specify iterating from right to left.
  3669. * @returns {Array} Returns the slice of `array`.
  3670. */
  3671. function baseWhile(array, predicate, isDrop, fromRight) {
  3672. var length = array.length,
  3673. index = fromRight ? length : -1;
  3674. while ((fromRight ? index-- : ++index < length) &&
  3675. predicate(array[index], index, array)) {}
  3676. return isDrop
  3677. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3678. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3679. }
  3680. /**
  3681. * The base implementation of `wrapperValue` which returns the result of
  3682. * performing a sequence of actions on the unwrapped `value`, where each
  3683. * successive action is supplied the return value of the previous.
  3684. *
  3685. * @private
  3686. * @param {*} value The unwrapped value.
  3687. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3688. * @returns {*} Returns the resolved value.
  3689. */
  3690. function baseWrapperValue(value, actions) {
  3691. var result = value;
  3692. if (result instanceof LazyWrapper) {
  3693. result = result.value();
  3694. }
  3695. return arrayReduce(actions, function(result, action) {
  3696. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3697. }, result);
  3698. }
  3699. /**
  3700. * The base implementation of methods like `_.xor`, without support for
  3701. * iteratee shorthands, that accepts an array of arrays to inspect.
  3702. *
  3703. * @private
  3704. * @param {Array} arrays The arrays to inspect.
  3705. * @param {Function} [iteratee] The iteratee invoked per element.
  3706. * @param {Function} [comparator] The comparator invoked per element.
  3707. * @returns {Array} Returns the new array of values.
  3708. */
  3709. function baseXor(arrays, iteratee, comparator) {
  3710. var index = -1,
  3711. length = arrays.length;
  3712. while (++index < length) {
  3713. var result = result
  3714. ? arrayPush(
  3715. baseDifference(result, arrays[index], iteratee, comparator),
  3716. baseDifference(arrays[index], result, iteratee, comparator)
  3717. )
  3718. : arrays[index];
  3719. }
  3720. return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
  3721. }
  3722. /**
  3723. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  3724. *
  3725. * @private
  3726. * @param {Array} props The property identifiers.
  3727. * @param {Array} values The property values.
  3728. * @param {Function} assignFunc The function to assign values.
  3729. * @returns {Object} Returns the new object.
  3730. */
  3731. function baseZipObject(props, values, assignFunc) {
  3732. var index = -1,
  3733. length = props.length,
  3734. valsLength = values.length,
  3735. result = {};
  3736. while (++index < length) {
  3737. var value = index < valsLength ? values[index] : undefined;
  3738. assignFunc(result, props[index], value);
  3739. }
  3740. return result;
  3741. }
  3742. /**
  3743. * Casts `value` to an empty array if it's not an array like object.
  3744. *
  3745. * @private
  3746. * @param {*} value The value to inspect.
  3747. * @returns {Array|Object} Returns the cast array-like object.
  3748. */
  3749. function castArrayLikeObject(value) {
  3750. return isArrayLikeObject(value) ? value : [];
  3751. }
  3752. /**
  3753. * Casts `value` to `identity` if it's not a function.
  3754. *
  3755. * @private
  3756. * @param {*} value The value to inspect.
  3757. * @returns {Function} Returns cast function.
  3758. */
  3759. function castFunction(value) {
  3760. return typeof value == 'function' ? value : identity;
  3761. }
  3762. /**
  3763. * Casts `value` to a path array if it's not one.
  3764. *
  3765. * @private
  3766. * @param {*} value The value to inspect.
  3767. * @returns {Array} Returns the cast property path array.
  3768. */
  3769. function castPath(value) {
  3770. return isArray(value) ? value : stringToPath(value);
  3771. }
  3772. /**
  3773. * Casts `array` to a slice if it's needed.
  3774. *
  3775. * @private
  3776. * @param {Array} array The array to inspect.
  3777. * @param {number} start The start position.
  3778. * @param {number} [end=array.length] The end position.
  3779. * @returns {Array} Returns the cast slice.
  3780. */
  3781. function castSlice(array, start, end) {
  3782. var length = array.length;
  3783. end = end === undefined ? length : end;
  3784. return (!start && end >= length) ? array : baseSlice(array, start, end);
  3785. }
  3786. /**
  3787. * Creates a clone of `buffer`.
  3788. *
  3789. * @private
  3790. * @param {Buffer} buffer The buffer to clone.
  3791. * @param {boolean} [isDeep] Specify a deep clone.
  3792. * @returns {Buffer} Returns the cloned buffer.
  3793. */
  3794. function cloneBuffer(buffer, isDeep) {
  3795. if (isDeep) {
  3796. return buffer.slice();
  3797. }
  3798. var result = new buffer.constructor(buffer.length);
  3799. buffer.copy(result);
  3800. return result;
  3801. }
  3802. /**
  3803. * Creates a clone of `arrayBuffer`.
  3804. *
  3805. * @private
  3806. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  3807. * @returns {ArrayBuffer} Returns the cloned array buffer.
  3808. */
  3809. function cloneArrayBuffer(arrayBuffer) {
  3810. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  3811. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  3812. return result;
  3813. }
  3814. /**
  3815. * Creates a clone of `dataView`.
  3816. *
  3817. * @private
  3818. * @param {Object} dataView The data view to clone.
  3819. * @param {boolean} [isDeep] Specify a deep clone.
  3820. * @returns {Object} Returns the cloned data view.
  3821. */
  3822. function cloneDataView(dataView, isDeep) {
  3823. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  3824. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  3825. }
  3826. /**
  3827. * Creates a clone of `map`.
  3828. *
  3829. * @private
  3830. * @param {Object} map The map to clone.
  3831. * @param {Function} cloneFunc The function to clone values.
  3832. * @param {boolean} [isDeep] Specify a deep clone.
  3833. * @returns {Object} Returns the cloned map.
  3834. */
  3835. function cloneMap(map, isDeep, cloneFunc) {
  3836. var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
  3837. return arrayReduce(array, addMapEntry, new map.constructor);
  3838. }
  3839. /**
  3840. * Creates a clone of `regexp`.
  3841. *
  3842. * @private
  3843. * @param {Object} regexp The regexp to clone.
  3844. * @returns {Object} Returns the cloned regexp.
  3845. */
  3846. function cloneRegExp(regexp) {
  3847. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  3848. result.lastIndex = regexp.lastIndex;
  3849. return result;
  3850. }
  3851. /**
  3852. * Creates a clone of `set`.
  3853. *
  3854. * @private
  3855. * @param {Object} set The set to clone.
  3856. * @param {Function} cloneFunc The function to clone values.
  3857. * @param {boolean} [isDeep] Specify a deep clone.
  3858. * @returns {Object} Returns the cloned set.
  3859. */
  3860. function cloneSet(set, isDeep, cloneFunc) {
  3861. var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
  3862. return arrayReduce(array, addSetEntry, new set.constructor);
  3863. }
  3864. /**
  3865. * Creates a clone of the `symbol` object.
  3866. *
  3867. * @private
  3868. * @param {Object} symbol The symbol object to clone.
  3869. * @returns {Object} Returns the cloned symbol object.
  3870. */
  3871. function cloneSymbol(symbol) {
  3872. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  3873. }
  3874. /**
  3875. * Creates a clone of `typedArray`.
  3876. *
  3877. * @private
  3878. * @param {Object} typedArray The typed array to clone.
  3879. * @param {boolean} [isDeep] Specify a deep clone.
  3880. * @returns {Object} Returns the cloned typed array.
  3881. */
  3882. function cloneTypedArray(typedArray, isDeep) {
  3883. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  3884. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  3885. }
  3886. /**
  3887. * Compares values to sort them in ascending order.
  3888. *
  3889. * @private
  3890. * @param {*} value The value to compare.
  3891. * @param {*} other The other value to compare.
  3892. * @returns {number} Returns the sort order indicator for `value`.
  3893. */
  3894. function compareAscending(value, other) {
  3895. if (value !== other) {
  3896. var valIsDefined = value !== undefined,
  3897. valIsNull = value === null,
  3898. valIsReflexive = value === value,
  3899. valIsSymbol = isSymbol(value);
  3900. var othIsDefined = other !== undefined,
  3901. othIsNull = other === null,
  3902. othIsReflexive = other === other,
  3903. othIsSymbol = isSymbol(other);
  3904. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  3905. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  3906. (valIsNull && othIsDefined && othIsReflexive) ||
  3907. (!valIsDefined && othIsReflexive) ||
  3908. !valIsReflexive) {
  3909. return 1;
  3910. }
  3911. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  3912. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  3913. (othIsNull && valIsDefined && valIsReflexive) ||
  3914. (!othIsDefined && valIsReflexive) ||
  3915. !othIsReflexive) {
  3916. return -1;
  3917. }
  3918. }
  3919. return 0;
  3920. }
  3921. /**
  3922. * Used by `_.orderBy` to compare multiple properties of a value to another
  3923. * and stable sort them.
  3924. *
  3925. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  3926. * specify an order of "desc" for descending or "asc" for ascending sort order
  3927. * of corresponding values.
  3928. *
  3929. * @private
  3930. * @param {Object} object The object to compare.
  3931. * @param {Object} other The other object to compare.
  3932. * @param {boolean[]|string[]} orders The order to sort by for each property.
  3933. * @returns {number} Returns the sort order indicator for `object`.
  3934. */
  3935. function compareMultiple(object, other, orders) {
  3936. var index = -1,
  3937. objCriteria = object.criteria,
  3938. othCriteria = other.criteria,
  3939. length = objCriteria.length,
  3940. ordersLength = orders.length;
  3941. while (++index < length) {
  3942. var result = compareAscending(objCriteria[index], othCriteria[index]);
  3943. if (result) {
  3944. if (index >= ordersLength) {
  3945. return result;
  3946. }
  3947. var order = orders[index];
  3948. return result * (order == 'desc' ? -1 : 1);
  3949. }
  3950. }
  3951. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  3952. // that causes it, under certain circumstances, to provide the same value for
  3953. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  3954. // for more details.
  3955. //
  3956. // This also ensures a stable sort in V8 and other engines.
  3957. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  3958. return object.index - other.index;
  3959. }
  3960. /**
  3961. * Creates an array that is the composition of partially applied arguments,
  3962. * placeholders, and provided arguments into a single array of arguments.
  3963. *
  3964. * @private
  3965. * @param {Array} args The provided arguments.
  3966. * @param {Array} partials The arguments to prepend to those provided.
  3967. * @param {Array} holders The `partials` placeholder indexes.
  3968. * @params {boolean} [isCurried] Specify composing for a curried function.
  3969. * @returns {Array} Returns the new array of composed arguments.
  3970. */
  3971. function composeArgs(args, partials, holders, isCurried) {
  3972. var argsIndex = -1,
  3973. argsLength = args.length,
  3974. holdersLength = holders.length,
  3975. leftIndex = -1,
  3976. leftLength = partials.length,
  3977. rangeLength = nativeMax(argsLength - holdersLength, 0),
  3978. result = Array(leftLength + rangeLength),
  3979. isUncurried = !isCurried;
  3980. while (++leftIndex < leftLength) {
  3981. result[leftIndex] = partials[leftIndex];
  3982. }
  3983. while (++argsIndex < holdersLength) {
  3984. if (isUncurried || argsIndex < argsLength) {
  3985. result[holders[argsIndex]] = args[argsIndex];
  3986. }
  3987. }
  3988. while (rangeLength--) {
  3989. result[leftIndex++] = args[argsIndex++];
  3990. }
  3991. return result;
  3992. }
  3993. /**
  3994. * This function is like `composeArgs` except that the arguments composition
  3995. * is tailored for `_.partialRight`.
  3996. *
  3997. * @private
  3998. * @param {Array} args The provided arguments.
  3999. * @param {Array} partials The arguments to append to those provided.
  4000. * @param {Array} holders The `partials` placeholder indexes.
  4001. * @params {boolean} [isCurried] Specify composing for a curried function.
  4002. * @returns {Array} Returns the new array of composed arguments.
  4003. */
  4004. function composeArgsRight(args, partials, holders, isCurried) {
  4005. var argsIndex = -1,
  4006. argsLength = args.length,
  4007. holdersIndex = -1,
  4008. holdersLength = holders.length,
  4009. rightIndex = -1,
  4010. rightLength = partials.length,
  4011. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4012. result = Array(rangeLength + rightLength),
  4013. isUncurried = !isCurried;
  4014. while (++argsIndex < rangeLength) {
  4015. result[argsIndex] = args[argsIndex];
  4016. }
  4017. var offset = argsIndex;
  4018. while (++rightIndex < rightLength) {
  4019. result[offset + rightIndex] = partials[rightIndex];
  4020. }
  4021. while (++holdersIndex < holdersLength) {
  4022. if (isUncurried || argsIndex < argsLength) {
  4023. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4024. }
  4025. }
  4026. return result;
  4027. }
  4028. /**
  4029. * Copies the values of `source` to `array`.
  4030. *
  4031. * @private
  4032. * @param {Array} source The array to copy values from.
  4033. * @param {Array} [array=[]] The array to copy values to.
  4034. * @returns {Array} Returns `array`.
  4035. */
  4036. function copyArray(source, array) {
  4037. var index = -1,
  4038. length = source.length;
  4039. array || (array = Array(length));
  4040. while (++index < length) {
  4041. array[index] = source[index];
  4042. }
  4043. return array;
  4044. }
  4045. /**
  4046. * Copies properties of `source` to `object`.
  4047. *
  4048. * @private
  4049. * @param {Object} source The object to copy properties from.
  4050. * @param {Array} props The property identifiers to copy.
  4051. * @param {Object} [object={}] The object to copy properties to.
  4052. * @param {Function} [customizer] The function to customize copied values.
  4053. * @returns {Object} Returns `object`.
  4054. */
  4055. function copyObject(source, props, object, customizer) {
  4056. object || (object = {});
  4057. var index = -1,
  4058. length = props.length;
  4059. while (++index < length) {
  4060. var key = props[index];
  4061. var newValue = customizer
  4062. ? customizer(object[key], source[key], key, object, source)
  4063. : undefined;
  4064. assignValue(object, key, newValue === undefined ? source[key] : newValue);
  4065. }
  4066. return object;
  4067. }
  4068. /**
  4069. * Copies own symbol properties of `source` to `object`.
  4070. *
  4071. * @private
  4072. * @param {Object} source The object to copy symbols from.
  4073. * @param {Object} [object={}] The object to copy symbols to.
  4074. * @returns {Object} Returns `object`.
  4075. */
  4076. function copySymbols(source, object) {
  4077. return copyObject(source, getSymbols(source), object);
  4078. }
  4079. /**
  4080. * Creates a function like `_.groupBy`.
  4081. *
  4082. * @private
  4083. * @param {Function} setter The function to set accumulator values.
  4084. * @param {Function} [initializer] The accumulator object initializer.
  4085. * @returns {Function} Returns the new aggregator function.
  4086. */
  4087. function createAggregator(setter, initializer) {
  4088. return function(collection, iteratee) {
  4089. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4090. accumulator = initializer ? initializer() : {};
  4091. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4092. };
  4093. }
  4094. /**
  4095. * Creates a function like `_.assign`.
  4096. *
  4097. * @private
  4098. * @param {Function} assigner The function to assign values.
  4099. * @returns {Function} Returns the new assigner function.
  4100. */
  4101. function createAssigner(assigner) {
  4102. return baseRest(function(object, sources) {
  4103. var index = -1,
  4104. length = sources.length,
  4105. customizer = length > 1 ? sources[length - 1] : undefined,
  4106. guard = length > 2 ? sources[2] : undefined;
  4107. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4108. ? (length--, customizer)
  4109. : undefined;
  4110. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4111. customizer = length < 3 ? undefined : customizer;
  4112. length = 1;
  4113. }
  4114. object = Object(object);
  4115. while (++index < length) {
  4116. var source = sources[index];
  4117. if (source) {
  4118. assigner(object, source, index, customizer);
  4119. }
  4120. }
  4121. return object;
  4122. });
  4123. }
  4124. /**
  4125. * Creates a `baseEach` or `baseEachRight` function.
  4126. *
  4127. * @private
  4128. * @param {Function} eachFunc The function to iterate over a collection.
  4129. * @param {boolean} [fromRight] Specify iterating from right to left.
  4130. * @returns {Function} Returns the new base function.
  4131. */
  4132. function createBaseEach(eachFunc, fromRight) {
  4133. return function(collection, iteratee) {
  4134. if (collection == null) {
  4135. return collection;
  4136. }
  4137. if (!isArrayLike(collection)) {
  4138. return eachFunc(collection, iteratee);
  4139. }
  4140. var length = collection.length,
  4141. index = fromRight ? length : -1,
  4142. iterable = Object(collection);
  4143. while ((fromRight ? index-- : ++index < length)) {
  4144. if (iteratee(iterable[index], index, iterable) === false) {
  4145. break;
  4146. }
  4147. }
  4148. return collection;
  4149. };
  4150. }
  4151. /**
  4152. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4153. *
  4154. * @private
  4155. * @param {boolean} [fromRight] Specify iterating from right to left.
  4156. * @returns {Function} Returns the new base function.
  4157. */
  4158. function createBaseFor(fromRight) {
  4159. return function(object, iteratee, keysFunc) {
  4160. var index = -1,
  4161. iterable = Object(object),
  4162. props = keysFunc(object),
  4163. length = props.length;
  4164. while (length--) {
  4165. var key = props[fromRight ? length : ++index];
  4166. if (iteratee(iterable[key], key, iterable) === false) {
  4167. break;
  4168. }
  4169. }
  4170. return object;
  4171. };
  4172. }
  4173. /**
  4174. * Creates a function that wraps `func` to invoke it with the optional `this`
  4175. * binding of `thisArg`.
  4176. *
  4177. * @private
  4178. * @param {Function} func The function to wrap.
  4179. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4180. * @param {*} [thisArg] The `this` binding of `func`.
  4181. * @returns {Function} Returns the new wrapped function.
  4182. */
  4183. function createBind(func, bitmask, thisArg) {
  4184. var isBind = bitmask & BIND_FLAG,
  4185. Ctor = createCtor(func);
  4186. function wrapper() {
  4187. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4188. return fn.apply(isBind ? thisArg : this, arguments);
  4189. }
  4190. return wrapper;
  4191. }
  4192. /**
  4193. * Creates a function like `_.lowerFirst`.
  4194. *
  4195. * @private
  4196. * @param {string} methodName The name of the `String` case method to use.
  4197. * @returns {Function} Returns the new case function.
  4198. */
  4199. function createCaseFirst(methodName) {
  4200. return function(string) {
  4201. string = toString(string);
  4202. var strSymbols = reHasComplexSymbol.test(string)
  4203. ? stringToArray(string)
  4204. : undefined;
  4205. var chr = strSymbols
  4206. ? strSymbols[0]
  4207. : string.charAt(0);
  4208. var trailing = strSymbols
  4209. ? castSlice(strSymbols, 1).join('')
  4210. : string.slice(1);
  4211. return chr[methodName]() + trailing;
  4212. };
  4213. }
  4214. /**
  4215. * Creates a function like `_.camelCase`.
  4216. *
  4217. * @private
  4218. * @param {Function} callback The function to combine each word.
  4219. * @returns {Function} Returns the new compounder function.
  4220. */
  4221. function createCompounder(callback) {
  4222. return function(string) {
  4223. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4224. };
  4225. }
  4226. /**
  4227. * Creates a function that produces an instance of `Ctor` regardless of
  4228. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4229. *
  4230. * @private
  4231. * @param {Function} Ctor The constructor to wrap.
  4232. * @returns {Function} Returns the new wrapped function.
  4233. */
  4234. function createCtor(Ctor) {
  4235. return function() {
  4236. // Use a `switch` statement to work with class constructors. See
  4237. // http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4238. // for more details.
  4239. var args = arguments;
  4240. switch (args.length) {
  4241. case 0: return new Ctor;
  4242. case 1: return new Ctor(args[0]);
  4243. case 2: return new Ctor(args[0], args[1]);
  4244. case 3: return new Ctor(args[0], args[1], args[2]);
  4245. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4246. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4247. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4248. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4249. }
  4250. var thisBinding = baseCreate(Ctor.prototype),
  4251. result = Ctor.apply(thisBinding, args);
  4252. // Mimic the constructor's `return` behavior.
  4253. // See https://es5.github.io/#x13.2.2 for more details.
  4254. return isObject(result) ? result : thisBinding;
  4255. };
  4256. }
  4257. /**
  4258. * Creates a function that wraps `func` to enable currying.
  4259. *
  4260. * @private
  4261. * @param {Function} func The function to wrap.
  4262. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4263. * @param {number} arity The arity of `func`.
  4264. * @returns {Function} Returns the new wrapped function.
  4265. */
  4266. function createCurry(func, bitmask, arity) {
  4267. var Ctor = createCtor(func);
  4268. function wrapper() {
  4269. var length = arguments.length,
  4270. args = Array(length),
  4271. index = length,
  4272. placeholder = getHolder(wrapper);
  4273. while (index--) {
  4274. args[index] = arguments[index];
  4275. }
  4276. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4277. ? []
  4278. : replaceHolders(args, placeholder);
  4279. length -= holders.length;
  4280. if (length < arity) {
  4281. return createRecurry(
  4282. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4283. args, holders, undefined, undefined, arity - length);
  4284. }
  4285. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4286. return apply(fn, this, args);
  4287. }
  4288. return wrapper;
  4289. }
  4290. /**
  4291. * Creates a `_.find` or `_.findLast` function.
  4292. *
  4293. * @private
  4294. * @param {Function} findIndexFunc The function to find the collection index.
  4295. * @returns {Function} Returns the new find function.
  4296. */
  4297. function createFind(findIndexFunc) {
  4298. return function(collection, predicate, fromIndex) {
  4299. var iterable = Object(collection);
  4300. if (!isArrayLike(collection)) {
  4301. var iteratee = getIteratee(predicate, 3);
  4302. collection = keys(collection);
  4303. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4304. }
  4305. var index = findIndexFunc(collection, predicate, fromIndex);
  4306. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4307. };
  4308. }
  4309. /**
  4310. * Creates a `_.flow` or `_.flowRight` function.
  4311. *
  4312. * @private
  4313. * @param {boolean} [fromRight] Specify iterating from right to left.
  4314. * @returns {Function} Returns the new flow function.
  4315. */
  4316. function createFlow(fromRight) {
  4317. return baseRest(function(funcs) {
  4318. funcs = baseFlatten(funcs, 1);
  4319. var length = funcs.length,
  4320. index = length,
  4321. prereq = LodashWrapper.prototype.thru;
  4322. if (fromRight) {
  4323. funcs.reverse();
  4324. }
  4325. while (index--) {
  4326. var func = funcs[index];
  4327. if (typeof func != 'function') {
  4328. throw new TypeError(FUNC_ERROR_TEXT);
  4329. }
  4330. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4331. var wrapper = new LodashWrapper([], true);
  4332. }
  4333. }
  4334. index = wrapper ? index : length;
  4335. while (++index < length) {
  4336. func = funcs[index];
  4337. var funcName = getFuncName(func),
  4338. data = funcName == 'wrapper' ? getData(func) : undefined;
  4339. if (data && isLaziable(data[0]) &&
  4340. data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
  4341. !data[4].length && data[9] == 1
  4342. ) {
  4343. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4344. } else {
  4345. wrapper = (func.length == 1 && isLaziable(func))
  4346. ? wrapper[funcName]()
  4347. : wrapper.thru(func);
  4348. }
  4349. }
  4350. return function() {
  4351. var args = arguments,
  4352. value = args[0];
  4353. if (wrapper && args.length == 1 &&
  4354. isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  4355. return wrapper.plant(value).value();
  4356. }
  4357. var index = 0,
  4358. result = length ? funcs[index].apply(this, args) : value;
  4359. while (++index < length) {
  4360. result = funcs[index].call(this, result);
  4361. }
  4362. return result;
  4363. };
  4364. });
  4365. }
  4366. /**
  4367. * Creates a function that wraps `func` to invoke it with optional `this`
  4368. * binding of `thisArg`, partial application, and currying.
  4369. *
  4370. * @private
  4371. * @param {Function|string} func The function or method name to wrap.
  4372. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4373. * @param {*} [thisArg] The `this` binding of `func`.
  4374. * @param {Array} [partials] The arguments to prepend to those provided to
  4375. * the new function.
  4376. * @param {Array} [holders] The `partials` placeholder indexes.
  4377. * @param {Array} [partialsRight] The arguments to append to those provided
  4378. * to the new function.
  4379. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4380. * @param {Array} [argPos] The argument positions of the new function.
  4381. * @param {number} [ary] The arity cap of `func`.
  4382. * @param {number} [arity] The arity of `func`.
  4383. * @returns {Function} Returns the new wrapped function.
  4384. */
  4385. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4386. var isAry = bitmask & ARY_FLAG,
  4387. isBind = bitmask & BIND_FLAG,
  4388. isBindKey = bitmask & BIND_KEY_FLAG,
  4389. isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
  4390. isFlip = bitmask & FLIP_FLAG,
  4391. Ctor = isBindKey ? undefined : createCtor(func);
  4392. function wrapper() {
  4393. var length = arguments.length,
  4394. args = Array(length),
  4395. index = length;
  4396. while (index--) {
  4397. args[index] = arguments[index];
  4398. }
  4399. if (isCurried) {
  4400. var placeholder = getHolder(wrapper),
  4401. holdersCount = countHolders(args, placeholder);
  4402. }
  4403. if (partials) {
  4404. args = composeArgs(args, partials, holders, isCurried);
  4405. }
  4406. if (partialsRight) {
  4407. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4408. }
  4409. length -= holdersCount;
  4410. if (isCurried && length < arity) {
  4411. var newHolders = replaceHolders(args, placeholder);
  4412. return createRecurry(
  4413. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4414. args, newHolders, argPos, ary, arity - length
  4415. );
  4416. }
  4417. var thisBinding = isBind ? thisArg : this,
  4418. fn = isBindKey ? thisBinding[func] : func;
  4419. length = args.length;
  4420. if (argPos) {
  4421. args = reorder(args, argPos);
  4422. } else if (isFlip && length > 1) {
  4423. args.reverse();
  4424. }
  4425. if (isAry && ary < length) {
  4426. args.length = ary;
  4427. }
  4428. if (this && this !== root && this instanceof wrapper) {
  4429. fn = Ctor || createCtor(fn);
  4430. }
  4431. return fn.apply(thisBinding, args);
  4432. }
  4433. return wrapper;
  4434. }
  4435. /**
  4436. * Creates a function like `_.invertBy`.
  4437. *
  4438. * @private
  4439. * @param {Function} setter The function to set accumulator values.
  4440. * @param {Function} toIteratee The function to resolve iteratees.
  4441. * @returns {Function} Returns the new inverter function.
  4442. */
  4443. function createInverter(setter, toIteratee) {
  4444. return function(object, iteratee) {
  4445. return baseInverter(object, setter, toIteratee(iteratee), {});
  4446. };
  4447. }
  4448. /**
  4449. * Creates a function that performs a mathematical operation on two values.
  4450. *
  4451. * @private
  4452. * @param {Function} operator The function to perform the operation.
  4453. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4454. * @returns {Function} Returns the new mathematical operation function.
  4455. */
  4456. function createMathOperation(operator, defaultValue) {
  4457. return function(value, other) {
  4458. var result;
  4459. if (value === undefined && other === undefined) {
  4460. return defaultValue;
  4461. }
  4462. if (value !== undefined) {
  4463. result = value;
  4464. }
  4465. if (other !== undefined) {
  4466. if (result === undefined) {
  4467. return other;
  4468. }
  4469. if (typeof value == 'string' || typeof other == 'string') {
  4470. value = baseToString(value);
  4471. other = baseToString(other);
  4472. } else {
  4473. value = baseToNumber(value);
  4474. other = baseToNumber(other);
  4475. }
  4476. result = operator(value, other);
  4477. }
  4478. return result;
  4479. };
  4480. }
  4481. /**
  4482. * Creates a function like `_.over`.
  4483. *
  4484. * @private
  4485. * @param {Function} arrayFunc The function to iterate over iteratees.
  4486. * @returns {Function} Returns the new over function.
  4487. */
  4488. function createOver(arrayFunc) {
  4489. return baseRest(function(iteratees) {
  4490. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  4491. ? arrayMap(iteratees[0], baseUnary(getIteratee()))
  4492. : arrayMap(baseFlatten(iteratees, 1), baseUnary(getIteratee()));
  4493. return baseRest(function(args) {
  4494. var thisArg = this;
  4495. return arrayFunc(iteratees, function(iteratee) {
  4496. return apply(iteratee, thisArg, args);
  4497. });
  4498. });
  4499. });
  4500. }
  4501. /**
  4502. * Creates the padding for `string` based on `length`. The `chars` string
  4503. * is truncated if the number of characters exceeds `length`.
  4504. *
  4505. * @private
  4506. * @param {number} length The padding length.
  4507. * @param {string} [chars=' '] The string used as padding.
  4508. * @returns {string} Returns the padding for `string`.
  4509. */
  4510. function createPadding(length, chars) {
  4511. chars = chars === undefined ? ' ' : baseToString(chars);
  4512. var charsLength = chars.length;
  4513. if (charsLength < 2) {
  4514. return charsLength ? baseRepeat(chars, length) : chars;
  4515. }
  4516. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4517. return reHasComplexSymbol.test(chars)
  4518. ? castSlice(stringToArray(result), 0, length).join('')
  4519. : result.slice(0, length);
  4520. }
  4521. /**
  4522. * Creates a function that wraps `func` to invoke it with the `this` binding
  4523. * of `thisArg` and `partials` prepended to the arguments it receives.
  4524. *
  4525. * @private
  4526. * @param {Function} func The function to wrap.
  4527. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4528. * @param {*} thisArg The `this` binding of `func`.
  4529. * @param {Array} partials The arguments to prepend to those provided to
  4530. * the new function.
  4531. * @returns {Function} Returns the new wrapped function.
  4532. */
  4533. function createPartial(func, bitmask, thisArg, partials) {
  4534. var isBind = bitmask & BIND_FLAG,
  4535. Ctor = createCtor(func);
  4536. function wrapper() {
  4537. var argsIndex = -1,
  4538. argsLength = arguments.length,
  4539. leftIndex = -1,
  4540. leftLength = partials.length,
  4541. args = Array(leftLength + argsLength),
  4542. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4543. while (++leftIndex < leftLength) {
  4544. args[leftIndex] = partials[leftIndex];
  4545. }
  4546. while (argsLength--) {
  4547. args[leftIndex++] = arguments[++argsIndex];
  4548. }
  4549. return apply(fn, isBind ? thisArg : this, args);
  4550. }
  4551. return wrapper;
  4552. }
  4553. /**
  4554. * Creates a `_.range` or `_.rangeRight` function.
  4555. *
  4556. * @private
  4557. * @param {boolean} [fromRight] Specify iterating from right to left.
  4558. * @returns {Function} Returns the new range function.
  4559. */
  4560. function createRange(fromRight) {
  4561. return function(start, end, step) {
  4562. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4563. end = step = undefined;
  4564. }
  4565. // Ensure the sign of `-0` is preserved.
  4566. start = toNumber(start);
  4567. start = start === start ? start : 0;
  4568. if (end === undefined) {
  4569. end = start;
  4570. start = 0;
  4571. } else {
  4572. end = toNumber(end) || 0;
  4573. }
  4574. step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
  4575. return baseRange(start, end, step, fromRight);
  4576. };
  4577. }
  4578. /**
  4579. * Creates a function that performs a relational operation on two values.
  4580. *
  4581. * @private
  4582. * @param {Function} operator The function to perform the operation.
  4583. * @returns {Function} Returns the new relational operation function.
  4584. */
  4585. function createRelationalOperation(operator) {
  4586. return function(value, other) {
  4587. if (!(typeof value == 'string' && typeof other == 'string')) {
  4588. value = toNumber(value);
  4589. other = toNumber(other);
  4590. }
  4591. return operator(value, other);
  4592. };
  4593. }
  4594. /**
  4595. * Creates a function that wraps `func` to continue currying.
  4596. *
  4597. * @private
  4598. * @param {Function} func The function to wrap.
  4599. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4600. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4601. * @param {*} placeholder The placeholder value.
  4602. * @param {*} [thisArg] The `this` binding of `func`.
  4603. * @param {Array} [partials] The arguments to prepend to those provided to
  4604. * the new function.
  4605. * @param {Array} [holders] The `partials` placeholder indexes.
  4606. * @param {Array} [argPos] The argument positions of the new function.
  4607. * @param {number} [ary] The arity cap of `func`.
  4608. * @param {number} [arity] The arity of `func`.
  4609. * @returns {Function} Returns the new wrapped function.
  4610. */
  4611. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4612. var isCurry = bitmask & CURRY_FLAG,
  4613. newHolders = isCurry ? holders : undefined,
  4614. newHoldersRight = isCurry ? undefined : holders,
  4615. newPartials = isCurry ? partials : undefined,
  4616. newPartialsRight = isCurry ? undefined : partials;
  4617. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  4618. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  4619. if (!(bitmask & CURRY_BOUND_FLAG)) {
  4620. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  4621. }
  4622. var newData = [
  4623. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4624. newHoldersRight, argPos, ary, arity
  4625. ];
  4626. var result = wrapFunc.apply(undefined, newData);
  4627. if (isLaziable(func)) {
  4628. setData(result, newData);
  4629. }
  4630. result.placeholder = placeholder;
  4631. return setWrapToString(result, func, bitmask);
  4632. }
  4633. /**
  4634. * Creates a function like `_.round`.
  4635. *
  4636. * @private
  4637. * @param {string} methodName The name of the `Math` method to use when rounding.
  4638. * @returns {Function} Returns the new round function.
  4639. */
  4640. function createRound(methodName) {
  4641. var func = Math[methodName];
  4642. return function(number, precision) {
  4643. number = toNumber(number);
  4644. precision = nativeMin(toInteger(precision), 292);
  4645. if (precision) {
  4646. // Shift with exponential notation to avoid floating-point issues.
  4647. // See [MDN](https://mdn.io/round#Examples) for more details.
  4648. var pair = (toString(number) + 'e').split('e'),
  4649. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4650. pair = (toString(value) + 'e').split('e');
  4651. return +(pair[0] + 'e' + (+pair[1] - precision));
  4652. }
  4653. return func(number);
  4654. };
  4655. }
  4656. /**
  4657. * Creates a set object of `values`.
  4658. *
  4659. * @private
  4660. * @param {Array} values The values to add to the set.
  4661. * @returns {Object} Returns the new set.
  4662. */
  4663. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4664. return new Set(values);
  4665. };
  4666. /**
  4667. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4668. *
  4669. * @private
  4670. * @param {Function} keysFunc The function to get the keys of a given object.
  4671. * @returns {Function} Returns the new pairs function.
  4672. */
  4673. function createToPairs(keysFunc) {
  4674. return function(object) {
  4675. var tag = getTag(object);
  4676. if (tag == mapTag) {
  4677. return mapToArray(object);
  4678. }
  4679. if (tag == setTag) {
  4680. return setToPairs(object);
  4681. }
  4682. return baseToPairs(object, keysFunc(object));
  4683. };
  4684. }
  4685. /**
  4686. * Creates a function that either curries or invokes `func` with optional
  4687. * `this` binding and partially applied arguments.
  4688. *
  4689. * @private
  4690. * @param {Function|string} func The function or method name to wrap.
  4691. * @param {number} bitmask The bitmask flags.
  4692. * The bitmask may be composed of the following flags:
  4693. * 1 - `_.bind`
  4694. * 2 - `_.bindKey`
  4695. * 4 - `_.curry` or `_.curryRight` of a bound function
  4696. * 8 - `_.curry`
  4697. * 16 - `_.curryRight`
  4698. * 32 - `_.partial`
  4699. * 64 - `_.partialRight`
  4700. * 128 - `_.rearg`
  4701. * 256 - `_.ary`
  4702. * 512 - `_.flip`
  4703. * @param {*} [thisArg] The `this` binding of `func`.
  4704. * @param {Array} [partials] The arguments to be partially applied.
  4705. * @param {Array} [holders] The `partials` placeholder indexes.
  4706. * @param {Array} [argPos] The argument positions of the new function.
  4707. * @param {number} [ary] The arity cap of `func`.
  4708. * @param {number} [arity] The arity of `func`.
  4709. * @returns {Function} Returns the new wrapped function.
  4710. */
  4711. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  4712. var isBindKey = bitmask & BIND_KEY_FLAG;
  4713. if (!isBindKey && typeof func != 'function') {
  4714. throw new TypeError(FUNC_ERROR_TEXT);
  4715. }
  4716. var length = partials ? partials.length : 0;
  4717. if (!length) {
  4718. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  4719. partials = holders = undefined;
  4720. }
  4721. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  4722. arity = arity === undefined ? arity : toInteger(arity);
  4723. length -= holders ? holders.length : 0;
  4724. if (bitmask & PARTIAL_RIGHT_FLAG) {
  4725. var partialsRight = partials,
  4726. holdersRight = holders;
  4727. partials = holders = undefined;
  4728. }
  4729. var data = isBindKey ? undefined : getData(func);
  4730. var newData = [
  4731. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  4732. argPos, ary, arity
  4733. ];
  4734. if (data) {
  4735. mergeData(newData, data);
  4736. }
  4737. func = newData[0];
  4738. bitmask = newData[1];
  4739. thisArg = newData[2];
  4740. partials = newData[3];
  4741. holders = newData[4];
  4742. arity = newData[9] = newData[9] == null
  4743. ? (isBindKey ? 0 : func.length)
  4744. : nativeMax(newData[9] - length, 0);
  4745. if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
  4746. bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
  4747. }
  4748. if (!bitmask || bitmask == BIND_FLAG) {
  4749. var result = createBind(func, bitmask, thisArg);
  4750. } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
  4751. result = createCurry(func, bitmask, arity);
  4752. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
  4753. result = createPartial(func, bitmask, thisArg, partials);
  4754. } else {
  4755. result = createHybrid.apply(undefined, newData);
  4756. }
  4757. var setter = data ? baseSetData : setData;
  4758. return setWrapToString(setter(result, newData), func, bitmask);
  4759. }
  4760. /**
  4761. * A specialized version of `baseIsEqualDeep` for arrays with support for
  4762. * partial deep comparisons.
  4763. *
  4764. * @private
  4765. * @param {Array} array The array to compare.
  4766. * @param {Array} other The other array to compare.
  4767. * @param {Function} equalFunc The function to determine equivalents of values.
  4768. * @param {Function} customizer The function to customize comparisons.
  4769. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4770. * for more details.
  4771. * @param {Object} stack Tracks traversed `array` and `other` objects.
  4772. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  4773. */
  4774. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  4775. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  4776. arrLength = array.length,
  4777. othLength = other.length;
  4778. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  4779. return false;
  4780. }
  4781. // Assume cyclic values are equal.
  4782. var stacked = stack.get(array);
  4783. if (stacked && stack.get(other)) {
  4784. return stacked == other;
  4785. }
  4786. var index = -1,
  4787. result = true,
  4788. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  4789. stack.set(array, other);
  4790. stack.set(other, array);
  4791. // Ignore non-index properties.
  4792. while (++index < arrLength) {
  4793. var arrValue = array[index],
  4794. othValue = other[index];
  4795. if (customizer) {
  4796. var compared = isPartial
  4797. ? customizer(othValue, arrValue, index, other, array, stack)
  4798. : customizer(arrValue, othValue, index, array, other, stack);
  4799. }
  4800. if (compared !== undefined) {
  4801. if (compared) {
  4802. continue;
  4803. }
  4804. result = false;
  4805. break;
  4806. }
  4807. // Recursively compare arrays (susceptible to call stack limits).
  4808. if (seen) {
  4809. if (!arraySome(other, function(othValue, othIndex) {
  4810. if (!seen.has(othIndex) &&
  4811. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  4812. return seen.add(othIndex);
  4813. }
  4814. })) {
  4815. result = false;
  4816. break;
  4817. }
  4818. } else if (!(
  4819. arrValue === othValue ||
  4820. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  4821. )) {
  4822. result = false;
  4823. break;
  4824. }
  4825. }
  4826. stack['delete'](array);
  4827. return result;
  4828. }
  4829. /**
  4830. * A specialized version of `baseIsEqualDeep` for comparing objects of
  4831. * the same `toStringTag`.
  4832. *
  4833. * **Note:** This function only supports comparing values with tags of
  4834. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  4835. *
  4836. * @private
  4837. * @param {Object} object The object to compare.
  4838. * @param {Object} other The other object to compare.
  4839. * @param {string} tag The `toStringTag` of the objects to compare.
  4840. * @param {Function} equalFunc The function to determine equivalents of values.
  4841. * @param {Function} customizer The function to customize comparisons.
  4842. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4843. * for more details.
  4844. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4845. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4846. */
  4847. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  4848. switch (tag) {
  4849. case dataViewTag:
  4850. if ((object.byteLength != other.byteLength) ||
  4851. (object.byteOffset != other.byteOffset)) {
  4852. return false;
  4853. }
  4854. object = object.buffer;
  4855. other = other.buffer;
  4856. case arrayBufferTag:
  4857. if ((object.byteLength != other.byteLength) ||
  4858. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  4859. return false;
  4860. }
  4861. return true;
  4862. case boolTag:
  4863. case dateTag:
  4864. case numberTag:
  4865. // Coerce booleans to `1` or `0` and dates to milliseconds.
  4866. // Invalid dates are coerced to `NaN`.
  4867. return eq(+object, +other);
  4868. case errorTag:
  4869. return object.name == other.name && object.message == other.message;
  4870. case regexpTag:
  4871. case stringTag:
  4872. // Coerce regexes to strings and treat strings, primitives and objects,
  4873. // as equal. See http://www.ecma-international.org/ecma-262/6.0/#sec-regexp.prototype.tostring
  4874. // for more details.
  4875. return object == (other + '');
  4876. case mapTag:
  4877. var convert = mapToArray;
  4878. case setTag:
  4879. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  4880. convert || (convert = setToArray);
  4881. if (object.size != other.size && !isPartial) {
  4882. return false;
  4883. }
  4884. // Assume cyclic values are equal.
  4885. var stacked = stack.get(object);
  4886. if (stacked) {
  4887. return stacked == other;
  4888. }
  4889. bitmask |= UNORDERED_COMPARE_FLAG;
  4890. // Recursively compare objects (susceptible to call stack limits).
  4891. stack.set(object, other);
  4892. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  4893. stack['delete'](object);
  4894. return result;
  4895. case symbolTag:
  4896. if (symbolValueOf) {
  4897. return symbolValueOf.call(object) == symbolValueOf.call(other);
  4898. }
  4899. }
  4900. return false;
  4901. }
  4902. /**
  4903. * A specialized version of `baseIsEqualDeep` for objects with support for
  4904. * partial deep comparisons.
  4905. *
  4906. * @private
  4907. * @param {Object} object The object to compare.
  4908. * @param {Object} other The other object to compare.
  4909. * @param {Function} equalFunc The function to determine equivalents of values.
  4910. * @param {Function} customizer The function to customize comparisons.
  4911. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4912. * for more details.
  4913. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4914. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4915. */
  4916. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  4917. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  4918. objProps = keys(object),
  4919. objLength = objProps.length,
  4920. othProps = keys(other),
  4921. othLength = othProps.length;
  4922. if (objLength != othLength && !isPartial) {
  4923. return false;
  4924. }
  4925. var index = objLength;
  4926. while (index--) {
  4927. var key = objProps[index];
  4928. if (!(isPartial ? key in other : baseHas(other, key))) {
  4929. return false;
  4930. }
  4931. }
  4932. // Assume cyclic values are equal.
  4933. var stacked = stack.get(object);
  4934. if (stacked && stack.get(other)) {
  4935. return stacked == other;
  4936. }
  4937. var result = true;
  4938. stack.set(object, other);
  4939. stack.set(other, object);
  4940. var skipCtor = isPartial;
  4941. while (++index < objLength) {
  4942. key = objProps[index];
  4943. var objValue = object[key],
  4944. othValue = other[key];
  4945. if (customizer) {
  4946. var compared = isPartial
  4947. ? customizer(othValue, objValue, key, other, object, stack)
  4948. : customizer(objValue, othValue, key, object, other, stack);
  4949. }
  4950. // Recursively compare objects (susceptible to call stack limits).
  4951. if (!(compared === undefined
  4952. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  4953. : compared
  4954. )) {
  4955. result = false;
  4956. break;
  4957. }
  4958. skipCtor || (skipCtor = key == 'constructor');
  4959. }
  4960. if (result && !skipCtor) {
  4961. var objCtor = object.constructor,
  4962. othCtor = other.constructor;
  4963. // Non `Object` object instances with different constructors are not equal.
  4964. if (objCtor != othCtor &&
  4965. ('constructor' in object && 'constructor' in other) &&
  4966. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  4967. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  4968. result = false;
  4969. }
  4970. }
  4971. stack['delete'](object);
  4972. return result;
  4973. }
  4974. /**
  4975. * Creates an array of own enumerable property names and symbols of `object`.
  4976. *
  4977. * @private
  4978. * @param {Object} object The object to query.
  4979. * @returns {Array} Returns the array of property names and symbols.
  4980. */
  4981. function getAllKeys(object) {
  4982. return baseGetAllKeys(object, keys, getSymbols);
  4983. }
  4984. /**
  4985. * Creates an array of own and inherited enumerable property names and
  4986. * symbols of `object`.
  4987. *
  4988. * @private
  4989. * @param {Object} object The object to query.
  4990. * @returns {Array} Returns the array of property names and symbols.
  4991. */
  4992. function getAllKeysIn(object) {
  4993. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  4994. }
  4995. /**
  4996. * Gets metadata for `func`.
  4997. *
  4998. * @private
  4999. * @param {Function} func The function to query.
  5000. * @returns {*} Returns the metadata for `func`.
  5001. */
  5002. var getData = !metaMap ? noop : function(func) {
  5003. return metaMap.get(func);
  5004. };
  5005. /**
  5006. * Gets the name of `func`.
  5007. *
  5008. * @private
  5009. * @param {Function} func The function to query.
  5010. * @returns {string} Returns the function name.
  5011. */
  5012. function getFuncName(func) {
  5013. var result = (func.name + ''),
  5014. array = realNames[result],
  5015. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5016. while (length--) {
  5017. var data = array[length],
  5018. otherFunc = data.func;
  5019. if (otherFunc == null || otherFunc == func) {
  5020. return data.name;
  5021. }
  5022. }
  5023. return result;
  5024. }
  5025. /**
  5026. * Gets the argument placeholder value for `func`.
  5027. *
  5028. * @private
  5029. * @param {Function} func The function to inspect.
  5030. * @returns {*} Returns the placeholder value.
  5031. */
  5032. function getHolder(func) {
  5033. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5034. return object.placeholder;
  5035. }
  5036. /**
  5037. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5038. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5039. * If arguments are provided, the chosen function is invoked with them and
  5040. * its result is returned.
  5041. *
  5042. * @private
  5043. * @param {*} [value] The value to convert to an iteratee.
  5044. * @param {number} [arity] The arity of the created iteratee.
  5045. * @returns {Function} Returns the chosen function or its result.
  5046. */
  5047. function getIteratee() {
  5048. var result = lodash.iteratee || iteratee;
  5049. result = result === iteratee ? baseIteratee : result;
  5050. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5051. }
  5052. /**
  5053. * Gets the "length" property value of `object`.
  5054. *
  5055. * **Note:** This function is used to avoid a
  5056. * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
  5057. * Safari on at least iOS 8.1-8.3 ARM64.
  5058. *
  5059. * @private
  5060. * @param {Object} object The object to query.
  5061. * @returns {*} Returns the "length" value.
  5062. */
  5063. var getLength = baseProperty('length');
  5064. /**
  5065. * Gets the data for `map`.
  5066. *
  5067. * @private
  5068. * @param {Object} map The map to query.
  5069. * @param {string} key The reference key.
  5070. * @returns {*} Returns the map data.
  5071. */
  5072. function getMapData(map, key) {
  5073. var data = map.__data__;
  5074. return isKeyable(key)
  5075. ? data[typeof key == 'string' ? 'string' : 'hash']
  5076. : data.map;
  5077. }
  5078. /**
  5079. * Gets the property names, values, and compare flags of `object`.
  5080. *
  5081. * @private
  5082. * @param {Object} object The object to query.
  5083. * @returns {Array} Returns the match data of `object`.
  5084. */
  5085. function getMatchData(object) {
  5086. var result = keys(object),
  5087. length = result.length;
  5088. while (length--) {
  5089. var key = result[length],
  5090. value = object[key];
  5091. result[length] = [key, value, isStrictComparable(value)];
  5092. }
  5093. return result;
  5094. }
  5095. /**
  5096. * Gets the native function at `key` of `object`.
  5097. *
  5098. * @private
  5099. * @param {Object} object The object to query.
  5100. * @param {string} key The key of the method to get.
  5101. * @returns {*} Returns the function if it's native, else `undefined`.
  5102. */
  5103. function getNative(object, key) {
  5104. var value = getValue(object, key);
  5105. return baseIsNative(value) ? value : undefined;
  5106. }
  5107. /**
  5108. * Gets the `[[Prototype]]` of `value`.
  5109. *
  5110. * @private
  5111. * @param {*} value The value to query.
  5112. * @returns {null|Object} Returns the `[[Prototype]]`.
  5113. */
  5114. var getPrototype = overArg(nativeGetPrototype, Object);
  5115. /**
  5116. * Creates an array of the own enumerable symbol properties of `object`.
  5117. *
  5118. * @private
  5119. * @param {Object} object The object to query.
  5120. * @returns {Array} Returns the array of symbols.
  5121. */
  5122. var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
  5123. /**
  5124. * Creates an array of the own and inherited enumerable symbol properties
  5125. * of `object`.
  5126. *
  5127. * @private
  5128. * @param {Object} object The object to query.
  5129. * @returns {Array} Returns the array of symbols.
  5130. */
  5131. var getSymbolsIn = !nativeGetSymbols ? getSymbols : function(object) {
  5132. var result = [];
  5133. while (object) {
  5134. arrayPush(result, getSymbols(object));
  5135. object = getPrototype(object);
  5136. }
  5137. return result;
  5138. };
  5139. /**
  5140. * Gets the `toStringTag` of `value`.
  5141. *
  5142. * @private
  5143. * @param {*} value The value to query.
  5144. * @returns {string} Returns the `toStringTag`.
  5145. */
  5146. var getTag = baseGetTag;
  5147. // Fallback for data views, maps, sets, and weak maps in IE 11,
  5148. // for data views in Edge, and promises in Node.js.
  5149. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5150. (Map && getTag(new Map) != mapTag) ||
  5151. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5152. (Set && getTag(new Set) != setTag) ||
  5153. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5154. getTag = function(value) {
  5155. var result = objectToString.call(value),
  5156. Ctor = result == objectTag ? value.constructor : undefined,
  5157. ctorString = Ctor ? toSource(Ctor) : undefined;
  5158. if (ctorString) {
  5159. switch (ctorString) {
  5160. case dataViewCtorString: return dataViewTag;
  5161. case mapCtorString: return mapTag;
  5162. case promiseCtorString: return promiseTag;
  5163. case setCtorString: return setTag;
  5164. case weakMapCtorString: return weakMapTag;
  5165. }
  5166. }
  5167. return result;
  5168. };
  5169. }
  5170. /**
  5171. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5172. *
  5173. * @private
  5174. * @param {number} start The start of the view.
  5175. * @param {number} end The end of the view.
  5176. * @param {Array} transforms The transformations to apply to the view.
  5177. * @returns {Object} Returns an object containing the `start` and `end`
  5178. * positions of the view.
  5179. */
  5180. function getView(start, end, transforms) {
  5181. var index = -1,
  5182. length = transforms.length;
  5183. while (++index < length) {
  5184. var data = transforms[index],
  5185. size = data.size;
  5186. switch (data.type) {
  5187. case 'drop': start += size; break;
  5188. case 'dropRight': end -= size; break;
  5189. case 'take': end = nativeMin(end, start + size); break;
  5190. case 'takeRight': start = nativeMax(start, end - size); break;
  5191. }
  5192. }
  5193. return { 'start': start, 'end': end };
  5194. }
  5195. /**
  5196. * Extracts wrapper details from the `source` body comment.
  5197. *
  5198. * @private
  5199. * @param {string} source The source to inspect.
  5200. * @returns {Array} Returns the wrapper details.
  5201. */
  5202. function getWrapDetails(source) {
  5203. var match = source.match(reWrapDetails);
  5204. return match ? match[1].split(reSplitDetails) : [];
  5205. }
  5206. /**
  5207. * Checks if `path` exists on `object`.
  5208. *
  5209. * @private
  5210. * @param {Object} object The object to query.
  5211. * @param {Array|string} path The path to check.
  5212. * @param {Function} hasFunc The function to check properties.
  5213. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5214. */
  5215. function hasPath(object, path, hasFunc) {
  5216. path = isKey(path, object) ? [path] : castPath(path);
  5217. var result,
  5218. index = -1,
  5219. length = path.length;
  5220. while (++index < length) {
  5221. var key = toKey(path[index]);
  5222. if (!(result = object != null && hasFunc(object, key))) {
  5223. break;
  5224. }
  5225. object = object[key];
  5226. }
  5227. if (result) {
  5228. return result;
  5229. }
  5230. var length = object ? object.length : 0;
  5231. return !!length && isLength(length) && isIndex(key, length) &&
  5232. (isArray(object) || isString(object) || isArguments(object));
  5233. }
  5234. /**
  5235. * Initializes an array clone.
  5236. *
  5237. * @private
  5238. * @param {Array} array The array to clone.
  5239. * @returns {Array} Returns the initialized clone.
  5240. */
  5241. function initCloneArray(array) {
  5242. var length = array.length,
  5243. result = array.constructor(length);
  5244. // Add properties assigned by `RegExp#exec`.
  5245. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5246. result.index = array.index;
  5247. result.input = array.input;
  5248. }
  5249. return result;
  5250. }
  5251. /**
  5252. * Initializes an object clone.
  5253. *
  5254. * @private
  5255. * @param {Object} object The object to clone.
  5256. * @returns {Object} Returns the initialized clone.
  5257. */
  5258. function initCloneObject(object) {
  5259. return (typeof object.constructor == 'function' && !isPrototype(object))
  5260. ? baseCreate(getPrototype(object))
  5261. : {};
  5262. }
  5263. /**
  5264. * Initializes an object clone based on its `toStringTag`.
  5265. *
  5266. * **Note:** This function only supports cloning values with tags of
  5267. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5268. *
  5269. * @private
  5270. * @param {Object} object The object to clone.
  5271. * @param {string} tag The `toStringTag` of the object to clone.
  5272. * @param {Function} cloneFunc The function to clone values.
  5273. * @param {boolean} [isDeep] Specify a deep clone.
  5274. * @returns {Object} Returns the initialized clone.
  5275. */
  5276. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  5277. var Ctor = object.constructor;
  5278. switch (tag) {
  5279. case arrayBufferTag:
  5280. return cloneArrayBuffer(object);
  5281. case boolTag:
  5282. case dateTag:
  5283. return new Ctor(+object);
  5284. case dataViewTag:
  5285. return cloneDataView(object, isDeep);
  5286. case float32Tag: case float64Tag:
  5287. case int8Tag: case int16Tag: case int32Tag:
  5288. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5289. return cloneTypedArray(object, isDeep);
  5290. case mapTag:
  5291. return cloneMap(object, isDeep, cloneFunc);
  5292. case numberTag:
  5293. case stringTag:
  5294. return new Ctor(object);
  5295. case regexpTag:
  5296. return cloneRegExp(object);
  5297. case setTag:
  5298. return cloneSet(object, isDeep, cloneFunc);
  5299. case symbolTag:
  5300. return cloneSymbol(object);
  5301. }
  5302. }
  5303. /**
  5304. * Creates an array of index keys for `object` values of arrays,
  5305. * `arguments` objects, and strings, otherwise `null` is returned.
  5306. *
  5307. * @private
  5308. * @param {Object} object The object to query.
  5309. * @returns {Array|null} Returns index keys, else `null`.
  5310. */
  5311. function indexKeys(object) {
  5312. var length = object ? object.length : undefined;
  5313. if (isLength(length) &&
  5314. (isArray(object) || isString(object) || isArguments(object))) {
  5315. return baseTimes(length, String);
  5316. }
  5317. return null;
  5318. }
  5319. /**
  5320. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5321. *
  5322. * @private
  5323. * @param {string} source The source to modify.
  5324. * @returns {Array} details The details to insert.
  5325. * @returns {string} Returns the modified source.
  5326. */
  5327. function insertWrapDetails(source, details) {
  5328. var length = details.length,
  5329. lastIndex = length - 1;
  5330. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5331. details = details.join(length > 2 ? ', ' : ' ');
  5332. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5333. }
  5334. /**
  5335. * Checks if `value` is a flattenable `arguments` object or array.
  5336. *
  5337. * @private
  5338. * @param {*} value The value to check.
  5339. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5340. */
  5341. function isFlattenable(value) {
  5342. return isArray(value) || isArguments(value) ||
  5343. !!(spreadableSymbol && value && value[spreadableSymbol])
  5344. }
  5345. /**
  5346. * Checks if `value` is a valid array-like index.
  5347. *
  5348. * @private
  5349. * @param {*} value The value to check.
  5350. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5351. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5352. */
  5353. function isIndex(value, length) {
  5354. length = length == null ? MAX_SAFE_INTEGER : length;
  5355. return !!length &&
  5356. (typeof value == 'number' || reIsUint.test(value)) &&
  5357. (value > -1 && value % 1 == 0 && value < length);
  5358. }
  5359. /**
  5360. * Checks if the given arguments are from an iteratee call.
  5361. *
  5362. * @private
  5363. * @param {*} value The potential iteratee value argument.
  5364. * @param {*} index The potential iteratee index or key argument.
  5365. * @param {*} object The potential iteratee object argument.
  5366. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5367. * else `false`.
  5368. */
  5369. function isIterateeCall(value, index, object) {
  5370. if (!isObject(object)) {
  5371. return false;
  5372. }
  5373. var type = typeof index;
  5374. if (type == 'number'
  5375. ? (isArrayLike(object) && isIndex(index, object.length))
  5376. : (type == 'string' && index in object)
  5377. ) {
  5378. return eq(object[index], value);
  5379. }
  5380. return false;
  5381. }
  5382. /**
  5383. * Checks if `value` is a property name and not a property path.
  5384. *
  5385. * @private
  5386. * @param {*} value The value to check.
  5387. * @param {Object} [object] The object to query keys on.
  5388. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5389. */
  5390. function isKey(value, object) {
  5391. if (isArray(value)) {
  5392. return false;
  5393. }
  5394. var type = typeof value;
  5395. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5396. value == null || isSymbol(value)) {
  5397. return true;
  5398. }
  5399. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5400. (object != null && value in Object(object));
  5401. }
  5402. /**
  5403. * Checks if `value` is suitable for use as unique object key.
  5404. *
  5405. * @private
  5406. * @param {*} value The value to check.
  5407. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5408. */
  5409. function isKeyable(value) {
  5410. var type = typeof value;
  5411. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5412. ? (value !== '__proto__')
  5413. : (value === null);
  5414. }
  5415. /**
  5416. * Checks if `func` has a lazy counterpart.
  5417. *
  5418. * @private
  5419. * @param {Function} func The function to check.
  5420. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5421. * else `false`.
  5422. */
  5423. function isLaziable(func) {
  5424. var funcName = getFuncName(func),
  5425. other = lodash[funcName];
  5426. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5427. return false;
  5428. }
  5429. if (func === other) {
  5430. return true;
  5431. }
  5432. var data = getData(other);
  5433. return !!data && func === data[0];
  5434. }
  5435. /**
  5436. * Checks if `func` has its source masked.
  5437. *
  5438. * @private
  5439. * @param {Function} func The function to check.
  5440. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5441. */
  5442. function isMasked(func) {
  5443. return !!maskSrcKey && (maskSrcKey in func);
  5444. }
  5445. /**
  5446. * Checks if `func` is capable of being masked.
  5447. *
  5448. * @private
  5449. * @param {*} value The value to check.
  5450. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5451. */
  5452. var isMaskable = coreJsData ? isFunction : stubFalse;
  5453. /**
  5454. * Checks if `value` is likely a prototype object.
  5455. *
  5456. * @private
  5457. * @param {*} value The value to check.
  5458. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5459. */
  5460. function isPrototype(value) {
  5461. var Ctor = value && value.constructor,
  5462. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5463. return value === proto;
  5464. }
  5465. /**
  5466. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5467. *
  5468. * @private
  5469. * @param {*} value The value to check.
  5470. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5471. * equality comparisons, else `false`.
  5472. */
  5473. function isStrictComparable(value) {
  5474. return value === value && !isObject(value);
  5475. }
  5476. /**
  5477. * A specialized version of `matchesProperty` for source values suitable
  5478. * for strict equality comparisons, i.e. `===`.
  5479. *
  5480. * @private
  5481. * @param {string} key The key of the property to get.
  5482. * @param {*} srcValue The value to match.
  5483. * @returns {Function} Returns the new spec function.
  5484. */
  5485. function matchesStrictComparable(key, srcValue) {
  5486. return function(object) {
  5487. if (object == null) {
  5488. return false;
  5489. }
  5490. return object[key] === srcValue &&
  5491. (srcValue !== undefined || (key in Object(object)));
  5492. };
  5493. }
  5494. /**
  5495. * Merges the function metadata of `source` into `data`.
  5496. *
  5497. * Merging metadata reduces the number of wrappers used to invoke a function.
  5498. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5499. * may be applied regardless of execution order. Methods like `_.ary` and
  5500. * `_.rearg` modify function arguments, making the order in which they are
  5501. * executed important, preventing the merging of metadata. However, we make
  5502. * an exception for a safe combined case where curried functions have `_.ary`
  5503. * and or `_.rearg` applied.
  5504. *
  5505. * @private
  5506. * @param {Array} data The destination metadata.
  5507. * @param {Array} source The source metadata.
  5508. * @returns {Array} Returns `data`.
  5509. */
  5510. function mergeData(data, source) {
  5511. var bitmask = data[1],
  5512. srcBitmask = source[1],
  5513. newBitmask = bitmask | srcBitmask,
  5514. isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
  5515. var isCombo =
  5516. ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
  5517. ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
  5518. ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
  5519. // Exit early if metadata can't be merged.
  5520. if (!(isCommon || isCombo)) {
  5521. return data;
  5522. }
  5523. // Use source `thisArg` if available.
  5524. if (srcBitmask & BIND_FLAG) {
  5525. data[2] = source[2];
  5526. // Set when currying a bound function.
  5527. newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
  5528. }
  5529. // Compose partial arguments.
  5530. var value = source[3];
  5531. if (value) {
  5532. var partials = data[3];
  5533. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5534. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5535. }
  5536. // Compose partial right arguments.
  5537. value = source[5];
  5538. if (value) {
  5539. partials = data[5];
  5540. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5541. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5542. }
  5543. // Use source `argPos` if available.
  5544. value = source[7];
  5545. if (value) {
  5546. data[7] = value;
  5547. }
  5548. // Use source `ary` if it's smaller.
  5549. if (srcBitmask & ARY_FLAG) {
  5550. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5551. }
  5552. // Use source `arity` if one is not provided.
  5553. if (data[9] == null) {
  5554. data[9] = source[9];
  5555. }
  5556. // Use source `func` and merge bitmasks.
  5557. data[0] = source[0];
  5558. data[1] = newBitmask;
  5559. return data;
  5560. }
  5561. /**
  5562. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  5563. *
  5564. * @private
  5565. * @param {*} objValue The destination value.
  5566. * @param {*} srcValue The source value.
  5567. * @param {string} key The key of the property to merge.
  5568. * @param {Object} object The parent object of `objValue`.
  5569. * @param {Object} source The parent object of `srcValue`.
  5570. * @param {Object} [stack] Tracks traversed source values and their merged
  5571. * counterparts.
  5572. * @returns {*} Returns the value to assign.
  5573. */
  5574. function mergeDefaults(objValue, srcValue, key, object, source, stack) {
  5575. if (isObject(objValue) && isObject(srcValue)) {
  5576. // Recursively merge objects and arrays (susceptible to call stack limits).
  5577. stack.set(srcValue, objValue);
  5578. baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
  5579. stack['delete'](srcValue);
  5580. }
  5581. return objValue;
  5582. }
  5583. /**
  5584. * Gets the parent value at `path` of `object`.
  5585. *
  5586. * @private
  5587. * @param {Object} object The object to query.
  5588. * @param {Array} path The path to get the parent value of.
  5589. * @returns {*} Returns the parent value.
  5590. */
  5591. function parent(object, path) {
  5592. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  5593. }
  5594. /**
  5595. * Reorder `array` according to the specified indexes where the element at
  5596. * the first index is assigned as the first element, the element at
  5597. * the second index is assigned as the second element, and so on.
  5598. *
  5599. * @private
  5600. * @param {Array} array The array to reorder.
  5601. * @param {Array} indexes The arranged array indexes.
  5602. * @returns {Array} Returns `array`.
  5603. */
  5604. function reorder(array, indexes) {
  5605. var arrLength = array.length,
  5606. length = nativeMin(indexes.length, arrLength),
  5607. oldArray = copyArray(array);
  5608. while (length--) {
  5609. var index = indexes[length];
  5610. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  5611. }
  5612. return array;
  5613. }
  5614. /**
  5615. * Sets metadata for `func`.
  5616. *
  5617. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  5618. * period of time, it will trip its breaker and transition to an identity
  5619. * function to avoid garbage collection pauses in V8. See
  5620. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  5621. * for more details.
  5622. *
  5623. * @private
  5624. * @param {Function} func The function to associate metadata with.
  5625. * @param {*} data The metadata.
  5626. * @returns {Function} Returns `func`.
  5627. */
  5628. var setData = (function() {
  5629. var count = 0,
  5630. lastCalled = 0;
  5631. return function(key, value) {
  5632. var stamp = now(),
  5633. remaining = HOT_SPAN - (stamp - lastCalled);
  5634. lastCalled = stamp;
  5635. if (remaining > 0) {
  5636. if (++count >= HOT_COUNT) {
  5637. return key;
  5638. }
  5639. } else {
  5640. count = 0;
  5641. }
  5642. return baseSetData(key, value);
  5643. };
  5644. }());
  5645. /**
  5646. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  5647. * with wrapper details in a comment at the top of the source body.
  5648. *
  5649. * @private
  5650. * @param {Function} wrapper The function to modify.
  5651. * @param {Function} reference The reference function.
  5652. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5653. * @returns {Function} Returns `wrapper`.
  5654. */
  5655. var setWrapToString = !defineProperty ? identity : function(wrapper, reference, bitmask) {
  5656. var source = (reference + '');
  5657. return defineProperty(wrapper, 'toString', {
  5658. 'configurable': true,
  5659. 'enumerable': false,
  5660. 'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)))
  5661. });
  5662. };
  5663. /**
  5664. * Converts `string` to a property path array.
  5665. *
  5666. * @private
  5667. * @param {string} string The string to convert.
  5668. * @returns {Array} Returns the property path array.
  5669. */
  5670. var stringToPath = memoize(function(string) {
  5671. var result = [];
  5672. toString(string).replace(rePropName, function(match, number, quote, string) {
  5673. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  5674. });
  5675. return result;
  5676. });
  5677. /**
  5678. * Converts `value` to a string key if it's not a string or symbol.
  5679. *
  5680. * @private
  5681. * @param {*} value The value to inspect.
  5682. * @returns {string|symbol} Returns the key.
  5683. */
  5684. function toKey(value) {
  5685. if (typeof value == 'string' || isSymbol(value)) {
  5686. return value;
  5687. }
  5688. var result = (value + '');
  5689. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  5690. }
  5691. /**
  5692. * Converts `func` to its source code.
  5693. *
  5694. * @private
  5695. * @param {Function} func The function to process.
  5696. * @returns {string} Returns the source code.
  5697. */
  5698. function toSource(func) {
  5699. if (func != null) {
  5700. try {
  5701. return funcToString.call(func);
  5702. } catch (e) {}
  5703. try {
  5704. return (func + '');
  5705. } catch (e) {}
  5706. }
  5707. return '';
  5708. }
  5709. /**
  5710. * Updates wrapper `details` based on `bitmask` flags.
  5711. *
  5712. * @private
  5713. * @returns {Array} details The details to modify.
  5714. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5715. * @returns {Array} Returns `details`.
  5716. */
  5717. function updateWrapDetails(details, bitmask) {
  5718. arrayEach(wrapFlags, function(pair) {
  5719. var value = '_.' + pair[0];
  5720. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  5721. details.push(value);
  5722. }
  5723. });
  5724. return details.sort();
  5725. }
  5726. /**
  5727. * Creates a clone of `wrapper`.
  5728. *
  5729. * @private
  5730. * @param {Object} wrapper The wrapper to clone.
  5731. * @returns {Object} Returns the cloned wrapper.
  5732. */
  5733. function wrapperClone(wrapper) {
  5734. if (wrapper instanceof LazyWrapper) {
  5735. return wrapper.clone();
  5736. }
  5737. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  5738. result.__actions__ = copyArray(wrapper.__actions__);
  5739. result.__index__ = wrapper.__index__;
  5740. result.__values__ = wrapper.__values__;
  5741. return result;
  5742. }
  5743. /*------------------------------------------------------------------------*/
  5744. /**
  5745. * Creates an array of elements split into groups the length of `size`.
  5746. * If `array` can't be split evenly, the final chunk will be the remaining
  5747. * elements.
  5748. *
  5749. * @static
  5750. * @memberOf _
  5751. * @since 3.0.0
  5752. * @category Array
  5753. * @param {Array} array The array to process.
  5754. * @param {number} [size=1] The length of each chunk
  5755. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  5756. * @returns {Array} Returns the new array of chunks.
  5757. * @example
  5758. *
  5759. * _.chunk(['a', 'b', 'c', 'd'], 2);
  5760. * // => [['a', 'b'], ['c', 'd']]
  5761. *
  5762. * _.chunk(['a', 'b', 'c', 'd'], 3);
  5763. * // => [['a', 'b', 'c'], ['d']]
  5764. */
  5765. function chunk(array, size, guard) {
  5766. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  5767. size = 1;
  5768. } else {
  5769. size = nativeMax(toInteger(size), 0);
  5770. }
  5771. var length = array ? array.length : 0;
  5772. if (!length || size < 1) {
  5773. return [];
  5774. }
  5775. var index = 0,
  5776. resIndex = 0,
  5777. result = Array(nativeCeil(length / size));
  5778. while (index < length) {
  5779. result[resIndex++] = baseSlice(array, index, (index += size));
  5780. }
  5781. return result;
  5782. }
  5783. /**
  5784. * Creates an array with all falsey values removed. The values `false`, `null`,
  5785. * `0`, `""`, `undefined`, and `NaN` are falsey.
  5786. *
  5787. * @static
  5788. * @memberOf _
  5789. * @since 0.1.0
  5790. * @category Array
  5791. * @param {Array} array The array to compact.
  5792. * @returns {Array} Returns the new array of filtered values.
  5793. * @example
  5794. *
  5795. * _.compact([0, 1, false, 2, '', 3]);
  5796. * // => [1, 2, 3]
  5797. */
  5798. function compact(array) {
  5799. var index = -1,
  5800. length = array ? array.length : 0,
  5801. resIndex = 0,
  5802. result = [];
  5803. while (++index < length) {
  5804. var value = array[index];
  5805. if (value) {
  5806. result[resIndex++] = value;
  5807. }
  5808. }
  5809. return result;
  5810. }
  5811. /**
  5812. * Creates a new array concatenating `array` with any additional arrays
  5813. * and/or values.
  5814. *
  5815. * @static
  5816. * @memberOf _
  5817. * @since 4.0.0
  5818. * @category Array
  5819. * @param {Array} array The array to concatenate.
  5820. * @param {...*} [values] The values to concatenate.
  5821. * @returns {Array} Returns the new concatenated array.
  5822. * @example
  5823. *
  5824. * var array = [1];
  5825. * var other = _.concat(array, 2, [3], [[4]]);
  5826. *
  5827. * console.log(other);
  5828. * // => [1, 2, 3, [4]]
  5829. *
  5830. * console.log(array);
  5831. * // => [1]
  5832. */
  5833. function concat() {
  5834. var length = arguments.length,
  5835. args = Array(length ? length - 1 : 0),
  5836. array = arguments[0],
  5837. index = length;
  5838. while (index--) {
  5839. args[index - 1] = arguments[index];
  5840. }
  5841. return length
  5842. ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
  5843. : [];
  5844. }
  5845. /**
  5846. * Creates an array of `array` values not included in the other given arrays
  5847. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5848. * for equality comparisons. The order of result values is determined by the
  5849. * order they occur in the first array.
  5850. *
  5851. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  5852. *
  5853. * @static
  5854. * @memberOf _
  5855. * @since 0.1.0
  5856. * @category Array
  5857. * @param {Array} array The array to inspect.
  5858. * @param {...Array} [values] The values to exclude.
  5859. * @returns {Array} Returns the new array of filtered values.
  5860. * @see _.without, _.xor
  5861. * @example
  5862. *
  5863. * _.difference([2, 1], [2, 3]);
  5864. * // => [1]
  5865. */
  5866. var difference = baseRest(function(array, values) {
  5867. return isArrayLikeObject(array)
  5868. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  5869. : [];
  5870. });
  5871. /**
  5872. * This method is like `_.difference` except that it accepts `iteratee` which
  5873. * is invoked for each element of `array` and `values` to generate the criterion
  5874. * by which they're compared. Result values are chosen from the first array.
  5875. * The iteratee is invoked with one argument: (value).
  5876. *
  5877. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  5878. *
  5879. * @static
  5880. * @memberOf _
  5881. * @since 4.0.0
  5882. * @category Array
  5883. * @param {Array} array The array to inspect.
  5884. * @param {...Array} [values] The values to exclude.
  5885. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  5886. * @returns {Array} Returns the new array of filtered values.
  5887. * @example
  5888. *
  5889. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  5890. * // => [1.2]
  5891. *
  5892. * // The `_.property` iteratee shorthand.
  5893. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  5894. * // => [{ 'x': 2 }]
  5895. */
  5896. var differenceBy = baseRest(function(array, values) {
  5897. var iteratee = last(values);
  5898. if (isArrayLikeObject(iteratee)) {
  5899. iteratee = undefined;
  5900. }
  5901. return isArrayLikeObject(array)
  5902. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  5903. : [];
  5904. });
  5905. /**
  5906. * This method is like `_.difference` except that it accepts `comparator`
  5907. * which is invoked to compare elements of `array` to `values`. Result values
  5908. * are chosen from the first array. The comparator is invoked with two arguments:
  5909. * (arrVal, othVal).
  5910. *
  5911. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  5912. *
  5913. * @static
  5914. * @memberOf _
  5915. * @since 4.0.0
  5916. * @category Array
  5917. * @param {Array} array The array to inspect.
  5918. * @param {...Array} [values] The values to exclude.
  5919. * @param {Function} [comparator] The comparator invoked per element.
  5920. * @returns {Array} Returns the new array of filtered values.
  5921. * @example
  5922. *
  5923. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  5924. *
  5925. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  5926. * // => [{ 'x': 2, 'y': 1 }]
  5927. */
  5928. var differenceWith = baseRest(function(array, values) {
  5929. var comparator = last(values);
  5930. if (isArrayLikeObject(comparator)) {
  5931. comparator = undefined;
  5932. }
  5933. return isArrayLikeObject(array)
  5934. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  5935. : [];
  5936. });
  5937. /**
  5938. * Creates a slice of `array` with `n` elements dropped from the beginning.
  5939. *
  5940. * @static
  5941. * @memberOf _
  5942. * @since 0.5.0
  5943. * @category Array
  5944. * @param {Array} array The array to query.
  5945. * @param {number} [n=1] The number of elements to drop.
  5946. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  5947. * @returns {Array} Returns the slice of `array`.
  5948. * @example
  5949. *
  5950. * _.drop([1, 2, 3]);
  5951. * // => [2, 3]
  5952. *
  5953. * _.drop([1, 2, 3], 2);
  5954. * // => [3]
  5955. *
  5956. * _.drop([1, 2, 3], 5);
  5957. * // => []
  5958. *
  5959. * _.drop([1, 2, 3], 0);
  5960. * // => [1, 2, 3]
  5961. */
  5962. function drop(array, n, guard) {
  5963. var length = array ? array.length : 0;
  5964. if (!length) {
  5965. return [];
  5966. }
  5967. n = (guard || n === undefined) ? 1 : toInteger(n);
  5968. return baseSlice(array, n < 0 ? 0 : n, length);
  5969. }
  5970. /**
  5971. * Creates a slice of `array` with `n` elements dropped from the end.
  5972. *
  5973. * @static
  5974. * @memberOf _
  5975. * @since 3.0.0
  5976. * @category Array
  5977. * @param {Array} array The array to query.
  5978. * @param {number} [n=1] The number of elements to drop.
  5979. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  5980. * @returns {Array} Returns the slice of `array`.
  5981. * @example
  5982. *
  5983. * _.dropRight([1, 2, 3]);
  5984. * // => [1, 2]
  5985. *
  5986. * _.dropRight([1, 2, 3], 2);
  5987. * // => [1]
  5988. *
  5989. * _.dropRight([1, 2, 3], 5);
  5990. * // => []
  5991. *
  5992. * _.dropRight([1, 2, 3], 0);
  5993. * // => [1, 2, 3]
  5994. */
  5995. function dropRight(array, n, guard) {
  5996. var length = array ? array.length : 0;
  5997. if (!length) {
  5998. return [];
  5999. }
  6000. n = (guard || n === undefined) ? 1 : toInteger(n);
  6001. n = length - n;
  6002. return baseSlice(array, 0, n < 0 ? 0 : n);
  6003. }
  6004. /**
  6005. * Creates a slice of `array` excluding elements dropped from the end.
  6006. * Elements are dropped until `predicate` returns falsey. The predicate is
  6007. * invoked with three arguments: (value, index, array).
  6008. *
  6009. * @static
  6010. * @memberOf _
  6011. * @since 3.0.0
  6012. * @category Array
  6013. * @param {Array} array The array to query.
  6014. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6015. * @returns {Array} Returns the slice of `array`.
  6016. * @example
  6017. *
  6018. * var users = [
  6019. * { 'user': 'barney', 'active': true },
  6020. * { 'user': 'fred', 'active': false },
  6021. * { 'user': 'pebbles', 'active': false }
  6022. * ];
  6023. *
  6024. * _.dropRightWhile(users, function(o) { return !o.active; });
  6025. * // => objects for ['barney']
  6026. *
  6027. * // The `_.matches` iteratee shorthand.
  6028. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6029. * // => objects for ['barney', 'fred']
  6030. *
  6031. * // The `_.matchesProperty` iteratee shorthand.
  6032. * _.dropRightWhile(users, ['active', false]);
  6033. * // => objects for ['barney']
  6034. *
  6035. * // The `_.property` iteratee shorthand.
  6036. * _.dropRightWhile(users, 'active');
  6037. * // => objects for ['barney', 'fred', 'pebbles']
  6038. */
  6039. function dropRightWhile(array, predicate) {
  6040. return (array && array.length)
  6041. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6042. : [];
  6043. }
  6044. /**
  6045. * Creates a slice of `array` excluding elements dropped from the beginning.
  6046. * Elements are dropped until `predicate` returns falsey. The predicate is
  6047. * invoked with three arguments: (value, index, array).
  6048. *
  6049. * @static
  6050. * @memberOf _
  6051. * @since 3.0.0
  6052. * @category Array
  6053. * @param {Array} array The array to query.
  6054. * @param {Function} [predicate=_.identity]
  6055. * The function invoked per iteration.
  6056. * @returns {Array} Returns the slice of `array`.
  6057. * @example
  6058. *
  6059. * var users = [
  6060. * { 'user': 'barney', 'active': false },
  6061. * { 'user': 'fred', 'active': false },
  6062. * { 'user': 'pebbles', 'active': true }
  6063. * ];
  6064. *
  6065. * _.dropWhile(users, function(o) { return !o.active; });
  6066. * // => objects for ['pebbles']
  6067. *
  6068. * // The `_.matches` iteratee shorthand.
  6069. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6070. * // => objects for ['fred', 'pebbles']
  6071. *
  6072. * // The `_.matchesProperty` iteratee shorthand.
  6073. * _.dropWhile(users, ['active', false]);
  6074. * // => objects for ['pebbles']
  6075. *
  6076. * // The `_.property` iteratee shorthand.
  6077. * _.dropWhile(users, 'active');
  6078. * // => objects for ['barney', 'fred', 'pebbles']
  6079. */
  6080. function dropWhile(array, predicate) {
  6081. return (array && array.length)
  6082. ? baseWhile(array, getIteratee(predicate, 3), true)
  6083. : [];
  6084. }
  6085. /**
  6086. * Fills elements of `array` with `value` from `start` up to, but not
  6087. * including, `end`.
  6088. *
  6089. * **Note:** This method mutates `array`.
  6090. *
  6091. * @static
  6092. * @memberOf _
  6093. * @since 3.2.0
  6094. * @category Array
  6095. * @param {Array} array The array to fill.
  6096. * @param {*} value The value to fill `array` with.
  6097. * @param {number} [start=0] The start position.
  6098. * @param {number} [end=array.length] The end position.
  6099. * @returns {Array} Returns `array`.
  6100. * @example
  6101. *
  6102. * var array = [1, 2, 3];
  6103. *
  6104. * _.fill(array, 'a');
  6105. * console.log(array);
  6106. * // => ['a', 'a', 'a']
  6107. *
  6108. * _.fill(Array(3), 2);
  6109. * // => [2, 2, 2]
  6110. *
  6111. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6112. * // => [4, '*', '*', 10]
  6113. */
  6114. function fill(array, value, start, end) {
  6115. var length = array ? array.length : 0;
  6116. if (!length) {
  6117. return [];
  6118. }
  6119. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6120. start = 0;
  6121. end = length;
  6122. }
  6123. return baseFill(array, value, start, end);
  6124. }
  6125. /**
  6126. * This method is like `_.find` except that it returns the index of the first
  6127. * element `predicate` returns truthy for instead of the element itself.
  6128. *
  6129. * @static
  6130. * @memberOf _
  6131. * @since 1.1.0
  6132. * @category Array
  6133. * @param {Array} array The array to search.
  6134. * @param {Function} [predicate=_.identity]
  6135. * The function invoked per iteration.
  6136. * @param {number} [fromIndex=0] The index to search from.
  6137. * @returns {number} Returns the index of the found element, else `-1`.
  6138. * @example
  6139. *
  6140. * var users = [
  6141. * { 'user': 'barney', 'active': false },
  6142. * { 'user': 'fred', 'active': false },
  6143. * { 'user': 'pebbles', 'active': true }
  6144. * ];
  6145. *
  6146. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6147. * // => 0
  6148. *
  6149. * // The `_.matches` iteratee shorthand.
  6150. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6151. * // => 1
  6152. *
  6153. * // The `_.matchesProperty` iteratee shorthand.
  6154. * _.findIndex(users, ['active', false]);
  6155. * // => 0
  6156. *
  6157. * // The `_.property` iteratee shorthand.
  6158. * _.findIndex(users, 'active');
  6159. * // => 2
  6160. */
  6161. function findIndex(array, predicate, fromIndex) {
  6162. var length = array ? array.length : 0;
  6163. if (!length) {
  6164. return -1;
  6165. }
  6166. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6167. if (index < 0) {
  6168. index = nativeMax(length + index, 0);
  6169. }
  6170. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6171. }
  6172. /**
  6173. * This method is like `_.findIndex` except that it iterates over elements
  6174. * of `collection` from right to left.
  6175. *
  6176. * @static
  6177. * @memberOf _
  6178. * @since 2.0.0
  6179. * @category Array
  6180. * @param {Array} array The array to search.
  6181. * @param {Function} [predicate=_.identity]
  6182. * The function invoked per iteration.
  6183. * @param {number} [fromIndex=array.length-1] The index to search from.
  6184. * @returns {number} Returns the index of the found element, else `-1`.
  6185. * @example
  6186. *
  6187. * var users = [
  6188. * { 'user': 'barney', 'active': true },
  6189. * { 'user': 'fred', 'active': false },
  6190. * { 'user': 'pebbles', 'active': false }
  6191. * ];
  6192. *
  6193. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6194. * // => 2
  6195. *
  6196. * // The `_.matches` iteratee shorthand.
  6197. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6198. * // => 0
  6199. *
  6200. * // The `_.matchesProperty` iteratee shorthand.
  6201. * _.findLastIndex(users, ['active', false]);
  6202. * // => 2
  6203. *
  6204. * // The `_.property` iteratee shorthand.
  6205. * _.findLastIndex(users, 'active');
  6206. * // => 0
  6207. */
  6208. function findLastIndex(array, predicate, fromIndex) {
  6209. var length = array ? array.length : 0;
  6210. if (!length) {
  6211. return -1;
  6212. }
  6213. var index = length - 1;
  6214. if (fromIndex !== undefined) {
  6215. index = toInteger(fromIndex);
  6216. index = fromIndex < 0
  6217. ? nativeMax(length + index, 0)
  6218. : nativeMin(index, length - 1);
  6219. }
  6220. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6221. }
  6222. /**
  6223. * Flattens `array` a single level deep.
  6224. *
  6225. * @static
  6226. * @memberOf _
  6227. * @since 0.1.0
  6228. * @category Array
  6229. * @param {Array} array The array to flatten.
  6230. * @returns {Array} Returns the new flattened array.
  6231. * @example
  6232. *
  6233. * _.flatten([1, [2, [3, [4]], 5]]);
  6234. * // => [1, 2, [3, [4]], 5]
  6235. */
  6236. function flatten(array) {
  6237. var length = array ? array.length : 0;
  6238. return length ? baseFlatten(array, 1) : [];
  6239. }
  6240. /**
  6241. * Recursively flattens `array`.
  6242. *
  6243. * @static
  6244. * @memberOf _
  6245. * @since 3.0.0
  6246. * @category Array
  6247. * @param {Array} array The array to flatten.
  6248. * @returns {Array} Returns the new flattened array.
  6249. * @example
  6250. *
  6251. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6252. * // => [1, 2, 3, 4, 5]
  6253. */
  6254. function flattenDeep(array) {
  6255. var length = array ? array.length : 0;
  6256. return length ? baseFlatten(array, INFINITY) : [];
  6257. }
  6258. /**
  6259. * Recursively flatten `array` up to `depth` times.
  6260. *
  6261. * @static
  6262. * @memberOf _
  6263. * @since 4.4.0
  6264. * @category Array
  6265. * @param {Array} array The array to flatten.
  6266. * @param {number} [depth=1] The maximum recursion depth.
  6267. * @returns {Array} Returns the new flattened array.
  6268. * @example
  6269. *
  6270. * var array = [1, [2, [3, [4]], 5]];
  6271. *
  6272. * _.flattenDepth(array, 1);
  6273. * // => [1, 2, [3, [4]], 5]
  6274. *
  6275. * _.flattenDepth(array, 2);
  6276. * // => [1, 2, 3, [4], 5]
  6277. */
  6278. function flattenDepth(array, depth) {
  6279. var length = array ? array.length : 0;
  6280. if (!length) {
  6281. return [];
  6282. }
  6283. depth = depth === undefined ? 1 : toInteger(depth);
  6284. return baseFlatten(array, depth);
  6285. }
  6286. /**
  6287. * The inverse of `_.toPairs`; this method returns an object composed
  6288. * from key-value `pairs`.
  6289. *
  6290. * @static
  6291. * @memberOf _
  6292. * @since 4.0.0
  6293. * @category Array
  6294. * @param {Array} pairs The key-value pairs.
  6295. * @returns {Object} Returns the new object.
  6296. * @example
  6297. *
  6298. * _.fromPairs([['a', 1], ['b', 2]]);
  6299. * // => { 'a': 1, 'b': 2 }
  6300. */
  6301. function fromPairs(pairs) {
  6302. var index = -1,
  6303. length = pairs ? pairs.length : 0,
  6304. result = {};
  6305. while (++index < length) {
  6306. var pair = pairs[index];
  6307. result[pair[0]] = pair[1];
  6308. }
  6309. return result;
  6310. }
  6311. /**
  6312. * Gets the first element of `array`.
  6313. *
  6314. * @static
  6315. * @memberOf _
  6316. * @since 0.1.0
  6317. * @alias first
  6318. * @category Array
  6319. * @param {Array} array The array to query.
  6320. * @returns {*} Returns the first element of `array`.
  6321. * @example
  6322. *
  6323. * _.head([1, 2, 3]);
  6324. * // => 1
  6325. *
  6326. * _.head([]);
  6327. * // => undefined
  6328. */
  6329. function head(array) {
  6330. return (array && array.length) ? array[0] : undefined;
  6331. }
  6332. /**
  6333. * Gets the index at which the first occurrence of `value` is found in `array`
  6334. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6335. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6336. * offset from the end of `array`.
  6337. *
  6338. * @static
  6339. * @memberOf _
  6340. * @since 0.1.0
  6341. * @category Array
  6342. * @param {Array} array The array to search.
  6343. * @param {*} value The value to search for.
  6344. * @param {number} [fromIndex=0] The index to search from.
  6345. * @returns {number} Returns the index of the matched value, else `-1`.
  6346. * @example
  6347. *
  6348. * _.indexOf([1, 2, 1, 2], 2);
  6349. * // => 1
  6350. *
  6351. * // Search from the `fromIndex`.
  6352. * _.indexOf([1, 2, 1, 2], 2, 2);
  6353. * // => 3
  6354. */
  6355. function indexOf(array, value, fromIndex) {
  6356. var length = array ? array.length : 0;
  6357. if (!length) {
  6358. return -1;
  6359. }
  6360. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6361. if (index < 0) {
  6362. index = nativeMax(length + index, 0);
  6363. }
  6364. return baseIndexOf(array, value, index);
  6365. }
  6366. /**
  6367. * Gets all but the last element of `array`.
  6368. *
  6369. * @static
  6370. * @memberOf _
  6371. * @since 0.1.0
  6372. * @category Array
  6373. * @param {Array} array The array to query.
  6374. * @returns {Array} Returns the slice of `array`.
  6375. * @example
  6376. *
  6377. * _.initial([1, 2, 3]);
  6378. * // => [1, 2]
  6379. */
  6380. function initial(array) {
  6381. return dropRight(array, 1);
  6382. }
  6383. /**
  6384. * Creates an array of unique values that are included in all given arrays
  6385. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6386. * for equality comparisons. The order of result values is determined by the
  6387. * order they occur in the first array.
  6388. *
  6389. * @static
  6390. * @memberOf _
  6391. * @since 0.1.0
  6392. * @category Array
  6393. * @param {...Array} [arrays] The arrays to inspect.
  6394. * @returns {Array} Returns the new array of intersecting values.
  6395. * @example
  6396. *
  6397. * _.intersection([2, 1], [2, 3]);
  6398. * // => [2]
  6399. */
  6400. var intersection = baseRest(function(arrays) {
  6401. var mapped = arrayMap(arrays, castArrayLikeObject);
  6402. return (mapped.length && mapped[0] === arrays[0])
  6403. ? baseIntersection(mapped)
  6404. : [];
  6405. });
  6406. /**
  6407. * This method is like `_.intersection` except that it accepts `iteratee`
  6408. * which is invoked for each element of each `arrays` to generate the criterion
  6409. * by which they're compared. Result values are chosen from the first array.
  6410. * The iteratee is invoked with one argument: (value).
  6411. *
  6412. * @static
  6413. * @memberOf _
  6414. * @since 4.0.0
  6415. * @category Array
  6416. * @param {...Array} [arrays] The arrays to inspect.
  6417. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6418. * @returns {Array} Returns the new array of intersecting values.
  6419. * @example
  6420. *
  6421. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6422. * // => [2.1]
  6423. *
  6424. * // The `_.property` iteratee shorthand.
  6425. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6426. * // => [{ 'x': 1 }]
  6427. */
  6428. var intersectionBy = baseRest(function(arrays) {
  6429. var iteratee = last(arrays),
  6430. mapped = arrayMap(arrays, castArrayLikeObject);
  6431. if (iteratee === last(mapped)) {
  6432. iteratee = undefined;
  6433. } else {
  6434. mapped.pop();
  6435. }
  6436. return (mapped.length && mapped[0] === arrays[0])
  6437. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6438. : [];
  6439. });
  6440. /**
  6441. * This method is like `_.intersection` except that it accepts `comparator`
  6442. * which is invoked to compare elements of `arrays`. Result values are chosen
  6443. * from the first array. The comparator is invoked with two arguments:
  6444. * (arrVal, othVal).
  6445. *
  6446. * @static
  6447. * @memberOf _
  6448. * @since 4.0.0
  6449. * @category Array
  6450. * @param {...Array} [arrays] The arrays to inspect.
  6451. * @param {Function} [comparator] The comparator invoked per element.
  6452. * @returns {Array} Returns the new array of intersecting values.
  6453. * @example
  6454. *
  6455. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6456. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6457. *
  6458. * _.intersectionWith(objects, others, _.isEqual);
  6459. * // => [{ 'x': 1, 'y': 2 }]
  6460. */
  6461. var intersectionWith = baseRest(function(arrays) {
  6462. var comparator = last(arrays),
  6463. mapped = arrayMap(arrays, castArrayLikeObject);
  6464. if (comparator === last(mapped)) {
  6465. comparator = undefined;
  6466. } else {
  6467. mapped.pop();
  6468. }
  6469. return (mapped.length && mapped[0] === arrays[0])
  6470. ? baseIntersection(mapped, undefined, comparator)
  6471. : [];
  6472. });
  6473. /**
  6474. * Converts all elements in `array` into a string separated by `separator`.
  6475. *
  6476. * @static
  6477. * @memberOf _
  6478. * @since 4.0.0
  6479. * @category Array
  6480. * @param {Array} array The array to convert.
  6481. * @param {string} [separator=','] The element separator.
  6482. * @returns {string} Returns the joined string.
  6483. * @example
  6484. *
  6485. * _.join(['a', 'b', 'c'], '~');
  6486. * // => 'a~b~c'
  6487. */
  6488. function join(array, separator) {
  6489. return array ? nativeJoin.call(array, separator) : '';
  6490. }
  6491. /**
  6492. * Gets the last element of `array`.
  6493. *
  6494. * @static
  6495. * @memberOf _
  6496. * @since 0.1.0
  6497. * @category Array
  6498. * @param {Array} array The array to query.
  6499. * @returns {*} Returns the last element of `array`.
  6500. * @example
  6501. *
  6502. * _.last([1, 2, 3]);
  6503. * // => 3
  6504. */
  6505. function last(array) {
  6506. var length = array ? array.length : 0;
  6507. return length ? array[length - 1] : undefined;
  6508. }
  6509. /**
  6510. * This method is like `_.indexOf` except that it iterates over elements of
  6511. * `array` from right to left.
  6512. *
  6513. * @static
  6514. * @memberOf _
  6515. * @since 0.1.0
  6516. * @category Array
  6517. * @param {Array} array The array to search.
  6518. * @param {*} value The value to search for.
  6519. * @param {number} [fromIndex=array.length-1] The index to search from.
  6520. * @returns {number} Returns the index of the matched value, else `-1`.
  6521. * @example
  6522. *
  6523. * _.lastIndexOf([1, 2, 1, 2], 2);
  6524. * // => 3
  6525. *
  6526. * // Search from the `fromIndex`.
  6527. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  6528. * // => 1
  6529. */
  6530. function lastIndexOf(array, value, fromIndex) {
  6531. var length = array ? array.length : 0;
  6532. if (!length) {
  6533. return -1;
  6534. }
  6535. var index = length;
  6536. if (fromIndex !== undefined) {
  6537. index = toInteger(fromIndex);
  6538. index = (
  6539. index < 0
  6540. ? nativeMax(length + index, 0)
  6541. : nativeMin(index, length - 1)
  6542. ) + 1;
  6543. }
  6544. if (value !== value) {
  6545. return baseFindIndex(array, baseIsNaN, index - 1, true);
  6546. }
  6547. while (index--) {
  6548. if (array[index] === value) {
  6549. return index;
  6550. }
  6551. }
  6552. return -1;
  6553. }
  6554. /**
  6555. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  6556. * element from the end is returned.
  6557. *
  6558. * @static
  6559. * @memberOf _
  6560. * @since 4.11.0
  6561. * @category Array
  6562. * @param {Array} array The array to query.
  6563. * @param {number} [n=0] The index of the element to return.
  6564. * @returns {*} Returns the nth element of `array`.
  6565. * @example
  6566. *
  6567. * var array = ['a', 'b', 'c', 'd'];
  6568. *
  6569. * _.nth(array, 1);
  6570. * // => 'b'
  6571. *
  6572. * _.nth(array, -2);
  6573. * // => 'c';
  6574. */
  6575. function nth(array, n) {
  6576. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  6577. }
  6578. /**
  6579. * Removes all given values from `array` using
  6580. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6581. * for equality comparisons.
  6582. *
  6583. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  6584. * to remove elements from an array by predicate.
  6585. *
  6586. * @static
  6587. * @memberOf _
  6588. * @since 2.0.0
  6589. * @category Array
  6590. * @param {Array} array The array to modify.
  6591. * @param {...*} [values] The values to remove.
  6592. * @returns {Array} Returns `array`.
  6593. * @example
  6594. *
  6595. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  6596. *
  6597. * _.pull(array, 'a', 'c');
  6598. * console.log(array);
  6599. * // => ['b', 'b']
  6600. */
  6601. var pull = baseRest(pullAll);
  6602. /**
  6603. * This method is like `_.pull` except that it accepts an array of values to remove.
  6604. *
  6605. * **Note:** Unlike `_.difference`, this method mutates `array`.
  6606. *
  6607. * @static
  6608. * @memberOf _
  6609. * @since 4.0.0
  6610. * @category Array
  6611. * @param {Array} array The array to modify.
  6612. * @param {Array} values The values to remove.
  6613. * @returns {Array} Returns `array`.
  6614. * @example
  6615. *
  6616. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  6617. *
  6618. * _.pullAll(array, ['a', 'c']);
  6619. * console.log(array);
  6620. * // => ['b', 'b']
  6621. */
  6622. function pullAll(array, values) {
  6623. return (array && array.length && values && values.length)
  6624. ? basePullAll(array, values)
  6625. : array;
  6626. }
  6627. /**
  6628. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  6629. * invoked for each element of `array` and `values` to generate the criterion
  6630. * by which they're compared. The iteratee is invoked with one argument: (value).
  6631. *
  6632. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  6633. *
  6634. * @static
  6635. * @memberOf _
  6636. * @since 4.0.0
  6637. * @category Array
  6638. * @param {Array} array The array to modify.
  6639. * @param {Array} values The values to remove.
  6640. * @param {Function} [iteratee=_.identity]
  6641. * The iteratee invoked per element.
  6642. * @returns {Array} Returns `array`.
  6643. * @example
  6644. *
  6645. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  6646. *
  6647. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  6648. * console.log(array);
  6649. * // => [{ 'x': 2 }]
  6650. */
  6651. function pullAllBy(array, values, iteratee) {
  6652. return (array && array.length && values && values.length)
  6653. ? basePullAll(array, values, getIteratee(iteratee, 2))
  6654. : array;
  6655. }
  6656. /**
  6657. * This method is like `_.pullAll` except that it accepts `comparator` which
  6658. * is invoked to compare elements of `array` to `values`. The comparator is
  6659. * invoked with two arguments: (arrVal, othVal).
  6660. *
  6661. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  6662. *
  6663. * @static
  6664. * @memberOf _
  6665. * @since 4.6.0
  6666. * @category Array
  6667. * @param {Array} array The array to modify.
  6668. * @param {Array} values The values to remove.
  6669. * @param {Function} [comparator] The comparator invoked per element.
  6670. * @returns {Array} Returns `array`.
  6671. * @example
  6672. *
  6673. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  6674. *
  6675. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  6676. * console.log(array);
  6677. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  6678. */
  6679. function pullAllWith(array, values, comparator) {
  6680. return (array && array.length && values && values.length)
  6681. ? basePullAll(array, values, undefined, comparator)
  6682. : array;
  6683. }
  6684. /**
  6685. * Removes elements from `array` corresponding to `indexes` and returns an
  6686. * array of removed elements.
  6687. *
  6688. * **Note:** Unlike `_.at`, this method mutates `array`.
  6689. *
  6690. * @static
  6691. * @memberOf _
  6692. * @since 3.0.0
  6693. * @category Array
  6694. * @param {Array} array The array to modify.
  6695. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  6696. * @returns {Array} Returns the new array of removed elements.
  6697. * @example
  6698. *
  6699. * var array = ['a', 'b', 'c', 'd'];
  6700. * var pulled = _.pullAt(array, [1, 3]);
  6701. *
  6702. * console.log(array);
  6703. * // => ['a', 'c']
  6704. *
  6705. * console.log(pulled);
  6706. * // => ['b', 'd']
  6707. */
  6708. var pullAt = baseRest(function(array, indexes) {
  6709. indexes = baseFlatten(indexes, 1);
  6710. var length = array ? array.length : 0,
  6711. result = baseAt(array, indexes);
  6712. basePullAt(array, arrayMap(indexes, function(index) {
  6713. return isIndex(index, length) ? +index : index;
  6714. }).sort(compareAscending));
  6715. return result;
  6716. });
  6717. /**
  6718. * Removes all elements from `array` that `predicate` returns truthy for
  6719. * and returns an array of the removed elements. The predicate is invoked
  6720. * with three arguments: (value, index, array).
  6721. *
  6722. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  6723. * to pull elements from an array by value.
  6724. *
  6725. * @static
  6726. * @memberOf _
  6727. * @since 2.0.0
  6728. * @category Array
  6729. * @param {Array} array The array to modify.
  6730. * @param {Function} [predicate=_.identity]
  6731. * The function invoked per iteration.
  6732. * @returns {Array} Returns the new array of removed elements.
  6733. * @example
  6734. *
  6735. * var array = [1, 2, 3, 4];
  6736. * var evens = _.remove(array, function(n) {
  6737. * return n % 2 == 0;
  6738. * });
  6739. *
  6740. * console.log(array);
  6741. * // => [1, 3]
  6742. *
  6743. * console.log(evens);
  6744. * // => [2, 4]
  6745. */
  6746. function remove(array, predicate) {
  6747. var result = [];
  6748. if (!(array && array.length)) {
  6749. return result;
  6750. }
  6751. var index = -1,
  6752. indexes = [],
  6753. length = array.length;
  6754. predicate = getIteratee(predicate, 3);
  6755. while (++index < length) {
  6756. var value = array[index];
  6757. if (predicate(value, index, array)) {
  6758. result.push(value);
  6759. indexes.push(index);
  6760. }
  6761. }
  6762. basePullAt(array, indexes);
  6763. return result;
  6764. }
  6765. /**
  6766. * Reverses `array` so that the first element becomes the last, the second
  6767. * element becomes the second to last, and so on.
  6768. *
  6769. * **Note:** This method mutates `array` and is based on
  6770. * [`Array#reverse`](https://mdn.io/Array/reverse).
  6771. *
  6772. * @static
  6773. * @memberOf _
  6774. * @since 4.0.0
  6775. * @category Array
  6776. * @param {Array} array The array to modify.
  6777. * @returns {Array} Returns `array`.
  6778. * @example
  6779. *
  6780. * var array = [1, 2, 3];
  6781. *
  6782. * _.reverse(array);
  6783. * // => [3, 2, 1]
  6784. *
  6785. * console.log(array);
  6786. * // => [3, 2, 1]
  6787. */
  6788. function reverse(array) {
  6789. return array ? nativeReverse.call(array) : array;
  6790. }
  6791. /**
  6792. * Creates a slice of `array` from `start` up to, but not including, `end`.
  6793. *
  6794. * **Note:** This method is used instead of
  6795. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  6796. * returned.
  6797. *
  6798. * @static
  6799. * @memberOf _
  6800. * @since 3.0.0
  6801. * @category Array
  6802. * @param {Array} array The array to slice.
  6803. * @param {number} [start=0] The start position.
  6804. * @param {number} [end=array.length] The end position.
  6805. * @returns {Array} Returns the slice of `array`.
  6806. */
  6807. function slice(array, start, end) {
  6808. var length = array ? array.length : 0;
  6809. if (!length) {
  6810. return [];
  6811. }
  6812. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  6813. start = 0;
  6814. end = length;
  6815. }
  6816. else {
  6817. start = start == null ? 0 : toInteger(start);
  6818. end = end === undefined ? length : toInteger(end);
  6819. }
  6820. return baseSlice(array, start, end);
  6821. }
  6822. /**
  6823. * Uses a binary search to determine the lowest index at which `value`
  6824. * should be inserted into `array` in order to maintain its sort order.
  6825. *
  6826. * @static
  6827. * @memberOf _
  6828. * @since 0.1.0
  6829. * @category Array
  6830. * @param {Array} array The sorted array to inspect.
  6831. * @param {*} value The value to evaluate.
  6832. * @returns {number} Returns the index at which `value` should be inserted
  6833. * into `array`.
  6834. * @example
  6835. *
  6836. * _.sortedIndex([30, 50], 40);
  6837. * // => 1
  6838. */
  6839. function sortedIndex(array, value) {
  6840. return baseSortedIndex(array, value);
  6841. }
  6842. /**
  6843. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  6844. * which is invoked for `value` and each element of `array` to compute their
  6845. * sort ranking. The iteratee is invoked with one argument: (value).
  6846. *
  6847. * @static
  6848. * @memberOf _
  6849. * @since 4.0.0
  6850. * @category Array
  6851. * @param {Array} array The sorted array to inspect.
  6852. * @param {*} value The value to evaluate.
  6853. * @param {Function} [iteratee=_.identity]
  6854. * The iteratee invoked per element.
  6855. * @returns {number} Returns the index at which `value` should be inserted
  6856. * into `array`.
  6857. * @example
  6858. *
  6859. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  6860. *
  6861. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  6862. * // => 0
  6863. *
  6864. * // The `_.property` iteratee shorthand.
  6865. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  6866. * // => 0
  6867. */
  6868. function sortedIndexBy(array, value, iteratee) {
  6869. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  6870. }
  6871. /**
  6872. * This method is like `_.indexOf` except that it performs a binary
  6873. * search on a sorted `array`.
  6874. *
  6875. * @static
  6876. * @memberOf _
  6877. * @since 4.0.0
  6878. * @category Array
  6879. * @param {Array} array The array to search.
  6880. * @param {*} value The value to search for.
  6881. * @returns {number} Returns the index of the matched value, else `-1`.
  6882. * @example
  6883. *
  6884. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  6885. * // => 1
  6886. */
  6887. function sortedIndexOf(array, value) {
  6888. var length = array ? array.length : 0;
  6889. if (length) {
  6890. var index = baseSortedIndex(array, value);
  6891. if (index < length && eq(array[index], value)) {
  6892. return index;
  6893. }
  6894. }
  6895. return -1;
  6896. }
  6897. /**
  6898. * This method is like `_.sortedIndex` except that it returns the highest
  6899. * index at which `value` should be inserted into `array` in order to
  6900. * maintain its sort order.
  6901. *
  6902. * @static
  6903. * @memberOf _
  6904. * @since 3.0.0
  6905. * @category Array
  6906. * @param {Array} array The sorted array to inspect.
  6907. * @param {*} value The value to evaluate.
  6908. * @returns {number} Returns the index at which `value` should be inserted
  6909. * into `array`.
  6910. * @example
  6911. *
  6912. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  6913. * // => 4
  6914. */
  6915. function sortedLastIndex(array, value) {
  6916. return baseSortedIndex(array, value, true);
  6917. }
  6918. /**
  6919. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  6920. * which is invoked for `value` and each element of `array` to compute their
  6921. * sort ranking. The iteratee is invoked with one argument: (value).
  6922. *
  6923. * @static
  6924. * @memberOf _
  6925. * @since 4.0.0
  6926. * @category Array
  6927. * @param {Array} array The sorted array to inspect.
  6928. * @param {*} value The value to evaluate.
  6929. * @param {Function} [iteratee=_.identity]
  6930. * The iteratee invoked per element.
  6931. * @returns {number} Returns the index at which `value` should be inserted
  6932. * into `array`.
  6933. * @example
  6934. *
  6935. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  6936. *
  6937. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  6938. * // => 1
  6939. *
  6940. * // The `_.property` iteratee shorthand.
  6941. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  6942. * // => 1
  6943. */
  6944. function sortedLastIndexBy(array, value, iteratee) {
  6945. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  6946. }
  6947. /**
  6948. * This method is like `_.lastIndexOf` except that it performs a binary
  6949. * search on a sorted `array`.
  6950. *
  6951. * @static
  6952. * @memberOf _
  6953. * @since 4.0.0
  6954. * @category Array
  6955. * @param {Array} array The array to search.
  6956. * @param {*} value The value to search for.
  6957. * @returns {number} Returns the index of the matched value, else `-1`.
  6958. * @example
  6959. *
  6960. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  6961. * // => 3
  6962. */
  6963. function sortedLastIndexOf(array, value) {
  6964. var length = array ? array.length : 0;
  6965. if (length) {
  6966. var index = baseSortedIndex(array, value, true) - 1;
  6967. if (eq(array[index], value)) {
  6968. return index;
  6969. }
  6970. }
  6971. return -1;
  6972. }
  6973. /**
  6974. * This method is like `_.uniq` except that it's designed and optimized
  6975. * for sorted arrays.
  6976. *
  6977. * @static
  6978. * @memberOf _
  6979. * @since 4.0.0
  6980. * @category Array
  6981. * @param {Array} array The array to inspect.
  6982. * @returns {Array} Returns the new duplicate free array.
  6983. * @example
  6984. *
  6985. * _.sortedUniq([1, 1, 2]);
  6986. * // => [1, 2]
  6987. */
  6988. function sortedUniq(array) {
  6989. return (array && array.length)
  6990. ? baseSortedUniq(array)
  6991. : [];
  6992. }
  6993. /**
  6994. * This method is like `_.uniqBy` except that it's designed and optimized
  6995. * for sorted arrays.
  6996. *
  6997. * @static
  6998. * @memberOf _
  6999. * @since 4.0.0
  7000. * @category Array
  7001. * @param {Array} array The array to inspect.
  7002. * @param {Function} [iteratee] The iteratee invoked per element.
  7003. * @returns {Array} Returns the new duplicate free array.
  7004. * @example
  7005. *
  7006. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7007. * // => [1.1, 2.3]
  7008. */
  7009. function sortedUniqBy(array, iteratee) {
  7010. return (array && array.length)
  7011. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7012. : [];
  7013. }
  7014. /**
  7015. * Gets all but the first element of `array`.
  7016. *
  7017. * @static
  7018. * @memberOf _
  7019. * @since 4.0.0
  7020. * @category Array
  7021. * @param {Array} array The array to query.
  7022. * @returns {Array} Returns the slice of `array`.
  7023. * @example
  7024. *
  7025. * _.tail([1, 2, 3]);
  7026. * // => [2, 3]
  7027. */
  7028. function tail(array) {
  7029. return drop(array, 1);
  7030. }
  7031. /**
  7032. * Creates a slice of `array` with `n` elements taken from the beginning.
  7033. *
  7034. * @static
  7035. * @memberOf _
  7036. * @since 0.1.0
  7037. * @category Array
  7038. * @param {Array} array The array to query.
  7039. * @param {number} [n=1] The number of elements to take.
  7040. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7041. * @returns {Array} Returns the slice of `array`.
  7042. * @example
  7043. *
  7044. * _.take([1, 2, 3]);
  7045. * // => [1]
  7046. *
  7047. * _.take([1, 2, 3], 2);
  7048. * // => [1, 2]
  7049. *
  7050. * _.take([1, 2, 3], 5);
  7051. * // => [1, 2, 3]
  7052. *
  7053. * _.take([1, 2, 3], 0);
  7054. * // => []
  7055. */
  7056. function take(array, n, guard) {
  7057. if (!(array && array.length)) {
  7058. return [];
  7059. }
  7060. n = (guard || n === undefined) ? 1 : toInteger(n);
  7061. return baseSlice(array, 0, n < 0 ? 0 : n);
  7062. }
  7063. /**
  7064. * Creates a slice of `array` with `n` elements taken from the end.
  7065. *
  7066. * @static
  7067. * @memberOf _
  7068. * @since 3.0.0
  7069. * @category Array
  7070. * @param {Array} array The array to query.
  7071. * @param {number} [n=1] The number of elements to take.
  7072. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7073. * @returns {Array} Returns the slice of `array`.
  7074. * @example
  7075. *
  7076. * _.takeRight([1, 2, 3]);
  7077. * // => [3]
  7078. *
  7079. * _.takeRight([1, 2, 3], 2);
  7080. * // => [2, 3]
  7081. *
  7082. * _.takeRight([1, 2, 3], 5);
  7083. * // => [1, 2, 3]
  7084. *
  7085. * _.takeRight([1, 2, 3], 0);
  7086. * // => []
  7087. */
  7088. function takeRight(array, n, guard) {
  7089. var length = array ? array.length : 0;
  7090. if (!length) {
  7091. return [];
  7092. }
  7093. n = (guard || n === undefined) ? 1 : toInteger(n);
  7094. n = length - n;
  7095. return baseSlice(array, n < 0 ? 0 : n, length);
  7096. }
  7097. /**
  7098. * Creates a slice of `array` with elements taken from the end. Elements are
  7099. * taken until `predicate` returns falsey. The predicate is invoked with
  7100. * three arguments: (value, index, array).
  7101. *
  7102. * @static
  7103. * @memberOf _
  7104. * @since 3.0.0
  7105. * @category Array
  7106. * @param {Array} array The array to query.
  7107. * @param {Function} [predicate=_.identity]
  7108. * The function invoked per iteration.
  7109. * @returns {Array} Returns the slice of `array`.
  7110. * @example
  7111. *
  7112. * var users = [
  7113. * { 'user': 'barney', 'active': true },
  7114. * { 'user': 'fred', 'active': false },
  7115. * { 'user': 'pebbles', 'active': false }
  7116. * ];
  7117. *
  7118. * _.takeRightWhile(users, function(o) { return !o.active; });
  7119. * // => objects for ['fred', 'pebbles']
  7120. *
  7121. * // The `_.matches` iteratee shorthand.
  7122. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7123. * // => objects for ['pebbles']
  7124. *
  7125. * // The `_.matchesProperty` iteratee shorthand.
  7126. * _.takeRightWhile(users, ['active', false]);
  7127. * // => objects for ['fred', 'pebbles']
  7128. *
  7129. * // The `_.property` iteratee shorthand.
  7130. * _.takeRightWhile(users, 'active');
  7131. * // => []
  7132. */
  7133. function takeRightWhile(array, predicate) {
  7134. return (array && array.length)
  7135. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7136. : [];
  7137. }
  7138. /**
  7139. * Creates a slice of `array` with elements taken from the beginning. Elements
  7140. * are taken until `predicate` returns falsey. The predicate is invoked with
  7141. * three arguments: (value, index, array).
  7142. *
  7143. * @static
  7144. * @memberOf _
  7145. * @since 3.0.0
  7146. * @category Array
  7147. * @param {Array} array The array to query.
  7148. * @param {Function} [predicate=_.identity]
  7149. * The function invoked per iteration.
  7150. * @returns {Array} Returns the slice of `array`.
  7151. * @example
  7152. *
  7153. * var users = [
  7154. * { 'user': 'barney', 'active': false },
  7155. * { 'user': 'fred', 'active': false},
  7156. * { 'user': 'pebbles', 'active': true }
  7157. * ];
  7158. *
  7159. * _.takeWhile(users, function(o) { return !o.active; });
  7160. * // => objects for ['barney', 'fred']
  7161. *
  7162. * // The `_.matches` iteratee shorthand.
  7163. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7164. * // => objects for ['barney']
  7165. *
  7166. * // The `_.matchesProperty` iteratee shorthand.
  7167. * _.takeWhile(users, ['active', false]);
  7168. * // => objects for ['barney', 'fred']
  7169. *
  7170. * // The `_.property` iteratee shorthand.
  7171. * _.takeWhile(users, 'active');
  7172. * // => []
  7173. */
  7174. function takeWhile(array, predicate) {
  7175. return (array && array.length)
  7176. ? baseWhile(array, getIteratee(predicate, 3))
  7177. : [];
  7178. }
  7179. /**
  7180. * Creates an array of unique values, in order, from all given arrays using
  7181. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7182. * for equality comparisons.
  7183. *
  7184. * @static
  7185. * @memberOf _
  7186. * @since 0.1.0
  7187. * @category Array
  7188. * @param {...Array} [arrays] The arrays to inspect.
  7189. * @returns {Array} Returns the new array of combined values.
  7190. * @example
  7191. *
  7192. * _.union([2], [1, 2]);
  7193. * // => [2, 1]
  7194. */
  7195. var union = baseRest(function(arrays) {
  7196. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7197. });
  7198. /**
  7199. * This method is like `_.union` except that it accepts `iteratee` which is
  7200. * invoked for each element of each `arrays` to generate the criterion by
  7201. * which uniqueness is computed. Result values are chosen from the first
  7202. * array in which the value occurs. The iteratee is invoked with one argument:
  7203. * (value).
  7204. *
  7205. * @static
  7206. * @memberOf _
  7207. * @since 4.0.0
  7208. * @category Array
  7209. * @param {...Array} [arrays] The arrays to inspect.
  7210. * @param {Function} [iteratee=_.identity]
  7211. * The iteratee invoked per element.
  7212. * @returns {Array} Returns the new array of combined values.
  7213. * @example
  7214. *
  7215. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7216. * // => [2.1, 1.2]
  7217. *
  7218. * // The `_.property` iteratee shorthand.
  7219. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7220. * // => [{ 'x': 1 }, { 'x': 2 }]
  7221. */
  7222. var unionBy = baseRest(function(arrays) {
  7223. var iteratee = last(arrays);
  7224. if (isArrayLikeObject(iteratee)) {
  7225. iteratee = undefined;
  7226. }
  7227. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7228. });
  7229. /**
  7230. * This method is like `_.union` except that it accepts `comparator` which
  7231. * is invoked to compare elements of `arrays`. Result values are chosen from
  7232. * the first array in which the value occurs. The comparator is invoked
  7233. * with two arguments: (arrVal, othVal).
  7234. *
  7235. * @static
  7236. * @memberOf _
  7237. * @since 4.0.0
  7238. * @category Array
  7239. * @param {...Array} [arrays] The arrays to inspect.
  7240. * @param {Function} [comparator] The comparator invoked per element.
  7241. * @returns {Array} Returns the new array of combined values.
  7242. * @example
  7243. *
  7244. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7245. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7246. *
  7247. * _.unionWith(objects, others, _.isEqual);
  7248. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7249. */
  7250. var unionWith = baseRest(function(arrays) {
  7251. var comparator = last(arrays);
  7252. if (isArrayLikeObject(comparator)) {
  7253. comparator = undefined;
  7254. }
  7255. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7256. });
  7257. /**
  7258. * Creates a duplicate-free version of an array, using
  7259. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7260. * for equality comparisons, in which only the first occurrence of each
  7261. * element is kept.
  7262. *
  7263. * @static
  7264. * @memberOf _
  7265. * @since 0.1.0
  7266. * @category Array
  7267. * @param {Array} array The array to inspect.
  7268. * @returns {Array} Returns the new duplicate free array.
  7269. * @example
  7270. *
  7271. * _.uniq([2, 1, 2]);
  7272. * // => [2, 1]
  7273. */
  7274. function uniq(array) {
  7275. return (array && array.length)
  7276. ? baseUniq(array)
  7277. : [];
  7278. }
  7279. /**
  7280. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7281. * invoked for each element in `array` to generate the criterion by which
  7282. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  7283. *
  7284. * @static
  7285. * @memberOf _
  7286. * @since 4.0.0
  7287. * @category Array
  7288. * @param {Array} array The array to inspect.
  7289. * @param {Function} [iteratee=_.identity]
  7290. * The iteratee invoked per element.
  7291. * @returns {Array} Returns the new duplicate free array.
  7292. * @example
  7293. *
  7294. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7295. * // => [2.1, 1.2]
  7296. *
  7297. * // The `_.property` iteratee shorthand.
  7298. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7299. * // => [{ 'x': 1 }, { 'x': 2 }]
  7300. */
  7301. function uniqBy(array, iteratee) {
  7302. return (array && array.length)
  7303. ? baseUniq(array, getIteratee(iteratee, 2))
  7304. : [];
  7305. }
  7306. /**
  7307. * This method is like `_.uniq` except that it accepts `comparator` which
  7308. * is invoked to compare elements of `array`. The comparator is invoked with
  7309. * two arguments: (arrVal, othVal).
  7310. *
  7311. * @static
  7312. * @memberOf _
  7313. * @since 4.0.0
  7314. * @category Array
  7315. * @param {Array} array The array to inspect.
  7316. * @param {Function} [comparator] The comparator invoked per element.
  7317. * @returns {Array} Returns the new duplicate free array.
  7318. * @example
  7319. *
  7320. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7321. *
  7322. * _.uniqWith(objects, _.isEqual);
  7323. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7324. */
  7325. function uniqWith(array, comparator) {
  7326. return (array && array.length)
  7327. ? baseUniq(array, undefined, comparator)
  7328. : [];
  7329. }
  7330. /**
  7331. * This method is like `_.zip` except that it accepts an array of grouped
  7332. * elements and creates an array regrouping the elements to their pre-zip
  7333. * configuration.
  7334. *
  7335. * @static
  7336. * @memberOf _
  7337. * @since 1.2.0
  7338. * @category Array
  7339. * @param {Array} array The array of grouped elements to process.
  7340. * @returns {Array} Returns the new array of regrouped elements.
  7341. * @example
  7342. *
  7343. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7344. * // => [['a', 1, true], ['b', 2, false]]
  7345. *
  7346. * _.unzip(zipped);
  7347. * // => [['a', 'b'], [1, 2], [true, false]]
  7348. */
  7349. function unzip(array) {
  7350. if (!(array && array.length)) {
  7351. return [];
  7352. }
  7353. var length = 0;
  7354. array = arrayFilter(array, function(group) {
  7355. if (isArrayLikeObject(group)) {
  7356. length = nativeMax(group.length, length);
  7357. return true;
  7358. }
  7359. });
  7360. return baseTimes(length, function(index) {
  7361. return arrayMap(array, baseProperty(index));
  7362. });
  7363. }
  7364. /**
  7365. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7366. * how regrouped values should be combined. The iteratee is invoked with the
  7367. * elements of each group: (...group).
  7368. *
  7369. * @static
  7370. * @memberOf _
  7371. * @since 3.8.0
  7372. * @category Array
  7373. * @param {Array} array The array of grouped elements to process.
  7374. * @param {Function} [iteratee=_.identity] The function to combine
  7375. * regrouped values.
  7376. * @returns {Array} Returns the new array of regrouped elements.
  7377. * @example
  7378. *
  7379. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7380. * // => [[1, 10, 100], [2, 20, 200]]
  7381. *
  7382. * _.unzipWith(zipped, _.add);
  7383. * // => [3, 30, 300]
  7384. */
  7385. function unzipWith(array, iteratee) {
  7386. if (!(array && array.length)) {
  7387. return [];
  7388. }
  7389. var result = unzip(array);
  7390. if (iteratee == null) {
  7391. return result;
  7392. }
  7393. return arrayMap(result, function(group) {
  7394. return apply(iteratee, undefined, group);
  7395. });
  7396. }
  7397. /**
  7398. * Creates an array excluding all given values using
  7399. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7400. * for equality comparisons.
  7401. *
  7402. * **Note:** Unlike `_.pull`, this method returns a new array.
  7403. *
  7404. * @static
  7405. * @memberOf _
  7406. * @since 0.1.0
  7407. * @category Array
  7408. * @param {Array} array The array to inspect.
  7409. * @param {...*} [values] The values to exclude.
  7410. * @returns {Array} Returns the new array of filtered values.
  7411. * @see _.difference, _.xor
  7412. * @example
  7413. *
  7414. * _.without([2, 1, 2, 3], 1, 2);
  7415. * // => [3]
  7416. */
  7417. var without = baseRest(function(array, values) {
  7418. return isArrayLikeObject(array)
  7419. ? baseDifference(array, values)
  7420. : [];
  7421. });
  7422. /**
  7423. * Creates an array of unique values that is the
  7424. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7425. * of the given arrays. The order of result values is determined by the order
  7426. * they occur in the arrays.
  7427. *
  7428. * @static
  7429. * @memberOf _
  7430. * @since 2.4.0
  7431. * @category Array
  7432. * @param {...Array} [arrays] The arrays to inspect.
  7433. * @returns {Array} Returns the new array of filtered values.
  7434. * @see _.difference, _.without
  7435. * @example
  7436. *
  7437. * _.xor([2, 1], [2, 3]);
  7438. * // => [1, 3]
  7439. */
  7440. var xor = baseRest(function(arrays) {
  7441. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7442. });
  7443. /**
  7444. * This method is like `_.xor` except that it accepts `iteratee` which is
  7445. * invoked for each element of each `arrays` to generate the criterion by
  7446. * which by which they're compared. The iteratee is invoked with one argument:
  7447. * (value).
  7448. *
  7449. * @static
  7450. * @memberOf _
  7451. * @since 4.0.0
  7452. * @category Array
  7453. * @param {...Array} [arrays] The arrays to inspect.
  7454. * @param {Function} [iteratee=_.identity]
  7455. * The iteratee invoked per element.
  7456. * @returns {Array} Returns the new array of filtered values.
  7457. * @example
  7458. *
  7459. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7460. * // => [1.2, 3.4]
  7461. *
  7462. * // The `_.property` iteratee shorthand.
  7463. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7464. * // => [{ 'x': 2 }]
  7465. */
  7466. var xorBy = baseRest(function(arrays) {
  7467. var iteratee = last(arrays);
  7468. if (isArrayLikeObject(iteratee)) {
  7469. iteratee = undefined;
  7470. }
  7471. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7472. });
  7473. /**
  7474. * This method is like `_.xor` except that it accepts `comparator` which is
  7475. * invoked to compare elements of `arrays`. The comparator is invoked with
  7476. * two arguments: (arrVal, othVal).
  7477. *
  7478. * @static
  7479. * @memberOf _
  7480. * @since 4.0.0
  7481. * @category Array
  7482. * @param {...Array} [arrays] The arrays to inspect.
  7483. * @param {Function} [comparator] The comparator invoked per element.
  7484. * @returns {Array} Returns the new array of filtered values.
  7485. * @example
  7486. *
  7487. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7488. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7489. *
  7490. * _.xorWith(objects, others, _.isEqual);
  7491. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7492. */
  7493. var xorWith = baseRest(function(arrays) {
  7494. var comparator = last(arrays);
  7495. if (isArrayLikeObject(comparator)) {
  7496. comparator = undefined;
  7497. }
  7498. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7499. });
  7500. /**
  7501. * Creates an array of grouped elements, the first of which contains the
  7502. * first elements of the given arrays, the second of which contains the
  7503. * second elements of the given arrays, and so on.
  7504. *
  7505. * @static
  7506. * @memberOf _
  7507. * @since 0.1.0
  7508. * @category Array
  7509. * @param {...Array} [arrays] The arrays to process.
  7510. * @returns {Array} Returns the new array of grouped elements.
  7511. * @example
  7512. *
  7513. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7514. * // => [['a', 1, true], ['b', 2, false]]
  7515. */
  7516. var zip = baseRest(unzip);
  7517. /**
  7518. * This method is like `_.fromPairs` except that it accepts two arrays,
  7519. * one of property identifiers and one of corresponding values.
  7520. *
  7521. * @static
  7522. * @memberOf _
  7523. * @since 0.4.0
  7524. * @category Array
  7525. * @param {Array} [props=[]] The property identifiers.
  7526. * @param {Array} [values=[]] The property values.
  7527. * @returns {Object} Returns the new object.
  7528. * @example
  7529. *
  7530. * _.zipObject(['a', 'b'], [1, 2]);
  7531. * // => { 'a': 1, 'b': 2 }
  7532. */
  7533. function zipObject(props, values) {
  7534. return baseZipObject(props || [], values || [], assignValue);
  7535. }
  7536. /**
  7537. * This method is like `_.zipObject` except that it supports property paths.
  7538. *
  7539. * @static
  7540. * @memberOf _
  7541. * @since 4.1.0
  7542. * @category Array
  7543. * @param {Array} [props=[]] The property identifiers.
  7544. * @param {Array} [values=[]] The property values.
  7545. * @returns {Object} Returns the new object.
  7546. * @example
  7547. *
  7548. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  7549. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  7550. */
  7551. function zipObjectDeep(props, values) {
  7552. return baseZipObject(props || [], values || [], baseSet);
  7553. }
  7554. /**
  7555. * This method is like `_.zip` except that it accepts `iteratee` to specify
  7556. * how grouped values should be combined. The iteratee is invoked with the
  7557. * elements of each group: (...group).
  7558. *
  7559. * @static
  7560. * @memberOf _
  7561. * @since 3.8.0
  7562. * @category Array
  7563. * @param {...Array} [arrays] The arrays to process.
  7564. * @param {Function} [iteratee=_.identity] The function to combine grouped values.
  7565. * @returns {Array} Returns the new array of grouped elements.
  7566. * @example
  7567. *
  7568. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  7569. * return a + b + c;
  7570. * });
  7571. * // => [111, 222]
  7572. */
  7573. var zipWith = baseRest(function(arrays) {
  7574. var length = arrays.length,
  7575. iteratee = length > 1 ? arrays[length - 1] : undefined;
  7576. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  7577. return unzipWith(arrays, iteratee);
  7578. });
  7579. /*------------------------------------------------------------------------*/
  7580. /**
  7581. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  7582. * chain sequences enabled. The result of such sequences must be unwrapped
  7583. * with `_#value`.
  7584. *
  7585. * @static
  7586. * @memberOf _
  7587. * @since 1.3.0
  7588. * @category Seq
  7589. * @param {*} value The value to wrap.
  7590. * @returns {Object} Returns the new `lodash` wrapper instance.
  7591. * @example
  7592. *
  7593. * var users = [
  7594. * { 'user': 'barney', 'age': 36 },
  7595. * { 'user': 'fred', 'age': 40 },
  7596. * { 'user': 'pebbles', 'age': 1 }
  7597. * ];
  7598. *
  7599. * var youngest = _
  7600. * .chain(users)
  7601. * .sortBy('age')
  7602. * .map(function(o) {
  7603. * return o.user + ' is ' + o.age;
  7604. * })
  7605. * .head()
  7606. * .value();
  7607. * // => 'pebbles is 1'
  7608. */
  7609. function chain(value) {
  7610. var result = lodash(value);
  7611. result.__chain__ = true;
  7612. return result;
  7613. }
  7614. /**
  7615. * This method invokes `interceptor` and returns `value`. The interceptor
  7616. * is invoked with one argument; (value). The purpose of this method is to
  7617. * "tap into" a method chain sequence in order to modify intermediate results.
  7618. *
  7619. * @static
  7620. * @memberOf _
  7621. * @since 0.1.0
  7622. * @category Seq
  7623. * @param {*} value The value to provide to `interceptor`.
  7624. * @param {Function} interceptor The function to invoke.
  7625. * @returns {*} Returns `value`.
  7626. * @example
  7627. *
  7628. * _([1, 2, 3])
  7629. * .tap(function(array) {
  7630. * // Mutate input array.
  7631. * array.pop();
  7632. * })
  7633. * .reverse()
  7634. * .value();
  7635. * // => [2, 1]
  7636. */
  7637. function tap(value, interceptor) {
  7638. interceptor(value);
  7639. return value;
  7640. }
  7641. /**
  7642. * This method is like `_.tap` except that it returns the result of `interceptor`.
  7643. * The purpose of this method is to "pass thru" values replacing intermediate
  7644. * results in a method chain sequence.
  7645. *
  7646. * @static
  7647. * @memberOf _
  7648. * @since 3.0.0
  7649. * @category Seq
  7650. * @param {*} value The value to provide to `interceptor`.
  7651. * @param {Function} interceptor The function to invoke.
  7652. * @returns {*} Returns the result of `interceptor`.
  7653. * @example
  7654. *
  7655. * _(' abc ')
  7656. * .chain()
  7657. * .trim()
  7658. * .thru(function(value) {
  7659. * return [value];
  7660. * })
  7661. * .value();
  7662. * // => ['abc']
  7663. */
  7664. function thru(value, interceptor) {
  7665. return interceptor(value);
  7666. }
  7667. /**
  7668. * This method is the wrapper version of `_.at`.
  7669. *
  7670. * @name at
  7671. * @memberOf _
  7672. * @since 1.0.0
  7673. * @category Seq
  7674. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  7675. * @returns {Object} Returns the new `lodash` wrapper instance.
  7676. * @example
  7677. *
  7678. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  7679. *
  7680. * _(object).at(['a[0].b.c', 'a[1]']).value();
  7681. * // => [3, 4]
  7682. */
  7683. var wrapperAt = baseRest(function(paths) {
  7684. paths = baseFlatten(paths, 1);
  7685. var length = paths.length,
  7686. start = length ? paths[0] : 0,
  7687. value = this.__wrapped__,
  7688. interceptor = function(object) { return baseAt(object, paths); };
  7689. if (length > 1 || this.__actions__.length ||
  7690. !(value instanceof LazyWrapper) || !isIndex(start)) {
  7691. return this.thru(interceptor);
  7692. }
  7693. value = value.slice(start, +start + (length ? 1 : 0));
  7694. value.__actions__.push({
  7695. 'func': thru,
  7696. 'args': [interceptor],
  7697. 'thisArg': undefined
  7698. });
  7699. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  7700. if (length && !array.length) {
  7701. array.push(undefined);
  7702. }
  7703. return array;
  7704. });
  7705. });
  7706. /**
  7707. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  7708. *
  7709. * @name chain
  7710. * @memberOf _
  7711. * @since 0.1.0
  7712. * @category Seq
  7713. * @returns {Object} Returns the new `lodash` wrapper instance.
  7714. * @example
  7715. *
  7716. * var users = [
  7717. * { 'user': 'barney', 'age': 36 },
  7718. * { 'user': 'fred', 'age': 40 }
  7719. * ];
  7720. *
  7721. * // A sequence without explicit chaining.
  7722. * _(users).head();
  7723. * // => { 'user': 'barney', 'age': 36 }
  7724. *
  7725. * // A sequence with explicit chaining.
  7726. * _(users)
  7727. * .chain()
  7728. * .head()
  7729. * .pick('user')
  7730. * .value();
  7731. * // => { 'user': 'barney' }
  7732. */
  7733. function wrapperChain() {
  7734. return chain(this);
  7735. }
  7736. /**
  7737. * Executes the chain sequence and returns the wrapped result.
  7738. *
  7739. * @name commit
  7740. * @memberOf _
  7741. * @since 3.2.0
  7742. * @category Seq
  7743. * @returns {Object} Returns the new `lodash` wrapper instance.
  7744. * @example
  7745. *
  7746. * var array = [1, 2];
  7747. * var wrapped = _(array).push(3);
  7748. *
  7749. * console.log(array);
  7750. * // => [1, 2]
  7751. *
  7752. * wrapped = wrapped.commit();
  7753. * console.log(array);
  7754. * // => [1, 2, 3]
  7755. *
  7756. * wrapped.last();
  7757. * // => 3
  7758. *
  7759. * console.log(array);
  7760. * // => [1, 2, 3]
  7761. */
  7762. function wrapperCommit() {
  7763. return new LodashWrapper(this.value(), this.__chain__);
  7764. }
  7765. /**
  7766. * Gets the next value on a wrapped object following the
  7767. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  7768. *
  7769. * @name next
  7770. * @memberOf _
  7771. * @since 4.0.0
  7772. * @category Seq
  7773. * @returns {Object} Returns the next iterator value.
  7774. * @example
  7775. *
  7776. * var wrapped = _([1, 2]);
  7777. *
  7778. * wrapped.next();
  7779. * // => { 'done': false, 'value': 1 }
  7780. *
  7781. * wrapped.next();
  7782. * // => { 'done': false, 'value': 2 }
  7783. *
  7784. * wrapped.next();
  7785. * // => { 'done': true, 'value': undefined }
  7786. */
  7787. function wrapperNext() {
  7788. if (this.__values__ === undefined) {
  7789. this.__values__ = toArray(this.value());
  7790. }
  7791. var done = this.__index__ >= this.__values__.length,
  7792. value = done ? undefined : this.__values__[this.__index__++];
  7793. return { 'done': done, 'value': value };
  7794. }
  7795. /**
  7796. * Enables the wrapper to be iterable.
  7797. *
  7798. * @name Symbol.iterator
  7799. * @memberOf _
  7800. * @since 4.0.0
  7801. * @category Seq
  7802. * @returns {Object} Returns the wrapper object.
  7803. * @example
  7804. *
  7805. * var wrapped = _([1, 2]);
  7806. *
  7807. * wrapped[Symbol.iterator]() === wrapped;
  7808. * // => true
  7809. *
  7810. * Array.from(wrapped);
  7811. * // => [1, 2]
  7812. */
  7813. function wrapperToIterator() {
  7814. return this;
  7815. }
  7816. /**
  7817. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  7818. *
  7819. * @name plant
  7820. * @memberOf _
  7821. * @since 3.2.0
  7822. * @category Seq
  7823. * @param {*} value The value to plant.
  7824. * @returns {Object} Returns the new `lodash` wrapper instance.
  7825. * @example
  7826. *
  7827. * function square(n) {
  7828. * return n * n;
  7829. * }
  7830. *
  7831. * var wrapped = _([1, 2]).map(square);
  7832. * var other = wrapped.plant([3, 4]);
  7833. *
  7834. * other.value();
  7835. * // => [9, 16]
  7836. *
  7837. * wrapped.value();
  7838. * // => [1, 4]
  7839. */
  7840. function wrapperPlant(value) {
  7841. var result,
  7842. parent = this;
  7843. while (parent instanceof baseLodash) {
  7844. var clone = wrapperClone(parent);
  7845. clone.__index__ = 0;
  7846. clone.__values__ = undefined;
  7847. if (result) {
  7848. previous.__wrapped__ = clone;
  7849. } else {
  7850. result = clone;
  7851. }
  7852. var previous = clone;
  7853. parent = parent.__wrapped__;
  7854. }
  7855. previous.__wrapped__ = value;
  7856. return result;
  7857. }
  7858. /**
  7859. * This method is the wrapper version of `_.reverse`.
  7860. *
  7861. * **Note:** This method mutates the wrapped array.
  7862. *
  7863. * @name reverse
  7864. * @memberOf _
  7865. * @since 0.1.0
  7866. * @category Seq
  7867. * @returns {Object} Returns the new `lodash` wrapper instance.
  7868. * @example
  7869. *
  7870. * var array = [1, 2, 3];
  7871. *
  7872. * _(array).reverse().value()
  7873. * // => [3, 2, 1]
  7874. *
  7875. * console.log(array);
  7876. * // => [3, 2, 1]
  7877. */
  7878. function wrapperReverse() {
  7879. var value = this.__wrapped__;
  7880. if (value instanceof LazyWrapper) {
  7881. var wrapped = value;
  7882. if (this.__actions__.length) {
  7883. wrapped = new LazyWrapper(this);
  7884. }
  7885. wrapped = wrapped.reverse();
  7886. wrapped.__actions__.push({
  7887. 'func': thru,
  7888. 'args': [reverse],
  7889. 'thisArg': undefined
  7890. });
  7891. return new LodashWrapper(wrapped, this.__chain__);
  7892. }
  7893. return this.thru(reverse);
  7894. }
  7895. /**
  7896. * Executes the chain sequence to resolve the unwrapped value.
  7897. *
  7898. * @name value
  7899. * @memberOf _
  7900. * @since 0.1.0
  7901. * @alias toJSON, valueOf
  7902. * @category Seq
  7903. * @returns {*} Returns the resolved unwrapped value.
  7904. * @example
  7905. *
  7906. * _([1, 2, 3]).value();
  7907. * // => [1, 2, 3]
  7908. */
  7909. function wrapperValue() {
  7910. return baseWrapperValue(this.__wrapped__, this.__actions__);
  7911. }
  7912. /*------------------------------------------------------------------------*/
  7913. /**
  7914. * Creates an object composed of keys generated from the results of running
  7915. * each element of `collection` thru `iteratee`. The corresponding value of
  7916. * each key is the number of times the key was returned by `iteratee`. The
  7917. * iteratee is invoked with one argument: (value).
  7918. *
  7919. * @static
  7920. * @memberOf _
  7921. * @since 0.5.0
  7922. * @category Collection
  7923. * @param {Array|Object} collection The collection to iterate over.
  7924. * @param {Function} [iteratee=_.identity]
  7925. * The iteratee to transform keys.
  7926. * @returns {Object} Returns the composed aggregate object.
  7927. * @example
  7928. *
  7929. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  7930. * // => { '4': 1, '6': 2 }
  7931. *
  7932. * // The `_.property` iteratee shorthand.
  7933. * _.countBy(['one', 'two', 'three'], 'length');
  7934. * // => { '3': 2, '5': 1 }
  7935. */
  7936. var countBy = createAggregator(function(result, value, key) {
  7937. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  7938. });
  7939. /**
  7940. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  7941. * Iteration is stopped once `predicate` returns falsey. The predicate is
  7942. * invoked with three arguments: (value, index|key, collection).
  7943. *
  7944. * @static
  7945. * @memberOf _
  7946. * @since 0.1.0
  7947. * @category Collection
  7948. * @param {Array|Object} collection The collection to iterate over.
  7949. * @param {Function} [predicate=_.identity]
  7950. * The function invoked per iteration.
  7951. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7952. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  7953. * else `false`.
  7954. * @example
  7955. *
  7956. * _.every([true, 1, null, 'yes'], Boolean);
  7957. * // => false
  7958. *
  7959. * var users = [
  7960. * { 'user': 'barney', 'age': 36, 'active': false },
  7961. * { 'user': 'fred', 'age': 40, 'active': false }
  7962. * ];
  7963. *
  7964. * // The `_.matches` iteratee shorthand.
  7965. * _.every(users, { 'user': 'barney', 'active': false });
  7966. * // => false
  7967. *
  7968. * // The `_.matchesProperty` iteratee shorthand.
  7969. * _.every(users, ['active', false]);
  7970. * // => true
  7971. *
  7972. * // The `_.property` iteratee shorthand.
  7973. * _.every(users, 'active');
  7974. * // => false
  7975. */
  7976. function every(collection, predicate, guard) {
  7977. var func = isArray(collection) ? arrayEvery : baseEvery;
  7978. if (guard && isIterateeCall(collection, predicate, guard)) {
  7979. predicate = undefined;
  7980. }
  7981. return func(collection, getIteratee(predicate, 3));
  7982. }
  7983. /**
  7984. * Iterates over elements of `collection`, returning an array of all elements
  7985. * `predicate` returns truthy for. The predicate is invoked with three
  7986. * arguments: (value, index|key, collection).
  7987. *
  7988. * **Note:** Unlike `_.remove`, this method returns a new array.
  7989. *
  7990. * @static
  7991. * @memberOf _
  7992. * @since 0.1.0
  7993. * @category Collection
  7994. * @param {Array|Object} collection The collection to iterate over.
  7995. * @param {Function} [predicate=_.identity]
  7996. * The function invoked per iteration.
  7997. * @returns {Array} Returns the new filtered array.
  7998. * @see _.reject
  7999. * @example
  8000. *
  8001. * var users = [
  8002. * { 'user': 'barney', 'age': 36, 'active': true },
  8003. * { 'user': 'fred', 'age': 40, 'active': false }
  8004. * ];
  8005. *
  8006. * _.filter(users, function(o) { return !o.active; });
  8007. * // => objects for ['fred']
  8008. *
  8009. * // The `_.matches` iteratee shorthand.
  8010. * _.filter(users, { 'age': 36, 'active': true });
  8011. * // => objects for ['barney']
  8012. *
  8013. * // The `_.matchesProperty` iteratee shorthand.
  8014. * _.filter(users, ['active', false]);
  8015. * // => objects for ['fred']
  8016. *
  8017. * // The `_.property` iteratee shorthand.
  8018. * _.filter(users, 'active');
  8019. * // => objects for ['barney']
  8020. */
  8021. function filter(collection, predicate) {
  8022. var func = isArray(collection) ? arrayFilter : baseFilter;
  8023. return func(collection, getIteratee(predicate, 3));
  8024. }
  8025. /**
  8026. * Iterates over elements of `collection`, returning the first element
  8027. * `predicate` returns truthy for. The predicate is invoked with three
  8028. * arguments: (value, index|key, collection).
  8029. *
  8030. * @static
  8031. * @memberOf _
  8032. * @since 0.1.0
  8033. * @category Collection
  8034. * @param {Array|Object} collection The collection to search.
  8035. * @param {Function} [predicate=_.identity]
  8036. * The function invoked per iteration.
  8037. * @param {number} [fromIndex=0] The index to search from.
  8038. * @returns {*} Returns the matched element, else `undefined`.
  8039. * @example
  8040. *
  8041. * var users = [
  8042. * { 'user': 'barney', 'age': 36, 'active': true },
  8043. * { 'user': 'fred', 'age': 40, 'active': false },
  8044. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8045. * ];
  8046. *
  8047. * _.find(users, function(o) { return o.age < 40; });
  8048. * // => object for 'barney'
  8049. *
  8050. * // The `_.matches` iteratee shorthand.
  8051. * _.find(users, { 'age': 1, 'active': true });
  8052. * // => object for 'pebbles'
  8053. *
  8054. * // The `_.matchesProperty` iteratee shorthand.
  8055. * _.find(users, ['active', false]);
  8056. * // => object for 'fred'
  8057. *
  8058. * // The `_.property` iteratee shorthand.
  8059. * _.find(users, 'active');
  8060. * // => object for 'barney'
  8061. */
  8062. var find = createFind(findIndex);
  8063. /**
  8064. * This method is like `_.find` except that it iterates over elements of
  8065. * `collection` from right to left.
  8066. *
  8067. * @static
  8068. * @memberOf _
  8069. * @since 2.0.0
  8070. * @category Collection
  8071. * @param {Array|Object} collection The collection to search.
  8072. * @param {Function} [predicate=_.identity]
  8073. * The function invoked per iteration.
  8074. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8075. * @returns {*} Returns the matched element, else `undefined`.
  8076. * @example
  8077. *
  8078. * _.findLast([1, 2, 3, 4], function(n) {
  8079. * return n % 2 == 1;
  8080. * });
  8081. * // => 3
  8082. */
  8083. var findLast = createFind(findLastIndex);
  8084. /**
  8085. * Creates a flattened array of values by running each element in `collection`
  8086. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8087. * with three arguments: (value, index|key, collection).
  8088. *
  8089. * @static
  8090. * @memberOf _
  8091. * @since 4.0.0
  8092. * @category Collection
  8093. * @param {Array|Object} collection The collection to iterate over.
  8094. * @param {Function} [iteratee=_.identity]
  8095. * The function invoked per iteration.
  8096. * @returns {Array} Returns the new flattened array.
  8097. * @example
  8098. *
  8099. * function duplicate(n) {
  8100. * return [n, n];
  8101. * }
  8102. *
  8103. * _.flatMap([1, 2], duplicate);
  8104. * // => [1, 1, 2, 2]
  8105. */
  8106. function flatMap(collection, iteratee) {
  8107. return baseFlatten(map(collection, iteratee), 1);
  8108. }
  8109. /**
  8110. * This method is like `_.flatMap` except that it recursively flattens the
  8111. * mapped results.
  8112. *
  8113. * @static
  8114. * @memberOf _
  8115. * @since 4.7.0
  8116. * @category Collection
  8117. * @param {Array|Object} collection The collection to iterate over.
  8118. * @param {Function} [iteratee=_.identity]
  8119. * The function invoked per iteration.
  8120. * @returns {Array} Returns the new flattened array.
  8121. * @example
  8122. *
  8123. * function duplicate(n) {
  8124. * return [[[n, n]]];
  8125. * }
  8126. *
  8127. * _.flatMapDeep([1, 2], duplicate);
  8128. * // => [1, 1, 2, 2]
  8129. */
  8130. function flatMapDeep(collection, iteratee) {
  8131. return baseFlatten(map(collection, iteratee), INFINITY);
  8132. }
  8133. /**
  8134. * This method is like `_.flatMap` except that it recursively flattens the
  8135. * mapped results up to `depth` times.
  8136. *
  8137. * @static
  8138. * @memberOf _
  8139. * @since 4.7.0
  8140. * @category Collection
  8141. * @param {Array|Object} collection The collection to iterate over.
  8142. * @param {Function} [iteratee=_.identity]
  8143. * The function invoked per iteration.
  8144. * @param {number} [depth=1] The maximum recursion depth.
  8145. * @returns {Array} Returns the new flattened array.
  8146. * @example
  8147. *
  8148. * function duplicate(n) {
  8149. * return [[[n, n]]];
  8150. * }
  8151. *
  8152. * _.flatMapDepth([1, 2], duplicate, 2);
  8153. * // => [[1, 1], [2, 2]]
  8154. */
  8155. function flatMapDepth(collection, iteratee, depth) {
  8156. depth = depth === undefined ? 1 : toInteger(depth);
  8157. return baseFlatten(map(collection, iteratee), depth);
  8158. }
  8159. /**
  8160. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8161. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8162. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8163. *
  8164. * **Note:** As with other "Collections" methods, objects with a "length"
  8165. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8166. * or `_.forOwn` for object iteration.
  8167. *
  8168. * @static
  8169. * @memberOf _
  8170. * @since 0.1.0
  8171. * @alias each
  8172. * @category Collection
  8173. * @param {Array|Object} collection The collection to iterate over.
  8174. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8175. * @returns {Array|Object} Returns `collection`.
  8176. * @see _.forEachRight
  8177. * @example
  8178. *
  8179. * _([1, 2]).forEach(function(value) {
  8180. * console.log(value);
  8181. * });
  8182. * // => Logs `1` then `2`.
  8183. *
  8184. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8185. * console.log(key);
  8186. * });
  8187. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8188. */
  8189. function forEach(collection, iteratee) {
  8190. var func = isArray(collection) ? arrayEach : baseEach;
  8191. return func(collection, getIteratee(iteratee, 3));
  8192. }
  8193. /**
  8194. * This method is like `_.forEach` except that it iterates over elements of
  8195. * `collection` from right to left.
  8196. *
  8197. * @static
  8198. * @memberOf _
  8199. * @since 2.0.0
  8200. * @alias eachRight
  8201. * @category Collection
  8202. * @param {Array|Object} collection The collection to iterate over.
  8203. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8204. * @returns {Array|Object} Returns `collection`.
  8205. * @see _.forEach
  8206. * @example
  8207. *
  8208. * _.forEachRight([1, 2], function(value) {
  8209. * console.log(value);
  8210. * });
  8211. * // => Logs `2` then `1`.
  8212. */
  8213. function forEachRight(collection, iteratee) {
  8214. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8215. return func(collection, getIteratee(iteratee, 3));
  8216. }
  8217. /**
  8218. * Creates an object composed of keys generated from the results of running
  8219. * each element of `collection` thru `iteratee`. The order of grouped values
  8220. * is determined by the order they occur in `collection`. The corresponding
  8221. * value of each key is an array of elements responsible for generating the
  8222. * key. The iteratee is invoked with one argument: (value).
  8223. *
  8224. * @static
  8225. * @memberOf _
  8226. * @since 0.1.0
  8227. * @category Collection
  8228. * @param {Array|Object} collection The collection to iterate over.
  8229. * @param {Function} [iteratee=_.identity]
  8230. * The iteratee to transform keys.
  8231. * @returns {Object} Returns the composed aggregate object.
  8232. * @example
  8233. *
  8234. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8235. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8236. *
  8237. * // The `_.property` iteratee shorthand.
  8238. * _.groupBy(['one', 'two', 'three'], 'length');
  8239. * // => { '3': ['one', 'two'], '5': ['three'] }
  8240. */
  8241. var groupBy = createAggregator(function(result, value, key) {
  8242. if (hasOwnProperty.call(result, key)) {
  8243. result[key].push(value);
  8244. } else {
  8245. result[key] = [value];
  8246. }
  8247. });
  8248. /**
  8249. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8250. * checked for a substring of `value`, otherwise
  8251. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  8252. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8253. * the offset from the end of `collection`.
  8254. *
  8255. * @static
  8256. * @memberOf _
  8257. * @since 0.1.0
  8258. * @category Collection
  8259. * @param {Array|Object|string} collection The collection to search.
  8260. * @param {*} value The value to search for.
  8261. * @param {number} [fromIndex=0] The index to search from.
  8262. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8263. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8264. * @example
  8265. *
  8266. * _.includes([1, 2, 3], 1);
  8267. * // => true
  8268. *
  8269. * _.includes([1, 2, 3], 1, 2);
  8270. * // => false
  8271. *
  8272. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8273. * // => true
  8274. *
  8275. * _.includes('abcd', 'bc');
  8276. * // => true
  8277. */
  8278. function includes(collection, value, fromIndex, guard) {
  8279. collection = isArrayLike(collection) ? collection : values(collection);
  8280. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8281. var length = collection.length;
  8282. if (fromIndex < 0) {
  8283. fromIndex = nativeMax(length + fromIndex, 0);
  8284. }
  8285. return isString(collection)
  8286. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8287. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8288. }
  8289. /**
  8290. * Invokes the method at `path` of each element in `collection`, returning
  8291. * an array of the results of each invoked method. Any additional arguments
  8292. * are provided to each invoked method. If `path` is a function, it's invoked
  8293. * for, and `this` bound to, each element in `collection`.
  8294. *
  8295. * @static
  8296. * @memberOf _
  8297. * @since 4.0.0
  8298. * @category Collection
  8299. * @param {Array|Object} collection The collection to iterate over.
  8300. * @param {Array|Function|string} path The path of the method to invoke or
  8301. * the function invoked per iteration.
  8302. * @param {...*} [args] The arguments to invoke each method with.
  8303. * @returns {Array} Returns the array of results.
  8304. * @example
  8305. *
  8306. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8307. * // => [[1, 5, 7], [1, 2, 3]]
  8308. *
  8309. * _.invokeMap([123, 456], String.prototype.split, '');
  8310. * // => [['1', '2', '3'], ['4', '5', '6']]
  8311. */
  8312. var invokeMap = baseRest(function(collection, path, args) {
  8313. var index = -1,
  8314. isFunc = typeof path == 'function',
  8315. isProp = isKey(path),
  8316. result = isArrayLike(collection) ? Array(collection.length) : [];
  8317. baseEach(collection, function(value) {
  8318. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  8319. result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
  8320. });
  8321. return result;
  8322. });
  8323. /**
  8324. * Creates an object composed of keys generated from the results of running
  8325. * each element of `collection` thru `iteratee`. The corresponding value of
  8326. * each key is the last element responsible for generating the key. The
  8327. * iteratee is invoked with one argument: (value).
  8328. *
  8329. * @static
  8330. * @memberOf _
  8331. * @since 4.0.0
  8332. * @category Collection
  8333. * @param {Array|Object} collection The collection to iterate over.
  8334. * @param {Function} [iteratee=_.identity]
  8335. * The iteratee to transform keys.
  8336. * @returns {Object} Returns the composed aggregate object.
  8337. * @example
  8338. *
  8339. * var array = [
  8340. * { 'dir': 'left', 'code': 97 },
  8341. * { 'dir': 'right', 'code': 100 }
  8342. * ];
  8343. *
  8344. * _.keyBy(array, function(o) {
  8345. * return String.fromCharCode(o.code);
  8346. * });
  8347. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8348. *
  8349. * _.keyBy(array, 'dir');
  8350. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8351. */
  8352. var keyBy = createAggregator(function(result, value, key) {
  8353. result[key] = value;
  8354. });
  8355. /**
  8356. * Creates an array of values by running each element in `collection` thru
  8357. * `iteratee`. The iteratee is invoked with three arguments:
  8358. * (value, index|key, collection).
  8359. *
  8360. * Many lodash methods are guarded to work as iteratees for methods like
  8361. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8362. *
  8363. * The guarded methods are:
  8364. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8365. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8366. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8367. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8368. *
  8369. * @static
  8370. * @memberOf _
  8371. * @since 0.1.0
  8372. * @category Collection
  8373. * @param {Array|Object} collection The collection to iterate over.
  8374. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8375. * @returns {Array} Returns the new mapped array.
  8376. * @example
  8377. *
  8378. * function square(n) {
  8379. * return n * n;
  8380. * }
  8381. *
  8382. * _.map([4, 8], square);
  8383. * // => [16, 64]
  8384. *
  8385. * _.map({ 'a': 4, 'b': 8 }, square);
  8386. * // => [16, 64] (iteration order is not guaranteed)
  8387. *
  8388. * var users = [
  8389. * { 'user': 'barney' },
  8390. * { 'user': 'fred' }
  8391. * ];
  8392. *
  8393. * // The `_.property` iteratee shorthand.
  8394. * _.map(users, 'user');
  8395. * // => ['barney', 'fred']
  8396. */
  8397. function map(collection, iteratee) {
  8398. var func = isArray(collection) ? arrayMap : baseMap;
  8399. return func(collection, getIteratee(iteratee, 3));
  8400. }
  8401. /**
  8402. * This method is like `_.sortBy` except that it allows specifying the sort
  8403. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8404. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8405. * descending or "asc" for ascending sort order of corresponding values.
  8406. *
  8407. * @static
  8408. * @memberOf _
  8409. * @since 4.0.0
  8410. * @category Collection
  8411. * @param {Array|Object} collection The collection to iterate over.
  8412. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8413. * The iteratees to sort by.
  8414. * @param {string[]} [orders] The sort orders of `iteratees`.
  8415. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8416. * @returns {Array} Returns the new sorted array.
  8417. * @example
  8418. *
  8419. * var users = [
  8420. * { 'user': 'fred', 'age': 48 },
  8421. * { 'user': 'barney', 'age': 34 },
  8422. * { 'user': 'fred', 'age': 40 },
  8423. * { 'user': 'barney', 'age': 36 }
  8424. * ];
  8425. *
  8426. * // Sort by `user` in ascending order and by `age` in descending order.
  8427. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8428. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8429. */
  8430. function orderBy(collection, iteratees, orders, guard) {
  8431. if (collection == null) {
  8432. return [];
  8433. }
  8434. if (!isArray(iteratees)) {
  8435. iteratees = iteratees == null ? [] : [iteratees];
  8436. }
  8437. orders = guard ? undefined : orders;
  8438. if (!isArray(orders)) {
  8439. orders = orders == null ? [] : [orders];
  8440. }
  8441. return baseOrderBy(collection, iteratees, orders);
  8442. }
  8443. /**
  8444. * Creates an array of elements split into two groups, the first of which
  8445. * contains elements `predicate` returns truthy for, the second of which
  8446. * contains elements `predicate` returns falsey for. The predicate is
  8447. * invoked with one argument: (value).
  8448. *
  8449. * @static
  8450. * @memberOf _
  8451. * @since 3.0.0
  8452. * @category Collection
  8453. * @param {Array|Object} collection The collection to iterate over.
  8454. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8455. * @returns {Array} Returns the array of grouped elements.
  8456. * @example
  8457. *
  8458. * var users = [
  8459. * { 'user': 'barney', 'age': 36, 'active': false },
  8460. * { 'user': 'fred', 'age': 40, 'active': true },
  8461. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8462. * ];
  8463. *
  8464. * _.partition(users, function(o) { return o.active; });
  8465. * // => objects for [['fred'], ['barney', 'pebbles']]
  8466. *
  8467. * // The `_.matches` iteratee shorthand.
  8468. * _.partition(users, { 'age': 1, 'active': false });
  8469. * // => objects for [['pebbles'], ['barney', 'fred']]
  8470. *
  8471. * // The `_.matchesProperty` iteratee shorthand.
  8472. * _.partition(users, ['active', false]);
  8473. * // => objects for [['barney', 'pebbles'], ['fred']]
  8474. *
  8475. * // The `_.property` iteratee shorthand.
  8476. * _.partition(users, 'active');
  8477. * // => objects for [['fred'], ['barney', 'pebbles']]
  8478. */
  8479. var partition = createAggregator(function(result, value, key) {
  8480. result[key ? 0 : 1].push(value);
  8481. }, function() { return [[], []]; });
  8482. /**
  8483. * Reduces `collection` to a value which is the accumulated result of running
  8484. * each element in `collection` thru `iteratee`, where each successive
  8485. * invocation is supplied the return value of the previous. If `accumulator`
  8486. * is not given, the first element of `collection` is used as the initial
  8487. * value. The iteratee is invoked with four arguments:
  8488. * (accumulator, value, index|key, collection).
  8489. *
  8490. * Many lodash methods are guarded to work as iteratees for methods like
  8491. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8492. *
  8493. * The guarded methods are:
  8494. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8495. * and `sortBy`
  8496. *
  8497. * @static
  8498. * @memberOf _
  8499. * @since 0.1.0
  8500. * @category Collection
  8501. * @param {Array|Object} collection The collection to iterate over.
  8502. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8503. * @param {*} [accumulator] The initial value.
  8504. * @returns {*} Returns the accumulated value.
  8505. * @see _.reduceRight
  8506. * @example
  8507. *
  8508. * _.reduce([1, 2], function(sum, n) {
  8509. * return sum + n;
  8510. * }, 0);
  8511. * // => 3
  8512. *
  8513. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8514. * (result[value] || (result[value] = [])).push(key);
  8515. * return result;
  8516. * }, {});
  8517. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8518. */
  8519. function reduce(collection, iteratee, accumulator) {
  8520. var func = isArray(collection) ? arrayReduce : baseReduce,
  8521. initAccum = arguments.length < 3;
  8522. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8523. }
  8524. /**
  8525. * This method is like `_.reduce` except that it iterates over elements of
  8526. * `collection` from right to left.
  8527. *
  8528. * @static
  8529. * @memberOf _
  8530. * @since 0.1.0
  8531. * @category Collection
  8532. * @param {Array|Object} collection The collection to iterate over.
  8533. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8534. * @param {*} [accumulator] The initial value.
  8535. * @returns {*} Returns the accumulated value.
  8536. * @see _.reduce
  8537. * @example
  8538. *
  8539. * var array = [[0, 1], [2, 3], [4, 5]];
  8540. *
  8541. * _.reduceRight(array, function(flattened, other) {
  8542. * return flattened.concat(other);
  8543. * }, []);
  8544. * // => [4, 5, 2, 3, 0, 1]
  8545. */
  8546. function reduceRight(collection, iteratee, accumulator) {
  8547. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  8548. initAccum = arguments.length < 3;
  8549. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  8550. }
  8551. /**
  8552. * The opposite of `_.filter`; this method returns the elements of `collection`
  8553. * that `predicate` does **not** return truthy for.
  8554. *
  8555. * @static
  8556. * @memberOf _
  8557. * @since 0.1.0
  8558. * @category Collection
  8559. * @param {Array|Object} collection The collection to iterate over.
  8560. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8561. * @returns {Array} Returns the new filtered array.
  8562. * @see _.filter
  8563. * @example
  8564. *
  8565. * var users = [
  8566. * { 'user': 'barney', 'age': 36, 'active': false },
  8567. * { 'user': 'fred', 'age': 40, 'active': true }
  8568. * ];
  8569. *
  8570. * _.reject(users, function(o) { return !o.active; });
  8571. * // => objects for ['fred']
  8572. *
  8573. * // The `_.matches` iteratee shorthand.
  8574. * _.reject(users, { 'age': 40, 'active': true });
  8575. * // => objects for ['barney']
  8576. *
  8577. * // The `_.matchesProperty` iteratee shorthand.
  8578. * _.reject(users, ['active', false]);
  8579. * // => objects for ['fred']
  8580. *
  8581. * // The `_.property` iteratee shorthand.
  8582. * _.reject(users, 'active');
  8583. * // => objects for ['barney']
  8584. */
  8585. function reject(collection, predicate) {
  8586. var func = isArray(collection) ? arrayFilter : baseFilter;
  8587. return func(collection, negate(getIteratee(predicate, 3)));
  8588. }
  8589. /**
  8590. * Gets a random element from `collection`.
  8591. *
  8592. * @static
  8593. * @memberOf _
  8594. * @since 2.0.0
  8595. * @category Collection
  8596. * @param {Array|Object} collection The collection to sample.
  8597. * @returns {*} Returns the random element.
  8598. * @example
  8599. *
  8600. * _.sample([1, 2, 3, 4]);
  8601. * // => 2
  8602. */
  8603. function sample(collection) {
  8604. var array = isArrayLike(collection) ? collection : values(collection),
  8605. length = array.length;
  8606. return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
  8607. }
  8608. /**
  8609. * Gets `n` random elements at unique keys from `collection` up to the
  8610. * size of `collection`.
  8611. *
  8612. * @static
  8613. * @memberOf _
  8614. * @since 4.0.0
  8615. * @category Collection
  8616. * @param {Array|Object} collection The collection to sample.
  8617. * @param {number} [n=1] The number of elements to sample.
  8618. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8619. * @returns {Array} Returns the random elements.
  8620. * @example
  8621. *
  8622. * _.sampleSize([1, 2, 3], 2);
  8623. * // => [3, 1]
  8624. *
  8625. * _.sampleSize([1, 2, 3], 4);
  8626. * // => [2, 3, 1]
  8627. */
  8628. function sampleSize(collection, n, guard) {
  8629. var index = -1,
  8630. result = toArray(collection),
  8631. length = result.length,
  8632. lastIndex = length - 1;
  8633. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  8634. n = 1;
  8635. } else {
  8636. n = baseClamp(toInteger(n), 0, length);
  8637. }
  8638. while (++index < n) {
  8639. var rand = baseRandom(index, lastIndex),
  8640. value = result[rand];
  8641. result[rand] = result[index];
  8642. result[index] = value;
  8643. }
  8644. result.length = n;
  8645. return result;
  8646. }
  8647. /**
  8648. * Creates an array of shuffled values, using a version of the
  8649. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  8650. *
  8651. * @static
  8652. * @memberOf _
  8653. * @since 0.1.0
  8654. * @category Collection
  8655. * @param {Array|Object} collection The collection to shuffle.
  8656. * @returns {Array} Returns the new shuffled array.
  8657. * @example
  8658. *
  8659. * _.shuffle([1, 2, 3, 4]);
  8660. * // => [4, 1, 3, 2]
  8661. */
  8662. function shuffle(collection) {
  8663. return sampleSize(collection, MAX_ARRAY_LENGTH);
  8664. }
  8665. /**
  8666. * Gets the size of `collection` by returning its length for array-like
  8667. * values or the number of own enumerable string keyed properties for objects.
  8668. *
  8669. * @static
  8670. * @memberOf _
  8671. * @since 0.1.0
  8672. * @category Collection
  8673. * @param {Array|Object} collection The collection to inspect.
  8674. * @returns {number} Returns the collection size.
  8675. * @example
  8676. *
  8677. * _.size([1, 2, 3]);
  8678. * // => 3
  8679. *
  8680. * _.size({ 'a': 1, 'b': 2 });
  8681. * // => 2
  8682. *
  8683. * _.size('pebbles');
  8684. * // => 7
  8685. */
  8686. function size(collection) {
  8687. if (collection == null) {
  8688. return 0;
  8689. }
  8690. if (isArrayLike(collection)) {
  8691. var result = collection.length;
  8692. return (result && isString(collection)) ? stringSize(collection) : result;
  8693. }
  8694. if (isObjectLike(collection)) {
  8695. var tag = getTag(collection);
  8696. if (tag == mapTag || tag == setTag) {
  8697. return collection.size;
  8698. }
  8699. }
  8700. return keys(collection).length;
  8701. }
  8702. /**
  8703. * Checks if `predicate` returns truthy for **any** element of `collection`.
  8704. * Iteration is stopped once `predicate` returns truthy. The predicate is
  8705. * invoked with three arguments: (value, index|key, collection).
  8706. *
  8707. * @static
  8708. * @memberOf _
  8709. * @since 0.1.0
  8710. * @category Collection
  8711. * @param {Array|Object} collection The collection to iterate over.
  8712. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8713. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8714. * @returns {boolean} Returns `true` if any element passes the predicate check,
  8715. * else `false`.
  8716. * @example
  8717. *
  8718. * _.some([null, 0, 'yes', false], Boolean);
  8719. * // => true
  8720. *
  8721. * var users = [
  8722. * { 'user': 'barney', 'active': true },
  8723. * { 'user': 'fred', 'active': false }
  8724. * ];
  8725. *
  8726. * // The `_.matches` iteratee shorthand.
  8727. * _.some(users, { 'user': 'barney', 'active': false });
  8728. * // => false
  8729. *
  8730. * // The `_.matchesProperty` iteratee shorthand.
  8731. * _.some(users, ['active', false]);
  8732. * // => true
  8733. *
  8734. * // The `_.property` iteratee shorthand.
  8735. * _.some(users, 'active');
  8736. * // => true
  8737. */
  8738. function some(collection, predicate, guard) {
  8739. var func = isArray(collection) ? arraySome : baseSome;
  8740. if (guard && isIterateeCall(collection, predicate, guard)) {
  8741. predicate = undefined;
  8742. }
  8743. return func(collection, getIteratee(predicate, 3));
  8744. }
  8745. /**
  8746. * Creates an array of elements, sorted in ascending order by the results of
  8747. * running each element in a collection thru each iteratee. This method
  8748. * performs a stable sort, that is, it preserves the original sort order of
  8749. * equal elements. The iteratees are invoked with one argument: (value).
  8750. *
  8751. * @static
  8752. * @memberOf _
  8753. * @since 0.1.0
  8754. * @category Collection
  8755. * @param {Array|Object} collection The collection to iterate over.
  8756. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  8757. * The iteratees to sort by.
  8758. * @returns {Array} Returns the new sorted array.
  8759. * @example
  8760. *
  8761. * var users = [
  8762. * { 'user': 'fred', 'age': 48 },
  8763. * { 'user': 'barney', 'age': 36 },
  8764. * { 'user': 'fred', 'age': 40 },
  8765. * { 'user': 'barney', 'age': 34 }
  8766. * ];
  8767. *
  8768. * _.sortBy(users, function(o) { return o.user; });
  8769. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8770. *
  8771. * _.sortBy(users, ['user', 'age']);
  8772. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  8773. *
  8774. * _.sortBy(users, 'user', function(o) {
  8775. * return Math.floor(o.age / 10);
  8776. * });
  8777. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8778. */
  8779. var sortBy = baseRest(function(collection, iteratees) {
  8780. if (collection == null) {
  8781. return [];
  8782. }
  8783. var length = iteratees.length;
  8784. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  8785. iteratees = [];
  8786. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  8787. iteratees = [iteratees[0]];
  8788. }
  8789. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  8790. });
  8791. /*------------------------------------------------------------------------*/
  8792. /**
  8793. * Gets the timestamp of the number of milliseconds that have elapsed since
  8794. * the Unix epoch (1 January 1970 00:00:00 UTC).
  8795. *
  8796. * @static
  8797. * @memberOf _
  8798. * @since 2.4.0
  8799. * @category Date
  8800. * @returns {number} Returns the timestamp.
  8801. * @example
  8802. *
  8803. * _.defer(function(stamp) {
  8804. * console.log(_.now() - stamp);
  8805. * }, _.now());
  8806. * // => Logs the number of milliseconds it took for the deferred invocation.
  8807. */
  8808. function now() {
  8809. return Date.now();
  8810. }
  8811. /*------------------------------------------------------------------------*/
  8812. /**
  8813. * The opposite of `_.before`; this method creates a function that invokes
  8814. * `func` once it's called `n` or more times.
  8815. *
  8816. * @static
  8817. * @memberOf _
  8818. * @since 0.1.0
  8819. * @category Function
  8820. * @param {number} n The number of calls before `func` is invoked.
  8821. * @param {Function} func The function to restrict.
  8822. * @returns {Function} Returns the new restricted function.
  8823. * @example
  8824. *
  8825. * var saves = ['profile', 'settings'];
  8826. *
  8827. * var done = _.after(saves.length, function() {
  8828. * console.log('done saving!');
  8829. * });
  8830. *
  8831. * _.forEach(saves, function(type) {
  8832. * asyncSave({ 'type': type, 'complete': done });
  8833. * });
  8834. * // => Logs 'done saving!' after the two async saves have completed.
  8835. */
  8836. function after(n, func) {
  8837. if (typeof func != 'function') {
  8838. throw new TypeError(FUNC_ERROR_TEXT);
  8839. }
  8840. n = toInteger(n);
  8841. return function() {
  8842. if (--n < 1) {
  8843. return func.apply(this, arguments);
  8844. }
  8845. };
  8846. }
  8847. /**
  8848. * Creates a function that invokes `func`, with up to `n` arguments,
  8849. * ignoring any additional arguments.
  8850. *
  8851. * @static
  8852. * @memberOf _
  8853. * @since 3.0.0
  8854. * @category Function
  8855. * @param {Function} func The function to cap arguments for.
  8856. * @param {number} [n=func.length] The arity cap.
  8857. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8858. * @returns {Function} Returns the new capped function.
  8859. * @example
  8860. *
  8861. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  8862. * // => [6, 8, 10]
  8863. */
  8864. function ary(func, n, guard) {
  8865. n = guard ? undefined : n;
  8866. n = (func && n == null) ? func.length : n;
  8867. return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  8868. }
  8869. /**
  8870. * Creates a function that invokes `func`, with the `this` binding and arguments
  8871. * of the created function, while it's called less than `n` times. Subsequent
  8872. * calls to the created function return the result of the last `func` invocation.
  8873. *
  8874. * @static
  8875. * @memberOf _
  8876. * @since 3.0.0
  8877. * @category Function
  8878. * @param {number} n The number of calls at which `func` is no longer invoked.
  8879. * @param {Function} func The function to restrict.
  8880. * @returns {Function} Returns the new restricted function.
  8881. * @example
  8882. *
  8883. * jQuery(element).on('click', _.before(5, addContactToList));
  8884. * // => Allows adding up to 4 contacts to the list.
  8885. */
  8886. function before(n, func) {
  8887. var result;
  8888. if (typeof func != 'function') {
  8889. throw new TypeError(FUNC_ERROR_TEXT);
  8890. }
  8891. n = toInteger(n);
  8892. return function() {
  8893. if (--n > 0) {
  8894. result = func.apply(this, arguments);
  8895. }
  8896. if (n <= 1) {
  8897. func = undefined;
  8898. }
  8899. return result;
  8900. };
  8901. }
  8902. /**
  8903. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  8904. * and `partials` prepended to the arguments it receives.
  8905. *
  8906. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  8907. * may be used as a placeholder for partially applied arguments.
  8908. *
  8909. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  8910. * property of bound functions.
  8911. *
  8912. * @static
  8913. * @memberOf _
  8914. * @since 0.1.0
  8915. * @category Function
  8916. * @param {Function} func The function to bind.
  8917. * @param {*} thisArg The `this` binding of `func`.
  8918. * @param {...*} [partials] The arguments to be partially applied.
  8919. * @returns {Function} Returns the new bound function.
  8920. * @example
  8921. *
  8922. * function greet(greeting, punctuation) {
  8923. * return greeting + ' ' + this.user + punctuation;
  8924. * }
  8925. *
  8926. * var object = { 'user': 'fred' };
  8927. *
  8928. * var bound = _.bind(greet, object, 'hi');
  8929. * bound('!');
  8930. * // => 'hi fred!'
  8931. *
  8932. * // Bound with placeholders.
  8933. * var bound = _.bind(greet, object, _, '!');
  8934. * bound('hi');
  8935. * // => 'hi fred!'
  8936. */
  8937. var bind = baseRest(function(func, thisArg, partials) {
  8938. var bitmask = BIND_FLAG;
  8939. if (partials.length) {
  8940. var holders = replaceHolders(partials, getHolder(bind));
  8941. bitmask |= PARTIAL_FLAG;
  8942. }
  8943. return createWrap(func, bitmask, thisArg, partials, holders);
  8944. });
  8945. /**
  8946. * Creates a function that invokes the method at `object[key]` with `partials`
  8947. * prepended to the arguments it receives.
  8948. *
  8949. * This method differs from `_.bind` by allowing bound functions to reference
  8950. * methods that may be redefined or don't yet exist. See
  8951. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  8952. * for more details.
  8953. *
  8954. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  8955. * builds, may be used as a placeholder for partially applied arguments.
  8956. *
  8957. * @static
  8958. * @memberOf _
  8959. * @since 0.10.0
  8960. * @category Function
  8961. * @param {Object} object The object to invoke the method on.
  8962. * @param {string} key The key of the method.
  8963. * @param {...*} [partials] The arguments to be partially applied.
  8964. * @returns {Function} Returns the new bound function.
  8965. * @example
  8966. *
  8967. * var object = {
  8968. * 'user': 'fred',
  8969. * 'greet': function(greeting, punctuation) {
  8970. * return greeting + ' ' + this.user + punctuation;
  8971. * }
  8972. * };
  8973. *
  8974. * var bound = _.bindKey(object, 'greet', 'hi');
  8975. * bound('!');
  8976. * // => 'hi fred!'
  8977. *
  8978. * object.greet = function(greeting, punctuation) {
  8979. * return greeting + 'ya ' + this.user + punctuation;
  8980. * };
  8981. *
  8982. * bound('!');
  8983. * // => 'hiya fred!'
  8984. *
  8985. * // Bound with placeholders.
  8986. * var bound = _.bindKey(object, 'greet', _, '!');
  8987. * bound('hi');
  8988. * // => 'hiya fred!'
  8989. */
  8990. var bindKey = baseRest(function(object, key, partials) {
  8991. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  8992. if (partials.length) {
  8993. var holders = replaceHolders(partials, getHolder(bindKey));
  8994. bitmask |= PARTIAL_FLAG;
  8995. }
  8996. return createWrap(key, bitmask, object, partials, holders);
  8997. });
  8998. /**
  8999. * Creates a function that accepts arguments of `func` and either invokes
  9000. * `func` returning its result, if at least `arity` number of arguments have
  9001. * been provided, or returns a function that accepts the remaining `func`
  9002. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9003. * is not sufficient.
  9004. *
  9005. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9006. * may be used as a placeholder for provided arguments.
  9007. *
  9008. * **Note:** This method doesn't set the "length" property of curried functions.
  9009. *
  9010. * @static
  9011. * @memberOf _
  9012. * @since 2.0.0
  9013. * @category Function
  9014. * @param {Function} func The function to curry.
  9015. * @param {number} [arity=func.length] The arity of `func`.
  9016. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9017. * @returns {Function} Returns the new curried function.
  9018. * @example
  9019. *
  9020. * var abc = function(a, b, c) {
  9021. * return [a, b, c];
  9022. * };
  9023. *
  9024. * var curried = _.curry(abc);
  9025. *
  9026. * curried(1)(2)(3);
  9027. * // => [1, 2, 3]
  9028. *
  9029. * curried(1, 2)(3);
  9030. * // => [1, 2, 3]
  9031. *
  9032. * curried(1, 2, 3);
  9033. * // => [1, 2, 3]
  9034. *
  9035. * // Curried with placeholders.
  9036. * curried(1)(_, 3)(2);
  9037. * // => [1, 2, 3]
  9038. */
  9039. function curry(func, arity, guard) {
  9040. arity = guard ? undefined : arity;
  9041. var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9042. result.placeholder = curry.placeholder;
  9043. return result;
  9044. }
  9045. /**
  9046. * This method is like `_.curry` except that arguments are applied to `func`
  9047. * in the manner of `_.partialRight` instead of `_.partial`.
  9048. *
  9049. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9050. * builds, may be used as a placeholder for provided arguments.
  9051. *
  9052. * **Note:** This method doesn't set the "length" property of curried functions.
  9053. *
  9054. * @static
  9055. * @memberOf _
  9056. * @since 3.0.0
  9057. * @category Function
  9058. * @param {Function} func The function to curry.
  9059. * @param {number} [arity=func.length] The arity of `func`.
  9060. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9061. * @returns {Function} Returns the new curried function.
  9062. * @example
  9063. *
  9064. * var abc = function(a, b, c) {
  9065. * return [a, b, c];
  9066. * };
  9067. *
  9068. * var curried = _.curryRight(abc);
  9069. *
  9070. * curried(3)(2)(1);
  9071. * // => [1, 2, 3]
  9072. *
  9073. * curried(2, 3)(1);
  9074. * // => [1, 2, 3]
  9075. *
  9076. * curried(1, 2, 3);
  9077. * // => [1, 2, 3]
  9078. *
  9079. * // Curried with placeholders.
  9080. * curried(3)(1, _)(2);
  9081. * // => [1, 2, 3]
  9082. */
  9083. function curryRight(func, arity, guard) {
  9084. arity = guard ? undefined : arity;
  9085. var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9086. result.placeholder = curryRight.placeholder;
  9087. return result;
  9088. }
  9089. /**
  9090. * Creates a debounced function that delays invoking `func` until after `wait`
  9091. * milliseconds have elapsed since the last time the debounced function was
  9092. * invoked. The debounced function comes with a `cancel` method to cancel
  9093. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9094. * Provide an options object to indicate whether `func` should be invoked on
  9095. * the leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9096. * with the last arguments provided to the debounced function. Subsequent calls
  9097. * to the debounced function return the result of the last `func` invocation.
  9098. *
  9099. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  9100. * on the trailing edge of the timeout only if the debounced function is
  9101. * invoked more than once during the `wait` timeout.
  9102. *
  9103. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9104. * for details over the differences between `_.debounce` and `_.throttle`.
  9105. *
  9106. * @static
  9107. * @memberOf _
  9108. * @since 0.1.0
  9109. * @category Function
  9110. * @param {Function} func The function to debounce.
  9111. * @param {number} [wait=0] The number of milliseconds to delay.
  9112. * @param {Object} [options={}] The options object.
  9113. * @param {boolean} [options.leading=false]
  9114. * Specify invoking on the leading edge of the timeout.
  9115. * @param {number} [options.maxWait]
  9116. * The maximum time `func` is allowed to be delayed before it's invoked.
  9117. * @param {boolean} [options.trailing=true]
  9118. * Specify invoking on the trailing edge of the timeout.
  9119. * @returns {Function} Returns the new debounced function.
  9120. * @example
  9121. *
  9122. * // Avoid costly calculations while the window size is in flux.
  9123. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9124. *
  9125. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9126. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9127. * 'leading': true,
  9128. * 'trailing': false
  9129. * }));
  9130. *
  9131. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9132. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9133. * var source = new EventSource('/stream');
  9134. * jQuery(source).on('message', debounced);
  9135. *
  9136. * // Cancel the trailing debounced invocation.
  9137. * jQuery(window).on('popstate', debounced.cancel);
  9138. */
  9139. function debounce(func, wait, options) {
  9140. var lastArgs,
  9141. lastThis,
  9142. maxWait,
  9143. result,
  9144. timerId,
  9145. lastCallTime,
  9146. lastInvokeTime = 0,
  9147. leading = false,
  9148. maxing = false,
  9149. trailing = true;
  9150. if (typeof func != 'function') {
  9151. throw new TypeError(FUNC_ERROR_TEXT);
  9152. }
  9153. wait = toNumber(wait) || 0;
  9154. if (isObject(options)) {
  9155. leading = !!options.leading;
  9156. maxing = 'maxWait' in options;
  9157. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9158. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9159. }
  9160. function invokeFunc(time) {
  9161. var args = lastArgs,
  9162. thisArg = lastThis;
  9163. lastArgs = lastThis = undefined;
  9164. lastInvokeTime = time;
  9165. result = func.apply(thisArg, args);
  9166. return result;
  9167. }
  9168. function leadingEdge(time) {
  9169. // Reset any `maxWait` timer.
  9170. lastInvokeTime = time;
  9171. // Start the timer for the trailing edge.
  9172. timerId = setTimeout(timerExpired, wait);
  9173. // Invoke the leading edge.
  9174. return leading ? invokeFunc(time) : result;
  9175. }
  9176. function remainingWait(time) {
  9177. var timeSinceLastCall = time - lastCallTime,
  9178. timeSinceLastInvoke = time - lastInvokeTime,
  9179. result = wait - timeSinceLastCall;
  9180. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  9181. }
  9182. function shouldInvoke(time) {
  9183. var timeSinceLastCall = time - lastCallTime,
  9184. timeSinceLastInvoke = time - lastInvokeTime;
  9185. // Either this is the first call, activity has stopped and we're at the
  9186. // trailing edge, the system time has gone backwards and we're treating
  9187. // it as the trailing edge, or we've hit the `maxWait` limit.
  9188. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9189. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9190. }
  9191. function timerExpired() {
  9192. var time = now();
  9193. if (shouldInvoke(time)) {
  9194. return trailingEdge(time);
  9195. }
  9196. // Restart the timer.
  9197. timerId = setTimeout(timerExpired, remainingWait(time));
  9198. }
  9199. function trailingEdge(time) {
  9200. timerId = undefined;
  9201. // Only invoke if we have `lastArgs` which means `func` has been
  9202. // debounced at least once.
  9203. if (trailing && lastArgs) {
  9204. return invokeFunc(time);
  9205. }
  9206. lastArgs = lastThis = undefined;
  9207. return result;
  9208. }
  9209. function cancel() {
  9210. if (timerId !== undefined) {
  9211. clearTimeout(timerId);
  9212. }
  9213. lastInvokeTime = 0;
  9214. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9215. }
  9216. function flush() {
  9217. return timerId === undefined ? result : trailingEdge(now());
  9218. }
  9219. function debounced() {
  9220. var time = now(),
  9221. isInvoking = shouldInvoke(time);
  9222. lastArgs = arguments;
  9223. lastThis = this;
  9224. lastCallTime = time;
  9225. if (isInvoking) {
  9226. if (timerId === undefined) {
  9227. return leadingEdge(lastCallTime);
  9228. }
  9229. if (maxing) {
  9230. // Handle invocations in a tight loop.
  9231. timerId = setTimeout(timerExpired, wait);
  9232. return invokeFunc(lastCallTime);
  9233. }
  9234. }
  9235. if (timerId === undefined) {
  9236. timerId = setTimeout(timerExpired, wait);
  9237. }
  9238. return result;
  9239. }
  9240. debounced.cancel = cancel;
  9241. debounced.flush = flush;
  9242. return debounced;
  9243. }
  9244. /**
  9245. * Defers invoking the `func` until the current call stack has cleared. Any
  9246. * additional arguments are provided to `func` when it's invoked.
  9247. *
  9248. * @static
  9249. * @memberOf _
  9250. * @since 0.1.0
  9251. * @category Function
  9252. * @param {Function} func The function to defer.
  9253. * @param {...*} [args] The arguments to invoke `func` with.
  9254. * @returns {number} Returns the timer id.
  9255. * @example
  9256. *
  9257. * _.defer(function(text) {
  9258. * console.log(text);
  9259. * }, 'deferred');
  9260. * // => Logs 'deferred' after one or more milliseconds.
  9261. */
  9262. var defer = baseRest(function(func, args) {
  9263. return baseDelay(func, 1, args);
  9264. });
  9265. /**
  9266. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9267. * provided to `func` when it's invoked.
  9268. *
  9269. * @static
  9270. * @memberOf _
  9271. * @since 0.1.0
  9272. * @category Function
  9273. * @param {Function} func The function to delay.
  9274. * @param {number} wait The number of milliseconds to delay invocation.
  9275. * @param {...*} [args] The arguments to invoke `func` with.
  9276. * @returns {number} Returns the timer id.
  9277. * @example
  9278. *
  9279. * _.delay(function(text) {
  9280. * console.log(text);
  9281. * }, 1000, 'later');
  9282. * // => Logs 'later' after one second.
  9283. */
  9284. var delay = baseRest(function(func, wait, args) {
  9285. return baseDelay(func, toNumber(wait) || 0, args);
  9286. });
  9287. /**
  9288. * Creates a function that invokes `func` with arguments reversed.
  9289. *
  9290. * @static
  9291. * @memberOf _
  9292. * @since 4.0.0
  9293. * @category Function
  9294. * @param {Function} func The function to flip arguments for.
  9295. * @returns {Function} Returns the new flipped function.
  9296. * @example
  9297. *
  9298. * var flipped = _.flip(function() {
  9299. * return _.toArray(arguments);
  9300. * });
  9301. *
  9302. * flipped('a', 'b', 'c', 'd');
  9303. * // => ['d', 'c', 'b', 'a']
  9304. */
  9305. function flip(func) {
  9306. return createWrap(func, FLIP_FLAG);
  9307. }
  9308. /**
  9309. * Creates a function that memoizes the result of `func`. If `resolver` is
  9310. * provided, it determines the cache key for storing the result based on the
  9311. * arguments provided to the memoized function. By default, the first argument
  9312. * provided to the memoized function is used as the map cache key. The `func`
  9313. * is invoked with the `this` binding of the memoized function.
  9314. *
  9315. * **Note:** The cache is exposed as the `cache` property on the memoized
  9316. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9317. * constructor with one whose instances implement the
  9318. * [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  9319. * method interface of `delete`, `get`, `has`, and `set`.
  9320. *
  9321. * @static
  9322. * @memberOf _
  9323. * @since 0.1.0
  9324. * @category Function
  9325. * @param {Function} func The function to have its output memoized.
  9326. * @param {Function} [resolver] The function to resolve the cache key.
  9327. * @returns {Function} Returns the new memoized function.
  9328. * @example
  9329. *
  9330. * var object = { 'a': 1, 'b': 2 };
  9331. * var other = { 'c': 3, 'd': 4 };
  9332. *
  9333. * var values = _.memoize(_.values);
  9334. * values(object);
  9335. * // => [1, 2]
  9336. *
  9337. * values(other);
  9338. * // => [3, 4]
  9339. *
  9340. * object.a = 2;
  9341. * values(object);
  9342. * // => [1, 2]
  9343. *
  9344. * // Modify the result cache.
  9345. * values.cache.set(object, ['a', 'b']);
  9346. * values(object);
  9347. * // => ['a', 'b']
  9348. *
  9349. * // Replace `_.memoize.Cache`.
  9350. * _.memoize.Cache = WeakMap;
  9351. */
  9352. function memoize(func, resolver) {
  9353. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  9354. throw new TypeError(FUNC_ERROR_TEXT);
  9355. }
  9356. var memoized = function() {
  9357. var args = arguments,
  9358. key = resolver ? resolver.apply(this, args) : args[0],
  9359. cache = memoized.cache;
  9360. if (cache.has(key)) {
  9361. return cache.get(key);
  9362. }
  9363. var result = func.apply(this, args);
  9364. memoized.cache = cache.set(key, result);
  9365. return result;
  9366. };
  9367. memoized.cache = new (memoize.Cache || MapCache);
  9368. return memoized;
  9369. }
  9370. // Assign cache to `_.memoize`.
  9371. memoize.Cache = MapCache;
  9372. /**
  9373. * Creates a function that negates the result of the predicate `func`. The
  9374. * `func` predicate is invoked with the `this` binding and arguments of the
  9375. * created function.
  9376. *
  9377. * @static
  9378. * @memberOf _
  9379. * @since 3.0.0
  9380. * @category Function
  9381. * @param {Function} predicate The predicate to negate.
  9382. * @returns {Function} Returns the new negated function.
  9383. * @example
  9384. *
  9385. * function isEven(n) {
  9386. * return n % 2 == 0;
  9387. * }
  9388. *
  9389. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9390. * // => [1, 3, 5]
  9391. */
  9392. function negate(predicate) {
  9393. if (typeof predicate != 'function') {
  9394. throw new TypeError(FUNC_ERROR_TEXT);
  9395. }
  9396. return function() {
  9397. var args = arguments;
  9398. switch (args.length) {
  9399. case 0: return !predicate.call(this);
  9400. case 1: return !predicate.call(this, args[0]);
  9401. case 2: return !predicate.call(this, args[0], args[1]);
  9402. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9403. }
  9404. return !predicate.apply(this, args);
  9405. };
  9406. }
  9407. /**
  9408. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9409. * to the function return the value of the first invocation. The `func` is
  9410. * invoked with the `this` binding and arguments of the created function.
  9411. *
  9412. * @static
  9413. * @memberOf _
  9414. * @since 0.1.0
  9415. * @category Function
  9416. * @param {Function} func The function to restrict.
  9417. * @returns {Function} Returns the new restricted function.
  9418. * @example
  9419. *
  9420. * var initialize = _.once(createApplication);
  9421. * initialize();
  9422. * initialize();
  9423. * // => `createApplication` is invoked once
  9424. */
  9425. function once(func) {
  9426. return before(2, func);
  9427. }
  9428. /**
  9429. * Creates a function that invokes `func` with its arguments transformed.
  9430. *
  9431. * @static
  9432. * @since 4.0.0
  9433. * @memberOf _
  9434. * @category Function
  9435. * @param {Function} func The function to wrap.
  9436. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9437. * The argument transforms.
  9438. * @returns {Function} Returns the new function.
  9439. * @example
  9440. *
  9441. * function doubled(n) {
  9442. * return n * 2;
  9443. * }
  9444. *
  9445. * function square(n) {
  9446. * return n * n;
  9447. * }
  9448. *
  9449. * var func = _.overArgs(function(x, y) {
  9450. * return [x, y];
  9451. * }, [square, doubled]);
  9452. *
  9453. * func(9, 3);
  9454. * // => [81, 6]
  9455. *
  9456. * func(10, 5);
  9457. * // => [100, 10]
  9458. */
  9459. var overArgs = baseRest(function(func, transforms) {
  9460. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9461. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9462. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9463. var funcsLength = transforms.length;
  9464. return baseRest(function(args) {
  9465. var index = -1,
  9466. length = nativeMin(args.length, funcsLength);
  9467. while (++index < length) {
  9468. args[index] = transforms[index].call(this, args[index]);
  9469. }
  9470. return apply(func, this, args);
  9471. });
  9472. });
  9473. /**
  9474. * Creates a function that invokes `func` with `partials` prepended to the
  9475. * arguments it receives. This method is like `_.bind` except it does **not**
  9476. * alter the `this` binding.
  9477. *
  9478. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9479. * builds, may be used as a placeholder for partially applied arguments.
  9480. *
  9481. * **Note:** This method doesn't set the "length" property of partially
  9482. * applied functions.
  9483. *
  9484. * @static
  9485. * @memberOf _
  9486. * @since 0.2.0
  9487. * @category Function
  9488. * @param {Function} func The function to partially apply arguments to.
  9489. * @param {...*} [partials] The arguments to be partially applied.
  9490. * @returns {Function} Returns the new partially applied function.
  9491. * @example
  9492. *
  9493. * function greet(greeting, name) {
  9494. * return greeting + ' ' + name;
  9495. * }
  9496. *
  9497. * var sayHelloTo = _.partial(greet, 'hello');
  9498. * sayHelloTo('fred');
  9499. * // => 'hello fred'
  9500. *
  9501. * // Partially applied with placeholders.
  9502. * var greetFred = _.partial(greet, _, 'fred');
  9503. * greetFred('hi');
  9504. * // => 'hi fred'
  9505. */
  9506. var partial = baseRest(function(func, partials) {
  9507. var holders = replaceHolders(partials, getHolder(partial));
  9508. return createWrap(func, PARTIAL_FLAG, undefined, partials, holders);
  9509. });
  9510. /**
  9511. * This method is like `_.partial` except that partially applied arguments
  9512. * are appended to the arguments it receives.
  9513. *
  9514. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9515. * builds, may be used as a placeholder for partially applied arguments.
  9516. *
  9517. * **Note:** This method doesn't set the "length" property of partially
  9518. * applied functions.
  9519. *
  9520. * @static
  9521. * @memberOf _
  9522. * @since 1.0.0
  9523. * @category Function
  9524. * @param {Function} func The function to partially apply arguments to.
  9525. * @param {...*} [partials] The arguments to be partially applied.
  9526. * @returns {Function} Returns the new partially applied function.
  9527. * @example
  9528. *
  9529. * function greet(greeting, name) {
  9530. * return greeting + ' ' + name;
  9531. * }
  9532. *
  9533. * var greetFred = _.partialRight(greet, 'fred');
  9534. * greetFred('hi');
  9535. * // => 'hi fred'
  9536. *
  9537. * // Partially applied with placeholders.
  9538. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9539. * sayHelloTo('fred');
  9540. * // => 'hello fred'
  9541. */
  9542. var partialRight = baseRest(function(func, partials) {
  9543. var holders = replaceHolders(partials, getHolder(partialRight));
  9544. return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9545. });
  9546. /**
  9547. * Creates a function that invokes `func` with arguments arranged according
  9548. * to the specified `indexes` where the argument value at the first index is
  9549. * provided as the first argument, the argument value at the second index is
  9550. * provided as the second argument, and so on.
  9551. *
  9552. * @static
  9553. * @memberOf _
  9554. * @since 3.0.0
  9555. * @category Function
  9556. * @param {Function} func The function to rearrange arguments for.
  9557. * @param {...(number|number[])} indexes The arranged argument indexes.
  9558. * @returns {Function} Returns the new function.
  9559. * @example
  9560. *
  9561. * var rearged = _.rearg(function(a, b, c) {
  9562. * return [a, b, c];
  9563. * }, [2, 0, 1]);
  9564. *
  9565. * rearged('b', 'c', 'a')
  9566. * // => ['a', 'b', 'c']
  9567. */
  9568. var rearg = baseRest(function(func, indexes) {
  9569. return createWrap(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
  9570. });
  9571. /**
  9572. * Creates a function that invokes `func` with the `this` binding of the
  9573. * created function and arguments from `start` and beyond provided as
  9574. * an array.
  9575. *
  9576. * **Note:** This method is based on the
  9577. * [rest parameter](https://mdn.io/rest_parameters).
  9578. *
  9579. * @static
  9580. * @memberOf _
  9581. * @since 4.0.0
  9582. * @category Function
  9583. * @param {Function} func The function to apply a rest parameter to.
  9584. * @param {number} [start=func.length-1] The start position of the rest parameter.
  9585. * @returns {Function} Returns the new function.
  9586. * @example
  9587. *
  9588. * var say = _.rest(function(what, names) {
  9589. * return what + ' ' + _.initial(names).join(', ') +
  9590. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  9591. * });
  9592. *
  9593. * say('hello', 'fred', 'barney', 'pebbles');
  9594. * // => 'hello fred, barney, & pebbles'
  9595. */
  9596. function rest(func, start) {
  9597. if (typeof func != 'function') {
  9598. throw new TypeError(FUNC_ERROR_TEXT);
  9599. }
  9600. start = start === undefined ? start : toInteger(start);
  9601. return baseRest(func, start);
  9602. }
  9603. /**
  9604. * Creates a function that invokes `func` with the `this` binding of the
  9605. * create function and an array of arguments much like
  9606. * [`Function#apply`](http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.apply).
  9607. *
  9608. * **Note:** This method is based on the
  9609. * [spread operator](https://mdn.io/spread_operator).
  9610. *
  9611. * @static
  9612. * @memberOf _
  9613. * @since 3.2.0
  9614. * @category Function
  9615. * @param {Function} func The function to spread arguments over.
  9616. * @param {number} [start=0] The start position of the spread.
  9617. * @returns {Function} Returns the new function.
  9618. * @example
  9619. *
  9620. * var say = _.spread(function(who, what) {
  9621. * return who + ' says ' + what;
  9622. * });
  9623. *
  9624. * say(['fred', 'hello']);
  9625. * // => 'fred says hello'
  9626. *
  9627. * var numbers = Promise.all([
  9628. * Promise.resolve(40),
  9629. * Promise.resolve(36)
  9630. * ]);
  9631. *
  9632. * numbers.then(_.spread(function(x, y) {
  9633. * return x + y;
  9634. * }));
  9635. * // => a Promise of 76
  9636. */
  9637. function spread(func, start) {
  9638. if (typeof func != 'function') {
  9639. throw new TypeError(FUNC_ERROR_TEXT);
  9640. }
  9641. start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
  9642. return baseRest(function(args) {
  9643. var array = args[start],
  9644. otherArgs = castSlice(args, 0, start);
  9645. if (array) {
  9646. arrayPush(otherArgs, array);
  9647. }
  9648. return apply(func, this, otherArgs);
  9649. });
  9650. }
  9651. /**
  9652. * Creates a throttled function that only invokes `func` at most once per
  9653. * every `wait` milliseconds. The throttled function comes with a `cancel`
  9654. * method to cancel delayed `func` invocations and a `flush` method to
  9655. * immediately invoke them. Provide an options object to indicate whether
  9656. * `func` should be invoked on the leading and/or trailing edge of the `wait`
  9657. * timeout. The `func` is invoked with the last arguments provided to the
  9658. * throttled function. Subsequent calls to the throttled function return the
  9659. * result of the last `func` invocation.
  9660. *
  9661. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9662. * invoked on the trailing edge of the timeout only if the throttled function
  9663. * is invoked more than once during the `wait` timeout.
  9664. *
  9665. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9666. * for details over the differences between `_.throttle` and `_.debounce`.
  9667. *
  9668. * @static
  9669. * @memberOf _
  9670. * @since 0.1.0
  9671. * @category Function
  9672. * @param {Function} func The function to throttle.
  9673. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  9674. * @param {Object} [options={}] The options object.
  9675. * @param {boolean} [options.leading=true]
  9676. * Specify invoking on the leading edge of the timeout.
  9677. * @param {boolean} [options.trailing=true]
  9678. * Specify invoking on the trailing edge of the timeout.
  9679. * @returns {Function} Returns the new throttled function.
  9680. * @example
  9681. *
  9682. * // Avoid excessively updating the position while scrolling.
  9683. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  9684. *
  9685. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  9686. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  9687. * jQuery(element).on('click', throttled);
  9688. *
  9689. * // Cancel the trailing throttled invocation.
  9690. * jQuery(window).on('popstate', throttled.cancel);
  9691. */
  9692. function throttle(func, wait, options) {
  9693. var leading = true,
  9694. trailing = true;
  9695. if (typeof func != 'function') {
  9696. throw new TypeError(FUNC_ERROR_TEXT);
  9697. }
  9698. if (isObject(options)) {
  9699. leading = 'leading' in options ? !!options.leading : leading;
  9700. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9701. }
  9702. return debounce(func, wait, {
  9703. 'leading': leading,
  9704. 'maxWait': wait,
  9705. 'trailing': trailing
  9706. });
  9707. }
  9708. /**
  9709. * Creates a function that accepts up to one argument, ignoring any
  9710. * additional arguments.
  9711. *
  9712. * @static
  9713. * @memberOf _
  9714. * @since 4.0.0
  9715. * @category Function
  9716. * @param {Function} func The function to cap arguments for.
  9717. * @returns {Function} Returns the new capped function.
  9718. * @example
  9719. *
  9720. * _.map(['6', '8', '10'], _.unary(parseInt));
  9721. * // => [6, 8, 10]
  9722. */
  9723. function unary(func) {
  9724. return ary(func, 1);
  9725. }
  9726. /**
  9727. * Creates a function that provides `value` to `wrapper` as its first
  9728. * argument. Any additional arguments provided to the function are appended
  9729. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  9730. * binding of the created function.
  9731. *
  9732. * @static
  9733. * @memberOf _
  9734. * @since 0.1.0
  9735. * @category Function
  9736. * @param {*} value The value to wrap.
  9737. * @param {Function} [wrapper=identity] The wrapper function.
  9738. * @returns {Function} Returns the new function.
  9739. * @example
  9740. *
  9741. * var p = _.wrap(_.escape, function(func, text) {
  9742. * return '<p>' + func(text) + '</p>';
  9743. * });
  9744. *
  9745. * p('fred, barney, & pebbles');
  9746. * // => '<p>fred, barney, &amp; pebbles</p>'
  9747. */
  9748. function wrap(value, wrapper) {
  9749. wrapper = wrapper == null ? identity : wrapper;
  9750. return partial(wrapper, value);
  9751. }
  9752. /*------------------------------------------------------------------------*/
  9753. /**
  9754. * Casts `value` as an array if it's not one.
  9755. *
  9756. * @static
  9757. * @memberOf _
  9758. * @since 4.4.0
  9759. * @category Lang
  9760. * @param {*} value The value to inspect.
  9761. * @returns {Array} Returns the cast array.
  9762. * @example
  9763. *
  9764. * _.castArray(1);
  9765. * // => [1]
  9766. *
  9767. * _.castArray({ 'a': 1 });
  9768. * // => [{ 'a': 1 }]
  9769. *
  9770. * _.castArray('abc');
  9771. * // => ['abc']
  9772. *
  9773. * _.castArray(null);
  9774. * // => [null]
  9775. *
  9776. * _.castArray(undefined);
  9777. * // => [undefined]
  9778. *
  9779. * _.castArray();
  9780. * // => []
  9781. *
  9782. * var array = [1, 2, 3];
  9783. * console.log(_.castArray(array) === array);
  9784. * // => true
  9785. */
  9786. function castArray() {
  9787. if (!arguments.length) {
  9788. return [];
  9789. }
  9790. var value = arguments[0];
  9791. return isArray(value) ? value : [value];
  9792. }
  9793. /**
  9794. * Creates a shallow clone of `value`.
  9795. *
  9796. * **Note:** This method is loosely based on the
  9797. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  9798. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  9799. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  9800. * arrays. The own enumerable properties of `arguments` objects are cloned
  9801. * as plain objects. An empty object is returned for uncloneable values such
  9802. * as error objects, functions, DOM nodes, and WeakMaps.
  9803. *
  9804. * @static
  9805. * @memberOf _
  9806. * @since 0.1.0
  9807. * @category Lang
  9808. * @param {*} value The value to clone.
  9809. * @returns {*} Returns the cloned value.
  9810. * @see _.cloneDeep
  9811. * @example
  9812. *
  9813. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  9814. *
  9815. * var shallow = _.clone(objects);
  9816. * console.log(shallow[0] === objects[0]);
  9817. * // => true
  9818. */
  9819. function clone(value) {
  9820. return baseClone(value, false, true);
  9821. }
  9822. /**
  9823. * This method is like `_.clone` except that it accepts `customizer` which
  9824. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  9825. * cloning is handled by the method instead. The `customizer` is invoked with
  9826. * up to four arguments; (value [, index|key, object, stack]).
  9827. *
  9828. * @static
  9829. * @memberOf _
  9830. * @since 4.0.0
  9831. * @category Lang
  9832. * @param {*} value The value to clone.
  9833. * @param {Function} [customizer] The function to customize cloning.
  9834. * @returns {*} Returns the cloned value.
  9835. * @see _.cloneDeepWith
  9836. * @example
  9837. *
  9838. * function customizer(value) {
  9839. * if (_.isElement(value)) {
  9840. * return value.cloneNode(false);
  9841. * }
  9842. * }
  9843. *
  9844. * var el = _.cloneWith(document.body, customizer);
  9845. *
  9846. * console.log(el === document.body);
  9847. * // => false
  9848. * console.log(el.nodeName);
  9849. * // => 'BODY'
  9850. * console.log(el.childNodes.length);
  9851. * // => 0
  9852. */
  9853. function cloneWith(value, customizer) {
  9854. return baseClone(value, false, true, customizer);
  9855. }
  9856. /**
  9857. * This method is like `_.clone` except that it recursively clones `value`.
  9858. *
  9859. * @static
  9860. * @memberOf _
  9861. * @since 1.0.0
  9862. * @category Lang
  9863. * @param {*} value The value to recursively clone.
  9864. * @returns {*} Returns the deep cloned value.
  9865. * @see _.clone
  9866. * @example
  9867. *
  9868. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  9869. *
  9870. * var deep = _.cloneDeep(objects);
  9871. * console.log(deep[0] === objects[0]);
  9872. * // => false
  9873. */
  9874. function cloneDeep(value) {
  9875. return baseClone(value, true, true);
  9876. }
  9877. /**
  9878. * This method is like `_.cloneWith` except that it recursively clones `value`.
  9879. *
  9880. * @static
  9881. * @memberOf _
  9882. * @since 4.0.0
  9883. * @category Lang
  9884. * @param {*} value The value to recursively clone.
  9885. * @param {Function} [customizer] The function to customize cloning.
  9886. * @returns {*} Returns the deep cloned value.
  9887. * @see _.cloneWith
  9888. * @example
  9889. *
  9890. * function customizer(value) {
  9891. * if (_.isElement(value)) {
  9892. * return value.cloneNode(true);
  9893. * }
  9894. * }
  9895. *
  9896. * var el = _.cloneDeepWith(document.body, customizer);
  9897. *
  9898. * console.log(el === document.body);
  9899. * // => false
  9900. * console.log(el.nodeName);
  9901. * // => 'BODY'
  9902. * console.log(el.childNodes.length);
  9903. * // => 20
  9904. */
  9905. function cloneDeepWith(value, customizer) {
  9906. return baseClone(value, true, true, customizer);
  9907. }
  9908. /**
  9909. * Checks if `object` conforms to `source` by invoking the predicate properties
  9910. * of `source` with the corresponding property values of `object`. This method
  9911. * is equivalent to a `_.conforms` function when `source` is partially applied.
  9912. *
  9913. * @static
  9914. * @memberOf _
  9915. * @since 4.14.0
  9916. * @category Lang
  9917. * @param {Object} object The object to inspect.
  9918. * @param {Object} source The object of property predicates to conform to.
  9919. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  9920. * @example
  9921. *
  9922. * var object = { 'a': 1, 'b': 2 };
  9923. *
  9924. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  9925. * // => true
  9926. *
  9927. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  9928. * // => false
  9929. */
  9930. function conformsTo(object, source) {
  9931. return source == null || baseConformsTo(object, source, keys(source));
  9932. }
  9933. /**
  9934. * Performs a
  9935. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  9936. * comparison between two values to determine if they are equivalent.
  9937. *
  9938. * @static
  9939. * @memberOf _
  9940. * @since 4.0.0
  9941. * @category Lang
  9942. * @param {*} value The value to compare.
  9943. * @param {*} other The other value to compare.
  9944. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  9945. * @example
  9946. *
  9947. * var object = { 'a': 1 };
  9948. * var other = { 'a': 1 };
  9949. *
  9950. * _.eq(object, object);
  9951. * // => true
  9952. *
  9953. * _.eq(object, other);
  9954. * // => false
  9955. *
  9956. * _.eq('a', 'a');
  9957. * // => true
  9958. *
  9959. * _.eq('a', Object('a'));
  9960. * // => false
  9961. *
  9962. * _.eq(NaN, NaN);
  9963. * // => true
  9964. */
  9965. function eq(value, other) {
  9966. return value === other || (value !== value && other !== other);
  9967. }
  9968. /**
  9969. * Checks if `value` is greater than `other`.
  9970. *
  9971. * @static
  9972. * @memberOf _
  9973. * @since 3.9.0
  9974. * @category Lang
  9975. * @param {*} value The value to compare.
  9976. * @param {*} other The other value to compare.
  9977. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  9978. * else `false`.
  9979. * @see _.lt
  9980. * @example
  9981. *
  9982. * _.gt(3, 1);
  9983. * // => true
  9984. *
  9985. * _.gt(3, 3);
  9986. * // => false
  9987. *
  9988. * _.gt(1, 3);
  9989. * // => false
  9990. */
  9991. var gt = createRelationalOperation(baseGt);
  9992. /**
  9993. * Checks if `value` is greater than or equal to `other`.
  9994. *
  9995. * @static
  9996. * @memberOf _
  9997. * @since 3.9.0
  9998. * @category Lang
  9999. * @param {*} value The value to compare.
  10000. * @param {*} other The other value to compare.
  10001. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10002. * `other`, else `false`.
  10003. * @see _.lte
  10004. * @example
  10005. *
  10006. * _.gte(3, 1);
  10007. * // => true
  10008. *
  10009. * _.gte(3, 3);
  10010. * // => true
  10011. *
  10012. * _.gte(1, 3);
  10013. * // => false
  10014. */
  10015. var gte = createRelationalOperation(function(value, other) {
  10016. return value >= other;
  10017. });
  10018. /**
  10019. * Checks if `value` is likely an `arguments` object.
  10020. *
  10021. * @static
  10022. * @memberOf _
  10023. * @since 0.1.0
  10024. * @category Lang
  10025. * @param {*} value The value to check.
  10026. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10027. * else `false`.
  10028. * @example
  10029. *
  10030. * _.isArguments(function() { return arguments; }());
  10031. * // => true
  10032. *
  10033. * _.isArguments([1, 2, 3]);
  10034. * // => false
  10035. */
  10036. function isArguments(value) {
  10037. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  10038. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10039. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10040. }
  10041. /**
  10042. * Checks if `value` is classified as an `Array` object.
  10043. *
  10044. * @static
  10045. * @memberOf _
  10046. * @since 0.1.0
  10047. * @category Lang
  10048. * @param {*} value The value to check.
  10049. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10050. * @example
  10051. *
  10052. * _.isArray([1, 2, 3]);
  10053. * // => true
  10054. *
  10055. * _.isArray(document.body.children);
  10056. * // => false
  10057. *
  10058. * _.isArray('abc');
  10059. * // => false
  10060. *
  10061. * _.isArray(_.noop);
  10062. * // => false
  10063. */
  10064. var isArray = Array.isArray;
  10065. /**
  10066. * Checks if `value` is classified as an `ArrayBuffer` object.
  10067. *
  10068. * @static
  10069. * @memberOf _
  10070. * @since 4.3.0
  10071. * @category Lang
  10072. * @param {*} value The value to check.
  10073. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10074. * @example
  10075. *
  10076. * _.isArrayBuffer(new ArrayBuffer(2));
  10077. * // => true
  10078. *
  10079. * _.isArrayBuffer(new Array(2));
  10080. * // => false
  10081. */
  10082. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10083. /**
  10084. * Checks if `value` is array-like. A value is considered array-like if it's
  10085. * not a function and has a `value.length` that's an integer greater than or
  10086. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10087. *
  10088. * @static
  10089. * @memberOf _
  10090. * @since 4.0.0
  10091. * @category Lang
  10092. * @param {*} value The value to check.
  10093. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10094. * @example
  10095. *
  10096. * _.isArrayLike([1, 2, 3]);
  10097. * // => true
  10098. *
  10099. * _.isArrayLike(document.body.children);
  10100. * // => true
  10101. *
  10102. * _.isArrayLike('abc');
  10103. * // => true
  10104. *
  10105. * _.isArrayLike(_.noop);
  10106. * // => false
  10107. */
  10108. function isArrayLike(value) {
  10109. return value != null && isLength(getLength(value)) && !isFunction(value);
  10110. }
  10111. /**
  10112. * This method is like `_.isArrayLike` except that it also checks if `value`
  10113. * is an object.
  10114. *
  10115. * @static
  10116. * @memberOf _
  10117. * @since 4.0.0
  10118. * @category Lang
  10119. * @param {*} value The value to check.
  10120. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10121. * else `false`.
  10122. * @example
  10123. *
  10124. * _.isArrayLikeObject([1, 2, 3]);
  10125. * // => true
  10126. *
  10127. * _.isArrayLikeObject(document.body.children);
  10128. * // => true
  10129. *
  10130. * _.isArrayLikeObject('abc');
  10131. * // => false
  10132. *
  10133. * _.isArrayLikeObject(_.noop);
  10134. * // => false
  10135. */
  10136. function isArrayLikeObject(value) {
  10137. return isObjectLike(value) && isArrayLike(value);
  10138. }
  10139. /**
  10140. * Checks if `value` is classified as a boolean primitive or object.
  10141. *
  10142. * @static
  10143. * @memberOf _
  10144. * @since 0.1.0
  10145. * @category Lang
  10146. * @param {*} value The value to check.
  10147. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10148. * @example
  10149. *
  10150. * _.isBoolean(false);
  10151. * // => true
  10152. *
  10153. * _.isBoolean(null);
  10154. * // => false
  10155. */
  10156. function isBoolean(value) {
  10157. return value === true || value === false ||
  10158. (isObjectLike(value) && objectToString.call(value) == boolTag);
  10159. }
  10160. /**
  10161. * Checks if `value` is a buffer.
  10162. *
  10163. * @static
  10164. * @memberOf _
  10165. * @since 4.3.0
  10166. * @category Lang
  10167. * @param {*} value The value to check.
  10168. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10169. * @example
  10170. *
  10171. * _.isBuffer(new Buffer(2));
  10172. * // => true
  10173. *
  10174. * _.isBuffer(new Uint8Array(2));
  10175. * // => false
  10176. */
  10177. var isBuffer = nativeIsBuffer || stubFalse;
  10178. /**
  10179. * Checks if `value` is classified as a `Date` object.
  10180. *
  10181. * @static
  10182. * @memberOf _
  10183. * @since 0.1.0
  10184. * @category Lang
  10185. * @param {*} value The value to check.
  10186. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10187. * @example
  10188. *
  10189. * _.isDate(new Date);
  10190. * // => true
  10191. *
  10192. * _.isDate('Mon April 23 2012');
  10193. * // => false
  10194. */
  10195. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10196. /**
  10197. * Checks if `value` is likely a DOM element.
  10198. *
  10199. * @static
  10200. * @memberOf _
  10201. * @since 0.1.0
  10202. * @category Lang
  10203. * @param {*} value The value to check.
  10204. * @returns {boolean} Returns `true` if `value` is a DOM element,
  10205. * else `false`.
  10206. * @example
  10207. *
  10208. * _.isElement(document.body);
  10209. * // => true
  10210. *
  10211. * _.isElement('<body>');
  10212. * // => false
  10213. */
  10214. function isElement(value) {
  10215. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  10216. }
  10217. /**
  10218. * Checks if `value` is an empty object, collection, map, or set.
  10219. *
  10220. * Objects are considered empty if they have no own enumerable string keyed
  10221. * properties.
  10222. *
  10223. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10224. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10225. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10226. *
  10227. * @static
  10228. * @memberOf _
  10229. * @since 0.1.0
  10230. * @category Lang
  10231. * @param {*} value The value to check.
  10232. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10233. * @example
  10234. *
  10235. * _.isEmpty(null);
  10236. * // => true
  10237. *
  10238. * _.isEmpty(true);
  10239. * // => true
  10240. *
  10241. * _.isEmpty(1);
  10242. * // => true
  10243. *
  10244. * _.isEmpty([1, 2, 3]);
  10245. * // => false
  10246. *
  10247. * _.isEmpty({ 'a': 1 });
  10248. * // => false
  10249. */
  10250. function isEmpty(value) {
  10251. if (isArrayLike(value) &&
  10252. (isArray(value) || isString(value) || isFunction(value.splice) ||
  10253. isArguments(value) || isBuffer(value))) {
  10254. return !value.length;
  10255. }
  10256. if (isObjectLike(value)) {
  10257. var tag = getTag(value);
  10258. if (tag == mapTag || tag == setTag) {
  10259. return !value.size;
  10260. }
  10261. }
  10262. for (var key in value) {
  10263. if (hasOwnProperty.call(value, key)) {
  10264. return false;
  10265. }
  10266. }
  10267. return !(nonEnumShadows && keys(value).length);
  10268. }
  10269. /**
  10270. * Performs a deep comparison between two values to determine if they are
  10271. * equivalent.
  10272. *
  10273. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10274. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10275. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10276. * by their own, not inherited, enumerable properties. Functions and DOM
  10277. * nodes are **not** supported.
  10278. *
  10279. * @static
  10280. * @memberOf _
  10281. * @since 0.1.0
  10282. * @category Lang
  10283. * @param {*} value The value to compare.
  10284. * @param {*} other The other value to compare.
  10285. * @returns {boolean} Returns `true` if the values are equivalent,
  10286. * else `false`.
  10287. * @example
  10288. *
  10289. * var object = { 'a': 1 };
  10290. * var other = { 'a': 1 };
  10291. *
  10292. * _.isEqual(object, other);
  10293. * // => true
  10294. *
  10295. * object === other;
  10296. * // => false
  10297. */
  10298. function isEqual(value, other) {
  10299. return baseIsEqual(value, other);
  10300. }
  10301. /**
  10302. * This method is like `_.isEqual` except that it accepts `customizer` which
  10303. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10304. * are handled by the method instead. The `customizer` is invoked with up to
  10305. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10306. *
  10307. * @static
  10308. * @memberOf _
  10309. * @since 4.0.0
  10310. * @category Lang
  10311. * @param {*} value The value to compare.
  10312. * @param {*} other The other value to compare.
  10313. * @param {Function} [customizer] The function to customize comparisons.
  10314. * @returns {boolean} Returns `true` if the values are equivalent,
  10315. * else `false`.
  10316. * @example
  10317. *
  10318. * function isGreeting(value) {
  10319. * return /^h(?:i|ello)$/.test(value);
  10320. * }
  10321. *
  10322. * function customizer(objValue, othValue) {
  10323. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10324. * return true;
  10325. * }
  10326. * }
  10327. *
  10328. * var array = ['hello', 'goodbye'];
  10329. * var other = ['hi', 'goodbye'];
  10330. *
  10331. * _.isEqualWith(array, other, customizer);
  10332. * // => true
  10333. */
  10334. function isEqualWith(value, other, customizer) {
  10335. customizer = typeof customizer == 'function' ? customizer : undefined;
  10336. var result = customizer ? customizer(value, other) : undefined;
  10337. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  10338. }
  10339. /**
  10340. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10341. * `SyntaxError`, `TypeError`, or `URIError` object.
  10342. *
  10343. * @static
  10344. * @memberOf _
  10345. * @since 3.0.0
  10346. * @category Lang
  10347. * @param {*} value The value to check.
  10348. * @returns {boolean} Returns `true` if `value` is an error object,
  10349. * else `false`.
  10350. * @example
  10351. *
  10352. * _.isError(new Error);
  10353. * // => true
  10354. *
  10355. * _.isError(Error);
  10356. * // => false
  10357. */
  10358. function isError(value) {
  10359. if (!isObjectLike(value)) {
  10360. return false;
  10361. }
  10362. return (objectToString.call(value) == errorTag) ||
  10363. (typeof value.message == 'string' && typeof value.name == 'string');
  10364. }
  10365. /**
  10366. * Checks if `value` is a finite primitive number.
  10367. *
  10368. * **Note:** This method is based on
  10369. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10370. *
  10371. * @static
  10372. * @memberOf _
  10373. * @since 0.1.0
  10374. * @category Lang
  10375. * @param {*} value The value to check.
  10376. * @returns {boolean} Returns `true` if `value` is a finite number,
  10377. * else `false`.
  10378. * @example
  10379. *
  10380. * _.isFinite(3);
  10381. * // => true
  10382. *
  10383. * _.isFinite(Number.MIN_VALUE);
  10384. * // => true
  10385. *
  10386. * _.isFinite(Infinity);
  10387. * // => false
  10388. *
  10389. * _.isFinite('3');
  10390. * // => false
  10391. */
  10392. function isFinite(value) {
  10393. return typeof value == 'number' && nativeIsFinite(value);
  10394. }
  10395. /**
  10396. * Checks if `value` is classified as a `Function` object.
  10397. *
  10398. * @static
  10399. * @memberOf _
  10400. * @since 0.1.0
  10401. * @category Lang
  10402. * @param {*} value The value to check.
  10403. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10404. * @example
  10405. *
  10406. * _.isFunction(_);
  10407. * // => true
  10408. *
  10409. * _.isFunction(/abc/);
  10410. * // => false
  10411. */
  10412. function isFunction(value) {
  10413. // The use of `Object#toString` avoids issues with the `typeof` operator
  10414. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  10415. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  10416. var tag = isObject(value) ? objectToString.call(value) : '';
  10417. return tag == funcTag || tag == genTag;
  10418. }
  10419. /**
  10420. * Checks if `value` is an integer.
  10421. *
  10422. * **Note:** This method is based on
  10423. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10424. *
  10425. * @static
  10426. * @memberOf _
  10427. * @since 4.0.0
  10428. * @category Lang
  10429. * @param {*} value The value to check.
  10430. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10431. * @example
  10432. *
  10433. * _.isInteger(3);
  10434. * // => true
  10435. *
  10436. * _.isInteger(Number.MIN_VALUE);
  10437. * // => false
  10438. *
  10439. * _.isInteger(Infinity);
  10440. * // => false
  10441. *
  10442. * _.isInteger('3');
  10443. * // => false
  10444. */
  10445. function isInteger(value) {
  10446. return typeof value == 'number' && value == toInteger(value);
  10447. }
  10448. /**
  10449. * Checks if `value` is a valid array-like length.
  10450. *
  10451. * **Note:** This function is loosely based on
  10452. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10453. *
  10454. * @static
  10455. * @memberOf _
  10456. * @since 4.0.0
  10457. * @category Lang
  10458. * @param {*} value The value to check.
  10459. * @returns {boolean} Returns `true` if `value` is a valid length,
  10460. * else `false`.
  10461. * @example
  10462. *
  10463. * _.isLength(3);
  10464. * // => true
  10465. *
  10466. * _.isLength(Number.MIN_VALUE);
  10467. * // => false
  10468. *
  10469. * _.isLength(Infinity);
  10470. * // => false
  10471. *
  10472. * _.isLength('3');
  10473. * // => false
  10474. */
  10475. function isLength(value) {
  10476. return typeof value == 'number' &&
  10477. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10478. }
  10479. /**
  10480. * Checks if `value` is the
  10481. * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
  10482. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10483. *
  10484. * @static
  10485. * @memberOf _
  10486. * @since 0.1.0
  10487. * @category Lang
  10488. * @param {*} value The value to check.
  10489. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10490. * @example
  10491. *
  10492. * _.isObject({});
  10493. * // => true
  10494. *
  10495. * _.isObject([1, 2, 3]);
  10496. * // => true
  10497. *
  10498. * _.isObject(_.noop);
  10499. * // => true
  10500. *
  10501. * _.isObject(null);
  10502. * // => false
  10503. */
  10504. function isObject(value) {
  10505. var type = typeof value;
  10506. return !!value && (type == 'object' || type == 'function');
  10507. }
  10508. /**
  10509. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10510. * and has a `typeof` result of "object".
  10511. *
  10512. * @static
  10513. * @memberOf _
  10514. * @since 4.0.0
  10515. * @category Lang
  10516. * @param {*} value The value to check.
  10517. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10518. * @example
  10519. *
  10520. * _.isObjectLike({});
  10521. * // => true
  10522. *
  10523. * _.isObjectLike([1, 2, 3]);
  10524. * // => true
  10525. *
  10526. * _.isObjectLike(_.noop);
  10527. * // => false
  10528. *
  10529. * _.isObjectLike(null);
  10530. * // => false
  10531. */
  10532. function isObjectLike(value) {
  10533. return !!value && typeof value == 'object';
  10534. }
  10535. /**
  10536. * Checks if `value` is classified as a `Map` object.
  10537. *
  10538. * @static
  10539. * @memberOf _
  10540. * @since 4.3.0
  10541. * @category Lang
  10542. * @param {*} value The value to check.
  10543. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10544. * @example
  10545. *
  10546. * _.isMap(new Map);
  10547. * // => true
  10548. *
  10549. * _.isMap(new WeakMap);
  10550. * // => false
  10551. */
  10552. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  10553. /**
  10554. * Performs a partial deep comparison between `object` and `source` to
  10555. * determine if `object` contains equivalent property values. This method is
  10556. * equivalent to a `_.matches` function when `source` is partially applied.
  10557. *
  10558. * **Note:** This method supports comparing the same values as `_.isEqual`.
  10559. *
  10560. * @static
  10561. * @memberOf _
  10562. * @since 3.0.0
  10563. * @category Lang
  10564. * @param {Object} object The object to inspect.
  10565. * @param {Object} source The object of property values to match.
  10566. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10567. * @example
  10568. *
  10569. * var object = { 'a': 1, 'b': 2 };
  10570. *
  10571. * _.isMatch(object, { 'b': 2 });
  10572. * // => true
  10573. *
  10574. * _.isMatch(object, { 'b': 1 });
  10575. * // => false
  10576. */
  10577. function isMatch(object, source) {
  10578. return object === source || baseIsMatch(object, source, getMatchData(source));
  10579. }
  10580. /**
  10581. * This method is like `_.isMatch` except that it accepts `customizer` which
  10582. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10583. * are handled by the method instead. The `customizer` is invoked with five
  10584. * arguments: (objValue, srcValue, index|key, object, source).
  10585. *
  10586. * @static
  10587. * @memberOf _
  10588. * @since 4.0.0
  10589. * @category Lang
  10590. * @param {Object} object The object to inspect.
  10591. * @param {Object} source The object of property values to match.
  10592. * @param {Function} [customizer] The function to customize comparisons.
  10593. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10594. * @example
  10595. *
  10596. * function isGreeting(value) {
  10597. * return /^h(?:i|ello)$/.test(value);
  10598. * }
  10599. *
  10600. * function customizer(objValue, srcValue) {
  10601. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  10602. * return true;
  10603. * }
  10604. * }
  10605. *
  10606. * var object = { 'greeting': 'hello' };
  10607. * var source = { 'greeting': 'hi' };
  10608. *
  10609. * _.isMatchWith(object, source, customizer);
  10610. * // => true
  10611. */
  10612. function isMatchWith(object, source, customizer) {
  10613. customizer = typeof customizer == 'function' ? customizer : undefined;
  10614. return baseIsMatch(object, source, getMatchData(source), customizer);
  10615. }
  10616. /**
  10617. * Checks if `value` is `NaN`.
  10618. *
  10619. * **Note:** This method is based on
  10620. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  10621. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  10622. * `undefined` and other non-number values.
  10623. *
  10624. * @static
  10625. * @memberOf _
  10626. * @since 0.1.0
  10627. * @category Lang
  10628. * @param {*} value The value to check.
  10629. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  10630. * @example
  10631. *
  10632. * _.isNaN(NaN);
  10633. * // => true
  10634. *
  10635. * _.isNaN(new Number(NaN));
  10636. * // => true
  10637. *
  10638. * isNaN(undefined);
  10639. * // => true
  10640. *
  10641. * _.isNaN(undefined);
  10642. * // => false
  10643. */
  10644. function isNaN(value) {
  10645. // An `NaN` primitive is the only value that is not equal to itself.
  10646. // Perform the `toStringTag` check first to avoid errors with some
  10647. // ActiveX objects in IE.
  10648. return isNumber(value) && value != +value;
  10649. }
  10650. /**
  10651. * Checks if `value` is a pristine native function.
  10652. *
  10653. * **Note:** This method can't reliably detect native functions in the presence
  10654. * of the core-js package because core-js circumvents this kind of detection.
  10655. * Despite multiple requests, the core-js maintainer has made it clear: any
  10656. * attempt to fix the detection will be obstructed. As a result, we're left
  10657. * with little choice but to throw an error. Unfortunately, this also affects
  10658. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  10659. * which rely on core-js.
  10660. *
  10661. * @static
  10662. * @memberOf _
  10663. * @since 3.0.0
  10664. * @category Lang
  10665. * @param {*} value The value to check.
  10666. * @returns {boolean} Returns `true` if `value` is a native function,
  10667. * else `false`.
  10668. * @example
  10669. *
  10670. * _.isNative(Array.prototype.push);
  10671. * // => true
  10672. *
  10673. * _.isNative(_);
  10674. * // => false
  10675. */
  10676. function isNative(value) {
  10677. if (isMaskable(value)) {
  10678. throw new Error('This method is not supported with core-js. Try https://github.com/es-shims.');
  10679. }
  10680. return baseIsNative(value);
  10681. }
  10682. /**
  10683. * Checks if `value` is `null`.
  10684. *
  10685. * @static
  10686. * @memberOf _
  10687. * @since 0.1.0
  10688. * @category Lang
  10689. * @param {*} value The value to check.
  10690. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  10691. * @example
  10692. *
  10693. * _.isNull(null);
  10694. * // => true
  10695. *
  10696. * _.isNull(void 0);
  10697. * // => false
  10698. */
  10699. function isNull(value) {
  10700. return value === null;
  10701. }
  10702. /**
  10703. * Checks if `value` is `null` or `undefined`.
  10704. *
  10705. * @static
  10706. * @memberOf _
  10707. * @since 4.0.0
  10708. * @category Lang
  10709. * @param {*} value The value to check.
  10710. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  10711. * @example
  10712. *
  10713. * _.isNil(null);
  10714. * // => true
  10715. *
  10716. * _.isNil(void 0);
  10717. * // => true
  10718. *
  10719. * _.isNil(NaN);
  10720. * // => false
  10721. */
  10722. function isNil(value) {
  10723. return value == null;
  10724. }
  10725. /**
  10726. * Checks if `value` is classified as a `Number` primitive or object.
  10727. *
  10728. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  10729. * classified as numbers, use the `_.isFinite` method.
  10730. *
  10731. * @static
  10732. * @memberOf _
  10733. * @since 0.1.0
  10734. * @category Lang
  10735. * @param {*} value The value to check.
  10736. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  10737. * @example
  10738. *
  10739. * _.isNumber(3);
  10740. * // => true
  10741. *
  10742. * _.isNumber(Number.MIN_VALUE);
  10743. * // => true
  10744. *
  10745. * _.isNumber(Infinity);
  10746. * // => true
  10747. *
  10748. * _.isNumber('3');
  10749. * // => false
  10750. */
  10751. function isNumber(value) {
  10752. return typeof value == 'number' ||
  10753. (isObjectLike(value) && objectToString.call(value) == numberTag);
  10754. }
  10755. /**
  10756. * Checks if `value` is a plain object, that is, an object created by the
  10757. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  10758. *
  10759. * @static
  10760. * @memberOf _
  10761. * @since 0.8.0
  10762. * @category Lang
  10763. * @param {*} value The value to check.
  10764. * @returns {boolean} Returns `true` if `value` is a plain object,
  10765. * else `false`.
  10766. * @example
  10767. *
  10768. * function Foo() {
  10769. * this.a = 1;
  10770. * }
  10771. *
  10772. * _.isPlainObject(new Foo);
  10773. * // => false
  10774. *
  10775. * _.isPlainObject([1, 2, 3]);
  10776. * // => false
  10777. *
  10778. * _.isPlainObject({ 'x': 0, 'y': 0 });
  10779. * // => true
  10780. *
  10781. * _.isPlainObject(Object.create(null));
  10782. * // => true
  10783. */
  10784. function isPlainObject(value) {
  10785. if (!isObjectLike(value) ||
  10786. objectToString.call(value) != objectTag || isHostObject(value)) {
  10787. return false;
  10788. }
  10789. var proto = getPrototype(value);
  10790. if (proto === null) {
  10791. return true;
  10792. }
  10793. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  10794. return (typeof Ctor == 'function' &&
  10795. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  10796. }
  10797. /**
  10798. * Checks if `value` is classified as a `RegExp` object.
  10799. *
  10800. * @static
  10801. * @memberOf _
  10802. * @since 0.1.0
  10803. * @category Lang
  10804. * @param {*} value The value to check.
  10805. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  10806. * @example
  10807. *
  10808. * _.isRegExp(/abc/);
  10809. * // => true
  10810. *
  10811. * _.isRegExp('/abc/');
  10812. * // => false
  10813. */
  10814. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  10815. /**
  10816. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  10817. * double precision number which isn't the result of a rounded unsafe integer.
  10818. *
  10819. * **Note:** This method is based on
  10820. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  10821. *
  10822. * @static
  10823. * @memberOf _
  10824. * @since 4.0.0
  10825. * @category Lang
  10826. * @param {*} value The value to check.
  10827. * @returns {boolean} Returns `true` if `value` is a safe integer,
  10828. * else `false`.
  10829. * @example
  10830. *
  10831. * _.isSafeInteger(3);
  10832. * // => true
  10833. *
  10834. * _.isSafeInteger(Number.MIN_VALUE);
  10835. * // => false
  10836. *
  10837. * _.isSafeInteger(Infinity);
  10838. * // => false
  10839. *
  10840. * _.isSafeInteger('3');
  10841. * // => false
  10842. */
  10843. function isSafeInteger(value) {
  10844. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  10845. }
  10846. /**
  10847. * Checks if `value` is classified as a `Set` object.
  10848. *
  10849. * @static
  10850. * @memberOf _
  10851. * @since 4.3.0
  10852. * @category Lang
  10853. * @param {*} value The value to check.
  10854. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  10855. * @example
  10856. *
  10857. * _.isSet(new Set);
  10858. * // => true
  10859. *
  10860. * _.isSet(new WeakSet);
  10861. * // => false
  10862. */
  10863. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  10864. /**
  10865. * Checks if `value` is classified as a `String` primitive or object.
  10866. *
  10867. * @static
  10868. * @since 0.1.0
  10869. * @memberOf _
  10870. * @category Lang
  10871. * @param {*} value The value to check.
  10872. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  10873. * @example
  10874. *
  10875. * _.isString('abc');
  10876. * // => true
  10877. *
  10878. * _.isString(1);
  10879. * // => false
  10880. */
  10881. function isString(value) {
  10882. return typeof value == 'string' ||
  10883. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  10884. }
  10885. /**
  10886. * Checks if `value` is classified as a `Symbol` primitive or object.
  10887. *
  10888. * @static
  10889. * @memberOf _
  10890. * @since 4.0.0
  10891. * @category Lang
  10892. * @param {*} value The value to check.
  10893. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  10894. * @example
  10895. *
  10896. * _.isSymbol(Symbol.iterator);
  10897. * // => true
  10898. *
  10899. * _.isSymbol('abc');
  10900. * // => false
  10901. */
  10902. function isSymbol(value) {
  10903. return typeof value == 'symbol' ||
  10904. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  10905. }
  10906. /**
  10907. * Checks if `value` is classified as a typed array.
  10908. *
  10909. * @static
  10910. * @memberOf _
  10911. * @since 3.0.0
  10912. * @category Lang
  10913. * @param {*} value The value to check.
  10914. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  10915. * @example
  10916. *
  10917. * _.isTypedArray(new Uint8Array);
  10918. * // => true
  10919. *
  10920. * _.isTypedArray([]);
  10921. * // => false
  10922. */
  10923. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  10924. /**
  10925. * Checks if `value` is `undefined`.
  10926. *
  10927. * @static
  10928. * @since 0.1.0
  10929. * @memberOf _
  10930. * @category Lang
  10931. * @param {*} value The value to check.
  10932. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  10933. * @example
  10934. *
  10935. * _.isUndefined(void 0);
  10936. * // => true
  10937. *
  10938. * _.isUndefined(null);
  10939. * // => false
  10940. */
  10941. function isUndefined(value) {
  10942. return value === undefined;
  10943. }
  10944. /**
  10945. * Checks if `value` is classified as a `WeakMap` object.
  10946. *
  10947. * @static
  10948. * @memberOf _
  10949. * @since 4.3.0
  10950. * @category Lang
  10951. * @param {*} value The value to check.
  10952. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  10953. * @example
  10954. *
  10955. * _.isWeakMap(new WeakMap);
  10956. * // => true
  10957. *
  10958. * _.isWeakMap(new Map);
  10959. * // => false
  10960. */
  10961. function isWeakMap(value) {
  10962. return isObjectLike(value) && getTag(value) == weakMapTag;
  10963. }
  10964. /**
  10965. * Checks if `value` is classified as a `WeakSet` object.
  10966. *
  10967. * @static
  10968. * @memberOf _
  10969. * @since 4.3.0
  10970. * @category Lang
  10971. * @param {*} value The value to check.
  10972. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  10973. * @example
  10974. *
  10975. * _.isWeakSet(new WeakSet);
  10976. * // => true
  10977. *
  10978. * _.isWeakSet(new Set);
  10979. * // => false
  10980. */
  10981. function isWeakSet(value) {
  10982. return isObjectLike(value) && objectToString.call(value) == weakSetTag;
  10983. }
  10984. /**
  10985. * Checks if `value` is less than `other`.
  10986. *
  10987. * @static
  10988. * @memberOf _
  10989. * @since 3.9.0
  10990. * @category Lang
  10991. * @param {*} value The value to compare.
  10992. * @param {*} other The other value to compare.
  10993. * @returns {boolean} Returns `true` if `value` is less than `other`,
  10994. * else `false`.
  10995. * @see _.gt
  10996. * @example
  10997. *
  10998. * _.lt(1, 3);
  10999. * // => true
  11000. *
  11001. * _.lt(3, 3);
  11002. * // => false
  11003. *
  11004. * _.lt(3, 1);
  11005. * // => false
  11006. */
  11007. var lt = createRelationalOperation(baseLt);
  11008. /**
  11009. * Checks if `value` is less than or equal to `other`.
  11010. *
  11011. * @static
  11012. * @memberOf _
  11013. * @since 3.9.0
  11014. * @category Lang
  11015. * @param {*} value The value to compare.
  11016. * @param {*} other The other value to compare.
  11017. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11018. * `other`, else `false`.
  11019. * @see _.gte
  11020. * @example
  11021. *
  11022. * _.lte(1, 3);
  11023. * // => true
  11024. *
  11025. * _.lte(3, 3);
  11026. * // => true
  11027. *
  11028. * _.lte(3, 1);
  11029. * // => false
  11030. */
  11031. var lte = createRelationalOperation(function(value, other) {
  11032. return value <= other;
  11033. });
  11034. /**
  11035. * Converts `value` to an array.
  11036. *
  11037. * @static
  11038. * @since 0.1.0
  11039. * @memberOf _
  11040. * @category Lang
  11041. * @param {*} value The value to convert.
  11042. * @returns {Array} Returns the converted array.
  11043. * @example
  11044. *
  11045. * _.toArray({ 'a': 1, 'b': 2 });
  11046. * // => [1, 2]
  11047. *
  11048. * _.toArray('abc');
  11049. * // => ['a', 'b', 'c']
  11050. *
  11051. * _.toArray(1);
  11052. * // => []
  11053. *
  11054. * _.toArray(null);
  11055. * // => []
  11056. */
  11057. function toArray(value) {
  11058. if (!value) {
  11059. return [];
  11060. }
  11061. if (isArrayLike(value)) {
  11062. return isString(value) ? stringToArray(value) : copyArray(value);
  11063. }
  11064. if (iteratorSymbol && value[iteratorSymbol]) {
  11065. return iteratorToArray(value[iteratorSymbol]());
  11066. }
  11067. var tag = getTag(value),
  11068. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11069. return func(value);
  11070. }
  11071. /**
  11072. * Converts `value` to a finite number.
  11073. *
  11074. * @static
  11075. * @memberOf _
  11076. * @since 4.12.0
  11077. * @category Lang
  11078. * @param {*} value The value to convert.
  11079. * @returns {number} Returns the converted number.
  11080. * @example
  11081. *
  11082. * _.toFinite(3.2);
  11083. * // => 3.2
  11084. *
  11085. * _.toFinite(Number.MIN_VALUE);
  11086. * // => 5e-324
  11087. *
  11088. * _.toFinite(Infinity);
  11089. * // => 1.7976931348623157e+308
  11090. *
  11091. * _.toFinite('3.2');
  11092. * // => 3.2
  11093. */
  11094. function toFinite(value) {
  11095. if (!value) {
  11096. return value === 0 ? value : 0;
  11097. }
  11098. value = toNumber(value);
  11099. if (value === INFINITY || value === -INFINITY) {
  11100. var sign = (value < 0 ? -1 : 1);
  11101. return sign * MAX_INTEGER;
  11102. }
  11103. return value === value ? value : 0;
  11104. }
  11105. /**
  11106. * Converts `value` to an integer.
  11107. *
  11108. * **Note:** This method is loosely based on
  11109. * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
  11110. *
  11111. * @static
  11112. * @memberOf _
  11113. * @since 4.0.0
  11114. * @category Lang
  11115. * @param {*} value The value to convert.
  11116. * @returns {number} Returns the converted integer.
  11117. * @example
  11118. *
  11119. * _.toInteger(3.2);
  11120. * // => 3
  11121. *
  11122. * _.toInteger(Number.MIN_VALUE);
  11123. * // => 0
  11124. *
  11125. * _.toInteger(Infinity);
  11126. * // => 1.7976931348623157e+308
  11127. *
  11128. * _.toInteger('3.2');
  11129. * // => 3
  11130. */
  11131. function toInteger(value) {
  11132. var result = toFinite(value),
  11133. remainder = result % 1;
  11134. return result === result ? (remainder ? result - remainder : result) : 0;
  11135. }
  11136. /**
  11137. * Converts `value` to an integer suitable for use as the length of an
  11138. * array-like object.
  11139. *
  11140. * **Note:** This method is based on
  11141. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  11142. *
  11143. * @static
  11144. * @memberOf _
  11145. * @since 4.0.0
  11146. * @category Lang
  11147. * @param {*} value The value to convert.
  11148. * @returns {number} Returns the converted integer.
  11149. * @example
  11150. *
  11151. * _.toLength(3.2);
  11152. * // => 3
  11153. *
  11154. * _.toLength(Number.MIN_VALUE);
  11155. * // => 0
  11156. *
  11157. * _.toLength(Infinity);
  11158. * // => 4294967295
  11159. *
  11160. * _.toLength('3.2');
  11161. * // => 3
  11162. */
  11163. function toLength(value) {
  11164. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11165. }
  11166. /**
  11167. * Converts `value` to a number.
  11168. *
  11169. * @static
  11170. * @memberOf _
  11171. * @since 4.0.0
  11172. * @category Lang
  11173. * @param {*} value The value to process.
  11174. * @returns {number} Returns the number.
  11175. * @example
  11176. *
  11177. * _.toNumber(3.2);
  11178. * // => 3.2
  11179. *
  11180. * _.toNumber(Number.MIN_VALUE);
  11181. * // => 5e-324
  11182. *
  11183. * _.toNumber(Infinity);
  11184. * // => Infinity
  11185. *
  11186. * _.toNumber('3.2');
  11187. * // => 3.2
  11188. */
  11189. function toNumber(value) {
  11190. if (typeof value == 'number') {
  11191. return value;
  11192. }
  11193. if (isSymbol(value)) {
  11194. return NAN;
  11195. }
  11196. if (isObject(value)) {
  11197. var other = isFunction(value.valueOf) ? value.valueOf() : value;
  11198. value = isObject(other) ? (other + '') : other;
  11199. }
  11200. if (typeof value != 'string') {
  11201. return value === 0 ? value : +value;
  11202. }
  11203. value = value.replace(reTrim, '');
  11204. var isBinary = reIsBinary.test(value);
  11205. return (isBinary || reIsOctal.test(value))
  11206. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11207. : (reIsBadHex.test(value) ? NAN : +value);
  11208. }
  11209. /**
  11210. * Converts `value` to a plain object flattening inherited enumerable string
  11211. * keyed properties of `value` to own properties of the plain object.
  11212. *
  11213. * @static
  11214. * @memberOf _
  11215. * @since 3.0.0
  11216. * @category Lang
  11217. * @param {*} value The value to convert.
  11218. * @returns {Object} Returns the converted plain object.
  11219. * @example
  11220. *
  11221. * function Foo() {
  11222. * this.b = 2;
  11223. * }
  11224. *
  11225. * Foo.prototype.c = 3;
  11226. *
  11227. * _.assign({ 'a': 1 }, new Foo);
  11228. * // => { 'a': 1, 'b': 2 }
  11229. *
  11230. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11231. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11232. */
  11233. function toPlainObject(value) {
  11234. return copyObject(value, keysIn(value));
  11235. }
  11236. /**
  11237. * Converts `value` to a safe integer. A safe integer can be compared and
  11238. * represented correctly.
  11239. *
  11240. * @static
  11241. * @memberOf _
  11242. * @since 4.0.0
  11243. * @category Lang
  11244. * @param {*} value The value to convert.
  11245. * @returns {number} Returns the converted integer.
  11246. * @example
  11247. *
  11248. * _.toSafeInteger(3.2);
  11249. * // => 3
  11250. *
  11251. * _.toSafeInteger(Number.MIN_VALUE);
  11252. * // => 0
  11253. *
  11254. * _.toSafeInteger(Infinity);
  11255. * // => 9007199254740991
  11256. *
  11257. * _.toSafeInteger('3.2');
  11258. * // => 3
  11259. */
  11260. function toSafeInteger(value) {
  11261. return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
  11262. }
  11263. /**
  11264. * Converts `value` to a string. An empty string is returned for `null`
  11265. * and `undefined` values. The sign of `-0` is preserved.
  11266. *
  11267. * @static
  11268. * @memberOf _
  11269. * @since 4.0.0
  11270. * @category Lang
  11271. * @param {*} value The value to process.
  11272. * @returns {string} Returns the string.
  11273. * @example
  11274. *
  11275. * _.toString(null);
  11276. * // => ''
  11277. *
  11278. * _.toString(-0);
  11279. * // => '-0'
  11280. *
  11281. * _.toString([1, 2, 3]);
  11282. * // => '1,2,3'
  11283. */
  11284. function toString(value) {
  11285. return value == null ? '' : baseToString(value);
  11286. }
  11287. /*------------------------------------------------------------------------*/
  11288. /**
  11289. * Assigns own enumerable string keyed properties of source objects to the
  11290. * destination object. Source objects are applied from left to right.
  11291. * Subsequent sources overwrite property assignments of previous sources.
  11292. *
  11293. * **Note:** This method mutates `object` and is loosely based on
  11294. * [`Object.assign`](https://mdn.io/Object/assign).
  11295. *
  11296. * @static
  11297. * @memberOf _
  11298. * @since 0.10.0
  11299. * @category Object
  11300. * @param {Object} object The destination object.
  11301. * @param {...Object} [sources] The source objects.
  11302. * @returns {Object} Returns `object`.
  11303. * @see _.assignIn
  11304. * @example
  11305. *
  11306. * function Foo() {
  11307. * this.a = 1;
  11308. * }
  11309. *
  11310. * function Bar() {
  11311. * this.c = 3;
  11312. * }
  11313. *
  11314. * Foo.prototype.b = 2;
  11315. * Bar.prototype.d = 4;
  11316. *
  11317. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11318. * // => { 'a': 1, 'c': 3 }
  11319. */
  11320. var assign = createAssigner(function(object, source) {
  11321. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  11322. copyObject(source, keys(source), object);
  11323. return;
  11324. }
  11325. for (var key in source) {
  11326. if (hasOwnProperty.call(source, key)) {
  11327. assignValue(object, key, source[key]);
  11328. }
  11329. }
  11330. });
  11331. /**
  11332. * This method is like `_.assign` except that it iterates over own and
  11333. * inherited source properties.
  11334. *
  11335. * **Note:** This method mutates `object`.
  11336. *
  11337. * @static
  11338. * @memberOf _
  11339. * @since 4.0.0
  11340. * @alias extend
  11341. * @category Object
  11342. * @param {Object} object The destination object.
  11343. * @param {...Object} [sources] The source objects.
  11344. * @returns {Object} Returns `object`.
  11345. * @see _.assign
  11346. * @example
  11347. *
  11348. * function Foo() {
  11349. * this.a = 1;
  11350. * }
  11351. *
  11352. * function Bar() {
  11353. * this.c = 3;
  11354. * }
  11355. *
  11356. * Foo.prototype.b = 2;
  11357. * Bar.prototype.d = 4;
  11358. *
  11359. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11360. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11361. */
  11362. var assignIn = createAssigner(function(object, source) {
  11363. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  11364. copyObject(source, keysIn(source), object);
  11365. return;
  11366. }
  11367. for (var key in source) {
  11368. assignValue(object, key, source[key]);
  11369. }
  11370. });
  11371. /**
  11372. * This method is like `_.assignIn` except that it accepts `customizer`
  11373. * which is invoked to produce the assigned values. If `customizer` returns
  11374. * `undefined`, assignment is handled by the method instead. The `customizer`
  11375. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11376. *
  11377. * **Note:** This method mutates `object`.
  11378. *
  11379. * @static
  11380. * @memberOf _
  11381. * @since 4.0.0
  11382. * @alias extendWith
  11383. * @category Object
  11384. * @param {Object} object The destination object.
  11385. * @param {...Object} sources The source objects.
  11386. * @param {Function} [customizer] The function to customize assigned values.
  11387. * @returns {Object} Returns `object`.
  11388. * @see _.assignWith
  11389. * @example
  11390. *
  11391. * function customizer(objValue, srcValue) {
  11392. * return _.isUndefined(objValue) ? srcValue : objValue;
  11393. * }
  11394. *
  11395. * var defaults = _.partialRight(_.assignInWith, customizer);
  11396. *
  11397. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11398. * // => { 'a': 1, 'b': 2 }
  11399. */
  11400. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11401. copyObject(source, keysIn(source), object, customizer);
  11402. });
  11403. /**
  11404. * This method is like `_.assign` except that it accepts `customizer`
  11405. * which is invoked to produce the assigned values. If `customizer` returns
  11406. * `undefined`, assignment is handled by the method instead. The `customizer`
  11407. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11408. *
  11409. * **Note:** This method mutates `object`.
  11410. *
  11411. * @static
  11412. * @memberOf _
  11413. * @since 4.0.0
  11414. * @category Object
  11415. * @param {Object} object The destination object.
  11416. * @param {...Object} sources The source objects.
  11417. * @param {Function} [customizer] The function to customize assigned values.
  11418. * @returns {Object} Returns `object`.
  11419. * @see _.assignInWith
  11420. * @example
  11421. *
  11422. * function customizer(objValue, srcValue) {
  11423. * return _.isUndefined(objValue) ? srcValue : objValue;
  11424. * }
  11425. *
  11426. * var defaults = _.partialRight(_.assignWith, customizer);
  11427. *
  11428. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11429. * // => { 'a': 1, 'b': 2 }
  11430. */
  11431. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11432. copyObject(source, keys(source), object, customizer);
  11433. });
  11434. /**
  11435. * Creates an array of values corresponding to `paths` of `object`.
  11436. *
  11437. * @static
  11438. * @memberOf _
  11439. * @since 1.0.0
  11440. * @category Object
  11441. * @param {Object} object The object to iterate over.
  11442. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  11443. * @returns {Array} Returns the picked values.
  11444. * @example
  11445. *
  11446. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11447. *
  11448. * _.at(object, ['a[0].b.c', 'a[1]']);
  11449. * // => [3, 4]
  11450. */
  11451. var at = baseRest(function(object, paths) {
  11452. return baseAt(object, baseFlatten(paths, 1));
  11453. });
  11454. /**
  11455. * Creates an object that inherits from the `prototype` object. If a
  11456. * `properties` object is given, its own enumerable string keyed properties
  11457. * are assigned to the created object.
  11458. *
  11459. * @static
  11460. * @memberOf _
  11461. * @since 2.3.0
  11462. * @category Object
  11463. * @param {Object} prototype The object to inherit from.
  11464. * @param {Object} [properties] The properties to assign to the object.
  11465. * @returns {Object} Returns the new object.
  11466. * @example
  11467. *
  11468. * function Shape() {
  11469. * this.x = 0;
  11470. * this.y = 0;
  11471. * }
  11472. *
  11473. * function Circle() {
  11474. * Shape.call(this);
  11475. * }
  11476. *
  11477. * Circle.prototype = _.create(Shape.prototype, {
  11478. * 'constructor': Circle
  11479. * });
  11480. *
  11481. * var circle = new Circle;
  11482. * circle instanceof Circle;
  11483. * // => true
  11484. *
  11485. * circle instanceof Shape;
  11486. * // => true
  11487. */
  11488. function create(prototype, properties) {
  11489. var result = baseCreate(prototype);
  11490. return properties ? baseAssign(result, properties) : result;
  11491. }
  11492. /**
  11493. * Assigns own and inherited enumerable string keyed properties of source
  11494. * objects to the destination object for all destination properties that
  11495. * resolve to `undefined`. Source objects are applied from left to right.
  11496. * Once a property is set, additional values of the same property are ignored.
  11497. *
  11498. * **Note:** This method mutates `object`.
  11499. *
  11500. * @static
  11501. * @since 0.1.0
  11502. * @memberOf _
  11503. * @category Object
  11504. * @param {Object} object The destination object.
  11505. * @param {...Object} [sources] The source objects.
  11506. * @returns {Object} Returns `object`.
  11507. * @see _.defaultsDeep
  11508. * @example
  11509. *
  11510. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11511. * // => { 'a': 1, 'b': 2 }
  11512. */
  11513. var defaults = baseRest(function(args) {
  11514. args.push(undefined, assignInDefaults);
  11515. return apply(assignInWith, undefined, args);
  11516. });
  11517. /**
  11518. * This method is like `_.defaults` except that it recursively assigns
  11519. * default properties.
  11520. *
  11521. * **Note:** This method mutates `object`.
  11522. *
  11523. * @static
  11524. * @memberOf _
  11525. * @since 3.10.0
  11526. * @category Object
  11527. * @param {Object} object The destination object.
  11528. * @param {...Object} [sources] The source objects.
  11529. * @returns {Object} Returns `object`.
  11530. * @see _.defaults
  11531. * @example
  11532. *
  11533. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11534. * // => { 'a': { 'b': 2, 'c': 3 } }
  11535. */
  11536. var defaultsDeep = baseRest(function(args) {
  11537. args.push(undefined, mergeDefaults);
  11538. return apply(mergeWith, undefined, args);
  11539. });
  11540. /**
  11541. * This method is like `_.find` except that it returns the key of the first
  11542. * element `predicate` returns truthy for instead of the element itself.
  11543. *
  11544. * @static
  11545. * @memberOf _
  11546. * @since 1.1.0
  11547. * @category Object
  11548. * @param {Object} object The object to search.
  11549. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11550. * @returns {string|undefined} Returns the key of the matched element,
  11551. * else `undefined`.
  11552. * @example
  11553. *
  11554. * var users = {
  11555. * 'barney': { 'age': 36, 'active': true },
  11556. * 'fred': { 'age': 40, 'active': false },
  11557. * 'pebbles': { 'age': 1, 'active': true }
  11558. * };
  11559. *
  11560. * _.findKey(users, function(o) { return o.age < 40; });
  11561. * // => 'barney' (iteration order is not guaranteed)
  11562. *
  11563. * // The `_.matches` iteratee shorthand.
  11564. * _.findKey(users, { 'age': 1, 'active': true });
  11565. * // => 'pebbles'
  11566. *
  11567. * // The `_.matchesProperty` iteratee shorthand.
  11568. * _.findKey(users, ['active', false]);
  11569. * // => 'fred'
  11570. *
  11571. * // The `_.property` iteratee shorthand.
  11572. * _.findKey(users, 'active');
  11573. * // => 'barney'
  11574. */
  11575. function findKey(object, predicate) {
  11576. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  11577. }
  11578. /**
  11579. * This method is like `_.findKey` except that it iterates over elements of
  11580. * a collection in the opposite order.
  11581. *
  11582. * @static
  11583. * @memberOf _
  11584. * @since 2.0.0
  11585. * @category Object
  11586. * @param {Object} object The object to search.
  11587. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11588. * @returns {string|undefined} Returns the key of the matched element,
  11589. * else `undefined`.
  11590. * @example
  11591. *
  11592. * var users = {
  11593. * 'barney': { 'age': 36, 'active': true },
  11594. * 'fred': { 'age': 40, 'active': false },
  11595. * 'pebbles': { 'age': 1, 'active': true }
  11596. * };
  11597. *
  11598. * _.findLastKey(users, function(o) { return o.age < 40; });
  11599. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  11600. *
  11601. * // The `_.matches` iteratee shorthand.
  11602. * _.findLastKey(users, { 'age': 36, 'active': true });
  11603. * // => 'barney'
  11604. *
  11605. * // The `_.matchesProperty` iteratee shorthand.
  11606. * _.findLastKey(users, ['active', false]);
  11607. * // => 'fred'
  11608. *
  11609. * // The `_.property` iteratee shorthand.
  11610. * _.findLastKey(users, 'active');
  11611. * // => 'pebbles'
  11612. */
  11613. function findLastKey(object, predicate) {
  11614. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  11615. }
  11616. /**
  11617. * Iterates over own and inherited enumerable string keyed properties of an
  11618. * object and invokes `iteratee` for each property. The iteratee is invoked
  11619. * with three arguments: (value, key, object). Iteratee functions may exit
  11620. * iteration early by explicitly returning `false`.
  11621. *
  11622. * @static
  11623. * @memberOf _
  11624. * @since 0.3.0
  11625. * @category Object
  11626. * @param {Object} object The object to iterate over.
  11627. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11628. * @returns {Object} Returns `object`.
  11629. * @see _.forInRight
  11630. * @example
  11631. *
  11632. * function Foo() {
  11633. * this.a = 1;
  11634. * this.b = 2;
  11635. * }
  11636. *
  11637. * Foo.prototype.c = 3;
  11638. *
  11639. * _.forIn(new Foo, function(value, key) {
  11640. * console.log(key);
  11641. * });
  11642. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  11643. */
  11644. function forIn(object, iteratee) {
  11645. return object == null
  11646. ? object
  11647. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  11648. }
  11649. /**
  11650. * This method is like `_.forIn` except that it iterates over properties of
  11651. * `object` in the opposite order.
  11652. *
  11653. * @static
  11654. * @memberOf _
  11655. * @since 2.0.0
  11656. * @category Object
  11657. * @param {Object} object The object to iterate over.
  11658. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11659. * @returns {Object} Returns `object`.
  11660. * @see _.forIn
  11661. * @example
  11662. *
  11663. * function Foo() {
  11664. * this.a = 1;
  11665. * this.b = 2;
  11666. * }
  11667. *
  11668. * Foo.prototype.c = 3;
  11669. *
  11670. * _.forInRight(new Foo, function(value, key) {
  11671. * console.log(key);
  11672. * });
  11673. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  11674. */
  11675. function forInRight(object, iteratee) {
  11676. return object == null
  11677. ? object
  11678. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  11679. }
  11680. /**
  11681. * Iterates over own enumerable string keyed properties of an object and
  11682. * invokes `iteratee` for each property. The iteratee is invoked with three
  11683. * arguments: (value, key, object). Iteratee functions may exit iteration
  11684. * early by explicitly returning `false`.
  11685. *
  11686. * @static
  11687. * @memberOf _
  11688. * @since 0.3.0
  11689. * @category Object
  11690. * @param {Object} object The object to iterate over.
  11691. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11692. * @returns {Object} Returns `object`.
  11693. * @see _.forOwnRight
  11694. * @example
  11695. *
  11696. * function Foo() {
  11697. * this.a = 1;
  11698. * this.b = 2;
  11699. * }
  11700. *
  11701. * Foo.prototype.c = 3;
  11702. *
  11703. * _.forOwn(new Foo, function(value, key) {
  11704. * console.log(key);
  11705. * });
  11706. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  11707. */
  11708. function forOwn(object, iteratee) {
  11709. return object && baseForOwn(object, getIteratee(iteratee, 3));
  11710. }
  11711. /**
  11712. * This method is like `_.forOwn` except that it iterates over properties of
  11713. * `object` in the opposite order.
  11714. *
  11715. * @static
  11716. * @memberOf _
  11717. * @since 2.0.0
  11718. * @category Object
  11719. * @param {Object} object The object to iterate over.
  11720. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11721. * @returns {Object} Returns `object`.
  11722. * @see _.forOwn
  11723. * @example
  11724. *
  11725. * function Foo() {
  11726. * this.a = 1;
  11727. * this.b = 2;
  11728. * }
  11729. *
  11730. * Foo.prototype.c = 3;
  11731. *
  11732. * _.forOwnRight(new Foo, function(value, key) {
  11733. * console.log(key);
  11734. * });
  11735. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  11736. */
  11737. function forOwnRight(object, iteratee) {
  11738. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  11739. }
  11740. /**
  11741. * Creates an array of function property names from own enumerable properties
  11742. * of `object`.
  11743. *
  11744. * @static
  11745. * @since 0.1.0
  11746. * @memberOf _
  11747. * @category Object
  11748. * @param {Object} object The object to inspect.
  11749. * @returns {Array} Returns the function names.
  11750. * @see _.functionsIn
  11751. * @example
  11752. *
  11753. * function Foo() {
  11754. * this.a = _.constant('a');
  11755. * this.b = _.constant('b');
  11756. * }
  11757. *
  11758. * Foo.prototype.c = _.constant('c');
  11759. *
  11760. * _.functions(new Foo);
  11761. * // => ['a', 'b']
  11762. */
  11763. function functions(object) {
  11764. return object == null ? [] : baseFunctions(object, keys(object));
  11765. }
  11766. /**
  11767. * Creates an array of function property names from own and inherited
  11768. * enumerable properties of `object`.
  11769. *
  11770. * @static
  11771. * @memberOf _
  11772. * @since 4.0.0
  11773. * @category Object
  11774. * @param {Object} object The object to inspect.
  11775. * @returns {Array} Returns the function names.
  11776. * @see _.functions
  11777. * @example
  11778. *
  11779. * function Foo() {
  11780. * this.a = _.constant('a');
  11781. * this.b = _.constant('b');
  11782. * }
  11783. *
  11784. * Foo.prototype.c = _.constant('c');
  11785. *
  11786. * _.functionsIn(new Foo);
  11787. * // => ['a', 'b', 'c']
  11788. */
  11789. function functionsIn(object) {
  11790. return object == null ? [] : baseFunctions(object, keysIn(object));
  11791. }
  11792. /**
  11793. * Gets the value at `path` of `object`. If the resolved value is
  11794. * `undefined`, the `defaultValue` is returned in its place.
  11795. *
  11796. * @static
  11797. * @memberOf _
  11798. * @since 3.7.0
  11799. * @category Object
  11800. * @param {Object} object The object to query.
  11801. * @param {Array|string} path The path of the property to get.
  11802. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  11803. * @returns {*} Returns the resolved value.
  11804. * @example
  11805. *
  11806. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11807. *
  11808. * _.get(object, 'a[0].b.c');
  11809. * // => 3
  11810. *
  11811. * _.get(object, ['a', '0', 'b', 'c']);
  11812. * // => 3
  11813. *
  11814. * _.get(object, 'a.b.c', 'default');
  11815. * // => 'default'
  11816. */
  11817. function get(object, path, defaultValue) {
  11818. var result = object == null ? undefined : baseGet(object, path);
  11819. return result === undefined ? defaultValue : result;
  11820. }
  11821. /**
  11822. * Checks if `path` is a direct property of `object`.
  11823. *
  11824. * @static
  11825. * @since 0.1.0
  11826. * @memberOf _
  11827. * @category Object
  11828. * @param {Object} object The object to query.
  11829. * @param {Array|string} path The path to check.
  11830. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11831. * @example
  11832. *
  11833. * var object = { 'a': { 'b': 2 } };
  11834. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  11835. *
  11836. * _.has(object, 'a');
  11837. * // => true
  11838. *
  11839. * _.has(object, 'a.b');
  11840. * // => true
  11841. *
  11842. * _.has(object, ['a', 'b']);
  11843. * // => true
  11844. *
  11845. * _.has(other, 'a');
  11846. * // => false
  11847. */
  11848. function has(object, path) {
  11849. return object != null && hasPath(object, path, baseHas);
  11850. }
  11851. /**
  11852. * Checks if `path` is a direct or inherited property of `object`.
  11853. *
  11854. * @static
  11855. * @memberOf _
  11856. * @since 4.0.0
  11857. * @category Object
  11858. * @param {Object} object The object to query.
  11859. * @param {Array|string} path The path to check.
  11860. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11861. * @example
  11862. *
  11863. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  11864. *
  11865. * _.hasIn(object, 'a');
  11866. * // => true
  11867. *
  11868. * _.hasIn(object, 'a.b');
  11869. * // => true
  11870. *
  11871. * _.hasIn(object, ['a', 'b']);
  11872. * // => true
  11873. *
  11874. * _.hasIn(object, 'b');
  11875. * // => false
  11876. */
  11877. function hasIn(object, path) {
  11878. return object != null && hasPath(object, path, baseHasIn);
  11879. }
  11880. /**
  11881. * Creates an object composed of the inverted keys and values of `object`.
  11882. * If `object` contains duplicate values, subsequent values overwrite
  11883. * property assignments of previous values.
  11884. *
  11885. * @static
  11886. * @memberOf _
  11887. * @since 0.7.0
  11888. * @category Object
  11889. * @param {Object} object The object to invert.
  11890. * @returns {Object} Returns the new inverted object.
  11891. * @example
  11892. *
  11893. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  11894. *
  11895. * _.invert(object);
  11896. * // => { '1': 'c', '2': 'b' }
  11897. */
  11898. var invert = createInverter(function(result, value, key) {
  11899. result[value] = key;
  11900. }, constant(identity));
  11901. /**
  11902. * This method is like `_.invert` except that the inverted object is generated
  11903. * from the results of running each element of `object` thru `iteratee`. The
  11904. * corresponding inverted value of each inverted key is an array of keys
  11905. * responsible for generating the inverted value. The iteratee is invoked
  11906. * with one argument: (value).
  11907. *
  11908. * @static
  11909. * @memberOf _
  11910. * @since 4.1.0
  11911. * @category Object
  11912. * @param {Object} object The object to invert.
  11913. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  11914. * @returns {Object} Returns the new inverted object.
  11915. * @example
  11916. *
  11917. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  11918. *
  11919. * _.invertBy(object);
  11920. * // => { '1': ['a', 'c'], '2': ['b'] }
  11921. *
  11922. * _.invertBy(object, function(value) {
  11923. * return 'group' + value;
  11924. * });
  11925. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  11926. */
  11927. var invertBy = createInverter(function(result, value, key) {
  11928. if (hasOwnProperty.call(result, value)) {
  11929. result[value].push(key);
  11930. } else {
  11931. result[value] = [key];
  11932. }
  11933. }, getIteratee);
  11934. /**
  11935. * Invokes the method at `path` of `object`.
  11936. *
  11937. * @static
  11938. * @memberOf _
  11939. * @since 4.0.0
  11940. * @category Object
  11941. * @param {Object} object The object to query.
  11942. * @param {Array|string} path The path of the method to invoke.
  11943. * @param {...*} [args] The arguments to invoke the method with.
  11944. * @returns {*} Returns the result of the invoked method.
  11945. * @example
  11946. *
  11947. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  11948. *
  11949. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  11950. * // => [2, 3]
  11951. */
  11952. var invoke = baseRest(baseInvoke);
  11953. /**
  11954. * Creates an array of the own enumerable property names of `object`.
  11955. *
  11956. * **Note:** Non-object values are coerced to objects. See the
  11957. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  11958. * for more details.
  11959. *
  11960. * @static
  11961. * @since 0.1.0
  11962. * @memberOf _
  11963. * @category Object
  11964. * @param {Object} object The object to query.
  11965. * @returns {Array} Returns the array of property names.
  11966. * @example
  11967. *
  11968. * function Foo() {
  11969. * this.a = 1;
  11970. * this.b = 2;
  11971. * }
  11972. *
  11973. * Foo.prototype.c = 3;
  11974. *
  11975. * _.keys(new Foo);
  11976. * // => ['a', 'b'] (iteration order is not guaranteed)
  11977. *
  11978. * _.keys('hi');
  11979. * // => ['0', '1']
  11980. */
  11981. function keys(object) {
  11982. var isProto = isPrototype(object);
  11983. if (!(isProto || isArrayLike(object))) {
  11984. return baseKeys(object);
  11985. }
  11986. var indexes = indexKeys(object),
  11987. skipIndexes = !!indexes,
  11988. result = indexes || [],
  11989. length = result.length;
  11990. for (var key in object) {
  11991. if (baseHas(object, key) &&
  11992. !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  11993. !(isProto && key == 'constructor')) {
  11994. result.push(key);
  11995. }
  11996. }
  11997. return result;
  11998. }
  11999. /**
  12000. * Creates an array of the own and inherited enumerable property names of `object`.
  12001. *
  12002. * **Note:** Non-object values are coerced to objects.
  12003. *
  12004. * @static
  12005. * @memberOf _
  12006. * @since 3.0.0
  12007. * @category Object
  12008. * @param {Object} object The object to query.
  12009. * @returns {Array} Returns the array of property names.
  12010. * @example
  12011. *
  12012. * function Foo() {
  12013. * this.a = 1;
  12014. * this.b = 2;
  12015. * }
  12016. *
  12017. * Foo.prototype.c = 3;
  12018. *
  12019. * _.keysIn(new Foo);
  12020. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12021. */
  12022. function keysIn(object) {
  12023. var index = -1,
  12024. isProto = isPrototype(object),
  12025. props = baseKeysIn(object),
  12026. propsLength = props.length,
  12027. indexes = indexKeys(object),
  12028. skipIndexes = !!indexes,
  12029. result = indexes || [],
  12030. length = result.length;
  12031. while (++index < propsLength) {
  12032. var key = props[index];
  12033. if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
  12034. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  12035. result.push(key);
  12036. }
  12037. }
  12038. return result;
  12039. }
  12040. /**
  12041. * The opposite of `_.mapValues`; this method creates an object with the
  12042. * same values as `object` and keys generated by running each own enumerable
  12043. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12044. * with three arguments: (value, key, object).
  12045. *
  12046. * @static
  12047. * @memberOf _
  12048. * @since 3.8.0
  12049. * @category Object
  12050. * @param {Object} object The object to iterate over.
  12051. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12052. * @returns {Object} Returns the new mapped object.
  12053. * @see _.mapValues
  12054. * @example
  12055. *
  12056. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12057. * return key + value;
  12058. * });
  12059. * // => { 'a1': 1, 'b2': 2 }
  12060. */
  12061. function mapKeys(object, iteratee) {
  12062. var result = {};
  12063. iteratee = getIteratee(iteratee, 3);
  12064. baseForOwn(object, function(value, key, object) {
  12065. result[iteratee(value, key, object)] = value;
  12066. });
  12067. return result;
  12068. }
  12069. /**
  12070. * Creates an object with the same keys as `object` and values generated
  12071. * by running each own enumerable string keyed property of `object` thru
  12072. * `iteratee`. The iteratee is invoked with three arguments:
  12073. * (value, key, object).
  12074. *
  12075. * @static
  12076. * @memberOf _
  12077. * @since 2.4.0
  12078. * @category Object
  12079. * @param {Object} object The object to iterate over.
  12080. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12081. * @returns {Object} Returns the new mapped object.
  12082. * @see _.mapKeys
  12083. * @example
  12084. *
  12085. * var users = {
  12086. * 'fred': { 'user': 'fred', 'age': 40 },
  12087. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12088. * };
  12089. *
  12090. * _.mapValues(users, function(o) { return o.age; });
  12091. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12092. *
  12093. * // The `_.property` iteratee shorthand.
  12094. * _.mapValues(users, 'age');
  12095. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12096. */
  12097. function mapValues(object, iteratee) {
  12098. var result = {};
  12099. iteratee = getIteratee(iteratee, 3);
  12100. baseForOwn(object, function(value, key, object) {
  12101. result[key] = iteratee(value, key, object);
  12102. });
  12103. return result;
  12104. }
  12105. /**
  12106. * This method is like `_.assign` except that it recursively merges own and
  12107. * inherited enumerable string keyed properties of source objects into the
  12108. * destination object. Source properties that resolve to `undefined` are
  12109. * skipped if a destination value exists. Array and plain object properties
  12110. * are merged recursively. Other objects and value types are overridden by
  12111. * assignment. Source objects are applied from left to right. Subsequent
  12112. * sources overwrite property assignments of previous sources.
  12113. *
  12114. * **Note:** This method mutates `object`.
  12115. *
  12116. * @static
  12117. * @memberOf _
  12118. * @since 0.5.0
  12119. * @category Object
  12120. * @param {Object} object The destination object.
  12121. * @param {...Object} [sources] The source objects.
  12122. * @returns {Object} Returns `object`.
  12123. * @example
  12124. *
  12125. * var object = {
  12126. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12127. * };
  12128. *
  12129. * var other = {
  12130. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12131. * };
  12132. *
  12133. * _.merge(object, other);
  12134. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12135. */
  12136. var merge = createAssigner(function(object, source, srcIndex) {
  12137. baseMerge(object, source, srcIndex);
  12138. });
  12139. /**
  12140. * This method is like `_.merge` except that it accepts `customizer` which
  12141. * is invoked to produce the merged values of the destination and source
  12142. * properties. If `customizer` returns `undefined`, merging is handled by the
  12143. * method instead. The `customizer` is invoked with seven arguments:
  12144. * (objValue, srcValue, key, object, source, stack).
  12145. *
  12146. * **Note:** This method mutates `object`.
  12147. *
  12148. * @static
  12149. * @memberOf _
  12150. * @since 4.0.0
  12151. * @category Object
  12152. * @param {Object} object The destination object.
  12153. * @param {...Object} sources The source objects.
  12154. * @param {Function} customizer The function to customize assigned values.
  12155. * @returns {Object} Returns `object`.
  12156. * @example
  12157. *
  12158. * function customizer(objValue, srcValue) {
  12159. * if (_.isArray(objValue)) {
  12160. * return objValue.concat(srcValue);
  12161. * }
  12162. * }
  12163. *
  12164. * var object = { 'a': [1], 'b': [2] };
  12165. * var other = { 'a': [3], 'b': [4] };
  12166. *
  12167. * _.mergeWith(object, other, customizer);
  12168. * // => { 'a': [1, 3], 'b': [2, 4] }
  12169. */
  12170. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12171. baseMerge(object, source, srcIndex, customizer);
  12172. });
  12173. /**
  12174. * The opposite of `_.pick`; this method creates an object composed of the
  12175. * own and inherited enumerable string keyed properties of `object` that are
  12176. * not omitted.
  12177. *
  12178. * @static
  12179. * @since 0.1.0
  12180. * @memberOf _
  12181. * @category Object
  12182. * @param {Object} object The source object.
  12183. * @param {...(string|string[])} [props] The property identifiers to omit.
  12184. * @returns {Object} Returns the new object.
  12185. * @example
  12186. *
  12187. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12188. *
  12189. * _.omit(object, ['a', 'c']);
  12190. * // => { 'b': '2' }
  12191. */
  12192. var omit = baseRest(function(object, props) {
  12193. if (object == null) {
  12194. return {};
  12195. }
  12196. props = arrayMap(baseFlatten(props, 1), toKey);
  12197. return basePick(object, baseDifference(getAllKeysIn(object), props));
  12198. });
  12199. /**
  12200. * The opposite of `_.pickBy`; this method creates an object composed of
  12201. * the own and inherited enumerable string keyed properties of `object` that
  12202. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12203. * arguments: (value, key).
  12204. *
  12205. * @static
  12206. * @memberOf _
  12207. * @since 4.0.0
  12208. * @category Object
  12209. * @param {Object} object The source object.
  12210. * @param {Function} [predicate=_.identity] The function invoked per property.
  12211. * @returns {Object} Returns the new object.
  12212. * @example
  12213. *
  12214. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12215. *
  12216. * _.omitBy(object, _.isNumber);
  12217. * // => { 'b': '2' }
  12218. */
  12219. function omitBy(object, predicate) {
  12220. return pickBy(object, negate(getIteratee(predicate)));
  12221. }
  12222. /**
  12223. * Creates an object composed of the picked `object` properties.
  12224. *
  12225. * @static
  12226. * @since 0.1.0
  12227. * @memberOf _
  12228. * @category Object
  12229. * @param {Object} object The source object.
  12230. * @param {...(string|string[])} [props] The property identifiers to pick.
  12231. * @returns {Object} Returns the new object.
  12232. * @example
  12233. *
  12234. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12235. *
  12236. * _.pick(object, ['a', 'c']);
  12237. * // => { 'a': 1, 'c': 3 }
  12238. */
  12239. var pick = baseRest(function(object, props) {
  12240. return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
  12241. });
  12242. /**
  12243. * Creates an object composed of the `object` properties `predicate` returns
  12244. * truthy for. The predicate is invoked with two arguments: (value, key).
  12245. *
  12246. * @static
  12247. * @memberOf _
  12248. * @since 4.0.0
  12249. * @category Object
  12250. * @param {Object} object The source object.
  12251. * @param {Function} [predicate=_.identity] The function invoked per property.
  12252. * @returns {Object} Returns the new object.
  12253. * @example
  12254. *
  12255. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12256. *
  12257. * _.pickBy(object, _.isNumber);
  12258. * // => { 'a': 1, 'c': 3 }
  12259. */
  12260. function pickBy(object, predicate) {
  12261. return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate));
  12262. }
  12263. /**
  12264. * This method is like `_.get` except that if the resolved value is a
  12265. * function it's invoked with the `this` binding of its parent object and
  12266. * its result is returned.
  12267. *
  12268. * @static
  12269. * @since 0.1.0
  12270. * @memberOf _
  12271. * @category Object
  12272. * @param {Object} object The object to query.
  12273. * @param {Array|string} path The path of the property to resolve.
  12274. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12275. * @returns {*} Returns the resolved value.
  12276. * @example
  12277. *
  12278. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12279. *
  12280. * _.result(object, 'a[0].b.c1');
  12281. * // => 3
  12282. *
  12283. * _.result(object, 'a[0].b.c2');
  12284. * // => 4
  12285. *
  12286. * _.result(object, 'a[0].b.c3', 'default');
  12287. * // => 'default'
  12288. *
  12289. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12290. * // => 'default'
  12291. */
  12292. function result(object, path, defaultValue) {
  12293. path = isKey(path, object) ? [path] : castPath(path);
  12294. var index = -1,
  12295. length = path.length;
  12296. // Ensure the loop is entered when path is empty.
  12297. if (!length) {
  12298. object = undefined;
  12299. length = 1;
  12300. }
  12301. while (++index < length) {
  12302. var value = object == null ? undefined : object[toKey(path[index])];
  12303. if (value === undefined) {
  12304. index = length;
  12305. value = defaultValue;
  12306. }
  12307. object = isFunction(value) ? value.call(object) : value;
  12308. }
  12309. return object;
  12310. }
  12311. /**
  12312. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12313. * it's created. Arrays are created for missing index properties while objects
  12314. * are created for all other missing properties. Use `_.setWith` to customize
  12315. * `path` creation.
  12316. *
  12317. * **Note:** This method mutates `object`.
  12318. *
  12319. * @static
  12320. * @memberOf _
  12321. * @since 3.7.0
  12322. * @category Object
  12323. * @param {Object} object The object to modify.
  12324. * @param {Array|string} path The path of the property to set.
  12325. * @param {*} value The value to set.
  12326. * @returns {Object} Returns `object`.
  12327. * @example
  12328. *
  12329. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12330. *
  12331. * _.set(object, 'a[0].b.c', 4);
  12332. * console.log(object.a[0].b.c);
  12333. * // => 4
  12334. *
  12335. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12336. * console.log(object.x[0].y.z);
  12337. * // => 5
  12338. */
  12339. function set(object, path, value) {
  12340. return object == null ? object : baseSet(object, path, value);
  12341. }
  12342. /**
  12343. * This method is like `_.set` except that it accepts `customizer` which is
  12344. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12345. * path creation is handled by the method instead. The `customizer` is invoked
  12346. * with three arguments: (nsValue, key, nsObject).
  12347. *
  12348. * **Note:** This method mutates `object`.
  12349. *
  12350. * @static
  12351. * @memberOf _
  12352. * @since 4.0.0
  12353. * @category Object
  12354. * @param {Object} object The object to modify.
  12355. * @param {Array|string} path The path of the property to set.
  12356. * @param {*} value The value to set.
  12357. * @param {Function} [customizer] The function to customize assigned values.
  12358. * @returns {Object} Returns `object`.
  12359. * @example
  12360. *
  12361. * var object = {};
  12362. *
  12363. * _.setWith(object, '[0][1]', 'a', Object);
  12364. * // => { '0': { '1': 'a' } }
  12365. */
  12366. function setWith(object, path, value, customizer) {
  12367. customizer = typeof customizer == 'function' ? customizer : undefined;
  12368. return object == null ? object : baseSet(object, path, value, customizer);
  12369. }
  12370. /**
  12371. * Creates an array of own enumerable string keyed-value pairs for `object`
  12372. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12373. * entries are returned.
  12374. *
  12375. * @static
  12376. * @memberOf _
  12377. * @since 4.0.0
  12378. * @alias entries
  12379. * @category Object
  12380. * @param {Object} object The object to query.
  12381. * @returns {Array} Returns the key-value pairs.
  12382. * @example
  12383. *
  12384. * function Foo() {
  12385. * this.a = 1;
  12386. * this.b = 2;
  12387. * }
  12388. *
  12389. * Foo.prototype.c = 3;
  12390. *
  12391. * _.toPairs(new Foo);
  12392. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12393. */
  12394. var toPairs = createToPairs(keys);
  12395. /**
  12396. * Creates an array of own and inherited enumerable string keyed-value pairs
  12397. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12398. * or set, its entries are returned.
  12399. *
  12400. * @static
  12401. * @memberOf _
  12402. * @since 4.0.0
  12403. * @alias entriesIn
  12404. * @category Object
  12405. * @param {Object} object The object to query.
  12406. * @returns {Array} Returns the key-value pairs.
  12407. * @example
  12408. *
  12409. * function Foo() {
  12410. * this.a = 1;
  12411. * this.b = 2;
  12412. * }
  12413. *
  12414. * Foo.prototype.c = 3;
  12415. *
  12416. * _.toPairsIn(new Foo);
  12417. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12418. */
  12419. var toPairsIn = createToPairs(keysIn);
  12420. /**
  12421. * An alternative to `_.reduce`; this method transforms `object` to a new
  12422. * `accumulator` object which is the result of running each of its own
  12423. * enumerable string keyed properties thru `iteratee`, with each invocation
  12424. * potentially mutating the `accumulator` object. If `accumulator` is not
  12425. * provided, a new object with the same `[[Prototype]]` will be used. The
  12426. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12427. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12428. *
  12429. * @static
  12430. * @memberOf _
  12431. * @since 1.3.0
  12432. * @category Object
  12433. * @param {Object} object The object to iterate over.
  12434. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12435. * @param {*} [accumulator] The custom accumulator value.
  12436. * @returns {*} Returns the accumulated value.
  12437. * @example
  12438. *
  12439. * _.transform([2, 3, 4], function(result, n) {
  12440. * result.push(n *= n);
  12441. * return n % 2 == 0;
  12442. * }, []);
  12443. * // => [4, 9]
  12444. *
  12445. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12446. * (result[value] || (result[value] = [])).push(key);
  12447. * }, {});
  12448. * // => { '1': ['a', 'c'], '2': ['b'] }
  12449. */
  12450. function transform(object, iteratee, accumulator) {
  12451. var isArr = isArray(object) || isTypedArray(object);
  12452. iteratee = getIteratee(iteratee, 4);
  12453. if (accumulator == null) {
  12454. if (isArr || isObject(object)) {
  12455. var Ctor = object.constructor;
  12456. if (isArr) {
  12457. accumulator = isArray(object) ? new Ctor : [];
  12458. } else {
  12459. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12460. }
  12461. } else {
  12462. accumulator = {};
  12463. }
  12464. }
  12465. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12466. return iteratee(accumulator, value, index, object);
  12467. });
  12468. return accumulator;
  12469. }
  12470. /**
  12471. * Removes the property at `path` of `object`.
  12472. *
  12473. * **Note:** This method mutates `object`.
  12474. *
  12475. * @static
  12476. * @memberOf _
  12477. * @since 4.0.0
  12478. * @category Object
  12479. * @param {Object} object The object to modify.
  12480. * @param {Array|string} path The path of the property to unset.
  12481. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12482. * @example
  12483. *
  12484. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12485. * _.unset(object, 'a[0].b.c');
  12486. * // => true
  12487. *
  12488. * console.log(object);
  12489. * // => { 'a': [{ 'b': {} }] };
  12490. *
  12491. * _.unset(object, ['a', '0', 'b', 'c']);
  12492. * // => true
  12493. *
  12494. * console.log(object);
  12495. * // => { 'a': [{ 'b': {} }] };
  12496. */
  12497. function unset(object, path) {
  12498. return object == null ? true : baseUnset(object, path);
  12499. }
  12500. /**
  12501. * This method is like `_.set` except that accepts `updater` to produce the
  12502. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12503. * is invoked with one argument: (value).
  12504. *
  12505. * **Note:** This method mutates `object`.
  12506. *
  12507. * @static
  12508. * @memberOf _
  12509. * @since 4.6.0
  12510. * @category Object
  12511. * @param {Object} object The object to modify.
  12512. * @param {Array|string} path The path of the property to set.
  12513. * @param {Function} updater The function to produce the updated value.
  12514. * @returns {Object} Returns `object`.
  12515. * @example
  12516. *
  12517. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12518. *
  12519. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12520. * console.log(object.a[0].b.c);
  12521. * // => 9
  12522. *
  12523. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12524. * console.log(object.x[0].y.z);
  12525. * // => 0
  12526. */
  12527. function update(object, path, updater) {
  12528. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12529. }
  12530. /**
  12531. * This method is like `_.update` except that it accepts `customizer` which is
  12532. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12533. * path creation is handled by the method instead. The `customizer` is invoked
  12534. * with three arguments: (nsValue, key, nsObject).
  12535. *
  12536. * **Note:** This method mutates `object`.
  12537. *
  12538. * @static
  12539. * @memberOf _
  12540. * @since 4.6.0
  12541. * @category Object
  12542. * @param {Object} object The object to modify.
  12543. * @param {Array|string} path The path of the property to set.
  12544. * @param {Function} updater The function to produce the updated value.
  12545. * @param {Function} [customizer] The function to customize assigned values.
  12546. * @returns {Object} Returns `object`.
  12547. * @example
  12548. *
  12549. * var object = {};
  12550. *
  12551. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  12552. * // => { '0': { '1': 'a' } }
  12553. */
  12554. function updateWith(object, path, updater, customizer) {
  12555. customizer = typeof customizer == 'function' ? customizer : undefined;
  12556. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  12557. }
  12558. /**
  12559. * Creates an array of the own enumerable string keyed property values of `object`.
  12560. *
  12561. * **Note:** Non-object values are coerced to objects.
  12562. *
  12563. * @static
  12564. * @since 0.1.0
  12565. * @memberOf _
  12566. * @category Object
  12567. * @param {Object} object The object to query.
  12568. * @returns {Array} Returns the array of property values.
  12569. * @example
  12570. *
  12571. * function Foo() {
  12572. * this.a = 1;
  12573. * this.b = 2;
  12574. * }
  12575. *
  12576. * Foo.prototype.c = 3;
  12577. *
  12578. * _.values(new Foo);
  12579. * // => [1, 2] (iteration order is not guaranteed)
  12580. *
  12581. * _.values('hi');
  12582. * // => ['h', 'i']
  12583. */
  12584. function values(object) {
  12585. return object ? baseValues(object, keys(object)) : [];
  12586. }
  12587. /**
  12588. * Creates an array of the own and inherited enumerable string keyed property
  12589. * values of `object`.
  12590. *
  12591. * **Note:** Non-object values are coerced to objects.
  12592. *
  12593. * @static
  12594. * @memberOf _
  12595. * @since 3.0.0
  12596. * @category Object
  12597. * @param {Object} object The object to query.
  12598. * @returns {Array} Returns the array of property values.
  12599. * @example
  12600. *
  12601. * function Foo() {
  12602. * this.a = 1;
  12603. * this.b = 2;
  12604. * }
  12605. *
  12606. * Foo.prototype.c = 3;
  12607. *
  12608. * _.valuesIn(new Foo);
  12609. * // => [1, 2, 3] (iteration order is not guaranteed)
  12610. */
  12611. function valuesIn(object) {
  12612. return object == null ? [] : baseValues(object, keysIn(object));
  12613. }
  12614. /*------------------------------------------------------------------------*/
  12615. /**
  12616. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  12617. *
  12618. * @static
  12619. * @memberOf _
  12620. * @since 4.0.0
  12621. * @category Number
  12622. * @param {number} number The number to clamp.
  12623. * @param {number} [lower] The lower bound.
  12624. * @param {number} upper The upper bound.
  12625. * @returns {number} Returns the clamped number.
  12626. * @example
  12627. *
  12628. * _.clamp(-10, -5, 5);
  12629. * // => -5
  12630. *
  12631. * _.clamp(10, -5, 5);
  12632. * // => 5
  12633. */
  12634. function clamp(number, lower, upper) {
  12635. if (upper === undefined) {
  12636. upper = lower;
  12637. lower = undefined;
  12638. }
  12639. if (upper !== undefined) {
  12640. upper = toNumber(upper);
  12641. upper = upper === upper ? upper : 0;
  12642. }
  12643. if (lower !== undefined) {
  12644. lower = toNumber(lower);
  12645. lower = lower === lower ? lower : 0;
  12646. }
  12647. return baseClamp(toNumber(number), lower, upper);
  12648. }
  12649. /**
  12650. * Checks if `n` is between `start` and up to, but not including, `end`. If
  12651. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  12652. * If `start` is greater than `end` the params are swapped to support
  12653. * negative ranges.
  12654. *
  12655. * @static
  12656. * @memberOf _
  12657. * @since 3.3.0
  12658. * @category Number
  12659. * @param {number} number The number to check.
  12660. * @param {number} [start=0] The start of the range.
  12661. * @param {number} end The end of the range.
  12662. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  12663. * @see _.range, _.rangeRight
  12664. * @example
  12665. *
  12666. * _.inRange(3, 2, 4);
  12667. * // => true
  12668. *
  12669. * _.inRange(4, 8);
  12670. * // => true
  12671. *
  12672. * _.inRange(4, 2);
  12673. * // => false
  12674. *
  12675. * _.inRange(2, 2);
  12676. * // => false
  12677. *
  12678. * _.inRange(1.2, 2);
  12679. * // => true
  12680. *
  12681. * _.inRange(5.2, 4);
  12682. * // => false
  12683. *
  12684. * _.inRange(-3, -2, -6);
  12685. * // => true
  12686. */
  12687. function inRange(number, start, end) {
  12688. start = toNumber(start) || 0;
  12689. if (end === undefined) {
  12690. end = start;
  12691. start = 0;
  12692. } else {
  12693. end = toNumber(end) || 0;
  12694. }
  12695. number = toNumber(number);
  12696. return baseInRange(number, start, end);
  12697. }
  12698. /**
  12699. * Produces a random number between the inclusive `lower` and `upper` bounds.
  12700. * If only one argument is provided a number between `0` and the given number
  12701. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  12702. * floats, a floating-point number is returned instead of an integer.
  12703. *
  12704. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  12705. * floating-point values which can produce unexpected results.
  12706. *
  12707. * @static
  12708. * @memberOf _
  12709. * @since 0.7.0
  12710. * @category Number
  12711. * @param {number} [lower=0] The lower bound.
  12712. * @param {number} [upper=1] The upper bound.
  12713. * @param {boolean} [floating] Specify returning a floating-point number.
  12714. * @returns {number} Returns the random number.
  12715. * @example
  12716. *
  12717. * _.random(0, 5);
  12718. * // => an integer between 0 and 5
  12719. *
  12720. * _.random(5);
  12721. * // => also an integer between 0 and 5
  12722. *
  12723. * _.random(5, true);
  12724. * // => a floating-point number between 0 and 5
  12725. *
  12726. * _.random(1.2, 5.2);
  12727. * // => a floating-point number between 1.2 and 5.2
  12728. */
  12729. function random(lower, upper, floating) {
  12730. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  12731. upper = floating = undefined;
  12732. }
  12733. if (floating === undefined) {
  12734. if (typeof upper == 'boolean') {
  12735. floating = upper;
  12736. upper = undefined;
  12737. }
  12738. else if (typeof lower == 'boolean') {
  12739. floating = lower;
  12740. lower = undefined;
  12741. }
  12742. }
  12743. if (lower === undefined && upper === undefined) {
  12744. lower = 0;
  12745. upper = 1;
  12746. }
  12747. else {
  12748. lower = toNumber(lower) || 0;
  12749. if (upper === undefined) {
  12750. upper = lower;
  12751. lower = 0;
  12752. } else {
  12753. upper = toNumber(upper) || 0;
  12754. }
  12755. }
  12756. if (lower > upper) {
  12757. var temp = lower;
  12758. lower = upper;
  12759. upper = temp;
  12760. }
  12761. if (floating || lower % 1 || upper % 1) {
  12762. var rand = nativeRandom();
  12763. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  12764. }
  12765. return baseRandom(lower, upper);
  12766. }
  12767. /*------------------------------------------------------------------------*/
  12768. /**
  12769. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  12770. *
  12771. * @static
  12772. * @memberOf _
  12773. * @since 3.0.0
  12774. * @category String
  12775. * @param {string} [string=''] The string to convert.
  12776. * @returns {string} Returns the camel cased string.
  12777. * @example
  12778. *
  12779. * _.camelCase('Foo Bar');
  12780. * // => 'fooBar'
  12781. *
  12782. * _.camelCase('--foo-bar--');
  12783. * // => 'fooBar'
  12784. *
  12785. * _.camelCase('__FOO_BAR__');
  12786. * // => 'fooBar'
  12787. */
  12788. var camelCase = createCompounder(function(result, word, index) {
  12789. word = word.toLowerCase();
  12790. return result + (index ? capitalize(word) : word);
  12791. });
  12792. /**
  12793. * Converts the first character of `string` to upper case and the remaining
  12794. * to lower case.
  12795. *
  12796. * @static
  12797. * @memberOf _
  12798. * @since 3.0.0
  12799. * @category String
  12800. * @param {string} [string=''] The string to capitalize.
  12801. * @returns {string} Returns the capitalized string.
  12802. * @example
  12803. *
  12804. * _.capitalize('FRED');
  12805. * // => 'Fred'
  12806. */
  12807. function capitalize(string) {
  12808. return upperFirst(toString(string).toLowerCase());
  12809. }
  12810. /**
  12811. * Deburrs `string` by converting
  12812. * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  12813. * to basic latin letters and removing
  12814. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  12815. *
  12816. * @static
  12817. * @memberOf _
  12818. * @since 3.0.0
  12819. * @category String
  12820. * @param {string} [string=''] The string to deburr.
  12821. * @returns {string} Returns the deburred string.
  12822. * @example
  12823. *
  12824. * _.deburr('déjà vu');
  12825. * // => 'deja vu'
  12826. */
  12827. function deburr(string) {
  12828. string = toString(string);
  12829. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  12830. }
  12831. /**
  12832. * Checks if `string` ends with the given target string.
  12833. *
  12834. * @static
  12835. * @memberOf _
  12836. * @since 3.0.0
  12837. * @category String
  12838. * @param {string} [string=''] The string to search.
  12839. * @param {string} [target] The string to search for.
  12840. * @param {number} [position=string.length] The position to search up to.
  12841. * @returns {boolean} Returns `true` if `string` ends with `target`,
  12842. * else `false`.
  12843. * @example
  12844. *
  12845. * _.endsWith('abc', 'c');
  12846. * // => true
  12847. *
  12848. * _.endsWith('abc', 'b');
  12849. * // => false
  12850. *
  12851. * _.endsWith('abc', 'b', 2);
  12852. * // => true
  12853. */
  12854. function endsWith(string, target, position) {
  12855. string = toString(string);
  12856. target = baseToString(target);
  12857. var length = string.length;
  12858. position = position === undefined
  12859. ? length
  12860. : baseClamp(toInteger(position), 0, length);
  12861. var end = position;
  12862. position -= target.length;
  12863. return position >= 0 && string.slice(position, end) == target;
  12864. }
  12865. /**
  12866. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  12867. * their corresponding HTML entities.
  12868. *
  12869. * **Note:** No other characters are escaped. To escape additional
  12870. * characters use a third-party library like [_he_](https://mths.be/he).
  12871. *
  12872. * Though the ">" character is escaped for symmetry, characters like
  12873. * ">" and "/" don't need escaping in HTML and have no special meaning
  12874. * unless they're part of a tag or unquoted attribute value. See
  12875. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  12876. * (under "semi-related fun fact") for more details.
  12877. *
  12878. * Backticks are escaped because in IE < 9, they can break out of
  12879. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  12880. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  12881. * [#133](https://html5sec.org/#133) of the
  12882. * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  12883. *
  12884. * When working with HTML you should always
  12885. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  12886. * XSS vectors.
  12887. *
  12888. * @static
  12889. * @since 0.1.0
  12890. * @memberOf _
  12891. * @category String
  12892. * @param {string} [string=''] The string to escape.
  12893. * @returns {string} Returns the escaped string.
  12894. * @example
  12895. *
  12896. * _.escape('fred, barney, & pebbles');
  12897. * // => 'fred, barney, &amp; pebbles'
  12898. */
  12899. function escape(string) {
  12900. string = toString(string);
  12901. return (string && reHasUnescapedHtml.test(string))
  12902. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  12903. : string;
  12904. }
  12905. /**
  12906. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  12907. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  12908. *
  12909. * @static
  12910. * @memberOf _
  12911. * @since 3.0.0
  12912. * @category String
  12913. * @param {string} [string=''] The string to escape.
  12914. * @returns {string} Returns the escaped string.
  12915. * @example
  12916. *
  12917. * _.escapeRegExp('[lodash](https://lodash.com/)');
  12918. * // => '\[lodash\]\(https://lodash\.com/\)'
  12919. */
  12920. function escapeRegExp(string) {
  12921. string = toString(string);
  12922. return (string && reHasRegExpChar.test(string))
  12923. ? string.replace(reRegExpChar, '\\$&')
  12924. : string;
  12925. }
  12926. /**
  12927. * Converts `string` to
  12928. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  12929. *
  12930. * @static
  12931. * @memberOf _
  12932. * @since 3.0.0
  12933. * @category String
  12934. * @param {string} [string=''] The string to convert.
  12935. * @returns {string} Returns the kebab cased string.
  12936. * @example
  12937. *
  12938. * _.kebabCase('Foo Bar');
  12939. * // => 'foo-bar'
  12940. *
  12941. * _.kebabCase('fooBar');
  12942. * // => 'foo-bar'
  12943. *
  12944. * _.kebabCase('__FOO_BAR__');
  12945. * // => 'foo-bar'
  12946. */
  12947. var kebabCase = createCompounder(function(result, word, index) {
  12948. return result + (index ? '-' : '') + word.toLowerCase();
  12949. });
  12950. /**
  12951. * Converts `string`, as space separated words, to lower case.
  12952. *
  12953. * @static
  12954. * @memberOf _
  12955. * @since 4.0.0
  12956. * @category String
  12957. * @param {string} [string=''] The string to convert.
  12958. * @returns {string} Returns the lower cased string.
  12959. * @example
  12960. *
  12961. * _.lowerCase('--Foo-Bar--');
  12962. * // => 'foo bar'
  12963. *
  12964. * _.lowerCase('fooBar');
  12965. * // => 'foo bar'
  12966. *
  12967. * _.lowerCase('__FOO_BAR__');
  12968. * // => 'foo bar'
  12969. */
  12970. var lowerCase = createCompounder(function(result, word, index) {
  12971. return result + (index ? ' ' : '') + word.toLowerCase();
  12972. });
  12973. /**
  12974. * Converts the first character of `string` to lower case.
  12975. *
  12976. * @static
  12977. * @memberOf _
  12978. * @since 4.0.0
  12979. * @category String
  12980. * @param {string} [string=''] The string to convert.
  12981. * @returns {string} Returns the converted string.
  12982. * @example
  12983. *
  12984. * _.lowerFirst('Fred');
  12985. * // => 'fred'
  12986. *
  12987. * _.lowerFirst('FRED');
  12988. * // => 'fRED'
  12989. */
  12990. var lowerFirst = createCaseFirst('toLowerCase');
  12991. /**
  12992. * Pads `string` on the left and right sides if it's shorter than `length`.
  12993. * Padding characters are truncated if they can't be evenly divided by `length`.
  12994. *
  12995. * @static
  12996. * @memberOf _
  12997. * @since 3.0.0
  12998. * @category String
  12999. * @param {string} [string=''] The string to pad.
  13000. * @param {number} [length=0] The padding length.
  13001. * @param {string} [chars=' '] The string used as padding.
  13002. * @returns {string} Returns the padded string.
  13003. * @example
  13004. *
  13005. * _.pad('abc', 8);
  13006. * // => ' abc '
  13007. *
  13008. * _.pad('abc', 8, '_-');
  13009. * // => '_-abc_-_'
  13010. *
  13011. * _.pad('abc', 3);
  13012. * // => 'abc'
  13013. */
  13014. function pad(string, length, chars) {
  13015. string = toString(string);
  13016. length = toInteger(length);
  13017. var strLength = length ? stringSize(string) : 0;
  13018. if (!length || strLength >= length) {
  13019. return string;
  13020. }
  13021. var mid = (length - strLength) / 2;
  13022. return (
  13023. createPadding(nativeFloor(mid), chars) +
  13024. string +
  13025. createPadding(nativeCeil(mid), chars)
  13026. );
  13027. }
  13028. /**
  13029. * Pads `string` on the right side if it's shorter than `length`. Padding
  13030. * characters are truncated if they exceed `length`.
  13031. *
  13032. * @static
  13033. * @memberOf _
  13034. * @since 4.0.0
  13035. * @category String
  13036. * @param {string} [string=''] The string to pad.
  13037. * @param {number} [length=0] The padding length.
  13038. * @param {string} [chars=' '] The string used as padding.
  13039. * @returns {string} Returns the padded string.
  13040. * @example
  13041. *
  13042. * _.padEnd('abc', 6);
  13043. * // => 'abc '
  13044. *
  13045. * _.padEnd('abc', 6, '_-');
  13046. * // => 'abc_-_'
  13047. *
  13048. * _.padEnd('abc', 3);
  13049. * // => 'abc'
  13050. */
  13051. function padEnd(string, length, chars) {
  13052. string = toString(string);
  13053. length = toInteger(length);
  13054. var strLength = length ? stringSize(string) : 0;
  13055. return (length && strLength < length)
  13056. ? (string + createPadding(length - strLength, chars))
  13057. : string;
  13058. }
  13059. /**
  13060. * Pads `string` on the left side if it's shorter than `length`. Padding
  13061. * characters are truncated if they exceed `length`.
  13062. *
  13063. * @static
  13064. * @memberOf _
  13065. * @since 4.0.0
  13066. * @category String
  13067. * @param {string} [string=''] The string to pad.
  13068. * @param {number} [length=0] The padding length.
  13069. * @param {string} [chars=' '] The string used as padding.
  13070. * @returns {string} Returns the padded string.
  13071. * @example
  13072. *
  13073. * _.padStart('abc', 6);
  13074. * // => ' abc'
  13075. *
  13076. * _.padStart('abc', 6, '_-');
  13077. * // => '_-_abc'
  13078. *
  13079. * _.padStart('abc', 3);
  13080. * // => 'abc'
  13081. */
  13082. function padStart(string, length, chars) {
  13083. string = toString(string);
  13084. length = toInteger(length);
  13085. var strLength = length ? stringSize(string) : 0;
  13086. return (length && strLength < length)
  13087. ? (createPadding(length - strLength, chars) + string)
  13088. : string;
  13089. }
  13090. /**
  13091. * Converts `string` to an integer of the specified radix. If `radix` is
  13092. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13093. * hexadecimal, in which case a `radix` of `16` is used.
  13094. *
  13095. * **Note:** This method aligns with the
  13096. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13097. *
  13098. * @static
  13099. * @memberOf _
  13100. * @since 1.1.0
  13101. * @category String
  13102. * @param {string} string The string to convert.
  13103. * @param {number} [radix=10] The radix to interpret `value` by.
  13104. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13105. * @returns {number} Returns the converted integer.
  13106. * @example
  13107. *
  13108. * _.parseInt('08');
  13109. * // => 8
  13110. *
  13111. * _.map(['6', '08', '10'], _.parseInt);
  13112. * // => [6, 8, 10]
  13113. */
  13114. function parseInt(string, radix, guard) {
  13115. // Chrome fails to trim leading <BOM> whitespace characters.
  13116. // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
  13117. if (guard || radix == null) {
  13118. radix = 0;
  13119. } else if (radix) {
  13120. radix = +radix;
  13121. }
  13122. string = toString(string).replace(reTrim, '');
  13123. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  13124. }
  13125. /**
  13126. * Repeats the given string `n` times.
  13127. *
  13128. * @static
  13129. * @memberOf _
  13130. * @since 3.0.0
  13131. * @category String
  13132. * @param {string} [string=''] The string to repeat.
  13133. * @param {number} [n=1] The number of times to repeat the string.
  13134. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13135. * @returns {string} Returns the repeated string.
  13136. * @example
  13137. *
  13138. * _.repeat('*', 3);
  13139. * // => '***'
  13140. *
  13141. * _.repeat('abc', 2);
  13142. * // => 'abcabc'
  13143. *
  13144. * _.repeat('abc', 0);
  13145. * // => ''
  13146. */
  13147. function repeat(string, n, guard) {
  13148. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13149. n = 1;
  13150. } else {
  13151. n = toInteger(n);
  13152. }
  13153. return baseRepeat(toString(string), n);
  13154. }
  13155. /**
  13156. * Replaces matches for `pattern` in `string` with `replacement`.
  13157. *
  13158. * **Note:** This method is based on
  13159. * [`String#replace`](https://mdn.io/String/replace).
  13160. *
  13161. * @static
  13162. * @memberOf _
  13163. * @since 4.0.0
  13164. * @category String
  13165. * @param {string} [string=''] The string to modify.
  13166. * @param {RegExp|string} pattern The pattern to replace.
  13167. * @param {Function|string} replacement The match replacement.
  13168. * @returns {string} Returns the modified string.
  13169. * @example
  13170. *
  13171. * _.replace('Hi Fred', 'Fred', 'Barney');
  13172. * // => 'Hi Barney'
  13173. */
  13174. function replace() {
  13175. var args = arguments,
  13176. string = toString(args[0]);
  13177. return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]);
  13178. }
  13179. /**
  13180. * Converts `string` to
  13181. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13182. *
  13183. * @static
  13184. * @memberOf _
  13185. * @since 3.0.0
  13186. * @category String
  13187. * @param {string} [string=''] The string to convert.
  13188. * @returns {string} Returns the snake cased string.
  13189. * @example
  13190. *
  13191. * _.snakeCase('Foo Bar');
  13192. * // => 'foo_bar'
  13193. *
  13194. * _.snakeCase('fooBar');
  13195. * // => 'foo_bar'
  13196. *
  13197. * _.snakeCase('--FOO-BAR--');
  13198. * // => 'foo_bar'
  13199. */
  13200. var snakeCase = createCompounder(function(result, word, index) {
  13201. return result + (index ? '_' : '') + word.toLowerCase();
  13202. });
  13203. /**
  13204. * Splits `string` by `separator`.
  13205. *
  13206. * **Note:** This method is based on
  13207. * [`String#split`](https://mdn.io/String/split).
  13208. *
  13209. * @static
  13210. * @memberOf _
  13211. * @since 4.0.0
  13212. * @category String
  13213. * @param {string} [string=''] The string to split.
  13214. * @param {RegExp|string} separator The separator pattern to split by.
  13215. * @param {number} [limit] The length to truncate results to.
  13216. * @returns {Array} Returns the string segments.
  13217. * @example
  13218. *
  13219. * _.split('a-b-c', '-', 2);
  13220. * // => ['a', 'b']
  13221. */
  13222. function split(string, separator, limit) {
  13223. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13224. separator = limit = undefined;
  13225. }
  13226. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13227. if (!limit) {
  13228. return [];
  13229. }
  13230. string = toString(string);
  13231. if (string && (
  13232. typeof separator == 'string' ||
  13233. (separator != null && !isRegExp(separator))
  13234. )) {
  13235. separator = baseToString(separator);
  13236. if (separator == '' && reHasComplexSymbol.test(string)) {
  13237. return castSlice(stringToArray(string), 0, limit);
  13238. }
  13239. }
  13240. return nativeSplit.call(string, separator, limit);
  13241. }
  13242. /**
  13243. * Converts `string` to
  13244. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13245. *
  13246. * @static
  13247. * @memberOf _
  13248. * @since 3.1.0
  13249. * @category String
  13250. * @param {string} [string=''] The string to convert.
  13251. * @returns {string} Returns the start cased string.
  13252. * @example
  13253. *
  13254. * _.startCase('--foo-bar--');
  13255. * // => 'Foo Bar'
  13256. *
  13257. * _.startCase('fooBar');
  13258. * // => 'Foo Bar'
  13259. *
  13260. * _.startCase('__FOO_BAR__');
  13261. * // => 'FOO BAR'
  13262. */
  13263. var startCase = createCompounder(function(result, word, index) {
  13264. return result + (index ? ' ' : '') + upperFirst(word);
  13265. });
  13266. /**
  13267. * Checks if `string` starts with the given target string.
  13268. *
  13269. * @static
  13270. * @memberOf _
  13271. * @since 3.0.0
  13272. * @category String
  13273. * @param {string} [string=''] The string to search.
  13274. * @param {string} [target] The string to search for.
  13275. * @param {number} [position=0] The position to search from.
  13276. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13277. * else `false`.
  13278. * @example
  13279. *
  13280. * _.startsWith('abc', 'a');
  13281. * // => true
  13282. *
  13283. * _.startsWith('abc', 'b');
  13284. * // => false
  13285. *
  13286. * _.startsWith('abc', 'b', 1);
  13287. * // => true
  13288. */
  13289. function startsWith(string, target, position) {
  13290. string = toString(string);
  13291. position = baseClamp(toInteger(position), 0, string.length);
  13292. target = baseToString(target);
  13293. return string.slice(position, position + target.length) == target;
  13294. }
  13295. /**
  13296. * Creates a compiled template function that can interpolate data properties
  13297. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13298. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13299. * properties may be accessed as free variables in the template. If a setting
  13300. * object is given, it takes precedence over `_.templateSettings` values.
  13301. *
  13302. * **Note:** In the development build `_.template` utilizes
  13303. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13304. * for easier debugging.
  13305. *
  13306. * For more information on precompiling templates see
  13307. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13308. *
  13309. * For more information on Chrome extension sandboxes see
  13310. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13311. *
  13312. * @static
  13313. * @since 0.1.0
  13314. * @memberOf _
  13315. * @category String
  13316. * @param {string} [string=''] The template string.
  13317. * @param {Object} [options={}] The options object.
  13318. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13319. * The HTML "escape" delimiter.
  13320. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13321. * The "evaluate" delimiter.
  13322. * @param {Object} [options.imports=_.templateSettings.imports]
  13323. * An object to import into the template as free variables.
  13324. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13325. * The "interpolate" delimiter.
  13326. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13327. * The sourceURL of the compiled template.
  13328. * @param {string} [options.variable='obj']
  13329. * The data object variable name.
  13330. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13331. * @returns {Function} Returns the compiled template function.
  13332. * @example
  13333. *
  13334. * // Use the "interpolate" delimiter to create a compiled template.
  13335. * var compiled = _.template('hello <%= user %>!');
  13336. * compiled({ 'user': 'fred' });
  13337. * // => 'hello fred!'
  13338. *
  13339. * // Use the HTML "escape" delimiter to escape data property values.
  13340. * var compiled = _.template('<b><%- value %></b>');
  13341. * compiled({ 'value': '<script>' });
  13342. * // => '<b>&lt;script&gt;</b>'
  13343. *
  13344. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13345. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13346. * compiled({ 'users': ['fred', 'barney'] });
  13347. * // => '<li>fred</li><li>barney</li>'
  13348. *
  13349. * // Use the internal `print` function in "evaluate" delimiters.
  13350. * var compiled = _.template('<% print("hello " + user); %>!');
  13351. * compiled({ 'user': 'barney' });
  13352. * // => 'hello barney!'
  13353. *
  13354. * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
  13355. * var compiled = _.template('hello ${ user }!');
  13356. * compiled({ 'user': 'pebbles' });
  13357. * // => 'hello pebbles!'
  13358. *
  13359. * // Use backslashes to treat delimiters as plain text.
  13360. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13361. * compiled({ 'value': 'ignored' });
  13362. * // => '<%- value %>'
  13363. *
  13364. * // Use the `imports` option to import `jQuery` as `jq`.
  13365. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13366. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13367. * compiled({ 'users': ['fred', 'barney'] });
  13368. * // => '<li>fred</li><li>barney</li>'
  13369. *
  13370. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13371. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13372. * compiled(data);
  13373. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13374. *
  13375. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13376. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13377. * compiled.source;
  13378. * // => function(data) {
  13379. * // var __t, __p = '';
  13380. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13381. * // return __p;
  13382. * // }
  13383. *
  13384. * // Use custom template delimiters.
  13385. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13386. * var compiled = _.template('hello {{ user }}!');
  13387. * compiled({ 'user': 'mustache' });
  13388. * // => 'hello mustache!'
  13389. *
  13390. * // Use the `source` property to inline compiled templates for meaningful
  13391. * // line numbers in error messages and stack traces.
  13392. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13393. * var JST = {\
  13394. * "main": ' + _.template(mainText).source + '\
  13395. * };\
  13396. * ');
  13397. */
  13398. function template(string, options, guard) {
  13399. // Based on John Resig's `tmpl` implementation
  13400. // (http://ejohn.org/blog/javascript-micro-templating/)
  13401. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13402. var settings = lodash.templateSettings;
  13403. if (guard && isIterateeCall(string, options, guard)) {
  13404. options = undefined;
  13405. }
  13406. string = toString(string);
  13407. options = assignInWith({}, options, settings, assignInDefaults);
  13408. var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
  13409. importsKeys = keys(imports),
  13410. importsValues = baseValues(imports, importsKeys);
  13411. var isEscaping,
  13412. isEvaluating,
  13413. index = 0,
  13414. interpolate = options.interpolate || reNoMatch,
  13415. source = "__p += '";
  13416. // Compile the regexp to match each delimiter.
  13417. var reDelimiters = RegExp(
  13418. (options.escape || reNoMatch).source + '|' +
  13419. interpolate.source + '|' +
  13420. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13421. (options.evaluate || reNoMatch).source + '|$'
  13422. , 'g');
  13423. // Use a sourceURL for easier debugging.
  13424. var sourceURL = '//# sourceURL=' +
  13425. ('sourceURL' in options
  13426. ? options.sourceURL
  13427. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13428. ) + '\n';
  13429. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13430. interpolateValue || (interpolateValue = esTemplateValue);
  13431. // Escape characters that can't be included in string literals.
  13432. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13433. // Replace delimiters with snippets.
  13434. if (escapeValue) {
  13435. isEscaping = true;
  13436. source += "' +\n__e(" + escapeValue + ") +\n'";
  13437. }
  13438. if (evaluateValue) {
  13439. isEvaluating = true;
  13440. source += "';\n" + evaluateValue + ";\n__p += '";
  13441. }
  13442. if (interpolateValue) {
  13443. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13444. }
  13445. index = offset + match.length;
  13446. // The JS engine embedded in Adobe products needs `match` returned in
  13447. // order to produce the correct `offset` value.
  13448. return match;
  13449. });
  13450. source += "';\n";
  13451. // If `variable` is not specified wrap a with-statement around the generated
  13452. // code to add the data object to the top of the scope chain.
  13453. var variable = options.variable;
  13454. if (!variable) {
  13455. source = 'with (obj) {\n' + source + '\n}\n';
  13456. }
  13457. // Cleanup code by stripping empty strings.
  13458. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13459. .replace(reEmptyStringMiddle, '$1')
  13460. .replace(reEmptyStringTrailing, '$1;');
  13461. // Frame code as the function body.
  13462. source = 'function(' + (variable || 'obj') + ') {\n' +
  13463. (variable
  13464. ? ''
  13465. : 'obj || (obj = {});\n'
  13466. ) +
  13467. "var __t, __p = ''" +
  13468. (isEscaping
  13469. ? ', __e = _.escape'
  13470. : ''
  13471. ) +
  13472. (isEvaluating
  13473. ? ', __j = Array.prototype.join;\n' +
  13474. "function print() { __p += __j.call(arguments, '') }\n"
  13475. : ';\n'
  13476. ) +
  13477. source +
  13478. 'return __p\n}';
  13479. var result = attempt(function() {
  13480. return Function(importsKeys, sourceURL + 'return ' + source)
  13481. .apply(undefined, importsValues);
  13482. });
  13483. // Provide the compiled function's source by its `toString` method or
  13484. // the `source` property as a convenience for inlining compiled templates.
  13485. result.source = source;
  13486. if (isError(result)) {
  13487. throw result;
  13488. }
  13489. return result;
  13490. }
  13491. /**
  13492. * Converts `string`, as a whole, to lower case just like
  13493. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13494. *
  13495. * @static
  13496. * @memberOf _
  13497. * @since 4.0.0
  13498. * @category String
  13499. * @param {string} [string=''] The string to convert.
  13500. * @returns {string} Returns the lower cased string.
  13501. * @example
  13502. *
  13503. * _.toLower('--Foo-Bar--');
  13504. * // => '--foo-bar--'
  13505. *
  13506. * _.toLower('fooBar');
  13507. * // => 'foobar'
  13508. *
  13509. * _.toLower('__FOO_BAR__');
  13510. * // => '__foo_bar__'
  13511. */
  13512. function toLower(value) {
  13513. return toString(value).toLowerCase();
  13514. }
  13515. /**
  13516. * Converts `string`, as a whole, to upper case just like
  13517. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13518. *
  13519. * @static
  13520. * @memberOf _
  13521. * @since 4.0.0
  13522. * @category String
  13523. * @param {string} [string=''] The string to convert.
  13524. * @returns {string} Returns the upper cased string.
  13525. * @example
  13526. *
  13527. * _.toUpper('--foo-bar--');
  13528. * // => '--FOO-BAR--'
  13529. *
  13530. * _.toUpper('fooBar');
  13531. * // => 'FOOBAR'
  13532. *
  13533. * _.toUpper('__foo_bar__');
  13534. * // => '__FOO_BAR__'
  13535. */
  13536. function toUpper(value) {
  13537. return toString(value).toUpperCase();
  13538. }
  13539. /**
  13540. * Removes leading and trailing whitespace or specified characters from `string`.
  13541. *
  13542. * @static
  13543. * @memberOf _
  13544. * @since 3.0.0
  13545. * @category String
  13546. * @param {string} [string=''] The string to trim.
  13547. * @param {string} [chars=whitespace] The characters to trim.
  13548. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13549. * @returns {string} Returns the trimmed string.
  13550. * @example
  13551. *
  13552. * _.trim(' abc ');
  13553. * // => 'abc'
  13554. *
  13555. * _.trim('-_-abc-_-', '_-');
  13556. * // => 'abc'
  13557. *
  13558. * _.map([' foo ', ' bar '], _.trim);
  13559. * // => ['foo', 'bar']
  13560. */
  13561. function trim(string, chars, guard) {
  13562. string = toString(string);
  13563. if (string && (guard || chars === undefined)) {
  13564. return string.replace(reTrim, '');
  13565. }
  13566. if (!string || !(chars = baseToString(chars))) {
  13567. return string;
  13568. }
  13569. var strSymbols = stringToArray(string),
  13570. chrSymbols = stringToArray(chars),
  13571. start = charsStartIndex(strSymbols, chrSymbols),
  13572. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  13573. return castSlice(strSymbols, start, end).join('');
  13574. }
  13575. /**
  13576. * Removes trailing whitespace or specified characters from `string`.
  13577. *
  13578. * @static
  13579. * @memberOf _
  13580. * @since 4.0.0
  13581. * @category String
  13582. * @param {string} [string=''] The string to trim.
  13583. * @param {string} [chars=whitespace] The characters to trim.
  13584. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13585. * @returns {string} Returns the trimmed string.
  13586. * @example
  13587. *
  13588. * _.trimEnd(' abc ');
  13589. * // => ' abc'
  13590. *
  13591. * _.trimEnd('-_-abc-_-', '_-');
  13592. * // => '-_-abc'
  13593. */
  13594. function trimEnd(string, chars, guard) {
  13595. string = toString(string);
  13596. if (string && (guard || chars === undefined)) {
  13597. return string.replace(reTrimEnd, '');
  13598. }
  13599. if (!string || !(chars = baseToString(chars))) {
  13600. return string;
  13601. }
  13602. var strSymbols = stringToArray(string),
  13603. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  13604. return castSlice(strSymbols, 0, end).join('');
  13605. }
  13606. /**
  13607. * Removes leading whitespace or specified characters from `string`.
  13608. *
  13609. * @static
  13610. * @memberOf _
  13611. * @since 4.0.0
  13612. * @category String
  13613. * @param {string} [string=''] The string to trim.
  13614. * @param {string} [chars=whitespace] The characters to trim.
  13615. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13616. * @returns {string} Returns the trimmed string.
  13617. * @example
  13618. *
  13619. * _.trimStart(' abc ');
  13620. * // => 'abc '
  13621. *
  13622. * _.trimStart('-_-abc-_-', '_-');
  13623. * // => 'abc-_-'
  13624. */
  13625. function trimStart(string, chars, guard) {
  13626. string = toString(string);
  13627. if (string && (guard || chars === undefined)) {
  13628. return string.replace(reTrimStart, '');
  13629. }
  13630. if (!string || !(chars = baseToString(chars))) {
  13631. return string;
  13632. }
  13633. var strSymbols = stringToArray(string),
  13634. start = charsStartIndex(strSymbols, stringToArray(chars));
  13635. return castSlice(strSymbols, start).join('');
  13636. }
  13637. /**
  13638. * Truncates `string` if it's longer than the given maximum string length.
  13639. * The last characters of the truncated string are replaced with the omission
  13640. * string which defaults to "...".
  13641. *
  13642. * @static
  13643. * @memberOf _
  13644. * @since 4.0.0
  13645. * @category String
  13646. * @param {string} [string=''] The string to truncate.
  13647. * @param {Object} [options={}] The options object.
  13648. * @param {number} [options.length=30] The maximum string length.
  13649. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  13650. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  13651. * @returns {string} Returns the truncated string.
  13652. * @example
  13653. *
  13654. * _.truncate('hi-diddly-ho there, neighborino');
  13655. * // => 'hi-diddly-ho there, neighbo...'
  13656. *
  13657. * _.truncate('hi-diddly-ho there, neighborino', {
  13658. * 'length': 24,
  13659. * 'separator': ' '
  13660. * });
  13661. * // => 'hi-diddly-ho there,...'
  13662. *
  13663. * _.truncate('hi-diddly-ho there, neighborino', {
  13664. * 'length': 24,
  13665. * 'separator': /,? +/
  13666. * });
  13667. * // => 'hi-diddly-ho there...'
  13668. *
  13669. * _.truncate('hi-diddly-ho there, neighborino', {
  13670. * 'omission': ' [...]'
  13671. * });
  13672. * // => 'hi-diddly-ho there, neig [...]'
  13673. */
  13674. function truncate(string, options) {
  13675. var length = DEFAULT_TRUNC_LENGTH,
  13676. omission = DEFAULT_TRUNC_OMISSION;
  13677. if (isObject(options)) {
  13678. var separator = 'separator' in options ? options.separator : separator;
  13679. length = 'length' in options ? toInteger(options.length) : length;
  13680. omission = 'omission' in options ? baseToString(options.omission) : omission;
  13681. }
  13682. string = toString(string);
  13683. var strLength = string.length;
  13684. if (reHasComplexSymbol.test(string)) {
  13685. var strSymbols = stringToArray(string);
  13686. strLength = strSymbols.length;
  13687. }
  13688. if (length >= strLength) {
  13689. return string;
  13690. }
  13691. var end = length - stringSize(omission);
  13692. if (end < 1) {
  13693. return omission;
  13694. }
  13695. var result = strSymbols
  13696. ? castSlice(strSymbols, 0, end).join('')
  13697. : string.slice(0, end);
  13698. if (separator === undefined) {
  13699. return result + omission;
  13700. }
  13701. if (strSymbols) {
  13702. end += (result.length - end);
  13703. }
  13704. if (isRegExp(separator)) {
  13705. if (string.slice(end).search(separator)) {
  13706. var match,
  13707. substring = result;
  13708. if (!separator.global) {
  13709. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  13710. }
  13711. separator.lastIndex = 0;
  13712. while ((match = separator.exec(substring))) {
  13713. var newEnd = match.index;
  13714. }
  13715. result = result.slice(0, newEnd === undefined ? end : newEnd);
  13716. }
  13717. } else if (string.indexOf(baseToString(separator), end) != end) {
  13718. var index = result.lastIndexOf(separator);
  13719. if (index > -1) {
  13720. result = result.slice(0, index);
  13721. }
  13722. }
  13723. return result + omission;
  13724. }
  13725. /**
  13726. * The inverse of `_.escape`; this method converts the HTML entities
  13727. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to
  13728. * their corresponding characters.
  13729. *
  13730. * **Note:** No other HTML entities are unescaped. To unescape additional
  13731. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  13732. *
  13733. * @static
  13734. * @memberOf _
  13735. * @since 0.6.0
  13736. * @category String
  13737. * @param {string} [string=''] The string to unescape.
  13738. * @returns {string} Returns the unescaped string.
  13739. * @example
  13740. *
  13741. * _.unescape('fred, barney, &amp; pebbles');
  13742. * // => 'fred, barney, & pebbles'
  13743. */
  13744. function unescape(string) {
  13745. string = toString(string);
  13746. return (string && reHasEscapedHtml.test(string))
  13747. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  13748. : string;
  13749. }
  13750. /**
  13751. * Converts `string`, as space separated words, to upper case.
  13752. *
  13753. * @static
  13754. * @memberOf _
  13755. * @since 4.0.0
  13756. * @category String
  13757. * @param {string} [string=''] The string to convert.
  13758. * @returns {string} Returns the upper cased string.
  13759. * @example
  13760. *
  13761. * _.upperCase('--foo-bar');
  13762. * // => 'FOO BAR'
  13763. *
  13764. * _.upperCase('fooBar');
  13765. * // => 'FOO BAR'
  13766. *
  13767. * _.upperCase('__foo_bar__');
  13768. * // => 'FOO BAR'
  13769. */
  13770. var upperCase = createCompounder(function(result, word, index) {
  13771. return result + (index ? ' ' : '') + word.toUpperCase();
  13772. });
  13773. /**
  13774. * Converts the first character of `string` to upper case.
  13775. *
  13776. * @static
  13777. * @memberOf _
  13778. * @since 4.0.0
  13779. * @category String
  13780. * @param {string} [string=''] The string to convert.
  13781. * @returns {string} Returns the converted string.
  13782. * @example
  13783. *
  13784. * _.upperFirst('fred');
  13785. * // => 'Fred'
  13786. *
  13787. * _.upperFirst('FRED');
  13788. * // => 'FRED'
  13789. */
  13790. var upperFirst = createCaseFirst('toUpperCase');
  13791. /**
  13792. * Splits `string` into an array of its words.
  13793. *
  13794. * @static
  13795. * @memberOf _
  13796. * @since 3.0.0
  13797. * @category String
  13798. * @param {string} [string=''] The string to inspect.
  13799. * @param {RegExp|string} [pattern] The pattern to match words.
  13800. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13801. * @returns {Array} Returns the words of `string`.
  13802. * @example
  13803. *
  13804. * _.words('fred, barney, & pebbles');
  13805. * // => ['fred', 'barney', 'pebbles']
  13806. *
  13807. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  13808. * // => ['fred', 'barney', '&', 'pebbles']
  13809. */
  13810. function words(string, pattern, guard) {
  13811. string = toString(string);
  13812. pattern = guard ? undefined : pattern;
  13813. if (pattern === undefined) {
  13814. pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord;
  13815. }
  13816. return string.match(pattern) || [];
  13817. }
  13818. /*------------------------------------------------------------------------*/
  13819. /**
  13820. * Attempts to invoke `func`, returning either the result or the caught error
  13821. * object. Any additional arguments are provided to `func` when it's invoked.
  13822. *
  13823. * @static
  13824. * @memberOf _
  13825. * @since 3.0.0
  13826. * @category Util
  13827. * @param {Function} func The function to attempt.
  13828. * @param {...*} [args] The arguments to invoke `func` with.
  13829. * @returns {*} Returns the `func` result or error object.
  13830. * @example
  13831. *
  13832. * // Avoid throwing errors for invalid selectors.
  13833. * var elements = _.attempt(function(selector) {
  13834. * return document.querySelectorAll(selector);
  13835. * }, '>_>');
  13836. *
  13837. * if (_.isError(elements)) {
  13838. * elements = [];
  13839. * }
  13840. */
  13841. var attempt = baseRest(function(func, args) {
  13842. try {
  13843. return apply(func, undefined, args);
  13844. } catch (e) {
  13845. return isError(e) ? e : new Error(e);
  13846. }
  13847. });
  13848. /**
  13849. * Binds methods of an object to the object itself, overwriting the existing
  13850. * method.
  13851. *
  13852. * **Note:** This method doesn't set the "length" property of bound functions.
  13853. *
  13854. * @static
  13855. * @since 0.1.0
  13856. * @memberOf _
  13857. * @category Util
  13858. * @param {Object} object The object to bind and assign the bound methods to.
  13859. * @param {...(string|string[])} methodNames The object method names to bind.
  13860. * @returns {Object} Returns `object`.
  13861. * @example
  13862. *
  13863. * var view = {
  13864. * 'label': 'docs',
  13865. * 'click': function() {
  13866. * console.log('clicked ' + this.label);
  13867. * }
  13868. * };
  13869. *
  13870. * _.bindAll(view, ['click']);
  13871. * jQuery(element).on('click', view.click);
  13872. * // => Logs 'clicked docs' when clicked.
  13873. */
  13874. var bindAll = baseRest(function(object, methodNames) {
  13875. arrayEach(baseFlatten(methodNames, 1), function(key) {
  13876. key = toKey(key);
  13877. object[key] = bind(object[key], object);
  13878. });
  13879. return object;
  13880. });
  13881. /**
  13882. * Creates a function that iterates over `pairs` and invokes the corresponding
  13883. * function of the first predicate to return truthy. The predicate-function
  13884. * pairs are invoked with the `this` binding and arguments of the created
  13885. * function.
  13886. *
  13887. * @static
  13888. * @memberOf _
  13889. * @since 4.0.0
  13890. * @category Util
  13891. * @param {Array} pairs The predicate-function pairs.
  13892. * @returns {Function} Returns the new composite function.
  13893. * @example
  13894. *
  13895. * var func = _.cond([
  13896. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  13897. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  13898. * [_.stubTrue, _.constant('no match')]
  13899. * ]);
  13900. *
  13901. * func({ 'a': 1, 'b': 2 });
  13902. * // => 'matches A'
  13903. *
  13904. * func({ 'a': 0, 'b': 1 });
  13905. * // => 'matches B'
  13906. *
  13907. * func({ 'a': '1', 'b': '2' });
  13908. * // => 'no match'
  13909. */
  13910. function cond(pairs) {
  13911. var length = pairs ? pairs.length : 0,
  13912. toIteratee = getIteratee();
  13913. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  13914. if (typeof pair[1] != 'function') {
  13915. throw new TypeError(FUNC_ERROR_TEXT);
  13916. }
  13917. return [toIteratee(pair[0]), pair[1]];
  13918. });
  13919. return baseRest(function(args) {
  13920. var index = -1;
  13921. while (++index < length) {
  13922. var pair = pairs[index];
  13923. if (apply(pair[0], this, args)) {
  13924. return apply(pair[1], this, args);
  13925. }
  13926. }
  13927. });
  13928. }
  13929. /**
  13930. * Creates a function that invokes the predicate properties of `source` with
  13931. * the corresponding property values of a given object, returning `true` if
  13932. * all predicates return truthy, else `false`.
  13933. *
  13934. * @static
  13935. * @memberOf _
  13936. * @since 4.0.0
  13937. * @category Util
  13938. * @param {Object} source The object of property predicates to conform to.
  13939. * @returns {Function} Returns the new spec function.
  13940. * @example
  13941. *
  13942. * var objects = [
  13943. * { 'a': 2, 'b': 1 },
  13944. * { 'a': 1, 'b': 2 }
  13945. * ];
  13946. *
  13947. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  13948. * // => [{ 'a': 1, 'b': 2 }]
  13949. */
  13950. function conforms(source) {
  13951. return baseConforms(baseClone(source, true));
  13952. }
  13953. /**
  13954. * Creates a function that returns `value`.
  13955. *
  13956. * @static
  13957. * @memberOf _
  13958. * @since 2.4.0
  13959. * @category Util
  13960. * @param {*} value The value to return from the new function.
  13961. * @returns {Function} Returns the new constant function.
  13962. * @example
  13963. *
  13964. * var objects = _.times(2, _.constant({ 'a': 1 }));
  13965. *
  13966. * console.log(objects);
  13967. * // => [{ 'a': 1 }, { 'a': 1 }]
  13968. *
  13969. * console.log(objects[0] === objects[1]);
  13970. * // => true
  13971. */
  13972. function constant(value) {
  13973. return function() {
  13974. return value;
  13975. };
  13976. }
  13977. /**
  13978. * Checks `value` to determine whether a default value should be returned in
  13979. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  13980. * or `undefined`.
  13981. *
  13982. * @static
  13983. * @memberOf _
  13984. * @since 4.14.0
  13985. * @category Util
  13986. * @param {*} value The value to check.
  13987. * @param {*} defaultValue The default value.
  13988. * @returns {*} Returns the resolved value.
  13989. * @example
  13990. *
  13991. * _.defaultTo(1, 10);
  13992. * // => 1
  13993. *
  13994. * _.defaultTo(undefined, 10);
  13995. * // => 10
  13996. */
  13997. function defaultTo(value, defaultValue) {
  13998. return (value == null || value !== value) ? defaultValue : value;
  13999. }
  14000. /**
  14001. * Creates a function that returns the result of invoking the given functions
  14002. * with the `this` binding of the created function, where each successive
  14003. * invocation is supplied the return value of the previous.
  14004. *
  14005. * @static
  14006. * @memberOf _
  14007. * @since 3.0.0
  14008. * @category Util
  14009. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14010. * @returns {Function} Returns the new composite function.
  14011. * @see _.flowRight
  14012. * @example
  14013. *
  14014. * function square(n) {
  14015. * return n * n;
  14016. * }
  14017. *
  14018. * var addSquare = _.flow([_.add, square]);
  14019. * addSquare(1, 2);
  14020. * // => 9
  14021. */
  14022. var flow = createFlow();
  14023. /**
  14024. * This method is like `_.flow` except that it creates a function that
  14025. * invokes the given functions from right to left.
  14026. *
  14027. * @static
  14028. * @since 3.0.0
  14029. * @memberOf _
  14030. * @category Util
  14031. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14032. * @returns {Function} Returns the new composite function.
  14033. * @see _.flow
  14034. * @example
  14035. *
  14036. * function square(n) {
  14037. * return n * n;
  14038. * }
  14039. *
  14040. * var addSquare = _.flowRight([square, _.add]);
  14041. * addSquare(1, 2);
  14042. * // => 9
  14043. */
  14044. var flowRight = createFlow(true);
  14045. /**
  14046. * This method returns the first argument it receives.
  14047. *
  14048. * @static
  14049. * @since 0.1.0
  14050. * @memberOf _
  14051. * @category Util
  14052. * @param {*} value Any value.
  14053. * @returns {*} Returns `value`.
  14054. * @example
  14055. *
  14056. * var object = { 'a': 1 };
  14057. *
  14058. * console.log(_.identity(object) === object);
  14059. * // => true
  14060. */
  14061. function identity(value) {
  14062. return value;
  14063. }
  14064. /**
  14065. * Creates a function that invokes `func` with the arguments of the created
  14066. * function. If `func` is a property name, the created function returns the
  14067. * property value for a given element. If `func` is an array or object, the
  14068. * created function returns `true` for elements that contain the equivalent
  14069. * source properties, otherwise it returns `false`.
  14070. *
  14071. * @static
  14072. * @since 4.0.0
  14073. * @memberOf _
  14074. * @category Util
  14075. * @param {*} [func=_.identity] The value to convert to a callback.
  14076. * @returns {Function} Returns the callback.
  14077. * @example
  14078. *
  14079. * var users = [
  14080. * { 'user': 'barney', 'age': 36, 'active': true },
  14081. * { 'user': 'fred', 'age': 40, 'active': false }
  14082. * ];
  14083. *
  14084. * // The `_.matches` iteratee shorthand.
  14085. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14086. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14087. *
  14088. * // The `_.matchesProperty` iteratee shorthand.
  14089. * _.filter(users, _.iteratee(['user', 'fred']));
  14090. * // => [{ 'user': 'fred', 'age': 40 }]
  14091. *
  14092. * // The `_.property` iteratee shorthand.
  14093. * _.map(users, _.iteratee('user'));
  14094. * // => ['barney', 'fred']
  14095. *
  14096. * // Create custom iteratee shorthands.
  14097. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14098. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14099. * return func.test(string);
  14100. * };
  14101. * });
  14102. *
  14103. * _.filter(['abc', 'def'], /ef/);
  14104. * // => ['def']
  14105. */
  14106. function iteratee(func) {
  14107. return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
  14108. }
  14109. /**
  14110. * Creates a function that performs a partial deep comparison between a given
  14111. * object and `source`, returning `true` if the given object has equivalent
  14112. * property values, else `false`. The created function is equivalent to
  14113. * `_.isMatch` with a `source` partially applied.
  14114. *
  14115. * **Note:** This method supports comparing the same values as `_.isEqual`.
  14116. *
  14117. * @static
  14118. * @memberOf _
  14119. * @since 3.0.0
  14120. * @category Util
  14121. * @param {Object} source The object of property values to match.
  14122. * @returns {Function} Returns the new spec function.
  14123. * @example
  14124. *
  14125. * var objects = [
  14126. * { 'a': 1, 'b': 2, 'c': 3 },
  14127. * { 'a': 4, 'b': 5, 'c': 6 }
  14128. * ];
  14129. *
  14130. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14131. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14132. */
  14133. function matches(source) {
  14134. return baseMatches(baseClone(source, true));
  14135. }
  14136. /**
  14137. * Creates a function that performs a partial deep comparison between the
  14138. * value at `path` of a given object to `srcValue`, returning `true` if the
  14139. * object value is equivalent, else `false`.
  14140. *
  14141. * **Note:** This method supports comparing the same values as `_.isEqual`.
  14142. *
  14143. * @static
  14144. * @memberOf _
  14145. * @since 3.2.0
  14146. * @category Util
  14147. * @param {Array|string} path The path of the property to get.
  14148. * @param {*} srcValue The value to match.
  14149. * @returns {Function} Returns the new spec function.
  14150. * @example
  14151. *
  14152. * var objects = [
  14153. * { 'a': 1, 'b': 2, 'c': 3 },
  14154. * { 'a': 4, 'b': 5, 'c': 6 }
  14155. * ];
  14156. *
  14157. * _.find(objects, _.matchesProperty('a', 4));
  14158. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14159. */
  14160. function matchesProperty(path, srcValue) {
  14161. return baseMatchesProperty(path, baseClone(srcValue, true));
  14162. }
  14163. /**
  14164. * Creates a function that invokes the method at `path` of a given object.
  14165. * Any additional arguments are provided to the invoked method.
  14166. *
  14167. * @static
  14168. * @memberOf _
  14169. * @since 3.7.0
  14170. * @category Util
  14171. * @param {Array|string} path The path of the method to invoke.
  14172. * @param {...*} [args] The arguments to invoke the method with.
  14173. * @returns {Function} Returns the new invoker function.
  14174. * @example
  14175. *
  14176. * var objects = [
  14177. * { 'a': { 'b': _.constant(2) } },
  14178. * { 'a': { 'b': _.constant(1) } }
  14179. * ];
  14180. *
  14181. * _.map(objects, _.method('a.b'));
  14182. * // => [2, 1]
  14183. *
  14184. * _.map(objects, _.method(['a', 'b']));
  14185. * // => [2, 1]
  14186. */
  14187. var method = baseRest(function(path, args) {
  14188. return function(object) {
  14189. return baseInvoke(object, path, args);
  14190. };
  14191. });
  14192. /**
  14193. * The opposite of `_.method`; this method creates a function that invokes
  14194. * the method at a given path of `object`. Any additional arguments are
  14195. * provided to the invoked method.
  14196. *
  14197. * @static
  14198. * @memberOf _
  14199. * @since 3.7.0
  14200. * @category Util
  14201. * @param {Object} object The object to query.
  14202. * @param {...*} [args] The arguments to invoke the method with.
  14203. * @returns {Function} Returns the new invoker function.
  14204. * @example
  14205. *
  14206. * var array = _.times(3, _.constant),
  14207. * object = { 'a': array, 'b': array, 'c': array };
  14208. *
  14209. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14210. * // => [2, 0]
  14211. *
  14212. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14213. * // => [2, 0]
  14214. */
  14215. var methodOf = baseRest(function(object, args) {
  14216. return function(path) {
  14217. return baseInvoke(object, path, args);
  14218. };
  14219. });
  14220. /**
  14221. * Adds all own enumerable string keyed function properties of a source
  14222. * object to the destination object. If `object` is a function, then methods
  14223. * are added to its prototype as well.
  14224. *
  14225. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14226. * avoid conflicts caused by modifying the original.
  14227. *
  14228. * @static
  14229. * @since 0.1.0
  14230. * @memberOf _
  14231. * @category Util
  14232. * @param {Function|Object} [object=lodash] The destination object.
  14233. * @param {Object} source The object of functions to add.
  14234. * @param {Object} [options={}] The options object.
  14235. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14236. * @returns {Function|Object} Returns `object`.
  14237. * @example
  14238. *
  14239. * function vowels(string) {
  14240. * return _.filter(string, function(v) {
  14241. * return /[aeiou]/i.test(v);
  14242. * });
  14243. * }
  14244. *
  14245. * _.mixin({ 'vowels': vowels });
  14246. * _.vowels('fred');
  14247. * // => ['e']
  14248. *
  14249. * _('fred').vowels().value();
  14250. * // => ['e']
  14251. *
  14252. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14253. * _('fred').vowels();
  14254. * // => ['e']
  14255. */
  14256. function mixin(object, source, options) {
  14257. var props = keys(source),
  14258. methodNames = baseFunctions(source, props);
  14259. if (options == null &&
  14260. !(isObject(source) && (methodNames.length || !props.length))) {
  14261. options = source;
  14262. source = object;
  14263. object = this;
  14264. methodNames = baseFunctions(source, keys(source));
  14265. }
  14266. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14267. isFunc = isFunction(object);
  14268. arrayEach(methodNames, function(methodName) {
  14269. var func = source[methodName];
  14270. object[methodName] = func;
  14271. if (isFunc) {
  14272. object.prototype[methodName] = function() {
  14273. var chainAll = this.__chain__;
  14274. if (chain || chainAll) {
  14275. var result = object(this.__wrapped__),
  14276. actions = result.__actions__ = copyArray(this.__actions__);
  14277. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14278. result.__chain__ = chainAll;
  14279. return result;
  14280. }
  14281. return func.apply(object, arrayPush([this.value()], arguments));
  14282. };
  14283. }
  14284. });
  14285. return object;
  14286. }
  14287. /**
  14288. * Reverts the `_` variable to its previous value and returns a reference to
  14289. * the `lodash` function.
  14290. *
  14291. * @static
  14292. * @since 0.1.0
  14293. * @memberOf _
  14294. * @category Util
  14295. * @returns {Function} Returns the `lodash` function.
  14296. * @example
  14297. *
  14298. * var lodash = _.noConflict();
  14299. */
  14300. function noConflict() {
  14301. if (root._ === this) {
  14302. root._ = oldDash;
  14303. }
  14304. return this;
  14305. }
  14306. /**
  14307. * This method returns `undefined`.
  14308. *
  14309. * @static
  14310. * @memberOf _
  14311. * @since 2.3.0
  14312. * @category Util
  14313. * @example
  14314. *
  14315. * _.times(2, _.noop);
  14316. * // => [undefined, undefined]
  14317. */
  14318. function noop() {
  14319. // No operation performed.
  14320. }
  14321. /**
  14322. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14323. * the nth argument from the end is returned.
  14324. *
  14325. * @static
  14326. * @memberOf _
  14327. * @since 4.0.0
  14328. * @category Util
  14329. * @param {number} [n=0] The index of the argument to return.
  14330. * @returns {Function} Returns the new pass-thru function.
  14331. * @example
  14332. *
  14333. * var func = _.nthArg(1);
  14334. * func('a', 'b', 'c', 'd');
  14335. * // => 'b'
  14336. *
  14337. * var func = _.nthArg(-2);
  14338. * func('a', 'b', 'c', 'd');
  14339. * // => 'c'
  14340. */
  14341. function nthArg(n) {
  14342. n = toInteger(n);
  14343. return baseRest(function(args) {
  14344. return baseNth(args, n);
  14345. });
  14346. }
  14347. /**
  14348. * Creates a function that invokes `iteratees` with the arguments it receives
  14349. * and returns their results.
  14350. *
  14351. * @static
  14352. * @memberOf _
  14353. * @since 4.0.0
  14354. * @category Util
  14355. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14356. * The iteratees to invoke.
  14357. * @returns {Function} Returns the new function.
  14358. * @example
  14359. *
  14360. * var func = _.over([Math.max, Math.min]);
  14361. *
  14362. * func(1, 2, 3, 4);
  14363. * // => [4, 1]
  14364. */
  14365. var over = createOver(arrayMap);
  14366. /**
  14367. * Creates a function that checks if **all** of the `predicates` return
  14368. * truthy when invoked with the arguments it receives.
  14369. *
  14370. * @static
  14371. * @memberOf _
  14372. * @since 4.0.0
  14373. * @category Util
  14374. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14375. * The predicates to check.
  14376. * @returns {Function} Returns the new function.
  14377. * @example
  14378. *
  14379. * var func = _.overEvery([Boolean, isFinite]);
  14380. *
  14381. * func('1');
  14382. * // => true
  14383. *
  14384. * func(null);
  14385. * // => false
  14386. *
  14387. * func(NaN);
  14388. * // => false
  14389. */
  14390. var overEvery = createOver(arrayEvery);
  14391. /**
  14392. * Creates a function that checks if **any** of the `predicates` return
  14393. * truthy when invoked with the arguments it receives.
  14394. *
  14395. * @static
  14396. * @memberOf _
  14397. * @since 4.0.0
  14398. * @category Util
  14399. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14400. * The predicates to check.
  14401. * @returns {Function} Returns the new function.
  14402. * @example
  14403. *
  14404. * var func = _.overSome([Boolean, isFinite]);
  14405. *
  14406. * func('1');
  14407. * // => true
  14408. *
  14409. * func(null);
  14410. * // => true
  14411. *
  14412. * func(NaN);
  14413. * // => false
  14414. */
  14415. var overSome = createOver(arraySome);
  14416. /**
  14417. * Creates a function that returns the value at `path` of a given object.
  14418. *
  14419. * @static
  14420. * @memberOf _
  14421. * @since 2.4.0
  14422. * @category Util
  14423. * @param {Array|string} path The path of the property to get.
  14424. * @returns {Function} Returns the new accessor function.
  14425. * @example
  14426. *
  14427. * var objects = [
  14428. * { 'a': { 'b': 2 } },
  14429. * { 'a': { 'b': 1 } }
  14430. * ];
  14431. *
  14432. * _.map(objects, _.property('a.b'));
  14433. * // => [2, 1]
  14434. *
  14435. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14436. * // => [1, 2]
  14437. */
  14438. function property(path) {
  14439. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14440. }
  14441. /**
  14442. * The opposite of `_.property`; this method creates a function that returns
  14443. * the value at a given path of `object`.
  14444. *
  14445. * @static
  14446. * @memberOf _
  14447. * @since 3.0.0
  14448. * @category Util
  14449. * @param {Object} object The object to query.
  14450. * @returns {Function} Returns the new accessor function.
  14451. * @example
  14452. *
  14453. * var array = [0, 1, 2],
  14454. * object = { 'a': array, 'b': array, 'c': array };
  14455. *
  14456. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14457. * // => [2, 0]
  14458. *
  14459. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14460. * // => [2, 0]
  14461. */
  14462. function propertyOf(object) {
  14463. return function(path) {
  14464. return object == null ? undefined : baseGet(object, path);
  14465. };
  14466. }
  14467. /**
  14468. * Creates an array of numbers (positive and/or negative) progressing from
  14469. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14470. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14471. * it's set to `start` with `start` then set to `0`.
  14472. *
  14473. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14474. * floating-point values which can produce unexpected results.
  14475. *
  14476. * @static
  14477. * @since 0.1.0
  14478. * @memberOf _
  14479. * @category Util
  14480. * @param {number} [start=0] The start of the range.
  14481. * @param {number} end The end of the range.
  14482. * @param {number} [step=1] The value to increment or decrement by.
  14483. * @returns {Array} Returns the range of numbers.
  14484. * @see _.inRange, _.rangeRight
  14485. * @example
  14486. *
  14487. * _.range(4);
  14488. * // => [0, 1, 2, 3]
  14489. *
  14490. * _.range(-4);
  14491. * // => [0, -1, -2, -3]
  14492. *
  14493. * _.range(1, 5);
  14494. * // => [1, 2, 3, 4]
  14495. *
  14496. * _.range(0, 20, 5);
  14497. * // => [0, 5, 10, 15]
  14498. *
  14499. * _.range(0, -4, -1);
  14500. * // => [0, -1, -2, -3]
  14501. *
  14502. * _.range(1, 4, 0);
  14503. * // => [1, 1, 1]
  14504. *
  14505. * _.range(0);
  14506. * // => []
  14507. */
  14508. var range = createRange();
  14509. /**
  14510. * This method is like `_.range` except that it populates values in
  14511. * descending order.
  14512. *
  14513. * @static
  14514. * @memberOf _
  14515. * @since 4.0.0
  14516. * @category Util
  14517. * @param {number} [start=0] The start of the range.
  14518. * @param {number} end The end of the range.
  14519. * @param {number} [step=1] The value to increment or decrement by.
  14520. * @returns {Array} Returns the range of numbers.
  14521. * @see _.inRange, _.range
  14522. * @example
  14523. *
  14524. * _.rangeRight(4);
  14525. * // => [3, 2, 1, 0]
  14526. *
  14527. * _.rangeRight(-4);
  14528. * // => [-3, -2, -1, 0]
  14529. *
  14530. * _.rangeRight(1, 5);
  14531. * // => [4, 3, 2, 1]
  14532. *
  14533. * _.rangeRight(0, 20, 5);
  14534. * // => [15, 10, 5, 0]
  14535. *
  14536. * _.rangeRight(0, -4, -1);
  14537. * // => [-3, -2, -1, 0]
  14538. *
  14539. * _.rangeRight(1, 4, 0);
  14540. * // => [1, 1, 1]
  14541. *
  14542. * _.rangeRight(0);
  14543. * // => []
  14544. */
  14545. var rangeRight = createRange(true);
  14546. /**
  14547. * This method returns a new empty array.
  14548. *
  14549. * @static
  14550. * @memberOf _
  14551. * @since 4.13.0
  14552. * @category Util
  14553. * @returns {Array} Returns the new empty array.
  14554. * @example
  14555. *
  14556. * var arrays = _.times(2, _.stubArray);
  14557. *
  14558. * console.log(arrays);
  14559. * // => [[], []]
  14560. *
  14561. * console.log(arrays[0] === arrays[1]);
  14562. * // => false
  14563. */
  14564. function stubArray() {
  14565. return [];
  14566. }
  14567. /**
  14568. * This method returns `false`.
  14569. *
  14570. * @static
  14571. * @memberOf _
  14572. * @since 4.13.0
  14573. * @category Util
  14574. * @returns {boolean} Returns `false`.
  14575. * @example
  14576. *
  14577. * _.times(2, _.stubFalse);
  14578. * // => [false, false]
  14579. */
  14580. function stubFalse() {
  14581. return false;
  14582. }
  14583. /**
  14584. * This method returns a new empty object.
  14585. *
  14586. * @static
  14587. * @memberOf _
  14588. * @since 4.13.0
  14589. * @category Util
  14590. * @returns {Object} Returns the new empty object.
  14591. * @example
  14592. *
  14593. * var objects = _.times(2, _.stubObject);
  14594. *
  14595. * console.log(objects);
  14596. * // => [{}, {}]
  14597. *
  14598. * console.log(objects[0] === objects[1]);
  14599. * // => false
  14600. */
  14601. function stubObject() {
  14602. return {};
  14603. }
  14604. /**
  14605. * This method returns an empty string.
  14606. *
  14607. * @static
  14608. * @memberOf _
  14609. * @since 4.13.0
  14610. * @category Util
  14611. * @returns {string} Returns the empty string.
  14612. * @example
  14613. *
  14614. * _.times(2, _.stubString);
  14615. * // => ['', '']
  14616. */
  14617. function stubString() {
  14618. return '';
  14619. }
  14620. /**
  14621. * This method returns `true`.
  14622. *
  14623. * @static
  14624. * @memberOf _
  14625. * @since 4.13.0
  14626. * @category Util
  14627. * @returns {boolean} Returns `true`.
  14628. * @example
  14629. *
  14630. * _.times(2, _.stubTrue);
  14631. * // => [true, true]
  14632. */
  14633. function stubTrue() {
  14634. return true;
  14635. }
  14636. /**
  14637. * Invokes the iteratee `n` times, returning an array of the results of
  14638. * each invocation. The iteratee is invoked with one argument; (index).
  14639. *
  14640. * @static
  14641. * @since 0.1.0
  14642. * @memberOf _
  14643. * @category Util
  14644. * @param {number} n The number of times to invoke `iteratee`.
  14645. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14646. * @returns {Array} Returns the array of results.
  14647. * @example
  14648. *
  14649. * _.times(3, String);
  14650. * // => ['0', '1', '2']
  14651. *
  14652. * _.times(4, _.constant(0));
  14653. * // => [0, 0, 0, 0]
  14654. */
  14655. function times(n, iteratee) {
  14656. n = toInteger(n);
  14657. if (n < 1 || n > MAX_SAFE_INTEGER) {
  14658. return [];
  14659. }
  14660. var index = MAX_ARRAY_LENGTH,
  14661. length = nativeMin(n, MAX_ARRAY_LENGTH);
  14662. iteratee = getIteratee(iteratee);
  14663. n -= MAX_ARRAY_LENGTH;
  14664. var result = baseTimes(length, iteratee);
  14665. while (++index < n) {
  14666. iteratee(index);
  14667. }
  14668. return result;
  14669. }
  14670. /**
  14671. * Converts `value` to a property path array.
  14672. *
  14673. * @static
  14674. * @memberOf _
  14675. * @since 4.0.0
  14676. * @category Util
  14677. * @param {*} value The value to convert.
  14678. * @returns {Array} Returns the new property path array.
  14679. * @example
  14680. *
  14681. * _.toPath('a.b.c');
  14682. * // => ['a', 'b', 'c']
  14683. *
  14684. * _.toPath('a[0].b.c');
  14685. * // => ['a', '0', 'b', 'c']
  14686. */
  14687. function toPath(value) {
  14688. if (isArray(value)) {
  14689. return arrayMap(value, toKey);
  14690. }
  14691. return isSymbol(value) ? [value] : copyArray(stringToPath(value));
  14692. }
  14693. /**
  14694. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  14695. *
  14696. * @static
  14697. * @since 0.1.0
  14698. * @memberOf _
  14699. * @category Util
  14700. * @param {string} [prefix=''] The value to prefix the ID with.
  14701. * @returns {string} Returns the unique ID.
  14702. * @example
  14703. *
  14704. * _.uniqueId('contact_');
  14705. * // => 'contact_104'
  14706. *
  14707. * _.uniqueId();
  14708. * // => '105'
  14709. */
  14710. function uniqueId(prefix) {
  14711. var id = ++idCounter;
  14712. return toString(prefix) + id;
  14713. }
  14714. /*------------------------------------------------------------------------*/
  14715. /**
  14716. * Adds two numbers.
  14717. *
  14718. * @static
  14719. * @memberOf _
  14720. * @since 3.4.0
  14721. * @category Math
  14722. * @param {number} augend The first number in an addition.
  14723. * @param {number} addend The second number in an addition.
  14724. * @returns {number} Returns the total.
  14725. * @example
  14726. *
  14727. * _.add(6, 4);
  14728. * // => 10
  14729. */
  14730. var add = createMathOperation(function(augend, addend) {
  14731. return augend + addend;
  14732. }, 0);
  14733. /**
  14734. * Computes `number` rounded up to `precision`.
  14735. *
  14736. * @static
  14737. * @memberOf _
  14738. * @since 3.10.0
  14739. * @category Math
  14740. * @param {number} number The number to round up.
  14741. * @param {number} [precision=0] The precision to round up to.
  14742. * @returns {number} Returns the rounded up number.
  14743. * @example
  14744. *
  14745. * _.ceil(4.006);
  14746. * // => 5
  14747. *
  14748. * _.ceil(6.004, 2);
  14749. * // => 6.01
  14750. *
  14751. * _.ceil(6040, -2);
  14752. * // => 6100
  14753. */
  14754. var ceil = createRound('ceil');
  14755. /**
  14756. * Divide two numbers.
  14757. *
  14758. * @static
  14759. * @memberOf _
  14760. * @since 4.7.0
  14761. * @category Math
  14762. * @param {number} dividend The first number in a division.
  14763. * @param {number} divisor The second number in a division.
  14764. * @returns {number} Returns the quotient.
  14765. * @example
  14766. *
  14767. * _.divide(6, 4);
  14768. * // => 1.5
  14769. */
  14770. var divide = createMathOperation(function(dividend, divisor) {
  14771. return dividend / divisor;
  14772. }, 1);
  14773. /**
  14774. * Computes `number` rounded down to `precision`.
  14775. *
  14776. * @static
  14777. * @memberOf _
  14778. * @since 3.10.0
  14779. * @category Math
  14780. * @param {number} number The number to round down.
  14781. * @param {number} [precision=0] The precision to round down to.
  14782. * @returns {number} Returns the rounded down number.
  14783. * @example
  14784. *
  14785. * _.floor(4.006);
  14786. * // => 4
  14787. *
  14788. * _.floor(0.046, 2);
  14789. * // => 0.04
  14790. *
  14791. * _.floor(4060, -2);
  14792. * // => 4000
  14793. */
  14794. var floor = createRound('floor');
  14795. /**
  14796. * Computes the maximum value of `array`. If `array` is empty or falsey,
  14797. * `undefined` is returned.
  14798. *
  14799. * @static
  14800. * @since 0.1.0
  14801. * @memberOf _
  14802. * @category Math
  14803. * @param {Array} array The array to iterate over.
  14804. * @returns {*} Returns the maximum value.
  14805. * @example
  14806. *
  14807. * _.max([4, 2, 8, 6]);
  14808. * // => 8
  14809. *
  14810. * _.max([]);
  14811. * // => undefined
  14812. */
  14813. function max(array) {
  14814. return (array && array.length)
  14815. ? baseExtremum(array, identity, baseGt)
  14816. : undefined;
  14817. }
  14818. /**
  14819. * This method is like `_.max` except that it accepts `iteratee` which is
  14820. * invoked for each element in `array` to generate the criterion by which
  14821. * the value is ranked. The iteratee is invoked with one argument: (value).
  14822. *
  14823. * @static
  14824. * @memberOf _
  14825. * @since 4.0.0
  14826. * @category Math
  14827. * @param {Array} array The array to iterate over.
  14828. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  14829. * @returns {*} Returns the maximum value.
  14830. * @example
  14831. *
  14832. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  14833. *
  14834. * _.maxBy(objects, function(o) { return o.n; });
  14835. * // => { 'n': 2 }
  14836. *
  14837. * // The `_.property` iteratee shorthand.
  14838. * _.maxBy(objects, 'n');
  14839. * // => { 'n': 2 }
  14840. */
  14841. function maxBy(array, iteratee) {
  14842. return (array && array.length)
  14843. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  14844. : undefined;
  14845. }
  14846. /**
  14847. * Computes the mean of the values in `array`.
  14848. *
  14849. * @static
  14850. * @memberOf _
  14851. * @since 4.0.0
  14852. * @category Math
  14853. * @param {Array} array The array to iterate over.
  14854. * @returns {number} Returns the mean.
  14855. * @example
  14856. *
  14857. * _.mean([4, 2, 8, 6]);
  14858. * // => 5
  14859. */
  14860. function mean(array) {
  14861. return baseMean(array, identity);
  14862. }
  14863. /**
  14864. * This method is like `_.mean` except that it accepts `iteratee` which is
  14865. * invoked for each element in `array` to generate the value to be averaged.
  14866. * The iteratee is invoked with one argument: (value).
  14867. *
  14868. * @static
  14869. * @memberOf _
  14870. * @since 4.7.0
  14871. * @category Math
  14872. * @param {Array} array The array to iterate over.
  14873. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  14874. * @returns {number} Returns the mean.
  14875. * @example
  14876. *
  14877. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  14878. *
  14879. * _.meanBy(objects, function(o) { return o.n; });
  14880. * // => 5
  14881. *
  14882. * // The `_.property` iteratee shorthand.
  14883. * _.meanBy(objects, 'n');
  14884. * // => 5
  14885. */
  14886. function meanBy(array, iteratee) {
  14887. return baseMean(array, getIteratee(iteratee, 2));
  14888. }
  14889. /**
  14890. * Computes the minimum value of `array`. If `array` is empty or falsey,
  14891. * `undefined` is returned.
  14892. *
  14893. * @static
  14894. * @since 0.1.0
  14895. * @memberOf _
  14896. * @category Math
  14897. * @param {Array} array The array to iterate over.
  14898. * @returns {*} Returns the minimum value.
  14899. * @example
  14900. *
  14901. * _.min([4, 2, 8, 6]);
  14902. * // => 2
  14903. *
  14904. * _.min([]);
  14905. * // => undefined
  14906. */
  14907. function min(array) {
  14908. return (array && array.length)
  14909. ? baseExtremum(array, identity, baseLt)
  14910. : undefined;
  14911. }
  14912. /**
  14913. * This method is like `_.min` except that it accepts `iteratee` which is
  14914. * invoked for each element in `array` to generate the criterion by which
  14915. * the value is ranked. The iteratee is invoked with one argument: (value).
  14916. *
  14917. * @static
  14918. * @memberOf _
  14919. * @since 4.0.0
  14920. * @category Math
  14921. * @param {Array} array The array to iterate over.
  14922. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  14923. * @returns {*} Returns the minimum value.
  14924. * @example
  14925. *
  14926. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  14927. *
  14928. * _.minBy(objects, function(o) { return o.n; });
  14929. * // => { 'n': 1 }
  14930. *
  14931. * // The `_.property` iteratee shorthand.
  14932. * _.minBy(objects, 'n');
  14933. * // => { 'n': 1 }
  14934. */
  14935. function minBy(array, iteratee) {
  14936. return (array && array.length)
  14937. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  14938. : undefined;
  14939. }
  14940. /**
  14941. * Multiply two numbers.
  14942. *
  14943. * @static
  14944. * @memberOf _
  14945. * @since 4.7.0
  14946. * @category Math
  14947. * @param {number} multiplier The first number in a multiplication.
  14948. * @param {number} multiplicand The second number in a multiplication.
  14949. * @returns {number} Returns the product.
  14950. * @example
  14951. *
  14952. * _.multiply(6, 4);
  14953. * // => 24
  14954. */
  14955. var multiply = createMathOperation(function(multiplier, multiplicand) {
  14956. return multiplier * multiplicand;
  14957. }, 1);
  14958. /**
  14959. * Computes `number` rounded to `precision`.
  14960. *
  14961. * @static
  14962. * @memberOf _
  14963. * @since 3.10.0
  14964. * @category Math
  14965. * @param {number} number The number to round.
  14966. * @param {number} [precision=0] The precision to round to.
  14967. * @returns {number} Returns the rounded number.
  14968. * @example
  14969. *
  14970. * _.round(4.006);
  14971. * // => 4
  14972. *
  14973. * _.round(4.006, 2);
  14974. * // => 4.01
  14975. *
  14976. * _.round(4060, -2);
  14977. * // => 4100
  14978. */
  14979. var round = createRound('round');
  14980. /**
  14981. * Subtract two numbers.
  14982. *
  14983. * @static
  14984. * @memberOf _
  14985. * @since 4.0.0
  14986. * @category Math
  14987. * @param {number} minuend The first number in a subtraction.
  14988. * @param {number} subtrahend The second number in a subtraction.
  14989. * @returns {number} Returns the difference.
  14990. * @example
  14991. *
  14992. * _.subtract(6, 4);
  14993. * // => 2
  14994. */
  14995. var subtract = createMathOperation(function(minuend, subtrahend) {
  14996. return minuend - subtrahend;
  14997. }, 0);
  14998. /**
  14999. * Computes the sum of the values in `array`.
  15000. *
  15001. * @static
  15002. * @memberOf _
  15003. * @since 3.4.0
  15004. * @category Math
  15005. * @param {Array} array The array to iterate over.
  15006. * @returns {number} Returns the sum.
  15007. * @example
  15008. *
  15009. * _.sum([4, 2, 8, 6]);
  15010. * // => 20
  15011. */
  15012. function sum(array) {
  15013. return (array && array.length)
  15014. ? baseSum(array, identity)
  15015. : 0;
  15016. }
  15017. /**
  15018. * This method is like `_.sum` except that it accepts `iteratee` which is
  15019. * invoked for each element in `array` to generate the value to be summed.
  15020. * The iteratee is invoked with one argument: (value).
  15021. *
  15022. * @static
  15023. * @memberOf _
  15024. * @since 4.0.0
  15025. * @category Math
  15026. * @param {Array} array The array to iterate over.
  15027. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15028. * @returns {number} Returns the sum.
  15029. * @example
  15030. *
  15031. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15032. *
  15033. * _.sumBy(objects, function(o) { return o.n; });
  15034. * // => 20
  15035. *
  15036. * // The `_.property` iteratee shorthand.
  15037. * _.sumBy(objects, 'n');
  15038. * // => 20
  15039. */
  15040. function sumBy(array, iteratee) {
  15041. return (array && array.length)
  15042. ? baseSum(array, getIteratee(iteratee, 2))
  15043. : 0;
  15044. }
  15045. /*------------------------------------------------------------------------*/
  15046. // Add methods that return wrapped values in chain sequences.
  15047. lodash.after = after;
  15048. lodash.ary = ary;
  15049. lodash.assign = assign;
  15050. lodash.assignIn = assignIn;
  15051. lodash.assignInWith = assignInWith;
  15052. lodash.assignWith = assignWith;
  15053. lodash.at = at;
  15054. lodash.before = before;
  15055. lodash.bind = bind;
  15056. lodash.bindAll = bindAll;
  15057. lodash.bindKey = bindKey;
  15058. lodash.castArray = castArray;
  15059. lodash.chain = chain;
  15060. lodash.chunk = chunk;
  15061. lodash.compact = compact;
  15062. lodash.concat = concat;
  15063. lodash.cond = cond;
  15064. lodash.conforms = conforms;
  15065. lodash.constant = constant;
  15066. lodash.countBy = countBy;
  15067. lodash.create = create;
  15068. lodash.curry = curry;
  15069. lodash.curryRight = curryRight;
  15070. lodash.debounce = debounce;
  15071. lodash.defaults = defaults;
  15072. lodash.defaultsDeep = defaultsDeep;
  15073. lodash.defer = defer;
  15074. lodash.delay = delay;
  15075. lodash.difference = difference;
  15076. lodash.differenceBy = differenceBy;
  15077. lodash.differenceWith = differenceWith;
  15078. lodash.drop = drop;
  15079. lodash.dropRight = dropRight;
  15080. lodash.dropRightWhile = dropRightWhile;
  15081. lodash.dropWhile = dropWhile;
  15082. lodash.fill = fill;
  15083. lodash.filter = filter;
  15084. lodash.flatMap = flatMap;
  15085. lodash.flatMapDeep = flatMapDeep;
  15086. lodash.flatMapDepth = flatMapDepth;
  15087. lodash.flatten = flatten;
  15088. lodash.flattenDeep = flattenDeep;
  15089. lodash.flattenDepth = flattenDepth;
  15090. lodash.flip = flip;
  15091. lodash.flow = flow;
  15092. lodash.flowRight = flowRight;
  15093. lodash.fromPairs = fromPairs;
  15094. lodash.functions = functions;
  15095. lodash.functionsIn = functionsIn;
  15096. lodash.groupBy = groupBy;
  15097. lodash.initial = initial;
  15098. lodash.intersection = intersection;
  15099. lodash.intersectionBy = intersectionBy;
  15100. lodash.intersectionWith = intersectionWith;
  15101. lodash.invert = invert;
  15102. lodash.invertBy = invertBy;
  15103. lodash.invokeMap = invokeMap;
  15104. lodash.iteratee = iteratee;
  15105. lodash.keyBy = keyBy;
  15106. lodash.keys = keys;
  15107. lodash.keysIn = keysIn;
  15108. lodash.map = map;
  15109. lodash.mapKeys = mapKeys;
  15110. lodash.mapValues = mapValues;
  15111. lodash.matches = matches;
  15112. lodash.matchesProperty = matchesProperty;
  15113. lodash.memoize = memoize;
  15114. lodash.merge = merge;
  15115. lodash.mergeWith = mergeWith;
  15116. lodash.method = method;
  15117. lodash.methodOf = methodOf;
  15118. lodash.mixin = mixin;
  15119. lodash.negate = negate;
  15120. lodash.nthArg = nthArg;
  15121. lodash.omit = omit;
  15122. lodash.omitBy = omitBy;
  15123. lodash.once = once;
  15124. lodash.orderBy = orderBy;
  15125. lodash.over = over;
  15126. lodash.overArgs = overArgs;
  15127. lodash.overEvery = overEvery;
  15128. lodash.overSome = overSome;
  15129. lodash.partial = partial;
  15130. lodash.partialRight = partialRight;
  15131. lodash.partition = partition;
  15132. lodash.pick = pick;
  15133. lodash.pickBy = pickBy;
  15134. lodash.property = property;
  15135. lodash.propertyOf = propertyOf;
  15136. lodash.pull = pull;
  15137. lodash.pullAll = pullAll;
  15138. lodash.pullAllBy = pullAllBy;
  15139. lodash.pullAllWith = pullAllWith;
  15140. lodash.pullAt = pullAt;
  15141. lodash.range = range;
  15142. lodash.rangeRight = rangeRight;
  15143. lodash.rearg = rearg;
  15144. lodash.reject = reject;
  15145. lodash.remove = remove;
  15146. lodash.rest = rest;
  15147. lodash.reverse = reverse;
  15148. lodash.sampleSize = sampleSize;
  15149. lodash.set = set;
  15150. lodash.setWith = setWith;
  15151. lodash.shuffle = shuffle;
  15152. lodash.slice = slice;
  15153. lodash.sortBy = sortBy;
  15154. lodash.sortedUniq = sortedUniq;
  15155. lodash.sortedUniqBy = sortedUniqBy;
  15156. lodash.split = split;
  15157. lodash.spread = spread;
  15158. lodash.tail = tail;
  15159. lodash.take = take;
  15160. lodash.takeRight = takeRight;
  15161. lodash.takeRightWhile = takeRightWhile;
  15162. lodash.takeWhile = takeWhile;
  15163. lodash.tap = tap;
  15164. lodash.throttle = throttle;
  15165. lodash.thru = thru;
  15166. lodash.toArray = toArray;
  15167. lodash.toPairs = toPairs;
  15168. lodash.toPairsIn = toPairsIn;
  15169. lodash.toPath = toPath;
  15170. lodash.toPlainObject = toPlainObject;
  15171. lodash.transform = transform;
  15172. lodash.unary = unary;
  15173. lodash.union = union;
  15174. lodash.unionBy = unionBy;
  15175. lodash.unionWith = unionWith;
  15176. lodash.uniq = uniq;
  15177. lodash.uniqBy = uniqBy;
  15178. lodash.uniqWith = uniqWith;
  15179. lodash.unset = unset;
  15180. lodash.unzip = unzip;
  15181. lodash.unzipWith = unzipWith;
  15182. lodash.update = update;
  15183. lodash.updateWith = updateWith;
  15184. lodash.values = values;
  15185. lodash.valuesIn = valuesIn;
  15186. lodash.without = without;
  15187. lodash.words = words;
  15188. lodash.wrap = wrap;
  15189. lodash.xor = xor;
  15190. lodash.xorBy = xorBy;
  15191. lodash.xorWith = xorWith;
  15192. lodash.zip = zip;
  15193. lodash.zipObject = zipObject;
  15194. lodash.zipObjectDeep = zipObjectDeep;
  15195. lodash.zipWith = zipWith;
  15196. // Add aliases.
  15197. lodash.entries = toPairs;
  15198. lodash.entriesIn = toPairsIn;
  15199. lodash.extend = assignIn;
  15200. lodash.extendWith = assignInWith;
  15201. // Add methods to `lodash.prototype`.
  15202. mixin(lodash, lodash);
  15203. /*------------------------------------------------------------------------*/
  15204. // Add methods that return unwrapped values in chain sequences.
  15205. lodash.add = add;
  15206. lodash.attempt = attempt;
  15207. lodash.camelCase = camelCase;
  15208. lodash.capitalize = capitalize;
  15209. lodash.ceil = ceil;
  15210. lodash.clamp = clamp;
  15211. lodash.clone = clone;
  15212. lodash.cloneDeep = cloneDeep;
  15213. lodash.cloneDeepWith = cloneDeepWith;
  15214. lodash.cloneWith = cloneWith;
  15215. lodash.conformsTo = conformsTo;
  15216. lodash.deburr = deburr;
  15217. lodash.defaultTo = defaultTo;
  15218. lodash.divide = divide;
  15219. lodash.endsWith = endsWith;
  15220. lodash.eq = eq;
  15221. lodash.escape = escape;
  15222. lodash.escapeRegExp = escapeRegExp;
  15223. lodash.every = every;
  15224. lodash.find = find;
  15225. lodash.findIndex = findIndex;
  15226. lodash.findKey = findKey;
  15227. lodash.findLast = findLast;
  15228. lodash.findLastIndex = findLastIndex;
  15229. lodash.findLastKey = findLastKey;
  15230. lodash.floor = floor;
  15231. lodash.forEach = forEach;
  15232. lodash.forEachRight = forEachRight;
  15233. lodash.forIn = forIn;
  15234. lodash.forInRight = forInRight;
  15235. lodash.forOwn = forOwn;
  15236. lodash.forOwnRight = forOwnRight;
  15237. lodash.get = get;
  15238. lodash.gt = gt;
  15239. lodash.gte = gte;
  15240. lodash.has = has;
  15241. lodash.hasIn = hasIn;
  15242. lodash.head = head;
  15243. lodash.identity = identity;
  15244. lodash.includes = includes;
  15245. lodash.indexOf = indexOf;
  15246. lodash.inRange = inRange;
  15247. lodash.invoke = invoke;
  15248. lodash.isArguments = isArguments;
  15249. lodash.isArray = isArray;
  15250. lodash.isArrayBuffer = isArrayBuffer;
  15251. lodash.isArrayLike = isArrayLike;
  15252. lodash.isArrayLikeObject = isArrayLikeObject;
  15253. lodash.isBoolean = isBoolean;
  15254. lodash.isBuffer = isBuffer;
  15255. lodash.isDate = isDate;
  15256. lodash.isElement = isElement;
  15257. lodash.isEmpty = isEmpty;
  15258. lodash.isEqual = isEqual;
  15259. lodash.isEqualWith = isEqualWith;
  15260. lodash.isError = isError;
  15261. lodash.isFinite = isFinite;
  15262. lodash.isFunction = isFunction;
  15263. lodash.isInteger = isInteger;
  15264. lodash.isLength = isLength;
  15265. lodash.isMap = isMap;
  15266. lodash.isMatch = isMatch;
  15267. lodash.isMatchWith = isMatchWith;
  15268. lodash.isNaN = isNaN;
  15269. lodash.isNative = isNative;
  15270. lodash.isNil = isNil;
  15271. lodash.isNull = isNull;
  15272. lodash.isNumber = isNumber;
  15273. lodash.isObject = isObject;
  15274. lodash.isObjectLike = isObjectLike;
  15275. lodash.isPlainObject = isPlainObject;
  15276. lodash.isRegExp = isRegExp;
  15277. lodash.isSafeInteger = isSafeInteger;
  15278. lodash.isSet = isSet;
  15279. lodash.isString = isString;
  15280. lodash.isSymbol = isSymbol;
  15281. lodash.isTypedArray = isTypedArray;
  15282. lodash.isUndefined = isUndefined;
  15283. lodash.isWeakMap = isWeakMap;
  15284. lodash.isWeakSet = isWeakSet;
  15285. lodash.join = join;
  15286. lodash.kebabCase = kebabCase;
  15287. lodash.last = last;
  15288. lodash.lastIndexOf = lastIndexOf;
  15289. lodash.lowerCase = lowerCase;
  15290. lodash.lowerFirst = lowerFirst;
  15291. lodash.lt = lt;
  15292. lodash.lte = lte;
  15293. lodash.max = max;
  15294. lodash.maxBy = maxBy;
  15295. lodash.mean = mean;
  15296. lodash.meanBy = meanBy;
  15297. lodash.min = min;
  15298. lodash.minBy = minBy;
  15299. lodash.stubArray = stubArray;
  15300. lodash.stubFalse = stubFalse;
  15301. lodash.stubObject = stubObject;
  15302. lodash.stubString = stubString;
  15303. lodash.stubTrue = stubTrue;
  15304. lodash.multiply = multiply;
  15305. lodash.nth = nth;
  15306. lodash.noConflict = noConflict;
  15307. lodash.noop = noop;
  15308. lodash.now = now;
  15309. lodash.pad = pad;
  15310. lodash.padEnd = padEnd;
  15311. lodash.padStart = padStart;
  15312. lodash.parseInt = parseInt;
  15313. lodash.random = random;
  15314. lodash.reduce = reduce;
  15315. lodash.reduceRight = reduceRight;
  15316. lodash.repeat = repeat;
  15317. lodash.replace = replace;
  15318. lodash.result = result;
  15319. lodash.round = round;
  15320. lodash.runInContext = runInContext;
  15321. lodash.sample = sample;
  15322. lodash.size = size;
  15323. lodash.snakeCase = snakeCase;
  15324. lodash.some = some;
  15325. lodash.sortedIndex = sortedIndex;
  15326. lodash.sortedIndexBy = sortedIndexBy;
  15327. lodash.sortedIndexOf = sortedIndexOf;
  15328. lodash.sortedLastIndex = sortedLastIndex;
  15329. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15330. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15331. lodash.startCase = startCase;
  15332. lodash.startsWith = startsWith;
  15333. lodash.subtract = subtract;
  15334. lodash.sum = sum;
  15335. lodash.sumBy = sumBy;
  15336. lodash.template = template;
  15337. lodash.times = times;
  15338. lodash.toFinite = toFinite;
  15339. lodash.toInteger = toInteger;
  15340. lodash.toLength = toLength;
  15341. lodash.toLower = toLower;
  15342. lodash.toNumber = toNumber;
  15343. lodash.toSafeInteger = toSafeInteger;
  15344. lodash.toString = toString;
  15345. lodash.toUpper = toUpper;
  15346. lodash.trim = trim;
  15347. lodash.trimEnd = trimEnd;
  15348. lodash.trimStart = trimStart;
  15349. lodash.truncate = truncate;
  15350. lodash.unescape = unescape;
  15351. lodash.uniqueId = uniqueId;
  15352. lodash.upperCase = upperCase;
  15353. lodash.upperFirst = upperFirst;
  15354. // Add aliases.
  15355. lodash.each = forEach;
  15356. lodash.eachRight = forEachRight;
  15357. lodash.first = head;
  15358. mixin(lodash, (function() {
  15359. var source = {};
  15360. baseForOwn(lodash, function(func, methodName) {
  15361. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15362. source[methodName] = func;
  15363. }
  15364. });
  15365. return source;
  15366. }()), { 'chain': false });
  15367. /*------------------------------------------------------------------------*/
  15368. /**
  15369. * The semantic version number.
  15370. *
  15371. * @static
  15372. * @memberOf _
  15373. * @type {string}
  15374. */
  15375. lodash.VERSION = VERSION;
  15376. // Assign default placeholders.
  15377. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15378. lodash[methodName].placeholder = lodash;
  15379. });
  15380. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15381. arrayEach(['drop', 'take'], function(methodName, index) {
  15382. LazyWrapper.prototype[methodName] = function(n) {
  15383. var filtered = this.__filtered__;
  15384. if (filtered && !index) {
  15385. return new LazyWrapper(this);
  15386. }
  15387. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15388. var result = this.clone();
  15389. if (filtered) {
  15390. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15391. } else {
  15392. result.__views__.push({
  15393. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15394. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15395. });
  15396. }
  15397. return result;
  15398. };
  15399. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15400. return this.reverse()[methodName](n).reverse();
  15401. };
  15402. });
  15403. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15404. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15405. var type = index + 1,
  15406. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15407. LazyWrapper.prototype[methodName] = function(iteratee) {
  15408. var result = this.clone();
  15409. result.__iteratees__.push({
  15410. 'iteratee': getIteratee(iteratee, 3),
  15411. 'type': type
  15412. });
  15413. result.__filtered__ = result.__filtered__ || isFilter;
  15414. return result;
  15415. };
  15416. });
  15417. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15418. arrayEach(['head', 'last'], function(methodName, index) {
  15419. var takeName = 'take' + (index ? 'Right' : '');
  15420. LazyWrapper.prototype[methodName] = function() {
  15421. return this[takeName](1).value()[0];
  15422. };
  15423. });
  15424. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15425. arrayEach(['initial', 'tail'], function(methodName, index) {
  15426. var dropName = 'drop' + (index ? '' : 'Right');
  15427. LazyWrapper.prototype[methodName] = function() {
  15428. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15429. };
  15430. });
  15431. LazyWrapper.prototype.compact = function() {
  15432. return this.filter(identity);
  15433. };
  15434. LazyWrapper.prototype.find = function(predicate) {
  15435. return this.filter(predicate).head();
  15436. };
  15437. LazyWrapper.prototype.findLast = function(predicate) {
  15438. return this.reverse().find(predicate);
  15439. };
  15440. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15441. if (typeof path == 'function') {
  15442. return new LazyWrapper(this);
  15443. }
  15444. return this.map(function(value) {
  15445. return baseInvoke(value, path, args);
  15446. });
  15447. });
  15448. LazyWrapper.prototype.reject = function(predicate) {
  15449. return this.filter(negate(getIteratee(predicate)));
  15450. };
  15451. LazyWrapper.prototype.slice = function(start, end) {
  15452. start = toInteger(start);
  15453. var result = this;
  15454. if (result.__filtered__ && (start > 0 || end < 0)) {
  15455. return new LazyWrapper(result);
  15456. }
  15457. if (start < 0) {
  15458. result = result.takeRight(-start);
  15459. } else if (start) {
  15460. result = result.drop(start);
  15461. }
  15462. if (end !== undefined) {
  15463. end = toInteger(end);
  15464. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15465. }
  15466. return result;
  15467. };
  15468. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15469. return this.reverse().takeWhile(predicate).reverse();
  15470. };
  15471. LazyWrapper.prototype.toArray = function() {
  15472. return this.take(MAX_ARRAY_LENGTH);
  15473. };
  15474. // Add `LazyWrapper` methods to `lodash.prototype`.
  15475. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15476. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15477. isTaker = /^(?:head|last)$/.test(methodName),
  15478. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15479. retUnwrapped = isTaker || /^find/.test(methodName);
  15480. if (!lodashFunc) {
  15481. return;
  15482. }
  15483. lodash.prototype[methodName] = function() {
  15484. var value = this.__wrapped__,
  15485. args = isTaker ? [1] : arguments,
  15486. isLazy = value instanceof LazyWrapper,
  15487. iteratee = args[0],
  15488. useLazy = isLazy || isArray(value);
  15489. var interceptor = function(value) {
  15490. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15491. return (isTaker && chainAll) ? result[0] : result;
  15492. };
  15493. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15494. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15495. isLazy = useLazy = false;
  15496. }
  15497. var chainAll = this.__chain__,
  15498. isHybrid = !!this.__actions__.length,
  15499. isUnwrapped = retUnwrapped && !chainAll,
  15500. onlyLazy = isLazy && !isHybrid;
  15501. if (!retUnwrapped && useLazy) {
  15502. value = onlyLazy ? value : new LazyWrapper(this);
  15503. var result = func.apply(value, args);
  15504. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15505. return new LodashWrapper(result, chainAll);
  15506. }
  15507. if (isUnwrapped && onlyLazy) {
  15508. return func.apply(this, args);
  15509. }
  15510. result = this.thru(interceptor);
  15511. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15512. };
  15513. });
  15514. // Add `Array` methods to `lodash.prototype`.
  15515. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15516. var func = arrayProto[methodName],
  15517. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15518. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15519. lodash.prototype[methodName] = function() {
  15520. var args = arguments;
  15521. if (retUnwrapped && !this.__chain__) {
  15522. var value = this.value();
  15523. return func.apply(isArray(value) ? value : [], args);
  15524. }
  15525. return this[chainName](function(value) {
  15526. return func.apply(isArray(value) ? value : [], args);
  15527. });
  15528. };
  15529. });
  15530. // Map minified method names to their real names.
  15531. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15532. var lodashFunc = lodash[methodName];
  15533. if (lodashFunc) {
  15534. var key = (lodashFunc.name + ''),
  15535. names = realNames[key] || (realNames[key] = []);
  15536. names.push({ 'name': methodName, 'func': lodashFunc });
  15537. }
  15538. });
  15539. realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{
  15540. 'name': 'wrapper',
  15541. 'func': undefined
  15542. }];
  15543. // Add methods to `LazyWrapper`.
  15544. LazyWrapper.prototype.clone = lazyClone;
  15545. LazyWrapper.prototype.reverse = lazyReverse;
  15546. LazyWrapper.prototype.value = lazyValue;
  15547. // Add chain sequence methods to the `lodash` wrapper.
  15548. lodash.prototype.at = wrapperAt;
  15549. lodash.prototype.chain = wrapperChain;
  15550. lodash.prototype.commit = wrapperCommit;
  15551. lodash.prototype.next = wrapperNext;
  15552. lodash.prototype.plant = wrapperPlant;
  15553. lodash.prototype.reverse = wrapperReverse;
  15554. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  15555. // Add lazy aliases.
  15556. lodash.prototype.first = lodash.prototype.head;
  15557. if (iteratorSymbol) {
  15558. lodash.prototype[iteratorSymbol] = wrapperToIterator;
  15559. }
  15560. return lodash;
  15561. }
  15562. /*--------------------------------------------------------------------------*/
  15563. // Export lodash.
  15564. var _ = runInContext();
  15565. // Some AMD build optimizers, like r.js, check for condition patterns like:
  15566. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  15567. // Expose Lodash on the global object to prevent errors when Lodash is
  15568. // loaded by a script tag in the presence of an AMD loader.
  15569. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  15570. // Use `_.noConflict` to remove Lodash from the global object.
  15571. root._ = _;
  15572. // Define as an anonymous module so, through path mapping, it can be
  15573. // referenced as the "underscore" module.
  15574. define(function() {
  15575. return _;
  15576. });
  15577. }
  15578. // Check for `exports` after `define` in case a build optimizer adds it.
  15579. else if (freeModule) {
  15580. // Export for Node.js.
  15581. (freeModule.exports = _)._ = _;
  15582. // Export for CommonJS support.
  15583. freeExports._ = _;
  15584. }
  15585. else {
  15586. // Export to the global object.
  15587. root._ = _;
  15588. }
  15589. }.call(this));