Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lodash.js 531KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209
  1. /**
  2. * @license
  3. * Lodash <https://lodash.com/>
  4. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.17.21';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Error message constants. */
  17. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  18. FUNC_ERROR_TEXT = 'Expected a function',
  19. INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
  20. /** Used to stand-in for `undefined` hash values. */
  21. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  22. /** Used as the maximum memoize cache size. */
  23. var MAX_MEMOIZE_SIZE = 500;
  24. /** Used as the internal argument placeholder. */
  25. var PLACEHOLDER = '__lodash_placeholder__';
  26. /** Used to compose bitmasks for cloning. */
  27. var CLONE_DEEP_FLAG = 1,
  28. CLONE_FLAT_FLAG = 2,
  29. CLONE_SYMBOLS_FLAG = 4;
  30. /** Used to compose bitmasks for value comparisons. */
  31. var COMPARE_PARTIAL_FLAG = 1,
  32. COMPARE_UNORDERED_FLAG = 2;
  33. /** Used to compose bitmasks for function metadata. */
  34. var WRAP_BIND_FLAG = 1,
  35. WRAP_BIND_KEY_FLAG = 2,
  36. WRAP_CURRY_BOUND_FLAG = 4,
  37. WRAP_CURRY_FLAG = 8,
  38. WRAP_CURRY_RIGHT_FLAG = 16,
  39. WRAP_PARTIAL_FLAG = 32,
  40. WRAP_PARTIAL_RIGHT_FLAG = 64,
  41. WRAP_ARY_FLAG = 128,
  42. WRAP_REARG_FLAG = 256,
  43. WRAP_FLIP_FLAG = 512;
  44. /** Used as default options for `_.truncate`. */
  45. var DEFAULT_TRUNC_LENGTH = 30,
  46. DEFAULT_TRUNC_OMISSION = '...';
  47. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  48. var HOT_COUNT = 800,
  49. HOT_SPAN = 16;
  50. /** Used to indicate the type of lazy iteratees. */
  51. var LAZY_FILTER_FLAG = 1,
  52. LAZY_MAP_FLAG = 2,
  53. LAZY_WHILE_FLAG = 3;
  54. /** Used as references for various `Number` constants. */
  55. var INFINITY = 1 / 0,
  56. MAX_SAFE_INTEGER = 9007199254740991,
  57. MAX_INTEGER = 1.7976931348623157e+308,
  58. NAN = 0 / 0;
  59. /** Used as references for the maximum length and index of an array. */
  60. var MAX_ARRAY_LENGTH = 4294967295,
  61. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  62. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  63. /** Used to associate wrap methods with their bit flags. */
  64. var wrapFlags = [
  65. ['ary', WRAP_ARY_FLAG],
  66. ['bind', WRAP_BIND_FLAG],
  67. ['bindKey', WRAP_BIND_KEY_FLAG],
  68. ['curry', WRAP_CURRY_FLAG],
  69. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  70. ['flip', WRAP_FLIP_FLAG],
  71. ['partial', WRAP_PARTIAL_FLAG],
  72. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  73. ['rearg', WRAP_REARG_FLAG]
  74. ];
  75. /** `Object#toString` result references. */
  76. var argsTag = '[object Arguments]',
  77. arrayTag = '[object Array]',
  78. asyncTag = '[object AsyncFunction]',
  79. boolTag = '[object Boolean]',
  80. dateTag = '[object Date]',
  81. domExcTag = '[object DOMException]',
  82. errorTag = '[object Error]',
  83. funcTag = '[object Function]',
  84. genTag = '[object GeneratorFunction]',
  85. mapTag = '[object Map]',
  86. numberTag = '[object Number]',
  87. nullTag = '[object Null]',
  88. objectTag = '[object Object]',
  89. promiseTag = '[object Promise]',
  90. proxyTag = '[object Proxy]',
  91. regexpTag = '[object RegExp]',
  92. setTag = '[object Set]',
  93. stringTag = '[object String]',
  94. symbolTag = '[object Symbol]',
  95. undefinedTag = '[object Undefined]',
  96. weakMapTag = '[object WeakMap]',
  97. weakSetTag = '[object WeakSet]';
  98. var arrayBufferTag = '[object ArrayBuffer]',
  99. dataViewTag = '[object DataView]',
  100. float32Tag = '[object Float32Array]',
  101. float64Tag = '[object Float64Array]',
  102. int8Tag = '[object Int8Array]',
  103. int16Tag = '[object Int16Array]',
  104. int32Tag = '[object Int32Array]',
  105. uint8Tag = '[object Uint8Array]',
  106. uint8ClampedTag = '[object Uint8ClampedArray]',
  107. uint16Tag = '[object Uint16Array]',
  108. uint32Tag = '[object Uint32Array]';
  109. /** Used to match empty string literals in compiled template source. */
  110. var reEmptyStringLeading = /\b__p \+= '';/g,
  111. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  112. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  113. /** Used to match HTML entities and HTML characters. */
  114. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  115. reUnescapedHtml = /[&<>"']/g,
  116. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  117. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  118. /** Used to match template delimiters. */
  119. var reEscape = /<%-([\s\S]+?)%>/g,
  120. reEvaluate = /<%([\s\S]+?)%>/g,
  121. reInterpolate = /<%=([\s\S]+?)%>/g;
  122. /** Used to match property names within property paths. */
  123. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  124. reIsPlainProp = /^\w*$/,
  125. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  126. /**
  127. * Used to match `RegExp`
  128. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  129. */
  130. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  131. reHasRegExpChar = RegExp(reRegExpChar.source);
  132. /** Used to match leading whitespace. */
  133. var reTrimStart = /^\s+/;
  134. /** Used to match a single whitespace character. */
  135. var reWhitespace = /\s/;
  136. /** Used to match wrap detail comments. */
  137. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  138. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  139. reSplitDetails = /,? & /;
  140. /** Used to match words composed of alphanumeric characters. */
  141. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  142. /**
  143. * Used to validate the `validate` option in `_.template` variable.
  144. *
  145. * Forbids characters which could potentially change the meaning of the function argument definition:
  146. * - "()," (modification of function parameters)
  147. * - "=" (default value)
  148. * - "[]{}" (destructuring of function parameters)
  149. * - "/" (beginning of a comment)
  150. * - whitespace
  151. */
  152. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  153. /** Used to match backslashes in property paths. */
  154. var reEscapeChar = /\\(\\)?/g;
  155. /**
  156. * Used to match
  157. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  158. */
  159. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  160. /** Used to match `RegExp` flags from their coerced string values. */
  161. var reFlags = /\w*$/;
  162. /** Used to detect bad signed hexadecimal string values. */
  163. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  164. /** Used to detect binary string values. */
  165. var reIsBinary = /^0b[01]+$/i;
  166. /** Used to detect host constructors (Safari). */
  167. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  168. /** Used to detect octal string values. */
  169. var reIsOctal = /^0o[0-7]+$/i;
  170. /** Used to detect unsigned integer values. */
  171. var reIsUint = /^(?:0|[1-9]\d*)$/;
  172. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  173. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  174. /** Used to ensure capturing order of template delimiters. */
  175. var reNoMatch = /($^)/;
  176. /** Used to match unescaped characters in compiled string literals. */
  177. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  178. /** Used to compose unicode character classes. */
  179. var rsAstralRange = '\\ud800-\\udfff',
  180. rsComboMarksRange = '\\u0300-\\u036f',
  181. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  182. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  183. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  184. rsDingbatRange = '\\u2700-\\u27bf',
  185. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  186. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  187. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  188. rsPunctuationRange = '\\u2000-\\u206f',
  189. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  190. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  191. rsVarRange = '\\ufe0e\\ufe0f',
  192. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  193. /** Used to compose unicode capture groups. */
  194. var rsApos = "['\u2019]",
  195. rsAstral = '[' + rsAstralRange + ']',
  196. rsBreak = '[' + rsBreakRange + ']',
  197. rsCombo = '[' + rsComboRange + ']',
  198. rsDigits = '\\d+',
  199. rsDingbat = '[' + rsDingbatRange + ']',
  200. rsLower = '[' + rsLowerRange + ']',
  201. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  202. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  203. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  204. rsNonAstral = '[^' + rsAstralRange + ']',
  205. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  206. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  207. rsUpper = '[' + rsUpperRange + ']',
  208. rsZWJ = '\\u200d';
  209. /** Used to compose unicode regexes. */
  210. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  211. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  212. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  213. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  214. reOptMod = rsModifier + '?',
  215. rsOptVar = '[' + rsVarRange + ']?',
  216. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  217. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  218. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  219. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  220. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  221. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  222. /** Used to match apostrophes. */
  223. var reApos = RegExp(rsApos, 'g');
  224. /**
  225. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  226. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  227. */
  228. var reComboMark = RegExp(rsCombo, 'g');
  229. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  230. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  231. /** Used to match complex or compound words. */
  232. var reUnicodeWord = RegExp([
  233. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  234. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  235. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  236. rsUpper + '+' + rsOptContrUpper,
  237. rsOrdUpper,
  238. rsOrdLower,
  239. rsDigits,
  240. rsEmoji
  241. ].join('|'), 'g');
  242. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  243. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  244. /** Used to detect strings that need a more robust regexp to match words. */
  245. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  246. /** Used to assign default `context` object properties. */
  247. var contextProps = [
  248. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  249. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  250. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  251. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  252. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  253. ];
  254. /** Used to make template sourceURLs easier to identify. */
  255. var templateCounter = -1;
  256. /** Used to identify `toStringTag` values of typed arrays. */
  257. var typedArrayTags = {};
  258. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  259. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  260. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  261. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  262. typedArrayTags[uint32Tag] = true;
  263. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  264. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  265. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  266. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  267. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  268. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  269. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  270. typedArrayTags[weakMapTag] = false;
  271. /** Used to identify `toStringTag` values supported by `_.clone`. */
  272. var cloneableTags = {};
  273. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  274. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  275. cloneableTags[boolTag] = cloneableTags[dateTag] =
  276. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  277. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  278. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  279. cloneableTags[numberTag] = cloneableTags[objectTag] =
  280. cloneableTags[regexpTag] = cloneableTags[setTag] =
  281. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  282. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  283. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  284. cloneableTags[errorTag] = cloneableTags[funcTag] =
  285. cloneableTags[weakMapTag] = false;
  286. /** Used to map Latin Unicode letters to basic Latin letters. */
  287. var deburredLetters = {
  288. // Latin-1 Supplement block.
  289. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  290. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  291. '\xc7': 'C', '\xe7': 'c',
  292. '\xd0': 'D', '\xf0': 'd',
  293. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  294. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  295. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  296. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  297. '\xd1': 'N', '\xf1': 'n',
  298. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  299. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  300. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  301. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  302. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  303. '\xc6': 'Ae', '\xe6': 'ae',
  304. '\xde': 'Th', '\xfe': 'th',
  305. '\xdf': 'ss',
  306. // Latin Extended-A block.
  307. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  308. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  309. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  310. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  311. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  312. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  313. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  314. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  315. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  316. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  317. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  318. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  319. '\u0134': 'J', '\u0135': 'j',
  320. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  321. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  322. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  323. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  324. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  325. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  326. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  327. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  328. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  329. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  330. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  331. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  332. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  333. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  334. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  335. '\u0174': 'W', '\u0175': 'w',
  336. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  337. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  338. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  339. '\u0132': 'IJ', '\u0133': 'ij',
  340. '\u0152': 'Oe', '\u0153': 'oe',
  341. '\u0149': "'n", '\u017f': 's'
  342. };
  343. /** Used to map characters to HTML entities. */
  344. var htmlEscapes = {
  345. '&': '&amp;',
  346. '<': '&lt;',
  347. '>': '&gt;',
  348. '"': '&quot;',
  349. "'": '&#39;'
  350. };
  351. /** Used to map HTML entities to characters. */
  352. var htmlUnescapes = {
  353. '&amp;': '&',
  354. '&lt;': '<',
  355. '&gt;': '>',
  356. '&quot;': '"',
  357. '&#39;': "'"
  358. };
  359. /** Used to escape characters for inclusion in compiled string literals. */
  360. var stringEscapes = {
  361. '\\': '\\',
  362. "'": "'",
  363. '\n': 'n',
  364. '\r': 'r',
  365. '\u2028': 'u2028',
  366. '\u2029': 'u2029'
  367. };
  368. /** Built-in method references without a dependency on `root`. */
  369. var freeParseFloat = parseFloat,
  370. freeParseInt = parseInt;
  371. /** Detect free variable `global` from Node.js. */
  372. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  373. /** Detect free variable `self`. */
  374. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  375. /** Used as a reference to the global object. */
  376. var root = freeGlobal || freeSelf || Function('return this')();
  377. /** Detect free variable `exports`. */
  378. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  379. /** Detect free variable `module`. */
  380. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  381. /** Detect the popular CommonJS extension `module.exports`. */
  382. var moduleExports = freeModule && freeModule.exports === freeExports;
  383. /** Detect free variable `process` from Node.js. */
  384. var freeProcess = moduleExports && freeGlobal.process;
  385. /** Used to access faster Node.js helpers. */
  386. var nodeUtil = (function() {
  387. try {
  388. // Use `util.types` for Node.js 10+.
  389. var types = freeModule && freeModule.require && freeModule.require('util').types;
  390. if (types) {
  391. return types;
  392. }
  393. // Legacy `process.binding('util')` for Node.js < 10.
  394. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  395. } catch (e) {}
  396. }());
  397. /* Node.js helper references. */
  398. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  399. nodeIsDate = nodeUtil && nodeUtil.isDate,
  400. nodeIsMap = nodeUtil && nodeUtil.isMap,
  401. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  402. nodeIsSet = nodeUtil && nodeUtil.isSet,
  403. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  404. /*--------------------------------------------------------------------------*/
  405. /**
  406. * A faster alternative to `Function#apply`, this function invokes `func`
  407. * with the `this` binding of `thisArg` and the arguments of `args`.
  408. *
  409. * @private
  410. * @param {Function} func The function to invoke.
  411. * @param {*} thisArg The `this` binding of `func`.
  412. * @param {Array} args The arguments to invoke `func` with.
  413. * @returns {*} Returns the result of `func`.
  414. */
  415. function apply(func, thisArg, args) {
  416. switch (args.length) {
  417. case 0: return func.call(thisArg);
  418. case 1: return func.call(thisArg, args[0]);
  419. case 2: return func.call(thisArg, args[0], args[1]);
  420. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  421. }
  422. return func.apply(thisArg, args);
  423. }
  424. /**
  425. * A specialized version of `baseAggregator` for arrays.
  426. *
  427. * @private
  428. * @param {Array} [array] The array to iterate over.
  429. * @param {Function} setter The function to set `accumulator` values.
  430. * @param {Function} iteratee The iteratee to transform keys.
  431. * @param {Object} accumulator The initial aggregated object.
  432. * @returns {Function} Returns `accumulator`.
  433. */
  434. function arrayAggregator(array, setter, iteratee, accumulator) {
  435. var index = -1,
  436. length = array == null ? 0 : array.length;
  437. while (++index < length) {
  438. var value = array[index];
  439. setter(accumulator, value, iteratee(value), array);
  440. }
  441. return accumulator;
  442. }
  443. /**
  444. * A specialized version of `_.forEach` for arrays without support for
  445. * iteratee shorthands.
  446. *
  447. * @private
  448. * @param {Array} [array] The array to iterate over.
  449. * @param {Function} iteratee The function invoked per iteration.
  450. * @returns {Array} Returns `array`.
  451. */
  452. function arrayEach(array, iteratee) {
  453. var index = -1,
  454. length = array == null ? 0 : array.length;
  455. while (++index < length) {
  456. if (iteratee(array[index], index, array) === false) {
  457. break;
  458. }
  459. }
  460. return array;
  461. }
  462. /**
  463. * A specialized version of `_.forEachRight` for arrays without support for
  464. * iteratee shorthands.
  465. *
  466. * @private
  467. * @param {Array} [array] The array to iterate over.
  468. * @param {Function} iteratee The function invoked per iteration.
  469. * @returns {Array} Returns `array`.
  470. */
  471. function arrayEachRight(array, iteratee) {
  472. var length = array == null ? 0 : array.length;
  473. while (length--) {
  474. if (iteratee(array[length], length, array) === false) {
  475. break;
  476. }
  477. }
  478. return array;
  479. }
  480. /**
  481. * A specialized version of `_.every` for arrays without support for
  482. * iteratee shorthands.
  483. *
  484. * @private
  485. * @param {Array} [array] The array to iterate over.
  486. * @param {Function} predicate The function invoked per iteration.
  487. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  488. * else `false`.
  489. */
  490. function arrayEvery(array, predicate) {
  491. var index = -1,
  492. length = array == null ? 0 : array.length;
  493. while (++index < length) {
  494. if (!predicate(array[index], index, array)) {
  495. return false;
  496. }
  497. }
  498. return true;
  499. }
  500. /**
  501. * A specialized version of `_.filter` for arrays without support for
  502. * iteratee shorthands.
  503. *
  504. * @private
  505. * @param {Array} [array] The array to iterate over.
  506. * @param {Function} predicate The function invoked per iteration.
  507. * @returns {Array} Returns the new filtered array.
  508. */
  509. function arrayFilter(array, predicate) {
  510. var index = -1,
  511. length = array == null ? 0 : array.length,
  512. resIndex = 0,
  513. result = [];
  514. while (++index < length) {
  515. var value = array[index];
  516. if (predicate(value, index, array)) {
  517. result[resIndex++] = value;
  518. }
  519. }
  520. return result;
  521. }
  522. /**
  523. * A specialized version of `_.includes` for arrays without support for
  524. * specifying an index to search from.
  525. *
  526. * @private
  527. * @param {Array} [array] The array to inspect.
  528. * @param {*} target The value to search for.
  529. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  530. */
  531. function arrayIncludes(array, value) {
  532. var length = array == null ? 0 : array.length;
  533. return !!length && baseIndexOf(array, value, 0) > -1;
  534. }
  535. /**
  536. * This function is like `arrayIncludes` except that it accepts a comparator.
  537. *
  538. * @private
  539. * @param {Array} [array] The array to inspect.
  540. * @param {*} target The value to search for.
  541. * @param {Function} comparator The comparator invoked per element.
  542. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  543. */
  544. function arrayIncludesWith(array, value, comparator) {
  545. var index = -1,
  546. length = array == null ? 0 : array.length;
  547. while (++index < length) {
  548. if (comparator(value, array[index])) {
  549. return true;
  550. }
  551. }
  552. return false;
  553. }
  554. /**
  555. * A specialized version of `_.map` for arrays without support for iteratee
  556. * shorthands.
  557. *
  558. * @private
  559. * @param {Array} [array] The array to iterate over.
  560. * @param {Function} iteratee The function invoked per iteration.
  561. * @returns {Array} Returns the new mapped array.
  562. */
  563. function arrayMap(array, iteratee) {
  564. var index = -1,
  565. length = array == null ? 0 : array.length,
  566. result = Array(length);
  567. while (++index < length) {
  568. result[index] = iteratee(array[index], index, array);
  569. }
  570. return result;
  571. }
  572. /**
  573. * Appends the elements of `values` to `array`.
  574. *
  575. * @private
  576. * @param {Array} array The array to modify.
  577. * @param {Array} values The values to append.
  578. * @returns {Array} Returns `array`.
  579. */
  580. function arrayPush(array, values) {
  581. var index = -1,
  582. length = values.length,
  583. offset = array.length;
  584. while (++index < length) {
  585. array[offset + index] = values[index];
  586. }
  587. return array;
  588. }
  589. /**
  590. * A specialized version of `_.reduce` for arrays without support for
  591. * iteratee shorthands.
  592. *
  593. * @private
  594. * @param {Array} [array] The array to iterate over.
  595. * @param {Function} iteratee The function invoked per iteration.
  596. * @param {*} [accumulator] The initial value.
  597. * @param {boolean} [initAccum] Specify using the first element of `array` as
  598. * the initial value.
  599. * @returns {*} Returns the accumulated value.
  600. */
  601. function arrayReduce(array, iteratee, accumulator, initAccum) {
  602. var index = -1,
  603. length = array == null ? 0 : array.length;
  604. if (initAccum && length) {
  605. accumulator = array[++index];
  606. }
  607. while (++index < length) {
  608. accumulator = iteratee(accumulator, array[index], index, array);
  609. }
  610. return accumulator;
  611. }
  612. /**
  613. * A specialized version of `_.reduceRight` for arrays without support for
  614. * iteratee shorthands.
  615. *
  616. * @private
  617. * @param {Array} [array] The array to iterate over.
  618. * @param {Function} iteratee The function invoked per iteration.
  619. * @param {*} [accumulator] The initial value.
  620. * @param {boolean} [initAccum] Specify using the last element of `array` as
  621. * the initial value.
  622. * @returns {*} Returns the accumulated value.
  623. */
  624. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  625. var length = array == null ? 0 : array.length;
  626. if (initAccum && length) {
  627. accumulator = array[--length];
  628. }
  629. while (length--) {
  630. accumulator = iteratee(accumulator, array[length], length, array);
  631. }
  632. return accumulator;
  633. }
  634. /**
  635. * A specialized version of `_.some` for arrays without support for iteratee
  636. * shorthands.
  637. *
  638. * @private
  639. * @param {Array} [array] The array to iterate over.
  640. * @param {Function} predicate The function invoked per iteration.
  641. * @returns {boolean} Returns `true` if any element passes the predicate check,
  642. * else `false`.
  643. */
  644. function arraySome(array, predicate) {
  645. var index = -1,
  646. length = array == null ? 0 : array.length;
  647. while (++index < length) {
  648. if (predicate(array[index], index, array)) {
  649. return true;
  650. }
  651. }
  652. return false;
  653. }
  654. /**
  655. * Gets the size of an ASCII `string`.
  656. *
  657. * @private
  658. * @param {string} string The string inspect.
  659. * @returns {number} Returns the string size.
  660. */
  661. var asciiSize = baseProperty('length');
  662. /**
  663. * Converts an ASCII `string` to an array.
  664. *
  665. * @private
  666. * @param {string} string The string to convert.
  667. * @returns {Array} Returns the converted array.
  668. */
  669. function asciiToArray(string) {
  670. return string.split('');
  671. }
  672. /**
  673. * Splits an ASCII `string` into an array of its words.
  674. *
  675. * @private
  676. * @param {string} The string to inspect.
  677. * @returns {Array} Returns the words of `string`.
  678. */
  679. function asciiWords(string) {
  680. return string.match(reAsciiWord) || [];
  681. }
  682. /**
  683. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  684. * without support for iteratee shorthands, which iterates over `collection`
  685. * using `eachFunc`.
  686. *
  687. * @private
  688. * @param {Array|Object} collection The collection to inspect.
  689. * @param {Function} predicate The function invoked per iteration.
  690. * @param {Function} eachFunc The function to iterate over `collection`.
  691. * @returns {*} Returns the found element or its key, else `undefined`.
  692. */
  693. function baseFindKey(collection, predicate, eachFunc) {
  694. var result;
  695. eachFunc(collection, function(value, key, collection) {
  696. if (predicate(value, key, collection)) {
  697. result = key;
  698. return false;
  699. }
  700. });
  701. return result;
  702. }
  703. /**
  704. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  705. * support for iteratee shorthands.
  706. *
  707. * @private
  708. * @param {Array} array The array to inspect.
  709. * @param {Function} predicate The function invoked per iteration.
  710. * @param {number} fromIndex The index to search from.
  711. * @param {boolean} [fromRight] Specify iterating from right to left.
  712. * @returns {number} Returns the index of the matched value, else `-1`.
  713. */
  714. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  715. var length = array.length,
  716. index = fromIndex + (fromRight ? 1 : -1);
  717. while ((fromRight ? index-- : ++index < length)) {
  718. if (predicate(array[index], index, array)) {
  719. return index;
  720. }
  721. }
  722. return -1;
  723. }
  724. /**
  725. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  726. *
  727. * @private
  728. * @param {Array} array The array to inspect.
  729. * @param {*} value The value to search for.
  730. * @param {number} fromIndex The index to search from.
  731. * @returns {number} Returns the index of the matched value, else `-1`.
  732. */
  733. function baseIndexOf(array, value, fromIndex) {
  734. return value === value
  735. ? strictIndexOf(array, value, fromIndex)
  736. : baseFindIndex(array, baseIsNaN, fromIndex);
  737. }
  738. /**
  739. * This function is like `baseIndexOf` except that it accepts a comparator.
  740. *
  741. * @private
  742. * @param {Array} array The array to inspect.
  743. * @param {*} value The value to search for.
  744. * @param {number} fromIndex The index to search from.
  745. * @param {Function} comparator The comparator invoked per element.
  746. * @returns {number} Returns the index of the matched value, else `-1`.
  747. */
  748. function baseIndexOfWith(array, value, fromIndex, comparator) {
  749. var index = fromIndex - 1,
  750. length = array.length;
  751. while (++index < length) {
  752. if (comparator(array[index], value)) {
  753. return index;
  754. }
  755. }
  756. return -1;
  757. }
  758. /**
  759. * The base implementation of `_.isNaN` without support for number objects.
  760. *
  761. * @private
  762. * @param {*} value The value to check.
  763. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  764. */
  765. function baseIsNaN(value) {
  766. return value !== value;
  767. }
  768. /**
  769. * The base implementation of `_.mean` and `_.meanBy` without support for
  770. * iteratee shorthands.
  771. *
  772. * @private
  773. * @param {Array} array The array to iterate over.
  774. * @param {Function} iteratee The function invoked per iteration.
  775. * @returns {number} Returns the mean.
  776. */
  777. function baseMean(array, iteratee) {
  778. var length = array == null ? 0 : array.length;
  779. return length ? (baseSum(array, iteratee) / length) : NAN;
  780. }
  781. /**
  782. * The base implementation of `_.property` without support for deep paths.
  783. *
  784. * @private
  785. * @param {string} key The key of the property to get.
  786. * @returns {Function} Returns the new accessor function.
  787. */
  788. function baseProperty(key) {
  789. return function(object) {
  790. return object == null ? undefined : object[key];
  791. };
  792. }
  793. /**
  794. * The base implementation of `_.propertyOf` without support for deep paths.
  795. *
  796. * @private
  797. * @param {Object} object The object to query.
  798. * @returns {Function} Returns the new accessor function.
  799. */
  800. function basePropertyOf(object) {
  801. return function(key) {
  802. return object == null ? undefined : object[key];
  803. };
  804. }
  805. /**
  806. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  807. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  808. *
  809. * @private
  810. * @param {Array|Object} collection The collection to iterate over.
  811. * @param {Function} iteratee The function invoked per iteration.
  812. * @param {*} accumulator The initial value.
  813. * @param {boolean} initAccum Specify using the first or last element of
  814. * `collection` as the initial value.
  815. * @param {Function} eachFunc The function to iterate over `collection`.
  816. * @returns {*} Returns the accumulated value.
  817. */
  818. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  819. eachFunc(collection, function(value, index, collection) {
  820. accumulator = initAccum
  821. ? (initAccum = false, value)
  822. : iteratee(accumulator, value, index, collection);
  823. });
  824. return accumulator;
  825. }
  826. /**
  827. * The base implementation of `_.sortBy` which uses `comparer` to define the
  828. * sort order of `array` and replaces criteria objects with their corresponding
  829. * values.
  830. *
  831. * @private
  832. * @param {Array} array The array to sort.
  833. * @param {Function} comparer The function to define sort order.
  834. * @returns {Array} Returns `array`.
  835. */
  836. function baseSortBy(array, comparer) {
  837. var length = array.length;
  838. array.sort(comparer);
  839. while (length--) {
  840. array[length] = array[length].value;
  841. }
  842. return array;
  843. }
  844. /**
  845. * The base implementation of `_.sum` and `_.sumBy` without support for
  846. * iteratee shorthands.
  847. *
  848. * @private
  849. * @param {Array} array The array to iterate over.
  850. * @param {Function} iteratee The function invoked per iteration.
  851. * @returns {number} Returns the sum.
  852. */
  853. function baseSum(array, iteratee) {
  854. var result,
  855. index = -1,
  856. length = array.length;
  857. while (++index < length) {
  858. var current = iteratee(array[index]);
  859. if (current !== undefined) {
  860. result = result === undefined ? current : (result + current);
  861. }
  862. }
  863. return result;
  864. }
  865. /**
  866. * The base implementation of `_.times` without support for iteratee shorthands
  867. * or max array length checks.
  868. *
  869. * @private
  870. * @param {number} n The number of times to invoke `iteratee`.
  871. * @param {Function} iteratee The function invoked per iteration.
  872. * @returns {Array} Returns the array of results.
  873. */
  874. function baseTimes(n, iteratee) {
  875. var index = -1,
  876. result = Array(n);
  877. while (++index < n) {
  878. result[index] = iteratee(index);
  879. }
  880. return result;
  881. }
  882. /**
  883. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  884. * of key-value pairs for `object` corresponding to the property names of `props`.
  885. *
  886. * @private
  887. * @param {Object} object The object to query.
  888. * @param {Array} props The property names to get values for.
  889. * @returns {Object} Returns the key-value pairs.
  890. */
  891. function baseToPairs(object, props) {
  892. return arrayMap(props, function(key) {
  893. return [key, object[key]];
  894. });
  895. }
  896. /**
  897. * The base implementation of `_.trim`.
  898. *
  899. * @private
  900. * @param {string} string The string to trim.
  901. * @returns {string} Returns the trimmed string.
  902. */
  903. function baseTrim(string) {
  904. return string
  905. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  906. : string;
  907. }
  908. /**
  909. * The base implementation of `_.unary` without support for storing metadata.
  910. *
  911. * @private
  912. * @param {Function} func The function to cap arguments for.
  913. * @returns {Function} Returns the new capped function.
  914. */
  915. function baseUnary(func) {
  916. return function(value) {
  917. return func(value);
  918. };
  919. }
  920. /**
  921. * The base implementation of `_.values` and `_.valuesIn` which creates an
  922. * array of `object` property values corresponding to the property names
  923. * of `props`.
  924. *
  925. * @private
  926. * @param {Object} object The object to query.
  927. * @param {Array} props The property names to get values for.
  928. * @returns {Object} Returns the array of property values.
  929. */
  930. function baseValues(object, props) {
  931. return arrayMap(props, function(key) {
  932. return object[key];
  933. });
  934. }
  935. /**
  936. * Checks if a `cache` value for `key` exists.
  937. *
  938. * @private
  939. * @param {Object} cache The cache to query.
  940. * @param {string} key The key of the entry to check.
  941. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  942. */
  943. function cacheHas(cache, key) {
  944. return cache.has(key);
  945. }
  946. /**
  947. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  948. * that is not found in the character symbols.
  949. *
  950. * @private
  951. * @param {Array} strSymbols The string symbols to inspect.
  952. * @param {Array} chrSymbols The character symbols to find.
  953. * @returns {number} Returns the index of the first unmatched string symbol.
  954. */
  955. function charsStartIndex(strSymbols, chrSymbols) {
  956. var index = -1,
  957. length = strSymbols.length;
  958. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  959. return index;
  960. }
  961. /**
  962. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  963. * that is not found in the character symbols.
  964. *
  965. * @private
  966. * @param {Array} strSymbols The string symbols to inspect.
  967. * @param {Array} chrSymbols The character symbols to find.
  968. * @returns {number} Returns the index of the last unmatched string symbol.
  969. */
  970. function charsEndIndex(strSymbols, chrSymbols) {
  971. var index = strSymbols.length;
  972. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  973. return index;
  974. }
  975. /**
  976. * Gets the number of `placeholder` occurrences in `array`.
  977. *
  978. * @private
  979. * @param {Array} array The array to inspect.
  980. * @param {*} placeholder The placeholder to search for.
  981. * @returns {number} Returns the placeholder count.
  982. */
  983. function countHolders(array, placeholder) {
  984. var length = array.length,
  985. result = 0;
  986. while (length--) {
  987. if (array[length] === placeholder) {
  988. ++result;
  989. }
  990. }
  991. return result;
  992. }
  993. /**
  994. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  995. * letters to basic Latin letters.
  996. *
  997. * @private
  998. * @param {string} letter The matched letter to deburr.
  999. * @returns {string} Returns the deburred letter.
  1000. */
  1001. var deburrLetter = basePropertyOf(deburredLetters);
  1002. /**
  1003. * Used by `_.escape` to convert characters to HTML entities.
  1004. *
  1005. * @private
  1006. * @param {string} chr The matched character to escape.
  1007. * @returns {string} Returns the escaped character.
  1008. */
  1009. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1010. /**
  1011. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1012. *
  1013. * @private
  1014. * @param {string} chr The matched character to escape.
  1015. * @returns {string} Returns the escaped character.
  1016. */
  1017. function escapeStringChar(chr) {
  1018. return '\\' + stringEscapes[chr];
  1019. }
  1020. /**
  1021. * Gets the value at `key` of `object`.
  1022. *
  1023. * @private
  1024. * @param {Object} [object] The object to query.
  1025. * @param {string} key The key of the property to get.
  1026. * @returns {*} Returns the property value.
  1027. */
  1028. function getValue(object, key) {
  1029. return object == null ? undefined : object[key];
  1030. }
  1031. /**
  1032. * Checks if `string` contains Unicode symbols.
  1033. *
  1034. * @private
  1035. * @param {string} string The string to inspect.
  1036. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1037. */
  1038. function hasUnicode(string) {
  1039. return reHasUnicode.test(string);
  1040. }
  1041. /**
  1042. * Checks if `string` contains a word composed of Unicode symbols.
  1043. *
  1044. * @private
  1045. * @param {string} string The string to inspect.
  1046. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1047. */
  1048. function hasUnicodeWord(string) {
  1049. return reHasUnicodeWord.test(string);
  1050. }
  1051. /**
  1052. * Converts `iterator` to an array.
  1053. *
  1054. * @private
  1055. * @param {Object} iterator The iterator to convert.
  1056. * @returns {Array} Returns the converted array.
  1057. */
  1058. function iteratorToArray(iterator) {
  1059. var data,
  1060. result = [];
  1061. while (!(data = iterator.next()).done) {
  1062. result.push(data.value);
  1063. }
  1064. return result;
  1065. }
  1066. /**
  1067. * Converts `map` to its key-value pairs.
  1068. *
  1069. * @private
  1070. * @param {Object} map The map to convert.
  1071. * @returns {Array} Returns the key-value pairs.
  1072. */
  1073. function mapToArray(map) {
  1074. var index = -1,
  1075. result = Array(map.size);
  1076. map.forEach(function(value, key) {
  1077. result[++index] = [key, value];
  1078. });
  1079. return result;
  1080. }
  1081. /**
  1082. * Creates a unary function that invokes `func` with its argument transformed.
  1083. *
  1084. * @private
  1085. * @param {Function} func The function to wrap.
  1086. * @param {Function} transform The argument transform.
  1087. * @returns {Function} Returns the new function.
  1088. */
  1089. function overArg(func, transform) {
  1090. return function(arg) {
  1091. return func(transform(arg));
  1092. };
  1093. }
  1094. /**
  1095. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1096. * and returns an array of their indexes.
  1097. *
  1098. * @private
  1099. * @param {Array} array The array to modify.
  1100. * @param {*} placeholder The placeholder to replace.
  1101. * @returns {Array} Returns the new array of placeholder indexes.
  1102. */
  1103. function replaceHolders(array, placeholder) {
  1104. var index = -1,
  1105. length = array.length,
  1106. resIndex = 0,
  1107. result = [];
  1108. while (++index < length) {
  1109. var value = array[index];
  1110. if (value === placeholder || value === PLACEHOLDER) {
  1111. array[index] = PLACEHOLDER;
  1112. result[resIndex++] = index;
  1113. }
  1114. }
  1115. return result;
  1116. }
  1117. /**
  1118. * Converts `set` to an array of its values.
  1119. *
  1120. * @private
  1121. * @param {Object} set The set to convert.
  1122. * @returns {Array} Returns the values.
  1123. */
  1124. function setToArray(set) {
  1125. var index = -1,
  1126. result = Array(set.size);
  1127. set.forEach(function(value) {
  1128. result[++index] = value;
  1129. });
  1130. return result;
  1131. }
  1132. /**
  1133. * Converts `set` to its value-value pairs.
  1134. *
  1135. * @private
  1136. * @param {Object} set The set to convert.
  1137. * @returns {Array} Returns the value-value pairs.
  1138. */
  1139. function setToPairs(set) {
  1140. var index = -1,
  1141. result = Array(set.size);
  1142. set.forEach(function(value) {
  1143. result[++index] = [value, value];
  1144. });
  1145. return result;
  1146. }
  1147. /**
  1148. * A specialized version of `_.indexOf` which performs strict equality
  1149. * comparisons of values, i.e. `===`.
  1150. *
  1151. * @private
  1152. * @param {Array} array The array to inspect.
  1153. * @param {*} value The value to search for.
  1154. * @param {number} fromIndex The index to search from.
  1155. * @returns {number} Returns the index of the matched value, else `-1`.
  1156. */
  1157. function strictIndexOf(array, value, fromIndex) {
  1158. var index = fromIndex - 1,
  1159. length = array.length;
  1160. while (++index < length) {
  1161. if (array[index] === value) {
  1162. return index;
  1163. }
  1164. }
  1165. return -1;
  1166. }
  1167. /**
  1168. * A specialized version of `_.lastIndexOf` which performs strict equality
  1169. * comparisons of values, i.e. `===`.
  1170. *
  1171. * @private
  1172. * @param {Array} array The array to inspect.
  1173. * @param {*} value The value to search for.
  1174. * @param {number} fromIndex The index to search from.
  1175. * @returns {number} Returns the index of the matched value, else `-1`.
  1176. */
  1177. function strictLastIndexOf(array, value, fromIndex) {
  1178. var index = fromIndex + 1;
  1179. while (index--) {
  1180. if (array[index] === value) {
  1181. return index;
  1182. }
  1183. }
  1184. return index;
  1185. }
  1186. /**
  1187. * Gets the number of symbols in `string`.
  1188. *
  1189. * @private
  1190. * @param {string} string The string to inspect.
  1191. * @returns {number} Returns the string size.
  1192. */
  1193. function stringSize(string) {
  1194. return hasUnicode(string)
  1195. ? unicodeSize(string)
  1196. : asciiSize(string);
  1197. }
  1198. /**
  1199. * Converts `string` to an array.
  1200. *
  1201. * @private
  1202. * @param {string} string The string to convert.
  1203. * @returns {Array} Returns the converted array.
  1204. */
  1205. function stringToArray(string) {
  1206. return hasUnicode(string)
  1207. ? unicodeToArray(string)
  1208. : asciiToArray(string);
  1209. }
  1210. /**
  1211. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  1212. * character of `string`.
  1213. *
  1214. * @private
  1215. * @param {string} string The string to inspect.
  1216. * @returns {number} Returns the index of the last non-whitespace character.
  1217. */
  1218. function trimmedEndIndex(string) {
  1219. var index = string.length;
  1220. while (index-- && reWhitespace.test(string.charAt(index))) {}
  1221. return index;
  1222. }
  1223. /**
  1224. * Used by `_.unescape` to convert HTML entities to characters.
  1225. *
  1226. * @private
  1227. * @param {string} chr The matched character to unescape.
  1228. * @returns {string} Returns the unescaped character.
  1229. */
  1230. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1231. /**
  1232. * Gets the size of a Unicode `string`.
  1233. *
  1234. * @private
  1235. * @param {string} string The string inspect.
  1236. * @returns {number} Returns the string size.
  1237. */
  1238. function unicodeSize(string) {
  1239. var result = reUnicode.lastIndex = 0;
  1240. while (reUnicode.test(string)) {
  1241. ++result;
  1242. }
  1243. return result;
  1244. }
  1245. /**
  1246. * Converts a Unicode `string` to an array.
  1247. *
  1248. * @private
  1249. * @param {string} string The string to convert.
  1250. * @returns {Array} Returns the converted array.
  1251. */
  1252. function unicodeToArray(string) {
  1253. return string.match(reUnicode) || [];
  1254. }
  1255. /**
  1256. * Splits a Unicode `string` into an array of its words.
  1257. *
  1258. * @private
  1259. * @param {string} The string to inspect.
  1260. * @returns {Array} Returns the words of `string`.
  1261. */
  1262. function unicodeWords(string) {
  1263. return string.match(reUnicodeWord) || [];
  1264. }
  1265. /*--------------------------------------------------------------------------*/
  1266. /**
  1267. * Create a new pristine `lodash` function using the `context` object.
  1268. *
  1269. * @static
  1270. * @memberOf _
  1271. * @since 1.1.0
  1272. * @category Util
  1273. * @param {Object} [context=root] The context object.
  1274. * @returns {Function} Returns a new `lodash` function.
  1275. * @example
  1276. *
  1277. * _.mixin({ 'foo': _.constant('foo') });
  1278. *
  1279. * var lodash = _.runInContext();
  1280. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1281. *
  1282. * _.isFunction(_.foo);
  1283. * // => true
  1284. * _.isFunction(_.bar);
  1285. * // => false
  1286. *
  1287. * lodash.isFunction(lodash.foo);
  1288. * // => false
  1289. * lodash.isFunction(lodash.bar);
  1290. * // => true
  1291. *
  1292. * // Create a suped-up `defer` in Node.js.
  1293. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1294. */
  1295. var runInContext = (function runInContext(context) {
  1296. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1297. /** Built-in constructor references. */
  1298. var Array = context.Array,
  1299. Date = context.Date,
  1300. Error = context.Error,
  1301. Function = context.Function,
  1302. Math = context.Math,
  1303. Object = context.Object,
  1304. RegExp = context.RegExp,
  1305. String = context.String,
  1306. TypeError = context.TypeError;
  1307. /** Used for built-in method references. */
  1308. var arrayProto = Array.prototype,
  1309. funcProto = Function.prototype,
  1310. objectProto = Object.prototype;
  1311. /** Used to detect overreaching core-js shims. */
  1312. var coreJsData = context['__core-js_shared__'];
  1313. /** Used to resolve the decompiled source of functions. */
  1314. var funcToString = funcProto.toString;
  1315. /** Used to check objects for own properties. */
  1316. var hasOwnProperty = objectProto.hasOwnProperty;
  1317. /** Used to generate unique IDs. */
  1318. var idCounter = 0;
  1319. /** Used to detect methods masquerading as native. */
  1320. var maskSrcKey = (function() {
  1321. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1322. return uid ? ('Symbol(src)_1.' + uid) : '';
  1323. }());
  1324. /**
  1325. * Used to resolve the
  1326. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1327. * of values.
  1328. */
  1329. var nativeObjectToString = objectProto.toString;
  1330. /** Used to infer the `Object` constructor. */
  1331. var objectCtorString = funcToString.call(Object);
  1332. /** Used to restore the original `_` reference in `_.noConflict`. */
  1333. var oldDash = root._;
  1334. /** Used to detect if a method is native. */
  1335. var reIsNative = RegExp('^' +
  1336. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1337. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1338. );
  1339. /** Built-in value references. */
  1340. var Buffer = moduleExports ? context.Buffer : undefined,
  1341. Symbol = context.Symbol,
  1342. Uint8Array = context.Uint8Array,
  1343. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1344. getPrototype = overArg(Object.getPrototypeOf, Object),
  1345. objectCreate = Object.create,
  1346. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1347. splice = arrayProto.splice,
  1348. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1349. symIterator = Symbol ? Symbol.iterator : undefined,
  1350. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1351. var defineProperty = (function() {
  1352. try {
  1353. var func = getNative(Object, 'defineProperty');
  1354. func({}, '', {});
  1355. return func;
  1356. } catch (e) {}
  1357. }());
  1358. /** Mocked built-ins. */
  1359. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1360. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1361. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1362. /* Built-in method references for those with the same name as other `lodash` methods. */
  1363. var nativeCeil = Math.ceil,
  1364. nativeFloor = Math.floor,
  1365. nativeGetSymbols = Object.getOwnPropertySymbols,
  1366. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1367. nativeIsFinite = context.isFinite,
  1368. nativeJoin = arrayProto.join,
  1369. nativeKeys = overArg(Object.keys, Object),
  1370. nativeMax = Math.max,
  1371. nativeMin = Math.min,
  1372. nativeNow = Date.now,
  1373. nativeParseInt = context.parseInt,
  1374. nativeRandom = Math.random,
  1375. nativeReverse = arrayProto.reverse;
  1376. /* Built-in method references that are verified to be native. */
  1377. var DataView = getNative(context, 'DataView'),
  1378. Map = getNative(context, 'Map'),
  1379. Promise = getNative(context, 'Promise'),
  1380. Set = getNative(context, 'Set'),
  1381. WeakMap = getNative(context, 'WeakMap'),
  1382. nativeCreate = getNative(Object, 'create');
  1383. /** Used to store function metadata. */
  1384. var metaMap = WeakMap && new WeakMap;
  1385. /** Used to lookup unminified function names. */
  1386. var realNames = {};
  1387. /** Used to detect maps, sets, and weakmaps. */
  1388. var dataViewCtorString = toSource(DataView),
  1389. mapCtorString = toSource(Map),
  1390. promiseCtorString = toSource(Promise),
  1391. setCtorString = toSource(Set),
  1392. weakMapCtorString = toSource(WeakMap);
  1393. /** Used to convert symbols to primitives and strings. */
  1394. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1395. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1396. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1397. /*------------------------------------------------------------------------*/
  1398. /**
  1399. * Creates a `lodash` object which wraps `value` to enable implicit method
  1400. * chain sequences. Methods that operate on and return arrays, collections,
  1401. * and functions can be chained together. Methods that retrieve a single value
  1402. * or may return a primitive value will automatically end the chain sequence
  1403. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1404. * with `_#value`.
  1405. *
  1406. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1407. * enabled using `_.chain`.
  1408. *
  1409. * The execution of chained methods is lazy, that is, it's deferred until
  1410. * `_#value` is implicitly or explicitly called.
  1411. *
  1412. * Lazy evaluation allows several methods to support shortcut fusion.
  1413. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1414. * the creation of intermediate arrays and can greatly reduce the number of
  1415. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1416. * fusion if the section is applied to an array and iteratees accept only
  1417. * one argument. The heuristic for whether a section qualifies for shortcut
  1418. * fusion is subject to change.
  1419. *
  1420. * Chaining is supported in custom builds as long as the `_#value` method is
  1421. * directly or indirectly included in the build.
  1422. *
  1423. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1424. *
  1425. * The wrapper `Array` methods are:
  1426. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1427. *
  1428. * The wrapper `String` methods are:
  1429. * `replace` and `split`
  1430. *
  1431. * The wrapper methods that support shortcut fusion are:
  1432. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1433. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1434. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1435. *
  1436. * The chainable wrapper methods are:
  1437. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1438. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1439. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1440. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1441. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1442. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1443. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1444. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1445. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1446. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1447. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1448. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1449. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1450. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1451. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1452. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1453. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1454. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1455. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1456. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1457. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1458. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1459. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1460. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1461. *
  1462. * The wrapper methods that are **not** chainable by default are:
  1463. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1464. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1465. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1466. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1467. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1468. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1469. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1470. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1471. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1472. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1473. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1474. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1475. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1476. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1477. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1478. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1479. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1480. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1481. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1482. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1483. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1484. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1485. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1486. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1487. * `upperFirst`, `value`, and `words`
  1488. *
  1489. * @name _
  1490. * @constructor
  1491. * @category Seq
  1492. * @param {*} value The value to wrap in a `lodash` instance.
  1493. * @returns {Object} Returns the new `lodash` wrapper instance.
  1494. * @example
  1495. *
  1496. * function square(n) {
  1497. * return n * n;
  1498. * }
  1499. *
  1500. * var wrapped = _([1, 2, 3]);
  1501. *
  1502. * // Returns an unwrapped value.
  1503. * wrapped.reduce(_.add);
  1504. * // => 6
  1505. *
  1506. * // Returns a wrapped value.
  1507. * var squares = wrapped.map(square);
  1508. *
  1509. * _.isArray(squares);
  1510. * // => false
  1511. *
  1512. * _.isArray(squares.value());
  1513. * // => true
  1514. */
  1515. function lodash(value) {
  1516. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1517. if (value instanceof LodashWrapper) {
  1518. return value;
  1519. }
  1520. if (hasOwnProperty.call(value, '__wrapped__')) {
  1521. return wrapperClone(value);
  1522. }
  1523. }
  1524. return new LodashWrapper(value);
  1525. }
  1526. /**
  1527. * The base implementation of `_.create` without support for assigning
  1528. * properties to the created object.
  1529. *
  1530. * @private
  1531. * @param {Object} proto The object to inherit from.
  1532. * @returns {Object} Returns the new object.
  1533. */
  1534. var baseCreate = (function() {
  1535. function object() {}
  1536. return function(proto) {
  1537. if (!isObject(proto)) {
  1538. return {};
  1539. }
  1540. if (objectCreate) {
  1541. return objectCreate(proto);
  1542. }
  1543. object.prototype = proto;
  1544. var result = new object;
  1545. object.prototype = undefined;
  1546. return result;
  1547. };
  1548. }());
  1549. /**
  1550. * The function whose prototype chain sequence wrappers inherit from.
  1551. *
  1552. * @private
  1553. */
  1554. function baseLodash() {
  1555. // No operation performed.
  1556. }
  1557. /**
  1558. * The base constructor for creating `lodash` wrapper objects.
  1559. *
  1560. * @private
  1561. * @param {*} value The value to wrap.
  1562. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1563. */
  1564. function LodashWrapper(value, chainAll) {
  1565. this.__wrapped__ = value;
  1566. this.__actions__ = [];
  1567. this.__chain__ = !!chainAll;
  1568. this.__index__ = 0;
  1569. this.__values__ = undefined;
  1570. }
  1571. /**
  1572. * By default, the template delimiters used by lodash are like those in
  1573. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1574. * following template settings to use alternative delimiters.
  1575. *
  1576. * @static
  1577. * @memberOf _
  1578. * @type {Object}
  1579. */
  1580. lodash.templateSettings = {
  1581. /**
  1582. * Used to detect `data` property values to be HTML-escaped.
  1583. *
  1584. * @memberOf _.templateSettings
  1585. * @type {RegExp}
  1586. */
  1587. 'escape': reEscape,
  1588. /**
  1589. * Used to detect code to be evaluated.
  1590. *
  1591. * @memberOf _.templateSettings
  1592. * @type {RegExp}
  1593. */
  1594. 'evaluate': reEvaluate,
  1595. /**
  1596. * Used to detect `data` property values to inject.
  1597. *
  1598. * @memberOf _.templateSettings
  1599. * @type {RegExp}
  1600. */
  1601. 'interpolate': reInterpolate,
  1602. /**
  1603. * Used to reference the data object in the template text.
  1604. *
  1605. * @memberOf _.templateSettings
  1606. * @type {string}
  1607. */
  1608. 'variable': '',
  1609. /**
  1610. * Used to import variables into the compiled template.
  1611. *
  1612. * @memberOf _.templateSettings
  1613. * @type {Object}
  1614. */
  1615. 'imports': {
  1616. /**
  1617. * A reference to the `lodash` function.
  1618. *
  1619. * @memberOf _.templateSettings.imports
  1620. * @type {Function}
  1621. */
  1622. '_': lodash
  1623. }
  1624. };
  1625. // Ensure wrappers are instances of `baseLodash`.
  1626. lodash.prototype = baseLodash.prototype;
  1627. lodash.prototype.constructor = lodash;
  1628. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1629. LodashWrapper.prototype.constructor = LodashWrapper;
  1630. /*------------------------------------------------------------------------*/
  1631. /**
  1632. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1633. *
  1634. * @private
  1635. * @constructor
  1636. * @param {*} value The value to wrap.
  1637. */
  1638. function LazyWrapper(value) {
  1639. this.__wrapped__ = value;
  1640. this.__actions__ = [];
  1641. this.__dir__ = 1;
  1642. this.__filtered__ = false;
  1643. this.__iteratees__ = [];
  1644. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1645. this.__views__ = [];
  1646. }
  1647. /**
  1648. * Creates a clone of the lazy wrapper object.
  1649. *
  1650. * @private
  1651. * @name clone
  1652. * @memberOf LazyWrapper
  1653. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1654. */
  1655. function lazyClone() {
  1656. var result = new LazyWrapper(this.__wrapped__);
  1657. result.__actions__ = copyArray(this.__actions__);
  1658. result.__dir__ = this.__dir__;
  1659. result.__filtered__ = this.__filtered__;
  1660. result.__iteratees__ = copyArray(this.__iteratees__);
  1661. result.__takeCount__ = this.__takeCount__;
  1662. result.__views__ = copyArray(this.__views__);
  1663. return result;
  1664. }
  1665. /**
  1666. * Reverses the direction of lazy iteration.
  1667. *
  1668. * @private
  1669. * @name reverse
  1670. * @memberOf LazyWrapper
  1671. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1672. */
  1673. function lazyReverse() {
  1674. if (this.__filtered__) {
  1675. var result = new LazyWrapper(this);
  1676. result.__dir__ = -1;
  1677. result.__filtered__ = true;
  1678. } else {
  1679. result = this.clone();
  1680. result.__dir__ *= -1;
  1681. }
  1682. return result;
  1683. }
  1684. /**
  1685. * Extracts the unwrapped value from its lazy wrapper.
  1686. *
  1687. * @private
  1688. * @name value
  1689. * @memberOf LazyWrapper
  1690. * @returns {*} Returns the unwrapped value.
  1691. */
  1692. function lazyValue() {
  1693. var array = this.__wrapped__.value(),
  1694. dir = this.__dir__,
  1695. isArr = isArray(array),
  1696. isRight = dir < 0,
  1697. arrLength = isArr ? array.length : 0,
  1698. view = getView(0, arrLength, this.__views__),
  1699. start = view.start,
  1700. end = view.end,
  1701. length = end - start,
  1702. index = isRight ? end : (start - 1),
  1703. iteratees = this.__iteratees__,
  1704. iterLength = iteratees.length,
  1705. resIndex = 0,
  1706. takeCount = nativeMin(length, this.__takeCount__);
  1707. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1708. return baseWrapperValue(array, this.__actions__);
  1709. }
  1710. var result = [];
  1711. outer:
  1712. while (length-- && resIndex < takeCount) {
  1713. index += dir;
  1714. var iterIndex = -1,
  1715. value = array[index];
  1716. while (++iterIndex < iterLength) {
  1717. var data = iteratees[iterIndex],
  1718. iteratee = data.iteratee,
  1719. type = data.type,
  1720. computed = iteratee(value);
  1721. if (type == LAZY_MAP_FLAG) {
  1722. value = computed;
  1723. } else if (!computed) {
  1724. if (type == LAZY_FILTER_FLAG) {
  1725. continue outer;
  1726. } else {
  1727. break outer;
  1728. }
  1729. }
  1730. }
  1731. result[resIndex++] = value;
  1732. }
  1733. return result;
  1734. }
  1735. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1736. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1737. LazyWrapper.prototype.constructor = LazyWrapper;
  1738. /*------------------------------------------------------------------------*/
  1739. /**
  1740. * Creates a hash object.
  1741. *
  1742. * @private
  1743. * @constructor
  1744. * @param {Array} [entries] The key-value pairs to cache.
  1745. */
  1746. function Hash(entries) {
  1747. var index = -1,
  1748. length = entries == null ? 0 : entries.length;
  1749. this.clear();
  1750. while (++index < length) {
  1751. var entry = entries[index];
  1752. this.set(entry[0], entry[1]);
  1753. }
  1754. }
  1755. /**
  1756. * Removes all key-value entries from the hash.
  1757. *
  1758. * @private
  1759. * @name clear
  1760. * @memberOf Hash
  1761. */
  1762. function hashClear() {
  1763. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1764. this.size = 0;
  1765. }
  1766. /**
  1767. * Removes `key` and its value from the hash.
  1768. *
  1769. * @private
  1770. * @name delete
  1771. * @memberOf Hash
  1772. * @param {Object} hash The hash to modify.
  1773. * @param {string} key The key of the value to remove.
  1774. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1775. */
  1776. function hashDelete(key) {
  1777. var result = this.has(key) && delete this.__data__[key];
  1778. this.size -= result ? 1 : 0;
  1779. return result;
  1780. }
  1781. /**
  1782. * Gets the hash value for `key`.
  1783. *
  1784. * @private
  1785. * @name get
  1786. * @memberOf Hash
  1787. * @param {string} key The key of the value to get.
  1788. * @returns {*} Returns the entry value.
  1789. */
  1790. function hashGet(key) {
  1791. var data = this.__data__;
  1792. if (nativeCreate) {
  1793. var result = data[key];
  1794. return result === HASH_UNDEFINED ? undefined : result;
  1795. }
  1796. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1797. }
  1798. /**
  1799. * Checks if a hash value for `key` exists.
  1800. *
  1801. * @private
  1802. * @name has
  1803. * @memberOf Hash
  1804. * @param {string} key The key of the entry to check.
  1805. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1806. */
  1807. function hashHas(key) {
  1808. var data = this.__data__;
  1809. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1810. }
  1811. /**
  1812. * Sets the hash `key` to `value`.
  1813. *
  1814. * @private
  1815. * @name set
  1816. * @memberOf Hash
  1817. * @param {string} key The key of the value to set.
  1818. * @param {*} value The value to set.
  1819. * @returns {Object} Returns the hash instance.
  1820. */
  1821. function hashSet(key, value) {
  1822. var data = this.__data__;
  1823. this.size += this.has(key) ? 0 : 1;
  1824. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1825. return this;
  1826. }
  1827. // Add methods to `Hash`.
  1828. Hash.prototype.clear = hashClear;
  1829. Hash.prototype['delete'] = hashDelete;
  1830. Hash.prototype.get = hashGet;
  1831. Hash.prototype.has = hashHas;
  1832. Hash.prototype.set = hashSet;
  1833. /*------------------------------------------------------------------------*/
  1834. /**
  1835. * Creates an list cache object.
  1836. *
  1837. * @private
  1838. * @constructor
  1839. * @param {Array} [entries] The key-value pairs to cache.
  1840. */
  1841. function ListCache(entries) {
  1842. var index = -1,
  1843. length = entries == null ? 0 : entries.length;
  1844. this.clear();
  1845. while (++index < length) {
  1846. var entry = entries[index];
  1847. this.set(entry[0], entry[1]);
  1848. }
  1849. }
  1850. /**
  1851. * Removes all key-value entries from the list cache.
  1852. *
  1853. * @private
  1854. * @name clear
  1855. * @memberOf ListCache
  1856. */
  1857. function listCacheClear() {
  1858. this.__data__ = [];
  1859. this.size = 0;
  1860. }
  1861. /**
  1862. * Removes `key` and its value from the list cache.
  1863. *
  1864. * @private
  1865. * @name delete
  1866. * @memberOf ListCache
  1867. * @param {string} key The key of the value to remove.
  1868. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1869. */
  1870. function listCacheDelete(key) {
  1871. var data = this.__data__,
  1872. index = assocIndexOf(data, key);
  1873. if (index < 0) {
  1874. return false;
  1875. }
  1876. var lastIndex = data.length - 1;
  1877. if (index == lastIndex) {
  1878. data.pop();
  1879. } else {
  1880. splice.call(data, index, 1);
  1881. }
  1882. --this.size;
  1883. return true;
  1884. }
  1885. /**
  1886. * Gets the list cache value for `key`.
  1887. *
  1888. * @private
  1889. * @name get
  1890. * @memberOf ListCache
  1891. * @param {string} key The key of the value to get.
  1892. * @returns {*} Returns the entry value.
  1893. */
  1894. function listCacheGet(key) {
  1895. var data = this.__data__,
  1896. index = assocIndexOf(data, key);
  1897. return index < 0 ? undefined : data[index][1];
  1898. }
  1899. /**
  1900. * Checks if a list cache value for `key` exists.
  1901. *
  1902. * @private
  1903. * @name has
  1904. * @memberOf ListCache
  1905. * @param {string} key The key of the entry to check.
  1906. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1907. */
  1908. function listCacheHas(key) {
  1909. return assocIndexOf(this.__data__, key) > -1;
  1910. }
  1911. /**
  1912. * Sets the list cache `key` to `value`.
  1913. *
  1914. * @private
  1915. * @name set
  1916. * @memberOf ListCache
  1917. * @param {string} key The key of the value to set.
  1918. * @param {*} value The value to set.
  1919. * @returns {Object} Returns the list cache instance.
  1920. */
  1921. function listCacheSet(key, value) {
  1922. var data = this.__data__,
  1923. index = assocIndexOf(data, key);
  1924. if (index < 0) {
  1925. ++this.size;
  1926. data.push([key, value]);
  1927. } else {
  1928. data[index][1] = value;
  1929. }
  1930. return this;
  1931. }
  1932. // Add methods to `ListCache`.
  1933. ListCache.prototype.clear = listCacheClear;
  1934. ListCache.prototype['delete'] = listCacheDelete;
  1935. ListCache.prototype.get = listCacheGet;
  1936. ListCache.prototype.has = listCacheHas;
  1937. ListCache.prototype.set = listCacheSet;
  1938. /*------------------------------------------------------------------------*/
  1939. /**
  1940. * Creates a map cache object to store key-value pairs.
  1941. *
  1942. * @private
  1943. * @constructor
  1944. * @param {Array} [entries] The key-value pairs to cache.
  1945. */
  1946. function MapCache(entries) {
  1947. var index = -1,
  1948. length = entries == null ? 0 : entries.length;
  1949. this.clear();
  1950. while (++index < length) {
  1951. var entry = entries[index];
  1952. this.set(entry[0], entry[1]);
  1953. }
  1954. }
  1955. /**
  1956. * Removes all key-value entries from the map.
  1957. *
  1958. * @private
  1959. * @name clear
  1960. * @memberOf MapCache
  1961. */
  1962. function mapCacheClear() {
  1963. this.size = 0;
  1964. this.__data__ = {
  1965. 'hash': new Hash,
  1966. 'map': new (Map || ListCache),
  1967. 'string': new Hash
  1968. };
  1969. }
  1970. /**
  1971. * Removes `key` and its value from the map.
  1972. *
  1973. * @private
  1974. * @name delete
  1975. * @memberOf MapCache
  1976. * @param {string} key The key of the value to remove.
  1977. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1978. */
  1979. function mapCacheDelete(key) {
  1980. var result = getMapData(this, key)['delete'](key);
  1981. this.size -= result ? 1 : 0;
  1982. return result;
  1983. }
  1984. /**
  1985. * Gets the map value for `key`.
  1986. *
  1987. * @private
  1988. * @name get
  1989. * @memberOf MapCache
  1990. * @param {string} key The key of the value to get.
  1991. * @returns {*} Returns the entry value.
  1992. */
  1993. function mapCacheGet(key) {
  1994. return getMapData(this, key).get(key);
  1995. }
  1996. /**
  1997. * Checks if a map value for `key` exists.
  1998. *
  1999. * @private
  2000. * @name has
  2001. * @memberOf MapCache
  2002. * @param {string} key The key of the entry to check.
  2003. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2004. */
  2005. function mapCacheHas(key) {
  2006. return getMapData(this, key).has(key);
  2007. }
  2008. /**
  2009. * Sets the map `key` to `value`.
  2010. *
  2011. * @private
  2012. * @name set
  2013. * @memberOf MapCache
  2014. * @param {string} key The key of the value to set.
  2015. * @param {*} value The value to set.
  2016. * @returns {Object} Returns the map cache instance.
  2017. */
  2018. function mapCacheSet(key, value) {
  2019. var data = getMapData(this, key),
  2020. size = data.size;
  2021. data.set(key, value);
  2022. this.size += data.size == size ? 0 : 1;
  2023. return this;
  2024. }
  2025. // Add methods to `MapCache`.
  2026. MapCache.prototype.clear = mapCacheClear;
  2027. MapCache.prototype['delete'] = mapCacheDelete;
  2028. MapCache.prototype.get = mapCacheGet;
  2029. MapCache.prototype.has = mapCacheHas;
  2030. MapCache.prototype.set = mapCacheSet;
  2031. /*------------------------------------------------------------------------*/
  2032. /**
  2033. *
  2034. * Creates an array cache object to store unique values.
  2035. *
  2036. * @private
  2037. * @constructor
  2038. * @param {Array} [values] The values to cache.
  2039. */
  2040. function SetCache(values) {
  2041. var index = -1,
  2042. length = values == null ? 0 : values.length;
  2043. this.__data__ = new MapCache;
  2044. while (++index < length) {
  2045. this.add(values[index]);
  2046. }
  2047. }
  2048. /**
  2049. * Adds `value` to the array cache.
  2050. *
  2051. * @private
  2052. * @name add
  2053. * @memberOf SetCache
  2054. * @alias push
  2055. * @param {*} value The value to cache.
  2056. * @returns {Object} Returns the cache instance.
  2057. */
  2058. function setCacheAdd(value) {
  2059. this.__data__.set(value, HASH_UNDEFINED);
  2060. return this;
  2061. }
  2062. /**
  2063. * Checks if `value` is in the array cache.
  2064. *
  2065. * @private
  2066. * @name has
  2067. * @memberOf SetCache
  2068. * @param {*} value The value to search for.
  2069. * @returns {number} Returns `true` if `value` is found, else `false`.
  2070. */
  2071. function setCacheHas(value) {
  2072. return this.__data__.has(value);
  2073. }
  2074. // Add methods to `SetCache`.
  2075. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2076. SetCache.prototype.has = setCacheHas;
  2077. /*------------------------------------------------------------------------*/
  2078. /**
  2079. * Creates a stack cache object to store key-value pairs.
  2080. *
  2081. * @private
  2082. * @constructor
  2083. * @param {Array} [entries] The key-value pairs to cache.
  2084. */
  2085. function Stack(entries) {
  2086. var data = this.__data__ = new ListCache(entries);
  2087. this.size = data.size;
  2088. }
  2089. /**
  2090. * Removes all key-value entries from the stack.
  2091. *
  2092. * @private
  2093. * @name clear
  2094. * @memberOf Stack
  2095. */
  2096. function stackClear() {
  2097. this.__data__ = new ListCache;
  2098. this.size = 0;
  2099. }
  2100. /**
  2101. * Removes `key` and its value from the stack.
  2102. *
  2103. * @private
  2104. * @name delete
  2105. * @memberOf Stack
  2106. * @param {string} key The key of the value to remove.
  2107. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2108. */
  2109. function stackDelete(key) {
  2110. var data = this.__data__,
  2111. result = data['delete'](key);
  2112. this.size = data.size;
  2113. return result;
  2114. }
  2115. /**
  2116. * Gets the stack value for `key`.
  2117. *
  2118. * @private
  2119. * @name get
  2120. * @memberOf Stack
  2121. * @param {string} key The key of the value to get.
  2122. * @returns {*} Returns the entry value.
  2123. */
  2124. function stackGet(key) {
  2125. return this.__data__.get(key);
  2126. }
  2127. /**
  2128. * Checks if a stack value for `key` exists.
  2129. *
  2130. * @private
  2131. * @name has
  2132. * @memberOf Stack
  2133. * @param {string} key The key of the entry to check.
  2134. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2135. */
  2136. function stackHas(key) {
  2137. return this.__data__.has(key);
  2138. }
  2139. /**
  2140. * Sets the stack `key` to `value`.
  2141. *
  2142. * @private
  2143. * @name set
  2144. * @memberOf Stack
  2145. * @param {string} key The key of the value to set.
  2146. * @param {*} value The value to set.
  2147. * @returns {Object} Returns the stack cache instance.
  2148. */
  2149. function stackSet(key, value) {
  2150. var data = this.__data__;
  2151. if (data instanceof ListCache) {
  2152. var pairs = data.__data__;
  2153. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2154. pairs.push([key, value]);
  2155. this.size = ++data.size;
  2156. return this;
  2157. }
  2158. data = this.__data__ = new MapCache(pairs);
  2159. }
  2160. data.set(key, value);
  2161. this.size = data.size;
  2162. return this;
  2163. }
  2164. // Add methods to `Stack`.
  2165. Stack.prototype.clear = stackClear;
  2166. Stack.prototype['delete'] = stackDelete;
  2167. Stack.prototype.get = stackGet;
  2168. Stack.prototype.has = stackHas;
  2169. Stack.prototype.set = stackSet;
  2170. /*------------------------------------------------------------------------*/
  2171. /**
  2172. * Creates an array of the enumerable property names of the array-like `value`.
  2173. *
  2174. * @private
  2175. * @param {*} value The value to query.
  2176. * @param {boolean} inherited Specify returning inherited property names.
  2177. * @returns {Array} Returns the array of property names.
  2178. */
  2179. function arrayLikeKeys(value, inherited) {
  2180. var isArr = isArray(value),
  2181. isArg = !isArr && isArguments(value),
  2182. isBuff = !isArr && !isArg && isBuffer(value),
  2183. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2184. skipIndexes = isArr || isArg || isBuff || isType,
  2185. result = skipIndexes ? baseTimes(value.length, String) : [],
  2186. length = result.length;
  2187. for (var key in value) {
  2188. if ((inherited || hasOwnProperty.call(value, key)) &&
  2189. !(skipIndexes && (
  2190. // Safari 9 has enumerable `arguments.length` in strict mode.
  2191. key == 'length' ||
  2192. // Node.js 0.10 has enumerable non-index properties on buffers.
  2193. (isBuff && (key == 'offset' || key == 'parent')) ||
  2194. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2195. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2196. // Skip index properties.
  2197. isIndex(key, length)
  2198. ))) {
  2199. result.push(key);
  2200. }
  2201. }
  2202. return result;
  2203. }
  2204. /**
  2205. * A specialized version of `_.sample` for arrays.
  2206. *
  2207. * @private
  2208. * @param {Array} array The array to sample.
  2209. * @returns {*} Returns the random element.
  2210. */
  2211. function arraySample(array) {
  2212. var length = array.length;
  2213. return length ? array[baseRandom(0, length - 1)] : undefined;
  2214. }
  2215. /**
  2216. * A specialized version of `_.sampleSize` for arrays.
  2217. *
  2218. * @private
  2219. * @param {Array} array The array to sample.
  2220. * @param {number} n The number of elements to sample.
  2221. * @returns {Array} Returns the random elements.
  2222. */
  2223. function arraySampleSize(array, n) {
  2224. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2225. }
  2226. /**
  2227. * A specialized version of `_.shuffle` for arrays.
  2228. *
  2229. * @private
  2230. * @param {Array} array The array to shuffle.
  2231. * @returns {Array} Returns the new shuffled array.
  2232. */
  2233. function arrayShuffle(array) {
  2234. return shuffleSelf(copyArray(array));
  2235. }
  2236. /**
  2237. * This function is like `assignValue` except that it doesn't assign
  2238. * `undefined` values.
  2239. *
  2240. * @private
  2241. * @param {Object} object The object to modify.
  2242. * @param {string} key The key of the property to assign.
  2243. * @param {*} value The value to assign.
  2244. */
  2245. function assignMergeValue(object, key, value) {
  2246. if ((value !== undefined && !eq(object[key], value)) ||
  2247. (value === undefined && !(key in object))) {
  2248. baseAssignValue(object, key, value);
  2249. }
  2250. }
  2251. /**
  2252. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2253. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2254. * for equality comparisons.
  2255. *
  2256. * @private
  2257. * @param {Object} object The object to modify.
  2258. * @param {string} key The key of the property to assign.
  2259. * @param {*} value The value to assign.
  2260. */
  2261. function assignValue(object, key, value) {
  2262. var objValue = object[key];
  2263. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2264. (value === undefined && !(key in object))) {
  2265. baseAssignValue(object, key, value);
  2266. }
  2267. }
  2268. /**
  2269. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2270. *
  2271. * @private
  2272. * @param {Array} array The array to inspect.
  2273. * @param {*} key The key to search for.
  2274. * @returns {number} Returns the index of the matched value, else `-1`.
  2275. */
  2276. function assocIndexOf(array, key) {
  2277. var length = array.length;
  2278. while (length--) {
  2279. if (eq(array[length][0], key)) {
  2280. return length;
  2281. }
  2282. }
  2283. return -1;
  2284. }
  2285. /**
  2286. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2287. * by `iteratee` and values set by `setter`.
  2288. *
  2289. * @private
  2290. * @param {Array|Object} collection The collection to iterate over.
  2291. * @param {Function} setter The function to set `accumulator` values.
  2292. * @param {Function} iteratee The iteratee to transform keys.
  2293. * @param {Object} accumulator The initial aggregated object.
  2294. * @returns {Function} Returns `accumulator`.
  2295. */
  2296. function baseAggregator(collection, setter, iteratee, accumulator) {
  2297. baseEach(collection, function(value, key, collection) {
  2298. setter(accumulator, value, iteratee(value), collection);
  2299. });
  2300. return accumulator;
  2301. }
  2302. /**
  2303. * The base implementation of `_.assign` without support for multiple sources
  2304. * or `customizer` functions.
  2305. *
  2306. * @private
  2307. * @param {Object} object The destination object.
  2308. * @param {Object} source The source object.
  2309. * @returns {Object} Returns `object`.
  2310. */
  2311. function baseAssign(object, source) {
  2312. return object && copyObject(source, keys(source), object);
  2313. }
  2314. /**
  2315. * The base implementation of `_.assignIn` without support for multiple sources
  2316. * or `customizer` functions.
  2317. *
  2318. * @private
  2319. * @param {Object} object The destination object.
  2320. * @param {Object} source The source object.
  2321. * @returns {Object} Returns `object`.
  2322. */
  2323. function baseAssignIn(object, source) {
  2324. return object && copyObject(source, keysIn(source), object);
  2325. }
  2326. /**
  2327. * The base implementation of `assignValue` and `assignMergeValue` without
  2328. * value checks.
  2329. *
  2330. * @private
  2331. * @param {Object} object The object to modify.
  2332. * @param {string} key The key of the property to assign.
  2333. * @param {*} value The value to assign.
  2334. */
  2335. function baseAssignValue(object, key, value) {
  2336. if (key == '__proto__' && defineProperty) {
  2337. defineProperty(object, key, {
  2338. 'configurable': true,
  2339. 'enumerable': true,
  2340. 'value': value,
  2341. 'writable': true
  2342. });
  2343. } else {
  2344. object[key] = value;
  2345. }
  2346. }
  2347. /**
  2348. * The base implementation of `_.at` without support for individual paths.
  2349. *
  2350. * @private
  2351. * @param {Object} object The object to iterate over.
  2352. * @param {string[]} paths The property paths to pick.
  2353. * @returns {Array} Returns the picked elements.
  2354. */
  2355. function baseAt(object, paths) {
  2356. var index = -1,
  2357. length = paths.length,
  2358. result = Array(length),
  2359. skip = object == null;
  2360. while (++index < length) {
  2361. result[index] = skip ? undefined : get(object, paths[index]);
  2362. }
  2363. return result;
  2364. }
  2365. /**
  2366. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2367. *
  2368. * @private
  2369. * @param {number} number The number to clamp.
  2370. * @param {number} [lower] The lower bound.
  2371. * @param {number} upper The upper bound.
  2372. * @returns {number} Returns the clamped number.
  2373. */
  2374. function baseClamp(number, lower, upper) {
  2375. if (number === number) {
  2376. if (upper !== undefined) {
  2377. number = number <= upper ? number : upper;
  2378. }
  2379. if (lower !== undefined) {
  2380. number = number >= lower ? number : lower;
  2381. }
  2382. }
  2383. return number;
  2384. }
  2385. /**
  2386. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2387. * traversed objects.
  2388. *
  2389. * @private
  2390. * @param {*} value The value to clone.
  2391. * @param {boolean} bitmask The bitmask flags.
  2392. * 1 - Deep clone
  2393. * 2 - Flatten inherited properties
  2394. * 4 - Clone symbols
  2395. * @param {Function} [customizer] The function to customize cloning.
  2396. * @param {string} [key] The key of `value`.
  2397. * @param {Object} [object] The parent object of `value`.
  2398. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2399. * @returns {*} Returns the cloned value.
  2400. */
  2401. function baseClone(value, bitmask, customizer, key, object, stack) {
  2402. var result,
  2403. isDeep = bitmask & CLONE_DEEP_FLAG,
  2404. isFlat = bitmask & CLONE_FLAT_FLAG,
  2405. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2406. if (customizer) {
  2407. result = object ? customizer(value, key, object, stack) : customizer(value);
  2408. }
  2409. if (result !== undefined) {
  2410. return result;
  2411. }
  2412. if (!isObject(value)) {
  2413. return value;
  2414. }
  2415. var isArr = isArray(value);
  2416. if (isArr) {
  2417. result = initCloneArray(value);
  2418. if (!isDeep) {
  2419. return copyArray(value, result);
  2420. }
  2421. } else {
  2422. var tag = getTag(value),
  2423. isFunc = tag == funcTag || tag == genTag;
  2424. if (isBuffer(value)) {
  2425. return cloneBuffer(value, isDeep);
  2426. }
  2427. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2428. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2429. if (!isDeep) {
  2430. return isFlat
  2431. ? copySymbolsIn(value, baseAssignIn(result, value))
  2432. : copySymbols(value, baseAssign(result, value));
  2433. }
  2434. } else {
  2435. if (!cloneableTags[tag]) {
  2436. return object ? value : {};
  2437. }
  2438. result = initCloneByTag(value, tag, isDeep);
  2439. }
  2440. }
  2441. // Check for circular references and return its corresponding clone.
  2442. stack || (stack = new Stack);
  2443. var stacked = stack.get(value);
  2444. if (stacked) {
  2445. return stacked;
  2446. }
  2447. stack.set(value, result);
  2448. if (isSet(value)) {
  2449. value.forEach(function(subValue) {
  2450. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2451. });
  2452. } else if (isMap(value)) {
  2453. value.forEach(function(subValue, key) {
  2454. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2455. });
  2456. }
  2457. var keysFunc = isFull
  2458. ? (isFlat ? getAllKeysIn : getAllKeys)
  2459. : (isFlat ? keysIn : keys);
  2460. var props = isArr ? undefined : keysFunc(value);
  2461. arrayEach(props || value, function(subValue, key) {
  2462. if (props) {
  2463. key = subValue;
  2464. subValue = value[key];
  2465. }
  2466. // Recursively populate clone (susceptible to call stack limits).
  2467. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2468. });
  2469. return result;
  2470. }
  2471. /**
  2472. * The base implementation of `_.conforms` which doesn't clone `source`.
  2473. *
  2474. * @private
  2475. * @param {Object} source The object of property predicates to conform to.
  2476. * @returns {Function} Returns the new spec function.
  2477. */
  2478. function baseConforms(source) {
  2479. var props = keys(source);
  2480. return function(object) {
  2481. return baseConformsTo(object, source, props);
  2482. };
  2483. }
  2484. /**
  2485. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2486. *
  2487. * @private
  2488. * @param {Object} object The object to inspect.
  2489. * @param {Object} source The object of property predicates to conform to.
  2490. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2491. */
  2492. function baseConformsTo(object, source, props) {
  2493. var length = props.length;
  2494. if (object == null) {
  2495. return !length;
  2496. }
  2497. object = Object(object);
  2498. while (length--) {
  2499. var key = props[length],
  2500. predicate = source[key],
  2501. value = object[key];
  2502. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2503. return false;
  2504. }
  2505. }
  2506. return true;
  2507. }
  2508. /**
  2509. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2510. * to provide to `func`.
  2511. *
  2512. * @private
  2513. * @param {Function} func The function to delay.
  2514. * @param {number} wait The number of milliseconds to delay invocation.
  2515. * @param {Array} args The arguments to provide to `func`.
  2516. * @returns {number|Object} Returns the timer id or timeout object.
  2517. */
  2518. function baseDelay(func, wait, args) {
  2519. if (typeof func != 'function') {
  2520. throw new TypeError(FUNC_ERROR_TEXT);
  2521. }
  2522. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2523. }
  2524. /**
  2525. * The base implementation of methods like `_.difference` without support
  2526. * for excluding multiple arrays or iteratee shorthands.
  2527. *
  2528. * @private
  2529. * @param {Array} array The array to inspect.
  2530. * @param {Array} values The values to exclude.
  2531. * @param {Function} [iteratee] The iteratee invoked per element.
  2532. * @param {Function} [comparator] The comparator invoked per element.
  2533. * @returns {Array} Returns the new array of filtered values.
  2534. */
  2535. function baseDifference(array, values, iteratee, comparator) {
  2536. var index = -1,
  2537. includes = arrayIncludes,
  2538. isCommon = true,
  2539. length = array.length,
  2540. result = [],
  2541. valuesLength = values.length;
  2542. if (!length) {
  2543. return result;
  2544. }
  2545. if (iteratee) {
  2546. values = arrayMap(values, baseUnary(iteratee));
  2547. }
  2548. if (comparator) {
  2549. includes = arrayIncludesWith;
  2550. isCommon = false;
  2551. }
  2552. else if (values.length >= LARGE_ARRAY_SIZE) {
  2553. includes = cacheHas;
  2554. isCommon = false;
  2555. values = new SetCache(values);
  2556. }
  2557. outer:
  2558. while (++index < length) {
  2559. var value = array[index],
  2560. computed = iteratee == null ? value : iteratee(value);
  2561. value = (comparator || value !== 0) ? value : 0;
  2562. if (isCommon && computed === computed) {
  2563. var valuesIndex = valuesLength;
  2564. while (valuesIndex--) {
  2565. if (values[valuesIndex] === computed) {
  2566. continue outer;
  2567. }
  2568. }
  2569. result.push(value);
  2570. }
  2571. else if (!includes(values, computed, comparator)) {
  2572. result.push(value);
  2573. }
  2574. }
  2575. return result;
  2576. }
  2577. /**
  2578. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2579. *
  2580. * @private
  2581. * @param {Array|Object} collection The collection to iterate over.
  2582. * @param {Function} iteratee The function invoked per iteration.
  2583. * @returns {Array|Object} Returns `collection`.
  2584. */
  2585. var baseEach = createBaseEach(baseForOwn);
  2586. /**
  2587. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2588. *
  2589. * @private
  2590. * @param {Array|Object} collection The collection to iterate over.
  2591. * @param {Function} iteratee The function invoked per iteration.
  2592. * @returns {Array|Object} Returns `collection`.
  2593. */
  2594. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2595. /**
  2596. * The base implementation of `_.every` without support for iteratee shorthands.
  2597. *
  2598. * @private
  2599. * @param {Array|Object} collection The collection to iterate over.
  2600. * @param {Function} predicate The function invoked per iteration.
  2601. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2602. * else `false`
  2603. */
  2604. function baseEvery(collection, predicate) {
  2605. var result = true;
  2606. baseEach(collection, function(value, index, collection) {
  2607. result = !!predicate(value, index, collection);
  2608. return result;
  2609. });
  2610. return result;
  2611. }
  2612. /**
  2613. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2614. * `comparator` to determine the extremum value.
  2615. *
  2616. * @private
  2617. * @param {Array} array The array to iterate over.
  2618. * @param {Function} iteratee The iteratee invoked per iteration.
  2619. * @param {Function} comparator The comparator used to compare values.
  2620. * @returns {*} Returns the extremum value.
  2621. */
  2622. function baseExtremum(array, iteratee, comparator) {
  2623. var index = -1,
  2624. length = array.length;
  2625. while (++index < length) {
  2626. var value = array[index],
  2627. current = iteratee(value);
  2628. if (current != null && (computed === undefined
  2629. ? (current === current && !isSymbol(current))
  2630. : comparator(current, computed)
  2631. )) {
  2632. var computed = current,
  2633. result = value;
  2634. }
  2635. }
  2636. return result;
  2637. }
  2638. /**
  2639. * The base implementation of `_.fill` without an iteratee call guard.
  2640. *
  2641. * @private
  2642. * @param {Array} array The array to fill.
  2643. * @param {*} value The value to fill `array` with.
  2644. * @param {number} [start=0] The start position.
  2645. * @param {number} [end=array.length] The end position.
  2646. * @returns {Array} Returns `array`.
  2647. */
  2648. function baseFill(array, value, start, end) {
  2649. var length = array.length;
  2650. start = toInteger(start);
  2651. if (start < 0) {
  2652. start = -start > length ? 0 : (length + start);
  2653. }
  2654. end = (end === undefined || end > length) ? length : toInteger(end);
  2655. if (end < 0) {
  2656. end += length;
  2657. }
  2658. end = start > end ? 0 : toLength(end);
  2659. while (start < end) {
  2660. array[start++] = value;
  2661. }
  2662. return array;
  2663. }
  2664. /**
  2665. * The base implementation of `_.filter` without support for iteratee shorthands.
  2666. *
  2667. * @private
  2668. * @param {Array|Object} collection The collection to iterate over.
  2669. * @param {Function} predicate The function invoked per iteration.
  2670. * @returns {Array} Returns the new filtered array.
  2671. */
  2672. function baseFilter(collection, predicate) {
  2673. var result = [];
  2674. baseEach(collection, function(value, index, collection) {
  2675. if (predicate(value, index, collection)) {
  2676. result.push(value);
  2677. }
  2678. });
  2679. return result;
  2680. }
  2681. /**
  2682. * The base implementation of `_.flatten` with support for restricting flattening.
  2683. *
  2684. * @private
  2685. * @param {Array} array The array to flatten.
  2686. * @param {number} depth The maximum recursion depth.
  2687. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2688. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2689. * @param {Array} [result=[]] The initial result value.
  2690. * @returns {Array} Returns the new flattened array.
  2691. */
  2692. function baseFlatten(array, depth, predicate, isStrict, result) {
  2693. var index = -1,
  2694. length = array.length;
  2695. predicate || (predicate = isFlattenable);
  2696. result || (result = []);
  2697. while (++index < length) {
  2698. var value = array[index];
  2699. if (depth > 0 && predicate(value)) {
  2700. if (depth > 1) {
  2701. // Recursively flatten arrays (susceptible to call stack limits).
  2702. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2703. } else {
  2704. arrayPush(result, value);
  2705. }
  2706. } else if (!isStrict) {
  2707. result[result.length] = value;
  2708. }
  2709. }
  2710. return result;
  2711. }
  2712. /**
  2713. * The base implementation of `baseForOwn` which iterates over `object`
  2714. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2715. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2716. *
  2717. * @private
  2718. * @param {Object} object The object to iterate over.
  2719. * @param {Function} iteratee The function invoked per iteration.
  2720. * @param {Function} keysFunc The function to get the keys of `object`.
  2721. * @returns {Object} Returns `object`.
  2722. */
  2723. var baseFor = createBaseFor();
  2724. /**
  2725. * This function is like `baseFor` except that it iterates over properties
  2726. * in the opposite order.
  2727. *
  2728. * @private
  2729. * @param {Object} object The object to iterate over.
  2730. * @param {Function} iteratee The function invoked per iteration.
  2731. * @param {Function} keysFunc The function to get the keys of `object`.
  2732. * @returns {Object} Returns `object`.
  2733. */
  2734. var baseForRight = createBaseFor(true);
  2735. /**
  2736. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2737. *
  2738. * @private
  2739. * @param {Object} object The object to iterate over.
  2740. * @param {Function} iteratee The function invoked per iteration.
  2741. * @returns {Object} Returns `object`.
  2742. */
  2743. function baseForOwn(object, iteratee) {
  2744. return object && baseFor(object, iteratee, keys);
  2745. }
  2746. /**
  2747. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2748. *
  2749. * @private
  2750. * @param {Object} object The object to iterate over.
  2751. * @param {Function} iteratee The function invoked per iteration.
  2752. * @returns {Object} Returns `object`.
  2753. */
  2754. function baseForOwnRight(object, iteratee) {
  2755. return object && baseForRight(object, iteratee, keys);
  2756. }
  2757. /**
  2758. * The base implementation of `_.functions` which creates an array of
  2759. * `object` function property names filtered from `props`.
  2760. *
  2761. * @private
  2762. * @param {Object} object The object to inspect.
  2763. * @param {Array} props The property names to filter.
  2764. * @returns {Array} Returns the function names.
  2765. */
  2766. function baseFunctions(object, props) {
  2767. return arrayFilter(props, function(key) {
  2768. return isFunction(object[key]);
  2769. });
  2770. }
  2771. /**
  2772. * The base implementation of `_.get` without support for default values.
  2773. *
  2774. * @private
  2775. * @param {Object} object The object to query.
  2776. * @param {Array|string} path The path of the property to get.
  2777. * @returns {*} Returns the resolved value.
  2778. */
  2779. function baseGet(object, path) {
  2780. path = castPath(path, object);
  2781. var index = 0,
  2782. length = path.length;
  2783. while (object != null && index < length) {
  2784. object = object[toKey(path[index++])];
  2785. }
  2786. return (index && index == length) ? object : undefined;
  2787. }
  2788. /**
  2789. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2790. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2791. * symbols of `object`.
  2792. *
  2793. * @private
  2794. * @param {Object} object The object to query.
  2795. * @param {Function} keysFunc The function to get the keys of `object`.
  2796. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2797. * @returns {Array} Returns the array of property names and symbols.
  2798. */
  2799. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2800. var result = keysFunc(object);
  2801. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2802. }
  2803. /**
  2804. * The base implementation of `getTag` without fallbacks for buggy environments.
  2805. *
  2806. * @private
  2807. * @param {*} value The value to query.
  2808. * @returns {string} Returns the `toStringTag`.
  2809. */
  2810. function baseGetTag(value) {
  2811. if (value == null) {
  2812. return value === undefined ? undefinedTag : nullTag;
  2813. }
  2814. return (symToStringTag && symToStringTag in Object(value))
  2815. ? getRawTag(value)
  2816. : objectToString(value);
  2817. }
  2818. /**
  2819. * The base implementation of `_.gt` which doesn't coerce arguments.
  2820. *
  2821. * @private
  2822. * @param {*} value The value to compare.
  2823. * @param {*} other The other value to compare.
  2824. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2825. * else `false`.
  2826. */
  2827. function baseGt(value, other) {
  2828. return value > other;
  2829. }
  2830. /**
  2831. * The base implementation of `_.has` without support for deep paths.
  2832. *
  2833. * @private
  2834. * @param {Object} [object] The object to query.
  2835. * @param {Array|string} key The key to check.
  2836. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2837. */
  2838. function baseHas(object, key) {
  2839. return object != null && hasOwnProperty.call(object, key);
  2840. }
  2841. /**
  2842. * The base implementation of `_.hasIn` without support for deep paths.
  2843. *
  2844. * @private
  2845. * @param {Object} [object] The object to query.
  2846. * @param {Array|string} key The key to check.
  2847. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2848. */
  2849. function baseHasIn(object, key) {
  2850. return object != null && key in Object(object);
  2851. }
  2852. /**
  2853. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2854. *
  2855. * @private
  2856. * @param {number} number The number to check.
  2857. * @param {number} start The start of the range.
  2858. * @param {number} end The end of the range.
  2859. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2860. */
  2861. function baseInRange(number, start, end) {
  2862. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2863. }
  2864. /**
  2865. * The base implementation of methods like `_.intersection`, without support
  2866. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2867. *
  2868. * @private
  2869. * @param {Array} arrays The arrays to inspect.
  2870. * @param {Function} [iteratee] The iteratee invoked per element.
  2871. * @param {Function} [comparator] The comparator invoked per element.
  2872. * @returns {Array} Returns the new array of shared values.
  2873. */
  2874. function baseIntersection(arrays, iteratee, comparator) {
  2875. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2876. length = arrays[0].length,
  2877. othLength = arrays.length,
  2878. othIndex = othLength,
  2879. caches = Array(othLength),
  2880. maxLength = Infinity,
  2881. result = [];
  2882. while (othIndex--) {
  2883. var array = arrays[othIndex];
  2884. if (othIndex && iteratee) {
  2885. array = arrayMap(array, baseUnary(iteratee));
  2886. }
  2887. maxLength = nativeMin(array.length, maxLength);
  2888. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2889. ? new SetCache(othIndex && array)
  2890. : undefined;
  2891. }
  2892. array = arrays[0];
  2893. var index = -1,
  2894. seen = caches[0];
  2895. outer:
  2896. while (++index < length && result.length < maxLength) {
  2897. var value = array[index],
  2898. computed = iteratee ? iteratee(value) : value;
  2899. value = (comparator || value !== 0) ? value : 0;
  2900. if (!(seen
  2901. ? cacheHas(seen, computed)
  2902. : includes(result, computed, comparator)
  2903. )) {
  2904. othIndex = othLength;
  2905. while (--othIndex) {
  2906. var cache = caches[othIndex];
  2907. if (!(cache
  2908. ? cacheHas(cache, computed)
  2909. : includes(arrays[othIndex], computed, comparator))
  2910. ) {
  2911. continue outer;
  2912. }
  2913. }
  2914. if (seen) {
  2915. seen.push(computed);
  2916. }
  2917. result.push(value);
  2918. }
  2919. }
  2920. return result;
  2921. }
  2922. /**
  2923. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2924. * `object` with values transformed by `iteratee` and set by `setter`.
  2925. *
  2926. * @private
  2927. * @param {Object} object The object to iterate over.
  2928. * @param {Function} setter The function to set `accumulator` values.
  2929. * @param {Function} iteratee The iteratee to transform values.
  2930. * @param {Object} accumulator The initial inverted object.
  2931. * @returns {Function} Returns `accumulator`.
  2932. */
  2933. function baseInverter(object, setter, iteratee, accumulator) {
  2934. baseForOwn(object, function(value, key, object) {
  2935. setter(accumulator, iteratee(value), key, object);
  2936. });
  2937. return accumulator;
  2938. }
  2939. /**
  2940. * The base implementation of `_.invoke` without support for individual
  2941. * method arguments.
  2942. *
  2943. * @private
  2944. * @param {Object} object The object to query.
  2945. * @param {Array|string} path The path of the method to invoke.
  2946. * @param {Array} args The arguments to invoke the method with.
  2947. * @returns {*} Returns the result of the invoked method.
  2948. */
  2949. function baseInvoke(object, path, args) {
  2950. path = castPath(path, object);
  2951. object = parent(object, path);
  2952. var func = object == null ? object : object[toKey(last(path))];
  2953. return func == null ? undefined : apply(func, object, args);
  2954. }
  2955. /**
  2956. * The base implementation of `_.isArguments`.
  2957. *
  2958. * @private
  2959. * @param {*} value The value to check.
  2960. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2961. */
  2962. function baseIsArguments(value) {
  2963. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2964. }
  2965. /**
  2966. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2967. *
  2968. * @private
  2969. * @param {*} value The value to check.
  2970. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2971. */
  2972. function baseIsArrayBuffer(value) {
  2973. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2974. }
  2975. /**
  2976. * The base implementation of `_.isDate` without Node.js optimizations.
  2977. *
  2978. * @private
  2979. * @param {*} value The value to check.
  2980. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2981. */
  2982. function baseIsDate(value) {
  2983. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2984. }
  2985. /**
  2986. * The base implementation of `_.isEqual` which supports partial comparisons
  2987. * and tracks traversed objects.
  2988. *
  2989. * @private
  2990. * @param {*} value The value to compare.
  2991. * @param {*} other The other value to compare.
  2992. * @param {boolean} bitmask The bitmask flags.
  2993. * 1 - Unordered comparison
  2994. * 2 - Partial comparison
  2995. * @param {Function} [customizer] The function to customize comparisons.
  2996. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2997. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2998. */
  2999. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3000. if (value === other) {
  3001. return true;
  3002. }
  3003. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  3004. return value !== value && other !== other;
  3005. }
  3006. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  3007. }
  3008. /**
  3009. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3010. * deep comparisons and tracks traversed objects enabling objects with circular
  3011. * references to be compared.
  3012. *
  3013. * @private
  3014. * @param {Object} object The object to compare.
  3015. * @param {Object} other The other object to compare.
  3016. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3017. * @param {Function} customizer The function to customize comparisons.
  3018. * @param {Function} equalFunc The function to determine equivalents of values.
  3019. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3020. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3021. */
  3022. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3023. var objIsArr = isArray(object),
  3024. othIsArr = isArray(other),
  3025. objTag = objIsArr ? arrayTag : getTag(object),
  3026. othTag = othIsArr ? arrayTag : getTag(other);
  3027. objTag = objTag == argsTag ? objectTag : objTag;
  3028. othTag = othTag == argsTag ? objectTag : othTag;
  3029. var objIsObj = objTag == objectTag,
  3030. othIsObj = othTag == objectTag,
  3031. isSameTag = objTag == othTag;
  3032. if (isSameTag && isBuffer(object)) {
  3033. if (!isBuffer(other)) {
  3034. return false;
  3035. }
  3036. objIsArr = true;
  3037. objIsObj = false;
  3038. }
  3039. if (isSameTag && !objIsObj) {
  3040. stack || (stack = new Stack);
  3041. return (objIsArr || isTypedArray(object))
  3042. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3043. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3044. }
  3045. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3046. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3047. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3048. if (objIsWrapped || othIsWrapped) {
  3049. var objUnwrapped = objIsWrapped ? object.value() : object,
  3050. othUnwrapped = othIsWrapped ? other.value() : other;
  3051. stack || (stack = new Stack);
  3052. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3053. }
  3054. }
  3055. if (!isSameTag) {
  3056. return false;
  3057. }
  3058. stack || (stack = new Stack);
  3059. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3060. }
  3061. /**
  3062. * The base implementation of `_.isMap` without Node.js optimizations.
  3063. *
  3064. * @private
  3065. * @param {*} value The value to check.
  3066. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3067. */
  3068. function baseIsMap(value) {
  3069. return isObjectLike(value) && getTag(value) == mapTag;
  3070. }
  3071. /**
  3072. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3073. *
  3074. * @private
  3075. * @param {Object} object The object to inspect.
  3076. * @param {Object} source The object of property values to match.
  3077. * @param {Array} matchData The property names, values, and compare flags to match.
  3078. * @param {Function} [customizer] The function to customize comparisons.
  3079. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3080. */
  3081. function baseIsMatch(object, source, matchData, customizer) {
  3082. var index = matchData.length,
  3083. length = index,
  3084. noCustomizer = !customizer;
  3085. if (object == null) {
  3086. return !length;
  3087. }
  3088. object = Object(object);
  3089. while (index--) {
  3090. var data = matchData[index];
  3091. if ((noCustomizer && data[2])
  3092. ? data[1] !== object[data[0]]
  3093. : !(data[0] in object)
  3094. ) {
  3095. return false;
  3096. }
  3097. }
  3098. while (++index < length) {
  3099. data = matchData[index];
  3100. var key = data[0],
  3101. objValue = object[key],
  3102. srcValue = data[1];
  3103. if (noCustomizer && data[2]) {
  3104. if (objValue === undefined && !(key in object)) {
  3105. return false;
  3106. }
  3107. } else {
  3108. var stack = new Stack;
  3109. if (customizer) {
  3110. var result = customizer(objValue, srcValue, key, object, source, stack);
  3111. }
  3112. if (!(result === undefined
  3113. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3114. : result
  3115. )) {
  3116. return false;
  3117. }
  3118. }
  3119. }
  3120. return true;
  3121. }
  3122. /**
  3123. * The base implementation of `_.isNative` without bad shim checks.
  3124. *
  3125. * @private
  3126. * @param {*} value The value to check.
  3127. * @returns {boolean} Returns `true` if `value` is a native function,
  3128. * else `false`.
  3129. */
  3130. function baseIsNative(value) {
  3131. if (!isObject(value) || isMasked(value)) {
  3132. return false;
  3133. }
  3134. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3135. return pattern.test(toSource(value));
  3136. }
  3137. /**
  3138. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3139. *
  3140. * @private
  3141. * @param {*} value The value to check.
  3142. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3143. */
  3144. function baseIsRegExp(value) {
  3145. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3146. }
  3147. /**
  3148. * The base implementation of `_.isSet` without Node.js optimizations.
  3149. *
  3150. * @private
  3151. * @param {*} value The value to check.
  3152. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3153. */
  3154. function baseIsSet(value) {
  3155. return isObjectLike(value) && getTag(value) == setTag;
  3156. }
  3157. /**
  3158. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3159. *
  3160. * @private
  3161. * @param {*} value The value to check.
  3162. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3163. */
  3164. function baseIsTypedArray(value) {
  3165. return isObjectLike(value) &&
  3166. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3167. }
  3168. /**
  3169. * The base implementation of `_.iteratee`.
  3170. *
  3171. * @private
  3172. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3173. * @returns {Function} Returns the iteratee.
  3174. */
  3175. function baseIteratee(value) {
  3176. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3177. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3178. if (typeof value == 'function') {
  3179. return value;
  3180. }
  3181. if (value == null) {
  3182. return identity;
  3183. }
  3184. if (typeof value == 'object') {
  3185. return isArray(value)
  3186. ? baseMatchesProperty(value[0], value[1])
  3187. : baseMatches(value);
  3188. }
  3189. return property(value);
  3190. }
  3191. /**
  3192. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3193. *
  3194. * @private
  3195. * @param {Object} object The object to query.
  3196. * @returns {Array} Returns the array of property names.
  3197. */
  3198. function baseKeys(object) {
  3199. if (!isPrototype(object)) {
  3200. return nativeKeys(object);
  3201. }
  3202. var result = [];
  3203. for (var key in Object(object)) {
  3204. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3205. result.push(key);
  3206. }
  3207. }
  3208. return result;
  3209. }
  3210. /**
  3211. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3212. *
  3213. * @private
  3214. * @param {Object} object The object to query.
  3215. * @returns {Array} Returns the array of property names.
  3216. */
  3217. function baseKeysIn(object) {
  3218. if (!isObject(object)) {
  3219. return nativeKeysIn(object);
  3220. }
  3221. var isProto = isPrototype(object),
  3222. result = [];
  3223. for (var key in object) {
  3224. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3225. result.push(key);
  3226. }
  3227. }
  3228. return result;
  3229. }
  3230. /**
  3231. * The base implementation of `_.lt` which doesn't coerce arguments.
  3232. *
  3233. * @private
  3234. * @param {*} value The value to compare.
  3235. * @param {*} other The other value to compare.
  3236. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3237. * else `false`.
  3238. */
  3239. function baseLt(value, other) {
  3240. return value < other;
  3241. }
  3242. /**
  3243. * The base implementation of `_.map` without support for iteratee shorthands.
  3244. *
  3245. * @private
  3246. * @param {Array|Object} collection The collection to iterate over.
  3247. * @param {Function} iteratee The function invoked per iteration.
  3248. * @returns {Array} Returns the new mapped array.
  3249. */
  3250. function baseMap(collection, iteratee) {
  3251. var index = -1,
  3252. result = isArrayLike(collection) ? Array(collection.length) : [];
  3253. baseEach(collection, function(value, key, collection) {
  3254. result[++index] = iteratee(value, key, collection);
  3255. });
  3256. return result;
  3257. }
  3258. /**
  3259. * The base implementation of `_.matches` which doesn't clone `source`.
  3260. *
  3261. * @private
  3262. * @param {Object} source The object of property values to match.
  3263. * @returns {Function} Returns the new spec function.
  3264. */
  3265. function baseMatches(source) {
  3266. var matchData = getMatchData(source);
  3267. if (matchData.length == 1 && matchData[0][2]) {
  3268. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3269. }
  3270. return function(object) {
  3271. return object === source || baseIsMatch(object, source, matchData);
  3272. };
  3273. }
  3274. /**
  3275. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3276. *
  3277. * @private
  3278. * @param {string} path The path of the property to get.
  3279. * @param {*} srcValue The value to match.
  3280. * @returns {Function} Returns the new spec function.
  3281. */
  3282. function baseMatchesProperty(path, srcValue) {
  3283. if (isKey(path) && isStrictComparable(srcValue)) {
  3284. return matchesStrictComparable(toKey(path), srcValue);
  3285. }
  3286. return function(object) {
  3287. var objValue = get(object, path);
  3288. return (objValue === undefined && objValue === srcValue)
  3289. ? hasIn(object, path)
  3290. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3291. };
  3292. }
  3293. /**
  3294. * The base implementation of `_.merge` without support for multiple sources.
  3295. *
  3296. * @private
  3297. * @param {Object} object The destination object.
  3298. * @param {Object} source The source object.
  3299. * @param {number} srcIndex The index of `source`.
  3300. * @param {Function} [customizer] The function to customize merged values.
  3301. * @param {Object} [stack] Tracks traversed source values and their merged
  3302. * counterparts.
  3303. */
  3304. function baseMerge(object, source, srcIndex, customizer, stack) {
  3305. if (object === source) {
  3306. return;
  3307. }
  3308. baseFor(source, function(srcValue, key) {
  3309. stack || (stack = new Stack);
  3310. if (isObject(srcValue)) {
  3311. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3312. }
  3313. else {
  3314. var newValue = customizer
  3315. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3316. : undefined;
  3317. if (newValue === undefined) {
  3318. newValue = srcValue;
  3319. }
  3320. assignMergeValue(object, key, newValue);
  3321. }
  3322. }, keysIn);
  3323. }
  3324. /**
  3325. * A specialized version of `baseMerge` for arrays and objects which performs
  3326. * deep merges and tracks traversed objects enabling objects with circular
  3327. * references to be merged.
  3328. *
  3329. * @private
  3330. * @param {Object} object The destination object.
  3331. * @param {Object} source The source object.
  3332. * @param {string} key The key of the value to merge.
  3333. * @param {number} srcIndex The index of `source`.
  3334. * @param {Function} mergeFunc The function to merge values.
  3335. * @param {Function} [customizer] The function to customize assigned values.
  3336. * @param {Object} [stack] Tracks traversed source values and their merged
  3337. * counterparts.
  3338. */
  3339. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3340. var objValue = safeGet(object, key),
  3341. srcValue = safeGet(source, key),
  3342. stacked = stack.get(srcValue);
  3343. if (stacked) {
  3344. assignMergeValue(object, key, stacked);
  3345. return;
  3346. }
  3347. var newValue = customizer
  3348. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3349. : undefined;
  3350. var isCommon = newValue === undefined;
  3351. if (isCommon) {
  3352. var isArr = isArray(srcValue),
  3353. isBuff = !isArr && isBuffer(srcValue),
  3354. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3355. newValue = srcValue;
  3356. if (isArr || isBuff || isTyped) {
  3357. if (isArray(objValue)) {
  3358. newValue = objValue;
  3359. }
  3360. else if (isArrayLikeObject(objValue)) {
  3361. newValue = copyArray(objValue);
  3362. }
  3363. else if (isBuff) {
  3364. isCommon = false;
  3365. newValue = cloneBuffer(srcValue, true);
  3366. }
  3367. else if (isTyped) {
  3368. isCommon = false;
  3369. newValue = cloneTypedArray(srcValue, true);
  3370. }
  3371. else {
  3372. newValue = [];
  3373. }
  3374. }
  3375. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3376. newValue = objValue;
  3377. if (isArguments(objValue)) {
  3378. newValue = toPlainObject(objValue);
  3379. }
  3380. else if (!isObject(objValue) || isFunction(objValue)) {
  3381. newValue = initCloneObject(srcValue);
  3382. }
  3383. }
  3384. else {
  3385. isCommon = false;
  3386. }
  3387. }
  3388. if (isCommon) {
  3389. // Recursively merge objects and arrays (susceptible to call stack limits).
  3390. stack.set(srcValue, newValue);
  3391. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3392. stack['delete'](srcValue);
  3393. }
  3394. assignMergeValue(object, key, newValue);
  3395. }
  3396. /**
  3397. * The base implementation of `_.nth` which doesn't coerce arguments.
  3398. *
  3399. * @private
  3400. * @param {Array} array The array to query.
  3401. * @param {number} n The index of the element to return.
  3402. * @returns {*} Returns the nth element of `array`.
  3403. */
  3404. function baseNth(array, n) {
  3405. var length = array.length;
  3406. if (!length) {
  3407. return;
  3408. }
  3409. n += n < 0 ? length : 0;
  3410. return isIndex(n, length) ? array[n] : undefined;
  3411. }
  3412. /**
  3413. * The base implementation of `_.orderBy` without param guards.
  3414. *
  3415. * @private
  3416. * @param {Array|Object} collection The collection to iterate over.
  3417. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3418. * @param {string[]} orders The sort orders of `iteratees`.
  3419. * @returns {Array} Returns the new sorted array.
  3420. */
  3421. function baseOrderBy(collection, iteratees, orders) {
  3422. if (iteratees.length) {
  3423. iteratees = arrayMap(iteratees, function(iteratee) {
  3424. if (isArray(iteratee)) {
  3425. return function(value) {
  3426. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  3427. }
  3428. }
  3429. return iteratee;
  3430. });
  3431. } else {
  3432. iteratees = [identity];
  3433. }
  3434. var index = -1;
  3435. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  3436. var result = baseMap(collection, function(value, key, collection) {
  3437. var criteria = arrayMap(iteratees, function(iteratee) {
  3438. return iteratee(value);
  3439. });
  3440. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3441. });
  3442. return baseSortBy(result, function(object, other) {
  3443. return compareMultiple(object, other, orders);
  3444. });
  3445. }
  3446. /**
  3447. * The base implementation of `_.pick` without support for individual
  3448. * property identifiers.
  3449. *
  3450. * @private
  3451. * @param {Object} object The source object.
  3452. * @param {string[]} paths The property paths to pick.
  3453. * @returns {Object} Returns the new object.
  3454. */
  3455. function basePick(object, paths) {
  3456. return basePickBy(object, paths, function(value, path) {
  3457. return hasIn(object, path);
  3458. });
  3459. }
  3460. /**
  3461. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3462. *
  3463. * @private
  3464. * @param {Object} object The source object.
  3465. * @param {string[]} paths The property paths to pick.
  3466. * @param {Function} predicate The function invoked per property.
  3467. * @returns {Object} Returns the new object.
  3468. */
  3469. function basePickBy(object, paths, predicate) {
  3470. var index = -1,
  3471. length = paths.length,
  3472. result = {};
  3473. while (++index < length) {
  3474. var path = paths[index],
  3475. value = baseGet(object, path);
  3476. if (predicate(value, path)) {
  3477. baseSet(result, castPath(path, object), value);
  3478. }
  3479. }
  3480. return result;
  3481. }
  3482. /**
  3483. * A specialized version of `baseProperty` which supports deep paths.
  3484. *
  3485. * @private
  3486. * @param {Array|string} path The path of the property to get.
  3487. * @returns {Function} Returns the new accessor function.
  3488. */
  3489. function basePropertyDeep(path) {
  3490. return function(object) {
  3491. return baseGet(object, path);
  3492. };
  3493. }
  3494. /**
  3495. * The base implementation of `_.pullAllBy` without support for iteratee
  3496. * shorthands.
  3497. *
  3498. * @private
  3499. * @param {Array} array The array to modify.
  3500. * @param {Array} values The values to remove.
  3501. * @param {Function} [iteratee] The iteratee invoked per element.
  3502. * @param {Function} [comparator] The comparator invoked per element.
  3503. * @returns {Array} Returns `array`.
  3504. */
  3505. function basePullAll(array, values, iteratee, comparator) {
  3506. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3507. index = -1,
  3508. length = values.length,
  3509. seen = array;
  3510. if (array === values) {
  3511. values = copyArray(values);
  3512. }
  3513. if (iteratee) {
  3514. seen = arrayMap(array, baseUnary(iteratee));
  3515. }
  3516. while (++index < length) {
  3517. var fromIndex = 0,
  3518. value = values[index],
  3519. computed = iteratee ? iteratee(value) : value;
  3520. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3521. if (seen !== array) {
  3522. splice.call(seen, fromIndex, 1);
  3523. }
  3524. splice.call(array, fromIndex, 1);
  3525. }
  3526. }
  3527. return array;
  3528. }
  3529. /**
  3530. * The base implementation of `_.pullAt` without support for individual
  3531. * indexes or capturing the removed elements.
  3532. *
  3533. * @private
  3534. * @param {Array} array The array to modify.
  3535. * @param {number[]} indexes The indexes of elements to remove.
  3536. * @returns {Array} Returns `array`.
  3537. */
  3538. function basePullAt(array, indexes) {
  3539. var length = array ? indexes.length : 0,
  3540. lastIndex = length - 1;
  3541. while (length--) {
  3542. var index = indexes[length];
  3543. if (length == lastIndex || index !== previous) {
  3544. var previous = index;
  3545. if (isIndex(index)) {
  3546. splice.call(array, index, 1);
  3547. } else {
  3548. baseUnset(array, index);
  3549. }
  3550. }
  3551. }
  3552. return array;
  3553. }
  3554. /**
  3555. * The base implementation of `_.random` without support for returning
  3556. * floating-point numbers.
  3557. *
  3558. * @private
  3559. * @param {number} lower The lower bound.
  3560. * @param {number} upper The upper bound.
  3561. * @returns {number} Returns the random number.
  3562. */
  3563. function baseRandom(lower, upper) {
  3564. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3565. }
  3566. /**
  3567. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3568. * coerce arguments.
  3569. *
  3570. * @private
  3571. * @param {number} start The start of the range.
  3572. * @param {number} end The end of the range.
  3573. * @param {number} step The value to increment or decrement by.
  3574. * @param {boolean} [fromRight] Specify iterating from right to left.
  3575. * @returns {Array} Returns the range of numbers.
  3576. */
  3577. function baseRange(start, end, step, fromRight) {
  3578. var index = -1,
  3579. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3580. result = Array(length);
  3581. while (length--) {
  3582. result[fromRight ? length : ++index] = start;
  3583. start += step;
  3584. }
  3585. return result;
  3586. }
  3587. /**
  3588. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3589. *
  3590. * @private
  3591. * @param {string} string The string to repeat.
  3592. * @param {number} n The number of times to repeat the string.
  3593. * @returns {string} Returns the repeated string.
  3594. */
  3595. function baseRepeat(string, n) {
  3596. var result = '';
  3597. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3598. return result;
  3599. }
  3600. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3601. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3602. do {
  3603. if (n % 2) {
  3604. result += string;
  3605. }
  3606. n = nativeFloor(n / 2);
  3607. if (n) {
  3608. string += string;
  3609. }
  3610. } while (n);
  3611. return result;
  3612. }
  3613. /**
  3614. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3615. *
  3616. * @private
  3617. * @param {Function} func The function to apply a rest parameter to.
  3618. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3619. * @returns {Function} Returns the new function.
  3620. */
  3621. function baseRest(func, start) {
  3622. return setToString(overRest(func, start, identity), func + '');
  3623. }
  3624. /**
  3625. * The base implementation of `_.sample`.
  3626. *
  3627. * @private
  3628. * @param {Array|Object} collection The collection to sample.
  3629. * @returns {*} Returns the random element.
  3630. */
  3631. function baseSample(collection) {
  3632. return arraySample(values(collection));
  3633. }
  3634. /**
  3635. * The base implementation of `_.sampleSize` without param guards.
  3636. *
  3637. * @private
  3638. * @param {Array|Object} collection The collection to sample.
  3639. * @param {number} n The number of elements to sample.
  3640. * @returns {Array} Returns the random elements.
  3641. */
  3642. function baseSampleSize(collection, n) {
  3643. var array = values(collection);
  3644. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3645. }
  3646. /**
  3647. * The base implementation of `_.set`.
  3648. *
  3649. * @private
  3650. * @param {Object} object The object to modify.
  3651. * @param {Array|string} path The path of the property to set.
  3652. * @param {*} value The value to set.
  3653. * @param {Function} [customizer] The function to customize path creation.
  3654. * @returns {Object} Returns `object`.
  3655. */
  3656. function baseSet(object, path, value, customizer) {
  3657. if (!isObject(object)) {
  3658. return object;
  3659. }
  3660. path = castPath(path, object);
  3661. var index = -1,
  3662. length = path.length,
  3663. lastIndex = length - 1,
  3664. nested = object;
  3665. while (nested != null && ++index < length) {
  3666. var key = toKey(path[index]),
  3667. newValue = value;
  3668. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  3669. return object;
  3670. }
  3671. if (index != lastIndex) {
  3672. var objValue = nested[key];
  3673. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3674. if (newValue === undefined) {
  3675. newValue = isObject(objValue)
  3676. ? objValue
  3677. : (isIndex(path[index + 1]) ? [] : {});
  3678. }
  3679. }
  3680. assignValue(nested, key, newValue);
  3681. nested = nested[key];
  3682. }
  3683. return object;
  3684. }
  3685. /**
  3686. * The base implementation of `setData` without support for hot loop shorting.
  3687. *
  3688. * @private
  3689. * @param {Function} func The function to associate metadata with.
  3690. * @param {*} data The metadata.
  3691. * @returns {Function} Returns `func`.
  3692. */
  3693. var baseSetData = !metaMap ? identity : function(func, data) {
  3694. metaMap.set(func, data);
  3695. return func;
  3696. };
  3697. /**
  3698. * The base implementation of `setToString` without support for hot loop shorting.
  3699. *
  3700. * @private
  3701. * @param {Function} func The function to modify.
  3702. * @param {Function} string The `toString` result.
  3703. * @returns {Function} Returns `func`.
  3704. */
  3705. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3706. return defineProperty(func, 'toString', {
  3707. 'configurable': true,
  3708. 'enumerable': false,
  3709. 'value': constant(string),
  3710. 'writable': true
  3711. });
  3712. };
  3713. /**
  3714. * The base implementation of `_.shuffle`.
  3715. *
  3716. * @private
  3717. * @param {Array|Object} collection The collection to shuffle.
  3718. * @returns {Array} Returns the new shuffled array.
  3719. */
  3720. function baseShuffle(collection) {
  3721. return shuffleSelf(values(collection));
  3722. }
  3723. /**
  3724. * The base implementation of `_.slice` without an iteratee call guard.
  3725. *
  3726. * @private
  3727. * @param {Array} array The array to slice.
  3728. * @param {number} [start=0] The start position.
  3729. * @param {number} [end=array.length] The end position.
  3730. * @returns {Array} Returns the slice of `array`.
  3731. */
  3732. function baseSlice(array, start, end) {
  3733. var index = -1,
  3734. length = array.length;
  3735. if (start < 0) {
  3736. start = -start > length ? 0 : (length + start);
  3737. }
  3738. end = end > length ? length : end;
  3739. if (end < 0) {
  3740. end += length;
  3741. }
  3742. length = start > end ? 0 : ((end - start) >>> 0);
  3743. start >>>= 0;
  3744. var result = Array(length);
  3745. while (++index < length) {
  3746. result[index] = array[index + start];
  3747. }
  3748. return result;
  3749. }
  3750. /**
  3751. * The base implementation of `_.some` without support for iteratee shorthands.
  3752. *
  3753. * @private
  3754. * @param {Array|Object} collection The collection to iterate over.
  3755. * @param {Function} predicate The function invoked per iteration.
  3756. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3757. * else `false`.
  3758. */
  3759. function baseSome(collection, predicate) {
  3760. var result;
  3761. baseEach(collection, function(value, index, collection) {
  3762. result = predicate(value, index, collection);
  3763. return !result;
  3764. });
  3765. return !!result;
  3766. }
  3767. /**
  3768. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3769. * performs a binary search of `array` to determine the index at which `value`
  3770. * should be inserted into `array` in order to maintain its sort order.
  3771. *
  3772. * @private
  3773. * @param {Array} array The sorted array to inspect.
  3774. * @param {*} value The value to evaluate.
  3775. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3776. * @returns {number} Returns the index at which `value` should be inserted
  3777. * into `array`.
  3778. */
  3779. function baseSortedIndex(array, value, retHighest) {
  3780. var low = 0,
  3781. high = array == null ? low : array.length;
  3782. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3783. while (low < high) {
  3784. var mid = (low + high) >>> 1,
  3785. computed = array[mid];
  3786. if (computed !== null && !isSymbol(computed) &&
  3787. (retHighest ? (computed <= value) : (computed < value))) {
  3788. low = mid + 1;
  3789. } else {
  3790. high = mid;
  3791. }
  3792. }
  3793. return high;
  3794. }
  3795. return baseSortedIndexBy(array, value, identity, retHighest);
  3796. }
  3797. /**
  3798. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3799. * which invokes `iteratee` for `value` and each element of `array` to compute
  3800. * their sort ranking. The iteratee is invoked with one argument; (value).
  3801. *
  3802. * @private
  3803. * @param {Array} array The sorted array to inspect.
  3804. * @param {*} value The value to evaluate.
  3805. * @param {Function} iteratee The iteratee invoked per element.
  3806. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3807. * @returns {number} Returns the index at which `value` should be inserted
  3808. * into `array`.
  3809. */
  3810. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3811. var low = 0,
  3812. high = array == null ? 0 : array.length;
  3813. if (high === 0) {
  3814. return 0;
  3815. }
  3816. value = iteratee(value);
  3817. var valIsNaN = value !== value,
  3818. valIsNull = value === null,
  3819. valIsSymbol = isSymbol(value),
  3820. valIsUndefined = value === undefined;
  3821. while (low < high) {
  3822. var mid = nativeFloor((low + high) / 2),
  3823. computed = iteratee(array[mid]),
  3824. othIsDefined = computed !== undefined,
  3825. othIsNull = computed === null,
  3826. othIsReflexive = computed === computed,
  3827. othIsSymbol = isSymbol(computed);
  3828. if (valIsNaN) {
  3829. var setLow = retHighest || othIsReflexive;
  3830. } else if (valIsUndefined) {
  3831. setLow = othIsReflexive && (retHighest || othIsDefined);
  3832. } else if (valIsNull) {
  3833. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3834. } else if (valIsSymbol) {
  3835. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3836. } else if (othIsNull || othIsSymbol) {
  3837. setLow = false;
  3838. } else {
  3839. setLow = retHighest ? (computed <= value) : (computed < value);
  3840. }
  3841. if (setLow) {
  3842. low = mid + 1;
  3843. } else {
  3844. high = mid;
  3845. }
  3846. }
  3847. return nativeMin(high, MAX_ARRAY_INDEX);
  3848. }
  3849. /**
  3850. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3851. * support for iteratee shorthands.
  3852. *
  3853. * @private
  3854. * @param {Array} array The array to inspect.
  3855. * @param {Function} [iteratee] The iteratee invoked per element.
  3856. * @returns {Array} Returns the new duplicate free array.
  3857. */
  3858. function baseSortedUniq(array, iteratee) {
  3859. var index = -1,
  3860. length = array.length,
  3861. resIndex = 0,
  3862. result = [];
  3863. while (++index < length) {
  3864. var value = array[index],
  3865. computed = iteratee ? iteratee(value) : value;
  3866. if (!index || !eq(computed, seen)) {
  3867. var seen = computed;
  3868. result[resIndex++] = value === 0 ? 0 : value;
  3869. }
  3870. }
  3871. return result;
  3872. }
  3873. /**
  3874. * The base implementation of `_.toNumber` which doesn't ensure correct
  3875. * conversions of binary, hexadecimal, or octal string values.
  3876. *
  3877. * @private
  3878. * @param {*} value The value to process.
  3879. * @returns {number} Returns the number.
  3880. */
  3881. function baseToNumber(value) {
  3882. if (typeof value == 'number') {
  3883. return value;
  3884. }
  3885. if (isSymbol(value)) {
  3886. return NAN;
  3887. }
  3888. return +value;
  3889. }
  3890. /**
  3891. * The base implementation of `_.toString` which doesn't convert nullish
  3892. * values to empty strings.
  3893. *
  3894. * @private
  3895. * @param {*} value The value to process.
  3896. * @returns {string} Returns the string.
  3897. */
  3898. function baseToString(value) {
  3899. // Exit early for strings to avoid a performance hit in some environments.
  3900. if (typeof value == 'string') {
  3901. return value;
  3902. }
  3903. if (isArray(value)) {
  3904. // Recursively convert values (susceptible to call stack limits).
  3905. return arrayMap(value, baseToString) + '';
  3906. }
  3907. if (isSymbol(value)) {
  3908. return symbolToString ? symbolToString.call(value) : '';
  3909. }
  3910. var result = (value + '');
  3911. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3912. }
  3913. /**
  3914. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3915. *
  3916. * @private
  3917. * @param {Array} array The array to inspect.
  3918. * @param {Function} [iteratee] The iteratee invoked per element.
  3919. * @param {Function} [comparator] The comparator invoked per element.
  3920. * @returns {Array} Returns the new duplicate free array.
  3921. */
  3922. function baseUniq(array, iteratee, comparator) {
  3923. var index = -1,
  3924. includes = arrayIncludes,
  3925. length = array.length,
  3926. isCommon = true,
  3927. result = [],
  3928. seen = result;
  3929. if (comparator) {
  3930. isCommon = false;
  3931. includes = arrayIncludesWith;
  3932. }
  3933. else if (length >= LARGE_ARRAY_SIZE) {
  3934. var set = iteratee ? null : createSet(array);
  3935. if (set) {
  3936. return setToArray(set);
  3937. }
  3938. isCommon = false;
  3939. includes = cacheHas;
  3940. seen = new SetCache;
  3941. }
  3942. else {
  3943. seen = iteratee ? [] : result;
  3944. }
  3945. outer:
  3946. while (++index < length) {
  3947. var value = array[index],
  3948. computed = iteratee ? iteratee(value) : value;
  3949. value = (comparator || value !== 0) ? value : 0;
  3950. if (isCommon && computed === computed) {
  3951. var seenIndex = seen.length;
  3952. while (seenIndex--) {
  3953. if (seen[seenIndex] === computed) {
  3954. continue outer;
  3955. }
  3956. }
  3957. if (iteratee) {
  3958. seen.push(computed);
  3959. }
  3960. result.push(value);
  3961. }
  3962. else if (!includes(seen, computed, comparator)) {
  3963. if (seen !== result) {
  3964. seen.push(computed);
  3965. }
  3966. result.push(value);
  3967. }
  3968. }
  3969. return result;
  3970. }
  3971. /**
  3972. * The base implementation of `_.unset`.
  3973. *
  3974. * @private
  3975. * @param {Object} object The object to modify.
  3976. * @param {Array|string} path The property path to unset.
  3977. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3978. */
  3979. function baseUnset(object, path) {
  3980. path = castPath(path, object);
  3981. object = parent(object, path);
  3982. return object == null || delete object[toKey(last(path))];
  3983. }
  3984. /**
  3985. * The base implementation of `_.update`.
  3986. *
  3987. * @private
  3988. * @param {Object} object The object to modify.
  3989. * @param {Array|string} path The path of the property to update.
  3990. * @param {Function} updater The function to produce the updated value.
  3991. * @param {Function} [customizer] The function to customize path creation.
  3992. * @returns {Object} Returns `object`.
  3993. */
  3994. function baseUpdate(object, path, updater, customizer) {
  3995. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3996. }
  3997. /**
  3998. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3999. * without support for iteratee shorthands.
  4000. *
  4001. * @private
  4002. * @param {Array} array The array to query.
  4003. * @param {Function} predicate The function invoked per iteration.
  4004. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4005. * @param {boolean} [fromRight] Specify iterating from right to left.
  4006. * @returns {Array} Returns the slice of `array`.
  4007. */
  4008. function baseWhile(array, predicate, isDrop, fromRight) {
  4009. var length = array.length,
  4010. index = fromRight ? length : -1;
  4011. while ((fromRight ? index-- : ++index < length) &&
  4012. predicate(array[index], index, array)) {}
  4013. return isDrop
  4014. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4015. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4016. }
  4017. /**
  4018. * The base implementation of `wrapperValue` which returns the result of
  4019. * performing a sequence of actions on the unwrapped `value`, where each
  4020. * successive action is supplied the return value of the previous.
  4021. *
  4022. * @private
  4023. * @param {*} value The unwrapped value.
  4024. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4025. * @returns {*} Returns the resolved value.
  4026. */
  4027. function baseWrapperValue(value, actions) {
  4028. var result = value;
  4029. if (result instanceof LazyWrapper) {
  4030. result = result.value();
  4031. }
  4032. return arrayReduce(actions, function(result, action) {
  4033. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  4034. }, result);
  4035. }
  4036. /**
  4037. * The base implementation of methods like `_.xor`, without support for
  4038. * iteratee shorthands, that accepts an array of arrays to inspect.
  4039. *
  4040. * @private
  4041. * @param {Array} arrays The arrays to inspect.
  4042. * @param {Function} [iteratee] The iteratee invoked per element.
  4043. * @param {Function} [comparator] The comparator invoked per element.
  4044. * @returns {Array} Returns the new array of values.
  4045. */
  4046. function baseXor(arrays, iteratee, comparator) {
  4047. var length = arrays.length;
  4048. if (length < 2) {
  4049. return length ? baseUniq(arrays[0]) : [];
  4050. }
  4051. var index = -1,
  4052. result = Array(length);
  4053. while (++index < length) {
  4054. var array = arrays[index],
  4055. othIndex = -1;
  4056. while (++othIndex < length) {
  4057. if (othIndex != index) {
  4058. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4059. }
  4060. }
  4061. }
  4062. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4063. }
  4064. /**
  4065. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4066. *
  4067. * @private
  4068. * @param {Array} props The property identifiers.
  4069. * @param {Array} values The property values.
  4070. * @param {Function} assignFunc The function to assign values.
  4071. * @returns {Object} Returns the new object.
  4072. */
  4073. function baseZipObject(props, values, assignFunc) {
  4074. var index = -1,
  4075. length = props.length,
  4076. valsLength = values.length,
  4077. result = {};
  4078. while (++index < length) {
  4079. var value = index < valsLength ? values[index] : undefined;
  4080. assignFunc(result, props[index], value);
  4081. }
  4082. return result;
  4083. }
  4084. /**
  4085. * Casts `value` to an empty array if it's not an array like object.
  4086. *
  4087. * @private
  4088. * @param {*} value The value to inspect.
  4089. * @returns {Array|Object} Returns the cast array-like object.
  4090. */
  4091. function castArrayLikeObject(value) {
  4092. return isArrayLikeObject(value) ? value : [];
  4093. }
  4094. /**
  4095. * Casts `value` to `identity` if it's not a function.
  4096. *
  4097. * @private
  4098. * @param {*} value The value to inspect.
  4099. * @returns {Function} Returns cast function.
  4100. */
  4101. function castFunction(value) {
  4102. return typeof value == 'function' ? value : identity;
  4103. }
  4104. /**
  4105. * Casts `value` to a path array if it's not one.
  4106. *
  4107. * @private
  4108. * @param {*} value The value to inspect.
  4109. * @param {Object} [object] The object to query keys on.
  4110. * @returns {Array} Returns the cast property path array.
  4111. */
  4112. function castPath(value, object) {
  4113. if (isArray(value)) {
  4114. return value;
  4115. }
  4116. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4117. }
  4118. /**
  4119. * A `baseRest` alias which can be replaced with `identity` by module
  4120. * replacement plugins.
  4121. *
  4122. * @private
  4123. * @type {Function}
  4124. * @param {Function} func The function to apply a rest parameter to.
  4125. * @returns {Function} Returns the new function.
  4126. */
  4127. var castRest = baseRest;
  4128. /**
  4129. * Casts `array` to a slice if it's needed.
  4130. *
  4131. * @private
  4132. * @param {Array} array The array to inspect.
  4133. * @param {number} start The start position.
  4134. * @param {number} [end=array.length] The end position.
  4135. * @returns {Array} Returns the cast slice.
  4136. */
  4137. function castSlice(array, start, end) {
  4138. var length = array.length;
  4139. end = end === undefined ? length : end;
  4140. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4141. }
  4142. /**
  4143. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4144. *
  4145. * @private
  4146. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4147. */
  4148. var clearTimeout = ctxClearTimeout || function(id) {
  4149. return root.clearTimeout(id);
  4150. };
  4151. /**
  4152. * Creates a clone of `buffer`.
  4153. *
  4154. * @private
  4155. * @param {Buffer} buffer The buffer to clone.
  4156. * @param {boolean} [isDeep] Specify a deep clone.
  4157. * @returns {Buffer} Returns the cloned buffer.
  4158. */
  4159. function cloneBuffer(buffer, isDeep) {
  4160. if (isDeep) {
  4161. return buffer.slice();
  4162. }
  4163. var length = buffer.length,
  4164. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4165. buffer.copy(result);
  4166. return result;
  4167. }
  4168. /**
  4169. * Creates a clone of `arrayBuffer`.
  4170. *
  4171. * @private
  4172. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4173. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4174. */
  4175. function cloneArrayBuffer(arrayBuffer) {
  4176. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4177. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4178. return result;
  4179. }
  4180. /**
  4181. * Creates a clone of `dataView`.
  4182. *
  4183. * @private
  4184. * @param {Object} dataView The data view to clone.
  4185. * @param {boolean} [isDeep] Specify a deep clone.
  4186. * @returns {Object} Returns the cloned data view.
  4187. */
  4188. function cloneDataView(dataView, isDeep) {
  4189. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4190. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4191. }
  4192. /**
  4193. * Creates a clone of `regexp`.
  4194. *
  4195. * @private
  4196. * @param {Object} regexp The regexp to clone.
  4197. * @returns {Object} Returns the cloned regexp.
  4198. */
  4199. function cloneRegExp(regexp) {
  4200. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4201. result.lastIndex = regexp.lastIndex;
  4202. return result;
  4203. }
  4204. /**
  4205. * Creates a clone of the `symbol` object.
  4206. *
  4207. * @private
  4208. * @param {Object} symbol The symbol object to clone.
  4209. * @returns {Object} Returns the cloned symbol object.
  4210. */
  4211. function cloneSymbol(symbol) {
  4212. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4213. }
  4214. /**
  4215. * Creates a clone of `typedArray`.
  4216. *
  4217. * @private
  4218. * @param {Object} typedArray The typed array to clone.
  4219. * @param {boolean} [isDeep] Specify a deep clone.
  4220. * @returns {Object} Returns the cloned typed array.
  4221. */
  4222. function cloneTypedArray(typedArray, isDeep) {
  4223. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4224. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4225. }
  4226. /**
  4227. * Compares values to sort them in ascending order.
  4228. *
  4229. * @private
  4230. * @param {*} value The value to compare.
  4231. * @param {*} other The other value to compare.
  4232. * @returns {number} Returns the sort order indicator for `value`.
  4233. */
  4234. function compareAscending(value, other) {
  4235. if (value !== other) {
  4236. var valIsDefined = value !== undefined,
  4237. valIsNull = value === null,
  4238. valIsReflexive = value === value,
  4239. valIsSymbol = isSymbol(value);
  4240. var othIsDefined = other !== undefined,
  4241. othIsNull = other === null,
  4242. othIsReflexive = other === other,
  4243. othIsSymbol = isSymbol(other);
  4244. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4245. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4246. (valIsNull && othIsDefined && othIsReflexive) ||
  4247. (!valIsDefined && othIsReflexive) ||
  4248. !valIsReflexive) {
  4249. return 1;
  4250. }
  4251. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4252. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4253. (othIsNull && valIsDefined && valIsReflexive) ||
  4254. (!othIsDefined && valIsReflexive) ||
  4255. !othIsReflexive) {
  4256. return -1;
  4257. }
  4258. }
  4259. return 0;
  4260. }
  4261. /**
  4262. * Used by `_.orderBy` to compare multiple properties of a value to another
  4263. * and stable sort them.
  4264. *
  4265. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4266. * specify an order of "desc" for descending or "asc" for ascending sort order
  4267. * of corresponding values.
  4268. *
  4269. * @private
  4270. * @param {Object} object The object to compare.
  4271. * @param {Object} other The other object to compare.
  4272. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4273. * @returns {number} Returns the sort order indicator for `object`.
  4274. */
  4275. function compareMultiple(object, other, orders) {
  4276. var index = -1,
  4277. objCriteria = object.criteria,
  4278. othCriteria = other.criteria,
  4279. length = objCriteria.length,
  4280. ordersLength = orders.length;
  4281. while (++index < length) {
  4282. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4283. if (result) {
  4284. if (index >= ordersLength) {
  4285. return result;
  4286. }
  4287. var order = orders[index];
  4288. return result * (order == 'desc' ? -1 : 1);
  4289. }
  4290. }
  4291. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4292. // that causes it, under certain circumstances, to provide the same value for
  4293. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4294. // for more details.
  4295. //
  4296. // This also ensures a stable sort in V8 and other engines.
  4297. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4298. return object.index - other.index;
  4299. }
  4300. /**
  4301. * Creates an array that is the composition of partially applied arguments,
  4302. * placeholders, and provided arguments into a single array of arguments.
  4303. *
  4304. * @private
  4305. * @param {Array} args The provided arguments.
  4306. * @param {Array} partials The arguments to prepend to those provided.
  4307. * @param {Array} holders The `partials` placeholder indexes.
  4308. * @params {boolean} [isCurried] Specify composing for a curried function.
  4309. * @returns {Array} Returns the new array of composed arguments.
  4310. */
  4311. function composeArgs(args, partials, holders, isCurried) {
  4312. var argsIndex = -1,
  4313. argsLength = args.length,
  4314. holdersLength = holders.length,
  4315. leftIndex = -1,
  4316. leftLength = partials.length,
  4317. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4318. result = Array(leftLength + rangeLength),
  4319. isUncurried = !isCurried;
  4320. while (++leftIndex < leftLength) {
  4321. result[leftIndex] = partials[leftIndex];
  4322. }
  4323. while (++argsIndex < holdersLength) {
  4324. if (isUncurried || argsIndex < argsLength) {
  4325. result[holders[argsIndex]] = args[argsIndex];
  4326. }
  4327. }
  4328. while (rangeLength--) {
  4329. result[leftIndex++] = args[argsIndex++];
  4330. }
  4331. return result;
  4332. }
  4333. /**
  4334. * This function is like `composeArgs` except that the arguments composition
  4335. * is tailored for `_.partialRight`.
  4336. *
  4337. * @private
  4338. * @param {Array} args The provided arguments.
  4339. * @param {Array} partials The arguments to append to those provided.
  4340. * @param {Array} holders The `partials` placeholder indexes.
  4341. * @params {boolean} [isCurried] Specify composing for a curried function.
  4342. * @returns {Array} Returns the new array of composed arguments.
  4343. */
  4344. function composeArgsRight(args, partials, holders, isCurried) {
  4345. var argsIndex = -1,
  4346. argsLength = args.length,
  4347. holdersIndex = -1,
  4348. holdersLength = holders.length,
  4349. rightIndex = -1,
  4350. rightLength = partials.length,
  4351. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4352. result = Array(rangeLength + rightLength),
  4353. isUncurried = !isCurried;
  4354. while (++argsIndex < rangeLength) {
  4355. result[argsIndex] = args[argsIndex];
  4356. }
  4357. var offset = argsIndex;
  4358. while (++rightIndex < rightLength) {
  4359. result[offset + rightIndex] = partials[rightIndex];
  4360. }
  4361. while (++holdersIndex < holdersLength) {
  4362. if (isUncurried || argsIndex < argsLength) {
  4363. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4364. }
  4365. }
  4366. return result;
  4367. }
  4368. /**
  4369. * Copies the values of `source` to `array`.
  4370. *
  4371. * @private
  4372. * @param {Array} source The array to copy values from.
  4373. * @param {Array} [array=[]] The array to copy values to.
  4374. * @returns {Array} Returns `array`.
  4375. */
  4376. function copyArray(source, array) {
  4377. var index = -1,
  4378. length = source.length;
  4379. array || (array = Array(length));
  4380. while (++index < length) {
  4381. array[index] = source[index];
  4382. }
  4383. return array;
  4384. }
  4385. /**
  4386. * Copies properties of `source` to `object`.
  4387. *
  4388. * @private
  4389. * @param {Object} source The object to copy properties from.
  4390. * @param {Array} props The property identifiers to copy.
  4391. * @param {Object} [object={}] The object to copy properties to.
  4392. * @param {Function} [customizer] The function to customize copied values.
  4393. * @returns {Object} Returns `object`.
  4394. */
  4395. function copyObject(source, props, object, customizer) {
  4396. var isNew = !object;
  4397. object || (object = {});
  4398. var index = -1,
  4399. length = props.length;
  4400. while (++index < length) {
  4401. var key = props[index];
  4402. var newValue = customizer
  4403. ? customizer(object[key], source[key], key, object, source)
  4404. : undefined;
  4405. if (newValue === undefined) {
  4406. newValue = source[key];
  4407. }
  4408. if (isNew) {
  4409. baseAssignValue(object, key, newValue);
  4410. } else {
  4411. assignValue(object, key, newValue);
  4412. }
  4413. }
  4414. return object;
  4415. }
  4416. /**
  4417. * Copies own symbols of `source` to `object`.
  4418. *
  4419. * @private
  4420. * @param {Object} source The object to copy symbols from.
  4421. * @param {Object} [object={}] The object to copy symbols to.
  4422. * @returns {Object} Returns `object`.
  4423. */
  4424. function copySymbols(source, object) {
  4425. return copyObject(source, getSymbols(source), object);
  4426. }
  4427. /**
  4428. * Copies own and inherited symbols of `source` to `object`.
  4429. *
  4430. * @private
  4431. * @param {Object} source The object to copy symbols from.
  4432. * @param {Object} [object={}] The object to copy symbols to.
  4433. * @returns {Object} Returns `object`.
  4434. */
  4435. function copySymbolsIn(source, object) {
  4436. return copyObject(source, getSymbolsIn(source), object);
  4437. }
  4438. /**
  4439. * Creates a function like `_.groupBy`.
  4440. *
  4441. * @private
  4442. * @param {Function} setter The function to set accumulator values.
  4443. * @param {Function} [initializer] The accumulator object initializer.
  4444. * @returns {Function} Returns the new aggregator function.
  4445. */
  4446. function createAggregator(setter, initializer) {
  4447. return function(collection, iteratee) {
  4448. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4449. accumulator = initializer ? initializer() : {};
  4450. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4451. };
  4452. }
  4453. /**
  4454. * Creates a function like `_.assign`.
  4455. *
  4456. * @private
  4457. * @param {Function} assigner The function to assign values.
  4458. * @returns {Function} Returns the new assigner function.
  4459. */
  4460. function createAssigner(assigner) {
  4461. return baseRest(function(object, sources) {
  4462. var index = -1,
  4463. length = sources.length,
  4464. customizer = length > 1 ? sources[length - 1] : undefined,
  4465. guard = length > 2 ? sources[2] : undefined;
  4466. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4467. ? (length--, customizer)
  4468. : undefined;
  4469. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4470. customizer = length < 3 ? undefined : customizer;
  4471. length = 1;
  4472. }
  4473. object = Object(object);
  4474. while (++index < length) {
  4475. var source = sources[index];
  4476. if (source) {
  4477. assigner(object, source, index, customizer);
  4478. }
  4479. }
  4480. return object;
  4481. });
  4482. }
  4483. /**
  4484. * Creates a `baseEach` or `baseEachRight` function.
  4485. *
  4486. * @private
  4487. * @param {Function} eachFunc The function to iterate over a collection.
  4488. * @param {boolean} [fromRight] Specify iterating from right to left.
  4489. * @returns {Function} Returns the new base function.
  4490. */
  4491. function createBaseEach(eachFunc, fromRight) {
  4492. return function(collection, iteratee) {
  4493. if (collection == null) {
  4494. return collection;
  4495. }
  4496. if (!isArrayLike(collection)) {
  4497. return eachFunc(collection, iteratee);
  4498. }
  4499. var length = collection.length,
  4500. index = fromRight ? length : -1,
  4501. iterable = Object(collection);
  4502. while ((fromRight ? index-- : ++index < length)) {
  4503. if (iteratee(iterable[index], index, iterable) === false) {
  4504. break;
  4505. }
  4506. }
  4507. return collection;
  4508. };
  4509. }
  4510. /**
  4511. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4512. *
  4513. * @private
  4514. * @param {boolean} [fromRight] Specify iterating from right to left.
  4515. * @returns {Function} Returns the new base function.
  4516. */
  4517. function createBaseFor(fromRight) {
  4518. return function(object, iteratee, keysFunc) {
  4519. var index = -1,
  4520. iterable = Object(object),
  4521. props = keysFunc(object),
  4522. length = props.length;
  4523. while (length--) {
  4524. var key = props[fromRight ? length : ++index];
  4525. if (iteratee(iterable[key], key, iterable) === false) {
  4526. break;
  4527. }
  4528. }
  4529. return object;
  4530. };
  4531. }
  4532. /**
  4533. * Creates a function that wraps `func` to invoke it with the optional `this`
  4534. * binding of `thisArg`.
  4535. *
  4536. * @private
  4537. * @param {Function} func The function to wrap.
  4538. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4539. * @param {*} [thisArg] The `this` binding of `func`.
  4540. * @returns {Function} Returns the new wrapped function.
  4541. */
  4542. function createBind(func, bitmask, thisArg) {
  4543. var isBind = bitmask & WRAP_BIND_FLAG,
  4544. Ctor = createCtor(func);
  4545. function wrapper() {
  4546. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4547. return fn.apply(isBind ? thisArg : this, arguments);
  4548. }
  4549. return wrapper;
  4550. }
  4551. /**
  4552. * Creates a function like `_.lowerFirst`.
  4553. *
  4554. * @private
  4555. * @param {string} methodName The name of the `String` case method to use.
  4556. * @returns {Function} Returns the new case function.
  4557. */
  4558. function createCaseFirst(methodName) {
  4559. return function(string) {
  4560. string = toString(string);
  4561. var strSymbols = hasUnicode(string)
  4562. ? stringToArray(string)
  4563. : undefined;
  4564. var chr = strSymbols
  4565. ? strSymbols[0]
  4566. : string.charAt(0);
  4567. var trailing = strSymbols
  4568. ? castSlice(strSymbols, 1).join('')
  4569. : string.slice(1);
  4570. return chr[methodName]() + trailing;
  4571. };
  4572. }
  4573. /**
  4574. * Creates a function like `_.camelCase`.
  4575. *
  4576. * @private
  4577. * @param {Function} callback The function to combine each word.
  4578. * @returns {Function} Returns the new compounder function.
  4579. */
  4580. function createCompounder(callback) {
  4581. return function(string) {
  4582. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4583. };
  4584. }
  4585. /**
  4586. * Creates a function that produces an instance of `Ctor` regardless of
  4587. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4588. *
  4589. * @private
  4590. * @param {Function} Ctor The constructor to wrap.
  4591. * @returns {Function} Returns the new wrapped function.
  4592. */
  4593. function createCtor(Ctor) {
  4594. return function() {
  4595. // Use a `switch` statement to work with class constructors. See
  4596. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4597. // for more details.
  4598. var args = arguments;
  4599. switch (args.length) {
  4600. case 0: return new Ctor;
  4601. case 1: return new Ctor(args[0]);
  4602. case 2: return new Ctor(args[0], args[1]);
  4603. case 3: return new Ctor(args[0], args[1], args[2]);
  4604. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4605. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4606. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4607. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4608. }
  4609. var thisBinding = baseCreate(Ctor.prototype),
  4610. result = Ctor.apply(thisBinding, args);
  4611. // Mimic the constructor's `return` behavior.
  4612. // See https://es5.github.io/#x13.2.2 for more details.
  4613. return isObject(result) ? result : thisBinding;
  4614. };
  4615. }
  4616. /**
  4617. * Creates a function that wraps `func` to enable currying.
  4618. *
  4619. * @private
  4620. * @param {Function} func The function to wrap.
  4621. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4622. * @param {number} arity The arity of `func`.
  4623. * @returns {Function} Returns the new wrapped function.
  4624. */
  4625. function createCurry(func, bitmask, arity) {
  4626. var Ctor = createCtor(func);
  4627. function wrapper() {
  4628. var length = arguments.length,
  4629. args = Array(length),
  4630. index = length,
  4631. placeholder = getHolder(wrapper);
  4632. while (index--) {
  4633. args[index] = arguments[index];
  4634. }
  4635. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4636. ? []
  4637. : replaceHolders(args, placeholder);
  4638. length -= holders.length;
  4639. if (length < arity) {
  4640. return createRecurry(
  4641. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4642. args, holders, undefined, undefined, arity - length);
  4643. }
  4644. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4645. return apply(fn, this, args);
  4646. }
  4647. return wrapper;
  4648. }
  4649. /**
  4650. * Creates a `_.find` or `_.findLast` function.
  4651. *
  4652. * @private
  4653. * @param {Function} findIndexFunc The function to find the collection index.
  4654. * @returns {Function} Returns the new find function.
  4655. */
  4656. function createFind(findIndexFunc) {
  4657. return function(collection, predicate, fromIndex) {
  4658. var iterable = Object(collection);
  4659. if (!isArrayLike(collection)) {
  4660. var iteratee = getIteratee(predicate, 3);
  4661. collection = keys(collection);
  4662. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4663. }
  4664. var index = findIndexFunc(collection, predicate, fromIndex);
  4665. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4666. };
  4667. }
  4668. /**
  4669. * Creates a `_.flow` or `_.flowRight` function.
  4670. *
  4671. * @private
  4672. * @param {boolean} [fromRight] Specify iterating from right to left.
  4673. * @returns {Function} Returns the new flow function.
  4674. */
  4675. function createFlow(fromRight) {
  4676. return flatRest(function(funcs) {
  4677. var length = funcs.length,
  4678. index = length,
  4679. prereq = LodashWrapper.prototype.thru;
  4680. if (fromRight) {
  4681. funcs.reverse();
  4682. }
  4683. while (index--) {
  4684. var func = funcs[index];
  4685. if (typeof func != 'function') {
  4686. throw new TypeError(FUNC_ERROR_TEXT);
  4687. }
  4688. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4689. var wrapper = new LodashWrapper([], true);
  4690. }
  4691. }
  4692. index = wrapper ? index : length;
  4693. while (++index < length) {
  4694. func = funcs[index];
  4695. var funcName = getFuncName(func),
  4696. data = funcName == 'wrapper' ? getData(func) : undefined;
  4697. if (data && isLaziable(data[0]) &&
  4698. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4699. !data[4].length && data[9] == 1
  4700. ) {
  4701. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4702. } else {
  4703. wrapper = (func.length == 1 && isLaziable(func))
  4704. ? wrapper[funcName]()
  4705. : wrapper.thru(func);
  4706. }
  4707. }
  4708. return function() {
  4709. var args = arguments,
  4710. value = args[0];
  4711. if (wrapper && args.length == 1 && isArray(value)) {
  4712. return wrapper.plant(value).value();
  4713. }
  4714. var index = 0,
  4715. result = length ? funcs[index].apply(this, args) : value;
  4716. while (++index < length) {
  4717. result = funcs[index].call(this, result);
  4718. }
  4719. return result;
  4720. };
  4721. });
  4722. }
  4723. /**
  4724. * Creates a function that wraps `func` to invoke it with optional `this`
  4725. * binding of `thisArg`, partial application, and currying.
  4726. *
  4727. * @private
  4728. * @param {Function|string} func The function or method name to wrap.
  4729. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4730. * @param {*} [thisArg] The `this` binding of `func`.
  4731. * @param {Array} [partials] The arguments to prepend to those provided to
  4732. * the new function.
  4733. * @param {Array} [holders] The `partials` placeholder indexes.
  4734. * @param {Array} [partialsRight] The arguments to append to those provided
  4735. * to the new function.
  4736. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4737. * @param {Array} [argPos] The argument positions of the new function.
  4738. * @param {number} [ary] The arity cap of `func`.
  4739. * @param {number} [arity] The arity of `func`.
  4740. * @returns {Function} Returns the new wrapped function.
  4741. */
  4742. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4743. var isAry = bitmask & WRAP_ARY_FLAG,
  4744. isBind = bitmask & WRAP_BIND_FLAG,
  4745. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4746. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4747. isFlip = bitmask & WRAP_FLIP_FLAG,
  4748. Ctor = isBindKey ? undefined : createCtor(func);
  4749. function wrapper() {
  4750. var length = arguments.length,
  4751. args = Array(length),
  4752. index = length;
  4753. while (index--) {
  4754. args[index] = arguments[index];
  4755. }
  4756. if (isCurried) {
  4757. var placeholder = getHolder(wrapper),
  4758. holdersCount = countHolders(args, placeholder);
  4759. }
  4760. if (partials) {
  4761. args = composeArgs(args, partials, holders, isCurried);
  4762. }
  4763. if (partialsRight) {
  4764. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4765. }
  4766. length -= holdersCount;
  4767. if (isCurried && length < arity) {
  4768. var newHolders = replaceHolders(args, placeholder);
  4769. return createRecurry(
  4770. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4771. args, newHolders, argPos, ary, arity - length
  4772. );
  4773. }
  4774. var thisBinding = isBind ? thisArg : this,
  4775. fn = isBindKey ? thisBinding[func] : func;
  4776. length = args.length;
  4777. if (argPos) {
  4778. args = reorder(args, argPos);
  4779. } else if (isFlip && length > 1) {
  4780. args.reverse();
  4781. }
  4782. if (isAry && ary < length) {
  4783. args.length = ary;
  4784. }
  4785. if (this && this !== root && this instanceof wrapper) {
  4786. fn = Ctor || createCtor(fn);
  4787. }
  4788. return fn.apply(thisBinding, args);
  4789. }
  4790. return wrapper;
  4791. }
  4792. /**
  4793. * Creates a function like `_.invertBy`.
  4794. *
  4795. * @private
  4796. * @param {Function} setter The function to set accumulator values.
  4797. * @param {Function} toIteratee The function to resolve iteratees.
  4798. * @returns {Function} Returns the new inverter function.
  4799. */
  4800. function createInverter(setter, toIteratee) {
  4801. return function(object, iteratee) {
  4802. return baseInverter(object, setter, toIteratee(iteratee), {});
  4803. };
  4804. }
  4805. /**
  4806. * Creates a function that performs a mathematical operation on two values.
  4807. *
  4808. * @private
  4809. * @param {Function} operator The function to perform the operation.
  4810. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4811. * @returns {Function} Returns the new mathematical operation function.
  4812. */
  4813. function createMathOperation(operator, defaultValue) {
  4814. return function(value, other) {
  4815. var result;
  4816. if (value === undefined && other === undefined) {
  4817. return defaultValue;
  4818. }
  4819. if (value !== undefined) {
  4820. result = value;
  4821. }
  4822. if (other !== undefined) {
  4823. if (result === undefined) {
  4824. return other;
  4825. }
  4826. if (typeof value == 'string' || typeof other == 'string') {
  4827. value = baseToString(value);
  4828. other = baseToString(other);
  4829. } else {
  4830. value = baseToNumber(value);
  4831. other = baseToNumber(other);
  4832. }
  4833. result = operator(value, other);
  4834. }
  4835. return result;
  4836. };
  4837. }
  4838. /**
  4839. * Creates a function like `_.over`.
  4840. *
  4841. * @private
  4842. * @param {Function} arrayFunc The function to iterate over iteratees.
  4843. * @returns {Function} Returns the new over function.
  4844. */
  4845. function createOver(arrayFunc) {
  4846. return flatRest(function(iteratees) {
  4847. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4848. return baseRest(function(args) {
  4849. var thisArg = this;
  4850. return arrayFunc(iteratees, function(iteratee) {
  4851. return apply(iteratee, thisArg, args);
  4852. });
  4853. });
  4854. });
  4855. }
  4856. /**
  4857. * Creates the padding for `string` based on `length`. The `chars` string
  4858. * is truncated if the number of characters exceeds `length`.
  4859. *
  4860. * @private
  4861. * @param {number} length The padding length.
  4862. * @param {string} [chars=' '] The string used as padding.
  4863. * @returns {string} Returns the padding for `string`.
  4864. */
  4865. function createPadding(length, chars) {
  4866. chars = chars === undefined ? ' ' : baseToString(chars);
  4867. var charsLength = chars.length;
  4868. if (charsLength < 2) {
  4869. return charsLength ? baseRepeat(chars, length) : chars;
  4870. }
  4871. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4872. return hasUnicode(chars)
  4873. ? castSlice(stringToArray(result), 0, length).join('')
  4874. : result.slice(0, length);
  4875. }
  4876. /**
  4877. * Creates a function that wraps `func` to invoke it with the `this` binding
  4878. * of `thisArg` and `partials` prepended to the arguments it receives.
  4879. *
  4880. * @private
  4881. * @param {Function} func The function to wrap.
  4882. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4883. * @param {*} thisArg The `this` binding of `func`.
  4884. * @param {Array} partials The arguments to prepend to those provided to
  4885. * the new function.
  4886. * @returns {Function} Returns the new wrapped function.
  4887. */
  4888. function createPartial(func, bitmask, thisArg, partials) {
  4889. var isBind = bitmask & WRAP_BIND_FLAG,
  4890. Ctor = createCtor(func);
  4891. function wrapper() {
  4892. var argsIndex = -1,
  4893. argsLength = arguments.length,
  4894. leftIndex = -1,
  4895. leftLength = partials.length,
  4896. args = Array(leftLength + argsLength),
  4897. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4898. while (++leftIndex < leftLength) {
  4899. args[leftIndex] = partials[leftIndex];
  4900. }
  4901. while (argsLength--) {
  4902. args[leftIndex++] = arguments[++argsIndex];
  4903. }
  4904. return apply(fn, isBind ? thisArg : this, args);
  4905. }
  4906. return wrapper;
  4907. }
  4908. /**
  4909. * Creates a `_.range` or `_.rangeRight` function.
  4910. *
  4911. * @private
  4912. * @param {boolean} [fromRight] Specify iterating from right to left.
  4913. * @returns {Function} Returns the new range function.
  4914. */
  4915. function createRange(fromRight) {
  4916. return function(start, end, step) {
  4917. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4918. end = step = undefined;
  4919. }
  4920. // Ensure the sign of `-0` is preserved.
  4921. start = toFinite(start);
  4922. if (end === undefined) {
  4923. end = start;
  4924. start = 0;
  4925. } else {
  4926. end = toFinite(end);
  4927. }
  4928. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4929. return baseRange(start, end, step, fromRight);
  4930. };
  4931. }
  4932. /**
  4933. * Creates a function that performs a relational operation on two values.
  4934. *
  4935. * @private
  4936. * @param {Function} operator The function to perform the operation.
  4937. * @returns {Function} Returns the new relational operation function.
  4938. */
  4939. function createRelationalOperation(operator) {
  4940. return function(value, other) {
  4941. if (!(typeof value == 'string' && typeof other == 'string')) {
  4942. value = toNumber(value);
  4943. other = toNumber(other);
  4944. }
  4945. return operator(value, other);
  4946. };
  4947. }
  4948. /**
  4949. * Creates a function that wraps `func` to continue currying.
  4950. *
  4951. * @private
  4952. * @param {Function} func The function to wrap.
  4953. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4954. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4955. * @param {*} placeholder The placeholder value.
  4956. * @param {*} [thisArg] The `this` binding of `func`.
  4957. * @param {Array} [partials] The arguments to prepend to those provided to
  4958. * the new function.
  4959. * @param {Array} [holders] The `partials` placeholder indexes.
  4960. * @param {Array} [argPos] The argument positions of the new function.
  4961. * @param {number} [ary] The arity cap of `func`.
  4962. * @param {number} [arity] The arity of `func`.
  4963. * @returns {Function} Returns the new wrapped function.
  4964. */
  4965. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4966. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4967. newHolders = isCurry ? holders : undefined,
  4968. newHoldersRight = isCurry ? undefined : holders,
  4969. newPartials = isCurry ? partials : undefined,
  4970. newPartialsRight = isCurry ? undefined : partials;
  4971. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4972. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4973. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4974. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4975. }
  4976. var newData = [
  4977. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4978. newHoldersRight, argPos, ary, arity
  4979. ];
  4980. var result = wrapFunc.apply(undefined, newData);
  4981. if (isLaziable(func)) {
  4982. setData(result, newData);
  4983. }
  4984. result.placeholder = placeholder;
  4985. return setWrapToString(result, func, bitmask);
  4986. }
  4987. /**
  4988. * Creates a function like `_.round`.
  4989. *
  4990. * @private
  4991. * @param {string} methodName The name of the `Math` method to use when rounding.
  4992. * @returns {Function} Returns the new round function.
  4993. */
  4994. function createRound(methodName) {
  4995. var func = Math[methodName];
  4996. return function(number, precision) {
  4997. number = toNumber(number);
  4998. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  4999. if (precision && nativeIsFinite(number)) {
  5000. // Shift with exponential notation to avoid floating-point issues.
  5001. // See [MDN](https://mdn.io/round#Examples) for more details.
  5002. var pair = (toString(number) + 'e').split('e'),
  5003. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5004. pair = (toString(value) + 'e').split('e');
  5005. return +(pair[0] + 'e' + (+pair[1] - precision));
  5006. }
  5007. return func(number);
  5008. };
  5009. }
  5010. /**
  5011. * Creates a set object of `values`.
  5012. *
  5013. * @private
  5014. * @param {Array} values The values to add to the set.
  5015. * @returns {Object} Returns the new set.
  5016. */
  5017. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5018. return new Set(values);
  5019. };
  5020. /**
  5021. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5022. *
  5023. * @private
  5024. * @param {Function} keysFunc The function to get the keys of a given object.
  5025. * @returns {Function} Returns the new pairs function.
  5026. */
  5027. function createToPairs(keysFunc) {
  5028. return function(object) {
  5029. var tag = getTag(object);
  5030. if (tag == mapTag) {
  5031. return mapToArray(object);
  5032. }
  5033. if (tag == setTag) {
  5034. return setToPairs(object);
  5035. }
  5036. return baseToPairs(object, keysFunc(object));
  5037. };
  5038. }
  5039. /**
  5040. * Creates a function that either curries or invokes `func` with optional
  5041. * `this` binding and partially applied arguments.
  5042. *
  5043. * @private
  5044. * @param {Function|string} func The function or method name to wrap.
  5045. * @param {number} bitmask The bitmask flags.
  5046. * 1 - `_.bind`
  5047. * 2 - `_.bindKey`
  5048. * 4 - `_.curry` or `_.curryRight` of a bound function
  5049. * 8 - `_.curry`
  5050. * 16 - `_.curryRight`
  5051. * 32 - `_.partial`
  5052. * 64 - `_.partialRight`
  5053. * 128 - `_.rearg`
  5054. * 256 - `_.ary`
  5055. * 512 - `_.flip`
  5056. * @param {*} [thisArg] The `this` binding of `func`.
  5057. * @param {Array} [partials] The arguments to be partially applied.
  5058. * @param {Array} [holders] The `partials` placeholder indexes.
  5059. * @param {Array} [argPos] The argument positions of the new function.
  5060. * @param {number} [ary] The arity cap of `func`.
  5061. * @param {number} [arity] The arity of `func`.
  5062. * @returns {Function} Returns the new wrapped function.
  5063. */
  5064. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5065. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5066. if (!isBindKey && typeof func != 'function') {
  5067. throw new TypeError(FUNC_ERROR_TEXT);
  5068. }
  5069. var length = partials ? partials.length : 0;
  5070. if (!length) {
  5071. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5072. partials = holders = undefined;
  5073. }
  5074. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5075. arity = arity === undefined ? arity : toInteger(arity);
  5076. length -= holders ? holders.length : 0;
  5077. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5078. var partialsRight = partials,
  5079. holdersRight = holders;
  5080. partials = holders = undefined;
  5081. }
  5082. var data = isBindKey ? undefined : getData(func);
  5083. var newData = [
  5084. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5085. argPos, ary, arity
  5086. ];
  5087. if (data) {
  5088. mergeData(newData, data);
  5089. }
  5090. func = newData[0];
  5091. bitmask = newData[1];
  5092. thisArg = newData[2];
  5093. partials = newData[3];
  5094. holders = newData[4];
  5095. arity = newData[9] = newData[9] === undefined
  5096. ? (isBindKey ? 0 : func.length)
  5097. : nativeMax(newData[9] - length, 0);
  5098. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5099. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5100. }
  5101. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5102. var result = createBind(func, bitmask, thisArg);
  5103. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5104. result = createCurry(func, bitmask, arity);
  5105. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5106. result = createPartial(func, bitmask, thisArg, partials);
  5107. } else {
  5108. result = createHybrid.apply(undefined, newData);
  5109. }
  5110. var setter = data ? baseSetData : setData;
  5111. return setWrapToString(setter(result, newData), func, bitmask);
  5112. }
  5113. /**
  5114. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5115. * of source objects to the destination object for all destination properties
  5116. * that resolve to `undefined`.
  5117. *
  5118. * @private
  5119. * @param {*} objValue The destination value.
  5120. * @param {*} srcValue The source value.
  5121. * @param {string} key The key of the property to assign.
  5122. * @param {Object} object The parent object of `objValue`.
  5123. * @returns {*} Returns the value to assign.
  5124. */
  5125. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5126. if (objValue === undefined ||
  5127. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5128. return srcValue;
  5129. }
  5130. return objValue;
  5131. }
  5132. /**
  5133. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5134. * objects into destination objects that are passed thru.
  5135. *
  5136. * @private
  5137. * @param {*} objValue The destination value.
  5138. * @param {*} srcValue The source value.
  5139. * @param {string} key The key of the property to merge.
  5140. * @param {Object} object The parent object of `objValue`.
  5141. * @param {Object} source The parent object of `srcValue`.
  5142. * @param {Object} [stack] Tracks traversed source values and their merged
  5143. * counterparts.
  5144. * @returns {*} Returns the value to assign.
  5145. */
  5146. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5147. if (isObject(objValue) && isObject(srcValue)) {
  5148. // Recursively merge objects and arrays (susceptible to call stack limits).
  5149. stack.set(srcValue, objValue);
  5150. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5151. stack['delete'](srcValue);
  5152. }
  5153. return objValue;
  5154. }
  5155. /**
  5156. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5157. * objects.
  5158. *
  5159. * @private
  5160. * @param {*} value The value to inspect.
  5161. * @param {string} key The key of the property to inspect.
  5162. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5163. */
  5164. function customOmitClone(value) {
  5165. return isPlainObject(value) ? undefined : value;
  5166. }
  5167. /**
  5168. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5169. * partial deep comparisons.
  5170. *
  5171. * @private
  5172. * @param {Array} array The array to compare.
  5173. * @param {Array} other The other array to compare.
  5174. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5175. * @param {Function} customizer The function to customize comparisons.
  5176. * @param {Function} equalFunc The function to determine equivalents of values.
  5177. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5178. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5179. */
  5180. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5181. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5182. arrLength = array.length,
  5183. othLength = other.length;
  5184. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5185. return false;
  5186. }
  5187. // Check that cyclic values are equal.
  5188. var arrStacked = stack.get(array);
  5189. var othStacked = stack.get(other);
  5190. if (arrStacked && othStacked) {
  5191. return arrStacked == other && othStacked == array;
  5192. }
  5193. var index = -1,
  5194. result = true,
  5195. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5196. stack.set(array, other);
  5197. stack.set(other, array);
  5198. // Ignore non-index properties.
  5199. while (++index < arrLength) {
  5200. var arrValue = array[index],
  5201. othValue = other[index];
  5202. if (customizer) {
  5203. var compared = isPartial
  5204. ? customizer(othValue, arrValue, index, other, array, stack)
  5205. : customizer(arrValue, othValue, index, array, other, stack);
  5206. }
  5207. if (compared !== undefined) {
  5208. if (compared) {
  5209. continue;
  5210. }
  5211. result = false;
  5212. break;
  5213. }
  5214. // Recursively compare arrays (susceptible to call stack limits).
  5215. if (seen) {
  5216. if (!arraySome(other, function(othValue, othIndex) {
  5217. if (!cacheHas(seen, othIndex) &&
  5218. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5219. return seen.push(othIndex);
  5220. }
  5221. })) {
  5222. result = false;
  5223. break;
  5224. }
  5225. } else if (!(
  5226. arrValue === othValue ||
  5227. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5228. )) {
  5229. result = false;
  5230. break;
  5231. }
  5232. }
  5233. stack['delete'](array);
  5234. stack['delete'](other);
  5235. return result;
  5236. }
  5237. /**
  5238. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5239. * the same `toStringTag`.
  5240. *
  5241. * **Note:** This function only supports comparing values with tags of
  5242. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5243. *
  5244. * @private
  5245. * @param {Object} object The object to compare.
  5246. * @param {Object} other The other object to compare.
  5247. * @param {string} tag The `toStringTag` of the objects to compare.
  5248. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5249. * @param {Function} customizer The function to customize comparisons.
  5250. * @param {Function} equalFunc The function to determine equivalents of values.
  5251. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5252. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5253. */
  5254. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5255. switch (tag) {
  5256. case dataViewTag:
  5257. if ((object.byteLength != other.byteLength) ||
  5258. (object.byteOffset != other.byteOffset)) {
  5259. return false;
  5260. }
  5261. object = object.buffer;
  5262. other = other.buffer;
  5263. case arrayBufferTag:
  5264. if ((object.byteLength != other.byteLength) ||
  5265. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5266. return false;
  5267. }
  5268. return true;
  5269. case boolTag:
  5270. case dateTag:
  5271. case numberTag:
  5272. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5273. // Invalid dates are coerced to `NaN`.
  5274. return eq(+object, +other);
  5275. case errorTag:
  5276. return object.name == other.name && object.message == other.message;
  5277. case regexpTag:
  5278. case stringTag:
  5279. // Coerce regexes to strings and treat strings, primitives and objects,
  5280. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5281. // for more details.
  5282. return object == (other + '');
  5283. case mapTag:
  5284. var convert = mapToArray;
  5285. case setTag:
  5286. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5287. convert || (convert = setToArray);
  5288. if (object.size != other.size && !isPartial) {
  5289. return false;
  5290. }
  5291. // Assume cyclic values are equal.
  5292. var stacked = stack.get(object);
  5293. if (stacked) {
  5294. return stacked == other;
  5295. }
  5296. bitmask |= COMPARE_UNORDERED_FLAG;
  5297. // Recursively compare objects (susceptible to call stack limits).
  5298. stack.set(object, other);
  5299. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5300. stack['delete'](object);
  5301. return result;
  5302. case symbolTag:
  5303. if (symbolValueOf) {
  5304. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5305. }
  5306. }
  5307. return false;
  5308. }
  5309. /**
  5310. * A specialized version of `baseIsEqualDeep` for objects with support for
  5311. * partial deep comparisons.
  5312. *
  5313. * @private
  5314. * @param {Object} object The object to compare.
  5315. * @param {Object} other The other object to compare.
  5316. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5317. * @param {Function} customizer The function to customize comparisons.
  5318. * @param {Function} equalFunc The function to determine equivalents of values.
  5319. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5320. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5321. */
  5322. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5323. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5324. objProps = getAllKeys(object),
  5325. objLength = objProps.length,
  5326. othProps = getAllKeys(other),
  5327. othLength = othProps.length;
  5328. if (objLength != othLength && !isPartial) {
  5329. return false;
  5330. }
  5331. var index = objLength;
  5332. while (index--) {
  5333. var key = objProps[index];
  5334. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5335. return false;
  5336. }
  5337. }
  5338. // Check that cyclic values are equal.
  5339. var objStacked = stack.get(object);
  5340. var othStacked = stack.get(other);
  5341. if (objStacked && othStacked) {
  5342. return objStacked == other && othStacked == object;
  5343. }
  5344. var result = true;
  5345. stack.set(object, other);
  5346. stack.set(other, object);
  5347. var skipCtor = isPartial;
  5348. while (++index < objLength) {
  5349. key = objProps[index];
  5350. var objValue = object[key],
  5351. othValue = other[key];
  5352. if (customizer) {
  5353. var compared = isPartial
  5354. ? customizer(othValue, objValue, key, other, object, stack)
  5355. : customizer(objValue, othValue, key, object, other, stack);
  5356. }
  5357. // Recursively compare objects (susceptible to call stack limits).
  5358. if (!(compared === undefined
  5359. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5360. : compared
  5361. )) {
  5362. result = false;
  5363. break;
  5364. }
  5365. skipCtor || (skipCtor = key == 'constructor');
  5366. }
  5367. if (result && !skipCtor) {
  5368. var objCtor = object.constructor,
  5369. othCtor = other.constructor;
  5370. // Non `Object` object instances with different constructors are not equal.
  5371. if (objCtor != othCtor &&
  5372. ('constructor' in object && 'constructor' in other) &&
  5373. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5374. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5375. result = false;
  5376. }
  5377. }
  5378. stack['delete'](object);
  5379. stack['delete'](other);
  5380. return result;
  5381. }
  5382. /**
  5383. * A specialized version of `baseRest` which flattens the rest array.
  5384. *
  5385. * @private
  5386. * @param {Function} func The function to apply a rest parameter to.
  5387. * @returns {Function} Returns the new function.
  5388. */
  5389. function flatRest(func) {
  5390. return setToString(overRest(func, undefined, flatten), func + '');
  5391. }
  5392. /**
  5393. * Creates an array of own enumerable property names and symbols of `object`.
  5394. *
  5395. * @private
  5396. * @param {Object} object The object to query.
  5397. * @returns {Array} Returns the array of property names and symbols.
  5398. */
  5399. function getAllKeys(object) {
  5400. return baseGetAllKeys(object, keys, getSymbols);
  5401. }
  5402. /**
  5403. * Creates an array of own and inherited enumerable property names and
  5404. * symbols of `object`.
  5405. *
  5406. * @private
  5407. * @param {Object} object The object to query.
  5408. * @returns {Array} Returns the array of property names and symbols.
  5409. */
  5410. function getAllKeysIn(object) {
  5411. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5412. }
  5413. /**
  5414. * Gets metadata for `func`.
  5415. *
  5416. * @private
  5417. * @param {Function} func The function to query.
  5418. * @returns {*} Returns the metadata for `func`.
  5419. */
  5420. var getData = !metaMap ? noop : function(func) {
  5421. return metaMap.get(func);
  5422. };
  5423. /**
  5424. * Gets the name of `func`.
  5425. *
  5426. * @private
  5427. * @param {Function} func The function to query.
  5428. * @returns {string} Returns the function name.
  5429. */
  5430. function getFuncName(func) {
  5431. var result = (func.name + ''),
  5432. array = realNames[result],
  5433. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5434. while (length--) {
  5435. var data = array[length],
  5436. otherFunc = data.func;
  5437. if (otherFunc == null || otherFunc == func) {
  5438. return data.name;
  5439. }
  5440. }
  5441. return result;
  5442. }
  5443. /**
  5444. * Gets the argument placeholder value for `func`.
  5445. *
  5446. * @private
  5447. * @param {Function} func The function to inspect.
  5448. * @returns {*} Returns the placeholder value.
  5449. */
  5450. function getHolder(func) {
  5451. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5452. return object.placeholder;
  5453. }
  5454. /**
  5455. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5456. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5457. * If arguments are provided, the chosen function is invoked with them and
  5458. * its result is returned.
  5459. *
  5460. * @private
  5461. * @param {*} [value] The value to convert to an iteratee.
  5462. * @param {number} [arity] The arity of the created iteratee.
  5463. * @returns {Function} Returns the chosen function or its result.
  5464. */
  5465. function getIteratee() {
  5466. var result = lodash.iteratee || iteratee;
  5467. result = result === iteratee ? baseIteratee : result;
  5468. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5469. }
  5470. /**
  5471. * Gets the data for `map`.
  5472. *
  5473. * @private
  5474. * @param {Object} map The map to query.
  5475. * @param {string} key The reference key.
  5476. * @returns {*} Returns the map data.
  5477. */
  5478. function getMapData(map, key) {
  5479. var data = map.__data__;
  5480. return isKeyable(key)
  5481. ? data[typeof key == 'string' ? 'string' : 'hash']
  5482. : data.map;
  5483. }
  5484. /**
  5485. * Gets the property names, values, and compare flags of `object`.
  5486. *
  5487. * @private
  5488. * @param {Object} object The object to query.
  5489. * @returns {Array} Returns the match data of `object`.
  5490. */
  5491. function getMatchData(object) {
  5492. var result = keys(object),
  5493. length = result.length;
  5494. while (length--) {
  5495. var key = result[length],
  5496. value = object[key];
  5497. result[length] = [key, value, isStrictComparable(value)];
  5498. }
  5499. return result;
  5500. }
  5501. /**
  5502. * Gets the native function at `key` of `object`.
  5503. *
  5504. * @private
  5505. * @param {Object} object The object to query.
  5506. * @param {string} key The key of the method to get.
  5507. * @returns {*} Returns the function if it's native, else `undefined`.
  5508. */
  5509. function getNative(object, key) {
  5510. var value = getValue(object, key);
  5511. return baseIsNative(value) ? value : undefined;
  5512. }
  5513. /**
  5514. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5515. *
  5516. * @private
  5517. * @param {*} value The value to query.
  5518. * @returns {string} Returns the raw `toStringTag`.
  5519. */
  5520. function getRawTag(value) {
  5521. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5522. tag = value[symToStringTag];
  5523. try {
  5524. value[symToStringTag] = undefined;
  5525. var unmasked = true;
  5526. } catch (e) {}
  5527. var result = nativeObjectToString.call(value);
  5528. if (unmasked) {
  5529. if (isOwn) {
  5530. value[symToStringTag] = tag;
  5531. } else {
  5532. delete value[symToStringTag];
  5533. }
  5534. }
  5535. return result;
  5536. }
  5537. /**
  5538. * Creates an array of the own enumerable symbols of `object`.
  5539. *
  5540. * @private
  5541. * @param {Object} object The object to query.
  5542. * @returns {Array} Returns the array of symbols.
  5543. */
  5544. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5545. if (object == null) {
  5546. return [];
  5547. }
  5548. object = Object(object);
  5549. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5550. return propertyIsEnumerable.call(object, symbol);
  5551. });
  5552. };
  5553. /**
  5554. * Creates an array of the own and inherited enumerable symbols of `object`.
  5555. *
  5556. * @private
  5557. * @param {Object} object The object to query.
  5558. * @returns {Array} Returns the array of symbols.
  5559. */
  5560. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5561. var result = [];
  5562. while (object) {
  5563. arrayPush(result, getSymbols(object));
  5564. object = getPrototype(object);
  5565. }
  5566. return result;
  5567. };
  5568. /**
  5569. * Gets the `toStringTag` of `value`.
  5570. *
  5571. * @private
  5572. * @param {*} value The value to query.
  5573. * @returns {string} Returns the `toStringTag`.
  5574. */
  5575. var getTag = baseGetTag;
  5576. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5577. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5578. (Map && getTag(new Map) != mapTag) ||
  5579. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5580. (Set && getTag(new Set) != setTag) ||
  5581. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5582. getTag = function(value) {
  5583. var result = baseGetTag(value),
  5584. Ctor = result == objectTag ? value.constructor : undefined,
  5585. ctorString = Ctor ? toSource(Ctor) : '';
  5586. if (ctorString) {
  5587. switch (ctorString) {
  5588. case dataViewCtorString: return dataViewTag;
  5589. case mapCtorString: return mapTag;
  5590. case promiseCtorString: return promiseTag;
  5591. case setCtorString: return setTag;
  5592. case weakMapCtorString: return weakMapTag;
  5593. }
  5594. }
  5595. return result;
  5596. };
  5597. }
  5598. /**
  5599. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5600. *
  5601. * @private
  5602. * @param {number} start The start of the view.
  5603. * @param {number} end The end of the view.
  5604. * @param {Array} transforms The transformations to apply to the view.
  5605. * @returns {Object} Returns an object containing the `start` and `end`
  5606. * positions of the view.
  5607. */
  5608. function getView(start, end, transforms) {
  5609. var index = -1,
  5610. length = transforms.length;
  5611. while (++index < length) {
  5612. var data = transforms[index],
  5613. size = data.size;
  5614. switch (data.type) {
  5615. case 'drop': start += size; break;
  5616. case 'dropRight': end -= size; break;
  5617. case 'take': end = nativeMin(end, start + size); break;
  5618. case 'takeRight': start = nativeMax(start, end - size); break;
  5619. }
  5620. }
  5621. return { 'start': start, 'end': end };
  5622. }
  5623. /**
  5624. * Extracts wrapper details from the `source` body comment.
  5625. *
  5626. * @private
  5627. * @param {string} source The source to inspect.
  5628. * @returns {Array} Returns the wrapper details.
  5629. */
  5630. function getWrapDetails(source) {
  5631. var match = source.match(reWrapDetails);
  5632. return match ? match[1].split(reSplitDetails) : [];
  5633. }
  5634. /**
  5635. * Checks if `path` exists on `object`.
  5636. *
  5637. * @private
  5638. * @param {Object} object The object to query.
  5639. * @param {Array|string} path The path to check.
  5640. * @param {Function} hasFunc The function to check properties.
  5641. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5642. */
  5643. function hasPath(object, path, hasFunc) {
  5644. path = castPath(path, object);
  5645. var index = -1,
  5646. length = path.length,
  5647. result = false;
  5648. while (++index < length) {
  5649. var key = toKey(path[index]);
  5650. if (!(result = object != null && hasFunc(object, key))) {
  5651. break;
  5652. }
  5653. object = object[key];
  5654. }
  5655. if (result || ++index != length) {
  5656. return result;
  5657. }
  5658. length = object == null ? 0 : object.length;
  5659. return !!length && isLength(length) && isIndex(key, length) &&
  5660. (isArray(object) || isArguments(object));
  5661. }
  5662. /**
  5663. * Initializes an array clone.
  5664. *
  5665. * @private
  5666. * @param {Array} array The array to clone.
  5667. * @returns {Array} Returns the initialized clone.
  5668. */
  5669. function initCloneArray(array) {
  5670. var length = array.length,
  5671. result = new array.constructor(length);
  5672. // Add properties assigned by `RegExp#exec`.
  5673. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5674. result.index = array.index;
  5675. result.input = array.input;
  5676. }
  5677. return result;
  5678. }
  5679. /**
  5680. * Initializes an object clone.
  5681. *
  5682. * @private
  5683. * @param {Object} object The object to clone.
  5684. * @returns {Object} Returns the initialized clone.
  5685. */
  5686. function initCloneObject(object) {
  5687. return (typeof object.constructor == 'function' && !isPrototype(object))
  5688. ? baseCreate(getPrototype(object))
  5689. : {};
  5690. }
  5691. /**
  5692. * Initializes an object clone based on its `toStringTag`.
  5693. *
  5694. * **Note:** This function only supports cloning values with tags of
  5695. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5696. *
  5697. * @private
  5698. * @param {Object} object The object to clone.
  5699. * @param {string} tag The `toStringTag` of the object to clone.
  5700. * @param {boolean} [isDeep] Specify a deep clone.
  5701. * @returns {Object} Returns the initialized clone.
  5702. */
  5703. function initCloneByTag(object, tag, isDeep) {
  5704. var Ctor = object.constructor;
  5705. switch (tag) {
  5706. case arrayBufferTag:
  5707. return cloneArrayBuffer(object);
  5708. case boolTag:
  5709. case dateTag:
  5710. return new Ctor(+object);
  5711. case dataViewTag:
  5712. return cloneDataView(object, isDeep);
  5713. case float32Tag: case float64Tag:
  5714. case int8Tag: case int16Tag: case int32Tag:
  5715. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5716. return cloneTypedArray(object, isDeep);
  5717. case mapTag:
  5718. return new Ctor;
  5719. case numberTag:
  5720. case stringTag:
  5721. return new Ctor(object);
  5722. case regexpTag:
  5723. return cloneRegExp(object);
  5724. case setTag:
  5725. return new Ctor;
  5726. case symbolTag:
  5727. return cloneSymbol(object);
  5728. }
  5729. }
  5730. /**
  5731. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5732. *
  5733. * @private
  5734. * @param {string} source The source to modify.
  5735. * @returns {Array} details The details to insert.
  5736. * @returns {string} Returns the modified source.
  5737. */
  5738. function insertWrapDetails(source, details) {
  5739. var length = details.length;
  5740. if (!length) {
  5741. return source;
  5742. }
  5743. var lastIndex = length - 1;
  5744. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5745. details = details.join(length > 2 ? ', ' : ' ');
  5746. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5747. }
  5748. /**
  5749. * Checks if `value` is a flattenable `arguments` object or array.
  5750. *
  5751. * @private
  5752. * @param {*} value The value to check.
  5753. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5754. */
  5755. function isFlattenable(value) {
  5756. return isArray(value) || isArguments(value) ||
  5757. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5758. }
  5759. /**
  5760. * Checks if `value` is a valid array-like index.
  5761. *
  5762. * @private
  5763. * @param {*} value The value to check.
  5764. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5765. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5766. */
  5767. function isIndex(value, length) {
  5768. var type = typeof value;
  5769. length = length == null ? MAX_SAFE_INTEGER : length;
  5770. return !!length &&
  5771. (type == 'number' ||
  5772. (type != 'symbol' && reIsUint.test(value))) &&
  5773. (value > -1 && value % 1 == 0 && value < length);
  5774. }
  5775. /**
  5776. * Checks if the given arguments are from an iteratee call.
  5777. *
  5778. * @private
  5779. * @param {*} value The potential iteratee value argument.
  5780. * @param {*} index The potential iteratee index or key argument.
  5781. * @param {*} object The potential iteratee object argument.
  5782. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5783. * else `false`.
  5784. */
  5785. function isIterateeCall(value, index, object) {
  5786. if (!isObject(object)) {
  5787. return false;
  5788. }
  5789. var type = typeof index;
  5790. if (type == 'number'
  5791. ? (isArrayLike(object) && isIndex(index, object.length))
  5792. : (type == 'string' && index in object)
  5793. ) {
  5794. return eq(object[index], value);
  5795. }
  5796. return false;
  5797. }
  5798. /**
  5799. * Checks if `value` is a property name and not a property path.
  5800. *
  5801. * @private
  5802. * @param {*} value The value to check.
  5803. * @param {Object} [object] The object to query keys on.
  5804. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5805. */
  5806. function isKey(value, object) {
  5807. if (isArray(value)) {
  5808. return false;
  5809. }
  5810. var type = typeof value;
  5811. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5812. value == null || isSymbol(value)) {
  5813. return true;
  5814. }
  5815. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5816. (object != null && value in Object(object));
  5817. }
  5818. /**
  5819. * Checks if `value` is suitable for use as unique object key.
  5820. *
  5821. * @private
  5822. * @param {*} value The value to check.
  5823. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5824. */
  5825. function isKeyable(value) {
  5826. var type = typeof value;
  5827. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5828. ? (value !== '__proto__')
  5829. : (value === null);
  5830. }
  5831. /**
  5832. * Checks if `func` has a lazy counterpart.
  5833. *
  5834. * @private
  5835. * @param {Function} func The function to check.
  5836. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5837. * else `false`.
  5838. */
  5839. function isLaziable(func) {
  5840. var funcName = getFuncName(func),
  5841. other = lodash[funcName];
  5842. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5843. return false;
  5844. }
  5845. if (func === other) {
  5846. return true;
  5847. }
  5848. var data = getData(other);
  5849. return !!data && func === data[0];
  5850. }
  5851. /**
  5852. * Checks if `func` has its source masked.
  5853. *
  5854. * @private
  5855. * @param {Function} func The function to check.
  5856. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5857. */
  5858. function isMasked(func) {
  5859. return !!maskSrcKey && (maskSrcKey in func);
  5860. }
  5861. /**
  5862. * Checks if `func` is capable of being masked.
  5863. *
  5864. * @private
  5865. * @param {*} value The value to check.
  5866. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5867. */
  5868. var isMaskable = coreJsData ? isFunction : stubFalse;
  5869. /**
  5870. * Checks if `value` is likely a prototype object.
  5871. *
  5872. * @private
  5873. * @param {*} value The value to check.
  5874. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5875. */
  5876. function isPrototype(value) {
  5877. var Ctor = value && value.constructor,
  5878. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5879. return value === proto;
  5880. }
  5881. /**
  5882. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5883. *
  5884. * @private
  5885. * @param {*} value The value to check.
  5886. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5887. * equality comparisons, else `false`.
  5888. */
  5889. function isStrictComparable(value) {
  5890. return value === value && !isObject(value);
  5891. }
  5892. /**
  5893. * A specialized version of `matchesProperty` for source values suitable
  5894. * for strict equality comparisons, i.e. `===`.
  5895. *
  5896. * @private
  5897. * @param {string} key The key of the property to get.
  5898. * @param {*} srcValue The value to match.
  5899. * @returns {Function} Returns the new spec function.
  5900. */
  5901. function matchesStrictComparable(key, srcValue) {
  5902. return function(object) {
  5903. if (object == null) {
  5904. return false;
  5905. }
  5906. return object[key] === srcValue &&
  5907. (srcValue !== undefined || (key in Object(object)));
  5908. };
  5909. }
  5910. /**
  5911. * A specialized version of `_.memoize` which clears the memoized function's
  5912. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5913. *
  5914. * @private
  5915. * @param {Function} func The function to have its output memoized.
  5916. * @returns {Function} Returns the new memoized function.
  5917. */
  5918. function memoizeCapped(func) {
  5919. var result = memoize(func, function(key) {
  5920. if (cache.size === MAX_MEMOIZE_SIZE) {
  5921. cache.clear();
  5922. }
  5923. return key;
  5924. });
  5925. var cache = result.cache;
  5926. return result;
  5927. }
  5928. /**
  5929. * Merges the function metadata of `source` into `data`.
  5930. *
  5931. * Merging metadata reduces the number of wrappers used to invoke a function.
  5932. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5933. * may be applied regardless of execution order. Methods like `_.ary` and
  5934. * `_.rearg` modify function arguments, making the order in which they are
  5935. * executed important, preventing the merging of metadata. However, we make
  5936. * an exception for a safe combined case where curried functions have `_.ary`
  5937. * and or `_.rearg` applied.
  5938. *
  5939. * @private
  5940. * @param {Array} data The destination metadata.
  5941. * @param {Array} source The source metadata.
  5942. * @returns {Array} Returns `data`.
  5943. */
  5944. function mergeData(data, source) {
  5945. var bitmask = data[1],
  5946. srcBitmask = source[1],
  5947. newBitmask = bitmask | srcBitmask,
  5948. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5949. var isCombo =
  5950. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5951. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5952. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5953. // Exit early if metadata can't be merged.
  5954. if (!(isCommon || isCombo)) {
  5955. return data;
  5956. }
  5957. // Use source `thisArg` if available.
  5958. if (srcBitmask & WRAP_BIND_FLAG) {
  5959. data[2] = source[2];
  5960. // Set when currying a bound function.
  5961. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5962. }
  5963. // Compose partial arguments.
  5964. var value = source[3];
  5965. if (value) {
  5966. var partials = data[3];
  5967. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5968. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5969. }
  5970. // Compose partial right arguments.
  5971. value = source[5];
  5972. if (value) {
  5973. partials = data[5];
  5974. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5975. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5976. }
  5977. // Use source `argPos` if available.
  5978. value = source[7];
  5979. if (value) {
  5980. data[7] = value;
  5981. }
  5982. // Use source `ary` if it's smaller.
  5983. if (srcBitmask & WRAP_ARY_FLAG) {
  5984. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5985. }
  5986. // Use source `arity` if one is not provided.
  5987. if (data[9] == null) {
  5988. data[9] = source[9];
  5989. }
  5990. // Use source `func` and merge bitmasks.
  5991. data[0] = source[0];
  5992. data[1] = newBitmask;
  5993. return data;
  5994. }
  5995. /**
  5996. * This function is like
  5997. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5998. * except that it includes inherited enumerable properties.
  5999. *
  6000. * @private
  6001. * @param {Object} object The object to query.
  6002. * @returns {Array} Returns the array of property names.
  6003. */
  6004. function nativeKeysIn(object) {
  6005. var result = [];
  6006. if (object != null) {
  6007. for (var key in Object(object)) {
  6008. result.push(key);
  6009. }
  6010. }
  6011. return result;
  6012. }
  6013. /**
  6014. * Converts `value` to a string using `Object.prototype.toString`.
  6015. *
  6016. * @private
  6017. * @param {*} value The value to convert.
  6018. * @returns {string} Returns the converted string.
  6019. */
  6020. function objectToString(value) {
  6021. return nativeObjectToString.call(value);
  6022. }
  6023. /**
  6024. * A specialized version of `baseRest` which transforms the rest array.
  6025. *
  6026. * @private
  6027. * @param {Function} func The function to apply a rest parameter to.
  6028. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6029. * @param {Function} transform The rest array transform.
  6030. * @returns {Function} Returns the new function.
  6031. */
  6032. function overRest(func, start, transform) {
  6033. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6034. return function() {
  6035. var args = arguments,
  6036. index = -1,
  6037. length = nativeMax(args.length - start, 0),
  6038. array = Array(length);
  6039. while (++index < length) {
  6040. array[index] = args[start + index];
  6041. }
  6042. index = -1;
  6043. var otherArgs = Array(start + 1);
  6044. while (++index < start) {
  6045. otherArgs[index] = args[index];
  6046. }
  6047. otherArgs[start] = transform(array);
  6048. return apply(func, this, otherArgs);
  6049. };
  6050. }
  6051. /**
  6052. * Gets the parent value at `path` of `object`.
  6053. *
  6054. * @private
  6055. * @param {Object} object The object to query.
  6056. * @param {Array} path The path to get the parent value of.
  6057. * @returns {*} Returns the parent value.
  6058. */
  6059. function parent(object, path) {
  6060. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6061. }
  6062. /**
  6063. * Reorder `array` according to the specified indexes where the element at
  6064. * the first index is assigned as the first element, the element at
  6065. * the second index is assigned as the second element, and so on.
  6066. *
  6067. * @private
  6068. * @param {Array} array The array to reorder.
  6069. * @param {Array} indexes The arranged array indexes.
  6070. * @returns {Array} Returns `array`.
  6071. */
  6072. function reorder(array, indexes) {
  6073. var arrLength = array.length,
  6074. length = nativeMin(indexes.length, arrLength),
  6075. oldArray = copyArray(array);
  6076. while (length--) {
  6077. var index = indexes[length];
  6078. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6079. }
  6080. return array;
  6081. }
  6082. /**
  6083. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6084. *
  6085. * @private
  6086. * @param {Object} object The object to query.
  6087. * @param {string} key The key of the property to get.
  6088. * @returns {*} Returns the property value.
  6089. */
  6090. function safeGet(object, key) {
  6091. if (key === 'constructor' && typeof object[key] === 'function') {
  6092. return;
  6093. }
  6094. if (key == '__proto__') {
  6095. return;
  6096. }
  6097. return object[key];
  6098. }
  6099. /**
  6100. * Sets metadata for `func`.
  6101. *
  6102. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6103. * period of time, it will trip its breaker and transition to an identity
  6104. * function to avoid garbage collection pauses in V8. See
  6105. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6106. * for more details.
  6107. *
  6108. * @private
  6109. * @param {Function} func The function to associate metadata with.
  6110. * @param {*} data The metadata.
  6111. * @returns {Function} Returns `func`.
  6112. */
  6113. var setData = shortOut(baseSetData);
  6114. /**
  6115. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6116. *
  6117. * @private
  6118. * @param {Function} func The function to delay.
  6119. * @param {number} wait The number of milliseconds to delay invocation.
  6120. * @returns {number|Object} Returns the timer id or timeout object.
  6121. */
  6122. var setTimeout = ctxSetTimeout || function(func, wait) {
  6123. return root.setTimeout(func, wait);
  6124. };
  6125. /**
  6126. * Sets the `toString` method of `func` to return `string`.
  6127. *
  6128. * @private
  6129. * @param {Function} func The function to modify.
  6130. * @param {Function} string The `toString` result.
  6131. * @returns {Function} Returns `func`.
  6132. */
  6133. var setToString = shortOut(baseSetToString);
  6134. /**
  6135. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6136. * with wrapper details in a comment at the top of the source body.
  6137. *
  6138. * @private
  6139. * @param {Function} wrapper The function to modify.
  6140. * @param {Function} reference The reference function.
  6141. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6142. * @returns {Function} Returns `wrapper`.
  6143. */
  6144. function setWrapToString(wrapper, reference, bitmask) {
  6145. var source = (reference + '');
  6146. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6147. }
  6148. /**
  6149. * Creates a function that'll short out and invoke `identity` instead
  6150. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6151. * milliseconds.
  6152. *
  6153. * @private
  6154. * @param {Function} func The function to restrict.
  6155. * @returns {Function} Returns the new shortable function.
  6156. */
  6157. function shortOut(func) {
  6158. var count = 0,
  6159. lastCalled = 0;
  6160. return function() {
  6161. var stamp = nativeNow(),
  6162. remaining = HOT_SPAN - (stamp - lastCalled);
  6163. lastCalled = stamp;
  6164. if (remaining > 0) {
  6165. if (++count >= HOT_COUNT) {
  6166. return arguments[0];
  6167. }
  6168. } else {
  6169. count = 0;
  6170. }
  6171. return func.apply(undefined, arguments);
  6172. };
  6173. }
  6174. /**
  6175. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6176. *
  6177. * @private
  6178. * @param {Array} array The array to shuffle.
  6179. * @param {number} [size=array.length] The size of `array`.
  6180. * @returns {Array} Returns `array`.
  6181. */
  6182. function shuffleSelf(array, size) {
  6183. var index = -1,
  6184. length = array.length,
  6185. lastIndex = length - 1;
  6186. size = size === undefined ? length : size;
  6187. while (++index < size) {
  6188. var rand = baseRandom(index, lastIndex),
  6189. value = array[rand];
  6190. array[rand] = array[index];
  6191. array[index] = value;
  6192. }
  6193. array.length = size;
  6194. return array;
  6195. }
  6196. /**
  6197. * Converts `string` to a property path array.
  6198. *
  6199. * @private
  6200. * @param {string} string The string to convert.
  6201. * @returns {Array} Returns the property path array.
  6202. */
  6203. var stringToPath = memoizeCapped(function(string) {
  6204. var result = [];
  6205. if (string.charCodeAt(0) === 46 /* . */) {
  6206. result.push('');
  6207. }
  6208. string.replace(rePropName, function(match, number, quote, subString) {
  6209. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6210. });
  6211. return result;
  6212. });
  6213. /**
  6214. * Converts `value` to a string key if it's not a string or symbol.
  6215. *
  6216. * @private
  6217. * @param {*} value The value to inspect.
  6218. * @returns {string|symbol} Returns the key.
  6219. */
  6220. function toKey(value) {
  6221. if (typeof value == 'string' || isSymbol(value)) {
  6222. return value;
  6223. }
  6224. var result = (value + '');
  6225. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6226. }
  6227. /**
  6228. * Converts `func` to its source code.
  6229. *
  6230. * @private
  6231. * @param {Function} func The function to convert.
  6232. * @returns {string} Returns the source code.
  6233. */
  6234. function toSource(func) {
  6235. if (func != null) {
  6236. try {
  6237. return funcToString.call(func);
  6238. } catch (e) {}
  6239. try {
  6240. return (func + '');
  6241. } catch (e) {}
  6242. }
  6243. return '';
  6244. }
  6245. /**
  6246. * Updates wrapper `details` based on `bitmask` flags.
  6247. *
  6248. * @private
  6249. * @returns {Array} details The details to modify.
  6250. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6251. * @returns {Array} Returns `details`.
  6252. */
  6253. function updateWrapDetails(details, bitmask) {
  6254. arrayEach(wrapFlags, function(pair) {
  6255. var value = '_.' + pair[0];
  6256. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6257. details.push(value);
  6258. }
  6259. });
  6260. return details.sort();
  6261. }
  6262. /**
  6263. * Creates a clone of `wrapper`.
  6264. *
  6265. * @private
  6266. * @param {Object} wrapper The wrapper to clone.
  6267. * @returns {Object} Returns the cloned wrapper.
  6268. */
  6269. function wrapperClone(wrapper) {
  6270. if (wrapper instanceof LazyWrapper) {
  6271. return wrapper.clone();
  6272. }
  6273. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6274. result.__actions__ = copyArray(wrapper.__actions__);
  6275. result.__index__ = wrapper.__index__;
  6276. result.__values__ = wrapper.__values__;
  6277. return result;
  6278. }
  6279. /*------------------------------------------------------------------------*/
  6280. /**
  6281. * Creates an array of elements split into groups the length of `size`.
  6282. * If `array` can't be split evenly, the final chunk will be the remaining
  6283. * elements.
  6284. *
  6285. * @static
  6286. * @memberOf _
  6287. * @since 3.0.0
  6288. * @category Array
  6289. * @param {Array} array The array to process.
  6290. * @param {number} [size=1] The length of each chunk
  6291. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6292. * @returns {Array} Returns the new array of chunks.
  6293. * @example
  6294. *
  6295. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6296. * // => [['a', 'b'], ['c', 'd']]
  6297. *
  6298. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6299. * // => [['a', 'b', 'c'], ['d']]
  6300. */
  6301. function chunk(array, size, guard) {
  6302. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6303. size = 1;
  6304. } else {
  6305. size = nativeMax(toInteger(size), 0);
  6306. }
  6307. var length = array == null ? 0 : array.length;
  6308. if (!length || size < 1) {
  6309. return [];
  6310. }
  6311. var index = 0,
  6312. resIndex = 0,
  6313. result = Array(nativeCeil(length / size));
  6314. while (index < length) {
  6315. result[resIndex++] = baseSlice(array, index, (index += size));
  6316. }
  6317. return result;
  6318. }
  6319. /**
  6320. * Creates an array with all falsey values removed. The values `false`, `null`,
  6321. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6322. *
  6323. * @static
  6324. * @memberOf _
  6325. * @since 0.1.0
  6326. * @category Array
  6327. * @param {Array} array The array to compact.
  6328. * @returns {Array} Returns the new array of filtered values.
  6329. * @example
  6330. *
  6331. * _.compact([0, 1, false, 2, '', 3]);
  6332. * // => [1, 2, 3]
  6333. */
  6334. function compact(array) {
  6335. var index = -1,
  6336. length = array == null ? 0 : array.length,
  6337. resIndex = 0,
  6338. result = [];
  6339. while (++index < length) {
  6340. var value = array[index];
  6341. if (value) {
  6342. result[resIndex++] = value;
  6343. }
  6344. }
  6345. return result;
  6346. }
  6347. /**
  6348. * Creates a new array concatenating `array` with any additional arrays
  6349. * and/or values.
  6350. *
  6351. * @static
  6352. * @memberOf _
  6353. * @since 4.0.0
  6354. * @category Array
  6355. * @param {Array} array The array to concatenate.
  6356. * @param {...*} [values] The values to concatenate.
  6357. * @returns {Array} Returns the new concatenated array.
  6358. * @example
  6359. *
  6360. * var array = [1];
  6361. * var other = _.concat(array, 2, [3], [[4]]);
  6362. *
  6363. * console.log(other);
  6364. * // => [1, 2, 3, [4]]
  6365. *
  6366. * console.log(array);
  6367. * // => [1]
  6368. */
  6369. function concat() {
  6370. var length = arguments.length;
  6371. if (!length) {
  6372. return [];
  6373. }
  6374. var args = Array(length - 1),
  6375. array = arguments[0],
  6376. index = length;
  6377. while (index--) {
  6378. args[index - 1] = arguments[index];
  6379. }
  6380. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6381. }
  6382. /**
  6383. * Creates an array of `array` values not included in the other given arrays
  6384. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6385. * for equality comparisons. The order and references of result values are
  6386. * determined by the first array.
  6387. *
  6388. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6389. *
  6390. * @static
  6391. * @memberOf _
  6392. * @since 0.1.0
  6393. * @category Array
  6394. * @param {Array} array The array to inspect.
  6395. * @param {...Array} [values] The values to exclude.
  6396. * @returns {Array} Returns the new array of filtered values.
  6397. * @see _.without, _.xor
  6398. * @example
  6399. *
  6400. * _.difference([2, 1], [2, 3]);
  6401. * // => [1]
  6402. */
  6403. var difference = baseRest(function(array, values) {
  6404. return isArrayLikeObject(array)
  6405. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6406. : [];
  6407. });
  6408. /**
  6409. * This method is like `_.difference` except that it accepts `iteratee` which
  6410. * is invoked for each element of `array` and `values` to generate the criterion
  6411. * by which they're compared. The order and references of result values are
  6412. * determined by the first array. The iteratee is invoked with one argument:
  6413. * (value).
  6414. *
  6415. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6416. *
  6417. * @static
  6418. * @memberOf _
  6419. * @since 4.0.0
  6420. * @category Array
  6421. * @param {Array} array The array to inspect.
  6422. * @param {...Array} [values] The values to exclude.
  6423. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6424. * @returns {Array} Returns the new array of filtered values.
  6425. * @example
  6426. *
  6427. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6428. * // => [1.2]
  6429. *
  6430. * // The `_.property` iteratee shorthand.
  6431. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6432. * // => [{ 'x': 2 }]
  6433. */
  6434. var differenceBy = baseRest(function(array, values) {
  6435. var iteratee = last(values);
  6436. if (isArrayLikeObject(iteratee)) {
  6437. iteratee = undefined;
  6438. }
  6439. return isArrayLikeObject(array)
  6440. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6441. : [];
  6442. });
  6443. /**
  6444. * This method is like `_.difference` except that it accepts `comparator`
  6445. * which is invoked to compare elements of `array` to `values`. The order and
  6446. * references of result values are determined by the first array. The comparator
  6447. * is invoked with two arguments: (arrVal, othVal).
  6448. *
  6449. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6450. *
  6451. * @static
  6452. * @memberOf _
  6453. * @since 4.0.0
  6454. * @category Array
  6455. * @param {Array} array The array to inspect.
  6456. * @param {...Array} [values] The values to exclude.
  6457. * @param {Function} [comparator] The comparator invoked per element.
  6458. * @returns {Array} Returns the new array of filtered values.
  6459. * @example
  6460. *
  6461. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6462. *
  6463. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6464. * // => [{ 'x': 2, 'y': 1 }]
  6465. */
  6466. var differenceWith = baseRest(function(array, values) {
  6467. var comparator = last(values);
  6468. if (isArrayLikeObject(comparator)) {
  6469. comparator = undefined;
  6470. }
  6471. return isArrayLikeObject(array)
  6472. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6473. : [];
  6474. });
  6475. /**
  6476. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6477. *
  6478. * @static
  6479. * @memberOf _
  6480. * @since 0.5.0
  6481. * @category Array
  6482. * @param {Array} array The array to query.
  6483. * @param {number} [n=1] The number of elements to drop.
  6484. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6485. * @returns {Array} Returns the slice of `array`.
  6486. * @example
  6487. *
  6488. * _.drop([1, 2, 3]);
  6489. * // => [2, 3]
  6490. *
  6491. * _.drop([1, 2, 3], 2);
  6492. * // => [3]
  6493. *
  6494. * _.drop([1, 2, 3], 5);
  6495. * // => []
  6496. *
  6497. * _.drop([1, 2, 3], 0);
  6498. * // => [1, 2, 3]
  6499. */
  6500. function drop(array, n, guard) {
  6501. var length = array == null ? 0 : array.length;
  6502. if (!length) {
  6503. return [];
  6504. }
  6505. n = (guard || n === undefined) ? 1 : toInteger(n);
  6506. return baseSlice(array, n < 0 ? 0 : n, length);
  6507. }
  6508. /**
  6509. * Creates a slice of `array` with `n` elements dropped from the end.
  6510. *
  6511. * @static
  6512. * @memberOf _
  6513. * @since 3.0.0
  6514. * @category Array
  6515. * @param {Array} array The array to query.
  6516. * @param {number} [n=1] The number of elements to drop.
  6517. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6518. * @returns {Array} Returns the slice of `array`.
  6519. * @example
  6520. *
  6521. * _.dropRight([1, 2, 3]);
  6522. * // => [1, 2]
  6523. *
  6524. * _.dropRight([1, 2, 3], 2);
  6525. * // => [1]
  6526. *
  6527. * _.dropRight([1, 2, 3], 5);
  6528. * // => []
  6529. *
  6530. * _.dropRight([1, 2, 3], 0);
  6531. * // => [1, 2, 3]
  6532. */
  6533. function dropRight(array, n, guard) {
  6534. var length = array == null ? 0 : array.length;
  6535. if (!length) {
  6536. return [];
  6537. }
  6538. n = (guard || n === undefined) ? 1 : toInteger(n);
  6539. n = length - n;
  6540. return baseSlice(array, 0, n < 0 ? 0 : n);
  6541. }
  6542. /**
  6543. * Creates a slice of `array` excluding elements dropped from the end.
  6544. * Elements are dropped until `predicate` returns falsey. The predicate is
  6545. * invoked with three arguments: (value, index, array).
  6546. *
  6547. * @static
  6548. * @memberOf _
  6549. * @since 3.0.0
  6550. * @category Array
  6551. * @param {Array} array The array to query.
  6552. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6553. * @returns {Array} Returns the slice of `array`.
  6554. * @example
  6555. *
  6556. * var users = [
  6557. * { 'user': 'barney', 'active': true },
  6558. * { 'user': 'fred', 'active': false },
  6559. * { 'user': 'pebbles', 'active': false }
  6560. * ];
  6561. *
  6562. * _.dropRightWhile(users, function(o) { return !o.active; });
  6563. * // => objects for ['barney']
  6564. *
  6565. * // The `_.matches` iteratee shorthand.
  6566. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6567. * // => objects for ['barney', 'fred']
  6568. *
  6569. * // The `_.matchesProperty` iteratee shorthand.
  6570. * _.dropRightWhile(users, ['active', false]);
  6571. * // => objects for ['barney']
  6572. *
  6573. * // The `_.property` iteratee shorthand.
  6574. * _.dropRightWhile(users, 'active');
  6575. * // => objects for ['barney', 'fred', 'pebbles']
  6576. */
  6577. function dropRightWhile(array, predicate) {
  6578. return (array && array.length)
  6579. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6580. : [];
  6581. }
  6582. /**
  6583. * Creates a slice of `array` excluding elements dropped from the beginning.
  6584. * Elements are dropped until `predicate` returns falsey. The predicate is
  6585. * invoked with three arguments: (value, index, array).
  6586. *
  6587. * @static
  6588. * @memberOf _
  6589. * @since 3.0.0
  6590. * @category Array
  6591. * @param {Array} array The array to query.
  6592. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6593. * @returns {Array} Returns the slice of `array`.
  6594. * @example
  6595. *
  6596. * var users = [
  6597. * { 'user': 'barney', 'active': false },
  6598. * { 'user': 'fred', 'active': false },
  6599. * { 'user': 'pebbles', 'active': true }
  6600. * ];
  6601. *
  6602. * _.dropWhile(users, function(o) { return !o.active; });
  6603. * // => objects for ['pebbles']
  6604. *
  6605. * // The `_.matches` iteratee shorthand.
  6606. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6607. * // => objects for ['fred', 'pebbles']
  6608. *
  6609. * // The `_.matchesProperty` iteratee shorthand.
  6610. * _.dropWhile(users, ['active', false]);
  6611. * // => objects for ['pebbles']
  6612. *
  6613. * // The `_.property` iteratee shorthand.
  6614. * _.dropWhile(users, 'active');
  6615. * // => objects for ['barney', 'fred', 'pebbles']
  6616. */
  6617. function dropWhile(array, predicate) {
  6618. return (array && array.length)
  6619. ? baseWhile(array, getIteratee(predicate, 3), true)
  6620. : [];
  6621. }
  6622. /**
  6623. * Fills elements of `array` with `value` from `start` up to, but not
  6624. * including, `end`.
  6625. *
  6626. * **Note:** This method mutates `array`.
  6627. *
  6628. * @static
  6629. * @memberOf _
  6630. * @since 3.2.0
  6631. * @category Array
  6632. * @param {Array} array The array to fill.
  6633. * @param {*} value The value to fill `array` with.
  6634. * @param {number} [start=0] The start position.
  6635. * @param {number} [end=array.length] The end position.
  6636. * @returns {Array} Returns `array`.
  6637. * @example
  6638. *
  6639. * var array = [1, 2, 3];
  6640. *
  6641. * _.fill(array, 'a');
  6642. * console.log(array);
  6643. * // => ['a', 'a', 'a']
  6644. *
  6645. * _.fill(Array(3), 2);
  6646. * // => [2, 2, 2]
  6647. *
  6648. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6649. * // => [4, '*', '*', 10]
  6650. */
  6651. function fill(array, value, start, end) {
  6652. var length = array == null ? 0 : array.length;
  6653. if (!length) {
  6654. return [];
  6655. }
  6656. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6657. start = 0;
  6658. end = length;
  6659. }
  6660. return baseFill(array, value, start, end);
  6661. }
  6662. /**
  6663. * This method is like `_.find` except that it returns the index of the first
  6664. * element `predicate` returns truthy for instead of the element itself.
  6665. *
  6666. * @static
  6667. * @memberOf _
  6668. * @since 1.1.0
  6669. * @category Array
  6670. * @param {Array} array The array to inspect.
  6671. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6672. * @param {number} [fromIndex=0] The index to search from.
  6673. * @returns {number} Returns the index of the found element, else `-1`.
  6674. * @example
  6675. *
  6676. * var users = [
  6677. * { 'user': 'barney', 'active': false },
  6678. * { 'user': 'fred', 'active': false },
  6679. * { 'user': 'pebbles', 'active': true }
  6680. * ];
  6681. *
  6682. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6683. * // => 0
  6684. *
  6685. * // The `_.matches` iteratee shorthand.
  6686. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6687. * // => 1
  6688. *
  6689. * // The `_.matchesProperty` iteratee shorthand.
  6690. * _.findIndex(users, ['active', false]);
  6691. * // => 0
  6692. *
  6693. * // The `_.property` iteratee shorthand.
  6694. * _.findIndex(users, 'active');
  6695. * // => 2
  6696. */
  6697. function findIndex(array, predicate, fromIndex) {
  6698. var length = array == null ? 0 : array.length;
  6699. if (!length) {
  6700. return -1;
  6701. }
  6702. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6703. if (index < 0) {
  6704. index = nativeMax(length + index, 0);
  6705. }
  6706. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6707. }
  6708. /**
  6709. * This method is like `_.findIndex` except that it iterates over elements
  6710. * of `collection` from right to left.
  6711. *
  6712. * @static
  6713. * @memberOf _
  6714. * @since 2.0.0
  6715. * @category Array
  6716. * @param {Array} array The array to inspect.
  6717. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6718. * @param {number} [fromIndex=array.length-1] The index to search from.
  6719. * @returns {number} Returns the index of the found element, else `-1`.
  6720. * @example
  6721. *
  6722. * var users = [
  6723. * { 'user': 'barney', 'active': true },
  6724. * { 'user': 'fred', 'active': false },
  6725. * { 'user': 'pebbles', 'active': false }
  6726. * ];
  6727. *
  6728. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6729. * // => 2
  6730. *
  6731. * // The `_.matches` iteratee shorthand.
  6732. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6733. * // => 0
  6734. *
  6735. * // The `_.matchesProperty` iteratee shorthand.
  6736. * _.findLastIndex(users, ['active', false]);
  6737. * // => 2
  6738. *
  6739. * // The `_.property` iteratee shorthand.
  6740. * _.findLastIndex(users, 'active');
  6741. * // => 0
  6742. */
  6743. function findLastIndex(array, predicate, fromIndex) {
  6744. var length = array == null ? 0 : array.length;
  6745. if (!length) {
  6746. return -1;
  6747. }
  6748. var index = length - 1;
  6749. if (fromIndex !== undefined) {
  6750. index = toInteger(fromIndex);
  6751. index = fromIndex < 0
  6752. ? nativeMax(length + index, 0)
  6753. : nativeMin(index, length - 1);
  6754. }
  6755. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6756. }
  6757. /**
  6758. * Flattens `array` a single level deep.
  6759. *
  6760. * @static
  6761. * @memberOf _
  6762. * @since 0.1.0
  6763. * @category Array
  6764. * @param {Array} array The array to flatten.
  6765. * @returns {Array} Returns the new flattened array.
  6766. * @example
  6767. *
  6768. * _.flatten([1, [2, [3, [4]], 5]]);
  6769. * // => [1, 2, [3, [4]], 5]
  6770. */
  6771. function flatten(array) {
  6772. var length = array == null ? 0 : array.length;
  6773. return length ? baseFlatten(array, 1) : [];
  6774. }
  6775. /**
  6776. * Recursively flattens `array`.
  6777. *
  6778. * @static
  6779. * @memberOf _
  6780. * @since 3.0.0
  6781. * @category Array
  6782. * @param {Array} array The array to flatten.
  6783. * @returns {Array} Returns the new flattened array.
  6784. * @example
  6785. *
  6786. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6787. * // => [1, 2, 3, 4, 5]
  6788. */
  6789. function flattenDeep(array) {
  6790. var length = array == null ? 0 : array.length;
  6791. return length ? baseFlatten(array, INFINITY) : [];
  6792. }
  6793. /**
  6794. * Recursively flatten `array` up to `depth` times.
  6795. *
  6796. * @static
  6797. * @memberOf _
  6798. * @since 4.4.0
  6799. * @category Array
  6800. * @param {Array} array The array to flatten.
  6801. * @param {number} [depth=1] The maximum recursion depth.
  6802. * @returns {Array} Returns the new flattened array.
  6803. * @example
  6804. *
  6805. * var array = [1, [2, [3, [4]], 5]];
  6806. *
  6807. * _.flattenDepth(array, 1);
  6808. * // => [1, 2, [3, [4]], 5]
  6809. *
  6810. * _.flattenDepth(array, 2);
  6811. * // => [1, 2, 3, [4], 5]
  6812. */
  6813. function flattenDepth(array, depth) {
  6814. var length = array == null ? 0 : array.length;
  6815. if (!length) {
  6816. return [];
  6817. }
  6818. depth = depth === undefined ? 1 : toInteger(depth);
  6819. return baseFlatten(array, depth);
  6820. }
  6821. /**
  6822. * The inverse of `_.toPairs`; this method returns an object composed
  6823. * from key-value `pairs`.
  6824. *
  6825. * @static
  6826. * @memberOf _
  6827. * @since 4.0.0
  6828. * @category Array
  6829. * @param {Array} pairs The key-value pairs.
  6830. * @returns {Object} Returns the new object.
  6831. * @example
  6832. *
  6833. * _.fromPairs([['a', 1], ['b', 2]]);
  6834. * // => { 'a': 1, 'b': 2 }
  6835. */
  6836. function fromPairs(pairs) {
  6837. var index = -1,
  6838. length = pairs == null ? 0 : pairs.length,
  6839. result = {};
  6840. while (++index < length) {
  6841. var pair = pairs[index];
  6842. result[pair[0]] = pair[1];
  6843. }
  6844. return result;
  6845. }
  6846. /**
  6847. * Gets the first element of `array`.
  6848. *
  6849. * @static
  6850. * @memberOf _
  6851. * @since 0.1.0
  6852. * @alias first
  6853. * @category Array
  6854. * @param {Array} array The array to query.
  6855. * @returns {*} Returns the first element of `array`.
  6856. * @example
  6857. *
  6858. * _.head([1, 2, 3]);
  6859. * // => 1
  6860. *
  6861. * _.head([]);
  6862. * // => undefined
  6863. */
  6864. function head(array) {
  6865. return (array && array.length) ? array[0] : undefined;
  6866. }
  6867. /**
  6868. * Gets the index at which the first occurrence of `value` is found in `array`
  6869. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6870. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6871. * offset from the end of `array`.
  6872. *
  6873. * @static
  6874. * @memberOf _
  6875. * @since 0.1.0
  6876. * @category Array
  6877. * @param {Array} array The array to inspect.
  6878. * @param {*} value The value to search for.
  6879. * @param {number} [fromIndex=0] The index to search from.
  6880. * @returns {number} Returns the index of the matched value, else `-1`.
  6881. * @example
  6882. *
  6883. * _.indexOf([1, 2, 1, 2], 2);
  6884. * // => 1
  6885. *
  6886. * // Search from the `fromIndex`.
  6887. * _.indexOf([1, 2, 1, 2], 2, 2);
  6888. * // => 3
  6889. */
  6890. function indexOf(array, value, fromIndex) {
  6891. var length = array == null ? 0 : array.length;
  6892. if (!length) {
  6893. return -1;
  6894. }
  6895. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6896. if (index < 0) {
  6897. index = nativeMax(length + index, 0);
  6898. }
  6899. return baseIndexOf(array, value, index);
  6900. }
  6901. /**
  6902. * Gets all but the last element of `array`.
  6903. *
  6904. * @static
  6905. * @memberOf _
  6906. * @since 0.1.0
  6907. * @category Array
  6908. * @param {Array} array The array to query.
  6909. * @returns {Array} Returns the slice of `array`.
  6910. * @example
  6911. *
  6912. * _.initial([1, 2, 3]);
  6913. * // => [1, 2]
  6914. */
  6915. function initial(array) {
  6916. var length = array == null ? 0 : array.length;
  6917. return length ? baseSlice(array, 0, -1) : [];
  6918. }
  6919. /**
  6920. * Creates an array of unique values that are included in all given arrays
  6921. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6922. * for equality comparisons. The order and references of result values are
  6923. * determined by the first array.
  6924. *
  6925. * @static
  6926. * @memberOf _
  6927. * @since 0.1.0
  6928. * @category Array
  6929. * @param {...Array} [arrays] The arrays to inspect.
  6930. * @returns {Array} Returns the new array of intersecting values.
  6931. * @example
  6932. *
  6933. * _.intersection([2, 1], [2, 3]);
  6934. * // => [2]
  6935. */
  6936. var intersection = baseRest(function(arrays) {
  6937. var mapped = arrayMap(arrays, castArrayLikeObject);
  6938. return (mapped.length && mapped[0] === arrays[0])
  6939. ? baseIntersection(mapped)
  6940. : [];
  6941. });
  6942. /**
  6943. * This method is like `_.intersection` except that it accepts `iteratee`
  6944. * which is invoked for each element of each `arrays` to generate the criterion
  6945. * by which they're compared. The order and references of result values are
  6946. * determined by the first array. The iteratee is invoked with one argument:
  6947. * (value).
  6948. *
  6949. * @static
  6950. * @memberOf _
  6951. * @since 4.0.0
  6952. * @category Array
  6953. * @param {...Array} [arrays] The arrays to inspect.
  6954. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6955. * @returns {Array} Returns the new array of intersecting values.
  6956. * @example
  6957. *
  6958. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6959. * // => [2.1]
  6960. *
  6961. * // The `_.property` iteratee shorthand.
  6962. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6963. * // => [{ 'x': 1 }]
  6964. */
  6965. var intersectionBy = baseRest(function(arrays) {
  6966. var iteratee = last(arrays),
  6967. mapped = arrayMap(arrays, castArrayLikeObject);
  6968. if (iteratee === last(mapped)) {
  6969. iteratee = undefined;
  6970. } else {
  6971. mapped.pop();
  6972. }
  6973. return (mapped.length && mapped[0] === arrays[0])
  6974. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6975. : [];
  6976. });
  6977. /**
  6978. * This method is like `_.intersection` except that it accepts `comparator`
  6979. * which is invoked to compare elements of `arrays`. The order and references
  6980. * of result values are determined by the first array. The comparator is
  6981. * invoked with two arguments: (arrVal, othVal).
  6982. *
  6983. * @static
  6984. * @memberOf _
  6985. * @since 4.0.0
  6986. * @category Array
  6987. * @param {...Array} [arrays] The arrays to inspect.
  6988. * @param {Function} [comparator] The comparator invoked per element.
  6989. * @returns {Array} Returns the new array of intersecting values.
  6990. * @example
  6991. *
  6992. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6993. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6994. *
  6995. * _.intersectionWith(objects, others, _.isEqual);
  6996. * // => [{ 'x': 1, 'y': 2 }]
  6997. */
  6998. var intersectionWith = baseRest(function(arrays) {
  6999. var comparator = last(arrays),
  7000. mapped = arrayMap(arrays, castArrayLikeObject);
  7001. comparator = typeof comparator == 'function' ? comparator : undefined;
  7002. if (comparator) {
  7003. mapped.pop();
  7004. }
  7005. return (mapped.length && mapped[0] === arrays[0])
  7006. ? baseIntersection(mapped, undefined, comparator)
  7007. : [];
  7008. });
  7009. /**
  7010. * Converts all elements in `array` into a string separated by `separator`.
  7011. *
  7012. * @static
  7013. * @memberOf _
  7014. * @since 4.0.0
  7015. * @category Array
  7016. * @param {Array} array The array to convert.
  7017. * @param {string} [separator=','] The element separator.
  7018. * @returns {string} Returns the joined string.
  7019. * @example
  7020. *
  7021. * _.join(['a', 'b', 'c'], '~');
  7022. * // => 'a~b~c'
  7023. */
  7024. function join(array, separator) {
  7025. return array == null ? '' : nativeJoin.call(array, separator);
  7026. }
  7027. /**
  7028. * Gets the last element of `array`.
  7029. *
  7030. * @static
  7031. * @memberOf _
  7032. * @since 0.1.0
  7033. * @category Array
  7034. * @param {Array} array The array to query.
  7035. * @returns {*} Returns the last element of `array`.
  7036. * @example
  7037. *
  7038. * _.last([1, 2, 3]);
  7039. * // => 3
  7040. */
  7041. function last(array) {
  7042. var length = array == null ? 0 : array.length;
  7043. return length ? array[length - 1] : undefined;
  7044. }
  7045. /**
  7046. * This method is like `_.indexOf` except that it iterates over elements of
  7047. * `array` from right to left.
  7048. *
  7049. * @static
  7050. * @memberOf _
  7051. * @since 0.1.0
  7052. * @category Array
  7053. * @param {Array} array The array to inspect.
  7054. * @param {*} value The value to search for.
  7055. * @param {number} [fromIndex=array.length-1] The index to search from.
  7056. * @returns {number} Returns the index of the matched value, else `-1`.
  7057. * @example
  7058. *
  7059. * _.lastIndexOf([1, 2, 1, 2], 2);
  7060. * // => 3
  7061. *
  7062. * // Search from the `fromIndex`.
  7063. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7064. * // => 1
  7065. */
  7066. function lastIndexOf(array, value, fromIndex) {
  7067. var length = array == null ? 0 : array.length;
  7068. if (!length) {
  7069. return -1;
  7070. }
  7071. var index = length;
  7072. if (fromIndex !== undefined) {
  7073. index = toInteger(fromIndex);
  7074. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7075. }
  7076. return value === value
  7077. ? strictLastIndexOf(array, value, index)
  7078. : baseFindIndex(array, baseIsNaN, index, true);
  7079. }
  7080. /**
  7081. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7082. * element from the end is returned.
  7083. *
  7084. * @static
  7085. * @memberOf _
  7086. * @since 4.11.0
  7087. * @category Array
  7088. * @param {Array} array The array to query.
  7089. * @param {number} [n=0] The index of the element to return.
  7090. * @returns {*} Returns the nth element of `array`.
  7091. * @example
  7092. *
  7093. * var array = ['a', 'b', 'c', 'd'];
  7094. *
  7095. * _.nth(array, 1);
  7096. * // => 'b'
  7097. *
  7098. * _.nth(array, -2);
  7099. * // => 'c';
  7100. */
  7101. function nth(array, n) {
  7102. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7103. }
  7104. /**
  7105. * Removes all given values from `array` using
  7106. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7107. * for equality comparisons.
  7108. *
  7109. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7110. * to remove elements from an array by predicate.
  7111. *
  7112. * @static
  7113. * @memberOf _
  7114. * @since 2.0.0
  7115. * @category Array
  7116. * @param {Array} array The array to modify.
  7117. * @param {...*} [values] The values to remove.
  7118. * @returns {Array} Returns `array`.
  7119. * @example
  7120. *
  7121. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7122. *
  7123. * _.pull(array, 'a', 'c');
  7124. * console.log(array);
  7125. * // => ['b', 'b']
  7126. */
  7127. var pull = baseRest(pullAll);
  7128. /**
  7129. * This method is like `_.pull` except that it accepts an array of values to remove.
  7130. *
  7131. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7132. *
  7133. * @static
  7134. * @memberOf _
  7135. * @since 4.0.0
  7136. * @category Array
  7137. * @param {Array} array The array to modify.
  7138. * @param {Array} values The values to remove.
  7139. * @returns {Array} Returns `array`.
  7140. * @example
  7141. *
  7142. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7143. *
  7144. * _.pullAll(array, ['a', 'c']);
  7145. * console.log(array);
  7146. * // => ['b', 'b']
  7147. */
  7148. function pullAll(array, values) {
  7149. return (array && array.length && values && values.length)
  7150. ? basePullAll(array, values)
  7151. : array;
  7152. }
  7153. /**
  7154. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7155. * invoked for each element of `array` and `values` to generate the criterion
  7156. * by which they're compared. The iteratee is invoked with one argument: (value).
  7157. *
  7158. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7159. *
  7160. * @static
  7161. * @memberOf _
  7162. * @since 4.0.0
  7163. * @category Array
  7164. * @param {Array} array The array to modify.
  7165. * @param {Array} values The values to remove.
  7166. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7167. * @returns {Array} Returns `array`.
  7168. * @example
  7169. *
  7170. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7171. *
  7172. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7173. * console.log(array);
  7174. * // => [{ 'x': 2 }]
  7175. */
  7176. function pullAllBy(array, values, iteratee) {
  7177. return (array && array.length && values && values.length)
  7178. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7179. : array;
  7180. }
  7181. /**
  7182. * This method is like `_.pullAll` except that it accepts `comparator` which
  7183. * is invoked to compare elements of `array` to `values`. The comparator is
  7184. * invoked with two arguments: (arrVal, othVal).
  7185. *
  7186. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7187. *
  7188. * @static
  7189. * @memberOf _
  7190. * @since 4.6.0
  7191. * @category Array
  7192. * @param {Array} array The array to modify.
  7193. * @param {Array} values The values to remove.
  7194. * @param {Function} [comparator] The comparator invoked per element.
  7195. * @returns {Array} Returns `array`.
  7196. * @example
  7197. *
  7198. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7199. *
  7200. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7201. * console.log(array);
  7202. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7203. */
  7204. function pullAllWith(array, values, comparator) {
  7205. return (array && array.length && values && values.length)
  7206. ? basePullAll(array, values, undefined, comparator)
  7207. : array;
  7208. }
  7209. /**
  7210. * Removes elements from `array` corresponding to `indexes` and returns an
  7211. * array of removed elements.
  7212. *
  7213. * **Note:** Unlike `_.at`, this method mutates `array`.
  7214. *
  7215. * @static
  7216. * @memberOf _
  7217. * @since 3.0.0
  7218. * @category Array
  7219. * @param {Array} array The array to modify.
  7220. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7221. * @returns {Array} Returns the new array of removed elements.
  7222. * @example
  7223. *
  7224. * var array = ['a', 'b', 'c', 'd'];
  7225. * var pulled = _.pullAt(array, [1, 3]);
  7226. *
  7227. * console.log(array);
  7228. * // => ['a', 'c']
  7229. *
  7230. * console.log(pulled);
  7231. * // => ['b', 'd']
  7232. */
  7233. var pullAt = flatRest(function(array, indexes) {
  7234. var length = array == null ? 0 : array.length,
  7235. result = baseAt(array, indexes);
  7236. basePullAt(array, arrayMap(indexes, function(index) {
  7237. return isIndex(index, length) ? +index : index;
  7238. }).sort(compareAscending));
  7239. return result;
  7240. });
  7241. /**
  7242. * Removes all elements from `array` that `predicate` returns truthy for
  7243. * and returns an array of the removed elements. The predicate is invoked
  7244. * with three arguments: (value, index, array).
  7245. *
  7246. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7247. * to pull elements from an array by value.
  7248. *
  7249. * @static
  7250. * @memberOf _
  7251. * @since 2.0.0
  7252. * @category Array
  7253. * @param {Array} array The array to modify.
  7254. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7255. * @returns {Array} Returns the new array of removed elements.
  7256. * @example
  7257. *
  7258. * var array = [1, 2, 3, 4];
  7259. * var evens = _.remove(array, function(n) {
  7260. * return n % 2 == 0;
  7261. * });
  7262. *
  7263. * console.log(array);
  7264. * // => [1, 3]
  7265. *
  7266. * console.log(evens);
  7267. * // => [2, 4]
  7268. */
  7269. function remove(array, predicate) {
  7270. var result = [];
  7271. if (!(array && array.length)) {
  7272. return result;
  7273. }
  7274. var index = -1,
  7275. indexes = [],
  7276. length = array.length;
  7277. predicate = getIteratee(predicate, 3);
  7278. while (++index < length) {
  7279. var value = array[index];
  7280. if (predicate(value, index, array)) {
  7281. result.push(value);
  7282. indexes.push(index);
  7283. }
  7284. }
  7285. basePullAt(array, indexes);
  7286. return result;
  7287. }
  7288. /**
  7289. * Reverses `array` so that the first element becomes the last, the second
  7290. * element becomes the second to last, and so on.
  7291. *
  7292. * **Note:** This method mutates `array` and is based on
  7293. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7294. *
  7295. * @static
  7296. * @memberOf _
  7297. * @since 4.0.0
  7298. * @category Array
  7299. * @param {Array} array The array to modify.
  7300. * @returns {Array} Returns `array`.
  7301. * @example
  7302. *
  7303. * var array = [1, 2, 3];
  7304. *
  7305. * _.reverse(array);
  7306. * // => [3, 2, 1]
  7307. *
  7308. * console.log(array);
  7309. * // => [3, 2, 1]
  7310. */
  7311. function reverse(array) {
  7312. return array == null ? array : nativeReverse.call(array);
  7313. }
  7314. /**
  7315. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7316. *
  7317. * **Note:** This method is used instead of
  7318. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7319. * returned.
  7320. *
  7321. * @static
  7322. * @memberOf _
  7323. * @since 3.0.0
  7324. * @category Array
  7325. * @param {Array} array The array to slice.
  7326. * @param {number} [start=0] The start position.
  7327. * @param {number} [end=array.length] The end position.
  7328. * @returns {Array} Returns the slice of `array`.
  7329. */
  7330. function slice(array, start, end) {
  7331. var length = array == null ? 0 : array.length;
  7332. if (!length) {
  7333. return [];
  7334. }
  7335. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7336. start = 0;
  7337. end = length;
  7338. }
  7339. else {
  7340. start = start == null ? 0 : toInteger(start);
  7341. end = end === undefined ? length : toInteger(end);
  7342. }
  7343. return baseSlice(array, start, end);
  7344. }
  7345. /**
  7346. * Uses a binary search to determine the lowest index at which `value`
  7347. * should be inserted into `array` in order to maintain its sort order.
  7348. *
  7349. * @static
  7350. * @memberOf _
  7351. * @since 0.1.0
  7352. * @category Array
  7353. * @param {Array} array The sorted array to inspect.
  7354. * @param {*} value The value to evaluate.
  7355. * @returns {number} Returns the index at which `value` should be inserted
  7356. * into `array`.
  7357. * @example
  7358. *
  7359. * _.sortedIndex([30, 50], 40);
  7360. * // => 1
  7361. */
  7362. function sortedIndex(array, value) {
  7363. return baseSortedIndex(array, value);
  7364. }
  7365. /**
  7366. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7367. * which is invoked for `value` and each element of `array` to compute their
  7368. * sort ranking. The iteratee is invoked with one argument: (value).
  7369. *
  7370. * @static
  7371. * @memberOf _
  7372. * @since 4.0.0
  7373. * @category Array
  7374. * @param {Array} array The sorted array to inspect.
  7375. * @param {*} value The value to evaluate.
  7376. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7377. * @returns {number} Returns the index at which `value` should be inserted
  7378. * into `array`.
  7379. * @example
  7380. *
  7381. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7382. *
  7383. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7384. * // => 0
  7385. *
  7386. * // The `_.property` iteratee shorthand.
  7387. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7388. * // => 0
  7389. */
  7390. function sortedIndexBy(array, value, iteratee) {
  7391. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7392. }
  7393. /**
  7394. * This method is like `_.indexOf` except that it performs a binary
  7395. * search on a sorted `array`.
  7396. *
  7397. * @static
  7398. * @memberOf _
  7399. * @since 4.0.0
  7400. * @category Array
  7401. * @param {Array} array The array to inspect.
  7402. * @param {*} value The value to search for.
  7403. * @returns {number} Returns the index of the matched value, else `-1`.
  7404. * @example
  7405. *
  7406. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7407. * // => 1
  7408. */
  7409. function sortedIndexOf(array, value) {
  7410. var length = array == null ? 0 : array.length;
  7411. if (length) {
  7412. var index = baseSortedIndex(array, value);
  7413. if (index < length && eq(array[index], value)) {
  7414. return index;
  7415. }
  7416. }
  7417. return -1;
  7418. }
  7419. /**
  7420. * This method is like `_.sortedIndex` except that it returns the highest
  7421. * index at which `value` should be inserted into `array` in order to
  7422. * maintain its sort order.
  7423. *
  7424. * @static
  7425. * @memberOf _
  7426. * @since 3.0.0
  7427. * @category Array
  7428. * @param {Array} array The sorted array to inspect.
  7429. * @param {*} value The value to evaluate.
  7430. * @returns {number} Returns the index at which `value` should be inserted
  7431. * into `array`.
  7432. * @example
  7433. *
  7434. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7435. * // => 4
  7436. */
  7437. function sortedLastIndex(array, value) {
  7438. return baseSortedIndex(array, value, true);
  7439. }
  7440. /**
  7441. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7442. * which is invoked for `value` and each element of `array` to compute their
  7443. * sort ranking. The iteratee is invoked with one argument: (value).
  7444. *
  7445. * @static
  7446. * @memberOf _
  7447. * @since 4.0.0
  7448. * @category Array
  7449. * @param {Array} array The sorted array to inspect.
  7450. * @param {*} value The value to evaluate.
  7451. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7452. * @returns {number} Returns the index at which `value` should be inserted
  7453. * into `array`.
  7454. * @example
  7455. *
  7456. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7457. *
  7458. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7459. * // => 1
  7460. *
  7461. * // The `_.property` iteratee shorthand.
  7462. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7463. * // => 1
  7464. */
  7465. function sortedLastIndexBy(array, value, iteratee) {
  7466. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7467. }
  7468. /**
  7469. * This method is like `_.lastIndexOf` except that it performs a binary
  7470. * search on a sorted `array`.
  7471. *
  7472. * @static
  7473. * @memberOf _
  7474. * @since 4.0.0
  7475. * @category Array
  7476. * @param {Array} array The array to inspect.
  7477. * @param {*} value The value to search for.
  7478. * @returns {number} Returns the index of the matched value, else `-1`.
  7479. * @example
  7480. *
  7481. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7482. * // => 3
  7483. */
  7484. function sortedLastIndexOf(array, value) {
  7485. var length = array == null ? 0 : array.length;
  7486. if (length) {
  7487. var index = baseSortedIndex(array, value, true) - 1;
  7488. if (eq(array[index], value)) {
  7489. return index;
  7490. }
  7491. }
  7492. return -1;
  7493. }
  7494. /**
  7495. * This method is like `_.uniq` except that it's designed and optimized
  7496. * for sorted arrays.
  7497. *
  7498. * @static
  7499. * @memberOf _
  7500. * @since 4.0.0
  7501. * @category Array
  7502. * @param {Array} array The array to inspect.
  7503. * @returns {Array} Returns the new duplicate free array.
  7504. * @example
  7505. *
  7506. * _.sortedUniq([1, 1, 2]);
  7507. * // => [1, 2]
  7508. */
  7509. function sortedUniq(array) {
  7510. return (array && array.length)
  7511. ? baseSortedUniq(array)
  7512. : [];
  7513. }
  7514. /**
  7515. * This method is like `_.uniqBy` except that it's designed and optimized
  7516. * for sorted arrays.
  7517. *
  7518. * @static
  7519. * @memberOf _
  7520. * @since 4.0.0
  7521. * @category Array
  7522. * @param {Array} array The array to inspect.
  7523. * @param {Function} [iteratee] The iteratee invoked per element.
  7524. * @returns {Array} Returns the new duplicate free array.
  7525. * @example
  7526. *
  7527. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7528. * // => [1.1, 2.3]
  7529. */
  7530. function sortedUniqBy(array, iteratee) {
  7531. return (array && array.length)
  7532. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7533. : [];
  7534. }
  7535. /**
  7536. * Gets all but the first element of `array`.
  7537. *
  7538. * @static
  7539. * @memberOf _
  7540. * @since 4.0.0
  7541. * @category Array
  7542. * @param {Array} array The array to query.
  7543. * @returns {Array} Returns the slice of `array`.
  7544. * @example
  7545. *
  7546. * _.tail([1, 2, 3]);
  7547. * // => [2, 3]
  7548. */
  7549. function tail(array) {
  7550. var length = array == null ? 0 : array.length;
  7551. return length ? baseSlice(array, 1, length) : [];
  7552. }
  7553. /**
  7554. * Creates a slice of `array` with `n` elements taken from the beginning.
  7555. *
  7556. * @static
  7557. * @memberOf _
  7558. * @since 0.1.0
  7559. * @category Array
  7560. * @param {Array} array The array to query.
  7561. * @param {number} [n=1] The number of elements to take.
  7562. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7563. * @returns {Array} Returns the slice of `array`.
  7564. * @example
  7565. *
  7566. * _.take([1, 2, 3]);
  7567. * // => [1]
  7568. *
  7569. * _.take([1, 2, 3], 2);
  7570. * // => [1, 2]
  7571. *
  7572. * _.take([1, 2, 3], 5);
  7573. * // => [1, 2, 3]
  7574. *
  7575. * _.take([1, 2, 3], 0);
  7576. * // => []
  7577. */
  7578. function take(array, n, guard) {
  7579. if (!(array && array.length)) {
  7580. return [];
  7581. }
  7582. n = (guard || n === undefined) ? 1 : toInteger(n);
  7583. return baseSlice(array, 0, n < 0 ? 0 : n);
  7584. }
  7585. /**
  7586. * Creates a slice of `array` with `n` elements taken from the end.
  7587. *
  7588. * @static
  7589. * @memberOf _
  7590. * @since 3.0.0
  7591. * @category Array
  7592. * @param {Array} array The array to query.
  7593. * @param {number} [n=1] The number of elements to take.
  7594. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7595. * @returns {Array} Returns the slice of `array`.
  7596. * @example
  7597. *
  7598. * _.takeRight([1, 2, 3]);
  7599. * // => [3]
  7600. *
  7601. * _.takeRight([1, 2, 3], 2);
  7602. * // => [2, 3]
  7603. *
  7604. * _.takeRight([1, 2, 3], 5);
  7605. * // => [1, 2, 3]
  7606. *
  7607. * _.takeRight([1, 2, 3], 0);
  7608. * // => []
  7609. */
  7610. function takeRight(array, n, guard) {
  7611. var length = array == null ? 0 : array.length;
  7612. if (!length) {
  7613. return [];
  7614. }
  7615. n = (guard || n === undefined) ? 1 : toInteger(n);
  7616. n = length - n;
  7617. return baseSlice(array, n < 0 ? 0 : n, length);
  7618. }
  7619. /**
  7620. * Creates a slice of `array` with elements taken from the end. Elements are
  7621. * taken until `predicate` returns falsey. The predicate is invoked with
  7622. * three arguments: (value, index, array).
  7623. *
  7624. * @static
  7625. * @memberOf _
  7626. * @since 3.0.0
  7627. * @category Array
  7628. * @param {Array} array The array to query.
  7629. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7630. * @returns {Array} Returns the slice of `array`.
  7631. * @example
  7632. *
  7633. * var users = [
  7634. * { 'user': 'barney', 'active': true },
  7635. * { 'user': 'fred', 'active': false },
  7636. * { 'user': 'pebbles', 'active': false }
  7637. * ];
  7638. *
  7639. * _.takeRightWhile(users, function(o) { return !o.active; });
  7640. * // => objects for ['fred', 'pebbles']
  7641. *
  7642. * // The `_.matches` iteratee shorthand.
  7643. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7644. * // => objects for ['pebbles']
  7645. *
  7646. * // The `_.matchesProperty` iteratee shorthand.
  7647. * _.takeRightWhile(users, ['active', false]);
  7648. * // => objects for ['fred', 'pebbles']
  7649. *
  7650. * // The `_.property` iteratee shorthand.
  7651. * _.takeRightWhile(users, 'active');
  7652. * // => []
  7653. */
  7654. function takeRightWhile(array, predicate) {
  7655. return (array && array.length)
  7656. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7657. : [];
  7658. }
  7659. /**
  7660. * Creates a slice of `array` with elements taken from the beginning. Elements
  7661. * are taken until `predicate` returns falsey. The predicate is invoked with
  7662. * three arguments: (value, index, array).
  7663. *
  7664. * @static
  7665. * @memberOf _
  7666. * @since 3.0.0
  7667. * @category Array
  7668. * @param {Array} array The array to query.
  7669. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7670. * @returns {Array} Returns the slice of `array`.
  7671. * @example
  7672. *
  7673. * var users = [
  7674. * { 'user': 'barney', 'active': false },
  7675. * { 'user': 'fred', 'active': false },
  7676. * { 'user': 'pebbles', 'active': true }
  7677. * ];
  7678. *
  7679. * _.takeWhile(users, function(o) { return !o.active; });
  7680. * // => objects for ['barney', 'fred']
  7681. *
  7682. * // The `_.matches` iteratee shorthand.
  7683. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7684. * // => objects for ['barney']
  7685. *
  7686. * // The `_.matchesProperty` iteratee shorthand.
  7687. * _.takeWhile(users, ['active', false]);
  7688. * // => objects for ['barney', 'fred']
  7689. *
  7690. * // The `_.property` iteratee shorthand.
  7691. * _.takeWhile(users, 'active');
  7692. * // => []
  7693. */
  7694. function takeWhile(array, predicate) {
  7695. return (array && array.length)
  7696. ? baseWhile(array, getIteratee(predicate, 3))
  7697. : [];
  7698. }
  7699. /**
  7700. * Creates an array of unique values, in order, from all given arrays using
  7701. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7702. * for equality comparisons.
  7703. *
  7704. * @static
  7705. * @memberOf _
  7706. * @since 0.1.0
  7707. * @category Array
  7708. * @param {...Array} [arrays] The arrays to inspect.
  7709. * @returns {Array} Returns the new array of combined values.
  7710. * @example
  7711. *
  7712. * _.union([2], [1, 2]);
  7713. * // => [2, 1]
  7714. */
  7715. var union = baseRest(function(arrays) {
  7716. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7717. });
  7718. /**
  7719. * This method is like `_.union` except that it accepts `iteratee` which is
  7720. * invoked for each element of each `arrays` to generate the criterion by
  7721. * which uniqueness is computed. Result values are chosen from the first
  7722. * array in which the value occurs. The iteratee is invoked with one argument:
  7723. * (value).
  7724. *
  7725. * @static
  7726. * @memberOf _
  7727. * @since 4.0.0
  7728. * @category Array
  7729. * @param {...Array} [arrays] The arrays to inspect.
  7730. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7731. * @returns {Array} Returns the new array of combined values.
  7732. * @example
  7733. *
  7734. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7735. * // => [2.1, 1.2]
  7736. *
  7737. * // The `_.property` iteratee shorthand.
  7738. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7739. * // => [{ 'x': 1 }, { 'x': 2 }]
  7740. */
  7741. var unionBy = baseRest(function(arrays) {
  7742. var iteratee = last(arrays);
  7743. if (isArrayLikeObject(iteratee)) {
  7744. iteratee = undefined;
  7745. }
  7746. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7747. });
  7748. /**
  7749. * This method is like `_.union` except that it accepts `comparator` which
  7750. * is invoked to compare elements of `arrays`. Result values are chosen from
  7751. * the first array in which the value occurs. The comparator is invoked
  7752. * with two arguments: (arrVal, othVal).
  7753. *
  7754. * @static
  7755. * @memberOf _
  7756. * @since 4.0.0
  7757. * @category Array
  7758. * @param {...Array} [arrays] The arrays to inspect.
  7759. * @param {Function} [comparator] The comparator invoked per element.
  7760. * @returns {Array} Returns the new array of combined values.
  7761. * @example
  7762. *
  7763. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7764. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7765. *
  7766. * _.unionWith(objects, others, _.isEqual);
  7767. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7768. */
  7769. var unionWith = baseRest(function(arrays) {
  7770. var comparator = last(arrays);
  7771. comparator = typeof comparator == 'function' ? comparator : undefined;
  7772. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7773. });
  7774. /**
  7775. * Creates a duplicate-free version of an array, using
  7776. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7777. * for equality comparisons, in which only the first occurrence of each element
  7778. * is kept. The order of result values is determined by the order they occur
  7779. * in the array.
  7780. *
  7781. * @static
  7782. * @memberOf _
  7783. * @since 0.1.0
  7784. * @category Array
  7785. * @param {Array} array The array to inspect.
  7786. * @returns {Array} Returns the new duplicate free array.
  7787. * @example
  7788. *
  7789. * _.uniq([2, 1, 2]);
  7790. * // => [2, 1]
  7791. */
  7792. function uniq(array) {
  7793. return (array && array.length) ? baseUniq(array) : [];
  7794. }
  7795. /**
  7796. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7797. * invoked for each element in `array` to generate the criterion by which
  7798. * uniqueness is computed. The order of result values is determined by the
  7799. * order they occur in the array. The iteratee is invoked with one argument:
  7800. * (value).
  7801. *
  7802. * @static
  7803. * @memberOf _
  7804. * @since 4.0.0
  7805. * @category Array
  7806. * @param {Array} array The array to inspect.
  7807. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7808. * @returns {Array} Returns the new duplicate free array.
  7809. * @example
  7810. *
  7811. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7812. * // => [2.1, 1.2]
  7813. *
  7814. * // The `_.property` iteratee shorthand.
  7815. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7816. * // => [{ 'x': 1 }, { 'x': 2 }]
  7817. */
  7818. function uniqBy(array, iteratee) {
  7819. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7820. }
  7821. /**
  7822. * This method is like `_.uniq` except that it accepts `comparator` which
  7823. * is invoked to compare elements of `array`. The order of result values is
  7824. * determined by the order they occur in the array.The comparator is invoked
  7825. * with two arguments: (arrVal, othVal).
  7826. *
  7827. * @static
  7828. * @memberOf _
  7829. * @since 4.0.0
  7830. * @category Array
  7831. * @param {Array} array The array to inspect.
  7832. * @param {Function} [comparator] The comparator invoked per element.
  7833. * @returns {Array} Returns the new duplicate free array.
  7834. * @example
  7835. *
  7836. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7837. *
  7838. * _.uniqWith(objects, _.isEqual);
  7839. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7840. */
  7841. function uniqWith(array, comparator) {
  7842. comparator = typeof comparator == 'function' ? comparator : undefined;
  7843. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7844. }
  7845. /**
  7846. * This method is like `_.zip` except that it accepts an array of grouped
  7847. * elements and creates an array regrouping the elements to their pre-zip
  7848. * configuration.
  7849. *
  7850. * @static
  7851. * @memberOf _
  7852. * @since 1.2.0
  7853. * @category Array
  7854. * @param {Array} array The array of grouped elements to process.
  7855. * @returns {Array} Returns the new array of regrouped elements.
  7856. * @example
  7857. *
  7858. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7859. * // => [['a', 1, true], ['b', 2, false]]
  7860. *
  7861. * _.unzip(zipped);
  7862. * // => [['a', 'b'], [1, 2], [true, false]]
  7863. */
  7864. function unzip(array) {
  7865. if (!(array && array.length)) {
  7866. return [];
  7867. }
  7868. var length = 0;
  7869. array = arrayFilter(array, function(group) {
  7870. if (isArrayLikeObject(group)) {
  7871. length = nativeMax(group.length, length);
  7872. return true;
  7873. }
  7874. });
  7875. return baseTimes(length, function(index) {
  7876. return arrayMap(array, baseProperty(index));
  7877. });
  7878. }
  7879. /**
  7880. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7881. * how regrouped values should be combined. The iteratee is invoked with the
  7882. * elements of each group: (...group).
  7883. *
  7884. * @static
  7885. * @memberOf _
  7886. * @since 3.8.0
  7887. * @category Array
  7888. * @param {Array} array The array of grouped elements to process.
  7889. * @param {Function} [iteratee=_.identity] The function to combine
  7890. * regrouped values.
  7891. * @returns {Array} Returns the new array of regrouped elements.
  7892. * @example
  7893. *
  7894. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7895. * // => [[1, 10, 100], [2, 20, 200]]
  7896. *
  7897. * _.unzipWith(zipped, _.add);
  7898. * // => [3, 30, 300]
  7899. */
  7900. function unzipWith(array, iteratee) {
  7901. if (!(array && array.length)) {
  7902. return [];
  7903. }
  7904. var result = unzip(array);
  7905. if (iteratee == null) {
  7906. return result;
  7907. }
  7908. return arrayMap(result, function(group) {
  7909. return apply(iteratee, undefined, group);
  7910. });
  7911. }
  7912. /**
  7913. * Creates an array excluding all given values using
  7914. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7915. * for equality comparisons.
  7916. *
  7917. * **Note:** Unlike `_.pull`, this method returns a new array.
  7918. *
  7919. * @static
  7920. * @memberOf _
  7921. * @since 0.1.0
  7922. * @category Array
  7923. * @param {Array} array The array to inspect.
  7924. * @param {...*} [values] The values to exclude.
  7925. * @returns {Array} Returns the new array of filtered values.
  7926. * @see _.difference, _.xor
  7927. * @example
  7928. *
  7929. * _.without([2, 1, 2, 3], 1, 2);
  7930. * // => [3]
  7931. */
  7932. var without = baseRest(function(array, values) {
  7933. return isArrayLikeObject(array)
  7934. ? baseDifference(array, values)
  7935. : [];
  7936. });
  7937. /**
  7938. * Creates an array of unique values that is the
  7939. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7940. * of the given arrays. The order of result values is determined by the order
  7941. * they occur in the arrays.
  7942. *
  7943. * @static
  7944. * @memberOf _
  7945. * @since 2.4.0
  7946. * @category Array
  7947. * @param {...Array} [arrays] The arrays to inspect.
  7948. * @returns {Array} Returns the new array of filtered values.
  7949. * @see _.difference, _.without
  7950. * @example
  7951. *
  7952. * _.xor([2, 1], [2, 3]);
  7953. * // => [1, 3]
  7954. */
  7955. var xor = baseRest(function(arrays) {
  7956. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7957. });
  7958. /**
  7959. * This method is like `_.xor` except that it accepts `iteratee` which is
  7960. * invoked for each element of each `arrays` to generate the criterion by
  7961. * which by which they're compared. The order of result values is determined
  7962. * by the order they occur in the arrays. The iteratee is invoked with one
  7963. * argument: (value).
  7964. *
  7965. * @static
  7966. * @memberOf _
  7967. * @since 4.0.0
  7968. * @category Array
  7969. * @param {...Array} [arrays] The arrays to inspect.
  7970. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7971. * @returns {Array} Returns the new array of filtered values.
  7972. * @example
  7973. *
  7974. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7975. * // => [1.2, 3.4]
  7976. *
  7977. * // The `_.property` iteratee shorthand.
  7978. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7979. * // => [{ 'x': 2 }]
  7980. */
  7981. var xorBy = baseRest(function(arrays) {
  7982. var iteratee = last(arrays);
  7983. if (isArrayLikeObject(iteratee)) {
  7984. iteratee = undefined;
  7985. }
  7986. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7987. });
  7988. /**
  7989. * This method is like `_.xor` except that it accepts `comparator` which is
  7990. * invoked to compare elements of `arrays`. The order of result values is
  7991. * determined by the order they occur in the arrays. The comparator is invoked
  7992. * with two arguments: (arrVal, othVal).
  7993. *
  7994. * @static
  7995. * @memberOf _
  7996. * @since 4.0.0
  7997. * @category Array
  7998. * @param {...Array} [arrays] The arrays to inspect.
  7999. * @param {Function} [comparator] The comparator invoked per element.
  8000. * @returns {Array} Returns the new array of filtered values.
  8001. * @example
  8002. *
  8003. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8004. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8005. *
  8006. * _.xorWith(objects, others, _.isEqual);
  8007. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8008. */
  8009. var xorWith = baseRest(function(arrays) {
  8010. var comparator = last(arrays);
  8011. comparator = typeof comparator == 'function' ? comparator : undefined;
  8012. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  8013. });
  8014. /**
  8015. * Creates an array of grouped elements, the first of which contains the
  8016. * first elements of the given arrays, the second of which contains the
  8017. * second elements of the given arrays, and so on.
  8018. *
  8019. * @static
  8020. * @memberOf _
  8021. * @since 0.1.0
  8022. * @category Array
  8023. * @param {...Array} [arrays] The arrays to process.
  8024. * @returns {Array} Returns the new array of grouped elements.
  8025. * @example
  8026. *
  8027. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8028. * // => [['a', 1, true], ['b', 2, false]]
  8029. */
  8030. var zip = baseRest(unzip);
  8031. /**
  8032. * This method is like `_.fromPairs` except that it accepts two arrays,
  8033. * one of property identifiers and one of corresponding values.
  8034. *
  8035. * @static
  8036. * @memberOf _
  8037. * @since 0.4.0
  8038. * @category Array
  8039. * @param {Array} [props=[]] The property identifiers.
  8040. * @param {Array} [values=[]] The property values.
  8041. * @returns {Object} Returns the new object.
  8042. * @example
  8043. *
  8044. * _.zipObject(['a', 'b'], [1, 2]);
  8045. * // => { 'a': 1, 'b': 2 }
  8046. */
  8047. function zipObject(props, values) {
  8048. return baseZipObject(props || [], values || [], assignValue);
  8049. }
  8050. /**
  8051. * This method is like `_.zipObject` except that it supports property paths.
  8052. *
  8053. * @static
  8054. * @memberOf _
  8055. * @since 4.1.0
  8056. * @category Array
  8057. * @param {Array} [props=[]] The property identifiers.
  8058. * @param {Array} [values=[]] The property values.
  8059. * @returns {Object} Returns the new object.
  8060. * @example
  8061. *
  8062. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8063. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8064. */
  8065. function zipObjectDeep(props, values) {
  8066. return baseZipObject(props || [], values || [], baseSet);
  8067. }
  8068. /**
  8069. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8070. * how grouped values should be combined. The iteratee is invoked with the
  8071. * elements of each group: (...group).
  8072. *
  8073. * @static
  8074. * @memberOf _
  8075. * @since 3.8.0
  8076. * @category Array
  8077. * @param {...Array} [arrays] The arrays to process.
  8078. * @param {Function} [iteratee=_.identity] The function to combine
  8079. * grouped values.
  8080. * @returns {Array} Returns the new array of grouped elements.
  8081. * @example
  8082. *
  8083. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8084. * return a + b + c;
  8085. * });
  8086. * // => [111, 222]
  8087. */
  8088. var zipWith = baseRest(function(arrays) {
  8089. var length = arrays.length,
  8090. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8091. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8092. return unzipWith(arrays, iteratee);
  8093. });
  8094. /*------------------------------------------------------------------------*/
  8095. /**
  8096. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8097. * chain sequences enabled. The result of such sequences must be unwrapped
  8098. * with `_#value`.
  8099. *
  8100. * @static
  8101. * @memberOf _
  8102. * @since 1.3.0
  8103. * @category Seq
  8104. * @param {*} value The value to wrap.
  8105. * @returns {Object} Returns the new `lodash` wrapper instance.
  8106. * @example
  8107. *
  8108. * var users = [
  8109. * { 'user': 'barney', 'age': 36 },
  8110. * { 'user': 'fred', 'age': 40 },
  8111. * { 'user': 'pebbles', 'age': 1 }
  8112. * ];
  8113. *
  8114. * var youngest = _
  8115. * .chain(users)
  8116. * .sortBy('age')
  8117. * .map(function(o) {
  8118. * return o.user + ' is ' + o.age;
  8119. * })
  8120. * .head()
  8121. * .value();
  8122. * // => 'pebbles is 1'
  8123. */
  8124. function chain(value) {
  8125. var result = lodash(value);
  8126. result.__chain__ = true;
  8127. return result;
  8128. }
  8129. /**
  8130. * This method invokes `interceptor` and returns `value`. The interceptor
  8131. * is invoked with one argument; (value). The purpose of this method is to
  8132. * "tap into" a method chain sequence in order to modify intermediate results.
  8133. *
  8134. * @static
  8135. * @memberOf _
  8136. * @since 0.1.0
  8137. * @category Seq
  8138. * @param {*} value The value to provide to `interceptor`.
  8139. * @param {Function} interceptor The function to invoke.
  8140. * @returns {*} Returns `value`.
  8141. * @example
  8142. *
  8143. * _([1, 2, 3])
  8144. * .tap(function(array) {
  8145. * // Mutate input array.
  8146. * array.pop();
  8147. * })
  8148. * .reverse()
  8149. * .value();
  8150. * // => [2, 1]
  8151. */
  8152. function tap(value, interceptor) {
  8153. interceptor(value);
  8154. return value;
  8155. }
  8156. /**
  8157. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8158. * The purpose of this method is to "pass thru" values replacing intermediate
  8159. * results in a method chain sequence.
  8160. *
  8161. * @static
  8162. * @memberOf _
  8163. * @since 3.0.0
  8164. * @category Seq
  8165. * @param {*} value The value to provide to `interceptor`.
  8166. * @param {Function} interceptor The function to invoke.
  8167. * @returns {*} Returns the result of `interceptor`.
  8168. * @example
  8169. *
  8170. * _(' abc ')
  8171. * .chain()
  8172. * .trim()
  8173. * .thru(function(value) {
  8174. * return [value];
  8175. * })
  8176. * .value();
  8177. * // => ['abc']
  8178. */
  8179. function thru(value, interceptor) {
  8180. return interceptor(value);
  8181. }
  8182. /**
  8183. * This method is the wrapper version of `_.at`.
  8184. *
  8185. * @name at
  8186. * @memberOf _
  8187. * @since 1.0.0
  8188. * @category Seq
  8189. * @param {...(string|string[])} [paths] The property paths to pick.
  8190. * @returns {Object} Returns the new `lodash` wrapper instance.
  8191. * @example
  8192. *
  8193. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8194. *
  8195. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8196. * // => [3, 4]
  8197. */
  8198. var wrapperAt = flatRest(function(paths) {
  8199. var length = paths.length,
  8200. start = length ? paths[0] : 0,
  8201. value = this.__wrapped__,
  8202. interceptor = function(object) { return baseAt(object, paths); };
  8203. if (length > 1 || this.__actions__.length ||
  8204. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8205. return this.thru(interceptor);
  8206. }
  8207. value = value.slice(start, +start + (length ? 1 : 0));
  8208. value.__actions__.push({
  8209. 'func': thru,
  8210. 'args': [interceptor],
  8211. 'thisArg': undefined
  8212. });
  8213. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8214. if (length && !array.length) {
  8215. array.push(undefined);
  8216. }
  8217. return array;
  8218. });
  8219. });
  8220. /**
  8221. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8222. *
  8223. * @name chain
  8224. * @memberOf _
  8225. * @since 0.1.0
  8226. * @category Seq
  8227. * @returns {Object} Returns the new `lodash` wrapper instance.
  8228. * @example
  8229. *
  8230. * var users = [
  8231. * { 'user': 'barney', 'age': 36 },
  8232. * { 'user': 'fred', 'age': 40 }
  8233. * ];
  8234. *
  8235. * // A sequence without explicit chaining.
  8236. * _(users).head();
  8237. * // => { 'user': 'barney', 'age': 36 }
  8238. *
  8239. * // A sequence with explicit chaining.
  8240. * _(users)
  8241. * .chain()
  8242. * .head()
  8243. * .pick('user')
  8244. * .value();
  8245. * // => { 'user': 'barney' }
  8246. */
  8247. function wrapperChain() {
  8248. return chain(this);
  8249. }
  8250. /**
  8251. * Executes the chain sequence and returns the wrapped result.
  8252. *
  8253. * @name commit
  8254. * @memberOf _
  8255. * @since 3.2.0
  8256. * @category Seq
  8257. * @returns {Object} Returns the new `lodash` wrapper instance.
  8258. * @example
  8259. *
  8260. * var array = [1, 2];
  8261. * var wrapped = _(array).push(3);
  8262. *
  8263. * console.log(array);
  8264. * // => [1, 2]
  8265. *
  8266. * wrapped = wrapped.commit();
  8267. * console.log(array);
  8268. * // => [1, 2, 3]
  8269. *
  8270. * wrapped.last();
  8271. * // => 3
  8272. *
  8273. * console.log(array);
  8274. * // => [1, 2, 3]
  8275. */
  8276. function wrapperCommit() {
  8277. return new LodashWrapper(this.value(), this.__chain__);
  8278. }
  8279. /**
  8280. * Gets the next value on a wrapped object following the
  8281. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8282. *
  8283. * @name next
  8284. * @memberOf _
  8285. * @since 4.0.0
  8286. * @category Seq
  8287. * @returns {Object} Returns the next iterator value.
  8288. * @example
  8289. *
  8290. * var wrapped = _([1, 2]);
  8291. *
  8292. * wrapped.next();
  8293. * // => { 'done': false, 'value': 1 }
  8294. *
  8295. * wrapped.next();
  8296. * // => { 'done': false, 'value': 2 }
  8297. *
  8298. * wrapped.next();
  8299. * // => { 'done': true, 'value': undefined }
  8300. */
  8301. function wrapperNext() {
  8302. if (this.__values__ === undefined) {
  8303. this.__values__ = toArray(this.value());
  8304. }
  8305. var done = this.__index__ >= this.__values__.length,
  8306. value = done ? undefined : this.__values__[this.__index__++];
  8307. return { 'done': done, 'value': value };
  8308. }
  8309. /**
  8310. * Enables the wrapper to be iterable.
  8311. *
  8312. * @name Symbol.iterator
  8313. * @memberOf _
  8314. * @since 4.0.0
  8315. * @category Seq
  8316. * @returns {Object} Returns the wrapper object.
  8317. * @example
  8318. *
  8319. * var wrapped = _([1, 2]);
  8320. *
  8321. * wrapped[Symbol.iterator]() === wrapped;
  8322. * // => true
  8323. *
  8324. * Array.from(wrapped);
  8325. * // => [1, 2]
  8326. */
  8327. function wrapperToIterator() {
  8328. return this;
  8329. }
  8330. /**
  8331. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8332. *
  8333. * @name plant
  8334. * @memberOf _
  8335. * @since 3.2.0
  8336. * @category Seq
  8337. * @param {*} value The value to plant.
  8338. * @returns {Object} Returns the new `lodash` wrapper instance.
  8339. * @example
  8340. *
  8341. * function square(n) {
  8342. * return n * n;
  8343. * }
  8344. *
  8345. * var wrapped = _([1, 2]).map(square);
  8346. * var other = wrapped.plant([3, 4]);
  8347. *
  8348. * other.value();
  8349. * // => [9, 16]
  8350. *
  8351. * wrapped.value();
  8352. * // => [1, 4]
  8353. */
  8354. function wrapperPlant(value) {
  8355. var result,
  8356. parent = this;
  8357. while (parent instanceof baseLodash) {
  8358. var clone = wrapperClone(parent);
  8359. clone.__index__ = 0;
  8360. clone.__values__ = undefined;
  8361. if (result) {
  8362. previous.__wrapped__ = clone;
  8363. } else {
  8364. result = clone;
  8365. }
  8366. var previous = clone;
  8367. parent = parent.__wrapped__;
  8368. }
  8369. previous.__wrapped__ = value;
  8370. return result;
  8371. }
  8372. /**
  8373. * This method is the wrapper version of `_.reverse`.
  8374. *
  8375. * **Note:** This method mutates the wrapped array.
  8376. *
  8377. * @name reverse
  8378. * @memberOf _
  8379. * @since 0.1.0
  8380. * @category Seq
  8381. * @returns {Object} Returns the new `lodash` wrapper instance.
  8382. * @example
  8383. *
  8384. * var array = [1, 2, 3];
  8385. *
  8386. * _(array).reverse().value()
  8387. * // => [3, 2, 1]
  8388. *
  8389. * console.log(array);
  8390. * // => [3, 2, 1]
  8391. */
  8392. function wrapperReverse() {
  8393. var value = this.__wrapped__;
  8394. if (value instanceof LazyWrapper) {
  8395. var wrapped = value;
  8396. if (this.__actions__.length) {
  8397. wrapped = new LazyWrapper(this);
  8398. }
  8399. wrapped = wrapped.reverse();
  8400. wrapped.__actions__.push({
  8401. 'func': thru,
  8402. 'args': [reverse],
  8403. 'thisArg': undefined
  8404. });
  8405. return new LodashWrapper(wrapped, this.__chain__);
  8406. }
  8407. return this.thru(reverse);
  8408. }
  8409. /**
  8410. * Executes the chain sequence to resolve the unwrapped value.
  8411. *
  8412. * @name value
  8413. * @memberOf _
  8414. * @since 0.1.0
  8415. * @alias toJSON, valueOf
  8416. * @category Seq
  8417. * @returns {*} Returns the resolved unwrapped value.
  8418. * @example
  8419. *
  8420. * _([1, 2, 3]).value();
  8421. * // => [1, 2, 3]
  8422. */
  8423. function wrapperValue() {
  8424. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8425. }
  8426. /*------------------------------------------------------------------------*/
  8427. /**
  8428. * Creates an object composed of keys generated from the results of running
  8429. * each element of `collection` thru `iteratee`. The corresponding value of
  8430. * each key is the number of times the key was returned by `iteratee`. The
  8431. * iteratee is invoked with one argument: (value).
  8432. *
  8433. * @static
  8434. * @memberOf _
  8435. * @since 0.5.0
  8436. * @category Collection
  8437. * @param {Array|Object} collection The collection to iterate over.
  8438. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8439. * @returns {Object} Returns the composed aggregate object.
  8440. * @example
  8441. *
  8442. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8443. * // => { '4': 1, '6': 2 }
  8444. *
  8445. * // The `_.property` iteratee shorthand.
  8446. * _.countBy(['one', 'two', 'three'], 'length');
  8447. * // => { '3': 2, '5': 1 }
  8448. */
  8449. var countBy = createAggregator(function(result, value, key) {
  8450. if (hasOwnProperty.call(result, key)) {
  8451. ++result[key];
  8452. } else {
  8453. baseAssignValue(result, key, 1);
  8454. }
  8455. });
  8456. /**
  8457. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8458. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8459. * invoked with three arguments: (value, index|key, collection).
  8460. *
  8461. * **Note:** This method returns `true` for
  8462. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8463. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8464. * elements of empty collections.
  8465. *
  8466. * @static
  8467. * @memberOf _
  8468. * @since 0.1.0
  8469. * @category Collection
  8470. * @param {Array|Object} collection The collection to iterate over.
  8471. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8472. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8473. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8474. * else `false`.
  8475. * @example
  8476. *
  8477. * _.every([true, 1, null, 'yes'], Boolean);
  8478. * // => false
  8479. *
  8480. * var users = [
  8481. * { 'user': 'barney', 'age': 36, 'active': false },
  8482. * { 'user': 'fred', 'age': 40, 'active': false }
  8483. * ];
  8484. *
  8485. * // The `_.matches` iteratee shorthand.
  8486. * _.every(users, { 'user': 'barney', 'active': false });
  8487. * // => false
  8488. *
  8489. * // The `_.matchesProperty` iteratee shorthand.
  8490. * _.every(users, ['active', false]);
  8491. * // => true
  8492. *
  8493. * // The `_.property` iteratee shorthand.
  8494. * _.every(users, 'active');
  8495. * // => false
  8496. */
  8497. function every(collection, predicate, guard) {
  8498. var func = isArray(collection) ? arrayEvery : baseEvery;
  8499. if (guard && isIterateeCall(collection, predicate, guard)) {
  8500. predicate = undefined;
  8501. }
  8502. return func(collection, getIteratee(predicate, 3));
  8503. }
  8504. /**
  8505. * Iterates over elements of `collection`, returning an array of all elements
  8506. * `predicate` returns truthy for. The predicate is invoked with three
  8507. * arguments: (value, index|key, collection).
  8508. *
  8509. * **Note:** Unlike `_.remove`, this method returns a new array.
  8510. *
  8511. * @static
  8512. * @memberOf _
  8513. * @since 0.1.0
  8514. * @category Collection
  8515. * @param {Array|Object} collection The collection to iterate over.
  8516. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8517. * @returns {Array} Returns the new filtered array.
  8518. * @see _.reject
  8519. * @example
  8520. *
  8521. * var users = [
  8522. * { 'user': 'barney', 'age': 36, 'active': true },
  8523. * { 'user': 'fred', 'age': 40, 'active': false }
  8524. * ];
  8525. *
  8526. * _.filter(users, function(o) { return !o.active; });
  8527. * // => objects for ['fred']
  8528. *
  8529. * // The `_.matches` iteratee shorthand.
  8530. * _.filter(users, { 'age': 36, 'active': true });
  8531. * // => objects for ['barney']
  8532. *
  8533. * // The `_.matchesProperty` iteratee shorthand.
  8534. * _.filter(users, ['active', false]);
  8535. * // => objects for ['fred']
  8536. *
  8537. * // The `_.property` iteratee shorthand.
  8538. * _.filter(users, 'active');
  8539. * // => objects for ['barney']
  8540. *
  8541. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  8542. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  8543. * // => objects for ['fred', 'barney']
  8544. */
  8545. function filter(collection, predicate) {
  8546. var func = isArray(collection) ? arrayFilter : baseFilter;
  8547. return func(collection, getIteratee(predicate, 3));
  8548. }
  8549. /**
  8550. * Iterates over elements of `collection`, returning the first element
  8551. * `predicate` returns truthy for. The predicate is invoked with three
  8552. * arguments: (value, index|key, collection).
  8553. *
  8554. * @static
  8555. * @memberOf _
  8556. * @since 0.1.0
  8557. * @category Collection
  8558. * @param {Array|Object} collection The collection to inspect.
  8559. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8560. * @param {number} [fromIndex=0] The index to search from.
  8561. * @returns {*} Returns the matched element, else `undefined`.
  8562. * @example
  8563. *
  8564. * var users = [
  8565. * { 'user': 'barney', 'age': 36, 'active': true },
  8566. * { 'user': 'fred', 'age': 40, 'active': false },
  8567. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8568. * ];
  8569. *
  8570. * _.find(users, function(o) { return o.age < 40; });
  8571. * // => object for 'barney'
  8572. *
  8573. * // The `_.matches` iteratee shorthand.
  8574. * _.find(users, { 'age': 1, 'active': true });
  8575. * // => object for 'pebbles'
  8576. *
  8577. * // The `_.matchesProperty` iteratee shorthand.
  8578. * _.find(users, ['active', false]);
  8579. * // => object for 'fred'
  8580. *
  8581. * // The `_.property` iteratee shorthand.
  8582. * _.find(users, 'active');
  8583. * // => object for 'barney'
  8584. */
  8585. var find = createFind(findIndex);
  8586. /**
  8587. * This method is like `_.find` except that it iterates over elements of
  8588. * `collection` from right to left.
  8589. *
  8590. * @static
  8591. * @memberOf _
  8592. * @since 2.0.0
  8593. * @category Collection
  8594. * @param {Array|Object} collection The collection to inspect.
  8595. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8596. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8597. * @returns {*} Returns the matched element, else `undefined`.
  8598. * @example
  8599. *
  8600. * _.findLast([1, 2, 3, 4], function(n) {
  8601. * return n % 2 == 1;
  8602. * });
  8603. * // => 3
  8604. */
  8605. var findLast = createFind(findLastIndex);
  8606. /**
  8607. * Creates a flattened array of values by running each element in `collection`
  8608. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8609. * with three arguments: (value, index|key, collection).
  8610. *
  8611. * @static
  8612. * @memberOf _
  8613. * @since 4.0.0
  8614. * @category Collection
  8615. * @param {Array|Object} collection The collection to iterate over.
  8616. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8617. * @returns {Array} Returns the new flattened array.
  8618. * @example
  8619. *
  8620. * function duplicate(n) {
  8621. * return [n, n];
  8622. * }
  8623. *
  8624. * _.flatMap([1, 2], duplicate);
  8625. * // => [1, 1, 2, 2]
  8626. */
  8627. function flatMap(collection, iteratee) {
  8628. return baseFlatten(map(collection, iteratee), 1);
  8629. }
  8630. /**
  8631. * This method is like `_.flatMap` except that it recursively flattens the
  8632. * mapped results.
  8633. *
  8634. * @static
  8635. * @memberOf _
  8636. * @since 4.7.0
  8637. * @category Collection
  8638. * @param {Array|Object} collection The collection to iterate over.
  8639. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8640. * @returns {Array} Returns the new flattened array.
  8641. * @example
  8642. *
  8643. * function duplicate(n) {
  8644. * return [[[n, n]]];
  8645. * }
  8646. *
  8647. * _.flatMapDeep([1, 2], duplicate);
  8648. * // => [1, 1, 2, 2]
  8649. */
  8650. function flatMapDeep(collection, iteratee) {
  8651. return baseFlatten(map(collection, iteratee), INFINITY);
  8652. }
  8653. /**
  8654. * This method is like `_.flatMap` except that it recursively flattens the
  8655. * mapped results up to `depth` times.
  8656. *
  8657. * @static
  8658. * @memberOf _
  8659. * @since 4.7.0
  8660. * @category Collection
  8661. * @param {Array|Object} collection The collection to iterate over.
  8662. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8663. * @param {number} [depth=1] The maximum recursion depth.
  8664. * @returns {Array} Returns the new flattened array.
  8665. * @example
  8666. *
  8667. * function duplicate(n) {
  8668. * return [[[n, n]]];
  8669. * }
  8670. *
  8671. * _.flatMapDepth([1, 2], duplicate, 2);
  8672. * // => [[1, 1], [2, 2]]
  8673. */
  8674. function flatMapDepth(collection, iteratee, depth) {
  8675. depth = depth === undefined ? 1 : toInteger(depth);
  8676. return baseFlatten(map(collection, iteratee), depth);
  8677. }
  8678. /**
  8679. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8680. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8681. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8682. *
  8683. * **Note:** As with other "Collections" methods, objects with a "length"
  8684. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8685. * or `_.forOwn` for object iteration.
  8686. *
  8687. * @static
  8688. * @memberOf _
  8689. * @since 0.1.0
  8690. * @alias each
  8691. * @category Collection
  8692. * @param {Array|Object} collection The collection to iterate over.
  8693. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8694. * @returns {Array|Object} Returns `collection`.
  8695. * @see _.forEachRight
  8696. * @example
  8697. *
  8698. * _.forEach([1, 2], function(value) {
  8699. * console.log(value);
  8700. * });
  8701. * // => Logs `1` then `2`.
  8702. *
  8703. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8704. * console.log(key);
  8705. * });
  8706. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8707. */
  8708. function forEach(collection, iteratee) {
  8709. var func = isArray(collection) ? arrayEach : baseEach;
  8710. return func(collection, getIteratee(iteratee, 3));
  8711. }
  8712. /**
  8713. * This method is like `_.forEach` except that it iterates over elements of
  8714. * `collection` from right to left.
  8715. *
  8716. * @static
  8717. * @memberOf _
  8718. * @since 2.0.0
  8719. * @alias eachRight
  8720. * @category Collection
  8721. * @param {Array|Object} collection The collection to iterate over.
  8722. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8723. * @returns {Array|Object} Returns `collection`.
  8724. * @see _.forEach
  8725. * @example
  8726. *
  8727. * _.forEachRight([1, 2], function(value) {
  8728. * console.log(value);
  8729. * });
  8730. * // => Logs `2` then `1`.
  8731. */
  8732. function forEachRight(collection, iteratee) {
  8733. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8734. return func(collection, getIteratee(iteratee, 3));
  8735. }
  8736. /**
  8737. * Creates an object composed of keys generated from the results of running
  8738. * each element of `collection` thru `iteratee`. The order of grouped values
  8739. * is determined by the order they occur in `collection`. The corresponding
  8740. * value of each key is an array of elements responsible for generating the
  8741. * key. The iteratee is invoked with one argument: (value).
  8742. *
  8743. * @static
  8744. * @memberOf _
  8745. * @since 0.1.0
  8746. * @category Collection
  8747. * @param {Array|Object} collection The collection to iterate over.
  8748. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8749. * @returns {Object} Returns the composed aggregate object.
  8750. * @example
  8751. *
  8752. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8753. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8754. *
  8755. * // The `_.property` iteratee shorthand.
  8756. * _.groupBy(['one', 'two', 'three'], 'length');
  8757. * // => { '3': ['one', 'two'], '5': ['three'] }
  8758. */
  8759. var groupBy = createAggregator(function(result, value, key) {
  8760. if (hasOwnProperty.call(result, key)) {
  8761. result[key].push(value);
  8762. } else {
  8763. baseAssignValue(result, key, [value]);
  8764. }
  8765. });
  8766. /**
  8767. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8768. * checked for a substring of `value`, otherwise
  8769. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8770. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8771. * the offset from the end of `collection`.
  8772. *
  8773. * @static
  8774. * @memberOf _
  8775. * @since 0.1.0
  8776. * @category Collection
  8777. * @param {Array|Object|string} collection The collection to inspect.
  8778. * @param {*} value The value to search for.
  8779. * @param {number} [fromIndex=0] The index to search from.
  8780. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8781. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8782. * @example
  8783. *
  8784. * _.includes([1, 2, 3], 1);
  8785. * // => true
  8786. *
  8787. * _.includes([1, 2, 3], 1, 2);
  8788. * // => false
  8789. *
  8790. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8791. * // => true
  8792. *
  8793. * _.includes('abcd', 'bc');
  8794. * // => true
  8795. */
  8796. function includes(collection, value, fromIndex, guard) {
  8797. collection = isArrayLike(collection) ? collection : values(collection);
  8798. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8799. var length = collection.length;
  8800. if (fromIndex < 0) {
  8801. fromIndex = nativeMax(length + fromIndex, 0);
  8802. }
  8803. return isString(collection)
  8804. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8805. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8806. }
  8807. /**
  8808. * Invokes the method at `path` of each element in `collection`, returning
  8809. * an array of the results of each invoked method. Any additional arguments
  8810. * are provided to each invoked method. If `path` is a function, it's invoked
  8811. * for, and `this` bound to, each element in `collection`.
  8812. *
  8813. * @static
  8814. * @memberOf _
  8815. * @since 4.0.0
  8816. * @category Collection
  8817. * @param {Array|Object} collection The collection to iterate over.
  8818. * @param {Array|Function|string} path The path of the method to invoke or
  8819. * the function invoked per iteration.
  8820. * @param {...*} [args] The arguments to invoke each method with.
  8821. * @returns {Array} Returns the array of results.
  8822. * @example
  8823. *
  8824. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8825. * // => [[1, 5, 7], [1, 2, 3]]
  8826. *
  8827. * _.invokeMap([123, 456], String.prototype.split, '');
  8828. * // => [['1', '2', '3'], ['4', '5', '6']]
  8829. */
  8830. var invokeMap = baseRest(function(collection, path, args) {
  8831. var index = -1,
  8832. isFunc = typeof path == 'function',
  8833. result = isArrayLike(collection) ? Array(collection.length) : [];
  8834. baseEach(collection, function(value) {
  8835. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8836. });
  8837. return result;
  8838. });
  8839. /**
  8840. * Creates an object composed of keys generated from the results of running
  8841. * each element of `collection` thru `iteratee`. The corresponding value of
  8842. * each key is the last element responsible for generating the key. The
  8843. * iteratee is invoked with one argument: (value).
  8844. *
  8845. * @static
  8846. * @memberOf _
  8847. * @since 4.0.0
  8848. * @category Collection
  8849. * @param {Array|Object} collection The collection to iterate over.
  8850. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8851. * @returns {Object} Returns the composed aggregate object.
  8852. * @example
  8853. *
  8854. * var array = [
  8855. * { 'dir': 'left', 'code': 97 },
  8856. * { 'dir': 'right', 'code': 100 }
  8857. * ];
  8858. *
  8859. * _.keyBy(array, function(o) {
  8860. * return String.fromCharCode(o.code);
  8861. * });
  8862. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8863. *
  8864. * _.keyBy(array, 'dir');
  8865. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8866. */
  8867. var keyBy = createAggregator(function(result, value, key) {
  8868. baseAssignValue(result, key, value);
  8869. });
  8870. /**
  8871. * Creates an array of values by running each element in `collection` thru
  8872. * `iteratee`. The iteratee is invoked with three arguments:
  8873. * (value, index|key, collection).
  8874. *
  8875. * Many lodash methods are guarded to work as iteratees for methods like
  8876. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8877. *
  8878. * The guarded methods are:
  8879. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8880. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8881. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8882. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8883. *
  8884. * @static
  8885. * @memberOf _
  8886. * @since 0.1.0
  8887. * @category Collection
  8888. * @param {Array|Object} collection The collection to iterate over.
  8889. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8890. * @returns {Array} Returns the new mapped array.
  8891. * @example
  8892. *
  8893. * function square(n) {
  8894. * return n * n;
  8895. * }
  8896. *
  8897. * _.map([4, 8], square);
  8898. * // => [16, 64]
  8899. *
  8900. * _.map({ 'a': 4, 'b': 8 }, square);
  8901. * // => [16, 64] (iteration order is not guaranteed)
  8902. *
  8903. * var users = [
  8904. * { 'user': 'barney' },
  8905. * { 'user': 'fred' }
  8906. * ];
  8907. *
  8908. * // The `_.property` iteratee shorthand.
  8909. * _.map(users, 'user');
  8910. * // => ['barney', 'fred']
  8911. */
  8912. function map(collection, iteratee) {
  8913. var func = isArray(collection) ? arrayMap : baseMap;
  8914. return func(collection, getIteratee(iteratee, 3));
  8915. }
  8916. /**
  8917. * This method is like `_.sortBy` except that it allows specifying the sort
  8918. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8919. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8920. * descending or "asc" for ascending sort order of corresponding values.
  8921. *
  8922. * @static
  8923. * @memberOf _
  8924. * @since 4.0.0
  8925. * @category Collection
  8926. * @param {Array|Object} collection The collection to iterate over.
  8927. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8928. * The iteratees to sort by.
  8929. * @param {string[]} [orders] The sort orders of `iteratees`.
  8930. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8931. * @returns {Array} Returns the new sorted array.
  8932. * @example
  8933. *
  8934. * var users = [
  8935. * { 'user': 'fred', 'age': 48 },
  8936. * { 'user': 'barney', 'age': 34 },
  8937. * { 'user': 'fred', 'age': 40 },
  8938. * { 'user': 'barney', 'age': 36 }
  8939. * ];
  8940. *
  8941. * // Sort by `user` in ascending order and by `age` in descending order.
  8942. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8943. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8944. */
  8945. function orderBy(collection, iteratees, orders, guard) {
  8946. if (collection == null) {
  8947. return [];
  8948. }
  8949. if (!isArray(iteratees)) {
  8950. iteratees = iteratees == null ? [] : [iteratees];
  8951. }
  8952. orders = guard ? undefined : orders;
  8953. if (!isArray(orders)) {
  8954. orders = orders == null ? [] : [orders];
  8955. }
  8956. return baseOrderBy(collection, iteratees, orders);
  8957. }
  8958. /**
  8959. * Creates an array of elements split into two groups, the first of which
  8960. * contains elements `predicate` returns truthy for, the second of which
  8961. * contains elements `predicate` returns falsey for. The predicate is
  8962. * invoked with one argument: (value).
  8963. *
  8964. * @static
  8965. * @memberOf _
  8966. * @since 3.0.0
  8967. * @category Collection
  8968. * @param {Array|Object} collection The collection to iterate over.
  8969. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8970. * @returns {Array} Returns the array of grouped elements.
  8971. * @example
  8972. *
  8973. * var users = [
  8974. * { 'user': 'barney', 'age': 36, 'active': false },
  8975. * { 'user': 'fred', 'age': 40, 'active': true },
  8976. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8977. * ];
  8978. *
  8979. * _.partition(users, function(o) { return o.active; });
  8980. * // => objects for [['fred'], ['barney', 'pebbles']]
  8981. *
  8982. * // The `_.matches` iteratee shorthand.
  8983. * _.partition(users, { 'age': 1, 'active': false });
  8984. * // => objects for [['pebbles'], ['barney', 'fred']]
  8985. *
  8986. * // The `_.matchesProperty` iteratee shorthand.
  8987. * _.partition(users, ['active', false]);
  8988. * // => objects for [['barney', 'pebbles'], ['fred']]
  8989. *
  8990. * // The `_.property` iteratee shorthand.
  8991. * _.partition(users, 'active');
  8992. * // => objects for [['fred'], ['barney', 'pebbles']]
  8993. */
  8994. var partition = createAggregator(function(result, value, key) {
  8995. result[key ? 0 : 1].push(value);
  8996. }, function() { return [[], []]; });
  8997. /**
  8998. * Reduces `collection` to a value which is the accumulated result of running
  8999. * each element in `collection` thru `iteratee`, where each successive
  9000. * invocation is supplied the return value of the previous. If `accumulator`
  9001. * is not given, the first element of `collection` is used as the initial
  9002. * value. The iteratee is invoked with four arguments:
  9003. * (accumulator, value, index|key, collection).
  9004. *
  9005. * Many lodash methods are guarded to work as iteratees for methods like
  9006. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9007. *
  9008. * The guarded methods are:
  9009. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9010. * and `sortBy`
  9011. *
  9012. * @static
  9013. * @memberOf _
  9014. * @since 0.1.0
  9015. * @category Collection
  9016. * @param {Array|Object} collection The collection to iterate over.
  9017. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9018. * @param {*} [accumulator] The initial value.
  9019. * @returns {*} Returns the accumulated value.
  9020. * @see _.reduceRight
  9021. * @example
  9022. *
  9023. * _.reduce([1, 2], function(sum, n) {
  9024. * return sum + n;
  9025. * }, 0);
  9026. * // => 3
  9027. *
  9028. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9029. * (result[value] || (result[value] = [])).push(key);
  9030. * return result;
  9031. * }, {});
  9032. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9033. */
  9034. function reduce(collection, iteratee, accumulator) {
  9035. var func = isArray(collection) ? arrayReduce : baseReduce,
  9036. initAccum = arguments.length < 3;
  9037. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9038. }
  9039. /**
  9040. * This method is like `_.reduce` except that it iterates over elements of
  9041. * `collection` from right to left.
  9042. *
  9043. * @static
  9044. * @memberOf _
  9045. * @since 0.1.0
  9046. * @category Collection
  9047. * @param {Array|Object} collection The collection to iterate over.
  9048. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9049. * @param {*} [accumulator] The initial value.
  9050. * @returns {*} Returns the accumulated value.
  9051. * @see _.reduce
  9052. * @example
  9053. *
  9054. * var array = [[0, 1], [2, 3], [4, 5]];
  9055. *
  9056. * _.reduceRight(array, function(flattened, other) {
  9057. * return flattened.concat(other);
  9058. * }, []);
  9059. * // => [4, 5, 2, 3, 0, 1]
  9060. */
  9061. function reduceRight(collection, iteratee, accumulator) {
  9062. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9063. initAccum = arguments.length < 3;
  9064. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9065. }
  9066. /**
  9067. * The opposite of `_.filter`; this method returns the elements of `collection`
  9068. * that `predicate` does **not** return truthy for.
  9069. *
  9070. * @static
  9071. * @memberOf _
  9072. * @since 0.1.0
  9073. * @category Collection
  9074. * @param {Array|Object} collection The collection to iterate over.
  9075. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9076. * @returns {Array} Returns the new filtered array.
  9077. * @see _.filter
  9078. * @example
  9079. *
  9080. * var users = [
  9081. * { 'user': 'barney', 'age': 36, 'active': false },
  9082. * { 'user': 'fred', 'age': 40, 'active': true }
  9083. * ];
  9084. *
  9085. * _.reject(users, function(o) { return !o.active; });
  9086. * // => objects for ['fred']
  9087. *
  9088. * // The `_.matches` iteratee shorthand.
  9089. * _.reject(users, { 'age': 40, 'active': true });
  9090. * // => objects for ['barney']
  9091. *
  9092. * // The `_.matchesProperty` iteratee shorthand.
  9093. * _.reject(users, ['active', false]);
  9094. * // => objects for ['fred']
  9095. *
  9096. * // The `_.property` iteratee shorthand.
  9097. * _.reject(users, 'active');
  9098. * // => objects for ['barney']
  9099. */
  9100. function reject(collection, predicate) {
  9101. var func = isArray(collection) ? arrayFilter : baseFilter;
  9102. return func(collection, negate(getIteratee(predicate, 3)));
  9103. }
  9104. /**
  9105. * Gets a random element from `collection`.
  9106. *
  9107. * @static
  9108. * @memberOf _
  9109. * @since 2.0.0
  9110. * @category Collection
  9111. * @param {Array|Object} collection The collection to sample.
  9112. * @returns {*} Returns the random element.
  9113. * @example
  9114. *
  9115. * _.sample([1, 2, 3, 4]);
  9116. * // => 2
  9117. */
  9118. function sample(collection) {
  9119. var func = isArray(collection) ? arraySample : baseSample;
  9120. return func(collection);
  9121. }
  9122. /**
  9123. * Gets `n` random elements at unique keys from `collection` up to the
  9124. * size of `collection`.
  9125. *
  9126. * @static
  9127. * @memberOf _
  9128. * @since 4.0.0
  9129. * @category Collection
  9130. * @param {Array|Object} collection The collection to sample.
  9131. * @param {number} [n=1] The number of elements to sample.
  9132. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9133. * @returns {Array} Returns the random elements.
  9134. * @example
  9135. *
  9136. * _.sampleSize([1, 2, 3], 2);
  9137. * // => [3, 1]
  9138. *
  9139. * _.sampleSize([1, 2, 3], 4);
  9140. * // => [2, 3, 1]
  9141. */
  9142. function sampleSize(collection, n, guard) {
  9143. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9144. n = 1;
  9145. } else {
  9146. n = toInteger(n);
  9147. }
  9148. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9149. return func(collection, n);
  9150. }
  9151. /**
  9152. * Creates an array of shuffled values, using a version of the
  9153. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9154. *
  9155. * @static
  9156. * @memberOf _
  9157. * @since 0.1.0
  9158. * @category Collection
  9159. * @param {Array|Object} collection The collection to shuffle.
  9160. * @returns {Array} Returns the new shuffled array.
  9161. * @example
  9162. *
  9163. * _.shuffle([1, 2, 3, 4]);
  9164. * // => [4, 1, 3, 2]
  9165. */
  9166. function shuffle(collection) {
  9167. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9168. return func(collection);
  9169. }
  9170. /**
  9171. * Gets the size of `collection` by returning its length for array-like
  9172. * values or the number of own enumerable string keyed properties for objects.
  9173. *
  9174. * @static
  9175. * @memberOf _
  9176. * @since 0.1.0
  9177. * @category Collection
  9178. * @param {Array|Object|string} collection The collection to inspect.
  9179. * @returns {number} Returns the collection size.
  9180. * @example
  9181. *
  9182. * _.size([1, 2, 3]);
  9183. * // => 3
  9184. *
  9185. * _.size({ 'a': 1, 'b': 2 });
  9186. * // => 2
  9187. *
  9188. * _.size('pebbles');
  9189. * // => 7
  9190. */
  9191. function size(collection) {
  9192. if (collection == null) {
  9193. return 0;
  9194. }
  9195. if (isArrayLike(collection)) {
  9196. return isString(collection) ? stringSize(collection) : collection.length;
  9197. }
  9198. var tag = getTag(collection);
  9199. if (tag == mapTag || tag == setTag) {
  9200. return collection.size;
  9201. }
  9202. return baseKeys(collection).length;
  9203. }
  9204. /**
  9205. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9206. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9207. * invoked with three arguments: (value, index|key, collection).
  9208. *
  9209. * @static
  9210. * @memberOf _
  9211. * @since 0.1.0
  9212. * @category Collection
  9213. * @param {Array|Object} collection The collection to iterate over.
  9214. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9215. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9216. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9217. * else `false`.
  9218. * @example
  9219. *
  9220. * _.some([null, 0, 'yes', false], Boolean);
  9221. * // => true
  9222. *
  9223. * var users = [
  9224. * { 'user': 'barney', 'active': true },
  9225. * { 'user': 'fred', 'active': false }
  9226. * ];
  9227. *
  9228. * // The `_.matches` iteratee shorthand.
  9229. * _.some(users, { 'user': 'barney', 'active': false });
  9230. * // => false
  9231. *
  9232. * // The `_.matchesProperty` iteratee shorthand.
  9233. * _.some(users, ['active', false]);
  9234. * // => true
  9235. *
  9236. * // The `_.property` iteratee shorthand.
  9237. * _.some(users, 'active');
  9238. * // => true
  9239. */
  9240. function some(collection, predicate, guard) {
  9241. var func = isArray(collection) ? arraySome : baseSome;
  9242. if (guard && isIterateeCall(collection, predicate, guard)) {
  9243. predicate = undefined;
  9244. }
  9245. return func(collection, getIteratee(predicate, 3));
  9246. }
  9247. /**
  9248. * Creates an array of elements, sorted in ascending order by the results of
  9249. * running each element in a collection thru each iteratee. This method
  9250. * performs a stable sort, that is, it preserves the original sort order of
  9251. * equal elements. The iteratees are invoked with one argument: (value).
  9252. *
  9253. * @static
  9254. * @memberOf _
  9255. * @since 0.1.0
  9256. * @category Collection
  9257. * @param {Array|Object} collection The collection to iterate over.
  9258. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9259. * The iteratees to sort by.
  9260. * @returns {Array} Returns the new sorted array.
  9261. * @example
  9262. *
  9263. * var users = [
  9264. * { 'user': 'fred', 'age': 48 },
  9265. * { 'user': 'barney', 'age': 36 },
  9266. * { 'user': 'fred', 'age': 30 },
  9267. * { 'user': 'barney', 'age': 34 }
  9268. * ];
  9269. *
  9270. * _.sortBy(users, [function(o) { return o.user; }]);
  9271. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  9272. *
  9273. * _.sortBy(users, ['user', 'age']);
  9274. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  9275. */
  9276. var sortBy = baseRest(function(collection, iteratees) {
  9277. if (collection == null) {
  9278. return [];
  9279. }
  9280. var length = iteratees.length;
  9281. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9282. iteratees = [];
  9283. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9284. iteratees = [iteratees[0]];
  9285. }
  9286. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9287. });
  9288. /*------------------------------------------------------------------------*/
  9289. /**
  9290. * Gets the timestamp of the number of milliseconds that have elapsed since
  9291. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9292. *
  9293. * @static
  9294. * @memberOf _
  9295. * @since 2.4.0
  9296. * @category Date
  9297. * @returns {number} Returns the timestamp.
  9298. * @example
  9299. *
  9300. * _.defer(function(stamp) {
  9301. * console.log(_.now() - stamp);
  9302. * }, _.now());
  9303. * // => Logs the number of milliseconds it took for the deferred invocation.
  9304. */
  9305. var now = ctxNow || function() {
  9306. return root.Date.now();
  9307. };
  9308. /*------------------------------------------------------------------------*/
  9309. /**
  9310. * The opposite of `_.before`; this method creates a function that invokes
  9311. * `func` once it's called `n` or more times.
  9312. *
  9313. * @static
  9314. * @memberOf _
  9315. * @since 0.1.0
  9316. * @category Function
  9317. * @param {number} n The number of calls before `func` is invoked.
  9318. * @param {Function} func The function to restrict.
  9319. * @returns {Function} Returns the new restricted function.
  9320. * @example
  9321. *
  9322. * var saves = ['profile', 'settings'];
  9323. *
  9324. * var done = _.after(saves.length, function() {
  9325. * console.log('done saving!');
  9326. * });
  9327. *
  9328. * _.forEach(saves, function(type) {
  9329. * asyncSave({ 'type': type, 'complete': done });
  9330. * });
  9331. * // => Logs 'done saving!' after the two async saves have completed.
  9332. */
  9333. function after(n, func) {
  9334. if (typeof func != 'function') {
  9335. throw new TypeError(FUNC_ERROR_TEXT);
  9336. }
  9337. n = toInteger(n);
  9338. return function() {
  9339. if (--n < 1) {
  9340. return func.apply(this, arguments);
  9341. }
  9342. };
  9343. }
  9344. /**
  9345. * Creates a function that invokes `func`, with up to `n` arguments,
  9346. * ignoring any additional arguments.
  9347. *
  9348. * @static
  9349. * @memberOf _
  9350. * @since 3.0.0
  9351. * @category Function
  9352. * @param {Function} func The function to cap arguments for.
  9353. * @param {number} [n=func.length] The arity cap.
  9354. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9355. * @returns {Function} Returns the new capped function.
  9356. * @example
  9357. *
  9358. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9359. * // => [6, 8, 10]
  9360. */
  9361. function ary(func, n, guard) {
  9362. n = guard ? undefined : n;
  9363. n = (func && n == null) ? func.length : n;
  9364. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9365. }
  9366. /**
  9367. * Creates a function that invokes `func`, with the `this` binding and arguments
  9368. * of the created function, while it's called less than `n` times. Subsequent
  9369. * calls to the created function return the result of the last `func` invocation.
  9370. *
  9371. * @static
  9372. * @memberOf _
  9373. * @since 3.0.0
  9374. * @category Function
  9375. * @param {number} n The number of calls at which `func` is no longer invoked.
  9376. * @param {Function} func The function to restrict.
  9377. * @returns {Function} Returns the new restricted function.
  9378. * @example
  9379. *
  9380. * jQuery(element).on('click', _.before(5, addContactToList));
  9381. * // => Allows adding up to 4 contacts to the list.
  9382. */
  9383. function before(n, func) {
  9384. var result;
  9385. if (typeof func != 'function') {
  9386. throw new TypeError(FUNC_ERROR_TEXT);
  9387. }
  9388. n = toInteger(n);
  9389. return function() {
  9390. if (--n > 0) {
  9391. result = func.apply(this, arguments);
  9392. }
  9393. if (n <= 1) {
  9394. func = undefined;
  9395. }
  9396. return result;
  9397. };
  9398. }
  9399. /**
  9400. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9401. * and `partials` prepended to the arguments it receives.
  9402. *
  9403. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9404. * may be used as a placeholder for partially applied arguments.
  9405. *
  9406. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9407. * property of bound functions.
  9408. *
  9409. * @static
  9410. * @memberOf _
  9411. * @since 0.1.0
  9412. * @category Function
  9413. * @param {Function} func The function to bind.
  9414. * @param {*} thisArg The `this` binding of `func`.
  9415. * @param {...*} [partials] The arguments to be partially applied.
  9416. * @returns {Function} Returns the new bound function.
  9417. * @example
  9418. *
  9419. * function greet(greeting, punctuation) {
  9420. * return greeting + ' ' + this.user + punctuation;
  9421. * }
  9422. *
  9423. * var object = { 'user': 'fred' };
  9424. *
  9425. * var bound = _.bind(greet, object, 'hi');
  9426. * bound('!');
  9427. * // => 'hi fred!'
  9428. *
  9429. * // Bound with placeholders.
  9430. * var bound = _.bind(greet, object, _, '!');
  9431. * bound('hi');
  9432. * // => 'hi fred!'
  9433. */
  9434. var bind = baseRest(function(func, thisArg, partials) {
  9435. var bitmask = WRAP_BIND_FLAG;
  9436. if (partials.length) {
  9437. var holders = replaceHolders(partials, getHolder(bind));
  9438. bitmask |= WRAP_PARTIAL_FLAG;
  9439. }
  9440. return createWrap(func, bitmask, thisArg, partials, holders);
  9441. });
  9442. /**
  9443. * Creates a function that invokes the method at `object[key]` with `partials`
  9444. * prepended to the arguments it receives.
  9445. *
  9446. * This method differs from `_.bind` by allowing bound functions to reference
  9447. * methods that may be redefined or don't yet exist. See
  9448. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9449. * for more details.
  9450. *
  9451. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9452. * builds, may be used as a placeholder for partially applied arguments.
  9453. *
  9454. * @static
  9455. * @memberOf _
  9456. * @since 0.10.0
  9457. * @category Function
  9458. * @param {Object} object The object to invoke the method on.
  9459. * @param {string} key The key of the method.
  9460. * @param {...*} [partials] The arguments to be partially applied.
  9461. * @returns {Function} Returns the new bound function.
  9462. * @example
  9463. *
  9464. * var object = {
  9465. * 'user': 'fred',
  9466. * 'greet': function(greeting, punctuation) {
  9467. * return greeting + ' ' + this.user + punctuation;
  9468. * }
  9469. * };
  9470. *
  9471. * var bound = _.bindKey(object, 'greet', 'hi');
  9472. * bound('!');
  9473. * // => 'hi fred!'
  9474. *
  9475. * object.greet = function(greeting, punctuation) {
  9476. * return greeting + 'ya ' + this.user + punctuation;
  9477. * };
  9478. *
  9479. * bound('!');
  9480. * // => 'hiya fred!'
  9481. *
  9482. * // Bound with placeholders.
  9483. * var bound = _.bindKey(object, 'greet', _, '!');
  9484. * bound('hi');
  9485. * // => 'hiya fred!'
  9486. */
  9487. var bindKey = baseRest(function(object, key, partials) {
  9488. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9489. if (partials.length) {
  9490. var holders = replaceHolders(partials, getHolder(bindKey));
  9491. bitmask |= WRAP_PARTIAL_FLAG;
  9492. }
  9493. return createWrap(key, bitmask, object, partials, holders);
  9494. });
  9495. /**
  9496. * Creates a function that accepts arguments of `func` and either invokes
  9497. * `func` returning its result, if at least `arity` number of arguments have
  9498. * been provided, or returns a function that accepts the remaining `func`
  9499. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9500. * is not sufficient.
  9501. *
  9502. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9503. * may be used as a placeholder for provided arguments.
  9504. *
  9505. * **Note:** This method doesn't set the "length" property of curried functions.
  9506. *
  9507. * @static
  9508. * @memberOf _
  9509. * @since 2.0.0
  9510. * @category Function
  9511. * @param {Function} func The function to curry.
  9512. * @param {number} [arity=func.length] The arity of `func`.
  9513. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9514. * @returns {Function} Returns the new curried function.
  9515. * @example
  9516. *
  9517. * var abc = function(a, b, c) {
  9518. * return [a, b, c];
  9519. * };
  9520. *
  9521. * var curried = _.curry(abc);
  9522. *
  9523. * curried(1)(2)(3);
  9524. * // => [1, 2, 3]
  9525. *
  9526. * curried(1, 2)(3);
  9527. * // => [1, 2, 3]
  9528. *
  9529. * curried(1, 2, 3);
  9530. * // => [1, 2, 3]
  9531. *
  9532. * // Curried with placeholders.
  9533. * curried(1)(_, 3)(2);
  9534. * // => [1, 2, 3]
  9535. */
  9536. function curry(func, arity, guard) {
  9537. arity = guard ? undefined : arity;
  9538. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9539. result.placeholder = curry.placeholder;
  9540. return result;
  9541. }
  9542. /**
  9543. * This method is like `_.curry` except that arguments are applied to `func`
  9544. * in the manner of `_.partialRight` instead of `_.partial`.
  9545. *
  9546. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9547. * builds, may be used as a placeholder for provided arguments.
  9548. *
  9549. * **Note:** This method doesn't set the "length" property of curried functions.
  9550. *
  9551. * @static
  9552. * @memberOf _
  9553. * @since 3.0.0
  9554. * @category Function
  9555. * @param {Function} func The function to curry.
  9556. * @param {number} [arity=func.length] The arity of `func`.
  9557. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9558. * @returns {Function} Returns the new curried function.
  9559. * @example
  9560. *
  9561. * var abc = function(a, b, c) {
  9562. * return [a, b, c];
  9563. * };
  9564. *
  9565. * var curried = _.curryRight(abc);
  9566. *
  9567. * curried(3)(2)(1);
  9568. * // => [1, 2, 3]
  9569. *
  9570. * curried(2, 3)(1);
  9571. * // => [1, 2, 3]
  9572. *
  9573. * curried(1, 2, 3);
  9574. * // => [1, 2, 3]
  9575. *
  9576. * // Curried with placeholders.
  9577. * curried(3)(1, _)(2);
  9578. * // => [1, 2, 3]
  9579. */
  9580. function curryRight(func, arity, guard) {
  9581. arity = guard ? undefined : arity;
  9582. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9583. result.placeholder = curryRight.placeholder;
  9584. return result;
  9585. }
  9586. /**
  9587. * Creates a debounced function that delays invoking `func` until after `wait`
  9588. * milliseconds have elapsed since the last time the debounced function was
  9589. * invoked. The debounced function comes with a `cancel` method to cancel
  9590. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9591. * Provide `options` to indicate whether `func` should be invoked on the
  9592. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9593. * with the last arguments provided to the debounced function. Subsequent
  9594. * calls to the debounced function return the result of the last `func`
  9595. * invocation.
  9596. *
  9597. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9598. * invoked on the trailing edge of the timeout only if the debounced function
  9599. * is invoked more than once during the `wait` timeout.
  9600. *
  9601. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9602. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9603. *
  9604. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9605. * for details over the differences between `_.debounce` and `_.throttle`.
  9606. *
  9607. * @static
  9608. * @memberOf _
  9609. * @since 0.1.0
  9610. * @category Function
  9611. * @param {Function} func The function to debounce.
  9612. * @param {number} [wait=0] The number of milliseconds to delay.
  9613. * @param {Object} [options={}] The options object.
  9614. * @param {boolean} [options.leading=false]
  9615. * Specify invoking on the leading edge of the timeout.
  9616. * @param {number} [options.maxWait]
  9617. * The maximum time `func` is allowed to be delayed before it's invoked.
  9618. * @param {boolean} [options.trailing=true]
  9619. * Specify invoking on the trailing edge of the timeout.
  9620. * @returns {Function} Returns the new debounced function.
  9621. * @example
  9622. *
  9623. * // Avoid costly calculations while the window size is in flux.
  9624. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9625. *
  9626. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9627. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9628. * 'leading': true,
  9629. * 'trailing': false
  9630. * }));
  9631. *
  9632. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9633. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9634. * var source = new EventSource('/stream');
  9635. * jQuery(source).on('message', debounced);
  9636. *
  9637. * // Cancel the trailing debounced invocation.
  9638. * jQuery(window).on('popstate', debounced.cancel);
  9639. */
  9640. function debounce(func, wait, options) {
  9641. var lastArgs,
  9642. lastThis,
  9643. maxWait,
  9644. result,
  9645. timerId,
  9646. lastCallTime,
  9647. lastInvokeTime = 0,
  9648. leading = false,
  9649. maxing = false,
  9650. trailing = true;
  9651. if (typeof func != 'function') {
  9652. throw new TypeError(FUNC_ERROR_TEXT);
  9653. }
  9654. wait = toNumber(wait) || 0;
  9655. if (isObject(options)) {
  9656. leading = !!options.leading;
  9657. maxing = 'maxWait' in options;
  9658. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9659. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9660. }
  9661. function invokeFunc(time) {
  9662. var args = lastArgs,
  9663. thisArg = lastThis;
  9664. lastArgs = lastThis = undefined;
  9665. lastInvokeTime = time;
  9666. result = func.apply(thisArg, args);
  9667. return result;
  9668. }
  9669. function leadingEdge(time) {
  9670. // Reset any `maxWait` timer.
  9671. lastInvokeTime = time;
  9672. // Start the timer for the trailing edge.
  9673. timerId = setTimeout(timerExpired, wait);
  9674. // Invoke the leading edge.
  9675. return leading ? invokeFunc(time) : result;
  9676. }
  9677. function remainingWait(time) {
  9678. var timeSinceLastCall = time - lastCallTime,
  9679. timeSinceLastInvoke = time - lastInvokeTime,
  9680. timeWaiting = wait - timeSinceLastCall;
  9681. return maxing
  9682. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9683. : timeWaiting;
  9684. }
  9685. function shouldInvoke(time) {
  9686. var timeSinceLastCall = time - lastCallTime,
  9687. timeSinceLastInvoke = time - lastInvokeTime;
  9688. // Either this is the first call, activity has stopped and we're at the
  9689. // trailing edge, the system time has gone backwards and we're treating
  9690. // it as the trailing edge, or we've hit the `maxWait` limit.
  9691. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9692. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9693. }
  9694. function timerExpired() {
  9695. var time = now();
  9696. if (shouldInvoke(time)) {
  9697. return trailingEdge(time);
  9698. }
  9699. // Restart the timer.
  9700. timerId = setTimeout(timerExpired, remainingWait(time));
  9701. }
  9702. function trailingEdge(time) {
  9703. timerId = undefined;
  9704. // Only invoke if we have `lastArgs` which means `func` has been
  9705. // debounced at least once.
  9706. if (trailing && lastArgs) {
  9707. return invokeFunc(time);
  9708. }
  9709. lastArgs = lastThis = undefined;
  9710. return result;
  9711. }
  9712. function cancel() {
  9713. if (timerId !== undefined) {
  9714. clearTimeout(timerId);
  9715. }
  9716. lastInvokeTime = 0;
  9717. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9718. }
  9719. function flush() {
  9720. return timerId === undefined ? result : trailingEdge(now());
  9721. }
  9722. function debounced() {
  9723. var time = now(),
  9724. isInvoking = shouldInvoke(time);
  9725. lastArgs = arguments;
  9726. lastThis = this;
  9727. lastCallTime = time;
  9728. if (isInvoking) {
  9729. if (timerId === undefined) {
  9730. return leadingEdge(lastCallTime);
  9731. }
  9732. if (maxing) {
  9733. // Handle invocations in a tight loop.
  9734. clearTimeout(timerId);
  9735. timerId = setTimeout(timerExpired, wait);
  9736. return invokeFunc(lastCallTime);
  9737. }
  9738. }
  9739. if (timerId === undefined) {
  9740. timerId = setTimeout(timerExpired, wait);
  9741. }
  9742. return result;
  9743. }
  9744. debounced.cancel = cancel;
  9745. debounced.flush = flush;
  9746. return debounced;
  9747. }
  9748. /**
  9749. * Defers invoking the `func` until the current call stack has cleared. Any
  9750. * additional arguments are provided to `func` when it's invoked.
  9751. *
  9752. * @static
  9753. * @memberOf _
  9754. * @since 0.1.0
  9755. * @category Function
  9756. * @param {Function} func The function to defer.
  9757. * @param {...*} [args] The arguments to invoke `func` with.
  9758. * @returns {number} Returns the timer id.
  9759. * @example
  9760. *
  9761. * _.defer(function(text) {
  9762. * console.log(text);
  9763. * }, 'deferred');
  9764. * // => Logs 'deferred' after one millisecond.
  9765. */
  9766. var defer = baseRest(function(func, args) {
  9767. return baseDelay(func, 1, args);
  9768. });
  9769. /**
  9770. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9771. * provided to `func` when it's invoked.
  9772. *
  9773. * @static
  9774. * @memberOf _
  9775. * @since 0.1.0
  9776. * @category Function
  9777. * @param {Function} func The function to delay.
  9778. * @param {number} wait The number of milliseconds to delay invocation.
  9779. * @param {...*} [args] The arguments to invoke `func` with.
  9780. * @returns {number} Returns the timer id.
  9781. * @example
  9782. *
  9783. * _.delay(function(text) {
  9784. * console.log(text);
  9785. * }, 1000, 'later');
  9786. * // => Logs 'later' after one second.
  9787. */
  9788. var delay = baseRest(function(func, wait, args) {
  9789. return baseDelay(func, toNumber(wait) || 0, args);
  9790. });
  9791. /**
  9792. * Creates a function that invokes `func` with arguments reversed.
  9793. *
  9794. * @static
  9795. * @memberOf _
  9796. * @since 4.0.0
  9797. * @category Function
  9798. * @param {Function} func The function to flip arguments for.
  9799. * @returns {Function} Returns the new flipped function.
  9800. * @example
  9801. *
  9802. * var flipped = _.flip(function() {
  9803. * return _.toArray(arguments);
  9804. * });
  9805. *
  9806. * flipped('a', 'b', 'c', 'd');
  9807. * // => ['d', 'c', 'b', 'a']
  9808. */
  9809. function flip(func) {
  9810. return createWrap(func, WRAP_FLIP_FLAG);
  9811. }
  9812. /**
  9813. * Creates a function that memoizes the result of `func`. If `resolver` is
  9814. * provided, it determines the cache key for storing the result based on the
  9815. * arguments provided to the memoized function. By default, the first argument
  9816. * provided to the memoized function is used as the map cache key. The `func`
  9817. * is invoked with the `this` binding of the memoized function.
  9818. *
  9819. * **Note:** The cache is exposed as the `cache` property on the memoized
  9820. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9821. * constructor with one whose instances implement the
  9822. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9823. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9824. *
  9825. * @static
  9826. * @memberOf _
  9827. * @since 0.1.0
  9828. * @category Function
  9829. * @param {Function} func The function to have its output memoized.
  9830. * @param {Function} [resolver] The function to resolve the cache key.
  9831. * @returns {Function} Returns the new memoized function.
  9832. * @example
  9833. *
  9834. * var object = { 'a': 1, 'b': 2 };
  9835. * var other = { 'c': 3, 'd': 4 };
  9836. *
  9837. * var values = _.memoize(_.values);
  9838. * values(object);
  9839. * // => [1, 2]
  9840. *
  9841. * values(other);
  9842. * // => [3, 4]
  9843. *
  9844. * object.a = 2;
  9845. * values(object);
  9846. * // => [1, 2]
  9847. *
  9848. * // Modify the result cache.
  9849. * values.cache.set(object, ['a', 'b']);
  9850. * values(object);
  9851. * // => ['a', 'b']
  9852. *
  9853. * // Replace `_.memoize.Cache`.
  9854. * _.memoize.Cache = WeakMap;
  9855. */
  9856. function memoize(func, resolver) {
  9857. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9858. throw new TypeError(FUNC_ERROR_TEXT);
  9859. }
  9860. var memoized = function() {
  9861. var args = arguments,
  9862. key = resolver ? resolver.apply(this, args) : args[0],
  9863. cache = memoized.cache;
  9864. if (cache.has(key)) {
  9865. return cache.get(key);
  9866. }
  9867. var result = func.apply(this, args);
  9868. memoized.cache = cache.set(key, result) || cache;
  9869. return result;
  9870. };
  9871. memoized.cache = new (memoize.Cache || MapCache);
  9872. return memoized;
  9873. }
  9874. // Expose `MapCache`.
  9875. memoize.Cache = MapCache;
  9876. /**
  9877. * Creates a function that negates the result of the predicate `func`. The
  9878. * `func` predicate is invoked with the `this` binding and arguments of the
  9879. * created function.
  9880. *
  9881. * @static
  9882. * @memberOf _
  9883. * @since 3.0.0
  9884. * @category Function
  9885. * @param {Function} predicate The predicate to negate.
  9886. * @returns {Function} Returns the new negated function.
  9887. * @example
  9888. *
  9889. * function isEven(n) {
  9890. * return n % 2 == 0;
  9891. * }
  9892. *
  9893. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9894. * // => [1, 3, 5]
  9895. */
  9896. function negate(predicate) {
  9897. if (typeof predicate != 'function') {
  9898. throw new TypeError(FUNC_ERROR_TEXT);
  9899. }
  9900. return function() {
  9901. var args = arguments;
  9902. switch (args.length) {
  9903. case 0: return !predicate.call(this);
  9904. case 1: return !predicate.call(this, args[0]);
  9905. case 2: return !predicate.call(this, args[0], args[1]);
  9906. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9907. }
  9908. return !predicate.apply(this, args);
  9909. };
  9910. }
  9911. /**
  9912. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9913. * to the function return the value of the first invocation. The `func` is
  9914. * invoked with the `this` binding and arguments of the created function.
  9915. *
  9916. * @static
  9917. * @memberOf _
  9918. * @since 0.1.0
  9919. * @category Function
  9920. * @param {Function} func The function to restrict.
  9921. * @returns {Function} Returns the new restricted function.
  9922. * @example
  9923. *
  9924. * var initialize = _.once(createApplication);
  9925. * initialize();
  9926. * initialize();
  9927. * // => `createApplication` is invoked once
  9928. */
  9929. function once(func) {
  9930. return before(2, func);
  9931. }
  9932. /**
  9933. * Creates a function that invokes `func` with its arguments transformed.
  9934. *
  9935. * @static
  9936. * @since 4.0.0
  9937. * @memberOf _
  9938. * @category Function
  9939. * @param {Function} func The function to wrap.
  9940. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9941. * The argument transforms.
  9942. * @returns {Function} Returns the new function.
  9943. * @example
  9944. *
  9945. * function doubled(n) {
  9946. * return n * 2;
  9947. * }
  9948. *
  9949. * function square(n) {
  9950. * return n * n;
  9951. * }
  9952. *
  9953. * var func = _.overArgs(function(x, y) {
  9954. * return [x, y];
  9955. * }, [square, doubled]);
  9956. *
  9957. * func(9, 3);
  9958. * // => [81, 6]
  9959. *
  9960. * func(10, 5);
  9961. * // => [100, 10]
  9962. */
  9963. var overArgs = castRest(function(func, transforms) {
  9964. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9965. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9966. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9967. var funcsLength = transforms.length;
  9968. return baseRest(function(args) {
  9969. var index = -1,
  9970. length = nativeMin(args.length, funcsLength);
  9971. while (++index < length) {
  9972. args[index] = transforms[index].call(this, args[index]);
  9973. }
  9974. return apply(func, this, args);
  9975. });
  9976. });
  9977. /**
  9978. * Creates a function that invokes `func` with `partials` prepended to the
  9979. * arguments it receives. This method is like `_.bind` except it does **not**
  9980. * alter the `this` binding.
  9981. *
  9982. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9983. * builds, may be used as a placeholder for partially applied arguments.
  9984. *
  9985. * **Note:** This method doesn't set the "length" property of partially
  9986. * applied functions.
  9987. *
  9988. * @static
  9989. * @memberOf _
  9990. * @since 0.2.0
  9991. * @category Function
  9992. * @param {Function} func The function to partially apply arguments to.
  9993. * @param {...*} [partials] The arguments to be partially applied.
  9994. * @returns {Function} Returns the new partially applied function.
  9995. * @example
  9996. *
  9997. * function greet(greeting, name) {
  9998. * return greeting + ' ' + name;
  9999. * }
  10000. *
  10001. * var sayHelloTo = _.partial(greet, 'hello');
  10002. * sayHelloTo('fred');
  10003. * // => 'hello fred'
  10004. *
  10005. * // Partially applied with placeholders.
  10006. * var greetFred = _.partial(greet, _, 'fred');
  10007. * greetFred('hi');
  10008. * // => 'hi fred'
  10009. */
  10010. var partial = baseRest(function(func, partials) {
  10011. var holders = replaceHolders(partials, getHolder(partial));
  10012. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10013. });
  10014. /**
  10015. * This method is like `_.partial` except that partially applied arguments
  10016. * are appended to the arguments it receives.
  10017. *
  10018. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10019. * builds, may be used as a placeholder for partially applied arguments.
  10020. *
  10021. * **Note:** This method doesn't set the "length" property of partially
  10022. * applied functions.
  10023. *
  10024. * @static
  10025. * @memberOf _
  10026. * @since 1.0.0
  10027. * @category Function
  10028. * @param {Function} func The function to partially apply arguments to.
  10029. * @param {...*} [partials] The arguments to be partially applied.
  10030. * @returns {Function} Returns the new partially applied function.
  10031. * @example
  10032. *
  10033. * function greet(greeting, name) {
  10034. * return greeting + ' ' + name;
  10035. * }
  10036. *
  10037. * var greetFred = _.partialRight(greet, 'fred');
  10038. * greetFred('hi');
  10039. * // => 'hi fred'
  10040. *
  10041. * // Partially applied with placeholders.
  10042. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10043. * sayHelloTo('fred');
  10044. * // => 'hello fred'
  10045. */
  10046. var partialRight = baseRest(function(func, partials) {
  10047. var holders = replaceHolders(partials, getHolder(partialRight));
  10048. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10049. });
  10050. /**
  10051. * Creates a function that invokes `func` with arguments arranged according
  10052. * to the specified `indexes` where the argument value at the first index is
  10053. * provided as the first argument, the argument value at the second index is
  10054. * provided as the second argument, and so on.
  10055. *
  10056. * @static
  10057. * @memberOf _
  10058. * @since 3.0.0
  10059. * @category Function
  10060. * @param {Function} func The function to rearrange arguments for.
  10061. * @param {...(number|number[])} indexes The arranged argument indexes.
  10062. * @returns {Function} Returns the new function.
  10063. * @example
  10064. *
  10065. * var rearged = _.rearg(function(a, b, c) {
  10066. * return [a, b, c];
  10067. * }, [2, 0, 1]);
  10068. *
  10069. * rearged('b', 'c', 'a')
  10070. * // => ['a', 'b', 'c']
  10071. */
  10072. var rearg = flatRest(function(func, indexes) {
  10073. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10074. });
  10075. /**
  10076. * Creates a function that invokes `func` with the `this` binding of the
  10077. * created function and arguments from `start` and beyond provided as
  10078. * an array.
  10079. *
  10080. * **Note:** This method is based on the
  10081. * [rest parameter](https://mdn.io/rest_parameters).
  10082. *
  10083. * @static
  10084. * @memberOf _
  10085. * @since 4.0.0
  10086. * @category Function
  10087. * @param {Function} func The function to apply a rest parameter to.
  10088. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10089. * @returns {Function} Returns the new function.
  10090. * @example
  10091. *
  10092. * var say = _.rest(function(what, names) {
  10093. * return what + ' ' + _.initial(names).join(', ') +
  10094. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10095. * });
  10096. *
  10097. * say('hello', 'fred', 'barney', 'pebbles');
  10098. * // => 'hello fred, barney, & pebbles'
  10099. */
  10100. function rest(func, start) {
  10101. if (typeof func != 'function') {
  10102. throw new TypeError(FUNC_ERROR_TEXT);
  10103. }
  10104. start = start === undefined ? start : toInteger(start);
  10105. return baseRest(func, start);
  10106. }
  10107. /**
  10108. * Creates a function that invokes `func` with the `this` binding of the
  10109. * create function and an array of arguments much like
  10110. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10111. *
  10112. * **Note:** This method is based on the
  10113. * [spread operator](https://mdn.io/spread_operator).
  10114. *
  10115. * @static
  10116. * @memberOf _
  10117. * @since 3.2.0
  10118. * @category Function
  10119. * @param {Function} func The function to spread arguments over.
  10120. * @param {number} [start=0] The start position of the spread.
  10121. * @returns {Function} Returns the new function.
  10122. * @example
  10123. *
  10124. * var say = _.spread(function(who, what) {
  10125. * return who + ' says ' + what;
  10126. * });
  10127. *
  10128. * say(['fred', 'hello']);
  10129. * // => 'fred says hello'
  10130. *
  10131. * var numbers = Promise.all([
  10132. * Promise.resolve(40),
  10133. * Promise.resolve(36)
  10134. * ]);
  10135. *
  10136. * numbers.then(_.spread(function(x, y) {
  10137. * return x + y;
  10138. * }));
  10139. * // => a Promise of 76
  10140. */
  10141. function spread(func, start) {
  10142. if (typeof func != 'function') {
  10143. throw new TypeError(FUNC_ERROR_TEXT);
  10144. }
  10145. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10146. return baseRest(function(args) {
  10147. var array = args[start],
  10148. otherArgs = castSlice(args, 0, start);
  10149. if (array) {
  10150. arrayPush(otherArgs, array);
  10151. }
  10152. return apply(func, this, otherArgs);
  10153. });
  10154. }
  10155. /**
  10156. * Creates a throttled function that only invokes `func` at most once per
  10157. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10158. * method to cancel delayed `func` invocations and a `flush` method to
  10159. * immediately invoke them. Provide `options` to indicate whether `func`
  10160. * should be invoked on the leading and/or trailing edge of the `wait`
  10161. * timeout. The `func` is invoked with the last arguments provided to the
  10162. * throttled function. Subsequent calls to the throttled function return the
  10163. * result of the last `func` invocation.
  10164. *
  10165. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10166. * invoked on the trailing edge of the timeout only if the throttled function
  10167. * is invoked more than once during the `wait` timeout.
  10168. *
  10169. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10170. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10171. *
  10172. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10173. * for details over the differences between `_.throttle` and `_.debounce`.
  10174. *
  10175. * @static
  10176. * @memberOf _
  10177. * @since 0.1.0
  10178. * @category Function
  10179. * @param {Function} func The function to throttle.
  10180. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10181. * @param {Object} [options={}] The options object.
  10182. * @param {boolean} [options.leading=true]
  10183. * Specify invoking on the leading edge of the timeout.
  10184. * @param {boolean} [options.trailing=true]
  10185. * Specify invoking on the trailing edge of the timeout.
  10186. * @returns {Function} Returns the new throttled function.
  10187. * @example
  10188. *
  10189. * // Avoid excessively updating the position while scrolling.
  10190. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10191. *
  10192. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10193. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10194. * jQuery(element).on('click', throttled);
  10195. *
  10196. * // Cancel the trailing throttled invocation.
  10197. * jQuery(window).on('popstate', throttled.cancel);
  10198. */
  10199. function throttle(func, wait, options) {
  10200. var leading = true,
  10201. trailing = true;
  10202. if (typeof func != 'function') {
  10203. throw new TypeError(FUNC_ERROR_TEXT);
  10204. }
  10205. if (isObject(options)) {
  10206. leading = 'leading' in options ? !!options.leading : leading;
  10207. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10208. }
  10209. return debounce(func, wait, {
  10210. 'leading': leading,
  10211. 'maxWait': wait,
  10212. 'trailing': trailing
  10213. });
  10214. }
  10215. /**
  10216. * Creates a function that accepts up to one argument, ignoring any
  10217. * additional arguments.
  10218. *
  10219. * @static
  10220. * @memberOf _
  10221. * @since 4.0.0
  10222. * @category Function
  10223. * @param {Function} func The function to cap arguments for.
  10224. * @returns {Function} Returns the new capped function.
  10225. * @example
  10226. *
  10227. * _.map(['6', '8', '10'], _.unary(parseInt));
  10228. * // => [6, 8, 10]
  10229. */
  10230. function unary(func) {
  10231. return ary(func, 1);
  10232. }
  10233. /**
  10234. * Creates a function that provides `value` to `wrapper` as its first
  10235. * argument. Any additional arguments provided to the function are appended
  10236. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10237. * binding of the created function.
  10238. *
  10239. * @static
  10240. * @memberOf _
  10241. * @since 0.1.0
  10242. * @category Function
  10243. * @param {*} value The value to wrap.
  10244. * @param {Function} [wrapper=identity] The wrapper function.
  10245. * @returns {Function} Returns the new function.
  10246. * @example
  10247. *
  10248. * var p = _.wrap(_.escape, function(func, text) {
  10249. * return '<p>' + func(text) + '</p>';
  10250. * });
  10251. *
  10252. * p('fred, barney, & pebbles');
  10253. * // => '<p>fred, barney, &amp; pebbles</p>'
  10254. */
  10255. function wrap(value, wrapper) {
  10256. return partial(castFunction(wrapper), value);
  10257. }
  10258. /*------------------------------------------------------------------------*/
  10259. /**
  10260. * Casts `value` as an array if it's not one.
  10261. *
  10262. * @static
  10263. * @memberOf _
  10264. * @since 4.4.0
  10265. * @category Lang
  10266. * @param {*} value The value to inspect.
  10267. * @returns {Array} Returns the cast array.
  10268. * @example
  10269. *
  10270. * _.castArray(1);
  10271. * // => [1]
  10272. *
  10273. * _.castArray({ 'a': 1 });
  10274. * // => [{ 'a': 1 }]
  10275. *
  10276. * _.castArray('abc');
  10277. * // => ['abc']
  10278. *
  10279. * _.castArray(null);
  10280. * // => [null]
  10281. *
  10282. * _.castArray(undefined);
  10283. * // => [undefined]
  10284. *
  10285. * _.castArray();
  10286. * // => []
  10287. *
  10288. * var array = [1, 2, 3];
  10289. * console.log(_.castArray(array) === array);
  10290. * // => true
  10291. */
  10292. function castArray() {
  10293. if (!arguments.length) {
  10294. return [];
  10295. }
  10296. var value = arguments[0];
  10297. return isArray(value) ? value : [value];
  10298. }
  10299. /**
  10300. * Creates a shallow clone of `value`.
  10301. *
  10302. * **Note:** This method is loosely based on the
  10303. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10304. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10305. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10306. * arrays. The own enumerable properties of `arguments` objects are cloned
  10307. * as plain objects. An empty object is returned for uncloneable values such
  10308. * as error objects, functions, DOM nodes, and WeakMaps.
  10309. *
  10310. * @static
  10311. * @memberOf _
  10312. * @since 0.1.0
  10313. * @category Lang
  10314. * @param {*} value The value to clone.
  10315. * @returns {*} Returns the cloned value.
  10316. * @see _.cloneDeep
  10317. * @example
  10318. *
  10319. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10320. *
  10321. * var shallow = _.clone(objects);
  10322. * console.log(shallow[0] === objects[0]);
  10323. * // => true
  10324. */
  10325. function clone(value) {
  10326. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10327. }
  10328. /**
  10329. * This method is like `_.clone` except that it accepts `customizer` which
  10330. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10331. * cloning is handled by the method instead. The `customizer` is invoked with
  10332. * up to four arguments; (value [, index|key, object, stack]).
  10333. *
  10334. * @static
  10335. * @memberOf _
  10336. * @since 4.0.0
  10337. * @category Lang
  10338. * @param {*} value The value to clone.
  10339. * @param {Function} [customizer] The function to customize cloning.
  10340. * @returns {*} Returns the cloned value.
  10341. * @see _.cloneDeepWith
  10342. * @example
  10343. *
  10344. * function customizer(value) {
  10345. * if (_.isElement(value)) {
  10346. * return value.cloneNode(false);
  10347. * }
  10348. * }
  10349. *
  10350. * var el = _.cloneWith(document.body, customizer);
  10351. *
  10352. * console.log(el === document.body);
  10353. * // => false
  10354. * console.log(el.nodeName);
  10355. * // => 'BODY'
  10356. * console.log(el.childNodes.length);
  10357. * // => 0
  10358. */
  10359. function cloneWith(value, customizer) {
  10360. customizer = typeof customizer == 'function' ? customizer : undefined;
  10361. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10362. }
  10363. /**
  10364. * This method is like `_.clone` except that it recursively clones `value`.
  10365. *
  10366. * @static
  10367. * @memberOf _
  10368. * @since 1.0.0
  10369. * @category Lang
  10370. * @param {*} value The value to recursively clone.
  10371. * @returns {*} Returns the deep cloned value.
  10372. * @see _.clone
  10373. * @example
  10374. *
  10375. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10376. *
  10377. * var deep = _.cloneDeep(objects);
  10378. * console.log(deep[0] === objects[0]);
  10379. * // => false
  10380. */
  10381. function cloneDeep(value) {
  10382. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10383. }
  10384. /**
  10385. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10386. *
  10387. * @static
  10388. * @memberOf _
  10389. * @since 4.0.0
  10390. * @category Lang
  10391. * @param {*} value The value to recursively clone.
  10392. * @param {Function} [customizer] The function to customize cloning.
  10393. * @returns {*} Returns the deep cloned value.
  10394. * @see _.cloneWith
  10395. * @example
  10396. *
  10397. * function customizer(value) {
  10398. * if (_.isElement(value)) {
  10399. * return value.cloneNode(true);
  10400. * }
  10401. * }
  10402. *
  10403. * var el = _.cloneDeepWith(document.body, customizer);
  10404. *
  10405. * console.log(el === document.body);
  10406. * // => false
  10407. * console.log(el.nodeName);
  10408. * // => 'BODY'
  10409. * console.log(el.childNodes.length);
  10410. * // => 20
  10411. */
  10412. function cloneDeepWith(value, customizer) {
  10413. customizer = typeof customizer == 'function' ? customizer : undefined;
  10414. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10415. }
  10416. /**
  10417. * Checks if `object` conforms to `source` by invoking the predicate
  10418. * properties of `source` with the corresponding property values of `object`.
  10419. *
  10420. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10421. * partially applied.
  10422. *
  10423. * @static
  10424. * @memberOf _
  10425. * @since 4.14.0
  10426. * @category Lang
  10427. * @param {Object} object The object to inspect.
  10428. * @param {Object} source The object of property predicates to conform to.
  10429. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10430. * @example
  10431. *
  10432. * var object = { 'a': 1, 'b': 2 };
  10433. *
  10434. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10435. * // => true
  10436. *
  10437. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10438. * // => false
  10439. */
  10440. function conformsTo(object, source) {
  10441. return source == null || baseConformsTo(object, source, keys(source));
  10442. }
  10443. /**
  10444. * Performs a
  10445. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10446. * comparison between two values to determine if they are equivalent.
  10447. *
  10448. * @static
  10449. * @memberOf _
  10450. * @since 4.0.0
  10451. * @category Lang
  10452. * @param {*} value The value to compare.
  10453. * @param {*} other The other value to compare.
  10454. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10455. * @example
  10456. *
  10457. * var object = { 'a': 1 };
  10458. * var other = { 'a': 1 };
  10459. *
  10460. * _.eq(object, object);
  10461. * // => true
  10462. *
  10463. * _.eq(object, other);
  10464. * // => false
  10465. *
  10466. * _.eq('a', 'a');
  10467. * // => true
  10468. *
  10469. * _.eq('a', Object('a'));
  10470. * // => false
  10471. *
  10472. * _.eq(NaN, NaN);
  10473. * // => true
  10474. */
  10475. function eq(value, other) {
  10476. return value === other || (value !== value && other !== other);
  10477. }
  10478. /**
  10479. * Checks if `value` is greater than `other`.
  10480. *
  10481. * @static
  10482. * @memberOf _
  10483. * @since 3.9.0
  10484. * @category Lang
  10485. * @param {*} value The value to compare.
  10486. * @param {*} other The other value to compare.
  10487. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10488. * else `false`.
  10489. * @see _.lt
  10490. * @example
  10491. *
  10492. * _.gt(3, 1);
  10493. * // => true
  10494. *
  10495. * _.gt(3, 3);
  10496. * // => false
  10497. *
  10498. * _.gt(1, 3);
  10499. * // => false
  10500. */
  10501. var gt = createRelationalOperation(baseGt);
  10502. /**
  10503. * Checks if `value` is greater than or equal to `other`.
  10504. *
  10505. * @static
  10506. * @memberOf _
  10507. * @since 3.9.0
  10508. * @category Lang
  10509. * @param {*} value The value to compare.
  10510. * @param {*} other The other value to compare.
  10511. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10512. * `other`, else `false`.
  10513. * @see _.lte
  10514. * @example
  10515. *
  10516. * _.gte(3, 1);
  10517. * // => true
  10518. *
  10519. * _.gte(3, 3);
  10520. * // => true
  10521. *
  10522. * _.gte(1, 3);
  10523. * // => false
  10524. */
  10525. var gte = createRelationalOperation(function(value, other) {
  10526. return value >= other;
  10527. });
  10528. /**
  10529. * Checks if `value` is likely an `arguments` object.
  10530. *
  10531. * @static
  10532. * @memberOf _
  10533. * @since 0.1.0
  10534. * @category Lang
  10535. * @param {*} value The value to check.
  10536. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10537. * else `false`.
  10538. * @example
  10539. *
  10540. * _.isArguments(function() { return arguments; }());
  10541. * // => true
  10542. *
  10543. * _.isArguments([1, 2, 3]);
  10544. * // => false
  10545. */
  10546. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10547. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10548. !propertyIsEnumerable.call(value, 'callee');
  10549. };
  10550. /**
  10551. * Checks if `value` is classified as an `Array` object.
  10552. *
  10553. * @static
  10554. * @memberOf _
  10555. * @since 0.1.0
  10556. * @category Lang
  10557. * @param {*} value The value to check.
  10558. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10559. * @example
  10560. *
  10561. * _.isArray([1, 2, 3]);
  10562. * // => true
  10563. *
  10564. * _.isArray(document.body.children);
  10565. * // => false
  10566. *
  10567. * _.isArray('abc');
  10568. * // => false
  10569. *
  10570. * _.isArray(_.noop);
  10571. * // => false
  10572. */
  10573. var isArray = Array.isArray;
  10574. /**
  10575. * Checks if `value` is classified as an `ArrayBuffer` object.
  10576. *
  10577. * @static
  10578. * @memberOf _
  10579. * @since 4.3.0
  10580. * @category Lang
  10581. * @param {*} value The value to check.
  10582. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10583. * @example
  10584. *
  10585. * _.isArrayBuffer(new ArrayBuffer(2));
  10586. * // => true
  10587. *
  10588. * _.isArrayBuffer(new Array(2));
  10589. * // => false
  10590. */
  10591. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10592. /**
  10593. * Checks if `value` is array-like. A value is considered array-like if it's
  10594. * not a function and has a `value.length` that's an integer greater than or
  10595. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10596. *
  10597. * @static
  10598. * @memberOf _
  10599. * @since 4.0.0
  10600. * @category Lang
  10601. * @param {*} value The value to check.
  10602. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10603. * @example
  10604. *
  10605. * _.isArrayLike([1, 2, 3]);
  10606. * // => true
  10607. *
  10608. * _.isArrayLike(document.body.children);
  10609. * // => true
  10610. *
  10611. * _.isArrayLike('abc');
  10612. * // => true
  10613. *
  10614. * _.isArrayLike(_.noop);
  10615. * // => false
  10616. */
  10617. function isArrayLike(value) {
  10618. return value != null && isLength(value.length) && !isFunction(value);
  10619. }
  10620. /**
  10621. * This method is like `_.isArrayLike` except that it also checks if `value`
  10622. * is an object.
  10623. *
  10624. * @static
  10625. * @memberOf _
  10626. * @since 4.0.0
  10627. * @category Lang
  10628. * @param {*} value The value to check.
  10629. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10630. * else `false`.
  10631. * @example
  10632. *
  10633. * _.isArrayLikeObject([1, 2, 3]);
  10634. * // => true
  10635. *
  10636. * _.isArrayLikeObject(document.body.children);
  10637. * // => true
  10638. *
  10639. * _.isArrayLikeObject('abc');
  10640. * // => false
  10641. *
  10642. * _.isArrayLikeObject(_.noop);
  10643. * // => false
  10644. */
  10645. function isArrayLikeObject(value) {
  10646. return isObjectLike(value) && isArrayLike(value);
  10647. }
  10648. /**
  10649. * Checks if `value` is classified as a boolean primitive or object.
  10650. *
  10651. * @static
  10652. * @memberOf _
  10653. * @since 0.1.0
  10654. * @category Lang
  10655. * @param {*} value The value to check.
  10656. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10657. * @example
  10658. *
  10659. * _.isBoolean(false);
  10660. * // => true
  10661. *
  10662. * _.isBoolean(null);
  10663. * // => false
  10664. */
  10665. function isBoolean(value) {
  10666. return value === true || value === false ||
  10667. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10668. }
  10669. /**
  10670. * Checks if `value` is a buffer.
  10671. *
  10672. * @static
  10673. * @memberOf _
  10674. * @since 4.3.0
  10675. * @category Lang
  10676. * @param {*} value The value to check.
  10677. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10678. * @example
  10679. *
  10680. * _.isBuffer(new Buffer(2));
  10681. * // => true
  10682. *
  10683. * _.isBuffer(new Uint8Array(2));
  10684. * // => false
  10685. */
  10686. var isBuffer = nativeIsBuffer || stubFalse;
  10687. /**
  10688. * Checks if `value` is classified as a `Date` object.
  10689. *
  10690. * @static
  10691. * @memberOf _
  10692. * @since 0.1.0
  10693. * @category Lang
  10694. * @param {*} value The value to check.
  10695. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10696. * @example
  10697. *
  10698. * _.isDate(new Date);
  10699. * // => true
  10700. *
  10701. * _.isDate('Mon April 23 2012');
  10702. * // => false
  10703. */
  10704. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10705. /**
  10706. * Checks if `value` is likely a DOM element.
  10707. *
  10708. * @static
  10709. * @memberOf _
  10710. * @since 0.1.0
  10711. * @category Lang
  10712. * @param {*} value The value to check.
  10713. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10714. * @example
  10715. *
  10716. * _.isElement(document.body);
  10717. * // => true
  10718. *
  10719. * _.isElement('<body>');
  10720. * // => false
  10721. */
  10722. function isElement(value) {
  10723. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10724. }
  10725. /**
  10726. * Checks if `value` is an empty object, collection, map, or set.
  10727. *
  10728. * Objects are considered empty if they have no own enumerable string keyed
  10729. * properties.
  10730. *
  10731. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10732. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10733. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10734. *
  10735. * @static
  10736. * @memberOf _
  10737. * @since 0.1.0
  10738. * @category Lang
  10739. * @param {*} value The value to check.
  10740. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10741. * @example
  10742. *
  10743. * _.isEmpty(null);
  10744. * // => true
  10745. *
  10746. * _.isEmpty(true);
  10747. * // => true
  10748. *
  10749. * _.isEmpty(1);
  10750. * // => true
  10751. *
  10752. * _.isEmpty([1, 2, 3]);
  10753. * // => false
  10754. *
  10755. * _.isEmpty({ 'a': 1 });
  10756. * // => false
  10757. */
  10758. function isEmpty(value) {
  10759. if (value == null) {
  10760. return true;
  10761. }
  10762. if (isArrayLike(value) &&
  10763. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10764. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10765. return !value.length;
  10766. }
  10767. var tag = getTag(value);
  10768. if (tag == mapTag || tag == setTag) {
  10769. return !value.size;
  10770. }
  10771. if (isPrototype(value)) {
  10772. return !baseKeys(value).length;
  10773. }
  10774. for (var key in value) {
  10775. if (hasOwnProperty.call(value, key)) {
  10776. return false;
  10777. }
  10778. }
  10779. return true;
  10780. }
  10781. /**
  10782. * Performs a deep comparison between two values to determine if they are
  10783. * equivalent.
  10784. *
  10785. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10786. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10787. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10788. * by their own, not inherited, enumerable properties. Functions and DOM
  10789. * nodes are compared by strict equality, i.e. `===`.
  10790. *
  10791. * @static
  10792. * @memberOf _
  10793. * @since 0.1.0
  10794. * @category Lang
  10795. * @param {*} value The value to compare.
  10796. * @param {*} other The other value to compare.
  10797. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10798. * @example
  10799. *
  10800. * var object = { 'a': 1 };
  10801. * var other = { 'a': 1 };
  10802. *
  10803. * _.isEqual(object, other);
  10804. * // => true
  10805. *
  10806. * object === other;
  10807. * // => false
  10808. */
  10809. function isEqual(value, other) {
  10810. return baseIsEqual(value, other);
  10811. }
  10812. /**
  10813. * This method is like `_.isEqual` except that it accepts `customizer` which
  10814. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10815. * are handled by the method instead. The `customizer` is invoked with up to
  10816. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10817. *
  10818. * @static
  10819. * @memberOf _
  10820. * @since 4.0.0
  10821. * @category Lang
  10822. * @param {*} value The value to compare.
  10823. * @param {*} other The other value to compare.
  10824. * @param {Function} [customizer] The function to customize comparisons.
  10825. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10826. * @example
  10827. *
  10828. * function isGreeting(value) {
  10829. * return /^h(?:i|ello)$/.test(value);
  10830. * }
  10831. *
  10832. * function customizer(objValue, othValue) {
  10833. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10834. * return true;
  10835. * }
  10836. * }
  10837. *
  10838. * var array = ['hello', 'goodbye'];
  10839. * var other = ['hi', 'goodbye'];
  10840. *
  10841. * _.isEqualWith(array, other, customizer);
  10842. * // => true
  10843. */
  10844. function isEqualWith(value, other, customizer) {
  10845. customizer = typeof customizer == 'function' ? customizer : undefined;
  10846. var result = customizer ? customizer(value, other) : undefined;
  10847. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10848. }
  10849. /**
  10850. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10851. * `SyntaxError`, `TypeError`, or `URIError` object.
  10852. *
  10853. * @static
  10854. * @memberOf _
  10855. * @since 3.0.0
  10856. * @category Lang
  10857. * @param {*} value The value to check.
  10858. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10859. * @example
  10860. *
  10861. * _.isError(new Error);
  10862. * // => true
  10863. *
  10864. * _.isError(Error);
  10865. * // => false
  10866. */
  10867. function isError(value) {
  10868. if (!isObjectLike(value)) {
  10869. return false;
  10870. }
  10871. var tag = baseGetTag(value);
  10872. return tag == errorTag || tag == domExcTag ||
  10873. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10874. }
  10875. /**
  10876. * Checks if `value` is a finite primitive number.
  10877. *
  10878. * **Note:** This method is based on
  10879. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10880. *
  10881. * @static
  10882. * @memberOf _
  10883. * @since 0.1.0
  10884. * @category Lang
  10885. * @param {*} value The value to check.
  10886. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10887. * @example
  10888. *
  10889. * _.isFinite(3);
  10890. * // => true
  10891. *
  10892. * _.isFinite(Number.MIN_VALUE);
  10893. * // => true
  10894. *
  10895. * _.isFinite(Infinity);
  10896. * // => false
  10897. *
  10898. * _.isFinite('3');
  10899. * // => false
  10900. */
  10901. function isFinite(value) {
  10902. return typeof value == 'number' && nativeIsFinite(value);
  10903. }
  10904. /**
  10905. * Checks if `value` is classified as a `Function` object.
  10906. *
  10907. * @static
  10908. * @memberOf _
  10909. * @since 0.1.0
  10910. * @category Lang
  10911. * @param {*} value The value to check.
  10912. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10913. * @example
  10914. *
  10915. * _.isFunction(_);
  10916. * // => true
  10917. *
  10918. * _.isFunction(/abc/);
  10919. * // => false
  10920. */
  10921. function isFunction(value) {
  10922. if (!isObject(value)) {
  10923. return false;
  10924. }
  10925. // The use of `Object#toString` avoids issues with the `typeof` operator
  10926. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10927. var tag = baseGetTag(value);
  10928. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10929. }
  10930. /**
  10931. * Checks if `value` is an integer.
  10932. *
  10933. * **Note:** This method is based on
  10934. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10935. *
  10936. * @static
  10937. * @memberOf _
  10938. * @since 4.0.0
  10939. * @category Lang
  10940. * @param {*} value The value to check.
  10941. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10942. * @example
  10943. *
  10944. * _.isInteger(3);
  10945. * // => true
  10946. *
  10947. * _.isInteger(Number.MIN_VALUE);
  10948. * // => false
  10949. *
  10950. * _.isInteger(Infinity);
  10951. * // => false
  10952. *
  10953. * _.isInteger('3');
  10954. * // => false
  10955. */
  10956. function isInteger(value) {
  10957. return typeof value == 'number' && value == toInteger(value);
  10958. }
  10959. /**
  10960. * Checks if `value` is a valid array-like length.
  10961. *
  10962. * **Note:** This method is loosely based on
  10963. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10964. *
  10965. * @static
  10966. * @memberOf _
  10967. * @since 4.0.0
  10968. * @category Lang
  10969. * @param {*} value The value to check.
  10970. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10971. * @example
  10972. *
  10973. * _.isLength(3);
  10974. * // => true
  10975. *
  10976. * _.isLength(Number.MIN_VALUE);
  10977. * // => false
  10978. *
  10979. * _.isLength(Infinity);
  10980. * // => false
  10981. *
  10982. * _.isLength('3');
  10983. * // => false
  10984. */
  10985. function isLength(value) {
  10986. return typeof value == 'number' &&
  10987. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10988. }
  10989. /**
  10990. * Checks if `value` is the
  10991. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10992. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10993. *
  10994. * @static
  10995. * @memberOf _
  10996. * @since 0.1.0
  10997. * @category Lang
  10998. * @param {*} value The value to check.
  10999. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11000. * @example
  11001. *
  11002. * _.isObject({});
  11003. * // => true
  11004. *
  11005. * _.isObject([1, 2, 3]);
  11006. * // => true
  11007. *
  11008. * _.isObject(_.noop);
  11009. * // => true
  11010. *
  11011. * _.isObject(null);
  11012. * // => false
  11013. */
  11014. function isObject(value) {
  11015. var type = typeof value;
  11016. return value != null && (type == 'object' || type == 'function');
  11017. }
  11018. /**
  11019. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11020. * and has a `typeof` result of "object".
  11021. *
  11022. * @static
  11023. * @memberOf _
  11024. * @since 4.0.0
  11025. * @category Lang
  11026. * @param {*} value The value to check.
  11027. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11028. * @example
  11029. *
  11030. * _.isObjectLike({});
  11031. * // => true
  11032. *
  11033. * _.isObjectLike([1, 2, 3]);
  11034. * // => true
  11035. *
  11036. * _.isObjectLike(_.noop);
  11037. * // => false
  11038. *
  11039. * _.isObjectLike(null);
  11040. * // => false
  11041. */
  11042. function isObjectLike(value) {
  11043. return value != null && typeof value == 'object';
  11044. }
  11045. /**
  11046. * Checks if `value` is classified as a `Map` object.
  11047. *
  11048. * @static
  11049. * @memberOf _
  11050. * @since 4.3.0
  11051. * @category Lang
  11052. * @param {*} value The value to check.
  11053. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11054. * @example
  11055. *
  11056. * _.isMap(new Map);
  11057. * // => true
  11058. *
  11059. * _.isMap(new WeakMap);
  11060. * // => false
  11061. */
  11062. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11063. /**
  11064. * Performs a partial deep comparison between `object` and `source` to
  11065. * determine if `object` contains equivalent property values.
  11066. *
  11067. * **Note:** This method is equivalent to `_.matches` when `source` is
  11068. * partially applied.
  11069. *
  11070. * Partial comparisons will match empty array and empty object `source`
  11071. * values against any array or object value, respectively. See `_.isEqual`
  11072. * for a list of supported value comparisons.
  11073. *
  11074. * @static
  11075. * @memberOf _
  11076. * @since 3.0.0
  11077. * @category Lang
  11078. * @param {Object} object The object to inspect.
  11079. * @param {Object} source The object of property values to match.
  11080. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11081. * @example
  11082. *
  11083. * var object = { 'a': 1, 'b': 2 };
  11084. *
  11085. * _.isMatch(object, { 'b': 2 });
  11086. * // => true
  11087. *
  11088. * _.isMatch(object, { 'b': 1 });
  11089. * // => false
  11090. */
  11091. function isMatch(object, source) {
  11092. return object === source || baseIsMatch(object, source, getMatchData(source));
  11093. }
  11094. /**
  11095. * This method is like `_.isMatch` except that it accepts `customizer` which
  11096. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11097. * are handled by the method instead. The `customizer` is invoked with five
  11098. * arguments: (objValue, srcValue, index|key, object, source).
  11099. *
  11100. * @static
  11101. * @memberOf _
  11102. * @since 4.0.0
  11103. * @category Lang
  11104. * @param {Object} object The object to inspect.
  11105. * @param {Object} source The object of property values to match.
  11106. * @param {Function} [customizer] The function to customize comparisons.
  11107. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11108. * @example
  11109. *
  11110. * function isGreeting(value) {
  11111. * return /^h(?:i|ello)$/.test(value);
  11112. * }
  11113. *
  11114. * function customizer(objValue, srcValue) {
  11115. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11116. * return true;
  11117. * }
  11118. * }
  11119. *
  11120. * var object = { 'greeting': 'hello' };
  11121. * var source = { 'greeting': 'hi' };
  11122. *
  11123. * _.isMatchWith(object, source, customizer);
  11124. * // => true
  11125. */
  11126. function isMatchWith(object, source, customizer) {
  11127. customizer = typeof customizer == 'function' ? customizer : undefined;
  11128. return baseIsMatch(object, source, getMatchData(source), customizer);
  11129. }
  11130. /**
  11131. * Checks if `value` is `NaN`.
  11132. *
  11133. * **Note:** This method is based on
  11134. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11135. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11136. * `undefined` and other non-number values.
  11137. *
  11138. * @static
  11139. * @memberOf _
  11140. * @since 0.1.0
  11141. * @category Lang
  11142. * @param {*} value The value to check.
  11143. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11144. * @example
  11145. *
  11146. * _.isNaN(NaN);
  11147. * // => true
  11148. *
  11149. * _.isNaN(new Number(NaN));
  11150. * // => true
  11151. *
  11152. * isNaN(undefined);
  11153. * // => true
  11154. *
  11155. * _.isNaN(undefined);
  11156. * // => false
  11157. */
  11158. function isNaN(value) {
  11159. // An `NaN` primitive is the only value that is not equal to itself.
  11160. // Perform the `toStringTag` check first to avoid errors with some
  11161. // ActiveX objects in IE.
  11162. return isNumber(value) && value != +value;
  11163. }
  11164. /**
  11165. * Checks if `value` is a pristine native function.
  11166. *
  11167. * **Note:** This method can't reliably detect native functions in the presence
  11168. * of the core-js package because core-js circumvents this kind of detection.
  11169. * Despite multiple requests, the core-js maintainer has made it clear: any
  11170. * attempt to fix the detection will be obstructed. As a result, we're left
  11171. * with little choice but to throw an error. Unfortunately, this also affects
  11172. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11173. * which rely on core-js.
  11174. *
  11175. * @static
  11176. * @memberOf _
  11177. * @since 3.0.0
  11178. * @category Lang
  11179. * @param {*} value The value to check.
  11180. * @returns {boolean} Returns `true` if `value` is a native function,
  11181. * else `false`.
  11182. * @example
  11183. *
  11184. * _.isNative(Array.prototype.push);
  11185. * // => true
  11186. *
  11187. * _.isNative(_);
  11188. * // => false
  11189. */
  11190. function isNative(value) {
  11191. if (isMaskable(value)) {
  11192. throw new Error(CORE_ERROR_TEXT);
  11193. }
  11194. return baseIsNative(value);
  11195. }
  11196. /**
  11197. * Checks if `value` is `null`.
  11198. *
  11199. * @static
  11200. * @memberOf _
  11201. * @since 0.1.0
  11202. * @category Lang
  11203. * @param {*} value The value to check.
  11204. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11205. * @example
  11206. *
  11207. * _.isNull(null);
  11208. * // => true
  11209. *
  11210. * _.isNull(void 0);
  11211. * // => false
  11212. */
  11213. function isNull(value) {
  11214. return value === null;
  11215. }
  11216. /**
  11217. * Checks if `value` is `null` or `undefined`.
  11218. *
  11219. * @static
  11220. * @memberOf _
  11221. * @since 4.0.0
  11222. * @category Lang
  11223. * @param {*} value The value to check.
  11224. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11225. * @example
  11226. *
  11227. * _.isNil(null);
  11228. * // => true
  11229. *
  11230. * _.isNil(void 0);
  11231. * // => true
  11232. *
  11233. * _.isNil(NaN);
  11234. * // => false
  11235. */
  11236. function isNil(value) {
  11237. return value == null;
  11238. }
  11239. /**
  11240. * Checks if `value` is classified as a `Number` primitive or object.
  11241. *
  11242. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11243. * classified as numbers, use the `_.isFinite` method.
  11244. *
  11245. * @static
  11246. * @memberOf _
  11247. * @since 0.1.0
  11248. * @category Lang
  11249. * @param {*} value The value to check.
  11250. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11251. * @example
  11252. *
  11253. * _.isNumber(3);
  11254. * // => true
  11255. *
  11256. * _.isNumber(Number.MIN_VALUE);
  11257. * // => true
  11258. *
  11259. * _.isNumber(Infinity);
  11260. * // => true
  11261. *
  11262. * _.isNumber('3');
  11263. * // => false
  11264. */
  11265. function isNumber(value) {
  11266. return typeof value == 'number' ||
  11267. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11268. }
  11269. /**
  11270. * Checks if `value` is a plain object, that is, an object created by the
  11271. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11272. *
  11273. * @static
  11274. * @memberOf _
  11275. * @since 0.8.0
  11276. * @category Lang
  11277. * @param {*} value The value to check.
  11278. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11279. * @example
  11280. *
  11281. * function Foo() {
  11282. * this.a = 1;
  11283. * }
  11284. *
  11285. * _.isPlainObject(new Foo);
  11286. * // => false
  11287. *
  11288. * _.isPlainObject([1, 2, 3]);
  11289. * // => false
  11290. *
  11291. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11292. * // => true
  11293. *
  11294. * _.isPlainObject(Object.create(null));
  11295. * // => true
  11296. */
  11297. function isPlainObject(value) {
  11298. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11299. return false;
  11300. }
  11301. var proto = getPrototype(value);
  11302. if (proto === null) {
  11303. return true;
  11304. }
  11305. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11306. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11307. funcToString.call(Ctor) == objectCtorString;
  11308. }
  11309. /**
  11310. * Checks if `value` is classified as a `RegExp` object.
  11311. *
  11312. * @static
  11313. * @memberOf _
  11314. * @since 0.1.0
  11315. * @category Lang
  11316. * @param {*} value The value to check.
  11317. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11318. * @example
  11319. *
  11320. * _.isRegExp(/abc/);
  11321. * // => true
  11322. *
  11323. * _.isRegExp('/abc/');
  11324. * // => false
  11325. */
  11326. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11327. /**
  11328. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11329. * double precision number which isn't the result of a rounded unsafe integer.
  11330. *
  11331. * **Note:** This method is based on
  11332. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11333. *
  11334. * @static
  11335. * @memberOf _
  11336. * @since 4.0.0
  11337. * @category Lang
  11338. * @param {*} value The value to check.
  11339. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11340. * @example
  11341. *
  11342. * _.isSafeInteger(3);
  11343. * // => true
  11344. *
  11345. * _.isSafeInteger(Number.MIN_VALUE);
  11346. * // => false
  11347. *
  11348. * _.isSafeInteger(Infinity);
  11349. * // => false
  11350. *
  11351. * _.isSafeInteger('3');
  11352. * // => false
  11353. */
  11354. function isSafeInteger(value) {
  11355. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11356. }
  11357. /**
  11358. * Checks if `value` is classified as a `Set` object.
  11359. *
  11360. * @static
  11361. * @memberOf _
  11362. * @since 4.3.0
  11363. * @category Lang
  11364. * @param {*} value The value to check.
  11365. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11366. * @example
  11367. *
  11368. * _.isSet(new Set);
  11369. * // => true
  11370. *
  11371. * _.isSet(new WeakSet);
  11372. * // => false
  11373. */
  11374. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11375. /**
  11376. * Checks if `value` is classified as a `String` primitive or object.
  11377. *
  11378. * @static
  11379. * @since 0.1.0
  11380. * @memberOf _
  11381. * @category Lang
  11382. * @param {*} value The value to check.
  11383. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11384. * @example
  11385. *
  11386. * _.isString('abc');
  11387. * // => true
  11388. *
  11389. * _.isString(1);
  11390. * // => false
  11391. */
  11392. function isString(value) {
  11393. return typeof value == 'string' ||
  11394. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11395. }
  11396. /**
  11397. * Checks if `value` is classified as a `Symbol` primitive or object.
  11398. *
  11399. * @static
  11400. * @memberOf _
  11401. * @since 4.0.0
  11402. * @category Lang
  11403. * @param {*} value The value to check.
  11404. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11405. * @example
  11406. *
  11407. * _.isSymbol(Symbol.iterator);
  11408. * // => true
  11409. *
  11410. * _.isSymbol('abc');
  11411. * // => false
  11412. */
  11413. function isSymbol(value) {
  11414. return typeof value == 'symbol' ||
  11415. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11416. }
  11417. /**
  11418. * Checks if `value` is classified as a typed array.
  11419. *
  11420. * @static
  11421. * @memberOf _
  11422. * @since 3.0.0
  11423. * @category Lang
  11424. * @param {*} value The value to check.
  11425. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11426. * @example
  11427. *
  11428. * _.isTypedArray(new Uint8Array);
  11429. * // => true
  11430. *
  11431. * _.isTypedArray([]);
  11432. * // => false
  11433. */
  11434. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11435. /**
  11436. * Checks if `value` is `undefined`.
  11437. *
  11438. * @static
  11439. * @since 0.1.0
  11440. * @memberOf _
  11441. * @category Lang
  11442. * @param {*} value The value to check.
  11443. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11444. * @example
  11445. *
  11446. * _.isUndefined(void 0);
  11447. * // => true
  11448. *
  11449. * _.isUndefined(null);
  11450. * // => false
  11451. */
  11452. function isUndefined(value) {
  11453. return value === undefined;
  11454. }
  11455. /**
  11456. * Checks if `value` is classified as a `WeakMap` object.
  11457. *
  11458. * @static
  11459. * @memberOf _
  11460. * @since 4.3.0
  11461. * @category Lang
  11462. * @param {*} value The value to check.
  11463. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11464. * @example
  11465. *
  11466. * _.isWeakMap(new WeakMap);
  11467. * // => true
  11468. *
  11469. * _.isWeakMap(new Map);
  11470. * // => false
  11471. */
  11472. function isWeakMap(value) {
  11473. return isObjectLike(value) && getTag(value) == weakMapTag;
  11474. }
  11475. /**
  11476. * Checks if `value` is classified as a `WeakSet` object.
  11477. *
  11478. * @static
  11479. * @memberOf _
  11480. * @since 4.3.0
  11481. * @category Lang
  11482. * @param {*} value The value to check.
  11483. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11484. * @example
  11485. *
  11486. * _.isWeakSet(new WeakSet);
  11487. * // => true
  11488. *
  11489. * _.isWeakSet(new Set);
  11490. * // => false
  11491. */
  11492. function isWeakSet(value) {
  11493. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11494. }
  11495. /**
  11496. * Checks if `value` is less than `other`.
  11497. *
  11498. * @static
  11499. * @memberOf _
  11500. * @since 3.9.0
  11501. * @category Lang
  11502. * @param {*} value The value to compare.
  11503. * @param {*} other The other value to compare.
  11504. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11505. * else `false`.
  11506. * @see _.gt
  11507. * @example
  11508. *
  11509. * _.lt(1, 3);
  11510. * // => true
  11511. *
  11512. * _.lt(3, 3);
  11513. * // => false
  11514. *
  11515. * _.lt(3, 1);
  11516. * // => false
  11517. */
  11518. var lt = createRelationalOperation(baseLt);
  11519. /**
  11520. * Checks if `value` is less than or equal to `other`.
  11521. *
  11522. * @static
  11523. * @memberOf _
  11524. * @since 3.9.0
  11525. * @category Lang
  11526. * @param {*} value The value to compare.
  11527. * @param {*} other The other value to compare.
  11528. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11529. * `other`, else `false`.
  11530. * @see _.gte
  11531. * @example
  11532. *
  11533. * _.lte(1, 3);
  11534. * // => true
  11535. *
  11536. * _.lte(3, 3);
  11537. * // => true
  11538. *
  11539. * _.lte(3, 1);
  11540. * // => false
  11541. */
  11542. var lte = createRelationalOperation(function(value, other) {
  11543. return value <= other;
  11544. });
  11545. /**
  11546. * Converts `value` to an array.
  11547. *
  11548. * @static
  11549. * @since 0.1.0
  11550. * @memberOf _
  11551. * @category Lang
  11552. * @param {*} value The value to convert.
  11553. * @returns {Array} Returns the converted array.
  11554. * @example
  11555. *
  11556. * _.toArray({ 'a': 1, 'b': 2 });
  11557. * // => [1, 2]
  11558. *
  11559. * _.toArray('abc');
  11560. * // => ['a', 'b', 'c']
  11561. *
  11562. * _.toArray(1);
  11563. * // => []
  11564. *
  11565. * _.toArray(null);
  11566. * // => []
  11567. */
  11568. function toArray(value) {
  11569. if (!value) {
  11570. return [];
  11571. }
  11572. if (isArrayLike(value)) {
  11573. return isString(value) ? stringToArray(value) : copyArray(value);
  11574. }
  11575. if (symIterator && value[symIterator]) {
  11576. return iteratorToArray(value[symIterator]());
  11577. }
  11578. var tag = getTag(value),
  11579. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11580. return func(value);
  11581. }
  11582. /**
  11583. * Converts `value` to a finite number.
  11584. *
  11585. * @static
  11586. * @memberOf _
  11587. * @since 4.12.0
  11588. * @category Lang
  11589. * @param {*} value The value to convert.
  11590. * @returns {number} Returns the converted number.
  11591. * @example
  11592. *
  11593. * _.toFinite(3.2);
  11594. * // => 3.2
  11595. *
  11596. * _.toFinite(Number.MIN_VALUE);
  11597. * // => 5e-324
  11598. *
  11599. * _.toFinite(Infinity);
  11600. * // => 1.7976931348623157e+308
  11601. *
  11602. * _.toFinite('3.2');
  11603. * // => 3.2
  11604. */
  11605. function toFinite(value) {
  11606. if (!value) {
  11607. return value === 0 ? value : 0;
  11608. }
  11609. value = toNumber(value);
  11610. if (value === INFINITY || value === -INFINITY) {
  11611. var sign = (value < 0 ? -1 : 1);
  11612. return sign * MAX_INTEGER;
  11613. }
  11614. return value === value ? value : 0;
  11615. }
  11616. /**
  11617. * Converts `value` to an integer.
  11618. *
  11619. * **Note:** This method is loosely based on
  11620. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11621. *
  11622. * @static
  11623. * @memberOf _
  11624. * @since 4.0.0
  11625. * @category Lang
  11626. * @param {*} value The value to convert.
  11627. * @returns {number} Returns the converted integer.
  11628. * @example
  11629. *
  11630. * _.toInteger(3.2);
  11631. * // => 3
  11632. *
  11633. * _.toInteger(Number.MIN_VALUE);
  11634. * // => 0
  11635. *
  11636. * _.toInteger(Infinity);
  11637. * // => 1.7976931348623157e+308
  11638. *
  11639. * _.toInteger('3.2');
  11640. * // => 3
  11641. */
  11642. function toInteger(value) {
  11643. var result = toFinite(value),
  11644. remainder = result % 1;
  11645. return result === result ? (remainder ? result - remainder : result) : 0;
  11646. }
  11647. /**
  11648. * Converts `value` to an integer suitable for use as the length of an
  11649. * array-like object.
  11650. *
  11651. * **Note:** This method is based on
  11652. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11653. *
  11654. * @static
  11655. * @memberOf _
  11656. * @since 4.0.0
  11657. * @category Lang
  11658. * @param {*} value The value to convert.
  11659. * @returns {number} Returns the converted integer.
  11660. * @example
  11661. *
  11662. * _.toLength(3.2);
  11663. * // => 3
  11664. *
  11665. * _.toLength(Number.MIN_VALUE);
  11666. * // => 0
  11667. *
  11668. * _.toLength(Infinity);
  11669. * // => 4294967295
  11670. *
  11671. * _.toLength('3.2');
  11672. * // => 3
  11673. */
  11674. function toLength(value) {
  11675. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11676. }
  11677. /**
  11678. * Converts `value` to a number.
  11679. *
  11680. * @static
  11681. * @memberOf _
  11682. * @since 4.0.0
  11683. * @category Lang
  11684. * @param {*} value The value to process.
  11685. * @returns {number} Returns the number.
  11686. * @example
  11687. *
  11688. * _.toNumber(3.2);
  11689. * // => 3.2
  11690. *
  11691. * _.toNumber(Number.MIN_VALUE);
  11692. * // => 5e-324
  11693. *
  11694. * _.toNumber(Infinity);
  11695. * // => Infinity
  11696. *
  11697. * _.toNumber('3.2');
  11698. * // => 3.2
  11699. */
  11700. function toNumber(value) {
  11701. if (typeof value == 'number') {
  11702. return value;
  11703. }
  11704. if (isSymbol(value)) {
  11705. return NAN;
  11706. }
  11707. if (isObject(value)) {
  11708. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11709. value = isObject(other) ? (other + '') : other;
  11710. }
  11711. if (typeof value != 'string') {
  11712. return value === 0 ? value : +value;
  11713. }
  11714. value = baseTrim(value);
  11715. var isBinary = reIsBinary.test(value);
  11716. return (isBinary || reIsOctal.test(value))
  11717. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11718. : (reIsBadHex.test(value) ? NAN : +value);
  11719. }
  11720. /**
  11721. * Converts `value` to a plain object flattening inherited enumerable string
  11722. * keyed properties of `value` to own properties of the plain object.
  11723. *
  11724. * @static
  11725. * @memberOf _
  11726. * @since 3.0.0
  11727. * @category Lang
  11728. * @param {*} value The value to convert.
  11729. * @returns {Object} Returns the converted plain object.
  11730. * @example
  11731. *
  11732. * function Foo() {
  11733. * this.b = 2;
  11734. * }
  11735. *
  11736. * Foo.prototype.c = 3;
  11737. *
  11738. * _.assign({ 'a': 1 }, new Foo);
  11739. * // => { 'a': 1, 'b': 2 }
  11740. *
  11741. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11742. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11743. */
  11744. function toPlainObject(value) {
  11745. return copyObject(value, keysIn(value));
  11746. }
  11747. /**
  11748. * Converts `value` to a safe integer. A safe integer can be compared and
  11749. * represented correctly.
  11750. *
  11751. * @static
  11752. * @memberOf _
  11753. * @since 4.0.0
  11754. * @category Lang
  11755. * @param {*} value The value to convert.
  11756. * @returns {number} Returns the converted integer.
  11757. * @example
  11758. *
  11759. * _.toSafeInteger(3.2);
  11760. * // => 3
  11761. *
  11762. * _.toSafeInteger(Number.MIN_VALUE);
  11763. * // => 0
  11764. *
  11765. * _.toSafeInteger(Infinity);
  11766. * // => 9007199254740991
  11767. *
  11768. * _.toSafeInteger('3.2');
  11769. * // => 3
  11770. */
  11771. function toSafeInteger(value) {
  11772. return value
  11773. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11774. : (value === 0 ? value : 0);
  11775. }
  11776. /**
  11777. * Converts `value` to a string. An empty string is returned for `null`
  11778. * and `undefined` values. The sign of `-0` is preserved.
  11779. *
  11780. * @static
  11781. * @memberOf _
  11782. * @since 4.0.0
  11783. * @category Lang
  11784. * @param {*} value The value to convert.
  11785. * @returns {string} Returns the converted string.
  11786. * @example
  11787. *
  11788. * _.toString(null);
  11789. * // => ''
  11790. *
  11791. * _.toString(-0);
  11792. * // => '-0'
  11793. *
  11794. * _.toString([1, 2, 3]);
  11795. * // => '1,2,3'
  11796. */
  11797. function toString(value) {
  11798. return value == null ? '' : baseToString(value);
  11799. }
  11800. /*------------------------------------------------------------------------*/
  11801. /**
  11802. * Assigns own enumerable string keyed properties of source objects to the
  11803. * destination object. Source objects are applied from left to right.
  11804. * Subsequent sources overwrite property assignments of previous sources.
  11805. *
  11806. * **Note:** This method mutates `object` and is loosely based on
  11807. * [`Object.assign`](https://mdn.io/Object/assign).
  11808. *
  11809. * @static
  11810. * @memberOf _
  11811. * @since 0.10.0
  11812. * @category Object
  11813. * @param {Object} object The destination object.
  11814. * @param {...Object} [sources] The source objects.
  11815. * @returns {Object} Returns `object`.
  11816. * @see _.assignIn
  11817. * @example
  11818. *
  11819. * function Foo() {
  11820. * this.a = 1;
  11821. * }
  11822. *
  11823. * function Bar() {
  11824. * this.c = 3;
  11825. * }
  11826. *
  11827. * Foo.prototype.b = 2;
  11828. * Bar.prototype.d = 4;
  11829. *
  11830. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11831. * // => { 'a': 1, 'c': 3 }
  11832. */
  11833. var assign = createAssigner(function(object, source) {
  11834. if (isPrototype(source) || isArrayLike(source)) {
  11835. copyObject(source, keys(source), object);
  11836. return;
  11837. }
  11838. for (var key in source) {
  11839. if (hasOwnProperty.call(source, key)) {
  11840. assignValue(object, key, source[key]);
  11841. }
  11842. }
  11843. });
  11844. /**
  11845. * This method is like `_.assign` except that it iterates over own and
  11846. * inherited source properties.
  11847. *
  11848. * **Note:** This method mutates `object`.
  11849. *
  11850. * @static
  11851. * @memberOf _
  11852. * @since 4.0.0
  11853. * @alias extend
  11854. * @category Object
  11855. * @param {Object} object The destination object.
  11856. * @param {...Object} [sources] The source objects.
  11857. * @returns {Object} Returns `object`.
  11858. * @see _.assign
  11859. * @example
  11860. *
  11861. * function Foo() {
  11862. * this.a = 1;
  11863. * }
  11864. *
  11865. * function Bar() {
  11866. * this.c = 3;
  11867. * }
  11868. *
  11869. * Foo.prototype.b = 2;
  11870. * Bar.prototype.d = 4;
  11871. *
  11872. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11873. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11874. */
  11875. var assignIn = createAssigner(function(object, source) {
  11876. copyObject(source, keysIn(source), object);
  11877. });
  11878. /**
  11879. * This method is like `_.assignIn` except that it accepts `customizer`
  11880. * which is invoked to produce the assigned values. If `customizer` returns
  11881. * `undefined`, assignment is handled by the method instead. The `customizer`
  11882. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11883. *
  11884. * **Note:** This method mutates `object`.
  11885. *
  11886. * @static
  11887. * @memberOf _
  11888. * @since 4.0.0
  11889. * @alias extendWith
  11890. * @category Object
  11891. * @param {Object} object The destination object.
  11892. * @param {...Object} sources The source objects.
  11893. * @param {Function} [customizer] The function to customize assigned values.
  11894. * @returns {Object} Returns `object`.
  11895. * @see _.assignWith
  11896. * @example
  11897. *
  11898. * function customizer(objValue, srcValue) {
  11899. * return _.isUndefined(objValue) ? srcValue : objValue;
  11900. * }
  11901. *
  11902. * var defaults = _.partialRight(_.assignInWith, customizer);
  11903. *
  11904. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11905. * // => { 'a': 1, 'b': 2 }
  11906. */
  11907. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11908. copyObject(source, keysIn(source), object, customizer);
  11909. });
  11910. /**
  11911. * This method is like `_.assign` except that it accepts `customizer`
  11912. * which is invoked to produce the assigned values. If `customizer` returns
  11913. * `undefined`, assignment is handled by the method instead. The `customizer`
  11914. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11915. *
  11916. * **Note:** This method mutates `object`.
  11917. *
  11918. * @static
  11919. * @memberOf _
  11920. * @since 4.0.0
  11921. * @category Object
  11922. * @param {Object} object The destination object.
  11923. * @param {...Object} sources The source objects.
  11924. * @param {Function} [customizer] The function to customize assigned values.
  11925. * @returns {Object} Returns `object`.
  11926. * @see _.assignInWith
  11927. * @example
  11928. *
  11929. * function customizer(objValue, srcValue) {
  11930. * return _.isUndefined(objValue) ? srcValue : objValue;
  11931. * }
  11932. *
  11933. * var defaults = _.partialRight(_.assignWith, customizer);
  11934. *
  11935. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11936. * // => { 'a': 1, 'b': 2 }
  11937. */
  11938. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11939. copyObject(source, keys(source), object, customizer);
  11940. });
  11941. /**
  11942. * Creates an array of values corresponding to `paths` of `object`.
  11943. *
  11944. * @static
  11945. * @memberOf _
  11946. * @since 1.0.0
  11947. * @category Object
  11948. * @param {Object} object The object to iterate over.
  11949. * @param {...(string|string[])} [paths] The property paths to pick.
  11950. * @returns {Array} Returns the picked values.
  11951. * @example
  11952. *
  11953. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11954. *
  11955. * _.at(object, ['a[0].b.c', 'a[1]']);
  11956. * // => [3, 4]
  11957. */
  11958. var at = flatRest(baseAt);
  11959. /**
  11960. * Creates an object that inherits from the `prototype` object. If a
  11961. * `properties` object is given, its own enumerable string keyed properties
  11962. * are assigned to the created object.
  11963. *
  11964. * @static
  11965. * @memberOf _
  11966. * @since 2.3.0
  11967. * @category Object
  11968. * @param {Object} prototype The object to inherit from.
  11969. * @param {Object} [properties] The properties to assign to the object.
  11970. * @returns {Object} Returns the new object.
  11971. * @example
  11972. *
  11973. * function Shape() {
  11974. * this.x = 0;
  11975. * this.y = 0;
  11976. * }
  11977. *
  11978. * function Circle() {
  11979. * Shape.call(this);
  11980. * }
  11981. *
  11982. * Circle.prototype = _.create(Shape.prototype, {
  11983. * 'constructor': Circle
  11984. * });
  11985. *
  11986. * var circle = new Circle;
  11987. * circle instanceof Circle;
  11988. * // => true
  11989. *
  11990. * circle instanceof Shape;
  11991. * // => true
  11992. */
  11993. function create(prototype, properties) {
  11994. var result = baseCreate(prototype);
  11995. return properties == null ? result : baseAssign(result, properties);
  11996. }
  11997. /**
  11998. * Assigns own and inherited enumerable string keyed properties of source
  11999. * objects to the destination object for all destination properties that
  12000. * resolve to `undefined`. Source objects are applied from left to right.
  12001. * Once a property is set, additional values of the same property are ignored.
  12002. *
  12003. * **Note:** This method mutates `object`.
  12004. *
  12005. * @static
  12006. * @since 0.1.0
  12007. * @memberOf _
  12008. * @category Object
  12009. * @param {Object} object The destination object.
  12010. * @param {...Object} [sources] The source objects.
  12011. * @returns {Object} Returns `object`.
  12012. * @see _.defaultsDeep
  12013. * @example
  12014. *
  12015. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12016. * // => { 'a': 1, 'b': 2 }
  12017. */
  12018. var defaults = baseRest(function(object, sources) {
  12019. object = Object(object);
  12020. var index = -1;
  12021. var length = sources.length;
  12022. var guard = length > 2 ? sources[2] : undefined;
  12023. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  12024. length = 1;
  12025. }
  12026. while (++index < length) {
  12027. var source = sources[index];
  12028. var props = keysIn(source);
  12029. var propsIndex = -1;
  12030. var propsLength = props.length;
  12031. while (++propsIndex < propsLength) {
  12032. var key = props[propsIndex];
  12033. var value = object[key];
  12034. if (value === undefined ||
  12035. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  12036. object[key] = source[key];
  12037. }
  12038. }
  12039. }
  12040. return object;
  12041. });
  12042. /**
  12043. * This method is like `_.defaults` except that it recursively assigns
  12044. * default properties.
  12045. *
  12046. * **Note:** This method mutates `object`.
  12047. *
  12048. * @static
  12049. * @memberOf _
  12050. * @since 3.10.0
  12051. * @category Object
  12052. * @param {Object} object The destination object.
  12053. * @param {...Object} [sources] The source objects.
  12054. * @returns {Object} Returns `object`.
  12055. * @see _.defaults
  12056. * @example
  12057. *
  12058. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12059. * // => { 'a': { 'b': 2, 'c': 3 } }
  12060. */
  12061. var defaultsDeep = baseRest(function(args) {
  12062. args.push(undefined, customDefaultsMerge);
  12063. return apply(mergeWith, undefined, args);
  12064. });
  12065. /**
  12066. * This method is like `_.find` except that it returns the key of the first
  12067. * element `predicate` returns truthy for instead of the element itself.
  12068. *
  12069. * @static
  12070. * @memberOf _
  12071. * @since 1.1.0
  12072. * @category Object
  12073. * @param {Object} object The object to inspect.
  12074. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12075. * @returns {string|undefined} Returns the key of the matched element,
  12076. * else `undefined`.
  12077. * @example
  12078. *
  12079. * var users = {
  12080. * 'barney': { 'age': 36, 'active': true },
  12081. * 'fred': { 'age': 40, 'active': false },
  12082. * 'pebbles': { 'age': 1, 'active': true }
  12083. * };
  12084. *
  12085. * _.findKey(users, function(o) { return o.age < 40; });
  12086. * // => 'barney' (iteration order is not guaranteed)
  12087. *
  12088. * // The `_.matches` iteratee shorthand.
  12089. * _.findKey(users, { 'age': 1, 'active': true });
  12090. * // => 'pebbles'
  12091. *
  12092. * // The `_.matchesProperty` iteratee shorthand.
  12093. * _.findKey(users, ['active', false]);
  12094. * // => 'fred'
  12095. *
  12096. * // The `_.property` iteratee shorthand.
  12097. * _.findKey(users, 'active');
  12098. * // => 'barney'
  12099. */
  12100. function findKey(object, predicate) {
  12101. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12102. }
  12103. /**
  12104. * This method is like `_.findKey` except that it iterates over elements of
  12105. * a collection in the opposite order.
  12106. *
  12107. * @static
  12108. * @memberOf _
  12109. * @since 2.0.0
  12110. * @category Object
  12111. * @param {Object} object The object to inspect.
  12112. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12113. * @returns {string|undefined} Returns the key of the matched element,
  12114. * else `undefined`.
  12115. * @example
  12116. *
  12117. * var users = {
  12118. * 'barney': { 'age': 36, 'active': true },
  12119. * 'fred': { 'age': 40, 'active': false },
  12120. * 'pebbles': { 'age': 1, 'active': true }
  12121. * };
  12122. *
  12123. * _.findLastKey(users, function(o) { return o.age < 40; });
  12124. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12125. *
  12126. * // The `_.matches` iteratee shorthand.
  12127. * _.findLastKey(users, { 'age': 36, 'active': true });
  12128. * // => 'barney'
  12129. *
  12130. * // The `_.matchesProperty` iteratee shorthand.
  12131. * _.findLastKey(users, ['active', false]);
  12132. * // => 'fred'
  12133. *
  12134. * // The `_.property` iteratee shorthand.
  12135. * _.findLastKey(users, 'active');
  12136. * // => 'pebbles'
  12137. */
  12138. function findLastKey(object, predicate) {
  12139. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12140. }
  12141. /**
  12142. * Iterates over own and inherited enumerable string keyed properties of an
  12143. * object and invokes `iteratee` for each property. The iteratee is invoked
  12144. * with three arguments: (value, key, object). Iteratee functions may exit
  12145. * iteration early by explicitly returning `false`.
  12146. *
  12147. * @static
  12148. * @memberOf _
  12149. * @since 0.3.0
  12150. * @category Object
  12151. * @param {Object} object The object to iterate over.
  12152. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12153. * @returns {Object} Returns `object`.
  12154. * @see _.forInRight
  12155. * @example
  12156. *
  12157. * function Foo() {
  12158. * this.a = 1;
  12159. * this.b = 2;
  12160. * }
  12161. *
  12162. * Foo.prototype.c = 3;
  12163. *
  12164. * _.forIn(new Foo, function(value, key) {
  12165. * console.log(key);
  12166. * });
  12167. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12168. */
  12169. function forIn(object, iteratee) {
  12170. return object == null
  12171. ? object
  12172. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12173. }
  12174. /**
  12175. * This method is like `_.forIn` except that it iterates over properties of
  12176. * `object` in the opposite order.
  12177. *
  12178. * @static
  12179. * @memberOf _
  12180. * @since 2.0.0
  12181. * @category Object
  12182. * @param {Object} object The object to iterate over.
  12183. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12184. * @returns {Object} Returns `object`.
  12185. * @see _.forIn
  12186. * @example
  12187. *
  12188. * function Foo() {
  12189. * this.a = 1;
  12190. * this.b = 2;
  12191. * }
  12192. *
  12193. * Foo.prototype.c = 3;
  12194. *
  12195. * _.forInRight(new Foo, function(value, key) {
  12196. * console.log(key);
  12197. * });
  12198. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12199. */
  12200. function forInRight(object, iteratee) {
  12201. return object == null
  12202. ? object
  12203. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12204. }
  12205. /**
  12206. * Iterates over own enumerable string keyed properties of an object and
  12207. * invokes `iteratee` for each property. The iteratee is invoked with three
  12208. * arguments: (value, key, object). Iteratee functions may exit iteration
  12209. * early by explicitly returning `false`.
  12210. *
  12211. * @static
  12212. * @memberOf _
  12213. * @since 0.3.0
  12214. * @category Object
  12215. * @param {Object} object The object to iterate over.
  12216. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12217. * @returns {Object} Returns `object`.
  12218. * @see _.forOwnRight
  12219. * @example
  12220. *
  12221. * function Foo() {
  12222. * this.a = 1;
  12223. * this.b = 2;
  12224. * }
  12225. *
  12226. * Foo.prototype.c = 3;
  12227. *
  12228. * _.forOwn(new Foo, function(value, key) {
  12229. * console.log(key);
  12230. * });
  12231. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12232. */
  12233. function forOwn(object, iteratee) {
  12234. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12235. }
  12236. /**
  12237. * This method is like `_.forOwn` except that it iterates over properties of
  12238. * `object` in the opposite order.
  12239. *
  12240. * @static
  12241. * @memberOf _
  12242. * @since 2.0.0
  12243. * @category Object
  12244. * @param {Object} object The object to iterate over.
  12245. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12246. * @returns {Object} Returns `object`.
  12247. * @see _.forOwn
  12248. * @example
  12249. *
  12250. * function Foo() {
  12251. * this.a = 1;
  12252. * this.b = 2;
  12253. * }
  12254. *
  12255. * Foo.prototype.c = 3;
  12256. *
  12257. * _.forOwnRight(new Foo, function(value, key) {
  12258. * console.log(key);
  12259. * });
  12260. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12261. */
  12262. function forOwnRight(object, iteratee) {
  12263. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12264. }
  12265. /**
  12266. * Creates an array of function property names from own enumerable properties
  12267. * of `object`.
  12268. *
  12269. * @static
  12270. * @since 0.1.0
  12271. * @memberOf _
  12272. * @category Object
  12273. * @param {Object} object The object to inspect.
  12274. * @returns {Array} Returns the function names.
  12275. * @see _.functionsIn
  12276. * @example
  12277. *
  12278. * function Foo() {
  12279. * this.a = _.constant('a');
  12280. * this.b = _.constant('b');
  12281. * }
  12282. *
  12283. * Foo.prototype.c = _.constant('c');
  12284. *
  12285. * _.functions(new Foo);
  12286. * // => ['a', 'b']
  12287. */
  12288. function functions(object) {
  12289. return object == null ? [] : baseFunctions(object, keys(object));
  12290. }
  12291. /**
  12292. * Creates an array of function property names from own and inherited
  12293. * enumerable properties of `object`.
  12294. *
  12295. * @static
  12296. * @memberOf _
  12297. * @since 4.0.0
  12298. * @category Object
  12299. * @param {Object} object The object to inspect.
  12300. * @returns {Array} Returns the function names.
  12301. * @see _.functions
  12302. * @example
  12303. *
  12304. * function Foo() {
  12305. * this.a = _.constant('a');
  12306. * this.b = _.constant('b');
  12307. * }
  12308. *
  12309. * Foo.prototype.c = _.constant('c');
  12310. *
  12311. * _.functionsIn(new Foo);
  12312. * // => ['a', 'b', 'c']
  12313. */
  12314. function functionsIn(object) {
  12315. return object == null ? [] : baseFunctions(object, keysIn(object));
  12316. }
  12317. /**
  12318. * Gets the value at `path` of `object`. If the resolved value is
  12319. * `undefined`, the `defaultValue` is returned in its place.
  12320. *
  12321. * @static
  12322. * @memberOf _
  12323. * @since 3.7.0
  12324. * @category Object
  12325. * @param {Object} object The object to query.
  12326. * @param {Array|string} path The path of the property to get.
  12327. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12328. * @returns {*} Returns the resolved value.
  12329. * @example
  12330. *
  12331. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12332. *
  12333. * _.get(object, 'a[0].b.c');
  12334. * // => 3
  12335. *
  12336. * _.get(object, ['a', '0', 'b', 'c']);
  12337. * // => 3
  12338. *
  12339. * _.get(object, 'a.b.c', 'default');
  12340. * // => 'default'
  12341. */
  12342. function get(object, path, defaultValue) {
  12343. var result = object == null ? undefined : baseGet(object, path);
  12344. return result === undefined ? defaultValue : result;
  12345. }
  12346. /**
  12347. * Checks if `path` is a direct property of `object`.
  12348. *
  12349. * @static
  12350. * @since 0.1.0
  12351. * @memberOf _
  12352. * @category Object
  12353. * @param {Object} object The object to query.
  12354. * @param {Array|string} path The path to check.
  12355. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12356. * @example
  12357. *
  12358. * var object = { 'a': { 'b': 2 } };
  12359. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12360. *
  12361. * _.has(object, 'a');
  12362. * // => true
  12363. *
  12364. * _.has(object, 'a.b');
  12365. * // => true
  12366. *
  12367. * _.has(object, ['a', 'b']);
  12368. * // => true
  12369. *
  12370. * _.has(other, 'a');
  12371. * // => false
  12372. */
  12373. function has(object, path) {
  12374. return object != null && hasPath(object, path, baseHas);
  12375. }
  12376. /**
  12377. * Checks if `path` is a direct or inherited property of `object`.
  12378. *
  12379. * @static
  12380. * @memberOf _
  12381. * @since 4.0.0
  12382. * @category Object
  12383. * @param {Object} object The object to query.
  12384. * @param {Array|string} path The path to check.
  12385. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12386. * @example
  12387. *
  12388. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12389. *
  12390. * _.hasIn(object, 'a');
  12391. * // => true
  12392. *
  12393. * _.hasIn(object, 'a.b');
  12394. * // => true
  12395. *
  12396. * _.hasIn(object, ['a', 'b']);
  12397. * // => true
  12398. *
  12399. * _.hasIn(object, 'b');
  12400. * // => false
  12401. */
  12402. function hasIn(object, path) {
  12403. return object != null && hasPath(object, path, baseHasIn);
  12404. }
  12405. /**
  12406. * Creates an object composed of the inverted keys and values of `object`.
  12407. * If `object` contains duplicate values, subsequent values overwrite
  12408. * property assignments of previous values.
  12409. *
  12410. * @static
  12411. * @memberOf _
  12412. * @since 0.7.0
  12413. * @category Object
  12414. * @param {Object} object The object to invert.
  12415. * @returns {Object} Returns the new inverted object.
  12416. * @example
  12417. *
  12418. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12419. *
  12420. * _.invert(object);
  12421. * // => { '1': 'c', '2': 'b' }
  12422. */
  12423. var invert = createInverter(function(result, value, key) {
  12424. if (value != null &&
  12425. typeof value.toString != 'function') {
  12426. value = nativeObjectToString.call(value);
  12427. }
  12428. result[value] = key;
  12429. }, constant(identity));
  12430. /**
  12431. * This method is like `_.invert` except that the inverted object is generated
  12432. * from the results of running each element of `object` thru `iteratee`. The
  12433. * corresponding inverted value of each inverted key is an array of keys
  12434. * responsible for generating the inverted value. The iteratee is invoked
  12435. * with one argument: (value).
  12436. *
  12437. * @static
  12438. * @memberOf _
  12439. * @since 4.1.0
  12440. * @category Object
  12441. * @param {Object} object The object to invert.
  12442. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12443. * @returns {Object} Returns the new inverted object.
  12444. * @example
  12445. *
  12446. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12447. *
  12448. * _.invertBy(object);
  12449. * // => { '1': ['a', 'c'], '2': ['b'] }
  12450. *
  12451. * _.invertBy(object, function(value) {
  12452. * return 'group' + value;
  12453. * });
  12454. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12455. */
  12456. var invertBy = createInverter(function(result, value, key) {
  12457. if (value != null &&
  12458. typeof value.toString != 'function') {
  12459. value = nativeObjectToString.call(value);
  12460. }
  12461. if (hasOwnProperty.call(result, value)) {
  12462. result[value].push(key);
  12463. } else {
  12464. result[value] = [key];
  12465. }
  12466. }, getIteratee);
  12467. /**
  12468. * Invokes the method at `path` of `object`.
  12469. *
  12470. * @static
  12471. * @memberOf _
  12472. * @since 4.0.0
  12473. * @category Object
  12474. * @param {Object} object The object to query.
  12475. * @param {Array|string} path The path of the method to invoke.
  12476. * @param {...*} [args] The arguments to invoke the method with.
  12477. * @returns {*} Returns the result of the invoked method.
  12478. * @example
  12479. *
  12480. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12481. *
  12482. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12483. * // => [2, 3]
  12484. */
  12485. var invoke = baseRest(baseInvoke);
  12486. /**
  12487. * Creates an array of the own enumerable property names of `object`.
  12488. *
  12489. * **Note:** Non-object values are coerced to objects. See the
  12490. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12491. * for more details.
  12492. *
  12493. * @static
  12494. * @since 0.1.0
  12495. * @memberOf _
  12496. * @category Object
  12497. * @param {Object} object The object to query.
  12498. * @returns {Array} Returns the array of property names.
  12499. * @example
  12500. *
  12501. * function Foo() {
  12502. * this.a = 1;
  12503. * this.b = 2;
  12504. * }
  12505. *
  12506. * Foo.prototype.c = 3;
  12507. *
  12508. * _.keys(new Foo);
  12509. * // => ['a', 'b'] (iteration order is not guaranteed)
  12510. *
  12511. * _.keys('hi');
  12512. * // => ['0', '1']
  12513. */
  12514. function keys(object) {
  12515. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12516. }
  12517. /**
  12518. * Creates an array of the own and inherited enumerable property names of `object`.
  12519. *
  12520. * **Note:** Non-object values are coerced to objects.
  12521. *
  12522. * @static
  12523. * @memberOf _
  12524. * @since 3.0.0
  12525. * @category Object
  12526. * @param {Object} object The object to query.
  12527. * @returns {Array} Returns the array of property names.
  12528. * @example
  12529. *
  12530. * function Foo() {
  12531. * this.a = 1;
  12532. * this.b = 2;
  12533. * }
  12534. *
  12535. * Foo.prototype.c = 3;
  12536. *
  12537. * _.keysIn(new Foo);
  12538. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12539. */
  12540. function keysIn(object) {
  12541. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12542. }
  12543. /**
  12544. * The opposite of `_.mapValues`; this method creates an object with the
  12545. * same values as `object` and keys generated by running each own enumerable
  12546. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12547. * with three arguments: (value, key, object).
  12548. *
  12549. * @static
  12550. * @memberOf _
  12551. * @since 3.8.0
  12552. * @category Object
  12553. * @param {Object} object The object to iterate over.
  12554. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12555. * @returns {Object} Returns the new mapped object.
  12556. * @see _.mapValues
  12557. * @example
  12558. *
  12559. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12560. * return key + value;
  12561. * });
  12562. * // => { 'a1': 1, 'b2': 2 }
  12563. */
  12564. function mapKeys(object, iteratee) {
  12565. var result = {};
  12566. iteratee = getIteratee(iteratee, 3);
  12567. baseForOwn(object, function(value, key, object) {
  12568. baseAssignValue(result, iteratee(value, key, object), value);
  12569. });
  12570. return result;
  12571. }
  12572. /**
  12573. * Creates an object with the same keys as `object` and values generated
  12574. * by running each own enumerable string keyed property of `object` thru
  12575. * `iteratee`. The iteratee is invoked with three arguments:
  12576. * (value, key, object).
  12577. *
  12578. * @static
  12579. * @memberOf _
  12580. * @since 2.4.0
  12581. * @category Object
  12582. * @param {Object} object The object to iterate over.
  12583. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12584. * @returns {Object} Returns the new mapped object.
  12585. * @see _.mapKeys
  12586. * @example
  12587. *
  12588. * var users = {
  12589. * 'fred': { 'user': 'fred', 'age': 40 },
  12590. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12591. * };
  12592. *
  12593. * _.mapValues(users, function(o) { return o.age; });
  12594. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12595. *
  12596. * // The `_.property` iteratee shorthand.
  12597. * _.mapValues(users, 'age');
  12598. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12599. */
  12600. function mapValues(object, iteratee) {
  12601. var result = {};
  12602. iteratee = getIteratee(iteratee, 3);
  12603. baseForOwn(object, function(value, key, object) {
  12604. baseAssignValue(result, key, iteratee(value, key, object));
  12605. });
  12606. return result;
  12607. }
  12608. /**
  12609. * This method is like `_.assign` except that it recursively merges own and
  12610. * inherited enumerable string keyed properties of source objects into the
  12611. * destination object. Source properties that resolve to `undefined` are
  12612. * skipped if a destination value exists. Array and plain object properties
  12613. * are merged recursively. Other objects and value types are overridden by
  12614. * assignment. Source objects are applied from left to right. Subsequent
  12615. * sources overwrite property assignments of previous sources.
  12616. *
  12617. * **Note:** This method mutates `object`.
  12618. *
  12619. * @static
  12620. * @memberOf _
  12621. * @since 0.5.0
  12622. * @category Object
  12623. * @param {Object} object The destination object.
  12624. * @param {...Object} [sources] The source objects.
  12625. * @returns {Object} Returns `object`.
  12626. * @example
  12627. *
  12628. * var object = {
  12629. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12630. * };
  12631. *
  12632. * var other = {
  12633. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12634. * };
  12635. *
  12636. * _.merge(object, other);
  12637. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12638. */
  12639. var merge = createAssigner(function(object, source, srcIndex) {
  12640. baseMerge(object, source, srcIndex);
  12641. });
  12642. /**
  12643. * This method is like `_.merge` except that it accepts `customizer` which
  12644. * is invoked to produce the merged values of the destination and source
  12645. * properties. If `customizer` returns `undefined`, merging is handled by the
  12646. * method instead. The `customizer` is invoked with six arguments:
  12647. * (objValue, srcValue, key, object, source, stack).
  12648. *
  12649. * **Note:** This method mutates `object`.
  12650. *
  12651. * @static
  12652. * @memberOf _
  12653. * @since 4.0.0
  12654. * @category Object
  12655. * @param {Object} object The destination object.
  12656. * @param {...Object} sources The source objects.
  12657. * @param {Function} customizer The function to customize assigned values.
  12658. * @returns {Object} Returns `object`.
  12659. * @example
  12660. *
  12661. * function customizer(objValue, srcValue) {
  12662. * if (_.isArray(objValue)) {
  12663. * return objValue.concat(srcValue);
  12664. * }
  12665. * }
  12666. *
  12667. * var object = { 'a': [1], 'b': [2] };
  12668. * var other = { 'a': [3], 'b': [4] };
  12669. *
  12670. * _.mergeWith(object, other, customizer);
  12671. * // => { 'a': [1, 3], 'b': [2, 4] }
  12672. */
  12673. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12674. baseMerge(object, source, srcIndex, customizer);
  12675. });
  12676. /**
  12677. * The opposite of `_.pick`; this method creates an object composed of the
  12678. * own and inherited enumerable property paths of `object` that are not omitted.
  12679. *
  12680. * **Note:** This method is considerably slower than `_.pick`.
  12681. *
  12682. * @static
  12683. * @since 0.1.0
  12684. * @memberOf _
  12685. * @category Object
  12686. * @param {Object} object The source object.
  12687. * @param {...(string|string[])} [paths] The property paths to omit.
  12688. * @returns {Object} Returns the new object.
  12689. * @example
  12690. *
  12691. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12692. *
  12693. * _.omit(object, ['a', 'c']);
  12694. * // => { 'b': '2' }
  12695. */
  12696. var omit = flatRest(function(object, paths) {
  12697. var result = {};
  12698. if (object == null) {
  12699. return result;
  12700. }
  12701. var isDeep = false;
  12702. paths = arrayMap(paths, function(path) {
  12703. path = castPath(path, object);
  12704. isDeep || (isDeep = path.length > 1);
  12705. return path;
  12706. });
  12707. copyObject(object, getAllKeysIn(object), result);
  12708. if (isDeep) {
  12709. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12710. }
  12711. var length = paths.length;
  12712. while (length--) {
  12713. baseUnset(result, paths[length]);
  12714. }
  12715. return result;
  12716. });
  12717. /**
  12718. * The opposite of `_.pickBy`; this method creates an object composed of
  12719. * the own and inherited enumerable string keyed properties of `object` that
  12720. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12721. * arguments: (value, key).
  12722. *
  12723. * @static
  12724. * @memberOf _
  12725. * @since 4.0.0
  12726. * @category Object
  12727. * @param {Object} object The source object.
  12728. * @param {Function} [predicate=_.identity] The function invoked per property.
  12729. * @returns {Object} Returns the new object.
  12730. * @example
  12731. *
  12732. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12733. *
  12734. * _.omitBy(object, _.isNumber);
  12735. * // => { 'b': '2' }
  12736. */
  12737. function omitBy(object, predicate) {
  12738. return pickBy(object, negate(getIteratee(predicate)));
  12739. }
  12740. /**
  12741. * Creates an object composed of the picked `object` properties.
  12742. *
  12743. * @static
  12744. * @since 0.1.0
  12745. * @memberOf _
  12746. * @category Object
  12747. * @param {Object} object The source object.
  12748. * @param {...(string|string[])} [paths] The property paths to pick.
  12749. * @returns {Object} Returns the new object.
  12750. * @example
  12751. *
  12752. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12753. *
  12754. * _.pick(object, ['a', 'c']);
  12755. * // => { 'a': 1, 'c': 3 }
  12756. */
  12757. var pick = flatRest(function(object, paths) {
  12758. return object == null ? {} : basePick(object, paths);
  12759. });
  12760. /**
  12761. * Creates an object composed of the `object` properties `predicate` returns
  12762. * truthy for. The predicate is invoked with two arguments: (value, key).
  12763. *
  12764. * @static
  12765. * @memberOf _
  12766. * @since 4.0.0
  12767. * @category Object
  12768. * @param {Object} object The source object.
  12769. * @param {Function} [predicate=_.identity] The function invoked per property.
  12770. * @returns {Object} Returns the new object.
  12771. * @example
  12772. *
  12773. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12774. *
  12775. * _.pickBy(object, _.isNumber);
  12776. * // => { 'a': 1, 'c': 3 }
  12777. */
  12778. function pickBy(object, predicate) {
  12779. if (object == null) {
  12780. return {};
  12781. }
  12782. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12783. return [prop];
  12784. });
  12785. predicate = getIteratee(predicate);
  12786. return basePickBy(object, props, function(value, path) {
  12787. return predicate(value, path[0]);
  12788. });
  12789. }
  12790. /**
  12791. * This method is like `_.get` except that if the resolved value is a
  12792. * function it's invoked with the `this` binding of its parent object and
  12793. * its result is returned.
  12794. *
  12795. * @static
  12796. * @since 0.1.0
  12797. * @memberOf _
  12798. * @category Object
  12799. * @param {Object} object The object to query.
  12800. * @param {Array|string} path The path of the property to resolve.
  12801. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12802. * @returns {*} Returns the resolved value.
  12803. * @example
  12804. *
  12805. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12806. *
  12807. * _.result(object, 'a[0].b.c1');
  12808. * // => 3
  12809. *
  12810. * _.result(object, 'a[0].b.c2');
  12811. * // => 4
  12812. *
  12813. * _.result(object, 'a[0].b.c3', 'default');
  12814. * // => 'default'
  12815. *
  12816. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12817. * // => 'default'
  12818. */
  12819. function result(object, path, defaultValue) {
  12820. path = castPath(path, object);
  12821. var index = -1,
  12822. length = path.length;
  12823. // Ensure the loop is entered when path is empty.
  12824. if (!length) {
  12825. length = 1;
  12826. object = undefined;
  12827. }
  12828. while (++index < length) {
  12829. var value = object == null ? undefined : object[toKey(path[index])];
  12830. if (value === undefined) {
  12831. index = length;
  12832. value = defaultValue;
  12833. }
  12834. object = isFunction(value) ? value.call(object) : value;
  12835. }
  12836. return object;
  12837. }
  12838. /**
  12839. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12840. * it's created. Arrays are created for missing index properties while objects
  12841. * are created for all other missing properties. Use `_.setWith` to customize
  12842. * `path` creation.
  12843. *
  12844. * **Note:** This method mutates `object`.
  12845. *
  12846. * @static
  12847. * @memberOf _
  12848. * @since 3.7.0
  12849. * @category Object
  12850. * @param {Object} object The object to modify.
  12851. * @param {Array|string} path The path of the property to set.
  12852. * @param {*} value The value to set.
  12853. * @returns {Object} Returns `object`.
  12854. * @example
  12855. *
  12856. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12857. *
  12858. * _.set(object, 'a[0].b.c', 4);
  12859. * console.log(object.a[0].b.c);
  12860. * // => 4
  12861. *
  12862. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12863. * console.log(object.x[0].y.z);
  12864. * // => 5
  12865. */
  12866. function set(object, path, value) {
  12867. return object == null ? object : baseSet(object, path, value);
  12868. }
  12869. /**
  12870. * This method is like `_.set` except that it accepts `customizer` which is
  12871. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12872. * path creation is handled by the method instead. The `customizer` is invoked
  12873. * with three arguments: (nsValue, key, nsObject).
  12874. *
  12875. * **Note:** This method mutates `object`.
  12876. *
  12877. * @static
  12878. * @memberOf _
  12879. * @since 4.0.0
  12880. * @category Object
  12881. * @param {Object} object The object to modify.
  12882. * @param {Array|string} path The path of the property to set.
  12883. * @param {*} value The value to set.
  12884. * @param {Function} [customizer] The function to customize assigned values.
  12885. * @returns {Object} Returns `object`.
  12886. * @example
  12887. *
  12888. * var object = {};
  12889. *
  12890. * _.setWith(object, '[0][1]', 'a', Object);
  12891. * // => { '0': { '1': 'a' } }
  12892. */
  12893. function setWith(object, path, value, customizer) {
  12894. customizer = typeof customizer == 'function' ? customizer : undefined;
  12895. return object == null ? object : baseSet(object, path, value, customizer);
  12896. }
  12897. /**
  12898. * Creates an array of own enumerable string keyed-value pairs for `object`
  12899. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12900. * entries are returned.
  12901. *
  12902. * @static
  12903. * @memberOf _
  12904. * @since 4.0.0
  12905. * @alias entries
  12906. * @category Object
  12907. * @param {Object} object The object to query.
  12908. * @returns {Array} Returns the key-value pairs.
  12909. * @example
  12910. *
  12911. * function Foo() {
  12912. * this.a = 1;
  12913. * this.b = 2;
  12914. * }
  12915. *
  12916. * Foo.prototype.c = 3;
  12917. *
  12918. * _.toPairs(new Foo);
  12919. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12920. */
  12921. var toPairs = createToPairs(keys);
  12922. /**
  12923. * Creates an array of own and inherited enumerable string keyed-value pairs
  12924. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12925. * or set, its entries are returned.
  12926. *
  12927. * @static
  12928. * @memberOf _
  12929. * @since 4.0.0
  12930. * @alias entriesIn
  12931. * @category Object
  12932. * @param {Object} object The object to query.
  12933. * @returns {Array} Returns the key-value pairs.
  12934. * @example
  12935. *
  12936. * function Foo() {
  12937. * this.a = 1;
  12938. * this.b = 2;
  12939. * }
  12940. *
  12941. * Foo.prototype.c = 3;
  12942. *
  12943. * _.toPairsIn(new Foo);
  12944. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12945. */
  12946. var toPairsIn = createToPairs(keysIn);
  12947. /**
  12948. * An alternative to `_.reduce`; this method transforms `object` to a new
  12949. * `accumulator` object which is the result of running each of its own
  12950. * enumerable string keyed properties thru `iteratee`, with each invocation
  12951. * potentially mutating the `accumulator` object. If `accumulator` is not
  12952. * provided, a new object with the same `[[Prototype]]` will be used. The
  12953. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12954. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12955. *
  12956. * @static
  12957. * @memberOf _
  12958. * @since 1.3.0
  12959. * @category Object
  12960. * @param {Object} object The object to iterate over.
  12961. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12962. * @param {*} [accumulator] The custom accumulator value.
  12963. * @returns {*} Returns the accumulated value.
  12964. * @example
  12965. *
  12966. * _.transform([2, 3, 4], function(result, n) {
  12967. * result.push(n *= n);
  12968. * return n % 2 == 0;
  12969. * }, []);
  12970. * // => [4, 9]
  12971. *
  12972. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12973. * (result[value] || (result[value] = [])).push(key);
  12974. * }, {});
  12975. * // => { '1': ['a', 'c'], '2': ['b'] }
  12976. */
  12977. function transform(object, iteratee, accumulator) {
  12978. var isArr = isArray(object),
  12979. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12980. iteratee = getIteratee(iteratee, 4);
  12981. if (accumulator == null) {
  12982. var Ctor = object && object.constructor;
  12983. if (isArrLike) {
  12984. accumulator = isArr ? new Ctor : [];
  12985. }
  12986. else if (isObject(object)) {
  12987. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12988. }
  12989. else {
  12990. accumulator = {};
  12991. }
  12992. }
  12993. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12994. return iteratee(accumulator, value, index, object);
  12995. });
  12996. return accumulator;
  12997. }
  12998. /**
  12999. * Removes the property at `path` of `object`.
  13000. *
  13001. * **Note:** This method mutates `object`.
  13002. *
  13003. * @static
  13004. * @memberOf _
  13005. * @since 4.0.0
  13006. * @category Object
  13007. * @param {Object} object The object to modify.
  13008. * @param {Array|string} path The path of the property to unset.
  13009. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13010. * @example
  13011. *
  13012. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13013. * _.unset(object, 'a[0].b.c');
  13014. * // => true
  13015. *
  13016. * console.log(object);
  13017. * // => { 'a': [{ 'b': {} }] };
  13018. *
  13019. * _.unset(object, ['a', '0', 'b', 'c']);
  13020. * // => true
  13021. *
  13022. * console.log(object);
  13023. * // => { 'a': [{ 'b': {} }] };
  13024. */
  13025. function unset(object, path) {
  13026. return object == null ? true : baseUnset(object, path);
  13027. }
  13028. /**
  13029. * This method is like `_.set` except that accepts `updater` to produce the
  13030. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13031. * is invoked with one argument: (value).
  13032. *
  13033. * **Note:** This method mutates `object`.
  13034. *
  13035. * @static
  13036. * @memberOf _
  13037. * @since 4.6.0
  13038. * @category Object
  13039. * @param {Object} object The object to modify.
  13040. * @param {Array|string} path The path of the property to set.
  13041. * @param {Function} updater The function to produce the updated value.
  13042. * @returns {Object} Returns `object`.
  13043. * @example
  13044. *
  13045. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13046. *
  13047. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13048. * console.log(object.a[0].b.c);
  13049. * // => 9
  13050. *
  13051. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13052. * console.log(object.x[0].y.z);
  13053. * // => 0
  13054. */
  13055. function update(object, path, updater) {
  13056. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13057. }
  13058. /**
  13059. * This method is like `_.update` except that it accepts `customizer` which is
  13060. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13061. * path creation is handled by the method instead. The `customizer` is invoked
  13062. * with three arguments: (nsValue, key, nsObject).
  13063. *
  13064. * **Note:** This method mutates `object`.
  13065. *
  13066. * @static
  13067. * @memberOf _
  13068. * @since 4.6.0
  13069. * @category Object
  13070. * @param {Object} object The object to modify.
  13071. * @param {Array|string} path The path of the property to set.
  13072. * @param {Function} updater The function to produce the updated value.
  13073. * @param {Function} [customizer] The function to customize assigned values.
  13074. * @returns {Object} Returns `object`.
  13075. * @example
  13076. *
  13077. * var object = {};
  13078. *
  13079. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13080. * // => { '0': { '1': 'a' } }
  13081. */
  13082. function updateWith(object, path, updater, customizer) {
  13083. customizer = typeof customizer == 'function' ? customizer : undefined;
  13084. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13085. }
  13086. /**
  13087. * Creates an array of the own enumerable string keyed property values of `object`.
  13088. *
  13089. * **Note:** Non-object values are coerced to objects.
  13090. *
  13091. * @static
  13092. * @since 0.1.0
  13093. * @memberOf _
  13094. * @category Object
  13095. * @param {Object} object The object to query.
  13096. * @returns {Array} Returns the array of property values.
  13097. * @example
  13098. *
  13099. * function Foo() {
  13100. * this.a = 1;
  13101. * this.b = 2;
  13102. * }
  13103. *
  13104. * Foo.prototype.c = 3;
  13105. *
  13106. * _.values(new Foo);
  13107. * // => [1, 2] (iteration order is not guaranteed)
  13108. *
  13109. * _.values('hi');
  13110. * // => ['h', 'i']
  13111. */
  13112. function values(object) {
  13113. return object == null ? [] : baseValues(object, keys(object));
  13114. }
  13115. /**
  13116. * Creates an array of the own and inherited enumerable string keyed property
  13117. * values of `object`.
  13118. *
  13119. * **Note:** Non-object values are coerced to objects.
  13120. *
  13121. * @static
  13122. * @memberOf _
  13123. * @since 3.0.0
  13124. * @category Object
  13125. * @param {Object} object The object to query.
  13126. * @returns {Array} Returns the array of property values.
  13127. * @example
  13128. *
  13129. * function Foo() {
  13130. * this.a = 1;
  13131. * this.b = 2;
  13132. * }
  13133. *
  13134. * Foo.prototype.c = 3;
  13135. *
  13136. * _.valuesIn(new Foo);
  13137. * // => [1, 2, 3] (iteration order is not guaranteed)
  13138. */
  13139. function valuesIn(object) {
  13140. return object == null ? [] : baseValues(object, keysIn(object));
  13141. }
  13142. /*------------------------------------------------------------------------*/
  13143. /**
  13144. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13145. *
  13146. * @static
  13147. * @memberOf _
  13148. * @since 4.0.0
  13149. * @category Number
  13150. * @param {number} number The number to clamp.
  13151. * @param {number} [lower] The lower bound.
  13152. * @param {number} upper The upper bound.
  13153. * @returns {number} Returns the clamped number.
  13154. * @example
  13155. *
  13156. * _.clamp(-10, -5, 5);
  13157. * // => -5
  13158. *
  13159. * _.clamp(10, -5, 5);
  13160. * // => 5
  13161. */
  13162. function clamp(number, lower, upper) {
  13163. if (upper === undefined) {
  13164. upper = lower;
  13165. lower = undefined;
  13166. }
  13167. if (upper !== undefined) {
  13168. upper = toNumber(upper);
  13169. upper = upper === upper ? upper : 0;
  13170. }
  13171. if (lower !== undefined) {
  13172. lower = toNumber(lower);
  13173. lower = lower === lower ? lower : 0;
  13174. }
  13175. return baseClamp(toNumber(number), lower, upper);
  13176. }
  13177. /**
  13178. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13179. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13180. * If `start` is greater than `end` the params are swapped to support
  13181. * negative ranges.
  13182. *
  13183. * @static
  13184. * @memberOf _
  13185. * @since 3.3.0
  13186. * @category Number
  13187. * @param {number} number The number to check.
  13188. * @param {number} [start=0] The start of the range.
  13189. * @param {number} end The end of the range.
  13190. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13191. * @see _.range, _.rangeRight
  13192. * @example
  13193. *
  13194. * _.inRange(3, 2, 4);
  13195. * // => true
  13196. *
  13197. * _.inRange(4, 8);
  13198. * // => true
  13199. *
  13200. * _.inRange(4, 2);
  13201. * // => false
  13202. *
  13203. * _.inRange(2, 2);
  13204. * // => false
  13205. *
  13206. * _.inRange(1.2, 2);
  13207. * // => true
  13208. *
  13209. * _.inRange(5.2, 4);
  13210. * // => false
  13211. *
  13212. * _.inRange(-3, -2, -6);
  13213. * // => true
  13214. */
  13215. function inRange(number, start, end) {
  13216. start = toFinite(start);
  13217. if (end === undefined) {
  13218. end = start;
  13219. start = 0;
  13220. } else {
  13221. end = toFinite(end);
  13222. }
  13223. number = toNumber(number);
  13224. return baseInRange(number, start, end);
  13225. }
  13226. /**
  13227. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13228. * If only one argument is provided a number between `0` and the given number
  13229. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13230. * floats, a floating-point number is returned instead of an integer.
  13231. *
  13232. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13233. * floating-point values which can produce unexpected results.
  13234. *
  13235. * @static
  13236. * @memberOf _
  13237. * @since 0.7.0
  13238. * @category Number
  13239. * @param {number} [lower=0] The lower bound.
  13240. * @param {number} [upper=1] The upper bound.
  13241. * @param {boolean} [floating] Specify returning a floating-point number.
  13242. * @returns {number} Returns the random number.
  13243. * @example
  13244. *
  13245. * _.random(0, 5);
  13246. * // => an integer between 0 and 5
  13247. *
  13248. * _.random(5);
  13249. * // => also an integer between 0 and 5
  13250. *
  13251. * _.random(5, true);
  13252. * // => a floating-point number between 0 and 5
  13253. *
  13254. * _.random(1.2, 5.2);
  13255. * // => a floating-point number between 1.2 and 5.2
  13256. */
  13257. function random(lower, upper, floating) {
  13258. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13259. upper = floating = undefined;
  13260. }
  13261. if (floating === undefined) {
  13262. if (typeof upper == 'boolean') {
  13263. floating = upper;
  13264. upper = undefined;
  13265. }
  13266. else if (typeof lower == 'boolean') {
  13267. floating = lower;
  13268. lower = undefined;
  13269. }
  13270. }
  13271. if (lower === undefined && upper === undefined) {
  13272. lower = 0;
  13273. upper = 1;
  13274. }
  13275. else {
  13276. lower = toFinite(lower);
  13277. if (upper === undefined) {
  13278. upper = lower;
  13279. lower = 0;
  13280. } else {
  13281. upper = toFinite(upper);
  13282. }
  13283. }
  13284. if (lower > upper) {
  13285. var temp = lower;
  13286. lower = upper;
  13287. upper = temp;
  13288. }
  13289. if (floating || lower % 1 || upper % 1) {
  13290. var rand = nativeRandom();
  13291. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13292. }
  13293. return baseRandom(lower, upper);
  13294. }
  13295. /*------------------------------------------------------------------------*/
  13296. /**
  13297. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13298. *
  13299. * @static
  13300. * @memberOf _
  13301. * @since 3.0.0
  13302. * @category String
  13303. * @param {string} [string=''] The string to convert.
  13304. * @returns {string} Returns the camel cased string.
  13305. * @example
  13306. *
  13307. * _.camelCase('Foo Bar');
  13308. * // => 'fooBar'
  13309. *
  13310. * _.camelCase('--foo-bar--');
  13311. * // => 'fooBar'
  13312. *
  13313. * _.camelCase('__FOO_BAR__');
  13314. * // => 'fooBar'
  13315. */
  13316. var camelCase = createCompounder(function(result, word, index) {
  13317. word = word.toLowerCase();
  13318. return result + (index ? capitalize(word) : word);
  13319. });
  13320. /**
  13321. * Converts the first character of `string` to upper case and the remaining
  13322. * to lower case.
  13323. *
  13324. * @static
  13325. * @memberOf _
  13326. * @since 3.0.0
  13327. * @category String
  13328. * @param {string} [string=''] The string to capitalize.
  13329. * @returns {string} Returns the capitalized string.
  13330. * @example
  13331. *
  13332. * _.capitalize('FRED');
  13333. * // => 'Fred'
  13334. */
  13335. function capitalize(string) {
  13336. return upperFirst(toString(string).toLowerCase());
  13337. }
  13338. /**
  13339. * Deburrs `string` by converting
  13340. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13341. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13342. * letters to basic Latin letters and removing
  13343. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13344. *
  13345. * @static
  13346. * @memberOf _
  13347. * @since 3.0.0
  13348. * @category String
  13349. * @param {string} [string=''] The string to deburr.
  13350. * @returns {string} Returns the deburred string.
  13351. * @example
  13352. *
  13353. * _.deburr('déjà vu');
  13354. * // => 'deja vu'
  13355. */
  13356. function deburr(string) {
  13357. string = toString(string);
  13358. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13359. }
  13360. /**
  13361. * Checks if `string` ends with the given target string.
  13362. *
  13363. * @static
  13364. * @memberOf _
  13365. * @since 3.0.0
  13366. * @category String
  13367. * @param {string} [string=''] The string to inspect.
  13368. * @param {string} [target] The string to search for.
  13369. * @param {number} [position=string.length] The position to search up to.
  13370. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13371. * else `false`.
  13372. * @example
  13373. *
  13374. * _.endsWith('abc', 'c');
  13375. * // => true
  13376. *
  13377. * _.endsWith('abc', 'b');
  13378. * // => false
  13379. *
  13380. * _.endsWith('abc', 'b', 2);
  13381. * // => true
  13382. */
  13383. function endsWith(string, target, position) {
  13384. string = toString(string);
  13385. target = baseToString(target);
  13386. var length = string.length;
  13387. position = position === undefined
  13388. ? length
  13389. : baseClamp(toInteger(position), 0, length);
  13390. var end = position;
  13391. position -= target.length;
  13392. return position >= 0 && string.slice(position, end) == target;
  13393. }
  13394. /**
  13395. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13396. * corresponding HTML entities.
  13397. *
  13398. * **Note:** No other characters are escaped. To escape additional
  13399. * characters use a third-party library like [_he_](https://mths.be/he).
  13400. *
  13401. * Though the ">" character is escaped for symmetry, characters like
  13402. * ">" and "/" don't need escaping in HTML and have no special meaning
  13403. * unless they're part of a tag or unquoted attribute value. See
  13404. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13405. * (under "semi-related fun fact") for more details.
  13406. *
  13407. * When working with HTML you should always
  13408. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13409. * XSS vectors.
  13410. *
  13411. * @static
  13412. * @since 0.1.0
  13413. * @memberOf _
  13414. * @category String
  13415. * @param {string} [string=''] The string to escape.
  13416. * @returns {string} Returns the escaped string.
  13417. * @example
  13418. *
  13419. * _.escape('fred, barney, & pebbles');
  13420. * // => 'fred, barney, &amp; pebbles'
  13421. */
  13422. function escape(string) {
  13423. string = toString(string);
  13424. return (string && reHasUnescapedHtml.test(string))
  13425. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13426. : string;
  13427. }
  13428. /**
  13429. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13430. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13431. *
  13432. * @static
  13433. * @memberOf _
  13434. * @since 3.0.0
  13435. * @category String
  13436. * @param {string} [string=''] The string to escape.
  13437. * @returns {string} Returns the escaped string.
  13438. * @example
  13439. *
  13440. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13441. * // => '\[lodash\]\(https://lodash\.com/\)'
  13442. */
  13443. function escapeRegExp(string) {
  13444. string = toString(string);
  13445. return (string && reHasRegExpChar.test(string))
  13446. ? string.replace(reRegExpChar, '\\$&')
  13447. : string;
  13448. }
  13449. /**
  13450. * Converts `string` to
  13451. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13452. *
  13453. * @static
  13454. * @memberOf _
  13455. * @since 3.0.0
  13456. * @category String
  13457. * @param {string} [string=''] The string to convert.
  13458. * @returns {string} Returns the kebab cased string.
  13459. * @example
  13460. *
  13461. * _.kebabCase('Foo Bar');
  13462. * // => 'foo-bar'
  13463. *
  13464. * _.kebabCase('fooBar');
  13465. * // => 'foo-bar'
  13466. *
  13467. * _.kebabCase('__FOO_BAR__');
  13468. * // => 'foo-bar'
  13469. */
  13470. var kebabCase = createCompounder(function(result, word, index) {
  13471. return result + (index ? '-' : '') + word.toLowerCase();
  13472. });
  13473. /**
  13474. * Converts `string`, as space separated words, to lower case.
  13475. *
  13476. * @static
  13477. * @memberOf _
  13478. * @since 4.0.0
  13479. * @category String
  13480. * @param {string} [string=''] The string to convert.
  13481. * @returns {string} Returns the lower cased string.
  13482. * @example
  13483. *
  13484. * _.lowerCase('--Foo-Bar--');
  13485. * // => 'foo bar'
  13486. *
  13487. * _.lowerCase('fooBar');
  13488. * // => 'foo bar'
  13489. *
  13490. * _.lowerCase('__FOO_BAR__');
  13491. * // => 'foo bar'
  13492. */
  13493. var lowerCase = createCompounder(function(result, word, index) {
  13494. return result + (index ? ' ' : '') + word.toLowerCase();
  13495. });
  13496. /**
  13497. * Converts the first character of `string` to lower case.
  13498. *
  13499. * @static
  13500. * @memberOf _
  13501. * @since 4.0.0
  13502. * @category String
  13503. * @param {string} [string=''] The string to convert.
  13504. * @returns {string} Returns the converted string.
  13505. * @example
  13506. *
  13507. * _.lowerFirst('Fred');
  13508. * // => 'fred'
  13509. *
  13510. * _.lowerFirst('FRED');
  13511. * // => 'fRED'
  13512. */
  13513. var lowerFirst = createCaseFirst('toLowerCase');
  13514. /**
  13515. * Pads `string` on the left and right sides if it's shorter than `length`.
  13516. * Padding characters are truncated if they can't be evenly divided by `length`.
  13517. *
  13518. * @static
  13519. * @memberOf _
  13520. * @since 3.0.0
  13521. * @category String
  13522. * @param {string} [string=''] The string to pad.
  13523. * @param {number} [length=0] The padding length.
  13524. * @param {string} [chars=' '] The string used as padding.
  13525. * @returns {string} Returns the padded string.
  13526. * @example
  13527. *
  13528. * _.pad('abc', 8);
  13529. * // => ' abc '
  13530. *
  13531. * _.pad('abc', 8, '_-');
  13532. * // => '_-abc_-_'
  13533. *
  13534. * _.pad('abc', 3);
  13535. * // => 'abc'
  13536. */
  13537. function pad(string, length, chars) {
  13538. string = toString(string);
  13539. length = toInteger(length);
  13540. var strLength = length ? stringSize(string) : 0;
  13541. if (!length || strLength >= length) {
  13542. return string;
  13543. }
  13544. var mid = (length - strLength) / 2;
  13545. return (
  13546. createPadding(nativeFloor(mid), chars) +
  13547. string +
  13548. createPadding(nativeCeil(mid), chars)
  13549. );
  13550. }
  13551. /**
  13552. * Pads `string` on the right side if it's shorter than `length`. Padding
  13553. * characters are truncated if they exceed `length`.
  13554. *
  13555. * @static
  13556. * @memberOf _
  13557. * @since 4.0.0
  13558. * @category String
  13559. * @param {string} [string=''] The string to pad.
  13560. * @param {number} [length=0] The padding length.
  13561. * @param {string} [chars=' '] The string used as padding.
  13562. * @returns {string} Returns the padded string.
  13563. * @example
  13564. *
  13565. * _.padEnd('abc', 6);
  13566. * // => 'abc '
  13567. *
  13568. * _.padEnd('abc', 6, '_-');
  13569. * // => 'abc_-_'
  13570. *
  13571. * _.padEnd('abc', 3);
  13572. * // => 'abc'
  13573. */
  13574. function padEnd(string, length, chars) {
  13575. string = toString(string);
  13576. length = toInteger(length);
  13577. var strLength = length ? stringSize(string) : 0;
  13578. return (length && strLength < length)
  13579. ? (string + createPadding(length - strLength, chars))
  13580. : string;
  13581. }
  13582. /**
  13583. * Pads `string` on the left side if it's shorter than `length`. Padding
  13584. * characters are truncated if they exceed `length`.
  13585. *
  13586. * @static
  13587. * @memberOf _
  13588. * @since 4.0.0
  13589. * @category String
  13590. * @param {string} [string=''] The string to pad.
  13591. * @param {number} [length=0] The padding length.
  13592. * @param {string} [chars=' '] The string used as padding.
  13593. * @returns {string} Returns the padded string.
  13594. * @example
  13595. *
  13596. * _.padStart('abc', 6);
  13597. * // => ' abc'
  13598. *
  13599. * _.padStart('abc', 6, '_-');
  13600. * // => '_-_abc'
  13601. *
  13602. * _.padStart('abc', 3);
  13603. * // => 'abc'
  13604. */
  13605. function padStart(string, length, chars) {
  13606. string = toString(string);
  13607. length = toInteger(length);
  13608. var strLength = length ? stringSize(string) : 0;
  13609. return (length && strLength < length)
  13610. ? (createPadding(length - strLength, chars) + string)
  13611. : string;
  13612. }
  13613. /**
  13614. * Converts `string` to an integer of the specified radix. If `radix` is
  13615. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13616. * hexadecimal, in which case a `radix` of `16` is used.
  13617. *
  13618. * **Note:** This method aligns with the
  13619. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13620. *
  13621. * @static
  13622. * @memberOf _
  13623. * @since 1.1.0
  13624. * @category String
  13625. * @param {string} string The string to convert.
  13626. * @param {number} [radix=10] The radix to interpret `value` by.
  13627. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13628. * @returns {number} Returns the converted integer.
  13629. * @example
  13630. *
  13631. * _.parseInt('08');
  13632. * // => 8
  13633. *
  13634. * _.map(['6', '08', '10'], _.parseInt);
  13635. * // => [6, 8, 10]
  13636. */
  13637. function parseInt(string, radix, guard) {
  13638. if (guard || radix == null) {
  13639. radix = 0;
  13640. } else if (radix) {
  13641. radix = +radix;
  13642. }
  13643. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13644. }
  13645. /**
  13646. * Repeats the given string `n` times.
  13647. *
  13648. * @static
  13649. * @memberOf _
  13650. * @since 3.0.0
  13651. * @category String
  13652. * @param {string} [string=''] The string to repeat.
  13653. * @param {number} [n=1] The number of times to repeat the string.
  13654. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13655. * @returns {string} Returns the repeated string.
  13656. * @example
  13657. *
  13658. * _.repeat('*', 3);
  13659. * // => '***'
  13660. *
  13661. * _.repeat('abc', 2);
  13662. * // => 'abcabc'
  13663. *
  13664. * _.repeat('abc', 0);
  13665. * // => ''
  13666. */
  13667. function repeat(string, n, guard) {
  13668. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13669. n = 1;
  13670. } else {
  13671. n = toInteger(n);
  13672. }
  13673. return baseRepeat(toString(string), n);
  13674. }
  13675. /**
  13676. * Replaces matches for `pattern` in `string` with `replacement`.
  13677. *
  13678. * **Note:** This method is based on
  13679. * [`String#replace`](https://mdn.io/String/replace).
  13680. *
  13681. * @static
  13682. * @memberOf _
  13683. * @since 4.0.0
  13684. * @category String
  13685. * @param {string} [string=''] The string to modify.
  13686. * @param {RegExp|string} pattern The pattern to replace.
  13687. * @param {Function|string} replacement The match replacement.
  13688. * @returns {string} Returns the modified string.
  13689. * @example
  13690. *
  13691. * _.replace('Hi Fred', 'Fred', 'Barney');
  13692. * // => 'Hi Barney'
  13693. */
  13694. function replace() {
  13695. var args = arguments,
  13696. string = toString(args[0]);
  13697. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13698. }
  13699. /**
  13700. * Converts `string` to
  13701. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13702. *
  13703. * @static
  13704. * @memberOf _
  13705. * @since 3.0.0
  13706. * @category String
  13707. * @param {string} [string=''] The string to convert.
  13708. * @returns {string} Returns the snake cased string.
  13709. * @example
  13710. *
  13711. * _.snakeCase('Foo Bar');
  13712. * // => 'foo_bar'
  13713. *
  13714. * _.snakeCase('fooBar');
  13715. * // => 'foo_bar'
  13716. *
  13717. * _.snakeCase('--FOO-BAR--');
  13718. * // => 'foo_bar'
  13719. */
  13720. var snakeCase = createCompounder(function(result, word, index) {
  13721. return result + (index ? '_' : '') + word.toLowerCase();
  13722. });
  13723. /**
  13724. * Splits `string` by `separator`.
  13725. *
  13726. * **Note:** This method is based on
  13727. * [`String#split`](https://mdn.io/String/split).
  13728. *
  13729. * @static
  13730. * @memberOf _
  13731. * @since 4.0.0
  13732. * @category String
  13733. * @param {string} [string=''] The string to split.
  13734. * @param {RegExp|string} separator The separator pattern to split by.
  13735. * @param {number} [limit] The length to truncate results to.
  13736. * @returns {Array} Returns the string segments.
  13737. * @example
  13738. *
  13739. * _.split('a-b-c', '-', 2);
  13740. * // => ['a', 'b']
  13741. */
  13742. function split(string, separator, limit) {
  13743. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13744. separator = limit = undefined;
  13745. }
  13746. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13747. if (!limit) {
  13748. return [];
  13749. }
  13750. string = toString(string);
  13751. if (string && (
  13752. typeof separator == 'string' ||
  13753. (separator != null && !isRegExp(separator))
  13754. )) {
  13755. separator = baseToString(separator);
  13756. if (!separator && hasUnicode(string)) {
  13757. return castSlice(stringToArray(string), 0, limit);
  13758. }
  13759. }
  13760. return string.split(separator, limit);
  13761. }
  13762. /**
  13763. * Converts `string` to
  13764. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13765. *
  13766. * @static
  13767. * @memberOf _
  13768. * @since 3.1.0
  13769. * @category String
  13770. * @param {string} [string=''] The string to convert.
  13771. * @returns {string} Returns the start cased string.
  13772. * @example
  13773. *
  13774. * _.startCase('--foo-bar--');
  13775. * // => 'Foo Bar'
  13776. *
  13777. * _.startCase('fooBar');
  13778. * // => 'Foo Bar'
  13779. *
  13780. * _.startCase('__FOO_BAR__');
  13781. * // => 'FOO BAR'
  13782. */
  13783. var startCase = createCompounder(function(result, word, index) {
  13784. return result + (index ? ' ' : '') + upperFirst(word);
  13785. });
  13786. /**
  13787. * Checks if `string` starts with the given target string.
  13788. *
  13789. * @static
  13790. * @memberOf _
  13791. * @since 3.0.0
  13792. * @category String
  13793. * @param {string} [string=''] The string to inspect.
  13794. * @param {string} [target] The string to search for.
  13795. * @param {number} [position=0] The position to search from.
  13796. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13797. * else `false`.
  13798. * @example
  13799. *
  13800. * _.startsWith('abc', 'a');
  13801. * // => true
  13802. *
  13803. * _.startsWith('abc', 'b');
  13804. * // => false
  13805. *
  13806. * _.startsWith('abc', 'b', 1);
  13807. * // => true
  13808. */
  13809. function startsWith(string, target, position) {
  13810. string = toString(string);
  13811. position = position == null
  13812. ? 0
  13813. : baseClamp(toInteger(position), 0, string.length);
  13814. target = baseToString(target);
  13815. return string.slice(position, position + target.length) == target;
  13816. }
  13817. /**
  13818. * Creates a compiled template function that can interpolate data properties
  13819. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13820. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13821. * properties may be accessed as free variables in the template. If a setting
  13822. * object is given, it takes precedence over `_.templateSettings` values.
  13823. *
  13824. * **Note:** In the development build `_.template` utilizes
  13825. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13826. * for easier debugging.
  13827. *
  13828. * For more information on precompiling templates see
  13829. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13830. *
  13831. * For more information on Chrome extension sandboxes see
  13832. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13833. *
  13834. * @static
  13835. * @since 0.1.0
  13836. * @memberOf _
  13837. * @category String
  13838. * @param {string} [string=''] The template string.
  13839. * @param {Object} [options={}] The options object.
  13840. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13841. * The HTML "escape" delimiter.
  13842. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13843. * The "evaluate" delimiter.
  13844. * @param {Object} [options.imports=_.templateSettings.imports]
  13845. * An object to import into the template as free variables.
  13846. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13847. * The "interpolate" delimiter.
  13848. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13849. * The sourceURL of the compiled template.
  13850. * @param {string} [options.variable='obj']
  13851. * The data object variable name.
  13852. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13853. * @returns {Function} Returns the compiled template function.
  13854. * @example
  13855. *
  13856. * // Use the "interpolate" delimiter to create a compiled template.
  13857. * var compiled = _.template('hello <%= user %>!');
  13858. * compiled({ 'user': 'fred' });
  13859. * // => 'hello fred!'
  13860. *
  13861. * // Use the HTML "escape" delimiter to escape data property values.
  13862. * var compiled = _.template('<b><%- value %></b>');
  13863. * compiled({ 'value': '<script>' });
  13864. * // => '<b>&lt;script&gt;</b>'
  13865. *
  13866. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13867. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13868. * compiled({ 'users': ['fred', 'barney'] });
  13869. * // => '<li>fred</li><li>barney</li>'
  13870. *
  13871. * // Use the internal `print` function in "evaluate" delimiters.
  13872. * var compiled = _.template('<% print("hello " + user); %>!');
  13873. * compiled({ 'user': 'barney' });
  13874. * // => 'hello barney!'
  13875. *
  13876. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13877. * // Disable support by replacing the "interpolate" delimiter.
  13878. * var compiled = _.template('hello ${ user }!');
  13879. * compiled({ 'user': 'pebbles' });
  13880. * // => 'hello pebbles!'
  13881. *
  13882. * // Use backslashes to treat delimiters as plain text.
  13883. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13884. * compiled({ 'value': 'ignored' });
  13885. * // => '<%- value %>'
  13886. *
  13887. * // Use the `imports` option to import `jQuery` as `jq`.
  13888. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13889. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13890. * compiled({ 'users': ['fred', 'barney'] });
  13891. * // => '<li>fred</li><li>barney</li>'
  13892. *
  13893. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13894. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13895. * compiled(data);
  13896. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13897. *
  13898. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13899. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13900. * compiled.source;
  13901. * // => function(data) {
  13902. * // var __t, __p = '';
  13903. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13904. * // return __p;
  13905. * // }
  13906. *
  13907. * // Use custom template delimiters.
  13908. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13909. * var compiled = _.template('hello {{ user }}!');
  13910. * compiled({ 'user': 'mustache' });
  13911. * // => 'hello mustache!'
  13912. *
  13913. * // Use the `source` property to inline compiled templates for meaningful
  13914. * // line numbers in error messages and stack traces.
  13915. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13916. * var JST = {\
  13917. * "main": ' + _.template(mainText).source + '\
  13918. * };\
  13919. * ');
  13920. */
  13921. function template(string, options, guard) {
  13922. // Based on John Resig's `tmpl` implementation
  13923. // (http://ejohn.org/blog/javascript-micro-templating/)
  13924. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13925. var settings = lodash.templateSettings;
  13926. if (guard && isIterateeCall(string, options, guard)) {
  13927. options = undefined;
  13928. }
  13929. string = toString(string);
  13930. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13931. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13932. importsKeys = keys(imports),
  13933. importsValues = baseValues(imports, importsKeys);
  13934. var isEscaping,
  13935. isEvaluating,
  13936. index = 0,
  13937. interpolate = options.interpolate || reNoMatch,
  13938. source = "__p += '";
  13939. // Compile the regexp to match each delimiter.
  13940. var reDelimiters = RegExp(
  13941. (options.escape || reNoMatch).source + '|' +
  13942. interpolate.source + '|' +
  13943. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13944. (options.evaluate || reNoMatch).source + '|$'
  13945. , 'g');
  13946. // Use a sourceURL for easier debugging.
  13947. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13948. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  13949. // and escape the comment, thus injecting code that gets evaled.
  13950. var sourceURL = '//# sourceURL=' +
  13951. (hasOwnProperty.call(options, 'sourceURL')
  13952. ? (options.sourceURL + '').replace(/\s/g, ' ')
  13953. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13954. ) + '\n';
  13955. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13956. interpolateValue || (interpolateValue = esTemplateValue);
  13957. // Escape characters that can't be included in string literals.
  13958. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13959. // Replace delimiters with snippets.
  13960. if (escapeValue) {
  13961. isEscaping = true;
  13962. source += "' +\n__e(" + escapeValue + ") +\n'";
  13963. }
  13964. if (evaluateValue) {
  13965. isEvaluating = true;
  13966. source += "';\n" + evaluateValue + ";\n__p += '";
  13967. }
  13968. if (interpolateValue) {
  13969. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13970. }
  13971. index = offset + match.length;
  13972. // The JS engine embedded in Adobe products needs `match` returned in
  13973. // order to produce the correct `offset` value.
  13974. return match;
  13975. });
  13976. source += "';\n";
  13977. // If `variable` is not specified wrap a with-statement around the generated
  13978. // code to add the data object to the top of the scope chain.
  13979. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13980. if (!variable) {
  13981. source = 'with (obj) {\n' + source + '\n}\n';
  13982. }
  13983. // Throw an error if a forbidden character was found in `variable`, to prevent
  13984. // potential command injection attacks.
  13985. else if (reForbiddenIdentifierChars.test(variable)) {
  13986. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  13987. }
  13988. // Cleanup code by stripping empty strings.
  13989. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13990. .replace(reEmptyStringMiddle, '$1')
  13991. .replace(reEmptyStringTrailing, '$1;');
  13992. // Frame code as the function body.
  13993. source = 'function(' + (variable || 'obj') + ') {\n' +
  13994. (variable
  13995. ? ''
  13996. : 'obj || (obj = {});\n'
  13997. ) +
  13998. "var __t, __p = ''" +
  13999. (isEscaping
  14000. ? ', __e = _.escape'
  14001. : ''
  14002. ) +
  14003. (isEvaluating
  14004. ? ', __j = Array.prototype.join;\n' +
  14005. "function print() { __p += __j.call(arguments, '') }\n"
  14006. : ';\n'
  14007. ) +
  14008. source +
  14009. 'return __p\n}';
  14010. var result = attempt(function() {
  14011. return Function(importsKeys, sourceURL + 'return ' + source)
  14012. .apply(undefined, importsValues);
  14013. });
  14014. // Provide the compiled function's source by its `toString` method or
  14015. // the `source` property as a convenience for inlining compiled templates.
  14016. result.source = source;
  14017. if (isError(result)) {
  14018. throw result;
  14019. }
  14020. return result;
  14021. }
  14022. /**
  14023. * Converts `string`, as a whole, to lower case just like
  14024. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14025. *
  14026. * @static
  14027. * @memberOf _
  14028. * @since 4.0.0
  14029. * @category String
  14030. * @param {string} [string=''] The string to convert.
  14031. * @returns {string} Returns the lower cased string.
  14032. * @example
  14033. *
  14034. * _.toLower('--Foo-Bar--');
  14035. * // => '--foo-bar--'
  14036. *
  14037. * _.toLower('fooBar');
  14038. * // => 'foobar'
  14039. *
  14040. * _.toLower('__FOO_BAR__');
  14041. * // => '__foo_bar__'
  14042. */
  14043. function toLower(value) {
  14044. return toString(value).toLowerCase();
  14045. }
  14046. /**
  14047. * Converts `string`, as a whole, to upper case just like
  14048. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14049. *
  14050. * @static
  14051. * @memberOf _
  14052. * @since 4.0.0
  14053. * @category String
  14054. * @param {string} [string=''] The string to convert.
  14055. * @returns {string} Returns the upper cased string.
  14056. * @example
  14057. *
  14058. * _.toUpper('--foo-bar--');
  14059. * // => '--FOO-BAR--'
  14060. *
  14061. * _.toUpper('fooBar');
  14062. * // => 'FOOBAR'
  14063. *
  14064. * _.toUpper('__foo_bar__');
  14065. * // => '__FOO_BAR__'
  14066. */
  14067. function toUpper(value) {
  14068. return toString(value).toUpperCase();
  14069. }
  14070. /**
  14071. * Removes leading and trailing whitespace or specified characters from `string`.
  14072. *
  14073. * @static
  14074. * @memberOf _
  14075. * @since 3.0.0
  14076. * @category String
  14077. * @param {string} [string=''] The string to trim.
  14078. * @param {string} [chars=whitespace] The characters to trim.
  14079. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14080. * @returns {string} Returns the trimmed string.
  14081. * @example
  14082. *
  14083. * _.trim(' abc ');
  14084. * // => 'abc'
  14085. *
  14086. * _.trim('-_-abc-_-', '_-');
  14087. * // => 'abc'
  14088. *
  14089. * _.map([' foo ', ' bar '], _.trim);
  14090. * // => ['foo', 'bar']
  14091. */
  14092. function trim(string, chars, guard) {
  14093. string = toString(string);
  14094. if (string && (guard || chars === undefined)) {
  14095. return baseTrim(string);
  14096. }
  14097. if (!string || !(chars = baseToString(chars))) {
  14098. return string;
  14099. }
  14100. var strSymbols = stringToArray(string),
  14101. chrSymbols = stringToArray(chars),
  14102. start = charsStartIndex(strSymbols, chrSymbols),
  14103. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14104. return castSlice(strSymbols, start, end).join('');
  14105. }
  14106. /**
  14107. * Removes trailing whitespace or specified characters from `string`.
  14108. *
  14109. * @static
  14110. * @memberOf _
  14111. * @since 4.0.0
  14112. * @category String
  14113. * @param {string} [string=''] The string to trim.
  14114. * @param {string} [chars=whitespace] The characters to trim.
  14115. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14116. * @returns {string} Returns the trimmed string.
  14117. * @example
  14118. *
  14119. * _.trimEnd(' abc ');
  14120. * // => ' abc'
  14121. *
  14122. * _.trimEnd('-_-abc-_-', '_-');
  14123. * // => '-_-abc'
  14124. */
  14125. function trimEnd(string, chars, guard) {
  14126. string = toString(string);
  14127. if (string && (guard || chars === undefined)) {
  14128. return string.slice(0, trimmedEndIndex(string) + 1);
  14129. }
  14130. if (!string || !(chars = baseToString(chars))) {
  14131. return string;
  14132. }
  14133. var strSymbols = stringToArray(string),
  14134. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14135. return castSlice(strSymbols, 0, end).join('');
  14136. }
  14137. /**
  14138. * Removes leading whitespace or specified characters from `string`.
  14139. *
  14140. * @static
  14141. * @memberOf _
  14142. * @since 4.0.0
  14143. * @category String
  14144. * @param {string} [string=''] The string to trim.
  14145. * @param {string} [chars=whitespace] The characters to trim.
  14146. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14147. * @returns {string} Returns the trimmed string.
  14148. * @example
  14149. *
  14150. * _.trimStart(' abc ');
  14151. * // => 'abc '
  14152. *
  14153. * _.trimStart('-_-abc-_-', '_-');
  14154. * // => 'abc-_-'
  14155. */
  14156. function trimStart(string, chars, guard) {
  14157. string = toString(string);
  14158. if (string && (guard || chars === undefined)) {
  14159. return string.replace(reTrimStart, '');
  14160. }
  14161. if (!string || !(chars = baseToString(chars))) {
  14162. return string;
  14163. }
  14164. var strSymbols = stringToArray(string),
  14165. start = charsStartIndex(strSymbols, stringToArray(chars));
  14166. return castSlice(strSymbols, start).join('');
  14167. }
  14168. /**
  14169. * Truncates `string` if it's longer than the given maximum string length.
  14170. * The last characters of the truncated string are replaced with the omission
  14171. * string which defaults to "...".
  14172. *
  14173. * @static
  14174. * @memberOf _
  14175. * @since 4.0.0
  14176. * @category String
  14177. * @param {string} [string=''] The string to truncate.
  14178. * @param {Object} [options={}] The options object.
  14179. * @param {number} [options.length=30] The maximum string length.
  14180. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14181. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14182. * @returns {string} Returns the truncated string.
  14183. * @example
  14184. *
  14185. * _.truncate('hi-diddly-ho there, neighborino');
  14186. * // => 'hi-diddly-ho there, neighbo...'
  14187. *
  14188. * _.truncate('hi-diddly-ho there, neighborino', {
  14189. * 'length': 24,
  14190. * 'separator': ' '
  14191. * });
  14192. * // => 'hi-diddly-ho there,...'
  14193. *
  14194. * _.truncate('hi-diddly-ho there, neighborino', {
  14195. * 'length': 24,
  14196. * 'separator': /,? +/
  14197. * });
  14198. * // => 'hi-diddly-ho there...'
  14199. *
  14200. * _.truncate('hi-diddly-ho there, neighborino', {
  14201. * 'omission': ' [...]'
  14202. * });
  14203. * // => 'hi-diddly-ho there, neig [...]'
  14204. */
  14205. function truncate(string, options) {
  14206. var length = DEFAULT_TRUNC_LENGTH,
  14207. omission = DEFAULT_TRUNC_OMISSION;
  14208. if (isObject(options)) {
  14209. var separator = 'separator' in options ? options.separator : separator;
  14210. length = 'length' in options ? toInteger(options.length) : length;
  14211. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14212. }
  14213. string = toString(string);
  14214. var strLength = string.length;
  14215. if (hasUnicode(string)) {
  14216. var strSymbols = stringToArray(string);
  14217. strLength = strSymbols.length;
  14218. }
  14219. if (length >= strLength) {
  14220. return string;
  14221. }
  14222. var end = length - stringSize(omission);
  14223. if (end < 1) {
  14224. return omission;
  14225. }
  14226. var result = strSymbols
  14227. ? castSlice(strSymbols, 0, end).join('')
  14228. : string.slice(0, end);
  14229. if (separator === undefined) {
  14230. return result + omission;
  14231. }
  14232. if (strSymbols) {
  14233. end += (result.length - end);
  14234. }
  14235. if (isRegExp(separator)) {
  14236. if (string.slice(end).search(separator)) {
  14237. var match,
  14238. substring = result;
  14239. if (!separator.global) {
  14240. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14241. }
  14242. separator.lastIndex = 0;
  14243. while ((match = separator.exec(substring))) {
  14244. var newEnd = match.index;
  14245. }
  14246. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14247. }
  14248. } else if (string.indexOf(baseToString(separator), end) != end) {
  14249. var index = result.lastIndexOf(separator);
  14250. if (index > -1) {
  14251. result = result.slice(0, index);
  14252. }
  14253. }
  14254. return result + omission;
  14255. }
  14256. /**
  14257. * The inverse of `_.escape`; this method converts the HTML entities
  14258. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14259. * their corresponding characters.
  14260. *
  14261. * **Note:** No other HTML entities are unescaped. To unescape additional
  14262. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14263. *
  14264. * @static
  14265. * @memberOf _
  14266. * @since 0.6.0
  14267. * @category String
  14268. * @param {string} [string=''] The string to unescape.
  14269. * @returns {string} Returns the unescaped string.
  14270. * @example
  14271. *
  14272. * _.unescape('fred, barney, &amp; pebbles');
  14273. * // => 'fred, barney, & pebbles'
  14274. */
  14275. function unescape(string) {
  14276. string = toString(string);
  14277. return (string && reHasEscapedHtml.test(string))
  14278. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14279. : string;
  14280. }
  14281. /**
  14282. * Converts `string`, as space separated words, to upper case.
  14283. *
  14284. * @static
  14285. * @memberOf _
  14286. * @since 4.0.0
  14287. * @category String
  14288. * @param {string} [string=''] The string to convert.
  14289. * @returns {string} Returns the upper cased string.
  14290. * @example
  14291. *
  14292. * _.upperCase('--foo-bar');
  14293. * // => 'FOO BAR'
  14294. *
  14295. * _.upperCase('fooBar');
  14296. * // => 'FOO BAR'
  14297. *
  14298. * _.upperCase('__foo_bar__');
  14299. * // => 'FOO BAR'
  14300. */
  14301. var upperCase = createCompounder(function(result, word, index) {
  14302. return result + (index ? ' ' : '') + word.toUpperCase();
  14303. });
  14304. /**
  14305. * Converts the first character of `string` to upper case.
  14306. *
  14307. * @static
  14308. * @memberOf _
  14309. * @since 4.0.0
  14310. * @category String
  14311. * @param {string} [string=''] The string to convert.
  14312. * @returns {string} Returns the converted string.
  14313. * @example
  14314. *
  14315. * _.upperFirst('fred');
  14316. * // => 'Fred'
  14317. *
  14318. * _.upperFirst('FRED');
  14319. * // => 'FRED'
  14320. */
  14321. var upperFirst = createCaseFirst('toUpperCase');
  14322. /**
  14323. * Splits `string` into an array of its words.
  14324. *
  14325. * @static
  14326. * @memberOf _
  14327. * @since 3.0.0
  14328. * @category String
  14329. * @param {string} [string=''] The string to inspect.
  14330. * @param {RegExp|string} [pattern] The pattern to match words.
  14331. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14332. * @returns {Array} Returns the words of `string`.
  14333. * @example
  14334. *
  14335. * _.words('fred, barney, & pebbles');
  14336. * // => ['fred', 'barney', 'pebbles']
  14337. *
  14338. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14339. * // => ['fred', 'barney', '&', 'pebbles']
  14340. */
  14341. function words(string, pattern, guard) {
  14342. string = toString(string);
  14343. pattern = guard ? undefined : pattern;
  14344. if (pattern === undefined) {
  14345. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14346. }
  14347. return string.match(pattern) || [];
  14348. }
  14349. /*------------------------------------------------------------------------*/
  14350. /**
  14351. * Attempts to invoke `func`, returning either the result or the caught error
  14352. * object. Any additional arguments are provided to `func` when it's invoked.
  14353. *
  14354. * @static
  14355. * @memberOf _
  14356. * @since 3.0.0
  14357. * @category Util
  14358. * @param {Function} func The function to attempt.
  14359. * @param {...*} [args] The arguments to invoke `func` with.
  14360. * @returns {*} Returns the `func` result or error object.
  14361. * @example
  14362. *
  14363. * // Avoid throwing errors for invalid selectors.
  14364. * var elements = _.attempt(function(selector) {
  14365. * return document.querySelectorAll(selector);
  14366. * }, '>_>');
  14367. *
  14368. * if (_.isError(elements)) {
  14369. * elements = [];
  14370. * }
  14371. */
  14372. var attempt = baseRest(function(func, args) {
  14373. try {
  14374. return apply(func, undefined, args);
  14375. } catch (e) {
  14376. return isError(e) ? e : new Error(e);
  14377. }
  14378. });
  14379. /**
  14380. * Binds methods of an object to the object itself, overwriting the existing
  14381. * method.
  14382. *
  14383. * **Note:** This method doesn't set the "length" property of bound functions.
  14384. *
  14385. * @static
  14386. * @since 0.1.0
  14387. * @memberOf _
  14388. * @category Util
  14389. * @param {Object} object The object to bind and assign the bound methods to.
  14390. * @param {...(string|string[])} methodNames The object method names to bind.
  14391. * @returns {Object} Returns `object`.
  14392. * @example
  14393. *
  14394. * var view = {
  14395. * 'label': 'docs',
  14396. * 'click': function() {
  14397. * console.log('clicked ' + this.label);
  14398. * }
  14399. * };
  14400. *
  14401. * _.bindAll(view, ['click']);
  14402. * jQuery(element).on('click', view.click);
  14403. * // => Logs 'clicked docs' when clicked.
  14404. */
  14405. var bindAll = flatRest(function(object, methodNames) {
  14406. arrayEach(methodNames, function(key) {
  14407. key = toKey(key);
  14408. baseAssignValue(object, key, bind(object[key], object));
  14409. });
  14410. return object;
  14411. });
  14412. /**
  14413. * Creates a function that iterates over `pairs` and invokes the corresponding
  14414. * function of the first predicate to return truthy. The predicate-function
  14415. * pairs are invoked with the `this` binding and arguments of the created
  14416. * function.
  14417. *
  14418. * @static
  14419. * @memberOf _
  14420. * @since 4.0.0
  14421. * @category Util
  14422. * @param {Array} pairs The predicate-function pairs.
  14423. * @returns {Function} Returns the new composite function.
  14424. * @example
  14425. *
  14426. * var func = _.cond([
  14427. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14428. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14429. * [_.stubTrue, _.constant('no match')]
  14430. * ]);
  14431. *
  14432. * func({ 'a': 1, 'b': 2 });
  14433. * // => 'matches A'
  14434. *
  14435. * func({ 'a': 0, 'b': 1 });
  14436. * // => 'matches B'
  14437. *
  14438. * func({ 'a': '1', 'b': '2' });
  14439. * // => 'no match'
  14440. */
  14441. function cond(pairs) {
  14442. var length = pairs == null ? 0 : pairs.length,
  14443. toIteratee = getIteratee();
  14444. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14445. if (typeof pair[1] != 'function') {
  14446. throw new TypeError(FUNC_ERROR_TEXT);
  14447. }
  14448. return [toIteratee(pair[0]), pair[1]];
  14449. });
  14450. return baseRest(function(args) {
  14451. var index = -1;
  14452. while (++index < length) {
  14453. var pair = pairs[index];
  14454. if (apply(pair[0], this, args)) {
  14455. return apply(pair[1], this, args);
  14456. }
  14457. }
  14458. });
  14459. }
  14460. /**
  14461. * Creates a function that invokes the predicate properties of `source` with
  14462. * the corresponding property values of a given object, returning `true` if
  14463. * all predicates return truthy, else `false`.
  14464. *
  14465. * **Note:** The created function is equivalent to `_.conformsTo` with
  14466. * `source` partially applied.
  14467. *
  14468. * @static
  14469. * @memberOf _
  14470. * @since 4.0.0
  14471. * @category Util
  14472. * @param {Object} source The object of property predicates to conform to.
  14473. * @returns {Function} Returns the new spec function.
  14474. * @example
  14475. *
  14476. * var objects = [
  14477. * { 'a': 2, 'b': 1 },
  14478. * { 'a': 1, 'b': 2 }
  14479. * ];
  14480. *
  14481. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14482. * // => [{ 'a': 1, 'b': 2 }]
  14483. */
  14484. function conforms(source) {
  14485. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14486. }
  14487. /**
  14488. * Creates a function that returns `value`.
  14489. *
  14490. * @static
  14491. * @memberOf _
  14492. * @since 2.4.0
  14493. * @category Util
  14494. * @param {*} value The value to return from the new function.
  14495. * @returns {Function} Returns the new constant function.
  14496. * @example
  14497. *
  14498. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14499. *
  14500. * console.log(objects);
  14501. * // => [{ 'a': 1 }, { 'a': 1 }]
  14502. *
  14503. * console.log(objects[0] === objects[1]);
  14504. * // => true
  14505. */
  14506. function constant(value) {
  14507. return function() {
  14508. return value;
  14509. };
  14510. }
  14511. /**
  14512. * Checks `value` to determine whether a default value should be returned in
  14513. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14514. * or `undefined`.
  14515. *
  14516. * @static
  14517. * @memberOf _
  14518. * @since 4.14.0
  14519. * @category Util
  14520. * @param {*} value The value to check.
  14521. * @param {*} defaultValue The default value.
  14522. * @returns {*} Returns the resolved value.
  14523. * @example
  14524. *
  14525. * _.defaultTo(1, 10);
  14526. * // => 1
  14527. *
  14528. * _.defaultTo(undefined, 10);
  14529. * // => 10
  14530. */
  14531. function defaultTo(value, defaultValue) {
  14532. return (value == null || value !== value) ? defaultValue : value;
  14533. }
  14534. /**
  14535. * Creates a function that returns the result of invoking the given functions
  14536. * with the `this` binding of the created function, where each successive
  14537. * invocation is supplied the return value of the previous.
  14538. *
  14539. * @static
  14540. * @memberOf _
  14541. * @since 3.0.0
  14542. * @category Util
  14543. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14544. * @returns {Function} Returns the new composite function.
  14545. * @see _.flowRight
  14546. * @example
  14547. *
  14548. * function square(n) {
  14549. * return n * n;
  14550. * }
  14551. *
  14552. * var addSquare = _.flow([_.add, square]);
  14553. * addSquare(1, 2);
  14554. * // => 9
  14555. */
  14556. var flow = createFlow();
  14557. /**
  14558. * This method is like `_.flow` except that it creates a function that
  14559. * invokes the given functions from right to left.
  14560. *
  14561. * @static
  14562. * @since 3.0.0
  14563. * @memberOf _
  14564. * @category Util
  14565. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14566. * @returns {Function} Returns the new composite function.
  14567. * @see _.flow
  14568. * @example
  14569. *
  14570. * function square(n) {
  14571. * return n * n;
  14572. * }
  14573. *
  14574. * var addSquare = _.flowRight([square, _.add]);
  14575. * addSquare(1, 2);
  14576. * // => 9
  14577. */
  14578. var flowRight = createFlow(true);
  14579. /**
  14580. * This method returns the first argument it receives.
  14581. *
  14582. * @static
  14583. * @since 0.1.0
  14584. * @memberOf _
  14585. * @category Util
  14586. * @param {*} value Any value.
  14587. * @returns {*} Returns `value`.
  14588. * @example
  14589. *
  14590. * var object = { 'a': 1 };
  14591. *
  14592. * console.log(_.identity(object) === object);
  14593. * // => true
  14594. */
  14595. function identity(value) {
  14596. return value;
  14597. }
  14598. /**
  14599. * Creates a function that invokes `func` with the arguments of the created
  14600. * function. If `func` is a property name, the created function returns the
  14601. * property value for a given element. If `func` is an array or object, the
  14602. * created function returns `true` for elements that contain the equivalent
  14603. * source properties, otherwise it returns `false`.
  14604. *
  14605. * @static
  14606. * @since 4.0.0
  14607. * @memberOf _
  14608. * @category Util
  14609. * @param {*} [func=_.identity] The value to convert to a callback.
  14610. * @returns {Function} Returns the callback.
  14611. * @example
  14612. *
  14613. * var users = [
  14614. * { 'user': 'barney', 'age': 36, 'active': true },
  14615. * { 'user': 'fred', 'age': 40, 'active': false }
  14616. * ];
  14617. *
  14618. * // The `_.matches` iteratee shorthand.
  14619. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14620. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14621. *
  14622. * // The `_.matchesProperty` iteratee shorthand.
  14623. * _.filter(users, _.iteratee(['user', 'fred']));
  14624. * // => [{ 'user': 'fred', 'age': 40 }]
  14625. *
  14626. * // The `_.property` iteratee shorthand.
  14627. * _.map(users, _.iteratee('user'));
  14628. * // => ['barney', 'fred']
  14629. *
  14630. * // Create custom iteratee shorthands.
  14631. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14632. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14633. * return func.test(string);
  14634. * };
  14635. * });
  14636. *
  14637. * _.filter(['abc', 'def'], /ef/);
  14638. * // => ['def']
  14639. */
  14640. function iteratee(func) {
  14641. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14642. }
  14643. /**
  14644. * Creates a function that performs a partial deep comparison between a given
  14645. * object and `source`, returning `true` if the given object has equivalent
  14646. * property values, else `false`.
  14647. *
  14648. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14649. * partially applied.
  14650. *
  14651. * Partial comparisons will match empty array and empty object `source`
  14652. * values against any array or object value, respectively. See `_.isEqual`
  14653. * for a list of supported value comparisons.
  14654. *
  14655. * **Note:** Multiple values can be checked by combining several matchers
  14656. * using `_.overSome`
  14657. *
  14658. * @static
  14659. * @memberOf _
  14660. * @since 3.0.0
  14661. * @category Util
  14662. * @param {Object} source The object of property values to match.
  14663. * @returns {Function} Returns the new spec function.
  14664. * @example
  14665. *
  14666. * var objects = [
  14667. * { 'a': 1, 'b': 2, 'c': 3 },
  14668. * { 'a': 4, 'b': 5, 'c': 6 }
  14669. * ];
  14670. *
  14671. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14672. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14673. *
  14674. * // Checking for several possible values
  14675. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  14676. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14677. */
  14678. function matches(source) {
  14679. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14680. }
  14681. /**
  14682. * Creates a function that performs a partial deep comparison between the
  14683. * value at `path` of a given object to `srcValue`, returning `true` if the
  14684. * object value is equivalent, else `false`.
  14685. *
  14686. * **Note:** Partial comparisons will match empty array and empty object
  14687. * `srcValue` values against any array or object value, respectively. See
  14688. * `_.isEqual` for a list of supported value comparisons.
  14689. *
  14690. * **Note:** Multiple values can be checked by combining several matchers
  14691. * using `_.overSome`
  14692. *
  14693. * @static
  14694. * @memberOf _
  14695. * @since 3.2.0
  14696. * @category Util
  14697. * @param {Array|string} path The path of the property to get.
  14698. * @param {*} srcValue The value to match.
  14699. * @returns {Function} Returns the new spec function.
  14700. * @example
  14701. *
  14702. * var objects = [
  14703. * { 'a': 1, 'b': 2, 'c': 3 },
  14704. * { 'a': 4, 'b': 5, 'c': 6 }
  14705. * ];
  14706. *
  14707. * _.find(objects, _.matchesProperty('a', 4));
  14708. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14709. *
  14710. * // Checking for several possible values
  14711. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  14712. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14713. */
  14714. function matchesProperty(path, srcValue) {
  14715. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14716. }
  14717. /**
  14718. * Creates a function that invokes the method at `path` of a given object.
  14719. * Any additional arguments are provided to the invoked method.
  14720. *
  14721. * @static
  14722. * @memberOf _
  14723. * @since 3.7.0
  14724. * @category Util
  14725. * @param {Array|string} path The path of the method to invoke.
  14726. * @param {...*} [args] The arguments to invoke the method with.
  14727. * @returns {Function} Returns the new invoker function.
  14728. * @example
  14729. *
  14730. * var objects = [
  14731. * { 'a': { 'b': _.constant(2) } },
  14732. * { 'a': { 'b': _.constant(1) } }
  14733. * ];
  14734. *
  14735. * _.map(objects, _.method('a.b'));
  14736. * // => [2, 1]
  14737. *
  14738. * _.map(objects, _.method(['a', 'b']));
  14739. * // => [2, 1]
  14740. */
  14741. var method = baseRest(function(path, args) {
  14742. return function(object) {
  14743. return baseInvoke(object, path, args);
  14744. };
  14745. });
  14746. /**
  14747. * The opposite of `_.method`; this method creates a function that invokes
  14748. * the method at a given path of `object`. Any additional arguments are
  14749. * provided to the invoked method.
  14750. *
  14751. * @static
  14752. * @memberOf _
  14753. * @since 3.7.0
  14754. * @category Util
  14755. * @param {Object} object The object to query.
  14756. * @param {...*} [args] The arguments to invoke the method with.
  14757. * @returns {Function} Returns the new invoker function.
  14758. * @example
  14759. *
  14760. * var array = _.times(3, _.constant),
  14761. * object = { 'a': array, 'b': array, 'c': array };
  14762. *
  14763. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14764. * // => [2, 0]
  14765. *
  14766. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14767. * // => [2, 0]
  14768. */
  14769. var methodOf = baseRest(function(object, args) {
  14770. return function(path) {
  14771. return baseInvoke(object, path, args);
  14772. };
  14773. });
  14774. /**
  14775. * Adds all own enumerable string keyed function properties of a source
  14776. * object to the destination object. If `object` is a function, then methods
  14777. * are added to its prototype as well.
  14778. *
  14779. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14780. * avoid conflicts caused by modifying the original.
  14781. *
  14782. * @static
  14783. * @since 0.1.0
  14784. * @memberOf _
  14785. * @category Util
  14786. * @param {Function|Object} [object=lodash] The destination object.
  14787. * @param {Object} source The object of functions to add.
  14788. * @param {Object} [options={}] The options object.
  14789. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14790. * @returns {Function|Object} Returns `object`.
  14791. * @example
  14792. *
  14793. * function vowels(string) {
  14794. * return _.filter(string, function(v) {
  14795. * return /[aeiou]/i.test(v);
  14796. * });
  14797. * }
  14798. *
  14799. * _.mixin({ 'vowels': vowels });
  14800. * _.vowels('fred');
  14801. * // => ['e']
  14802. *
  14803. * _('fred').vowels().value();
  14804. * // => ['e']
  14805. *
  14806. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14807. * _('fred').vowels();
  14808. * // => ['e']
  14809. */
  14810. function mixin(object, source, options) {
  14811. var props = keys(source),
  14812. methodNames = baseFunctions(source, props);
  14813. if (options == null &&
  14814. !(isObject(source) && (methodNames.length || !props.length))) {
  14815. options = source;
  14816. source = object;
  14817. object = this;
  14818. methodNames = baseFunctions(source, keys(source));
  14819. }
  14820. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14821. isFunc = isFunction(object);
  14822. arrayEach(methodNames, function(methodName) {
  14823. var func = source[methodName];
  14824. object[methodName] = func;
  14825. if (isFunc) {
  14826. object.prototype[methodName] = function() {
  14827. var chainAll = this.__chain__;
  14828. if (chain || chainAll) {
  14829. var result = object(this.__wrapped__),
  14830. actions = result.__actions__ = copyArray(this.__actions__);
  14831. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14832. result.__chain__ = chainAll;
  14833. return result;
  14834. }
  14835. return func.apply(object, arrayPush([this.value()], arguments));
  14836. };
  14837. }
  14838. });
  14839. return object;
  14840. }
  14841. /**
  14842. * Reverts the `_` variable to its previous value and returns a reference to
  14843. * the `lodash` function.
  14844. *
  14845. * @static
  14846. * @since 0.1.0
  14847. * @memberOf _
  14848. * @category Util
  14849. * @returns {Function} Returns the `lodash` function.
  14850. * @example
  14851. *
  14852. * var lodash = _.noConflict();
  14853. */
  14854. function noConflict() {
  14855. if (root._ === this) {
  14856. root._ = oldDash;
  14857. }
  14858. return this;
  14859. }
  14860. /**
  14861. * This method returns `undefined`.
  14862. *
  14863. * @static
  14864. * @memberOf _
  14865. * @since 2.3.0
  14866. * @category Util
  14867. * @example
  14868. *
  14869. * _.times(2, _.noop);
  14870. * // => [undefined, undefined]
  14871. */
  14872. function noop() {
  14873. // No operation performed.
  14874. }
  14875. /**
  14876. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14877. * the nth argument from the end is returned.
  14878. *
  14879. * @static
  14880. * @memberOf _
  14881. * @since 4.0.0
  14882. * @category Util
  14883. * @param {number} [n=0] The index of the argument to return.
  14884. * @returns {Function} Returns the new pass-thru function.
  14885. * @example
  14886. *
  14887. * var func = _.nthArg(1);
  14888. * func('a', 'b', 'c', 'd');
  14889. * // => 'b'
  14890. *
  14891. * var func = _.nthArg(-2);
  14892. * func('a', 'b', 'c', 'd');
  14893. * // => 'c'
  14894. */
  14895. function nthArg(n) {
  14896. n = toInteger(n);
  14897. return baseRest(function(args) {
  14898. return baseNth(args, n);
  14899. });
  14900. }
  14901. /**
  14902. * Creates a function that invokes `iteratees` with the arguments it receives
  14903. * and returns their results.
  14904. *
  14905. * @static
  14906. * @memberOf _
  14907. * @since 4.0.0
  14908. * @category Util
  14909. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14910. * The iteratees to invoke.
  14911. * @returns {Function} Returns the new function.
  14912. * @example
  14913. *
  14914. * var func = _.over([Math.max, Math.min]);
  14915. *
  14916. * func(1, 2, 3, 4);
  14917. * // => [4, 1]
  14918. */
  14919. var over = createOver(arrayMap);
  14920. /**
  14921. * Creates a function that checks if **all** of the `predicates` return
  14922. * truthy when invoked with the arguments it receives.
  14923. *
  14924. * Following shorthands are possible for providing predicates.
  14925. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14926. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14927. *
  14928. * @static
  14929. * @memberOf _
  14930. * @since 4.0.0
  14931. * @category Util
  14932. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14933. * The predicates to check.
  14934. * @returns {Function} Returns the new function.
  14935. * @example
  14936. *
  14937. * var func = _.overEvery([Boolean, isFinite]);
  14938. *
  14939. * func('1');
  14940. * // => true
  14941. *
  14942. * func(null);
  14943. * // => false
  14944. *
  14945. * func(NaN);
  14946. * // => false
  14947. */
  14948. var overEvery = createOver(arrayEvery);
  14949. /**
  14950. * Creates a function that checks if **any** of the `predicates` return
  14951. * truthy when invoked with the arguments it receives.
  14952. *
  14953. * Following shorthands are possible for providing predicates.
  14954. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14955. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14956. *
  14957. * @static
  14958. * @memberOf _
  14959. * @since 4.0.0
  14960. * @category Util
  14961. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14962. * The predicates to check.
  14963. * @returns {Function} Returns the new function.
  14964. * @example
  14965. *
  14966. * var func = _.overSome([Boolean, isFinite]);
  14967. *
  14968. * func('1');
  14969. * // => true
  14970. *
  14971. * func(null);
  14972. * // => true
  14973. *
  14974. * func(NaN);
  14975. * // => false
  14976. *
  14977. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  14978. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  14979. */
  14980. var overSome = createOver(arraySome);
  14981. /**
  14982. * Creates a function that returns the value at `path` of a given object.
  14983. *
  14984. * @static
  14985. * @memberOf _
  14986. * @since 2.4.0
  14987. * @category Util
  14988. * @param {Array|string} path The path of the property to get.
  14989. * @returns {Function} Returns the new accessor function.
  14990. * @example
  14991. *
  14992. * var objects = [
  14993. * { 'a': { 'b': 2 } },
  14994. * { 'a': { 'b': 1 } }
  14995. * ];
  14996. *
  14997. * _.map(objects, _.property('a.b'));
  14998. * // => [2, 1]
  14999. *
  15000. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  15001. * // => [1, 2]
  15002. */
  15003. function property(path) {
  15004. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  15005. }
  15006. /**
  15007. * The opposite of `_.property`; this method creates a function that returns
  15008. * the value at a given path of `object`.
  15009. *
  15010. * @static
  15011. * @memberOf _
  15012. * @since 3.0.0
  15013. * @category Util
  15014. * @param {Object} object The object to query.
  15015. * @returns {Function} Returns the new accessor function.
  15016. * @example
  15017. *
  15018. * var array = [0, 1, 2],
  15019. * object = { 'a': array, 'b': array, 'c': array };
  15020. *
  15021. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15022. * // => [2, 0]
  15023. *
  15024. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15025. * // => [2, 0]
  15026. */
  15027. function propertyOf(object) {
  15028. return function(path) {
  15029. return object == null ? undefined : baseGet(object, path);
  15030. };
  15031. }
  15032. /**
  15033. * Creates an array of numbers (positive and/or negative) progressing from
  15034. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15035. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15036. * it's set to `start` with `start` then set to `0`.
  15037. *
  15038. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15039. * floating-point values which can produce unexpected results.
  15040. *
  15041. * @static
  15042. * @since 0.1.0
  15043. * @memberOf _
  15044. * @category Util
  15045. * @param {number} [start=0] The start of the range.
  15046. * @param {number} end The end of the range.
  15047. * @param {number} [step=1] The value to increment or decrement by.
  15048. * @returns {Array} Returns the range of numbers.
  15049. * @see _.inRange, _.rangeRight
  15050. * @example
  15051. *
  15052. * _.range(4);
  15053. * // => [0, 1, 2, 3]
  15054. *
  15055. * _.range(-4);
  15056. * // => [0, -1, -2, -3]
  15057. *
  15058. * _.range(1, 5);
  15059. * // => [1, 2, 3, 4]
  15060. *
  15061. * _.range(0, 20, 5);
  15062. * // => [0, 5, 10, 15]
  15063. *
  15064. * _.range(0, -4, -1);
  15065. * // => [0, -1, -2, -3]
  15066. *
  15067. * _.range(1, 4, 0);
  15068. * // => [1, 1, 1]
  15069. *
  15070. * _.range(0);
  15071. * // => []
  15072. */
  15073. var range = createRange();
  15074. /**
  15075. * This method is like `_.range` except that it populates values in
  15076. * descending order.
  15077. *
  15078. * @static
  15079. * @memberOf _
  15080. * @since 4.0.0
  15081. * @category Util
  15082. * @param {number} [start=0] The start of the range.
  15083. * @param {number} end The end of the range.
  15084. * @param {number} [step=1] The value to increment or decrement by.
  15085. * @returns {Array} Returns the range of numbers.
  15086. * @see _.inRange, _.range
  15087. * @example
  15088. *
  15089. * _.rangeRight(4);
  15090. * // => [3, 2, 1, 0]
  15091. *
  15092. * _.rangeRight(-4);
  15093. * // => [-3, -2, -1, 0]
  15094. *
  15095. * _.rangeRight(1, 5);
  15096. * // => [4, 3, 2, 1]
  15097. *
  15098. * _.rangeRight(0, 20, 5);
  15099. * // => [15, 10, 5, 0]
  15100. *
  15101. * _.rangeRight(0, -4, -1);
  15102. * // => [-3, -2, -1, 0]
  15103. *
  15104. * _.rangeRight(1, 4, 0);
  15105. * // => [1, 1, 1]
  15106. *
  15107. * _.rangeRight(0);
  15108. * // => []
  15109. */
  15110. var rangeRight = createRange(true);
  15111. /**
  15112. * This method returns a new empty array.
  15113. *
  15114. * @static
  15115. * @memberOf _
  15116. * @since 4.13.0
  15117. * @category Util
  15118. * @returns {Array} Returns the new empty array.
  15119. * @example
  15120. *
  15121. * var arrays = _.times(2, _.stubArray);
  15122. *
  15123. * console.log(arrays);
  15124. * // => [[], []]
  15125. *
  15126. * console.log(arrays[0] === arrays[1]);
  15127. * // => false
  15128. */
  15129. function stubArray() {
  15130. return [];
  15131. }
  15132. /**
  15133. * This method returns `false`.
  15134. *
  15135. * @static
  15136. * @memberOf _
  15137. * @since 4.13.0
  15138. * @category Util
  15139. * @returns {boolean} Returns `false`.
  15140. * @example
  15141. *
  15142. * _.times(2, _.stubFalse);
  15143. * // => [false, false]
  15144. */
  15145. function stubFalse() {
  15146. return false;
  15147. }
  15148. /**
  15149. * This method returns a new empty object.
  15150. *
  15151. * @static
  15152. * @memberOf _
  15153. * @since 4.13.0
  15154. * @category Util
  15155. * @returns {Object} Returns the new empty object.
  15156. * @example
  15157. *
  15158. * var objects = _.times(2, _.stubObject);
  15159. *
  15160. * console.log(objects);
  15161. * // => [{}, {}]
  15162. *
  15163. * console.log(objects[0] === objects[1]);
  15164. * // => false
  15165. */
  15166. function stubObject() {
  15167. return {};
  15168. }
  15169. /**
  15170. * This method returns an empty string.
  15171. *
  15172. * @static
  15173. * @memberOf _
  15174. * @since 4.13.0
  15175. * @category Util
  15176. * @returns {string} Returns the empty string.
  15177. * @example
  15178. *
  15179. * _.times(2, _.stubString);
  15180. * // => ['', '']
  15181. */
  15182. function stubString() {
  15183. return '';
  15184. }
  15185. /**
  15186. * This method returns `true`.
  15187. *
  15188. * @static
  15189. * @memberOf _
  15190. * @since 4.13.0
  15191. * @category Util
  15192. * @returns {boolean} Returns `true`.
  15193. * @example
  15194. *
  15195. * _.times(2, _.stubTrue);
  15196. * // => [true, true]
  15197. */
  15198. function stubTrue() {
  15199. return true;
  15200. }
  15201. /**
  15202. * Invokes the iteratee `n` times, returning an array of the results of
  15203. * each invocation. The iteratee is invoked with one argument; (index).
  15204. *
  15205. * @static
  15206. * @since 0.1.0
  15207. * @memberOf _
  15208. * @category Util
  15209. * @param {number} n The number of times to invoke `iteratee`.
  15210. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15211. * @returns {Array} Returns the array of results.
  15212. * @example
  15213. *
  15214. * _.times(3, String);
  15215. * // => ['0', '1', '2']
  15216. *
  15217. * _.times(4, _.constant(0));
  15218. * // => [0, 0, 0, 0]
  15219. */
  15220. function times(n, iteratee) {
  15221. n = toInteger(n);
  15222. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15223. return [];
  15224. }
  15225. var index = MAX_ARRAY_LENGTH,
  15226. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15227. iteratee = getIteratee(iteratee);
  15228. n -= MAX_ARRAY_LENGTH;
  15229. var result = baseTimes(length, iteratee);
  15230. while (++index < n) {
  15231. iteratee(index);
  15232. }
  15233. return result;
  15234. }
  15235. /**
  15236. * Converts `value` to a property path array.
  15237. *
  15238. * @static
  15239. * @memberOf _
  15240. * @since 4.0.0
  15241. * @category Util
  15242. * @param {*} value The value to convert.
  15243. * @returns {Array} Returns the new property path array.
  15244. * @example
  15245. *
  15246. * _.toPath('a.b.c');
  15247. * // => ['a', 'b', 'c']
  15248. *
  15249. * _.toPath('a[0].b.c');
  15250. * // => ['a', '0', 'b', 'c']
  15251. */
  15252. function toPath(value) {
  15253. if (isArray(value)) {
  15254. return arrayMap(value, toKey);
  15255. }
  15256. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15257. }
  15258. /**
  15259. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15260. *
  15261. * @static
  15262. * @since 0.1.0
  15263. * @memberOf _
  15264. * @category Util
  15265. * @param {string} [prefix=''] The value to prefix the ID with.
  15266. * @returns {string} Returns the unique ID.
  15267. * @example
  15268. *
  15269. * _.uniqueId('contact_');
  15270. * // => 'contact_104'
  15271. *
  15272. * _.uniqueId();
  15273. * // => '105'
  15274. */
  15275. function uniqueId(prefix) {
  15276. var id = ++idCounter;
  15277. return toString(prefix) + id;
  15278. }
  15279. /*------------------------------------------------------------------------*/
  15280. /**
  15281. * Adds two numbers.
  15282. *
  15283. * @static
  15284. * @memberOf _
  15285. * @since 3.4.0
  15286. * @category Math
  15287. * @param {number} augend The first number in an addition.
  15288. * @param {number} addend The second number in an addition.
  15289. * @returns {number} Returns the total.
  15290. * @example
  15291. *
  15292. * _.add(6, 4);
  15293. * // => 10
  15294. */
  15295. var add = createMathOperation(function(augend, addend) {
  15296. return augend + addend;
  15297. }, 0);
  15298. /**
  15299. * Computes `number` rounded up to `precision`.
  15300. *
  15301. * @static
  15302. * @memberOf _
  15303. * @since 3.10.0
  15304. * @category Math
  15305. * @param {number} number The number to round up.
  15306. * @param {number} [precision=0] The precision to round up to.
  15307. * @returns {number} Returns the rounded up number.
  15308. * @example
  15309. *
  15310. * _.ceil(4.006);
  15311. * // => 5
  15312. *
  15313. * _.ceil(6.004, 2);
  15314. * // => 6.01
  15315. *
  15316. * _.ceil(6040, -2);
  15317. * // => 6100
  15318. */
  15319. var ceil = createRound('ceil');
  15320. /**
  15321. * Divide two numbers.
  15322. *
  15323. * @static
  15324. * @memberOf _
  15325. * @since 4.7.0
  15326. * @category Math
  15327. * @param {number} dividend The first number in a division.
  15328. * @param {number} divisor The second number in a division.
  15329. * @returns {number} Returns the quotient.
  15330. * @example
  15331. *
  15332. * _.divide(6, 4);
  15333. * // => 1.5
  15334. */
  15335. var divide = createMathOperation(function(dividend, divisor) {
  15336. return dividend / divisor;
  15337. }, 1);
  15338. /**
  15339. * Computes `number` rounded down to `precision`.
  15340. *
  15341. * @static
  15342. * @memberOf _
  15343. * @since 3.10.0
  15344. * @category Math
  15345. * @param {number} number The number to round down.
  15346. * @param {number} [precision=0] The precision to round down to.
  15347. * @returns {number} Returns the rounded down number.
  15348. * @example
  15349. *
  15350. * _.floor(4.006);
  15351. * // => 4
  15352. *
  15353. * _.floor(0.046, 2);
  15354. * // => 0.04
  15355. *
  15356. * _.floor(4060, -2);
  15357. * // => 4000
  15358. */
  15359. var floor = createRound('floor');
  15360. /**
  15361. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15362. * `undefined` is returned.
  15363. *
  15364. * @static
  15365. * @since 0.1.0
  15366. * @memberOf _
  15367. * @category Math
  15368. * @param {Array} array The array to iterate over.
  15369. * @returns {*} Returns the maximum value.
  15370. * @example
  15371. *
  15372. * _.max([4, 2, 8, 6]);
  15373. * // => 8
  15374. *
  15375. * _.max([]);
  15376. * // => undefined
  15377. */
  15378. function max(array) {
  15379. return (array && array.length)
  15380. ? baseExtremum(array, identity, baseGt)
  15381. : undefined;
  15382. }
  15383. /**
  15384. * This method is like `_.max` except that it accepts `iteratee` which is
  15385. * invoked for each element in `array` to generate the criterion by which
  15386. * the value is ranked. The iteratee is invoked with one argument: (value).
  15387. *
  15388. * @static
  15389. * @memberOf _
  15390. * @since 4.0.0
  15391. * @category Math
  15392. * @param {Array} array The array to iterate over.
  15393. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15394. * @returns {*} Returns the maximum value.
  15395. * @example
  15396. *
  15397. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15398. *
  15399. * _.maxBy(objects, function(o) { return o.n; });
  15400. * // => { 'n': 2 }
  15401. *
  15402. * // The `_.property` iteratee shorthand.
  15403. * _.maxBy(objects, 'n');
  15404. * // => { 'n': 2 }
  15405. */
  15406. function maxBy(array, iteratee) {
  15407. return (array && array.length)
  15408. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15409. : undefined;
  15410. }
  15411. /**
  15412. * Computes the mean of the values in `array`.
  15413. *
  15414. * @static
  15415. * @memberOf _
  15416. * @since 4.0.0
  15417. * @category Math
  15418. * @param {Array} array The array to iterate over.
  15419. * @returns {number} Returns the mean.
  15420. * @example
  15421. *
  15422. * _.mean([4, 2, 8, 6]);
  15423. * // => 5
  15424. */
  15425. function mean(array) {
  15426. return baseMean(array, identity);
  15427. }
  15428. /**
  15429. * This method is like `_.mean` except that it accepts `iteratee` which is
  15430. * invoked for each element in `array` to generate the value to be averaged.
  15431. * The iteratee is invoked with one argument: (value).
  15432. *
  15433. * @static
  15434. * @memberOf _
  15435. * @since 4.7.0
  15436. * @category Math
  15437. * @param {Array} array The array to iterate over.
  15438. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15439. * @returns {number} Returns the mean.
  15440. * @example
  15441. *
  15442. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15443. *
  15444. * _.meanBy(objects, function(o) { return o.n; });
  15445. * // => 5
  15446. *
  15447. * // The `_.property` iteratee shorthand.
  15448. * _.meanBy(objects, 'n');
  15449. * // => 5
  15450. */
  15451. function meanBy(array, iteratee) {
  15452. return baseMean(array, getIteratee(iteratee, 2));
  15453. }
  15454. /**
  15455. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15456. * `undefined` is returned.
  15457. *
  15458. * @static
  15459. * @since 0.1.0
  15460. * @memberOf _
  15461. * @category Math
  15462. * @param {Array} array The array to iterate over.
  15463. * @returns {*} Returns the minimum value.
  15464. * @example
  15465. *
  15466. * _.min([4, 2, 8, 6]);
  15467. * // => 2
  15468. *
  15469. * _.min([]);
  15470. * // => undefined
  15471. */
  15472. function min(array) {
  15473. return (array && array.length)
  15474. ? baseExtremum(array, identity, baseLt)
  15475. : undefined;
  15476. }
  15477. /**
  15478. * This method is like `_.min` except that it accepts `iteratee` which is
  15479. * invoked for each element in `array` to generate the criterion by which
  15480. * the value is ranked. The iteratee is invoked with one argument: (value).
  15481. *
  15482. * @static
  15483. * @memberOf _
  15484. * @since 4.0.0
  15485. * @category Math
  15486. * @param {Array} array The array to iterate over.
  15487. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15488. * @returns {*} Returns the minimum value.
  15489. * @example
  15490. *
  15491. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15492. *
  15493. * _.minBy(objects, function(o) { return o.n; });
  15494. * // => { 'n': 1 }
  15495. *
  15496. * // The `_.property` iteratee shorthand.
  15497. * _.minBy(objects, 'n');
  15498. * // => { 'n': 1 }
  15499. */
  15500. function minBy(array, iteratee) {
  15501. return (array && array.length)
  15502. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15503. : undefined;
  15504. }
  15505. /**
  15506. * Multiply two numbers.
  15507. *
  15508. * @static
  15509. * @memberOf _
  15510. * @since 4.7.0
  15511. * @category Math
  15512. * @param {number} multiplier The first number in a multiplication.
  15513. * @param {number} multiplicand The second number in a multiplication.
  15514. * @returns {number} Returns the product.
  15515. * @example
  15516. *
  15517. * _.multiply(6, 4);
  15518. * // => 24
  15519. */
  15520. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15521. return multiplier * multiplicand;
  15522. }, 1);
  15523. /**
  15524. * Computes `number` rounded to `precision`.
  15525. *
  15526. * @static
  15527. * @memberOf _
  15528. * @since 3.10.0
  15529. * @category Math
  15530. * @param {number} number The number to round.
  15531. * @param {number} [precision=0] The precision to round to.
  15532. * @returns {number} Returns the rounded number.
  15533. * @example
  15534. *
  15535. * _.round(4.006);
  15536. * // => 4
  15537. *
  15538. * _.round(4.006, 2);
  15539. * // => 4.01
  15540. *
  15541. * _.round(4060, -2);
  15542. * // => 4100
  15543. */
  15544. var round = createRound('round');
  15545. /**
  15546. * Subtract two numbers.
  15547. *
  15548. * @static
  15549. * @memberOf _
  15550. * @since 4.0.0
  15551. * @category Math
  15552. * @param {number} minuend The first number in a subtraction.
  15553. * @param {number} subtrahend The second number in a subtraction.
  15554. * @returns {number} Returns the difference.
  15555. * @example
  15556. *
  15557. * _.subtract(6, 4);
  15558. * // => 2
  15559. */
  15560. var subtract = createMathOperation(function(minuend, subtrahend) {
  15561. return minuend - subtrahend;
  15562. }, 0);
  15563. /**
  15564. * Computes the sum of the values in `array`.
  15565. *
  15566. * @static
  15567. * @memberOf _
  15568. * @since 3.4.0
  15569. * @category Math
  15570. * @param {Array} array The array to iterate over.
  15571. * @returns {number} Returns the sum.
  15572. * @example
  15573. *
  15574. * _.sum([4, 2, 8, 6]);
  15575. * // => 20
  15576. */
  15577. function sum(array) {
  15578. return (array && array.length)
  15579. ? baseSum(array, identity)
  15580. : 0;
  15581. }
  15582. /**
  15583. * This method is like `_.sum` except that it accepts `iteratee` which is
  15584. * invoked for each element in `array` to generate the value to be summed.
  15585. * The iteratee is invoked with one argument: (value).
  15586. *
  15587. * @static
  15588. * @memberOf _
  15589. * @since 4.0.0
  15590. * @category Math
  15591. * @param {Array} array The array to iterate over.
  15592. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15593. * @returns {number} Returns the sum.
  15594. * @example
  15595. *
  15596. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15597. *
  15598. * _.sumBy(objects, function(o) { return o.n; });
  15599. * // => 20
  15600. *
  15601. * // The `_.property` iteratee shorthand.
  15602. * _.sumBy(objects, 'n');
  15603. * // => 20
  15604. */
  15605. function sumBy(array, iteratee) {
  15606. return (array && array.length)
  15607. ? baseSum(array, getIteratee(iteratee, 2))
  15608. : 0;
  15609. }
  15610. /*------------------------------------------------------------------------*/
  15611. // Add methods that return wrapped values in chain sequences.
  15612. lodash.after = after;
  15613. lodash.ary = ary;
  15614. lodash.assign = assign;
  15615. lodash.assignIn = assignIn;
  15616. lodash.assignInWith = assignInWith;
  15617. lodash.assignWith = assignWith;
  15618. lodash.at = at;
  15619. lodash.before = before;
  15620. lodash.bind = bind;
  15621. lodash.bindAll = bindAll;
  15622. lodash.bindKey = bindKey;
  15623. lodash.castArray = castArray;
  15624. lodash.chain = chain;
  15625. lodash.chunk = chunk;
  15626. lodash.compact = compact;
  15627. lodash.concat = concat;
  15628. lodash.cond = cond;
  15629. lodash.conforms = conforms;
  15630. lodash.constant = constant;
  15631. lodash.countBy = countBy;
  15632. lodash.create = create;
  15633. lodash.curry = curry;
  15634. lodash.curryRight = curryRight;
  15635. lodash.debounce = debounce;
  15636. lodash.defaults = defaults;
  15637. lodash.defaultsDeep = defaultsDeep;
  15638. lodash.defer = defer;
  15639. lodash.delay = delay;
  15640. lodash.difference = difference;
  15641. lodash.differenceBy = differenceBy;
  15642. lodash.differenceWith = differenceWith;
  15643. lodash.drop = drop;
  15644. lodash.dropRight = dropRight;
  15645. lodash.dropRightWhile = dropRightWhile;
  15646. lodash.dropWhile = dropWhile;
  15647. lodash.fill = fill;
  15648. lodash.filter = filter;
  15649. lodash.flatMap = flatMap;
  15650. lodash.flatMapDeep = flatMapDeep;
  15651. lodash.flatMapDepth = flatMapDepth;
  15652. lodash.flatten = flatten;
  15653. lodash.flattenDeep = flattenDeep;
  15654. lodash.flattenDepth = flattenDepth;
  15655. lodash.flip = flip;
  15656. lodash.flow = flow;
  15657. lodash.flowRight = flowRight;
  15658. lodash.fromPairs = fromPairs;
  15659. lodash.functions = functions;
  15660. lodash.functionsIn = functionsIn;
  15661. lodash.groupBy = groupBy;
  15662. lodash.initial = initial;
  15663. lodash.intersection = intersection;
  15664. lodash.intersectionBy = intersectionBy;
  15665. lodash.intersectionWith = intersectionWith;
  15666. lodash.invert = invert;
  15667. lodash.invertBy = invertBy;
  15668. lodash.invokeMap = invokeMap;
  15669. lodash.iteratee = iteratee;
  15670. lodash.keyBy = keyBy;
  15671. lodash.keys = keys;
  15672. lodash.keysIn = keysIn;
  15673. lodash.map = map;
  15674. lodash.mapKeys = mapKeys;
  15675. lodash.mapValues = mapValues;
  15676. lodash.matches = matches;
  15677. lodash.matchesProperty = matchesProperty;
  15678. lodash.memoize = memoize;
  15679. lodash.merge = merge;
  15680. lodash.mergeWith = mergeWith;
  15681. lodash.method = method;
  15682. lodash.methodOf = methodOf;
  15683. lodash.mixin = mixin;
  15684. lodash.negate = negate;
  15685. lodash.nthArg = nthArg;
  15686. lodash.omit = omit;
  15687. lodash.omitBy = omitBy;
  15688. lodash.once = once;
  15689. lodash.orderBy = orderBy;
  15690. lodash.over = over;
  15691. lodash.overArgs = overArgs;
  15692. lodash.overEvery = overEvery;
  15693. lodash.overSome = overSome;
  15694. lodash.partial = partial;
  15695. lodash.partialRight = partialRight;
  15696. lodash.partition = partition;
  15697. lodash.pick = pick;
  15698. lodash.pickBy = pickBy;
  15699. lodash.property = property;
  15700. lodash.propertyOf = propertyOf;
  15701. lodash.pull = pull;
  15702. lodash.pullAll = pullAll;
  15703. lodash.pullAllBy = pullAllBy;
  15704. lodash.pullAllWith = pullAllWith;
  15705. lodash.pullAt = pullAt;
  15706. lodash.range = range;
  15707. lodash.rangeRight = rangeRight;
  15708. lodash.rearg = rearg;
  15709. lodash.reject = reject;
  15710. lodash.remove = remove;
  15711. lodash.rest = rest;
  15712. lodash.reverse = reverse;
  15713. lodash.sampleSize = sampleSize;
  15714. lodash.set = set;
  15715. lodash.setWith = setWith;
  15716. lodash.shuffle = shuffle;
  15717. lodash.slice = slice;
  15718. lodash.sortBy = sortBy;
  15719. lodash.sortedUniq = sortedUniq;
  15720. lodash.sortedUniqBy = sortedUniqBy;
  15721. lodash.split = split;
  15722. lodash.spread = spread;
  15723. lodash.tail = tail;
  15724. lodash.take = take;
  15725. lodash.takeRight = takeRight;
  15726. lodash.takeRightWhile = takeRightWhile;
  15727. lodash.takeWhile = takeWhile;
  15728. lodash.tap = tap;
  15729. lodash.throttle = throttle;
  15730. lodash.thru = thru;
  15731. lodash.toArray = toArray;
  15732. lodash.toPairs = toPairs;
  15733. lodash.toPairsIn = toPairsIn;
  15734. lodash.toPath = toPath;
  15735. lodash.toPlainObject = toPlainObject;
  15736. lodash.transform = transform;
  15737. lodash.unary = unary;
  15738. lodash.union = union;
  15739. lodash.unionBy = unionBy;
  15740. lodash.unionWith = unionWith;
  15741. lodash.uniq = uniq;
  15742. lodash.uniqBy = uniqBy;
  15743. lodash.uniqWith = uniqWith;
  15744. lodash.unset = unset;
  15745. lodash.unzip = unzip;
  15746. lodash.unzipWith = unzipWith;
  15747. lodash.update = update;
  15748. lodash.updateWith = updateWith;
  15749. lodash.values = values;
  15750. lodash.valuesIn = valuesIn;
  15751. lodash.without = without;
  15752. lodash.words = words;
  15753. lodash.wrap = wrap;
  15754. lodash.xor = xor;
  15755. lodash.xorBy = xorBy;
  15756. lodash.xorWith = xorWith;
  15757. lodash.zip = zip;
  15758. lodash.zipObject = zipObject;
  15759. lodash.zipObjectDeep = zipObjectDeep;
  15760. lodash.zipWith = zipWith;
  15761. // Add aliases.
  15762. lodash.entries = toPairs;
  15763. lodash.entriesIn = toPairsIn;
  15764. lodash.extend = assignIn;
  15765. lodash.extendWith = assignInWith;
  15766. // Add methods to `lodash.prototype`.
  15767. mixin(lodash, lodash);
  15768. /*------------------------------------------------------------------------*/
  15769. // Add methods that return unwrapped values in chain sequences.
  15770. lodash.add = add;
  15771. lodash.attempt = attempt;
  15772. lodash.camelCase = camelCase;
  15773. lodash.capitalize = capitalize;
  15774. lodash.ceil = ceil;
  15775. lodash.clamp = clamp;
  15776. lodash.clone = clone;
  15777. lodash.cloneDeep = cloneDeep;
  15778. lodash.cloneDeepWith = cloneDeepWith;
  15779. lodash.cloneWith = cloneWith;
  15780. lodash.conformsTo = conformsTo;
  15781. lodash.deburr = deburr;
  15782. lodash.defaultTo = defaultTo;
  15783. lodash.divide = divide;
  15784. lodash.endsWith = endsWith;
  15785. lodash.eq = eq;
  15786. lodash.escape = escape;
  15787. lodash.escapeRegExp = escapeRegExp;
  15788. lodash.every = every;
  15789. lodash.find = find;
  15790. lodash.findIndex = findIndex;
  15791. lodash.findKey = findKey;
  15792. lodash.findLast = findLast;
  15793. lodash.findLastIndex = findLastIndex;
  15794. lodash.findLastKey = findLastKey;
  15795. lodash.floor = floor;
  15796. lodash.forEach = forEach;
  15797. lodash.forEachRight = forEachRight;
  15798. lodash.forIn = forIn;
  15799. lodash.forInRight = forInRight;
  15800. lodash.forOwn = forOwn;
  15801. lodash.forOwnRight = forOwnRight;
  15802. lodash.get = get;
  15803. lodash.gt = gt;
  15804. lodash.gte = gte;
  15805. lodash.has = has;
  15806. lodash.hasIn = hasIn;
  15807. lodash.head = head;
  15808. lodash.identity = identity;
  15809. lodash.includes = includes;
  15810. lodash.indexOf = indexOf;
  15811. lodash.inRange = inRange;
  15812. lodash.invoke = invoke;
  15813. lodash.isArguments = isArguments;
  15814. lodash.isArray = isArray;
  15815. lodash.isArrayBuffer = isArrayBuffer;
  15816. lodash.isArrayLike = isArrayLike;
  15817. lodash.isArrayLikeObject = isArrayLikeObject;
  15818. lodash.isBoolean = isBoolean;
  15819. lodash.isBuffer = isBuffer;
  15820. lodash.isDate = isDate;
  15821. lodash.isElement = isElement;
  15822. lodash.isEmpty = isEmpty;
  15823. lodash.isEqual = isEqual;
  15824. lodash.isEqualWith = isEqualWith;
  15825. lodash.isError = isError;
  15826. lodash.isFinite = isFinite;
  15827. lodash.isFunction = isFunction;
  15828. lodash.isInteger = isInteger;
  15829. lodash.isLength = isLength;
  15830. lodash.isMap = isMap;
  15831. lodash.isMatch = isMatch;
  15832. lodash.isMatchWith = isMatchWith;
  15833. lodash.isNaN = isNaN;
  15834. lodash.isNative = isNative;
  15835. lodash.isNil = isNil;
  15836. lodash.isNull = isNull;
  15837. lodash.isNumber = isNumber;
  15838. lodash.isObject = isObject;
  15839. lodash.isObjectLike = isObjectLike;
  15840. lodash.isPlainObject = isPlainObject;
  15841. lodash.isRegExp = isRegExp;
  15842. lodash.isSafeInteger = isSafeInteger;
  15843. lodash.isSet = isSet;
  15844. lodash.isString = isString;
  15845. lodash.isSymbol = isSymbol;
  15846. lodash.isTypedArray = isTypedArray;
  15847. lodash.isUndefined = isUndefined;
  15848. lodash.isWeakMap = isWeakMap;
  15849. lodash.isWeakSet = isWeakSet;
  15850. lodash.join = join;
  15851. lodash.kebabCase = kebabCase;
  15852. lodash.last = last;
  15853. lodash.lastIndexOf = lastIndexOf;
  15854. lodash.lowerCase = lowerCase;
  15855. lodash.lowerFirst = lowerFirst;
  15856. lodash.lt = lt;
  15857. lodash.lte = lte;
  15858. lodash.max = max;
  15859. lodash.maxBy = maxBy;
  15860. lodash.mean = mean;
  15861. lodash.meanBy = meanBy;
  15862. lodash.min = min;
  15863. lodash.minBy = minBy;
  15864. lodash.stubArray = stubArray;
  15865. lodash.stubFalse = stubFalse;
  15866. lodash.stubObject = stubObject;
  15867. lodash.stubString = stubString;
  15868. lodash.stubTrue = stubTrue;
  15869. lodash.multiply = multiply;
  15870. lodash.nth = nth;
  15871. lodash.noConflict = noConflict;
  15872. lodash.noop = noop;
  15873. lodash.now = now;
  15874. lodash.pad = pad;
  15875. lodash.padEnd = padEnd;
  15876. lodash.padStart = padStart;
  15877. lodash.parseInt = parseInt;
  15878. lodash.random = random;
  15879. lodash.reduce = reduce;
  15880. lodash.reduceRight = reduceRight;
  15881. lodash.repeat = repeat;
  15882. lodash.replace = replace;
  15883. lodash.result = result;
  15884. lodash.round = round;
  15885. lodash.runInContext = runInContext;
  15886. lodash.sample = sample;
  15887. lodash.size = size;
  15888. lodash.snakeCase = snakeCase;
  15889. lodash.some = some;
  15890. lodash.sortedIndex = sortedIndex;
  15891. lodash.sortedIndexBy = sortedIndexBy;
  15892. lodash.sortedIndexOf = sortedIndexOf;
  15893. lodash.sortedLastIndex = sortedLastIndex;
  15894. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15895. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15896. lodash.startCase = startCase;
  15897. lodash.startsWith = startsWith;
  15898. lodash.subtract = subtract;
  15899. lodash.sum = sum;
  15900. lodash.sumBy = sumBy;
  15901. lodash.template = template;
  15902. lodash.times = times;
  15903. lodash.toFinite = toFinite;
  15904. lodash.toInteger = toInteger;
  15905. lodash.toLength = toLength;
  15906. lodash.toLower = toLower;
  15907. lodash.toNumber = toNumber;
  15908. lodash.toSafeInteger = toSafeInteger;
  15909. lodash.toString = toString;
  15910. lodash.toUpper = toUpper;
  15911. lodash.trim = trim;
  15912. lodash.trimEnd = trimEnd;
  15913. lodash.trimStart = trimStart;
  15914. lodash.truncate = truncate;
  15915. lodash.unescape = unescape;
  15916. lodash.uniqueId = uniqueId;
  15917. lodash.upperCase = upperCase;
  15918. lodash.upperFirst = upperFirst;
  15919. // Add aliases.
  15920. lodash.each = forEach;
  15921. lodash.eachRight = forEachRight;
  15922. lodash.first = head;
  15923. mixin(lodash, (function() {
  15924. var source = {};
  15925. baseForOwn(lodash, function(func, methodName) {
  15926. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15927. source[methodName] = func;
  15928. }
  15929. });
  15930. return source;
  15931. }()), { 'chain': false });
  15932. /*------------------------------------------------------------------------*/
  15933. /**
  15934. * The semantic version number.
  15935. *
  15936. * @static
  15937. * @memberOf _
  15938. * @type {string}
  15939. */
  15940. lodash.VERSION = VERSION;
  15941. // Assign default placeholders.
  15942. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15943. lodash[methodName].placeholder = lodash;
  15944. });
  15945. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15946. arrayEach(['drop', 'take'], function(methodName, index) {
  15947. LazyWrapper.prototype[methodName] = function(n) {
  15948. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15949. var result = (this.__filtered__ && !index)
  15950. ? new LazyWrapper(this)
  15951. : this.clone();
  15952. if (result.__filtered__) {
  15953. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15954. } else {
  15955. result.__views__.push({
  15956. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15957. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15958. });
  15959. }
  15960. return result;
  15961. };
  15962. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15963. return this.reverse()[methodName](n).reverse();
  15964. };
  15965. });
  15966. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15967. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15968. var type = index + 1,
  15969. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15970. LazyWrapper.prototype[methodName] = function(iteratee) {
  15971. var result = this.clone();
  15972. result.__iteratees__.push({
  15973. 'iteratee': getIteratee(iteratee, 3),
  15974. 'type': type
  15975. });
  15976. result.__filtered__ = result.__filtered__ || isFilter;
  15977. return result;
  15978. };
  15979. });
  15980. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15981. arrayEach(['head', 'last'], function(methodName, index) {
  15982. var takeName = 'take' + (index ? 'Right' : '');
  15983. LazyWrapper.prototype[methodName] = function() {
  15984. return this[takeName](1).value()[0];
  15985. };
  15986. });
  15987. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15988. arrayEach(['initial', 'tail'], function(methodName, index) {
  15989. var dropName = 'drop' + (index ? '' : 'Right');
  15990. LazyWrapper.prototype[methodName] = function() {
  15991. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15992. };
  15993. });
  15994. LazyWrapper.prototype.compact = function() {
  15995. return this.filter(identity);
  15996. };
  15997. LazyWrapper.prototype.find = function(predicate) {
  15998. return this.filter(predicate).head();
  15999. };
  16000. LazyWrapper.prototype.findLast = function(predicate) {
  16001. return this.reverse().find(predicate);
  16002. };
  16003. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  16004. if (typeof path == 'function') {
  16005. return new LazyWrapper(this);
  16006. }
  16007. return this.map(function(value) {
  16008. return baseInvoke(value, path, args);
  16009. });
  16010. });
  16011. LazyWrapper.prototype.reject = function(predicate) {
  16012. return this.filter(negate(getIteratee(predicate)));
  16013. };
  16014. LazyWrapper.prototype.slice = function(start, end) {
  16015. start = toInteger(start);
  16016. var result = this;
  16017. if (result.__filtered__ && (start > 0 || end < 0)) {
  16018. return new LazyWrapper(result);
  16019. }
  16020. if (start < 0) {
  16021. result = result.takeRight(-start);
  16022. } else if (start) {
  16023. result = result.drop(start);
  16024. }
  16025. if (end !== undefined) {
  16026. end = toInteger(end);
  16027. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16028. }
  16029. return result;
  16030. };
  16031. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16032. return this.reverse().takeWhile(predicate).reverse();
  16033. };
  16034. LazyWrapper.prototype.toArray = function() {
  16035. return this.take(MAX_ARRAY_LENGTH);
  16036. };
  16037. // Add `LazyWrapper` methods to `lodash.prototype`.
  16038. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16039. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16040. isTaker = /^(?:head|last)$/.test(methodName),
  16041. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16042. retUnwrapped = isTaker || /^find/.test(methodName);
  16043. if (!lodashFunc) {
  16044. return;
  16045. }
  16046. lodash.prototype[methodName] = function() {
  16047. var value = this.__wrapped__,
  16048. args = isTaker ? [1] : arguments,
  16049. isLazy = value instanceof LazyWrapper,
  16050. iteratee = args[0],
  16051. useLazy = isLazy || isArray(value);
  16052. var interceptor = function(value) {
  16053. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16054. return (isTaker && chainAll) ? result[0] : result;
  16055. };
  16056. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16057. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16058. isLazy = useLazy = false;
  16059. }
  16060. var chainAll = this.__chain__,
  16061. isHybrid = !!this.__actions__.length,
  16062. isUnwrapped = retUnwrapped && !chainAll,
  16063. onlyLazy = isLazy && !isHybrid;
  16064. if (!retUnwrapped && useLazy) {
  16065. value = onlyLazy ? value : new LazyWrapper(this);
  16066. var result = func.apply(value, args);
  16067. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16068. return new LodashWrapper(result, chainAll);
  16069. }
  16070. if (isUnwrapped && onlyLazy) {
  16071. return func.apply(this, args);
  16072. }
  16073. result = this.thru(interceptor);
  16074. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16075. };
  16076. });
  16077. // Add `Array` methods to `lodash.prototype`.
  16078. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16079. var func = arrayProto[methodName],
  16080. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16081. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16082. lodash.prototype[methodName] = function() {
  16083. var args = arguments;
  16084. if (retUnwrapped && !this.__chain__) {
  16085. var value = this.value();
  16086. return func.apply(isArray(value) ? value : [], args);
  16087. }
  16088. return this[chainName](function(value) {
  16089. return func.apply(isArray(value) ? value : [], args);
  16090. });
  16091. };
  16092. });
  16093. // Map minified method names to their real names.
  16094. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16095. var lodashFunc = lodash[methodName];
  16096. if (lodashFunc) {
  16097. var key = lodashFunc.name + '';
  16098. if (!hasOwnProperty.call(realNames, key)) {
  16099. realNames[key] = [];
  16100. }
  16101. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16102. }
  16103. });
  16104. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16105. 'name': 'wrapper',
  16106. 'func': undefined
  16107. }];
  16108. // Add methods to `LazyWrapper`.
  16109. LazyWrapper.prototype.clone = lazyClone;
  16110. LazyWrapper.prototype.reverse = lazyReverse;
  16111. LazyWrapper.prototype.value = lazyValue;
  16112. // Add chain sequence methods to the `lodash` wrapper.
  16113. lodash.prototype.at = wrapperAt;
  16114. lodash.prototype.chain = wrapperChain;
  16115. lodash.prototype.commit = wrapperCommit;
  16116. lodash.prototype.next = wrapperNext;
  16117. lodash.prototype.plant = wrapperPlant;
  16118. lodash.prototype.reverse = wrapperReverse;
  16119. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16120. // Add lazy aliases.
  16121. lodash.prototype.first = lodash.prototype.head;
  16122. if (symIterator) {
  16123. lodash.prototype[symIterator] = wrapperToIterator;
  16124. }
  16125. return lodash;
  16126. });
  16127. /*--------------------------------------------------------------------------*/
  16128. // Export lodash.
  16129. var _ = runInContext();
  16130. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16131. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16132. // Expose Lodash on the global object to prevent errors when Lodash is
  16133. // loaded by a script tag in the presence of an AMD loader.
  16134. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16135. // Use `_.noConflict` to remove Lodash from the global object.
  16136. root._ = _;
  16137. // Define as an anonymous module so, through path mapping, it can be
  16138. // referenced as the "underscore" module.
  16139. define(function() {
  16140. return _;
  16141. });
  16142. }
  16143. // Check for `exports` after `define` in case a build optimizer adds it.
  16144. else if (freeModule) {
  16145. // Export for Node.js.
  16146. (freeModule.exports = _)._ = _;
  16147. // Export for CommonJS support.
  16148. freeExports._ = _;
  16149. }
  16150. else {
  16151. // Export to the global object.
  16152. root._ = _;
  16153. }
  16154. }.call(this));